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_BezierCurve.hxx>
00027 # include <gp_Pnt.hxx>
00028 # include <TColStd_Array1OfReal.hxx>
00029 # include <TColgp_Array1OfPnt.hxx>
00030 #endif
00031
00032 #include <Base/VectorPy.h>
00033 #include <Base/GeometryPyCXX.h>
00034
00035 #include "Geometry.h"
00036 #include "BezierCurvePy.h"
00037 #include "BezierCurvePy.cpp"
00038
00039 using namespace Part;
00040
00041
00042 std::string BezierCurvePy::representation(void) const
00043 {
00044 return "<BezierCurve object>";
00045 }
00046
00047 PyObject *BezierCurvePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00048 {
00049
00050 return new BezierCurvePy(new GeomBezierCurve);
00051 }
00052
00053
00054 int BezierCurvePy::PyInit(PyObject* , PyObject* )
00055 {
00056 return 0;
00057 }
00058
00059 PyObject* BezierCurvePy::isRational(PyObject *args)
00060 {
00061 if (!PyArg_ParseTuple(args, ""))
00062 return 0;
00063 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00064 (getGeometryPtr()->handle());
00065 Standard_Boolean val = curve->IsRational();
00066 if (val) {
00067 Py_INCREF(Py_True);
00068 return Py_True;
00069 }
00070 else {
00071 Py_INCREF(Py_False);
00072 return Py_False;
00073 }
00074 }
00075
00076 PyObject* BezierCurvePy::isPeriodic(PyObject *args)
00077 {
00078 if (!PyArg_ParseTuple(args, ""))
00079 return 0;
00080 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00081 (getGeometryPtr()->handle());
00082 Standard_Boolean val = curve->IsPeriodic();
00083 if (val) {
00084 Py_INCREF(Py_True);
00085 return Py_True;
00086 }
00087 else {
00088 Py_INCREF(Py_False);
00089 return Py_False;
00090 }
00091 }
00092
00093 PyObject* BezierCurvePy::isClosed(PyObject *args)
00094 {
00095 if (!PyArg_ParseTuple(args, ""))
00096 return 0;
00097 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00098 (getGeometryPtr()->handle());
00099 Standard_Boolean val = curve->IsClosed();
00100 if (val) {
00101 Py_INCREF(Py_True);
00102 return Py_True;
00103 }
00104 else {
00105 Py_INCREF(Py_False);
00106 return Py_False;
00107 }
00108 }
00109
00110 PyObject* BezierCurvePy::increase(PyObject * args)
00111 {
00112 int degree;
00113 if (!PyArg_ParseTuple(args, "i", °ree))
00114 return 0;
00115 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00116 (getGeometryPtr()->handle());
00117 curve->Increase(degree);
00118 Py_Return;
00119 }
00120
00121 PyObject* BezierCurvePy::insertPoleAfter(PyObject * args)
00122 {
00123 int index;
00124 double weight=1.0;
00125 PyObject* p;
00126 if (!PyArg_ParseTuple(args, "iO!|d", &index, &(Base::VectorPy::Type), &p, &weight))
00127 return 0;
00128 Base::Vector3d vec = static_cast<Base::VectorPy*>(p)->value();
00129 gp_Pnt pnt(vec.x, vec.y, vec.z);
00130 try {
00131 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00132 (getGeometryPtr()->handle());
00133 curve->InsertPoleAfter(index,pnt,weight);
00134 Py_Return;
00135 }
00136 catch (Standard_Failure) {
00137 Handle_Standard_Failure e = Standard_Failure::Caught();
00138 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00139 return 0;
00140 }
00141 }
00142
00143 PyObject* BezierCurvePy::insertPoleBefore(PyObject * args)
00144 {
00145 int index;
00146 double weight=1.0;
00147 PyObject* p;
00148 if (!PyArg_ParseTuple(args, "iO!|d", &index, &(Base::VectorPy::Type), &p, &weight))
00149 return 0;
00150 Base::Vector3d vec = static_cast<Base::VectorPy*>(p)->value();
00151 gp_Pnt pnt(vec.x, vec.y, vec.z);
00152 try {
00153 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00154 (getGeometryPtr()->handle());
00155 curve->InsertPoleBefore(index,pnt,weight);
00156 Py_Return;
00157 }
00158 catch (Standard_Failure) {
00159 Handle_Standard_Failure e = Standard_Failure::Caught();
00160 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00161 return 0;
00162 }
00163 }
00164
00165 PyObject* BezierCurvePy::removePole(PyObject * args)
00166 {
00167 int index;
00168 if (!PyArg_ParseTuple(args, "i", &index))
00169 return 0;
00170 try {
00171 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00172 (getGeometryPtr()->handle());
00173 curve->RemovePole(index);
00174 Py_Return;
00175 }
00176 catch (Standard_Failure) {
00177 Handle_Standard_Failure e = Standard_Failure::Caught();
00178 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00179 return 0;
00180 }
00181 }
00182
00183 PyObject* BezierCurvePy::segment(PyObject * args)
00184 {
00185 double u1,u2;
00186 if (!PyArg_ParseTuple(args, "dd", &u1,&u2))
00187 return 0;
00188 try {
00189 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00190 (getGeometryPtr()->handle());
00191 curve->Segment(u1,u2);
00192 Py_Return;
00193 }
00194 catch (Standard_Failure) {
00195 Handle_Standard_Failure e = Standard_Failure::Caught();
00196 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00197 return 0;
00198 }
00199 }
00200
00201 PyObject* BezierCurvePy::setPole(PyObject * args)
00202 {
00203 int index;
00204 double weight=-1.0;
00205 PyObject* p;
00206 if (!PyArg_ParseTuple(args, "iO!|d", &index, &(Base::VectorPy::Type), &p, &weight))
00207 return 0;
00208 Base::Vector3d vec = static_cast<Base::VectorPy*>(p)->value();
00209 gp_Pnt pnt(vec.x, vec.y, vec.z);
00210 try {
00211 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00212 (getGeometryPtr()->handle());
00213 if (weight < 0.0)
00214 curve->SetPole(index,pnt);
00215 else
00216 curve->SetPole(index,pnt,weight);
00217 Py_Return;
00218 }
00219 catch (Standard_Failure) {
00220 Handle_Standard_Failure e = Standard_Failure::Caught();
00221 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00222 return 0;
00223 }
00224 }
00225
00226 PyObject* BezierCurvePy::getPole(PyObject * args)
00227 {
00228 int index;
00229 if (!PyArg_ParseTuple(args, "i", &index))
00230 return 0;
00231 try {
00232 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00233 (getGeometryPtr()->handle());
00234 gp_Pnt pnt = curve->Pole(index);
00235 Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d(
00236 pnt.X(), pnt.Y(), pnt.Z()));
00237 return vec;
00238 }
00239 catch (Standard_Failure) {
00240 Handle_Standard_Failure e = Standard_Failure::Caught();
00241 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00242 return 0;
00243 }
00244 }
00245
00246 PyObject* BezierCurvePy::getPoles(PyObject * args)
00247 {
00248 if (!PyArg_ParseTuple(args, ""))
00249 return 0;
00250 try {
00251 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00252 (getGeometryPtr()->handle());
00253 TColgp_Array1OfPnt p(1,curve->NbPoles());
00254 curve->Poles(p);
00255 Py::List poles;
00256 for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) {
00257 gp_Pnt pnt = p(i);
00258 Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d(
00259 pnt.X(), pnt.Y(), pnt.Z()));
00260 poles.append(Py::Object(vec));
00261 }
00262 return Py::new_reference_to(poles);
00263 }
00264 catch (Standard_Failure) {
00265 Handle_Standard_Failure e = Standard_Failure::Caught();
00266 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00267 return 0;
00268 }
00269 }
00270
00271 PyObject* BezierCurvePy::setPoles(PyObject * args)
00272 {
00273 PyObject* plist;
00274 if (!PyArg_ParseTuple(args, "O!", &(PyList_Type), &plist))
00275 return 0;
00276 try {
00277 Py::List list(plist);
00278 TColgp_Array1OfPnt poles(1,list.size());
00279 int index = poles.Lower();
00280 for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00281 Py::Vector v(*it);
00282 Base::Vector3d pole = v.toVector();
00283 poles.SetValue(index++, gp_Pnt(pole.x,pole.y,pole.z));
00284 }
00285
00286 Handle_Geom_BezierCurve bezier = new Geom_BezierCurve(poles);
00287 this->getGeomBezierCurvePtr()->setHandle(bezier);
00288 Py_Return;
00289 }
00290 catch (Standard_Failure) {
00291 Handle_Standard_Failure e = Standard_Failure::Caught();
00292 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00293 return 0;
00294 }
00295 }
00296
00297 PyObject* BezierCurvePy::setWeight(PyObject * args)
00298 {
00299 int index;
00300 double weight;
00301 if (!PyArg_ParseTuple(args, "id", &index,&weight))
00302 return 0;
00303 try {
00304 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00305 (getGeometryPtr()->handle());
00306 curve->SetWeight(index,weight);
00307 Py_Return;
00308 }
00309 catch (Standard_Failure) {
00310 Handle_Standard_Failure e = Standard_Failure::Caught();
00311 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00312 return 0;
00313 }
00314 }
00315
00316 PyObject* BezierCurvePy::getWeight(PyObject * args)
00317 {
00318 int index;
00319 if (!PyArg_ParseTuple(args, "i", &index))
00320 return 0;
00321 try {
00322 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00323 (getGeometryPtr()->handle());
00324 double weight = curve->Weight(index);
00325 return Py_BuildValue("d", weight);
00326 }
00327 catch (Standard_Failure) {
00328 Handle_Standard_Failure e = Standard_Failure::Caught();
00329 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00330 return 0;
00331 }
00332 }
00333
00334 PyObject* BezierCurvePy::getWeights(PyObject * args)
00335 {
00336 if (!PyArg_ParseTuple(args, ""))
00337 return 0;
00338 try {
00339 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00340 (getGeometryPtr()->handle());
00341 TColStd_Array1OfReal w(1,curve->NbPoles());
00342 curve->Weights(w);
00343 Py::List weights;
00344 for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) {
00345 weights.append(Py::Float(w(i)));
00346 }
00347 return Py::new_reference_to(weights);
00348 }
00349 catch (Standard_Failure) {
00350 Handle_Standard_Failure e = Standard_Failure::Caught();
00351 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00352 return 0;
00353 }
00354 }
00355
00356 PyObject* BezierCurvePy::getResolution(PyObject* args)
00357 {
00358 double tol;
00359 if (!PyArg_ParseTuple(args, "d", &tol))
00360 return 0;
00361 try {
00362 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00363 (getGeometryPtr()->handle());
00364 double utol;
00365 curve->Resolution(tol,utol);
00366 return Py_BuildValue("d",utol);
00367 }
00368 catch (Standard_Failure) {
00369 Handle_Standard_Failure e = Standard_Failure::Caught();
00370 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00371 return 0;
00372 }
00373 }
00374
00375 Py::Int BezierCurvePy::getDegree(void) const
00376 {
00377 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00378 (getGeometryPtr()->handle());
00379 return Py::Int(curve->Degree());
00380 }
00381
00382 Py::Int BezierCurvePy::getMaxDegree(void) const
00383 {
00384 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00385 (getGeometryPtr()->handle());
00386 return Py::Int(curve->MaxDegree());
00387 }
00388
00389 Py::Int BezierCurvePy::getNbPoles(void) const
00390 {
00391 Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast
00392 (getGeometryPtr()->handle());
00393 return Py::Int(curve->NbPoles());
00394 }
00395
00396 Py::Object BezierCurvePy::getStartPoint(void) const
00397 {
00398 Handle_Geom_BezierCurve c = Handle_Geom_BezierCurve::DownCast
00399 (getGeometryPtr()->handle());
00400 gp_Pnt pnt = c->StartPoint();
00401 return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
00402 }
00403
00404 Py::Object BezierCurvePy::getEndPoint(void) const
00405 {
00406 Handle_Geom_BezierCurve c = Handle_Geom_BezierCurve::DownCast
00407 (getGeometryPtr()->handle());
00408 gp_Pnt pnt = c->EndPoint();
00409 return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
00410 }
00411
00412 PyObject *BezierCurvePy::getCustomAttributes(const char* ) const
00413 {
00414 return 0;
00415 }
00416
00417 int BezierCurvePy::setCustomAttributes(const char* , PyObject* )
00418 {
00419 return 0;
00420 }