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_ConicalSurface.hxx>
00027 # include <Geom_Circle.hxx>
00028 # include <GC_MakeConicalSurface.hxx>
00029 # include <gp_Circ.hxx>
00030 # include <gp_Cone.hxx>
00031 # include <gp_Lin.hxx>
00032 # include <Geom_Line.hxx>
00033 # include <Geom_TrimmedCurve.hxx>
00034 # include <Standard_Failure.hxx>
00035 #endif
00036
00037 #include <Base/GeometryPyCXX.h>
00038 #include <Base/VectorPy.h>
00039
00040 #include "Geometry.h"
00041 #include "LinePy.h"
00042 #include "CirclePy.h"
00043 #include "ConePy.h"
00044 #include "ConePy.cpp"
00045
00046 using namespace Part;
00047
00048 extern const char* gce_ErrorStatusText(gce_ErrorType et);
00049
00050
00051 std::string ConePy::representation(void) const
00052 {
00053 return "<Cone object>";
00054 }
00055
00056 PyObject *ConePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00057 {
00058
00059 return new ConePy(new GeomCone);
00060 }
00061
00062
00063 int ConePy::PyInit(PyObject* args, PyObject* kwds)
00064 {
00065 char* keywords_n[] = {NULL};
00066 if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
00067 const Handle_Geom_ConicalSurface& s = static_cast<const Handle_Geom_ConicalSurface&>
00068 (getGeometryPtr()->handle());
00069 s->SetRadius(1.0);
00070 return 0;
00071 }
00072
00073 PyObject *pV1, *pV2;
00074 double radius1, radius2;
00075 static char* keywords_pprr[] = {"Point1","Point2","Radius1","Radius2",NULL};
00076 PyErr_Clear();
00077 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!dd", keywords_pprr,
00078 &(Base::VectorPy::Type), &pV1,
00079 &(Base::VectorPy::Type), &pV2,
00080 &radius1, &radius2)) {
00081 Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
00082 Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
00083 GC_MakeConicalSurface mc(gp_Pnt(v1.x,v1.y,v1.z),
00084 gp_Pnt(v2.x,v2.y,v2.z),
00085 radius1, radius2);
00086 if (!mc.IsDone()) {
00087 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00088 return -1;
00089 }
00090
00091 Handle_Geom_ConicalSurface cone = Handle_Geom_ConicalSurface::DownCast
00092 (getGeometryPtr()->handle());
00093 cone->SetCone(mc.Value()->Cone());
00094 return 0;
00095 }
00096
00097 PyObject *pV3, *pV4;
00098 static char* keywords_pppp[] = {"Point1","Point2","Point3","Point4",NULL};
00099 PyErr_Clear();
00100 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!", keywords_pppp,
00101 &(Base::VectorPy::Type), &pV1,
00102 &(Base::VectorPy::Type), &pV2,
00103 &(Base::VectorPy::Type), &pV3,
00104 &(Base::VectorPy::Type), &pV4)) {
00105 Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
00106 Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
00107 Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
00108 Base::Vector3d v4 = static_cast<Base::VectorPy*>(pV4)->value();
00109 GC_MakeConicalSurface mc(gp_Pnt(v1.x,v1.y,v1.z),
00110 gp_Pnt(v2.x,v2.y,v2.z),
00111 gp_Pnt(v3.x,v3.y,v3.z),
00112 gp_Pnt(v4.x,v4.y,v4.z));
00113 if (!mc.IsDone()) {
00114 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00115 return -1;
00116 }
00117
00118 Handle_Geom_ConicalSurface cone = Handle_Geom_ConicalSurface::DownCast
00119 (getGeometryPtr()->handle());
00120 cone->SetCone(mc.Value()->Cone());
00121 return 0;
00122 }
00123
00124 PyObject *pCone;
00125 double dist;
00126 static char* keywords_cd[] = {"Cone","Distance",NULL};
00127 PyErr_Clear();
00128 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_cd,
00129 &(ConePy::Type), &pCone, &dist)) {
00130 ConePy* pcCone = static_cast<ConePy*>(pCone);
00131 Handle_Geom_ConicalSurface pcone = Handle_Geom_ConicalSurface::DownCast
00132 (pcCone->getGeometryPtr()->handle());
00133 GC_MakeConicalSurface mc(pcone->Cone(), dist);
00134 if (!mc.IsDone()) {
00135 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00136 return -1;
00137 }
00138
00139 Handle_Geom_ConicalSurface cone = Handle_Geom_ConicalSurface::DownCast
00140 (getGeometryPtr()->handle());
00141 cone->SetCone(mc.Value()->Cone());
00142 return 0;
00143 }
00144
00145 static char* keywords_c[] = {"Cone",NULL};
00146 PyErr_Clear();
00147 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_c,
00148 &(ConePy::Type), &pCone)) {
00149 ConePy* pcCone = static_cast<ConePy*>(pCone);
00150 Handle_Geom_ConicalSurface pcone = Handle_Geom_ConicalSurface::DownCast
00151 (pcCone->getGeometryPtr()->handle());
00152 GC_MakeConicalSurface mc(pcone->Cone());
00153 if (!mc.IsDone()) {
00154 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00155 return -1;
00156 }
00157
00158 Handle_Geom_ConicalSurface cone = Handle_Geom_ConicalSurface::DownCast
00159 (getGeometryPtr()->handle());
00160 cone->SetCone(mc.Value()->Cone());
00161 return 0;
00162 }
00163
00164 PyErr_SetString(PyExc_TypeError, "Cone constructor accepts:\n"
00165 "-- empty parameter list\n"
00166 "-- Cone\n"
00167 "-- Cone, Distance\n"
00168 "-- Point1, Point2, Radius1, Radius2\n"
00169 "-- Point1, Point2, Point3, Point4");
00170 return -1;
00171 }
00172
00173 PyObject* ConePy::uIso(PyObject * args)
00174 {
00175 double u;
00176 if (!PyArg_ParseTuple(args, "d", &u))
00177 return 0;
00178
00179 try {
00180 Handle_Geom_ConicalSurface cone = Handle_Geom_ConicalSurface::DownCast
00181 (getGeomConePtr()->handle());
00182 Handle_Geom_Line c = Handle_Geom_Line::DownCast(cone->UIso(u));
00183 GeomLineSegment* line = new GeomLineSegment();
00184 Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast
00185 (line->handle());
00186 Handle_Geom_Line this_line = Handle_Geom_Line::DownCast
00187 (this_curv->BasisCurve());
00188 this_line->SetLin(c->Lin());
00189 return new LinePy(line);
00190 }
00191 catch (Standard_Failure) {
00192 Handle_Standard_Failure e = Standard_Failure::Caught();
00193 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00194 return 0;
00195 }
00196 }
00197
00198 PyObject* ConePy::vIso(PyObject * args)
00199 {
00200 double v;
00201 if (!PyArg_ParseTuple(args, "d", &v))
00202 return 0;
00203
00204 try {
00205 Handle_Geom_ConicalSurface cone = Handle_Geom_ConicalSurface::DownCast
00206 (getGeomConePtr()->handle());
00207 Handle_Geom_Curve c = cone->VIso(v);
00208 return new CirclePy(new GeomCircle(Handle_Geom_Circle::DownCast(c)));
00209 }
00210 catch (Standard_Failure) {
00211 Handle_Standard_Failure e = Standard_Failure::Caught();
00212 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00213 return 0;
00214 }
00215 }
00216
00217 Py::Object ConePy::getApex(void) const
00218 {
00219 Handle_Geom_ConicalSurface s = Handle_Geom_ConicalSurface::DownCast
00220 (getGeomConePtr()->handle());
00221 gp_Pnt loc = s->Apex();
00222 return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
00223 }
00224
00225 Py::Float ConePy::getRadius(void) const
00226 {
00227 Handle_Geom_ConicalSurface s = Handle_Geom_ConicalSurface::DownCast
00228 (getGeomConePtr()->handle());
00229 return Py::Float(s->RefRadius());
00230 }
00231
00232 void ConePy::setRadius(Py::Float arg)
00233 {
00234 Handle_Geom_ConicalSurface s = Handle_Geom_ConicalSurface::DownCast
00235 (getGeomConePtr()->handle());
00236 s->SetRadius((double)arg);
00237 }
00238
00239 Py::Float ConePy::getSemiAngle(void) const
00240 {
00241 Handle_Geom_ConicalSurface s = Handle_Geom_ConicalSurface::DownCast
00242 (getGeomConePtr()->handle());
00243 return Py::Float(s->SemiAngle());
00244 }
00245
00246 void ConePy::setSemiAngle(Py::Float arg)
00247 {
00248 Handle_Geom_ConicalSurface s = Handle_Geom_ConicalSurface::DownCast
00249 (getGeomConePtr()->handle());
00250 s->SetSemiAngle((double)arg);
00251 }
00252
00253 Py::Object ConePy::getCenter(void) const
00254 {
00255 Handle_Geom_ElementarySurface s = Handle_Geom_ElementarySurface::DownCast
00256 (getGeomConePtr()->handle());
00257 gp_Pnt loc = s->Location();
00258 return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
00259 }
00260
00261 void ConePy::setCenter(Py::Object arg)
00262 {
00263 PyObject* p = arg.ptr();
00264 if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00265 Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
00266 Handle_Geom_ElementarySurface s = Handle_Geom_ElementarySurface::DownCast
00267 (getGeomConePtr()->handle());
00268 s->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
00269 }
00270 else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
00271 Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
00272 Handle_Geom_ElementarySurface s = Handle_Geom_ElementarySurface::DownCast
00273 (getGeomConePtr()->handle());
00274 s->SetLocation(gp_Pnt(loc.x, loc.y, loc.z));
00275 }
00276 else {
00277 std::string error = std::string("type must be 'Vector', not ");
00278 error += p->ob_type->tp_name;
00279 throw Py::TypeError(error);
00280 }
00281 }
00282
00283 Py::Object ConePy::getAxis(void) const
00284 {
00285 Handle_Geom_ElementarySurface s = Handle_Geom_ElementarySurface::DownCast
00286 (getGeometryPtr()->handle());
00287 gp_Dir dir = s->Axis().Direction();
00288 return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
00289 }
00290
00291 void ConePy::setAxis(Py::Object arg)
00292 {
00293 Standard_Real dir_x, dir_y, dir_z;
00294 PyObject *p = arg.ptr();
00295 if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00296 Base::Vector3d v = static_cast<Base::VectorPy*>(p)->value();
00297 dir_x = v.x;
00298 dir_y = v.y;
00299 dir_z = v.z;
00300 }
00301 else if (PyTuple_Check(p)) {
00302 Py::Tuple tuple(arg);
00303 dir_x = (double)Py::Float(tuple.getItem(0));
00304 dir_y = (double)Py::Float(tuple.getItem(1));
00305 dir_z = (double)Py::Float(tuple.getItem(2));
00306 }
00307 else {
00308 std::string error = std::string("type must be 'Vector' or tuple, not ");
00309 error += p->ob_type->tp_name;
00310 throw Py::TypeError(error);
00311 }
00312
00313 try {
00314 Handle_Geom_ElementarySurface this_surf = Handle_Geom_ElementarySurface::DownCast
00315 (this->getGeometryPtr()->handle());
00316 gp_Ax1 axis;
00317 axis.SetLocation(this_surf->Location());
00318 axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z));
00319 this_surf->SetAxis(axis);
00320 }
00321 catch (Standard_Failure) {
00322 throw Py::Exception("cannot set axis");
00323 }
00324 }
00325
00326 PyObject *ConePy::getCustomAttributes(const char* ) const
00327 {
00328 return 0;
00329 }
00330
00331 int ConePy::setCustomAttributes(const char* , PyObject* )
00332 {
00333 return 0;
00334 }
00335
00336