1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 #include <structmember.h>
29 #include <Standard_Stream.hxx>
31 #include <GEOMImpl_ICurvesOperations.hxx>
33 #include <TColStd_HArray1OfReal.hxx>
35 #include <GEOM_Function.hxx>
36 #include <GEOM_PythonDump.hxx>
38 #include <GEOMImpl_Types.hxx>
40 #include <GEOMImpl_PolylineDriver.hxx>
41 #include <GEOMImpl_CircleDriver.hxx>
42 #include <GEOMImpl_SplineDriver.hxx>
43 #include <GEOMImpl_EllipseDriver.hxx>
44 #include <GEOMImpl_ArcDriver.hxx>
45 #include <GEOMImpl_SketcherDriver.hxx>
46 #include <GEOMImpl_3DSketcherDriver.hxx>
48 #include <GEOMImpl_IPolyline.hxx>
49 #include <GEOMImpl_ICircle.hxx>
50 #include <GEOMImpl_ISpline.hxx>
51 #include <GEOMImpl_IEllipse.hxx>
52 #include <GEOMImpl_IArc.hxx>
53 #include <GEOMImpl_ISketcher.hxx>
54 #include <GEOMImpl_I3DSketcher.hxx>
56 #include "utilities.h"
58 #include <TDF_Tool.hxx>
60 #include <Standard_Failure.hxx>
61 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
64 /* ==================================
65 * =========== PYTHON ==============
66 * ==================================*/
75 PyStdOut_dealloc(PyStdOut *self)
81 PyStdOut_write(PyStdOut *self, PyObject *args)
85 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
89 *(self->out)=*(self->out)+c;
95 static PyMethodDef PyStdOut_methods[] = {
96 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
97 PyDoc_STR("write(string) -> None")},
98 {NULL, NULL} /* sentinel */
101 static PyMemberDef PyStdOut_memberlist[] = {
102 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
103 (char*)"flag indicating that a space needs to be printed; used by print"},
104 {NULL} /* Sentinel */
107 static PyTypeObject PyStdOut_Type = {
108 /* The ob_type field must be initialized in the module init function
109 * to be portable to Windows without using C++. */
110 PyObject_HEAD_INIT(NULL)
113 sizeof(PyStdOut), /*tp_basicsize*/
116 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
123 0, /*tp_as_sequence*/
128 PyObject_GenericGetAttr, /*tp_getattro*/
129 /* softspace is writable: we must supply tp_setattro */
130 PyObject_GenericSetAttr, /* tp_setattro */
132 Py_TPFLAGS_DEFAULT, /*tp_flags*/
136 0, /*tp_richcompare*/
137 0, /*tp_weaklistoffset*/
140 PyStdOut_methods, /*tp_methods*/
141 PyStdOut_memberlist, /*tp_members*/
155 PyObject * newPyStdOut( std::string& out )
158 self = PyObject_New(PyStdOut, &PyStdOut_Type);
163 return (PyObject*)self;
167 ////////////////////////END PYTHON///////////////////////////
168 //=============================================================================
172 //=============================================================================
173 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
174 : GEOM_IOperations(theEngine, theDocID)
176 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
179 //=============================================================================
183 //=============================================================================
184 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
186 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
190 //=============================================================================
194 //=============================================================================
195 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
196 Handle(GEOM_Object) thePnt2,
197 Handle(GEOM_Object) thePnt3)
201 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
203 //Add a new Circle object
204 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
206 //Add a new Circle function for creation a circle relatively to three points
207 Handle(GEOM_Function) aFunction =
208 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
209 if (aFunction.IsNull()) return NULL;
211 //Check if the function is set correctly
212 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
214 GEOMImpl_ICircle aCI (aFunction);
216 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
217 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
218 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
220 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
222 aCI.SetPoint1(aRefPnt1);
223 aCI.SetPoint2(aRefPnt2);
224 aCI.SetPoint3(aRefPnt3);
226 //Compute the Circle value
228 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
231 if (!GetSolver()->ComputeFunction(aFunction)) {
232 SetErrorCode("Circle driver failed");
236 catch (Standard_Failure) {
237 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
238 SetErrorCode(aFail->GetMessageString());
242 //Make a Python command
243 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
244 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
250 //=============================================================================
252 * MakeCircleCenter2Pnt
254 //=============================================================================
255 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
256 Handle(GEOM_Object) thePnt2,
257 Handle(GEOM_Object) thePnt3)
261 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
263 //Add a new Circle object
264 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
266 //Add a new Circle function for creation a circle relatively to center and 2 points
267 Handle(GEOM_Function) aFunction =
268 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
269 if (aFunction.IsNull()) return NULL;
271 //Check if the function is set correctly
272 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
274 GEOMImpl_ICircle aCI (aFunction);
276 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
277 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
278 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
280 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
282 aCI.SetPoint1(aRefPnt1);
283 aCI.SetPoint2(aRefPnt2);
284 aCI.SetPoint3(aRefPnt3);
286 //Compute the Circle value
288 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
291 if (!GetSolver()->ComputeFunction(aFunction)) {
292 SetErrorCode("Circle driver failed");
296 catch (Standard_Failure) {
297 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
298 SetErrorCode(aFail->GetMessageString());
302 //Make a Python command
303 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
304 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
310 //=============================================================================
314 //=============================================================================
315 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
316 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
320 // Not set thePnt means origin of global CS,
321 // Not set theVec means Z axis of global CS
322 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
324 //Add a new Circle object
325 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
327 //Add a new Circle function for creation a circle relatively to point and vector
328 Handle(GEOM_Function) aFunction =
329 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
330 if (aFunction.IsNull()) return NULL;
332 //Check if the function is set correctly
333 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
335 GEOMImpl_ICircle aCI (aFunction);
337 if (!thePnt.IsNull()) {
338 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
339 if (aRefPnt.IsNull()) return NULL;
340 aCI.SetCenter(aRefPnt);
343 if (!theVec.IsNull()) {
344 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
345 if (aRefVec.IsNull()) return NULL;
346 aCI.SetVector(aRefVec);
351 //Compute the Circle value
353 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
356 if (!GetSolver()->ComputeFunction(aFunction)) {
357 SetErrorCode("Circle driver failed");
361 catch (Standard_Failure) {
362 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
363 SetErrorCode(aFail->GetMessageString());
367 //Make a Python command
368 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
369 << thePnt << ", " << theVec << ", " << theR << ")";
375 //=============================================================================
379 //=============================================================================
380 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
381 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
382 double theRMajor, double theRMinor,
383 Handle(GEOM_Object) theVecMaj)
387 // Not set thePnt means origin of global CS,
388 // Not set theVec means Z axis of global CS
389 // Not set theVecMaj means X axis of global CS
390 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
392 //Add a new Ellipse object
393 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
395 //Add a new Ellipse function
396 Handle(GEOM_Function) aFunction =
397 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
398 if (aFunction.IsNull()) return NULL;
400 //Check if the function is set correctly
401 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
403 GEOMImpl_IEllipse aCI (aFunction);
405 if (!thePnt.IsNull()) {
406 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
407 if (aRefPnt.IsNull()) return NULL;
408 aCI.SetCenter(aRefPnt);
411 if (!theVec.IsNull()) {
412 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
413 if (aRefVec.IsNull()) return NULL;
414 aCI.SetVector(aRefVec);
417 aCI.SetRMajor(theRMajor);
418 aCI.SetRMinor(theRMinor);
420 if (!theVecMaj.IsNull()) {
421 Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
422 if (aRefVecMaj.IsNull()) return NULL;
423 aCI.SetVectorMajor(aRefVecMaj);
426 //Compute the Ellipse value
428 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
431 if (!GetSolver()->ComputeFunction(aFunction)) {
432 SetErrorCode("Ellipse driver failed");
436 catch (Standard_Failure) {
437 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
438 SetErrorCode(aFail->GetMessageString());
442 //Make a Python command
443 if (!theVecMaj.IsNull()) {
444 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
445 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
446 << ", " << theVecMaj << ")";
449 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
450 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
457 //=============================================================================
461 //=============================================================================
462 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
463 Handle(GEOM_Object) thePnt2,
464 Handle(GEOM_Object) thePnt3)
468 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
470 //Add a new Circle Arc object
471 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
473 //Add a new Circle Arc function
474 Handle(GEOM_Function) aFunction =
475 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
477 if (aFunction.IsNull()) return NULL;
479 //Check if the function is set correctly
480 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
481 GEOMImpl_IArc aCI (aFunction);
483 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
484 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
485 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
488 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
490 aCI.SetPoint1(aRefPnt1);
491 aCI.SetPoint2(aRefPnt2);
492 aCI.SetPoint3(aRefPnt3);
494 //Compute the Arc value
496 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
499 if (!GetSolver()->ComputeFunction(aFunction)) {
500 SetErrorCode("Arc driver failed");
504 catch (Standard_Failure) {
505 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
506 SetErrorCode(aFail->GetMessageString());
510 //Make a Python command
511 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
512 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
518 //=============================================================================
522 //=============================================================================
523 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
524 Handle(GEOM_Object) thePnt2,
525 Handle(GEOM_Object) thePnt3,
529 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
531 //Add a new Circle Arc object
532 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
534 //Add a new Circle Arc function
535 Handle(GEOM_Function) aFunction =
536 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
537 if (aFunction.IsNull()) return NULL;
539 //Check if the function is set correctly
540 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
542 GEOMImpl_IArc aCI (aFunction);
544 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
545 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
546 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
548 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
550 aCI.SetPoint1(aRefPnt1);
551 aCI.SetPoint2(aRefPnt2);
552 aCI.SetPoint3(aRefPnt3);
553 aCI.SetSense(theSense);
555 //Compute the Arc value
557 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
560 if (!GetSolver()->ComputeFunction(aFunction)) {
561 SetErrorCode("Arc driver failed");
565 catch (Standard_Failure) {
566 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
567 SetErrorCode(aFail->GetMessageString());
570 //Make a Python command
571 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
572 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
578 //=============================================================================
582 //=============================================================================
583 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
584 Handle(GEOM_Object) thePnt2,
585 Handle(GEOM_Object) thePnt3)
589 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
591 //Add a new Circle Arc object
592 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
594 //Add a new Circle Arc function
595 Handle(GEOM_Function) aFunction =
596 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
598 if (aFunction.IsNull()) return NULL;
600 //Check if the function is set correctly
601 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
602 GEOMImpl_IArc aCI (aFunction);
604 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
605 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
606 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
609 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
611 aCI.SetPoint1(aRefPnt1);
612 aCI.SetPoint2(aRefPnt2);
613 aCI.SetPoint3(aRefPnt3);
615 //Compute the Arc value
617 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
620 if (!GetSolver()->ComputeFunction(aFunction)) {
621 SetErrorCode("Arc driver failed");
625 catch (Standard_Failure) {
626 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
627 SetErrorCode(aFail->GetMessageString());
631 //Make a Python command
632 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
633 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
639 //=============================================================================
643 //=============================================================================
644 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
649 //Add a new Polyline object
650 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
652 //Add a new Polyline function for creation a polyline relatively to points set
653 Handle(GEOM_Function) aFunction =
654 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
655 if (aFunction.IsNull()) return NULL;
657 //Check if the function is set correctly
658 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
660 GEOMImpl_IPolyline aCI (aFunction);
662 int aLen = thePoints.size();
664 aCI.SetConstructorType(POINT_CONSTRUCTOR);
667 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
668 for (; it != thePoints.end(); it++, ind++) {
669 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
670 if (aRefPnt.IsNull()) {
671 SetErrorCode("NULL point for Polyline");
674 aCI.SetPoint(ind, aRefPnt);
677 aCI.SetIsClosed(theIsClosed);
679 //Compute the Polyline value
681 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
684 if (!GetSolver()->ComputeFunction(aFunction)) {
685 SetErrorCode("Polyline driver failed");
689 catch (Standard_Failure) {
690 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
691 SetErrorCode(aFail->GetMessageString());
695 //Make a Python command
696 GEOM::TPythonDump pd (aFunction);
697 pd << aPolyline << " = geompy.MakePolyline([";
699 it = thePoints.begin();
701 while (it != thePoints.end()) {
702 pd << ", " << (*it++);
704 pd << "], " << theIsClosed << ")";
710 //=============================================================================
714 //=============================================================================
715 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
716 (std::list<Handle(GEOM_Object)> thePoints,
721 //Add a new Spline object
722 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
724 //Add a new Spline function for creation a bezier curve relatively to points set
725 Handle(GEOM_Function) aFunction =
726 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
727 if (aFunction.IsNull()) return NULL;
729 //Check if the function is set correctly
730 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
732 GEOMImpl_ISpline aCI (aFunction);
734 int aLen = thePoints.size();
736 aCI.SetConstructorType(POINT_CONSTRUCTOR);
739 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
740 for (; it != thePoints.end(); it++, ind++) {
741 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
743 if (aRefPnt.IsNull()) return NULL;
745 aCI.SetPoint(ind, aRefPnt);
748 aCI.SetIsClosed(theIsClosed);
750 //Compute the Spline value
752 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
755 if (!GetSolver()->ComputeFunction(aFunction)) {
756 SetErrorCode("Spline driver failed");
760 catch (Standard_Failure) {
761 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
762 SetErrorCode(aFail->GetMessageString());
766 //Make a Python command
767 GEOM::TPythonDump pd (aFunction);
768 pd << aSpline << " = geompy.MakeBezier([";
770 it = thePoints.begin();
772 while (it != thePoints.end()) {
773 pd << ", " << (*it++);
775 pd << "], " << theIsClosed << ")";
781 //=============================================================================
783 * MakeSplineInterpolation
785 //=============================================================================
786 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
787 (std::list<Handle(GEOM_Object)> thePoints,
789 bool theDoReordering)
793 //Add a new Spline object
794 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
796 //Add a new Spline function for creation a bezier curve relatively to points set
797 Handle(GEOM_Function) aFunction =
798 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
799 if (aFunction.IsNull()) return NULL;
801 //Check if the function is set correctly
802 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
804 GEOMImpl_ISpline aCI (aFunction);
806 int aLen = thePoints.size();
807 aCI.SetConstructorType(POINT_CONSTRUCTOR);
811 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
812 for (; it != thePoints.end(); it++, ind++) {
813 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
815 if (aRefPnt.IsNull()) return NULL;
817 aCI.SetPoint(ind, aRefPnt);
820 aCI.SetIsClosed(theIsClosed);
821 aCI.SetDoReordering(theDoReordering);
823 //Compute the Spline value
825 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
828 if (!GetSolver()->ComputeFunction(aFunction)) {
829 SetErrorCode("Spline driver failed");
833 catch (Standard_Failure) {
834 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
835 SetErrorCode(aFail->GetMessageString());
839 //Make a Python command
840 GEOM::TPythonDump pd (aFunction);
841 pd << aSpline << " = geompy.MakeInterpol([";
843 it = thePoints.begin();
845 while (it != thePoints.end()) {
846 pd << ", " << (*it++);
848 pd << "], " << theIsClosed << ", " << theDoReordering << ")";
854 //=============================================================================
856 * MakeCurveParametric
858 //=============================================================================
859 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr,
860 double theParamMin, double theParamMax, double theParamStep,
861 CurveType theCurveType) {
862 TCollection_AsciiString aPyScript;
863 aPyScript +="from math import * \n";
864 aPyScript +="def X(t): \n";
865 aPyScript +=" return ";
866 aPyScript += thexExpr;
868 aPyScript +="def Y(t): \n";
869 aPyScript +=" return ";
870 aPyScript += theyExpr;
873 aPyScript +="def Z(t): \n";
874 aPyScript +=" return ";
875 aPyScript += thezExpr;
878 aPyScript +="def coordCalucator(tmin, tmax, tstep): \n";
879 aPyScript +=" coords = [] \n";
880 aPyScript +=" while tmin <= tmax : \n";
881 aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
882 aPyScript +=" tmin = tmin + tstep \n";
883 aPyScript +=" return coords \n";
887 if(theParamMin >= theParamMax) {
888 SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
892 if(theParamStep <= 0.0 ) {
893 SetErrorCode("Value of the step must be positive !!!");
897 /* Initialize the Python interpreter */
898 if (! Py_IsInitialized()) {
899 SetErrorCode("Python interpreter is not initialized !!! ");
903 PyGILState_STATE gstate;
904 gstate = PyGILState_Ensure();
906 PyObject* main_mod = PyImport_AddModule("__main__");
907 PyObject* main_dict = PyModule_GetDict(main_mod);
909 PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
912 SetErrorCode("Error during run python script !!!");
913 PyGILState_Release(gstate);
919 PyObject * func = NULL;
920 func = PyObject_GetAttrString(main_mod, "coordCalucator");
923 SetErrorCode("Can't get function from python module !!!");
924 PyGILState_Release(gstate);
928 PyObject* coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
929 PyObject* new_stderr = NULL;
933 std::string err_description="";
934 new_stderr = newPyStdOut(err_description);
935 PySys_SetObject((char*)"stderr", new_stderr);
937 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
938 Py_DECREF(new_stderr);
939 MESSAGE("Can't evaluate coordCalucator()" << " error is " << err_description);
940 SetErrorCode("Can't evaluate the expressions, please check them !!!");
941 PyGILState_Release(gstate);
945 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, PyList_Size( coords ) * 3);
947 if(PyList_Size( coords ) <= 0) {
948 SetErrorCode("Empty list of the points, please check input parameters !!!");
953 for ( Py_ssize_t i = 0; i< PyList_Size( coords ); ++i ) {
954 PyObject* coord = PyList_GetItem( coords, i );
956 for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
957 PyObject* item = PyList_GetItem(coord, j);
958 aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
968 PyGILState_Release(gstate);
970 Handle(GEOM_Object) aCurve;
971 Handle(GEOM_Function) aFunction;
972 TCollection_AsciiString aCurveType;
974 switch(theCurveType) {
976 //Add a new Polyline object
977 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
979 //Add a new Polyline function for creation a polyline relatively to points set
980 aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
981 if (aFunction.IsNull()) return NULL;
983 //Check if the function is set correctly
984 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
986 GEOMImpl_IPolyline aCI (aFunction);
988 aCI.SetLength(PyList_Size( coords ));
989 aCI.SetConstructorType(COORD_CONSTRUCTOR);
990 aCI.SetIsClosed(false);
991 aCI.SetCoordinates(aCoordsArray);
992 aCurveType = "geompy.GEOM.Polyline";
996 //Add a new Spline object
997 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
998 //Add a new Spline function for creation a bezier curve relatively to points set
1000 aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
1001 if (aFunction.IsNull()) return NULL;
1003 //Check if the function is set correctly
1004 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1006 GEOMImpl_ISpline aCI (aFunction);
1008 aCI.SetLength(PyList_Size( coords ));
1009 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1010 aCI.SetIsClosed(false);
1011 aCI.SetCoordinates(aCoordsArray);
1012 aCurveType = "geompy.GEOM.Bezier";
1015 case Interpolation: {
1016 //Add a new Spline object
1017 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1019 //Add a new Spline function for creation a bezier curve relatively to points set
1020 aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
1021 if (aFunction.IsNull()) return NULL;
1023 //Check if the function is set correctly
1024 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1026 GEOMImpl_ISpline aCI (aFunction);
1027 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1028 aCI.SetLength(PyList_Size( coords ));
1029 aCI.SetIsClosed(false);
1030 aCI.SetDoReordering(false);
1031 aCI.SetCoordinates(aCoordsArray);
1032 aCurveType = "geompy.GEOM.Interpolation";
1037 //Compute the Curve value
1039 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1042 if (!GetSolver()->ComputeFunction(aFunction)) {
1043 SetErrorCode("Curve driver failed !!!");
1047 catch (Standard_Failure) {
1048 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1049 SetErrorCode(aFail->GetMessageString());
1053 //Make a Python command
1054 GEOM::TPythonDump pd (aFunction);
1055 pd << aCurve << " = geompy.MakeCurveParametric(";
1056 pd << "\"" << thexExpr << "\", ";
1057 pd << "\"" << theyExpr << "\", ";
1058 pd << "\"" << thezExpr << "\", ";
1060 pd << theParamMin <<", ";
1061 pd << theParamMax <<", ";
1062 pd << theParamStep <<", ";
1063 pd << aCurveType.ToCString() <<")";
1069 //=============================================================================
1073 //=============================================================================
1074 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1075 std::list<double> theWorkingPlane)
1079 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1081 //Add a new Sketcher object
1082 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1084 //Add a new Sketcher function
1085 Handle(GEOM_Function) aFunction =
1086 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1087 if (aFunction.IsNull()) return NULL;
1089 //Check if the function is set correctly
1090 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1092 GEOMImpl_ISketcher aCI (aFunction);
1094 TCollection_AsciiString aCommand((char*) theCommand);
1095 aCI.SetCommand(aCommand);
1098 std::list<double>::iterator it = theWorkingPlane.begin();
1099 for (; it != theWorkingPlane.end(); it++, ind++)
1100 aCI.SetWorkingPlane(ind, *it);
1102 //Compute the Sketcher value
1104 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1107 if (!GetSolver()->ComputeFunction(aFunction)) {
1108 SetErrorCode("Sketcher driver failed");
1112 catch (Standard_Failure) {
1113 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1114 SetErrorCode(aFail->GetMessageString());
1118 //Make a Python command
1119 GEOM::TPythonDump pd (aFunction);
1120 pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1122 it = theWorkingPlane.begin();
1124 while (it != theWorkingPlane.end()) {
1125 pd << ", " << (*it++);
1133 //=============================================================================
1137 //=============================================================================
1138 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1142 //Add a new Sketcher object
1143 Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1145 //Add a new Sketcher function
1146 Handle(GEOM_Function) aFunction =
1147 a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
1148 if (aFunction.IsNull()) return NULL;
1150 //Check if the function is set correctly
1151 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1153 GEOMImpl_I3DSketcher aCI (aFunction);
1156 std::list<double>::iterator it = theCoordinates.begin();
1157 for (; it != theCoordinates.end(); it++)
1160 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1162 it = theCoordinates.begin();
1164 for (; it != theCoordinates.end(); it++, ind++)
1165 aCoordsArray->SetValue(ind, *it);
1167 aCI.SetCoordinates(aCoordsArray);
1169 //Compute the Sketcher value
1171 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1174 if (!GetSolver()->ComputeFunction(aFunction)) {
1175 SetErrorCode("3D Sketcher driver failed");
1179 catch (Standard_Failure) {
1180 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1181 SetErrorCode(aFail->GetMessageString());
1185 //Make a Python command
1186 GEOM::TPythonDump pd (aFunction);
1187 pd << a3DSketcher << " = geompy.Make3DSketcher([";
1189 it = theCoordinates.begin();
1191 while (it != theCoordinates.end()) {
1192 pd << ", " << (*it++);
1200 //=============================================================================
1202 * MakeSketcherOnPlane
1204 //=============================================================================
1205 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1206 (const char* theCommand,
1207 Handle(GEOM_Object) theWorkingPlane)
1211 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1213 //Add a new Sketcher object
1214 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1216 //Add a new Sketcher function
1217 Handle(GEOM_Function) aFunction =
1218 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1219 if (aFunction.IsNull()) return NULL;
1221 //Check if the function is set correctly
1222 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1224 GEOMImpl_ISketcher aCI (aFunction);
1226 TCollection_AsciiString aCommand((char*) theCommand);
1227 aCI.SetCommand(aCommand);
1229 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1230 if (aRefPlane.IsNull()) return NULL;
1231 aCI.SetWorkingPlane( aRefPlane );
1233 //Compute the Sketcher value
1235 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1238 if (!GetSolver()->ComputeFunction(aFunction)) {
1239 SetErrorCode("Sketcher driver failed");
1243 catch (Standard_Failure) {
1244 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1245 SetErrorCode(aFail->GetMessageString());
1249 //Make a Python command
1250 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1251 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";