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_BSplineCurve.hxx>
00027 # include <GeomAPI_PointsToBSpline.hxx>
00028 # include <GeomAPI_Interpolate.hxx>
00029 # include <GeomConvert_BSplineCurveToBezierCurve.hxx>
00030 # include <gp_Pnt.hxx>
00031 # include <TColStd_Array1OfReal.hxx>
00032 # include <TColgp_Array1OfPnt.hxx>
00033 # include <TColgp_HArray1OfPnt.hxx>
00034 # include <TColStd_Array1OfInteger.hxx>
00035 # include <Handle_TColgp_HArray1OfPnt.hxx>
00036 # include <Precision.hxx>
00037 #endif
00038
00039 #include <Base/VectorPy.h>
00040 #include <Base/GeometryPyCXX.h>
00041
00042 #include "Geometry.h"
00043 #include "BSplineCurvePy.h"
00044 #include "BSplineCurvePy.cpp"
00045 #include "BezierCurvePy.h"
00046
00047 using namespace Part;
00048
00049
00050 std::string BSplineCurvePy::representation(void) const
00051 {
00052 return "<BSplineCurve object>";
00053 }
00054
00055 PyObject *BSplineCurvePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00056 {
00057
00058 return new BSplineCurvePy(new GeomBSplineCurve);
00059 }
00060
00061
00062 int BSplineCurvePy::PyInit(PyObject* args, PyObject* )
00063 {
00064 if (PyArg_ParseTuple(args, "")) {
00065 return 0;
00066 }
00067
00068 PyErr_SetString(PyExc_TypeError, "B-Spline constructor accepts:\n"
00069 "-- empty parameter list\n");
00070 return -1;
00071 }
00072
00073 PyObject* BSplineCurvePy::isRational(PyObject *args)
00074 {
00075 if (!PyArg_ParseTuple(args, ""))
00076 return 0;
00077 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00078 (getGeometryPtr()->handle());
00079 Standard_Boolean val = curve->IsRational();
00080 if (val) {
00081 Py_INCREF(Py_True);
00082 return Py_True;
00083 }
00084 else {
00085 Py_INCREF(Py_False);
00086 return Py_False;
00087 }
00088 }
00089
00090 PyObject* BSplineCurvePy::isPeriodic(PyObject *args)
00091 {
00092 if (!PyArg_ParseTuple(args, ""))
00093 return 0;
00094 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00095 (getGeometryPtr()->handle());
00096 Standard_Boolean val = curve->IsPeriodic();
00097 if (val) {
00098 Py_INCREF(Py_True);
00099 return Py_True;
00100 }
00101 else {
00102 Py_INCREF(Py_False);
00103 return Py_False;
00104 }
00105 }
00106
00107 PyObject* BSplineCurvePy::isClosed(PyObject *args)
00108 {
00109 if (!PyArg_ParseTuple(args, ""))
00110 return 0;
00111 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00112 (getGeometryPtr()->handle());
00113 Standard_Boolean val = curve->IsClosed();
00114 if (val) {
00115 Py_INCREF(Py_True);
00116 return Py_True;
00117 }
00118 else {
00119 Py_INCREF(Py_False);
00120 return Py_False;
00121 }
00122 }
00123
00124 PyObject* BSplineCurvePy::increaseDegree(PyObject * args)
00125 {
00126 int degree;
00127 if (!PyArg_ParseTuple(args, "i", °ree))
00128 return 0;
00129 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00130 (getGeometryPtr()->handle());
00131 curve->IncreaseDegree(degree);
00132 Py_Return;
00133 }
00134
00135 PyObject* BSplineCurvePy::increaseMultiplicity(PyObject * args)
00136 {
00137 int mult=-1;
00138 int start, end;
00139 if (!PyArg_ParseTuple(args, "ii|i", &start, &end, &mult))
00140 return 0;
00141
00142 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00143 (getGeometryPtr()->handle());
00144 if (mult == -1) {
00145 mult = end;
00146 curve->IncreaseMultiplicity(start, mult);
00147 }
00148 else {
00149 curve->IncreaseMultiplicity(start, end, mult);
00150 }
00151
00152 Py_Return;
00153 }
00154
00155 PyObject* BSplineCurvePy::incrementMultiplicity(PyObject * args)
00156 {
00157 int start, end, mult;
00158 if (!PyArg_ParseTuple(args, "iii", &start, &end, &mult))
00159 return 0;
00160
00161 try {
00162 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00163 (getGeometryPtr()->handle());
00164 curve->IncrementMultiplicity(start, end, mult);
00165 }
00166 catch (Standard_Failure) {
00167 Handle_Standard_Failure e = Standard_Failure::Caught();
00168 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00169 return 0;
00170 }
00171
00172 Py_Return;
00173 }
00174
00175 PyObject* BSplineCurvePy::insertKnot(PyObject * args)
00176 {
00177 double U, tol = 0.0;
00178 int M=1;
00179 PyObject* add = Py_True;
00180 if (!PyArg_ParseTuple(args, "d|idO!", &U, &M, &tol, &PyBool_Type, &add))
00181 return 0;
00182
00183 try {
00184 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00185 (getGeometryPtr()->handle());
00186 curve->InsertKnot(U,M,tol,(add==Py_True));
00187 }
00188 catch (Standard_Failure) {
00189 Handle_Standard_Failure e = Standard_Failure::Caught();
00190 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00191 return 0;
00192 }
00193
00194 Py_Return;
00195 }
00196
00197 PyObject* BSplineCurvePy::insertKnots(PyObject * args)
00198 {
00199 double tol = 0.0;
00200 PyObject* add = Py_True;
00201 PyObject* obj1;
00202 PyObject* obj2;
00203 if (!PyArg_ParseTuple(args, "O!O!|dO!", &PyList_Type, &obj1,
00204 &PyList_Type, &obj2,
00205 &tol, &PyBool_Type, &add))
00206 return 0;
00207
00208 try {
00209 Py::List knots(obj1);
00210 TColStd_Array1OfReal k(1,knots.size());
00211 int index=1;
00212 for (Py::List::iterator it = knots.begin(); it != knots.end(); ++it) {
00213 Py::Float val(*it);
00214 k(index++) = (double)val;
00215 }
00216 Py::List mults(obj2);
00217 TColStd_Array1OfInteger m(1,mults.size());
00218 index=1;
00219 for (Py::List::iterator it = mults.begin(); it != mults.end(); ++it) {
00220 Py::Int val(*it);
00221 m(index++) = (int)val;
00222 }
00223
00224 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00225 (getGeometryPtr()->handle());
00226 curve->InsertKnots(k,m,tol,(add==Py_True));
00227 Py_Return;
00228 }
00229 catch (Standard_Failure) {
00230 Handle_Standard_Failure e = Standard_Failure::Caught();
00231 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00232 return 0;
00233 }
00234
00235 Py_Return;
00236 }
00237
00238 PyObject* BSplineCurvePy::removeKnot(PyObject * args)
00239 {
00240 double tol;
00241 int Index,M;
00242 if (!PyArg_ParseTuple(args, "iid", &Index, &M, &tol))
00243 return 0;
00244
00245 try {
00246 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00247 (getGeometryPtr()->handle());
00248 Standard_Boolean ok = curve->RemoveKnot(Index,M,tol);
00249 if (ok) {
00250 Py_INCREF(Py_True);
00251 return Py_True;
00252 }
00253 else {
00254 Py_INCREF(Py_False);
00255 return Py_False;
00256 }
00257 }
00258 catch (Standard_Failure) {
00259 Handle_Standard_Failure e = Standard_Failure::Caught();
00260 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00261 return 0;
00262 }
00263 }
00264
00265 PyObject* BSplineCurvePy::segment(PyObject * args)
00266 {
00267 double u1,u2;
00268 if (!PyArg_ParseTuple(args, "dd", &u1,&u2))
00269 return 0;
00270 try {
00271 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00272 (getGeometryPtr()->handle());
00273 curve->Segment(u1,u2);
00274 Py_Return;
00275 }
00276 catch (Standard_Failure) {
00277 Handle_Standard_Failure e = Standard_Failure::Caught();
00278 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00279 return 0;
00280 }
00281 }
00282
00283 PyObject* BSplineCurvePy::setKnot(PyObject * args)
00284 {
00285 int Index, M=-1;
00286 double K;
00287 if (!PyArg_ParseTuple(args, "id|i", &Index, &K, &M))
00288 return 0;
00289
00290 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00291 (getGeometryPtr()->handle());
00292 if (M == -1) {
00293 curve->SetKnot(Index, K);
00294 }
00295 else {
00296 curve->SetKnot(Index, K, M);
00297 }
00298
00299 Py_Return;
00300 }
00301
00302 PyObject* BSplineCurvePy::getKnot(PyObject * args)
00303 {
00304 int Index;
00305 if (!PyArg_ParseTuple(args, "i", &Index))
00306 return 0;
00307
00308 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00309 (getGeometryPtr()->handle());
00310 double M = curve->Knot(Index);
00311
00312 return Py_BuildValue("d",M);
00313 }
00314
00315 PyObject* BSplineCurvePy::setKnots(PyObject * args)
00316 {
00317 PyObject* obj;
00318 if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &obj))
00319 return 0;
00320 try {
00321 Py::List list(obj);
00322 TColStd_Array1OfReal k(1,list.size());
00323 int index=1;
00324 for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00325 Py::Float val(*it);
00326 k(index++) = (double)val;
00327 }
00328
00329 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00330 (getGeometryPtr()->handle());
00331 curve->SetKnots(k);
00332 Py_Return;
00333 }
00334 catch (Standard_Failure) {
00335 Handle_Standard_Failure e = Standard_Failure::Caught();
00336 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00337 return 0;
00338 }
00339 }
00340
00341 PyObject* BSplineCurvePy::getKnots(PyObject * args)
00342 {
00343 if (!PyArg_ParseTuple(args, ""))
00344 return 0;
00345 try {
00346 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00347 (getGeometryPtr()->handle());
00348 TColStd_Array1OfReal w(1,curve->NbKnots());
00349 curve->Knots(w);
00350 Py::List knots;
00351 for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) {
00352 knots.append(Py::Float(w(i)));
00353 }
00354 return Py::new_reference_to(knots);
00355 }
00356 catch (Standard_Failure) {
00357 Handle_Standard_Failure e = Standard_Failure::Caught();
00358 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00359 return 0;
00360 }
00361 }
00362
00363 PyObject* BSplineCurvePy::setPole(PyObject * args)
00364 {
00365 int index;
00366 double weight=-1.0;
00367 PyObject* p;
00368 if (!PyArg_ParseTuple(args, "iO!|d", &index, &(Base::VectorPy::Type), &p, &weight))
00369 return 0;
00370 Base::Vector3d vec = static_cast<Base::VectorPy*>(p)->value();
00371 gp_Pnt pnt(vec.x, vec.y, vec.z);
00372 try {
00373 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00374 (getGeometryPtr()->handle());
00375 if (weight < 0.0)
00376 curve->SetPole(index,pnt);
00377 else
00378 curve->SetPole(index,pnt,weight);
00379 Py_Return;
00380 }
00381 catch (Standard_Failure) {
00382 Handle_Standard_Failure e = Standard_Failure::Caught();
00383 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00384 return 0;
00385 }
00386 }
00387
00388 PyObject* BSplineCurvePy::getPole(PyObject * args)
00389 {
00390 int index;
00391 if (!PyArg_ParseTuple(args, "i", &index))
00392 return 0;
00393 try {
00394 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00395 (getGeometryPtr()->handle());
00396 gp_Pnt pnt = curve->Pole(index);
00397 Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d(
00398 pnt.X(), pnt.Y(), pnt.Z()));
00399 return vec;
00400 }
00401 catch (Standard_Failure) {
00402 Handle_Standard_Failure e = Standard_Failure::Caught();
00403 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00404 return 0;
00405 }
00406 }
00407
00408 PyObject* BSplineCurvePy::getPoles(PyObject * args)
00409 {
00410 if (!PyArg_ParseTuple(args, ""))
00411 return 0;
00412 try {
00413 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00414 (getGeometryPtr()->handle());
00415 TColgp_Array1OfPnt p(1,curve->NbPoles());
00416 curve->Poles(p);
00417 Py::List poles;
00418 for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) {
00419 gp_Pnt pnt = p(i);
00420 Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d(
00421 pnt.X(), pnt.Y(), pnt.Z()));
00422 poles.append(Py::Object(vec));
00423 }
00424 return Py::new_reference_to(poles);
00425 }
00426 catch (Standard_Failure) {
00427 Handle_Standard_Failure e = Standard_Failure::Caught();
00428 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00429 return 0;
00430 }
00431 }
00432
00433 PyObject* BSplineCurvePy::setWeight(PyObject * args)
00434 {
00435 int index;
00436 double weight;
00437 if (!PyArg_ParseTuple(args, "id", &index,&weight))
00438 return 0;
00439 try {
00440 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00441 (getGeometryPtr()->handle());
00442 curve->SetWeight(index,weight);
00443 Py_Return;
00444 }
00445 catch (Standard_Failure) {
00446 Handle_Standard_Failure e = Standard_Failure::Caught();
00447 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00448 return 0;
00449 }
00450 }
00451
00452 PyObject* BSplineCurvePy::getWeight(PyObject * args)
00453 {
00454 int index;
00455 if (!PyArg_ParseTuple(args, "i", &index))
00456 return 0;
00457 try {
00458 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00459 (getGeometryPtr()->handle());
00460 double weight = curve->Weight(index);
00461 return Py_BuildValue("d", weight);
00462 }
00463 catch (Standard_Failure) {
00464 Handle_Standard_Failure e = Standard_Failure::Caught();
00465 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00466 return 0;
00467 }
00468 }
00469
00470 PyObject* BSplineCurvePy::getWeights(PyObject * args)
00471 {
00472 if (!PyArg_ParseTuple(args, ""))
00473 return 0;
00474 try {
00475 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00476 (getGeometryPtr()->handle());
00477 TColStd_Array1OfReal w(1,curve->NbPoles());
00478 curve->Weights(w);
00479 Py::List weights;
00480 for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) {
00481 weights.append(Py::Float(w(i)));
00482 }
00483 return Py::new_reference_to(weights);
00484 }
00485 catch (Standard_Failure) {
00486 Handle_Standard_Failure e = Standard_Failure::Caught();
00487 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00488 return 0;
00489 }
00490 }
00491
00492 PyObject* BSplineCurvePy::getResolution(PyObject * args)
00493 {
00494 double tol;
00495 if (!PyArg_ParseTuple(args, "d", &tol))
00496 return 0;
00497 try {
00498 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00499 (getGeometryPtr()->handle());
00500 double utol;
00501 curve->Resolution(tol,utol);
00502 return Py_BuildValue("d",utol);
00503 }
00504 catch (Standard_Failure) {
00505 Handle_Standard_Failure e = Standard_Failure::Caught();
00506 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00507 return 0;
00508 }
00509 }
00510
00511 PyObject* BSplineCurvePy::movePoint(PyObject * args)
00512 {
00513 double U;
00514 int index1, index2;
00515 PyObject* pnt;
00516 if (!PyArg_ParseTuple(args, "dO!ii", &U, &(Base::VectorPy::Type),&pnt, &index1, &index2))
00517 return 0;
00518 try {
00519 Base::Vector3d p = static_cast<Base::VectorPy*>(pnt)->value();
00520 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00521 (getGeometryPtr()->handle());
00522 int first, last;
00523 curve->MovePoint(U, gp_Pnt(p.x,p.y,p.z), index1, index2, first, last);
00524 return Py_BuildValue("(ii)",first, last);
00525 }
00526 catch (Standard_Failure) {
00527 Handle_Standard_Failure e = Standard_Failure::Caught();
00528 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00529 return 0;
00530 }
00531 }
00532
00533 PyObject* BSplineCurvePy::setNotPeriodic(PyObject * args)
00534 {
00535 if (!PyArg_ParseTuple(args, ""))
00536 return 0;
00537 try {
00538 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00539 (getGeometryPtr()->handle());
00540 curve->SetNotPeriodic();
00541 Py_Return;
00542 }
00543 catch (Standard_Failure) {
00544 Handle_Standard_Failure e = Standard_Failure::Caught();
00545 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00546 return 0;
00547 }
00548 }
00549
00550 PyObject* BSplineCurvePy::setPeriodic(PyObject * args)
00551 {
00552 if (!PyArg_ParseTuple(args, ""))
00553 return 0;
00554 try {
00555 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00556 (getGeometryPtr()->handle());
00557 curve->SetPeriodic();
00558 Py_Return;
00559 }
00560 catch (Standard_Failure) {
00561 Handle_Standard_Failure e = Standard_Failure::Caught();
00562 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00563 return 0;
00564 }
00565 }
00566
00567 PyObject* BSplineCurvePy::setOrigin(PyObject * args)
00568 {
00569 int index;
00570 if (!PyArg_ParseTuple(args, "i", &index))
00571 return 0;
00572 try {
00573 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00574 (getGeometryPtr()->handle());
00575 curve->SetOrigin(index);
00576 Py_Return;
00577 }
00578 catch (Standard_Failure) {
00579 Handle_Standard_Failure e = Standard_Failure::Caught();
00580 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00581 return 0;
00582 }
00583 }
00584
00585 PyObject* BSplineCurvePy::getMultiplicity(PyObject * args)
00586 {
00587 int index;
00588 if (!PyArg_ParseTuple(args, "i", &index))
00589 return 0;
00590 try {
00591 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00592 (getGeometryPtr()->handle());
00593 int mult = curve->Multiplicity(index);
00594 return Py_BuildValue("i", mult);
00595 }
00596 catch (Standard_Failure) {
00597 Handle_Standard_Failure e = Standard_Failure::Caught();
00598 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00599 return 0;
00600 }
00601 }
00602
00603 PyObject* BSplineCurvePy::getMultiplicities(PyObject * args)
00604 {
00605 if (!PyArg_ParseTuple(args, ""))
00606 return 0;
00607 try {
00608 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00609 (getGeometryPtr()->handle());
00610 TColStd_Array1OfInteger m(1,curve->NbKnots());
00611 curve->Multiplicities(m);
00612 Py::List mults;
00613 for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) {
00614 mults.append(Py::Int(m(i)));
00615 }
00616 return Py::new_reference_to(mults);
00617 }
00618 catch (Standard_Failure) {
00619 Handle_Standard_Failure e = Standard_Failure::Caught();
00620 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00621 return 0;
00622 }
00623 }
00624
00625 Py::Int BSplineCurvePy::getDegree(void) const
00626 {
00627 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00628 (getGeometryPtr()->handle());
00629 return Py::Int(curve->Degree());
00630 }
00631
00632 Py::Int BSplineCurvePy::getMaxDegree(void) const
00633 {
00634 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00635 (getGeometryPtr()->handle());
00636 return Py::Int(curve->MaxDegree());
00637 }
00638
00639 Py::Int BSplineCurvePy::getNbPoles(void) const
00640 {
00641 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00642 (getGeometryPtr()->handle());
00643 return Py::Int(curve->NbPoles());
00644 }
00645
00646 Py::Int BSplineCurvePy::getNbKnots(void) const
00647 {
00648 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00649 (getGeometryPtr()->handle());
00650 return Py::Int(curve->NbKnots());
00651 }
00652
00653 Py::Object BSplineCurvePy::getStartPoint(void) const
00654 {
00655 Handle_Geom_BSplineCurve c = Handle_Geom_BSplineCurve::DownCast
00656 (getGeometryPtr()->handle());
00657 gp_Pnt pnt = c->StartPoint();
00658 return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
00659 }
00660
00661 Py::Object BSplineCurvePy::getEndPoint(void) const
00662 {
00663 Handle_Geom_BSplineCurve c = Handle_Geom_BSplineCurve::DownCast
00664 (getGeometryPtr()->handle());
00665 gp_Pnt pnt = c->EndPoint();
00666 return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z()));
00667 }
00668
00669 Py::Object BSplineCurvePy::getFirstUKnotIndex(void) const
00670 {
00671 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00672 (getGeometryPtr()->handle());
00673 return Py::Int(curve->FirstUKnotIndex());
00674 }
00675
00676 Py::Object BSplineCurvePy::getLastUKnotIndex(void) const
00677 {
00678 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00679 (getGeometryPtr()->handle());
00680 return Py::Int(curve->LastUKnotIndex());
00681 }
00682
00683 Py::List BSplineCurvePy::getKnotSequence(void) const
00684 {
00685 Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast
00686 (getGeometryPtr()->handle());
00687 Standard_Integer m = 0;
00688 for (int i=1; i<= curve->NbKnots(); i++)
00689 m += curve->Multiplicity(i);
00690 TColStd_Array1OfReal k(1,m);
00691 curve->KnotSequence(k);
00692 Py::List list;
00693 for (Standard_Integer i=k.Lower(); i<=k.Upper(); i++) {
00694 list.append(Py::Float(k(i)));
00695 }
00696 return list;
00697 }
00698
00699 PyObject* BSplineCurvePy::approximate(PyObject *args)
00700 {
00701 PyObject* obj;
00702 if (!PyArg_ParseTuple(args, "O!",&(PyList_Type), &obj))
00703 return 0;
00704 try {
00705 Py::List list(obj);
00706 TColgp_Array1OfPnt pnts(1,list.size());
00707 Standard_Integer index = 1;
00708 for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00709 Base::Vector3d vec = Py::Vector(*it).toVector();
00710 pnts(index++) = gp_Pnt(vec.x,vec.y,vec.z);
00711 }
00712
00713 GeomAPI_PointsToBSpline fit(pnts);
00714 Handle_Geom_BSplineCurve spline = fit.Curve();
00715 if (!spline.IsNull()) {
00716 this->getGeomBSplineCurvePtr()->setHandle(spline);
00717 Py_Return;
00718 }
00719 else {
00720 Standard_Failure::Raise("failed to approximate points");
00721 return 0;
00722 }
00723 }
00724 catch (Standard_Failure) {
00725 Handle_Standard_Failure e = Standard_Failure::Caught();
00726 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00727 return 0;
00728 }
00729 }
00730
00731 PyObject* BSplineCurvePy::interpolate(PyObject *args)
00732 {
00733 PyObject* obj;
00734 double tol3d = Precision::Approximation();
00735 PyObject* closed = Py_False;
00736 PyObject* t1=0; PyObject* t2=0;
00737 if (!PyArg_ParseTuple(args, "O!|O!dO!O!",&(PyList_Type), &obj, &PyBool_Type, &closed, &tol3d,
00738 &Base::VectorPy::Type, &t1, &Base::VectorPy::Type, &t2))
00739 return 0;
00740 try {
00741 Py::List list(obj);
00742 Handle_TColgp_HArray1OfPnt interpolationPoints = new TColgp_HArray1OfPnt(1, list.size());
00743 Standard_Integer index = 1;
00744 for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00745 Py::Vector v(*it);
00746 Base::Vector3d pnt = v.toVector();
00747 interpolationPoints->SetValue(index++, gp_Pnt(pnt.x,pnt.y,pnt.z));
00748 }
00749
00750 if (interpolationPoints->Length() < 2) {
00751 Standard_Failure::Raise("not enough points given");
00752 }
00753
00754 GeomAPI_Interpolate aBSplineInterpolation(interpolationPoints, (closed == Py_True), tol3d);
00755 if (t1 && t2) {
00756 Base::Vector3d v1 = Py::Vector(t1,false).toVector();
00757 Base::Vector3d v2 = Py::Vector(t1,false).toVector();
00758 gp_Vec initTangent(v1.x,v1.y,v1.z), finalTangent(v2.x,v2.y,v2.z);
00759 aBSplineInterpolation.Load(initTangent, finalTangent);
00760 }
00761 aBSplineInterpolation.Perform();
00762 if (aBSplineInterpolation.IsDone()) {
00763 Handle_Geom_BSplineCurve aBSplineCurve(aBSplineInterpolation.Curve());
00764 this->getGeomBSplineCurvePtr()->setHandle(aBSplineCurve);
00765 Py_Return;
00766 }
00767 else {
00768 Standard_Failure::Raise("failed to interpolate points");
00769 return 0;
00770 }
00771 }
00772 catch (Standard_Failure) {
00773 Handle_Standard_Failure e = Standard_Failure::Caught();
00774 std::string err = e->GetMessageString();
00775 if (err.empty()) err = e->DynamicType()->Name();
00776 PyErr_SetString(PyExc_Exception, err.c_str());
00777 return 0;
00778 }
00779 }
00780
00781 PyObject* BSplineCurvePy::buildFromPoles(PyObject *args)
00782 {
00783 PyObject* obj;
00784 int degree = 3;
00785 PyObject* closed = Py_False;
00786 if (!PyArg_ParseTuple(args, "O!|O!i",&(PyList_Type), &obj, &PyBool_Type, &closed, °ree))
00787 return 0;
00788 try {
00789 Py::List list(obj);
00790 TColgp_Array1OfPnt poles(1, list.size());
00791 Standard_Integer index = 1;
00792 for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00793 Py::Vector v(*it);
00794 Base::Vector3d pnt = v.toVector();
00795 poles(index++) = gp_Pnt(pnt.x,pnt.y,pnt.z);
00796 }
00797
00798 if (poles.Length() <= degree)
00799 degree = poles.Length()-1;
00800
00801 TColStd_Array1OfReal knots(1, poles.Length()+degree+1-2*(degree));
00802 TColStd_Array1OfInteger mults(1, poles.Length()+degree+1-2*(degree));
00803 for (int i=1; i<=knots.Length(); i++){
00804 knots.SetValue(i,(double)(i-1)/(knots.Length()-1));
00805 mults.SetValue(i,1);
00806 }
00807 mults.SetValue(1, degree+1);
00808 mults.SetValue(knots.Length(), degree+1);
00809
00810 Handle_Geom_BSplineCurve spline = new Geom_BSplineCurve(poles, knots, mults, degree, (closed == Py_True));
00811 if (!spline.IsNull()) {
00812 this->getGeomBSplineCurvePtr()->setHandle(spline);
00813 Py_Return;
00814 }
00815 else {
00816 Standard_Failure::Raise("failed to create spline");
00817 return 0;
00818 }
00819 }
00820 catch (Standard_Failure) {
00821 Handle_Standard_Failure e = Standard_Failure::Caught();
00822 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00823 return 0;
00824 }
00825 }
00826
00827 PyObject* BSplineCurvePy::toBezier(PyObject *args)
00828 {
00829 if (!PyArg_ParseTuple(args, ""))
00830 return 0;
00831
00832 Handle_Geom_BSplineCurve spline = Handle_Geom_BSplineCurve::DownCast
00833 (this->getGeomBSplineCurvePtr()->handle());
00834 GeomConvert_BSplineCurveToBezierCurve crt(spline);
00835
00836 Py::List list;
00837 Standard_Integer arcs = crt.NbArcs();
00838 for (Standard_Integer i=1; i<=arcs; i++) {
00839 Handle_Geom_BezierCurve bezier = crt.Arc(i);
00840 list.append(Py::asObject(new BezierCurvePy(new GeomBezierCurve(bezier))));
00841 }
00842
00843 return Py::new_reference_to(list);
00844 }
00845
00846 PyObject* BSplineCurvePy::join(PyObject *args)
00847 {
00848 PyObject* c;
00849 if (!PyArg_ParseTuple(args, "O!", &BSplineCurvePy::Type, &c))
00850 return 0;
00851
00852 GeomBSplineCurve* curve1 = this->getGeomBSplineCurvePtr();
00853 BSplineCurvePy* curve2 = static_cast<BSplineCurvePy*>(c);
00854 Handle_Geom_BSplineCurve spline = Handle_Geom_BSplineCurve::DownCast
00855 (curve2->getGeomBSplineCurvePtr()->handle());
00856
00857 bool ok = curve1->join(spline);
00858
00859 if (ok) {
00860 Py_INCREF(Py_True);
00861 return Py_True;
00862 }
00863 else {
00864 Py_INCREF(Py_False);
00865 return Py_False;
00866 }
00867 }
00868
00869 PyObject* BSplineCurvePy::makeC1Continuous(PyObject *args)
00870 {
00871 double tol = Precision::Approximation();
00872 double ang_tol = 1.0e-7;
00873 if (!PyArg_ParseTuple(args, "|dd", &tol, &ang_tol))
00874 return 0;
00875
00876 try {
00877 GeomBSplineCurve* spline = this->getGeomBSplineCurvePtr();
00878 spline->makeC1Continuous(tol, ang_tol);
00879 Py_Return;
00880 }
00881 catch (Standard_Failure) {
00882 Handle_Standard_Failure e = Standard_Failure::Caught();
00883 std::string err = e->GetMessageString();
00884 if (err.empty()) err = e->DynamicType()->Name();
00885 PyErr_SetString(PyExc_Exception, err.c_str());
00886 return 0;
00887 }
00888 }
00889
00890 PyObject* BSplineCurvePy::getCustomAttributes(const char* ) const
00891 {
00892 return 0;
00893 }
00894
00895 int BSplineCurvePy::setCustomAttributes(const char* , PyObject* )
00896 {
00897 return 0;
00898 }