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 <gp_Circ.hxx>
00027 # include <Geom_Circle.hxx>
00028 # include <GC_MakeCircle.hxx>
00029 #endif
00030
00031 #include "CirclePy.h"
00032 #include "CirclePy.cpp"
00033
00034 #include <Base/GeometryPyCXX.h>
00035 #include <Base/VectorPy.h>
00036
00037 using namespace Part;
00038
00039 extern const char* gce_ErrorStatusText(gce_ErrorType et);
00040
00041
00042 std::string CirclePy::representation(void) const
00043 {
00044 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00045 gp_Ax1 axis = circle->Axis();
00046 gp_Dir dir = axis.Direction();
00047 gp_Pnt loc = axis.Location();
00048 Standard_Real fRad = circle->Radius();
00049
00050 std::stringstream str;
00051 str << "Circle (";
00052 str << "Radius : " << fRad << ", ";
00053 str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), ";
00054 str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << ")";
00055 str << ")";
00056
00057 return str.str();
00058 }
00059
00060 PyObject *CirclePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00061 {
00062
00063 Handle_Geom_Circle circle = new Geom_Circle(gp_Circ());
00064 return new CirclePy(new GeomCircle(circle));
00065 }
00066
00067
00068 int CirclePy::PyInit(PyObject* args, PyObject* kwds)
00069 {
00070
00071 PyObject *pCirc;
00072 double dist;
00073 static char* keywords_cd[] = {"Circle","Distance",NULL};
00074 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_cd, &(CirclePy::Type), &pCirc, &dist)) {
00075 CirclePy* pcCircle = static_cast<CirclePy*>(pCirc);
00076 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast
00077 (pcCircle->getGeomCirclePtr()->handle());
00078 GC_MakeCircle mc(circle->Circ(), dist);
00079 if (!mc.IsDone()) {
00080 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00081 return -1;
00082 }
00083
00084 Handle_Geom_Circle circ = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00085 circ->SetCirc(mc.Value()->Circ());
00086 return 0;
00087 }
00088
00089
00090 PyObject *pV1, *pV2, *pV3;
00091 static char* keywords_cnr[] = {"Center","Normal","Radius",NULL};
00092 PyErr_Clear();
00093 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!d", keywords_cnr,
00094 &(Base::VectorPy::Type), &pV1,
00095 &(Base::VectorPy::Type), &pV2,
00096 &dist)) {
00097 Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
00098 Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
00099 GC_MakeCircle mc(gp_Pnt(v1.x,v1.y,v1.z),
00100 gp_Dir(v2.x,v2.y,v2.z),
00101 dist);
00102 if (!mc.IsDone()) {
00103 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00104 return -1;
00105 }
00106
00107 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00108 circle->SetCirc(mc.Value()->Circ());
00109 return 0;
00110 }
00111
00112 static char* keywords_c[] = {"Circle",NULL};
00113 PyErr_Clear();
00114 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_c, &(CirclePy::Type), &pCirc)) {
00115 CirclePy* pcCircle = static_cast<CirclePy*>(pCirc);
00116 Handle_Geom_Circle circ1 = Handle_Geom_Circle::DownCast
00117 (pcCircle->getGeomCirclePtr()->handle());
00118 Handle_Geom_Circle circ2 = Handle_Geom_Circle::DownCast
00119 (this->getGeomCirclePtr()->handle());
00120 circ2->SetCirc(circ1->Circ());
00121 return 0;
00122 }
00123
00124 static char* keywords_ppp[] = {"Point1","Point2","Point3",NULL};
00125 PyErr_Clear();
00126 if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ppp,
00127 &(Base::VectorPy::Type), &pV1,
00128 &(Base::VectorPy::Type), &pV2,
00129 &(Base::VectorPy::Type), &pV3)) {
00130 Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
00131 Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
00132 Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
00133 GC_MakeCircle mc(gp_Pnt(v1.x,v1.y,v1.z),
00134 gp_Pnt(v2.x,v2.y,v2.z),
00135 gp_Pnt(v3.x,v3.y,v3.z));
00136 if (!mc.IsDone()) {
00137 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(mc.Status()));
00138 return -1;
00139 }
00140
00141 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00142 circle->SetCirc(mc.Value()->Circ());
00143 return 0;
00144 }
00145
00146
00147 static char* keywords_n[] = {NULL};
00148 PyErr_Clear();
00149 if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) {
00150 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00151 circle->SetRadius(1.0);
00152 return 0;
00153 }
00154
00155 PyErr_SetString(PyExc_TypeError, "Circle constructor accepts:\n"
00156 "-- empty parameter list\n"
00157 "-- Circle\n"
00158 "-- Circle, Distance\n"
00159 "-- Center, Normal, Radius\n"
00160 "-- Point1, Point2, Point3");
00161 return -1;
00162 }
00163
00164 Py::Float CirclePy::getRadius(void) const
00165 {
00166 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00167 return Py::Float(circle->Radius());
00168 }
00169
00170 void CirclePy::setRadius(Py::Float arg)
00171 {
00172 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00173 circle->SetRadius((double)arg);
00174 }
00175
00176 Py::Object CirclePy::getCenter(void) const
00177 {
00178 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00179 gp_Pnt loc = circle->Location();
00180 return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z()));
00181 }
00182
00183 void CirclePy::setCenter(Py::Object arg)
00184 {
00185 PyObject* p = arg.ptr();
00186 if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00187 Base::Vector3d loc = static_cast<Base::VectorPy*>(p)->value();
00188 getGeomCirclePtr()->setCenter(loc);
00189 }
00190 else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
00191 Base::Vector3d loc = Base::getVectorFromTuple<double>(p);
00192 getGeomCirclePtr()->setCenter(loc);
00193 } else {
00194 std::string error = std::string("type must be 'Vector', not ");
00195 error += p->ob_type->tp_name;
00196 throw Py::TypeError(error);
00197 }
00198 }
00199
00200 Py::Object CirclePy::getAxis(void) const
00201 {
00202 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00203 gp_Ax1 axis = circle->Axis();
00204 gp_Dir dir = axis.Direction();
00205 return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z()));
00206 }
00207
00208 void CirclePy::setAxis(Py::Object arg)
00209 {
00210 PyObject* p = arg.ptr();
00211 Base::Vector3d val;
00212 if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) {
00213 val = static_cast<Base::VectorPy*>(p)->value();
00214 }
00215 else if (PyTuple_Check(p)) {
00216 val = Base::getVectorFromTuple<double>(p);
00217 }
00218 else {
00219 std::string error = std::string("type must be 'Vector', not ");
00220 error += p->ob_type->tp_name;
00221 throw Py::TypeError(error);
00222 }
00223
00224 Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle());
00225 try {
00226 gp_Ax1 axis;
00227 axis.SetLocation(circle->Location());
00228 axis.SetDirection(gp_Dir(val.x, val.y, val.z));
00229 circle->SetAxis(axis);
00230 }
00231 catch (Standard_Failure) {
00232 throw Py::Exception("cannot set axis");
00233 }
00234 }
00235
00236 PyObject *CirclePy::getCustomAttributes(const char* attr) const
00237 {
00238 return 0;
00239 }
00240
00241 int CirclePy::setCustomAttributes(const char* attr, PyObject *obj)
00242 {
00243 return 0;
00244 }