00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <Geom_CylindricalSurface.hxx>
00027 # include <Geom_Circle.hxx>
00028 # include <Geom_Line.hxx>
00029 # include <Geom_TrimmedCurve.hxx>
00030 # include <GC_MakeCylindricalSurface.hxx>
00031 # include <gp_Circ.hxx>
00032 # include <gp_Cylinder.hxx>
00033 # include <gp_Lin.hxx>
00034 #endif
00035
00036 #include <Base/GeometryPyCXX.h>
00037 #include <Base/VectorPy.h>
00038
00039 #include "Geometry.h"
00040 #include "CirclePy.h"
00041 #include "EllipsePy.h"
00042 #include "LinePy.h"
00043 #include "CylinderPy.h"
00044 #include "CylinderPy.cpp"
00045
00046 using namespace Part;
00047
00048 extern const char* gce_ErrorStatusText(gce_ErrorType et);
00049
00050
00051 std::string CylinderPy::representation(void) const
00052 {
00053 return "<Cylinder object>";
00054 }
00055
00056 PyObject *CylinderPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00057 {
00058
00059 return new CylinderPy(new GeomCylinder);
00060 }
00061
00062
00063 int CylinderPy::PyInit(PyObject* args, PyObject* kwds)
00064 {
00065
00066 PyObject *pCyl;
00067 double dist;
00068 static char* keywords_cd[] = {"Cylinder","Distance",NULL};
00069 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_cd, &(CylinderPy::Type), &pCyl, &dist)) {
00070 CylinderPy* pcCylinder = static_cast<CylinderPy*>(pCyl);
00071 Handle_Geom_CylindricalSurface cylinder = Handle_Geom_CylindricalSurface::DownCast
00072 (pcCylinder->getGeomCylinderPtr()->handle());
00073 GC_MakeCylindricalSurface mc(cylinder->Cylinder(), dist);
00074 if (!mc.IsDone()) {
00075 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00076 return -1;
00077 }
00078
00079 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00080 (getGeomCylinderPtr()->handle());
00081 cyl->SetCylinder(mc.Value()->Cylinder());
00082 return 0;
00083 }
00084
00085 static char* keywords_c[] = {"Cylinder",NULL};
00086 PyErr_Clear();
00087 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_c, &(CylinderPy::Type), &pCyl)) {
00088 CylinderPy* pcCylinder = static_cast<CylinderPy*>(pCyl);
00089 Handle_Geom_CylindricalSurface cyl1 = Handle_Geom_CylindricalSurface::DownCast
00090 (pcCylinder->getGeomCylinderPtr()->handle());
00091 Handle_Geom_CylindricalSurface cyl2 = Handle_Geom_CylindricalSurface::DownCast
00092 (this->getGeomCylinderPtr()->handle());
00093 cyl2->SetCylinder(cyl1->Cylinder());
00094 return 0;
00095 }
00096
00097 PyObject *pV1, *pV2, *pV3;
00098 static char* keywords_ppp[] = {"Point1","Point2","Point3",NULL};
00099 PyErr_Clear();
00100 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ppp,
00101 &(Base::VectorPy::Type), &pV1,
00102 &(Base::VectorPy::Type), &pV2,
00103 &(Base::VectorPy::Type), &pV3)) {
00104 Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
00105 Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
00106 Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
00107 GC_MakeCylindricalSurface mc(gp_Pnt(v1.x,v1.y,v1.z),
00108 gp_Pnt(v2.x,v2.y,v2.z),
00109 gp_Pnt(v3.x,v3.y,v3.z));
00110 if (!mc.IsDone()) {
00111 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00112 return -1;
00113 }
00114
00115 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00116 (getGeomCylinderPtr()->handle());
00117 cyl->SetCylinder(mc.Value()->Cylinder());
00118 return 0;
00119 }
00120
00121 static char* keywords_cc[] = {"Circle",NULL};
00122 PyErr_Clear();
00123 PyObject *pCirc;
00124 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_cc, &(CirclePy::Type), &pCirc)) {
00125 CirclePy* pcCircle = static_cast<CirclePy*>(pCirc);
00126 Handle_Geom_Circle circ = Handle_Geom_Circle::DownCast
00127 (pcCircle->getGeomCirclePtr()->handle());
00128 GC_MakeCylindricalSurface mc(circ->Circ());
00129 if (!mc.IsDone()) {
00130 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00131 return -1;
00132 }
00133
00134 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00135 (getGeomCylinderPtr()->handle());
00136 cyl->SetCylinder(mc.Value()->Cylinder());
00137 return 0;
00138 }
00139
00140 static char* keywords_n[] = {NULL};
00141 PyErr_Clear();
00142 if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
00143 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00144 (getGeomCylinderPtr()->handle());
00145 cyl->SetRadius(1.0);
00146 return 0;
00147 }
00148
00149
00150 PyErr_SetString(PyExc_TypeError, "Cylinder constructor accepts:\n"
00151 "-- empty parameter list\n"
00152 "-- Cylinder\n"
00153 "-- Cylinder, Distance\n"
00154 "-- Point1, Point2, Point3\n"
00155 "-- Circle");
00156 return -1;
00157 }
00158
00159 PyObject* CylinderPy::uIso(PyObject * args)
00160 {
00161 double v;
00162 if (!PyArg_ParseTuple(args, "d", &v))
00163 return 0;
00164
00165 try {
00166 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00167 (getGeomCylinderPtr()->handle());
00168 Handle_Geom_Curve c = cyl->UIso(v);
00169 if (!Handle_Geom_Line::DownCast(c).IsNull()) {
00170 GeomLineSegment* line = new GeomLineSegment();
00171 Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast
00172 (line->handle());
00173 Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
00174 (this_curv->BasisCurve());
00175 this_line->SetLin(Handle_Geom_Line::DownCast(c)->Lin());
00176 return new LinePy(line);
00177 }
00178
00179 PyErr_SetString(PyExc_NotImplementedError, "this type of conical curve is not implemented");
00180 return 0;
00181 }
00182 catch (Standard_Failure) {
00183 Handle_Standard_Failure e = Standard_Failure::Caught();
00184 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00185 return 0;
00186 }
00187 }
00188
00189 PyObject* CylinderPy::vIso(PyObject * args)
00190 {
00191 double v;
00192 if (!PyArg_ParseTuple(args, "d", &v))
00193 return 0;
00194
00195 try {
00196 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00197 (getGeomCylinderPtr()->handle());
00198 Handle_Geom_Curve c = cyl->VIso(v);
00199 if (!Handle_Geom_Circle::DownCast(c).IsNull()) {
00200 return new CirclePy(new GeomCircle(Handle_Geom_Circle::DownCast(c)));
00201 }
00202 if (!Handle_Geom_Ellipse::DownCast(c).IsNull()) {
00203 return new EllipsePy(new GeomEllipse(Handle_Geom_Ellipse::DownCast(c)));
00204 }
00205
00206 PyErr_SetString(PyExc_NotImplementedError, "this type of conical curve is not implemented");
00207 return 0;
00208 }
00209 catch (Standard_Failure) {
00210 Handle_Standard_Failure e = Standard_Failure::Caught();
00211 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00212 return 0;
00213 }
00214 }
00215
00216 Py::Float CylinderPy::getRadius(void) const
00217 {
00218 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00219 (getGeomCylinderPtr()->handle());
00220 return Py::Float(cyl->Radius());
00221 }
00222
00223 void CylinderPy::setRadius(Py::Float arg)
00224 {
00225 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00226 (getGeomCylinderPtr()->handle());
00227 cyl->SetRadius((double)arg);
00228 }
00229
00230 Py::Object CylinderPy::getCenter(void) const
00231 {
00232 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00233 (getGeomCylinderPtr()->handle());
00234 gp_Pnt loc = cyl->Location();
00235 return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
00236 }
00237
00238 void CylinderPy::setCenter(Py::Object arg)
00239 {
00240 PyObject* p = arg.ptr();
00241 if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00242 Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
00243 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00244 (getGeomCylinderPtr()->handle());
00245 cyl->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
00246 }
00247 else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
00248 Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
00249 Handle_Geom_CylindricalSurface cyl = Handle_Geom_CylindricalSurface::DownCast
00250 (getGeomCylinderPtr()->handle());
00251 cyl->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
00252 }
00253 else {
00254 std::string error = std::string("type must be 'Vector', not ");
00255 error += p->ob_type->tp_name;
00256 throw Py::TypeError(error);
00257 }
00258 }
00259
00260 Py::Object CylinderPy::getAxis(void) const
00261 {
00262 Handle_Geom_ElementarySurface s = Handle_Geom_ElementarySurface::DownCast
00263 (getGeometryPtr()->handle());
00264 gp_Dir dir = s->Axis().Direction();
00265 return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
00266 }
00267
00268 void CylinderPy::setAxis(Py::Object arg)
00269 {
00270 Standard_Real dir_x, dir_y, dir_z;
00271 PyObject *p = arg.ptr();
00272 if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00273 Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
00274 dir_x = v.x;
00275 dir_y = v.y;
00276 dir_z = v.z;
00277 }
00278 else if (PyTuple_Check(p)) {
00279 Py::Tuple tuple(arg);
00280 dir_x = (double)Py::Float(tuple.getItem(0));
00281 dir_y = (double)Py::Float(tuple.getItem(1));
00282 dir_z = (double)Py::Float(tuple.getItem(2));
00283 }
00284 else {
00285 std::string error = std::string("type must be 'Vector' or tuple, not ");
00286 error += p->ob_type->tp_name;
00287 throw Py::TypeError(error);
00288 }
00289
00290 try {
00291 Handle_Geom_ElementarySurface this_surf = Handle_Geom_ElementarySurface::DownCast
00292 (this->getGeometryPtr()->handle());
00293 gp_Ax1 axis;
00294 axis.SetLocation(this_surf->Location());
00295 axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
00296 this_surf->SetAxis(axis);
00297 }
00298 catch (Standard_Failure) {
00299 throw Py::Exception("cannot set axis");
00300 }
00301 }
00302
00303 PyObject *CylinderPy::getCustomAttributes(const char* ) const
00304 {
00305 return 0;
00306 }
00307
00308 int CylinderPy::setCustomAttributes(const char* , PyObject* )
00309 {
00310 return 0;
00311 }
00312
00313