1 // Copyright (C) 2007-2010 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
23 #include <structmember.h>
28 #include <Standard_Stream.hxx>
30 #include <GEOMImpl_ICurvesOperations.hxx>
32 #include <TColStd_HArray1OfReal.hxx>
34 #include <GEOM_Function.hxx>
35 #include <GEOM_PythonDump.hxx>
37 #include <GEOMImpl_Types.hxx>
39 #include <GEOMImpl_PolylineDriver.hxx>
40 #include <GEOMImpl_CircleDriver.hxx>
41 #include <GEOMImpl_SplineDriver.hxx>
42 #include <GEOMImpl_EllipseDriver.hxx>
43 #include <GEOMImpl_ArcDriver.hxx>
44 #include <GEOMImpl_SketcherDriver.hxx>
45 #include <GEOMImpl_3DSketcherDriver.hxx>
47 #include <GEOMImpl_IPolyline.hxx>
48 #include <GEOMImpl_ICircle.hxx>
49 #include <GEOMImpl_ISpline.hxx>
50 #include <GEOMImpl_IEllipse.hxx>
51 #include <GEOMImpl_IArc.hxx>
52 #include <GEOMImpl_ISketcher.hxx>
53 #include <GEOMImpl_I3DSketcher.hxx>
55 #include "utilities.h"
57 #include <TDF_Tool.hxx>
59 #include <Standard_Failure.hxx>
60 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
63 /* ==================================
64 * =========== PYTHON ==============
65 * ==================================*/
74 PyStdOut_dealloc(PyStdOut *self)
80 PyStdOut_write(PyStdOut *self, PyObject *args)
84 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
88 *(self->out)=*(self->out)+c;
94 static PyMethodDef PyStdOut_methods[] = {
95 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
96 PyDoc_STR("write(string) -> None")},
97 {NULL, NULL} /* sentinel */
100 static PyMemberDef PyStdOut_memberlist[] = {
101 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
102 (char*)"flag indicating that a space needs to be printed; used by print"},
103 {NULL} /* Sentinel */
106 static PyTypeObject PyStdOut_Type = {
107 /* The ob_type field must be initialized in the module init function
108 * to be portable to Windows without using C++. */
109 PyObject_HEAD_INIT(NULL)
112 sizeof(PyStdOut), /*tp_basicsize*/
115 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
122 0, /*tp_as_sequence*/
127 PyObject_GenericGetAttr, /*tp_getattro*/
128 /* softspace is writable: we must supply tp_setattro */
129 PyObject_GenericSetAttr, /* tp_setattro */
131 Py_TPFLAGS_DEFAULT, /*tp_flags*/
135 0, /*tp_richcompare*/
136 0, /*tp_weaklistoffset*/
139 PyStdOut_methods, /*tp_methods*/
140 PyStdOut_memberlist, /*tp_members*/
154 PyObject * newPyStdOut( std::string& out )
157 self = PyObject_New(PyStdOut, &PyStdOut_Type);
162 return (PyObject*)self;
166 ////////////////////////END PYTHON///////////////////////////
167 //=============================================================================
171 //=============================================================================
172 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
173 : GEOM_IOperations(theEngine, theDocID)
175 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
178 //=============================================================================
182 //=============================================================================
183 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
185 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
189 //=============================================================================
193 //=============================================================================
194 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
195 Handle(GEOM_Object) thePnt2,
196 Handle(GEOM_Object) thePnt3)
200 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
202 //Add a new Circle object
203 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
205 //Add a new Circle function for creation a circle relatively to three points
206 Handle(GEOM_Function) aFunction =
207 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
208 if (aFunction.IsNull()) return NULL;
210 //Check if the function is set correctly
211 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
213 GEOMImpl_ICircle aCI (aFunction);
215 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
216 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
217 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
219 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
221 aCI.SetPoint1(aRefPnt1);
222 aCI.SetPoint2(aRefPnt2);
223 aCI.SetPoint3(aRefPnt3);
225 //Compute the Circle value
227 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
230 if (!GetSolver()->ComputeFunction(aFunction)) {
231 SetErrorCode("Circle driver failed");
235 catch (Standard_Failure) {
236 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
237 SetErrorCode(aFail->GetMessageString());
241 //Make a Python command
242 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
243 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
249 //=============================================================================
251 * MakeCircleCenter2Pnt
253 //=============================================================================
254 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
255 Handle(GEOM_Object) thePnt2,
256 Handle(GEOM_Object) thePnt3)
260 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
262 //Add a new Circle object
263 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
265 //Add a new Circle function for creation a circle relatively to center and 2 points
266 Handle(GEOM_Function) aFunction =
267 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
268 if (aFunction.IsNull()) return NULL;
270 //Check if the function is set correctly
271 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
273 GEOMImpl_ICircle aCI (aFunction);
275 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
276 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
277 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
279 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
281 aCI.SetPoint1(aRefPnt1);
282 aCI.SetPoint2(aRefPnt2);
283 aCI.SetPoint3(aRefPnt3);
285 //Compute the Circle value
287 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
290 if (!GetSolver()->ComputeFunction(aFunction)) {
291 SetErrorCode("Circle driver failed");
295 catch (Standard_Failure) {
296 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
297 SetErrorCode(aFail->GetMessageString());
301 //Make a Python command
302 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
303 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
309 //=============================================================================
313 //=============================================================================
314 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
315 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
319 // Not set thePnt means origin of global CS,
320 // Not set theVec means Z axis of global CS
321 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
323 //Add a new Circle object
324 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
326 //Add a new Circle function for creation a circle relatively to point and vector
327 Handle(GEOM_Function) aFunction =
328 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
329 if (aFunction.IsNull()) return NULL;
331 //Check if the function is set correctly
332 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
334 GEOMImpl_ICircle aCI (aFunction);
336 if (!thePnt.IsNull()) {
337 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
338 if (aRefPnt.IsNull()) return NULL;
339 aCI.SetCenter(aRefPnt);
342 if (!theVec.IsNull()) {
343 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
344 if (aRefVec.IsNull()) return NULL;
345 aCI.SetVector(aRefVec);
350 //Compute the Circle value
352 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
355 if (!GetSolver()->ComputeFunction(aFunction)) {
356 SetErrorCode("Circle driver failed");
360 catch (Standard_Failure) {
361 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
362 SetErrorCode(aFail->GetMessageString());
366 //Make a Python command
367 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
368 << thePnt << ", " << theVec << ", " << theR << ")";
374 //=============================================================================
378 //=============================================================================
379 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
380 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
381 double theRMajor, double theRMinor,
382 Handle(GEOM_Object) theVecMaj)
386 // Not set thePnt means origin of global CS,
387 // Not set theVec means Z axis of global CS
388 // Not set theVecMaj means X axis of global CS
389 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
391 //Add a new Ellipse object
392 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
394 //Add a new Ellipse function
395 Handle(GEOM_Function) aFunction =
396 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
397 if (aFunction.IsNull()) return NULL;
399 //Check if the function is set correctly
400 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
402 GEOMImpl_IEllipse aCI (aFunction);
404 if (!thePnt.IsNull()) {
405 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
406 if (aRefPnt.IsNull()) return NULL;
407 aCI.SetCenter(aRefPnt);
410 if (!theVec.IsNull()) {
411 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
412 if (aRefVec.IsNull()) return NULL;
413 aCI.SetVector(aRefVec);
416 aCI.SetRMajor(theRMajor);
417 aCI.SetRMinor(theRMinor);
419 if (!theVecMaj.IsNull()) {
420 Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
421 if (aRefVecMaj.IsNull()) return NULL;
422 aCI.SetVectorMajor(aRefVecMaj);
425 //Compute the Ellipse value
427 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
430 if (!GetSolver()->ComputeFunction(aFunction)) {
431 SetErrorCode("Ellipse driver failed");
435 catch (Standard_Failure) {
436 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
437 SetErrorCode(aFail->GetMessageString());
441 //Make a Python command
442 if (!theVecMaj.IsNull()) {
443 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
444 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
445 << ", " << theVecMaj << ")";
448 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
449 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
456 //=============================================================================
460 //=============================================================================
461 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
462 Handle(GEOM_Object) thePnt2,
463 Handle(GEOM_Object) thePnt3)
467 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
469 //Add a new Circle Arc object
470 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
472 //Add a new Circle Arc function
473 Handle(GEOM_Function) aFunction =
474 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
476 if (aFunction.IsNull()) return NULL;
478 //Check if the function is set correctly
479 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
480 GEOMImpl_IArc aCI (aFunction);
482 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
483 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
484 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
487 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
489 aCI.SetPoint1(aRefPnt1);
490 aCI.SetPoint2(aRefPnt2);
491 aCI.SetPoint3(aRefPnt3);
493 //Compute the Arc value
495 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
498 if (!GetSolver()->ComputeFunction(aFunction)) {
499 SetErrorCode("Arc driver failed");
503 catch (Standard_Failure) {
504 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
505 SetErrorCode(aFail->GetMessageString());
509 //Make a Python command
510 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
511 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
517 //=============================================================================
521 //=============================================================================
522 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
523 Handle(GEOM_Object) thePnt2,
524 Handle(GEOM_Object) thePnt3,
528 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
530 //Add a new Circle Arc object
531 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
533 //Add a new Circle Arc function
534 Handle(GEOM_Function) aFunction =
535 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
536 if (aFunction.IsNull()) return NULL;
538 //Check if the function is set correctly
539 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
541 GEOMImpl_IArc aCI (aFunction);
543 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
544 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
545 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
547 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
549 aCI.SetPoint1(aRefPnt1);
550 aCI.SetPoint2(aRefPnt2);
551 aCI.SetPoint3(aRefPnt3);
552 aCI.SetSense(theSense);
554 //Compute the Arc value
556 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
559 if (!GetSolver()->ComputeFunction(aFunction)) {
560 SetErrorCode("Arc driver failed");
564 catch (Standard_Failure) {
565 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
566 SetErrorCode(aFail->GetMessageString());
569 //Make a Python command
570 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
571 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
577 //=============================================================================
581 //=============================================================================
582 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
583 Handle(GEOM_Object) thePnt2,
584 Handle(GEOM_Object) thePnt3)
588 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
590 //Add a new Circle Arc object
591 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
593 //Add a new Circle Arc function
594 Handle(GEOM_Function) aFunction =
595 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
597 if (aFunction.IsNull()) return NULL;
599 //Check if the function is set correctly
600 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
601 GEOMImpl_IArc aCI (aFunction);
603 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
604 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
605 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
608 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
610 aCI.SetPoint1(aRefPnt1);
611 aCI.SetPoint2(aRefPnt2);
612 aCI.SetPoint3(aRefPnt3);
614 //Compute the Arc value
616 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
619 if (!GetSolver()->ComputeFunction(aFunction)) {
620 SetErrorCode("Arc driver failed");
624 catch (Standard_Failure) {
625 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
626 SetErrorCode(aFail->GetMessageString());
630 //Make a Python command
631 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
632 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
638 //=============================================================================
642 //=============================================================================
643 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
648 //Add a new Polyline object
649 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
651 //Add a new Polyline function for creation a polyline relatively to points set
652 Handle(GEOM_Function) aFunction =
653 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
654 if (aFunction.IsNull()) return NULL;
656 //Check if the function is set correctly
657 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
659 GEOMImpl_IPolyline aCI (aFunction);
661 int aLen = thePoints.size();
663 aCI.SetConstructorType(POINT_CONSTRUCTOR);
666 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
667 for (; it != thePoints.end(); it++, ind++) {
668 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
669 if (aRefPnt.IsNull()) {
670 SetErrorCode("NULL point for Polyline");
673 aCI.SetPoint(ind, aRefPnt);
676 aCI.SetIsClosed(theIsClosed);
678 //Compute the Polyline value
680 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
683 if (!GetSolver()->ComputeFunction(aFunction)) {
684 SetErrorCode("Polyline driver failed");
688 catch (Standard_Failure) {
689 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
690 SetErrorCode(aFail->GetMessageString());
694 //Make a Python command
695 GEOM::TPythonDump pd (aFunction);
696 pd << aPolyline << " = geompy.MakePolyline([";
698 it = thePoints.begin();
700 while (it != thePoints.end()) {
701 pd << ", " << (*it++);
703 pd << "], " << theIsClosed << ")";
709 //=============================================================================
713 //=============================================================================
714 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
715 (std::list<Handle(GEOM_Object)> thePoints,
720 //Add a new Spline object
721 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
723 //Add a new Spline function for creation a bezier curve relatively to points set
724 Handle(GEOM_Function) aFunction =
725 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
726 if (aFunction.IsNull()) return NULL;
728 //Check if the function is set correctly
729 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
731 GEOMImpl_ISpline aCI (aFunction);
733 int aLen = thePoints.size();
735 aCI.SetConstructorType(POINT_CONSTRUCTOR);
738 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
739 for (; it != thePoints.end(); it++, ind++) {
740 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
742 if (aRefPnt.IsNull()) return NULL;
744 aCI.SetPoint(ind, aRefPnt);
747 aCI.SetIsClosed(theIsClosed);
749 //Compute the Spline value
751 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
754 if (!GetSolver()->ComputeFunction(aFunction)) {
755 SetErrorCode("Spline driver failed");
759 catch (Standard_Failure) {
760 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
761 SetErrorCode(aFail->GetMessageString());
765 //Make a Python command
766 GEOM::TPythonDump pd (aFunction);
767 pd << aSpline << " = geompy.MakeBezier([";
769 it = thePoints.begin();
771 while (it != thePoints.end()) {
772 pd << ", " << (*it++);
774 pd << "], " << theIsClosed << ")";
780 //=============================================================================
782 * MakeSplineInterpolation
784 //=============================================================================
785 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
786 (std::list<Handle(GEOM_Object)> thePoints,
788 bool theDoReordering)
792 //Add a new Spline object
793 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
795 //Add a new Spline function for creation a bezier curve relatively to points set
796 Handle(GEOM_Function) aFunction =
797 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
798 if (aFunction.IsNull()) return NULL;
800 //Check if the function is set correctly
801 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
803 GEOMImpl_ISpline aCI (aFunction);
805 int aLen = thePoints.size();
806 aCI.SetConstructorType(POINT_CONSTRUCTOR);
810 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
811 for (; it != thePoints.end(); it++, ind++) {
812 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
814 if (aRefPnt.IsNull()) return NULL;
816 aCI.SetPoint(ind, aRefPnt);
819 aCI.SetIsClosed(theIsClosed);
820 aCI.SetDoReordering(theDoReordering);
822 //Compute the Spline value
824 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
827 if (!GetSolver()->ComputeFunction(aFunction)) {
828 SetErrorCode("Spline driver failed");
832 catch (Standard_Failure) {
833 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
834 SetErrorCode(aFail->GetMessageString());
838 //Make a Python command
839 GEOM::TPythonDump pd (aFunction);
840 pd << aSpline << " = geompy.MakeInterpol([";
842 it = thePoints.begin();
844 while (it != thePoints.end()) {
845 pd << ", " << (*it++);
847 pd << "], " << theIsClosed << ", " << theDoReordering << ")";
853 //=============================================================================
855 * MakeCurveParametric
857 //=============================================================================
858 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr,
859 double theParamMin, double theParamMax, double theParamStep,
860 CurveType theCurveType) {
861 TCollection_AsciiString aPyScript;
862 aPyScript +="from math import * \n";
863 aPyScript +="def X(t): \n";
864 aPyScript +=" return ";
865 aPyScript += thexExpr;
867 aPyScript +="def Y(t): \n";
868 aPyScript +=" return ";
869 aPyScript += theyExpr;
872 aPyScript +="def Z(t): \n";
873 aPyScript +=" return ";
874 aPyScript += thezExpr;
877 aPyScript +="def coordCalucator(tmin, tmax, tstep): \n";
878 aPyScript +=" coords = [] \n";
879 aPyScript +=" while tmin <= tmax : \n";
880 aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
881 aPyScript +=" tmin = tmin + tstep \n";
882 aPyScript +=" return coords \n";
886 if(theParamMin >= theParamMax) {
887 SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
891 if(theParamStep <= 0.0 ) {
892 SetErrorCode("Value of the step must be positive !!!");
896 /* Initialize the Python interpreter */
897 if (! Py_IsInitialized()) {
898 SetErrorCode("Python interpreter is not initialized !!! ");
902 PyGILState_STATE gstate;
903 gstate = PyGILState_Ensure();
905 PyObject* main_mod = PyImport_AddModule("__main__");
906 PyObject* main_dict = PyModule_GetDict(main_mod);
908 PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
911 SetErrorCode("Error during run python script !!!");
912 PyGILState_Release(gstate);
918 PyObject * func = NULL;
919 func = PyObject_GetAttrString(main_mod, "coordCalucator");
922 SetErrorCode("Can't get function from python module !!!");
923 PyGILState_Release(gstate);
927 PyObject* coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
928 PyObject* new_stderr = NULL;
932 std::string err_description="";
933 new_stderr = newPyStdOut(err_description);
934 PySys_SetObject((char*)"stderr", new_stderr);
936 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
937 Py_DECREF(new_stderr);
938 MESSAGE("Can't evaluate coordCalucator()" << " error is " << err_description);
939 SetErrorCode("Can't evaluate the expressions, please check them !!!");
940 PyGILState_Release(gstate);
944 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, PyList_Size( coords ) * 3);
946 if(PyList_Size( coords ) <= 0) {
947 SetErrorCode("Empty list of the points, please check input parameters !!!");
952 for ( Py_ssize_t i = 0; i< PyList_Size( coords ); ++i ) {
953 PyObject* coord = PyList_GetItem( coords, i );
955 for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
956 PyObject* item = PyList_GetItem(coord, j);
957 aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
967 PyGILState_Release(gstate);
969 Handle(GEOM_Object) aCurve;
970 Handle(GEOM_Function) aFunction;
971 TCollection_AsciiString aCurveType;
973 switch(theCurveType) {
975 //Add a new Polyline object
976 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
978 //Add a new Polyline function for creation a polyline relatively to points set
979 aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
980 if (aFunction.IsNull()) return NULL;
982 //Check if the function is set correctly
983 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
985 GEOMImpl_IPolyline aCI (aFunction);
987 aCI.SetLength(PyList_Size( coords ));
988 aCI.SetConstructorType(COORD_CONSTRUCTOR);
989 aCI.SetIsClosed(false);
990 aCI.SetCoordinates(aCoordsArray);
991 aCurveType = "geompy.GEOM.Polyline";
995 //Add a new Spline object
996 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
997 //Add a new Spline function for creation a bezier curve relatively to points set
999 aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
1000 if (aFunction.IsNull()) return NULL;
1002 //Check if the function is set correctly
1003 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1005 GEOMImpl_ISpline aCI (aFunction);
1007 aCI.SetLength(PyList_Size( coords ));
1008 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1009 aCI.SetIsClosed(false);
1010 aCI.SetCoordinates(aCoordsArray);
1011 aCurveType = "geompy.GEOM.Bezier";
1014 case Interpolation: {
1015 //Add a new Spline object
1016 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1018 //Add a new Spline function for creation a bezier curve relatively to points set
1019 aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
1020 if (aFunction.IsNull()) return NULL;
1022 //Check if the function is set correctly
1023 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1025 GEOMImpl_ISpline aCI (aFunction);
1026 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1027 aCI.SetLength(PyList_Size( coords ));
1028 aCI.SetIsClosed(false);
1029 aCI.SetDoReordering(false);
1030 aCI.SetCoordinates(aCoordsArray);
1031 aCurveType = "geompy.GEOM.Interpolation";
1036 //Compute the Curve value
1038 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1041 if (!GetSolver()->ComputeFunction(aFunction)) {
1042 SetErrorCode("Curve driver failed !!!");
1046 catch (Standard_Failure) {
1047 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1048 SetErrorCode(aFail->GetMessageString());
1052 //Make a Python command
1053 GEOM::TPythonDump pd (aFunction);
1054 pd << aCurve << " = geompy.MakeCurveParametric(";
1055 pd << "\"" << thexExpr << "\", ";
1056 pd << "\"" << theyExpr << "\", ";
1057 pd << "\"" << thezExpr << "\", ";
1059 pd << theParamMin <<", ";
1060 pd << theParamMax <<", ";
1061 pd << theParamStep <<", ";
1062 pd << aCurveType.ToCString() <<")";
1068 //=============================================================================
1072 //=============================================================================
1073 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1074 std::list<double> theWorkingPlane)
1078 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1080 //Add a new Sketcher object
1081 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1083 //Add a new Sketcher function
1084 Handle(GEOM_Function) aFunction =
1085 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1086 if (aFunction.IsNull()) return NULL;
1088 //Check if the function is set correctly
1089 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1091 GEOMImpl_ISketcher aCI (aFunction);
1093 TCollection_AsciiString aCommand((char*) theCommand);
1094 aCI.SetCommand(aCommand);
1097 std::list<double>::iterator it = theWorkingPlane.begin();
1098 for (; it != theWorkingPlane.end(); it++, ind++)
1099 aCI.SetWorkingPlane(ind, *it);
1101 //Compute the Sketcher value
1103 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1106 if (!GetSolver()->ComputeFunction(aFunction)) {
1107 SetErrorCode("Sketcher driver failed");
1111 catch (Standard_Failure) {
1112 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1113 SetErrorCode(aFail->GetMessageString());
1117 //Make a Python command
1118 GEOM::TPythonDump pd (aFunction);
1119 pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1121 it = theWorkingPlane.begin();
1123 while (it != theWorkingPlane.end()) {
1124 pd << ", " << (*it++);
1132 //=============================================================================
1136 //=============================================================================
1137 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1141 //Add a new Sketcher object
1142 Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1144 //Add a new Sketcher function
1145 Handle(GEOM_Function) aFunction =
1146 a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
1147 if (aFunction.IsNull()) return NULL;
1149 //Check if the function is set correctly
1150 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1152 GEOMImpl_I3DSketcher aCI (aFunction);
1155 std::list<double>::iterator it = theCoordinates.begin();
1156 for (; it != theCoordinates.end(); it++)
1159 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1161 it = theCoordinates.begin();
1163 for (; it != theCoordinates.end(); it++, ind++)
1164 aCoordsArray->SetValue(ind, *it);
1166 aCI.SetCoordinates(aCoordsArray);
1168 //Compute the Sketcher value
1170 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1173 if (!GetSolver()->ComputeFunction(aFunction)) {
1174 SetErrorCode("3D Sketcher driver failed");
1178 catch (Standard_Failure) {
1179 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1180 SetErrorCode(aFail->GetMessageString());
1184 //Make a Python command
1185 GEOM::TPythonDump pd (aFunction);
1186 pd << a3DSketcher << " = geompy.Make3DSketcher([";
1188 it = theCoordinates.begin();
1190 while (it != theCoordinates.end()) {
1191 pd << ", " << (*it++);
1199 //=============================================================================
1201 * MakeSketcherOnPlane
1203 //=============================================================================
1204 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1205 (const char* theCommand,
1206 Handle(GEOM_Object) theWorkingPlane)
1210 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1212 //Add a new Sketcher object
1213 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1215 //Add a new Sketcher function
1216 Handle(GEOM_Function) aFunction =
1217 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1218 if (aFunction.IsNull()) return NULL;
1220 //Check if the function is set correctly
1221 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1223 GEOMImpl_ISketcher aCI (aFunction);
1225 TCollection_AsciiString aCommand((char*) theCommand);
1226 aCI.SetCommand(aCommand);
1228 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1229 if (aRefPlane.IsNull()) return NULL;
1230 aCI.SetWorkingPlane( aRefPlane );
1232 //Compute the Sketcher value
1234 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1237 if (!GetSolver()->ComputeFunction(aFunction)) {
1238 SetErrorCode("Sketcher driver failed");
1242 catch (Standard_Failure) {
1243 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1244 SetErrorCode(aFail->GetMessageString());
1248 //Make a Python command
1249 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1250 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";