1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 // E.A. : On windows with python 2.6, there is a conflict
25 // E.A. : between pymath.h and Standard_math.h which define
26 // E.A. : some same symbols : acosh, asinh, ...
27 #include <Standard_math.hxx>
32 #include <structmember.h>
38 #include "GEOMImpl_ICurvesOperations.hxx"
39 #include "GEOMImpl_Types.hxx"
41 #include "GEOM_Function.hxx"
42 #include "GEOM_PythonDump.hxx"
44 #include "GEOMImpl_PolylineDriver.hxx"
45 #include "GEOMImpl_CircleDriver.hxx"
46 #include "GEOMImpl_SplineDriver.hxx"
47 #include "GEOMImpl_EllipseDriver.hxx"
48 #include "GEOMImpl_ArcDriver.hxx"
49 #include "GEOMImpl_ShapeDriver.hxx"
50 #include "GEOMImpl_SketcherDriver.hxx"
51 #include "GEOMImpl_3DSketcherDriver.hxx"
53 #include "GEOMImpl_IPolyline.hxx"
54 #include "GEOMImpl_IPolyline2D.hxx"
55 #include "GEOMImpl_ICircle.hxx"
56 #include "GEOMImpl_ISpline.hxx"
57 #include "GEOMImpl_IEllipse.hxx"
58 #include "GEOMImpl_IArc.hxx"
59 #include "GEOMImpl_ISketcher.hxx"
60 #include "GEOMImpl_I3DSketcher.hxx"
61 #include "GEOMImpl_ICurveParametric.hxx"
62 #include "GEOMImpl_IIsoline.hxx"
63 #include "GEOMImpl_PolylineDumper.hxx"
65 #include "utilities.h"
67 #include <TDF_Tool.hxx>
68 #include <TColStd_HArray1OfByte.hxx>
69 #include <TColStd_HArray1OfReal.hxx>
71 #include <Standard_Failure.hxx>
72 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
75 /* ==================================
76 * =========== PYTHON ==============
77 * ==================================*/
88 PyStdOut_dealloc(PyStdOut *self)
94 PyStdOut_write(PyStdOut* self, PyObject* args)
98 if (!PyArg_ParseTuple(args, "t#:write", &c, &l))
101 *(self->out) = *(self->out) + c;
107 static PyMethodDef PyStdOut_methods[] = {
108 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
109 PyDoc_STR("write(string) -> None")},
110 {NULL, NULL} /* sentinel */
113 static PyMemberDef PyStdOut_memberlist[] = {
114 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
115 (char*)"flag indicating that a space needs to be printed; used by print"},
116 {NULL} /* Sentinel */
119 static PyTypeObject PyStdOut_Type = {
120 /* The ob_type field must be initialized in the module init function
121 * to be portable to Windows without using C++. */
122 PyObject_HEAD_INIT(NULL)
125 sizeof(PyStdOut), /*tp_basicsize*/
128 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
135 0, /*tp_as_sequence*/
140 PyObject_GenericGetAttr, /*tp_getattro*/
141 /* softspace is writable: we must supply tp_setattro */
142 PyObject_GenericSetAttr, /* tp_setattro */
144 Py_TPFLAGS_DEFAULT, /*tp_flags*/
148 0, /*tp_richcompare*/
149 0, /*tp_weaklistoffset*/
152 PyStdOut_methods, /*tp_methods*/
153 PyStdOut_memberlist, /*tp_members*/
167 PyObject* newPyStdOut( std::string& out )
169 PyStdOut* self = PyObject_New(PyStdOut, &PyStdOut_Type);
174 return (PyObject*)self;
178 ////////////////////////END PYTHON///////////////////////////
179 //=============================================================================
183 //=============================================================================
184 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
185 : GEOM_IOperations(theEngine, theDocID)
187 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
190 //=============================================================================
194 //=============================================================================
195 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
197 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
201 //=============================================================================
205 //=============================================================================
206 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
207 Handle(GEOM_Object) thePnt2,
208 Handle(GEOM_Object) thePnt3)
212 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
214 //Add a new Circle object
215 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
217 //Add a new Circle function for creation a circle relatively to three points
218 Handle(GEOM_Function) aFunction =
219 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
220 if (aFunction.IsNull()) return NULL;
222 //Check if the function is set correctly
223 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
225 GEOMImpl_ICircle aCI (aFunction);
227 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
228 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
229 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
231 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
233 aCI.SetPoint1(aRefPnt1);
234 aCI.SetPoint2(aRefPnt2);
235 aCI.SetPoint3(aRefPnt3);
237 //Compute the Circle value
240 if (!GetSolver()->ComputeFunction(aFunction)) {
241 SetErrorCode("Circle driver failed");
245 catch (Standard_Failure) {
246 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
247 SetErrorCode(aFail->GetMessageString());
251 //Make a Python command
252 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
253 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
259 //=============================================================================
261 * MakeCircleCenter2Pnt
263 //=============================================================================
264 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
265 Handle(GEOM_Object) thePnt2,
266 Handle(GEOM_Object) thePnt3)
270 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
272 //Add a new Circle object
273 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
275 //Add a new Circle function for creation a circle relatively to center and 2 points
276 Handle(GEOM_Function) aFunction =
277 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
278 if (aFunction.IsNull()) return NULL;
280 //Check if the function is set correctly
281 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
283 GEOMImpl_ICircle aCI (aFunction);
285 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
286 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
287 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
289 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
291 aCI.SetPoint1(aRefPnt1);
292 aCI.SetPoint2(aRefPnt2);
293 aCI.SetPoint3(aRefPnt3);
295 //Compute the Circle value
298 if (!GetSolver()->ComputeFunction(aFunction)) {
299 SetErrorCode("Circle driver failed");
303 catch (Standard_Failure) {
304 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
305 SetErrorCode(aFail->GetMessageString());
309 //Make a Python command
310 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
311 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
317 //=============================================================================
321 //=============================================================================
322 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
323 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
327 // Not set thePnt means origin of global CS,
328 // Not set theVec means Z axis of global CS
329 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
331 //Add a new Circle object
332 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
334 //Add a new Circle function for creation a circle relatively to point and vector
335 Handle(GEOM_Function) aFunction =
336 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
337 if (aFunction.IsNull()) return NULL;
339 //Check if the function is set correctly
340 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
342 GEOMImpl_ICircle aCI (aFunction);
344 if (!thePnt.IsNull()) {
345 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
346 if (aRefPnt.IsNull()) return NULL;
347 aCI.SetCenter(aRefPnt);
350 if (!theVec.IsNull()) {
351 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
352 if (aRefVec.IsNull()) return NULL;
353 aCI.SetVector(aRefVec);
358 //Compute the Circle value
361 if (!GetSolver()->ComputeFunction(aFunction)) {
362 SetErrorCode("Circle driver failed");
366 catch (Standard_Failure) {
367 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
368 SetErrorCode(aFail->GetMessageString());
372 //Make a Python command
373 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
374 << thePnt << ", " << theVec << ", " << theR << ")";
380 //=============================================================================
384 //=============================================================================
385 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
386 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
387 double theRMajor, double theRMinor,
388 Handle(GEOM_Object) theVecMaj)
392 // Not set thePnt means origin of global CS,
393 // Not set theVec means Z axis of global CS
394 // Not set theVecMaj means X axis of global CS
395 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
397 //Add a new Ellipse object
398 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
400 //Add a new Ellipse function
401 Handle(GEOM_Function) aFunction =
402 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
403 if (aFunction.IsNull()) return NULL;
405 //Check if the function is set correctly
406 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
408 GEOMImpl_IEllipse aCI (aFunction);
410 if (!thePnt.IsNull()) {
411 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
412 if (aRefPnt.IsNull()) return NULL;
413 aCI.SetCenter(aRefPnt);
416 if (!theVec.IsNull()) {
417 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
418 if (aRefVec.IsNull()) return NULL;
419 aCI.SetVector(aRefVec);
422 aCI.SetRMajor(theRMajor);
423 aCI.SetRMinor(theRMinor);
425 if (!theVecMaj.IsNull()) {
426 Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
427 if (aRefVecMaj.IsNull()) return NULL;
428 aCI.SetVectorMajor(aRefVecMaj);
431 //Compute the Ellipse value
434 if (!GetSolver()->ComputeFunction(aFunction)) {
435 SetErrorCode("Ellipse driver failed");
439 catch (Standard_Failure) {
440 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
441 SetErrorCode(aFail->GetMessageString());
445 //Make a Python command
446 if (!theVecMaj.IsNull()) {
447 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
448 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
449 << ", " << theVecMaj << ")";
452 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
453 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
460 //=============================================================================
464 //=============================================================================
465 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
466 Handle(GEOM_Object) thePnt2,
467 Handle(GEOM_Object) thePnt3)
471 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
473 //Add a new Circle Arc object
474 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
476 //Add a new Circle Arc function
477 Handle(GEOM_Function) aFunction =
478 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
480 if (aFunction.IsNull()) return NULL;
482 //Check if the function is set correctly
483 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
484 GEOMImpl_IArc aCI (aFunction);
486 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
487 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
488 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
490 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
492 aCI.SetPoint1(aRefPnt1);
493 aCI.SetPoint2(aRefPnt2);
494 aCI.SetPoint3(aRefPnt3);
496 //Compute the Arc value
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
558 if (!GetSolver()->ComputeFunction(aFunction)) {
559 SetErrorCode("Arc driver failed");
563 catch (Standard_Failure) {
564 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
565 SetErrorCode(aFail->GetMessageString());
568 //Make a Python command
569 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
570 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
576 //=============================================================================
580 //=============================================================================
581 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
582 Handle(GEOM_Object) thePnt2,
583 Handle(GEOM_Object) thePnt3)
587 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
589 //Add a new Circle Arc object
590 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
592 //Add a new Circle Arc function
593 Handle(GEOM_Function) aFunction =
594 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
596 if (aFunction.IsNull()) return NULL;
598 //Check if the function is set correctly
599 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
600 GEOMImpl_IArc aCI (aFunction);
602 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
603 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
604 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
606 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
608 aCI.SetPoint1(aRefPnt1);
609 aCI.SetPoint2(aRefPnt2);
610 aCI.SetPoint3(aRefPnt3);
612 //Compute the Arc value
615 if (!GetSolver()->ComputeFunction(aFunction)) {
616 SetErrorCode("Arc driver failed");
620 catch (Standard_Failure) {
621 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
622 SetErrorCode(aFail->GetMessageString());
626 //Make a Python command
627 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
628 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
634 //=============================================================================
638 //=============================================================================
639 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
644 //Add a new Polyline object
645 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
647 //Add a new Polyline function for creation a polyline relatively to points set
648 Handle(GEOM_Function) aFunction =
649 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
650 if (aFunction.IsNull()) return NULL;
652 //Check if the function is set correctly
653 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
655 GEOMImpl_IPolyline aCI (aFunction);
657 int aLen = thePoints.size();
659 aCI.SetConstructorType(POINT_CONSTRUCTOR);
662 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
663 for (; it != thePoints.end(); it++, ind++) {
664 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
665 if (aRefPnt.IsNull()) {
666 SetErrorCode("NULL point for Polyline");
669 aCI.SetPoint(ind, aRefPnt);
672 aCI.SetIsClosed(theIsClosed);
674 //Compute the Polyline value
677 if (!GetSolver()->ComputeFunction(aFunction)) {
678 SetErrorCode("Polyline driver failed");
682 catch (Standard_Failure) {
683 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
684 SetErrorCode(aFail->GetMessageString());
688 //Make a Python command
689 GEOM::TPythonDump pd (aFunction);
690 pd << aPolyline << " = geompy.MakePolyline([";
692 it = thePoints.begin();
694 while (it != thePoints.end()) {
695 pd << ", " << (*it++);
697 pd << "], " << theIsClosed << ")";
703 //=============================================================================
707 //=============================================================================
708 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
709 (std::list<Handle(GEOM_Object)> thePoints,
714 //Add a new Spline object
715 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
717 //Add a new Spline function for creation a bezier curve relatively to points set
718 Handle(GEOM_Function) aFunction =
719 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
720 if (aFunction.IsNull()) return NULL;
722 //Check if the function is set correctly
723 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
725 GEOMImpl_ISpline aCI (aFunction);
727 aCI.SetConstructorType(POINT_CONSTRUCTOR);
729 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
730 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
731 for (; it != thePoints.end(); it++) {
732 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
733 if (aRefPnt.IsNull()) {
734 SetErrorCode("NULL point for Besier curve");
737 aPoints->Append(aRefPnt);
739 aCI.SetPoints(aPoints);
741 aCI.SetIsClosed(theIsClosed);
743 //Compute the Spline value
746 if (!GetSolver()->ComputeFunction(aFunction)) {
747 SetErrorCode("Spline driver failed");
751 catch (Standard_Failure) {
752 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
753 SetErrorCode(aFail->GetMessageString());
757 //Make a Python command
758 GEOM::TPythonDump pd (aFunction);
759 pd << aSpline << " = geompy.MakeBezier([";
761 it = thePoints.begin();
763 while (it != thePoints.end()) {
764 pd << ", " << (*it++);
766 pd << "], " << theIsClosed << ")";
772 //=============================================================================
774 * MakeSplineInterpolation
776 //=============================================================================
777 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
778 (std::list<Handle(GEOM_Object)> thePoints,
780 bool theDoReordering)
784 //Add a new Spline object
785 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
787 //Add a new Spline function for interpolation type
788 Handle(GEOM_Function) aFunction =
789 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
790 if (aFunction.IsNull()) return NULL;
792 //Check if the function is set correctly
793 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
795 GEOMImpl_ISpline aCI (aFunction);
797 aCI.SetConstructorType(POINT_CONSTRUCTOR);
799 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
800 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
801 for (; it != thePoints.end(); it++) {
802 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
803 if (aRefPnt.IsNull()) {
806 aPoints->Append(aRefPnt);
808 aCI.SetPoints(aPoints);
810 aCI.SetIsClosed(theIsClosed);
811 aCI.SetDoReordering(theDoReordering);
813 //Compute the Spline value
816 if (!GetSolver()->ComputeFunction(aFunction)) {
817 SetErrorCode("Spline driver failed");
821 catch (Standard_Failure) {
822 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
823 SetErrorCode(aFail->GetMessageString());
827 //Make a Python command
828 GEOM::TPythonDump pd (aFunction);
829 pd << aSpline << " = geompy.MakeInterpol([";
831 it = thePoints.begin();
833 while (it != thePoints.end()) {
834 pd << ", " << (*it++);
836 pd << "], " << theIsClosed << ", " << theDoReordering << ")";
843 //=============================================================================
845 * MakeSplineInterpolWithTangents
847 //=============================================================================
848 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolWithTangents
849 (std::list<Handle(GEOM_Object)> thePoints,
850 Handle(GEOM_Object) theFirstVec,
851 Handle(GEOM_Object) theLastVec)
855 //Add a new Spline object
856 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
858 //Add a new Spline function for interpolation type
859 Handle(GEOM_Function) aFunction =
860 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOL_TANGENTS);
861 if (aFunction.IsNull()) return NULL;
863 //Check if the function is set correctly
864 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
866 GEOMImpl_ISpline aCI (aFunction);
868 aCI.SetConstructorType(POINT_CONSTRUCTOR);
870 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
871 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
872 for (; it != thePoints.end(); it++) {
873 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
874 if (aRefPnt.IsNull()) {
875 SetErrorCode("NULL point for Interpolation");
878 aPoints->Append(aRefPnt);
880 aCI.SetPoints(aPoints);
882 Handle(GEOM_Function) aVec1 = theFirstVec->GetLastFunction();
883 Handle(GEOM_Function) aVec2 = theLastVec->GetLastFunction();
885 if (aVec1.IsNull() || aVec2.IsNull()) return NULL;
887 aCI.SetFirstVector(aVec1);
888 aCI.SetLastVector(aVec2);
890 //Compute the Spline value
893 if (!GetSolver()->ComputeFunction(aFunction)) {
894 SetErrorCode("Spline driver failed");
898 catch (Standard_Failure) {
899 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
900 SetErrorCode(aFail->GetMessageString());
904 //Make a Python command
905 GEOM::TPythonDump pd (aFunction);
906 pd << aSpline << " = geompy.MakeInterpolWithTangents([";
908 it = thePoints.begin();
910 while (it != thePoints.end()) {
911 pd << ", " << (*it++);
913 pd << "], " << theFirstVec << ", " << theLastVec << ")";
919 //=============================================================================
921 * MakeCurveParametric
923 //=============================================================================
924 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
925 (const char* thexExpr, const char* theyExpr, const char* thezExpr,
926 double theParamMin, double theParamMax, double theParamStep,
927 CurveType theCurveType,
928 int theParamNbStep, bool theNewMethod)
930 TCollection_AsciiString aPyScript;
931 aPyScript +="from math import * \n";
932 aPyScript +="def X(t): \n";
933 aPyScript +=" return ";
934 aPyScript += thexExpr;
936 aPyScript +="def Y(t): \n";
937 aPyScript +=" return ";
938 aPyScript += theyExpr;
941 aPyScript +="def Z(t): \n";
942 aPyScript +=" return ";
943 aPyScript += thezExpr;
948 aPyScript +="def coordCalculator(tmin, tmax, nstep): \n";
949 aPyScript +=" coords = [] \n";
950 aPyScript +=" tstep = (tmax - tmin) / nstep \n";
951 aPyScript +=" n = 0 \n";
952 aPyScript +=" while n <= nstep : \n";
953 aPyScript +=" t = tmin + n*tstep \n";
954 aPyScript +=" coords.append([X(t), Y(t), Z(t)]) \n";
955 aPyScript +=" n = n+1 \n";
956 aPyScript +=" return coords \n";
960 aPyScript +="def coordCalculator(tmin, tmax, tstep): \n";
961 aPyScript +=" coords = [] \n";
962 aPyScript +=" while tmin <= tmax : \n";
963 aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
964 aPyScript +=" tmin = tmin + tstep \n";
965 aPyScript +=" return coords \n";
970 if(theParamMin >= theParamMax) {
971 SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
975 if(!theNewMethod && theParamStep <= 0.0) {
976 SetErrorCode("Value of the step must be positive !!!");
979 else if(theNewMethod && theParamNbStep < 0) {
980 SetErrorCode("The number of steps must be positive !!!");
984 /* Initialize the Python interpreter */
985 if (! Py_IsInitialized()) {
986 SetErrorCode("Python interpreter is not initialized !!! ");
990 PyGILState_STATE gstate;
991 gstate = PyGILState_Ensure();
993 PyObject* main_mod = PyImport_AddModule("__main__");
994 PyObject* main_dict = PyModule_GetDict(main_mod);
996 PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
999 SetErrorCode("Error during executing of python script !!!");
1001 PyGILState_Release(gstate);
1007 PyObject * func = NULL;
1008 func = PyObject_GetAttrString(main_mod, "coordCalculator");
1011 SetErrorCode("Can't get function from python module !!!");
1012 PyGILState_Release(gstate);
1018 coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep );
1020 coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
1022 if (coords == NULL){
1024 std::string err_description="";
1025 PyObject* new_stderr = newPyStdOut(err_description);
1026 PyObject* old_stderr = PySys_GetObject((char*)"stderr");
1027 Py_INCREF(old_stderr);
1028 PySys_SetObject((char*)"stderr", new_stderr);
1030 PySys_SetObject((char*)"stderr", old_stderr);
1031 Py_DECREF(new_stderr);
1032 MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description);
1033 SetErrorCode("Can't evaluate the expressions, please check them !!!");
1034 PyGILState_Release(gstate);
1038 int lsize = PyList_Size( coords );
1041 SetErrorCode("Empty list of the points, please check input parameters !!!");
1045 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, lsize * 3);
1048 for ( Py_ssize_t i = 0; i < lsize; ++i ) {
1049 PyObject* coord = PyList_GetItem( coords, i );
1050 if (coord != NULL) {
1051 for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
1052 PyObject* item = PyList_GetItem(coord, j);
1053 aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
1061 PyGILState_Release(gstate);
1063 Handle(GEOM_Object) aCurve;
1064 Handle(GEOM_Function) aFunction;
1065 TCollection_AsciiString aCurveType;
1067 switch(theCurveType) {
1069 //Add a new Polyline object
1070 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
1072 //Add a new Polyline function for creation a polyline relatively to points set
1073 aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
1074 if (aFunction.IsNull()) return NULL;
1076 //Check if the function is set correctly
1077 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
1079 GEOMImpl_IPolyline aCI (aFunction);
1081 aCI.SetLength(lsize);
1082 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1083 aCI.SetIsClosed(false);
1084 aCI.SetCoordinates(aCoordsArray);
1085 aCurveType = "GEOM.Polyline";
1089 //Add a new Spline object
1090 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1091 //Add a new Spline function for creation a bezier curve relatively to points set
1093 aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
1094 if (aFunction.IsNull()) return NULL;
1096 //Check if the function is set correctly
1097 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1099 GEOMImpl_ISpline aCI (aFunction);
1101 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1102 aCI.SetIsClosed(false);
1103 aCI.SetCoordinates(aCoordsArray);
1104 aCurveType = "GEOM.Bezier";
1107 case Interpolation: {
1108 //Add a new Spline object
1109 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1111 //Add a new Spline function for creation a bezier curve relatively to points set
1112 aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
1113 if (aFunction.IsNull()) return NULL;
1115 //Check if the function is set correctly
1116 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1118 GEOMImpl_ISpline aCI (aFunction);
1119 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1120 aCI.SetIsClosed(false);
1121 aCI.SetDoReordering(false);
1122 aCI.SetCoordinates(aCoordsArray);
1123 aCurveType = "GEOM.Interpolation";
1128 GEOMImpl_ICurveParametric aIP(aFunction);
1129 aIP.SetExprX (thexExpr);
1130 aIP.SetExprY (theyExpr);
1131 aIP.SetExprZ (thezExpr);
1132 aIP.SetParamMin (theParamMin);
1133 aIP.SetParamMax (theParamMax);
1135 aIP.SetParamNbStep(theParamNbStep);
1137 aIP.SetParamStep (theParamStep);
1139 //Compute the Curve value
1142 if (!GetSolver()->ComputeFunction(aFunction)) {
1143 SetErrorCode("Curve driver failed !!!");
1147 catch (Standard_Failure) {
1148 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1149 SetErrorCode(aFail->GetMessageString());
1153 //Make a Python command
1154 GEOM::TPythonDump pd (aFunction);
1155 pd << aCurve << " = geompy.MakeCurveParametric(";
1156 pd << "\"" << thexExpr << "\", ";
1157 pd << "\"" << theyExpr << "\", ";
1158 pd << "\"" << thezExpr << "\", ";
1160 pd << theParamMin <<", ";
1161 pd << theParamMax <<", ";
1163 pd << theParamNbStep <<", ";
1165 pd << theParamStep <<", ";
1166 pd << aCurveType.ToCString() <<", ";
1167 pd << theNewMethod <<")";
1173 //=============================================================================
1177 //=============================================================================
1178 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1179 std::list<double> theWorkingPlane)
1183 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1185 //Add a new Sketcher object
1186 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1188 //Add a new Sketcher function
1189 Handle(GEOM_Function) aFunction =
1190 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1191 if (aFunction.IsNull()) return NULL;
1193 //Check if the function is set correctly
1194 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1196 GEOMImpl_ISketcher aCI (aFunction);
1198 TCollection_AsciiString aCommand((char*) theCommand);
1199 aCI.SetCommand(aCommand);
1202 std::list<double>::iterator it = theWorkingPlane.begin();
1203 for (; it != theWorkingPlane.end(); it++, ind++)
1204 aCI.SetWorkingPlane(ind, *it);
1206 //Compute the Sketcher value
1209 if (!GetSolver()->ComputeFunction(aFunction)) {
1210 SetErrorCode("Sketcher driver failed");
1214 catch (Standard_Failure) {
1215 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1216 SetErrorCode(aFail->GetMessageString());
1220 //Make a Python command
1221 GEOM::TPythonDump pd (aFunction);
1222 pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1224 it = theWorkingPlane.begin();
1226 while (it != theWorkingPlane.end()) {
1227 pd << ", " << (*it++);
1235 //=============================================================================
1237 * MakeSketcherOnPlane
1239 //=============================================================================
1240 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1241 (const char* theCommand,
1242 Handle(GEOM_Object) theWorkingPlane)
1246 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1248 //Add a new Sketcher object
1249 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1251 //Add a new Sketcher function
1252 Handle(GEOM_Function) aFunction =
1253 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1254 if (aFunction.IsNull()) return NULL;
1256 //Check if the function is set correctly
1257 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1259 GEOMImpl_ISketcher aCI (aFunction);
1261 TCollection_AsciiString aCommand((char*) theCommand);
1262 aCI.SetCommand(aCommand);
1264 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1265 if (aRefPlane.IsNull()) return NULL;
1266 aCI.SetWorkingPlane( aRefPlane );
1268 //Compute the Sketcher value
1271 if (!GetSolver()->ComputeFunction(aFunction)) {
1272 SetErrorCode("Sketcher driver failed");
1276 catch (Standard_Failure) {
1277 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1278 SetErrorCode(aFail->GetMessageString());
1282 //Make a Python command
1283 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1284 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
1290 //=============================================================================
1292 * Make3DSketcherCommand
1294 //=============================================================================
1295 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcherCommand (const char* theCommand)
1299 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1301 //Add a new Sketcher object
1302 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1304 //Add a new Sketcher function
1305 Handle(GEOM_Function) aFunction =
1306 aSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COMMAND);
1307 if (aFunction.IsNull()) return NULL;
1309 //Check if the function is set correctly
1310 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1312 GEOMImpl_I3DSketcher aCI (aFunction);
1314 TCollection_AsciiString aCommand ((char*) theCommand);
1315 aCI.SetCommand(aCommand);
1317 //Compute the 3D Sketcher value
1320 if (!GetSolver()->ComputeFunction(aFunction)) {
1321 SetErrorCode("3D Sketcher driver failed");
1325 catch (Standard_Failure) {
1326 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1327 SetErrorCode(aFail->GetMessageString());
1331 //Make a Python command
1332 GEOM::TPythonDump pd (aFunction);
1333 pd << aSketcher << " = geompy.Make3DSketcherCommand(\"" << aCommand.ToCString() << "\")";
1339 //=============================================================================
1343 //=============================================================================
1344 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1348 //Add a new Sketcher object
1349 Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1351 //Add a new Sketcher function
1352 Handle(GEOM_Function) aFunction =
1353 a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COORDS);
1354 if (aFunction.IsNull()) return NULL;
1356 //Check if the function is set correctly
1357 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1359 GEOMImpl_I3DSketcher aCI (aFunction);
1362 std::list<double>::iterator it = theCoordinates.begin();
1363 for (; it != theCoordinates.end(); it++)
1366 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1368 it = theCoordinates.begin();
1370 for (; it != theCoordinates.end(); it++, ind++)
1371 aCoordsArray->SetValue(ind, *it);
1373 aCI.SetCoordinates(aCoordsArray);
1375 //Compute the Sketcher value
1378 if (!GetSolver()->ComputeFunction(aFunction)) {
1379 SetErrorCode("3D Sketcher driver failed");
1383 catch (Standard_Failure) {
1384 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1385 SetErrorCode(aFail->GetMessageString());
1389 //Make a Python command
1390 GEOM::TPythonDump pd (aFunction);
1391 pd << a3DSketcher << " = geompy.Make3DSketcher([";
1393 it = theCoordinates.begin();
1395 while (it != theCoordinates.end()) {
1396 pd << ", " << (*it++);
1404 //=============================================================================
1408 //=============================================================================
1409 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeIsoline
1410 (const Handle(GEOM_Object) &theFace,
1412 const double theParameter)
1416 if (theFace.IsNull()) {
1420 //Add a new Spline object
1421 Handle(GEOM_Object) anIsoline =
1422 GetEngine()->AddObject(GetDocID(), GEOM_ISOLINE);
1424 //Add a new Spline function for interpolation type
1425 Handle(GEOM_Function) aFunction =
1426 anIsoline->AddFunction(GEOMImpl_ShapeDriver::GetID(), SHAPE_ISOLINE);
1428 if (aFunction.IsNull()) {
1432 //Check if the function is set correctly
1433 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) {
1437 GEOMImpl_IIsoline aCI (aFunction);
1438 Handle(GEOM_Function) aRefFace = theFace->GetLastFunction();
1440 if (aRefFace.IsNull()) {
1444 aCI.SetFace(aRefFace);
1445 aCI.SetIsUIso(IsUIso);
1446 aCI.SetParameter(theParameter);
1448 //Compute the isoline curve
1451 if (!GetSolver()->ComputeFunction(aFunction)) {
1452 SetErrorCode("Shape driver failed");
1456 catch (Standard_Failure) {
1457 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1458 SetErrorCode(aFail->GetMessageString());
1462 //Make a Python command
1463 GEOM::TPythonDump (aFunction) << anIsoline << " = geompy.MakeIsoline( "
1464 << theFace << ", " << IsUIso << ", " << theParameter << " )";
1470 //=============================================================================
1474 //=============================================================================
1475 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline2D
1476 (const std::list <std::list <double> > &theCoords,
1477 const Handle(TColStd_HArray1OfExtendedString) &theNames,
1478 const Handle(TColStd_HArray1OfByte) &theTypes,
1479 const Handle(TColStd_HArray1OfByte) &theCloseds,
1480 const Handle(TColStd_HArray1OfReal) &theWorkingPlane)
1484 if (theCoords.empty() || theNames.IsNull() || theTypes.IsNull() ||
1485 theCloseds.IsNull() || theWorkingPlane.IsNull()) {
1489 // Add a new Polyline object
1490 Handle(GEOM_Object) aResult =
1491 GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE2D);
1492 Handle(GEOM_Function) aFunction = aResult->AddFunction
1493 (GEOMImpl_PolylineDriver::GetID(), POLYLINE2D_PLN_COORDS);
1495 if (aFunction.IsNull()) {
1499 // Check if the function is set correctly
1500 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) {
1504 GEOMImpl_IPolyline2D aCI(aFunction);
1506 aCI.SetCoords(theCoords);
1507 aCI.SetNames(theNames);
1508 aCI.SetTypes(theTypes);
1509 aCI.SetClosedFlags(theCloseds);
1510 aCI.SetWorkingPlaneDbls(theWorkingPlane);
1512 // Compute the isoline curve
1515 if (!GetSolver()->ComputeFunction(aFunction)) {
1516 SetErrorCode("Polyline driver failed");
1520 catch (Standard_Failure) {
1521 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1522 SetErrorCode(aFail->GetMessageString());
1526 //Make a Python command
1527 GEOMImpl_PolylineDumper aDumper(theCoords, theNames, theTypes,
1528 theCloseds, theWorkingPlane);
1530 aDumper.Dump(aResult);
1532 if (aDumper.IsDone() == Standard_False) {
1533 SetErrorCode("Python dump failed");
1541 //=============================================================================
1543 * MakePolyline2DOnPlane
1545 //=============================================================================
1546 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline2DOnPlane
1547 (const std::list <std::list <double> > &theCoords,
1548 const Handle(TColStd_HArray1OfExtendedString) &theNames,
1549 const Handle(TColStd_HArray1OfByte) &theTypes,
1550 const Handle(TColStd_HArray1OfByte) &theCloseds,
1551 const Handle(GEOM_Object) &theWorkingPlane)
1555 if (theCoords.empty() || theNames.IsNull() || theTypes.IsNull() ||
1556 theCloseds.IsNull() || theWorkingPlane.IsNull()) {
1560 //Add a new Polyline object
1561 Handle(GEOM_Object) aResult =
1562 GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE2D);
1563 Handle(GEOM_Function) aFunction = aResult->AddFunction
1564 (GEOMImpl_PolylineDriver::GetID(), POLYLINE2D_PLN_OBJECT);
1566 if (aFunction.IsNull()) {
1570 //Check if the function is set correctly
1571 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) {
1575 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1577 if (aRefPlane.IsNull()) {
1581 GEOMImpl_IPolyline2D aCI(aFunction);
1583 aCI.SetCoords(theCoords);
1584 aCI.SetNames(theNames);
1585 aCI.SetTypes(theTypes);
1586 aCI.SetClosedFlags(theCloseds);
1587 aCI.SetWorkingPlane(aRefPlane);
1589 //Compute the isoline curve
1592 if (!GetSolver()->ComputeFunction(aFunction)) {
1593 SetErrorCode("Polyline driver failed");
1597 catch (Standard_Failure) {
1598 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1599 SetErrorCode(aFail->GetMessageString());
1603 //Make a Python command
1604 GEOMImpl_PolylineDumper aDumper(theCoords, theNames, theTypes,
1605 theCloseds, theWorkingPlane);
1607 aDumper.Dump(aResult);
1609 if (aDumper.IsDone() == Standard_False) {
1610 SetErrorCode("Python dump failed");