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>
25 #include <Standard_Stream.hxx>
27 #include <GEOMImpl_ICurvesOperations.hxx>
29 #include <TColStd_HArray1OfReal.hxx>
31 #include <GEOM_Function.hxx>
32 #include <GEOM_PythonDump.hxx>
34 #include <GEOMImpl_Types.hxx>
36 #include <GEOMImpl_PolylineDriver.hxx>
37 #include <GEOMImpl_CircleDriver.hxx>
38 #include <GEOMImpl_SplineDriver.hxx>
39 #include <GEOMImpl_EllipseDriver.hxx>
40 #include <GEOMImpl_ArcDriver.hxx>
41 #include <GEOMImpl_SketcherDriver.hxx>
42 #include <GEOMImpl_3DSketcherDriver.hxx>
44 #include <GEOMImpl_IPolyline.hxx>
45 #include <GEOMImpl_ICircle.hxx>
46 #include <GEOMImpl_ISpline.hxx>
47 #include <GEOMImpl_IEllipse.hxx>
48 #include <GEOMImpl_IArc.hxx>
49 #include <GEOMImpl_ISketcher.hxx>
50 #include <GEOMImpl_I3DSketcher.hxx>
52 #include "utilities.h"
54 #include <TDF_Tool.hxx>
56 #include <Standard_Failure.hxx>
57 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
60 /* ==================================
61 * =========== PYTHON ==============
62 * ==================================*/
71 PyStdOut_dealloc(PyStdOut *self)
77 PyStdOut_write(PyStdOut *self, PyObject *args)
81 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
85 *(self->out)=*(self->out)+c;
91 static PyMethodDef PyStdOut_methods[] = {
92 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
93 PyDoc_STR("write(string) -> None")},
94 {NULL, NULL} /* sentinel */
97 static PyMemberDef PyStdOut_memberlist[] = {
98 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
99 (char*)"flag indicating that a space needs to be printed; used by print"},
100 {NULL} /* Sentinel */
103 static PyTypeObject PyStdOut_Type = {
104 /* The ob_type field must be initialized in the module init function
105 * to be portable to Windows without using C++. */
106 PyObject_HEAD_INIT(NULL)
109 sizeof(PyStdOut), /*tp_basicsize*/
112 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
119 0, /*tp_as_sequence*/
124 PyObject_GenericGetAttr, /*tp_getattro*/
125 /* softspace is writable: we must supply tp_setattro */
126 PyObject_GenericSetAttr, /* tp_setattro */
128 Py_TPFLAGS_DEFAULT, /*tp_flags*/
132 0, /*tp_richcompare*/
133 0, /*tp_weaklistoffset*/
136 PyStdOut_methods, /*tp_methods*/
137 PyStdOut_memberlist, /*tp_members*/
151 PyObject * newPyStdOut( std::string& out )
154 self = PyObject_New(PyStdOut, &PyStdOut_Type);
159 return (PyObject*)self;
163 ////////////////////////END PYTHON///////////////////////////
164 //=============================================================================
168 //=============================================================================
169 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
170 : GEOM_IOperations(theEngine, theDocID)
172 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
175 //=============================================================================
179 //=============================================================================
180 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
182 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
186 //=============================================================================
190 //=============================================================================
191 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
192 Handle(GEOM_Object) thePnt2,
193 Handle(GEOM_Object) thePnt3)
197 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
199 //Add a new Circle object
200 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
202 //Add a new Circle function for creation a circle relatively to three points
203 Handle(GEOM_Function) aFunction =
204 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
205 if (aFunction.IsNull()) return NULL;
207 //Check if the function is set correctly
208 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
210 GEOMImpl_ICircle aCI (aFunction);
212 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
213 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
214 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
216 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
218 aCI.SetPoint1(aRefPnt1);
219 aCI.SetPoint2(aRefPnt2);
220 aCI.SetPoint3(aRefPnt3);
222 //Compute the Circle value
224 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
227 if (!GetSolver()->ComputeFunction(aFunction)) {
228 SetErrorCode("Circle driver failed");
232 catch (Standard_Failure) {
233 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
234 SetErrorCode(aFail->GetMessageString());
238 //Make a Python command
239 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
240 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
246 //=============================================================================
248 * MakeCircleCenter2Pnt
250 //=============================================================================
251 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
252 Handle(GEOM_Object) thePnt2,
253 Handle(GEOM_Object) thePnt3)
257 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
259 //Add a new Circle object
260 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
262 //Add a new Circle function for creation a circle relatively to center and 2 points
263 Handle(GEOM_Function) aFunction =
264 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
265 if (aFunction.IsNull()) return NULL;
267 //Check if the function is set correctly
268 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
270 GEOMImpl_ICircle aCI (aFunction);
272 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
273 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
274 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
276 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
278 aCI.SetPoint1(aRefPnt1);
279 aCI.SetPoint2(aRefPnt2);
280 aCI.SetPoint3(aRefPnt3);
282 //Compute the Circle value
284 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
287 if (!GetSolver()->ComputeFunction(aFunction)) {
288 SetErrorCode("Circle driver failed");
292 catch (Standard_Failure) {
293 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
294 SetErrorCode(aFail->GetMessageString());
298 //Make a Python command
299 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
300 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
306 //=============================================================================
310 //=============================================================================
311 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
312 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
316 // Not set thePnt means origin of global CS,
317 // Not set theVec means Z axis of global CS
318 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
320 //Add a new Circle object
321 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
323 //Add a new Circle function for creation a circle relatively to point and vector
324 Handle(GEOM_Function) aFunction =
325 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
326 if (aFunction.IsNull()) return NULL;
328 //Check if the function is set correctly
329 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
331 GEOMImpl_ICircle aCI (aFunction);
333 if (!thePnt.IsNull()) {
334 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
335 if (aRefPnt.IsNull()) return NULL;
336 aCI.SetCenter(aRefPnt);
339 if (!theVec.IsNull()) {
340 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
341 if (aRefVec.IsNull()) return NULL;
342 aCI.SetVector(aRefVec);
347 //Compute the Circle value
349 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
352 if (!GetSolver()->ComputeFunction(aFunction)) {
353 SetErrorCode("Circle driver failed");
357 catch (Standard_Failure) {
358 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
359 SetErrorCode(aFail->GetMessageString());
363 //Make a Python command
364 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
365 << thePnt << ", " << theVec << ", " << theR << ")";
371 //=============================================================================
375 //=============================================================================
376 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
377 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
378 double theRMajor, double theRMinor,
379 Handle(GEOM_Object) theVecMaj)
383 // Not set thePnt means origin of global CS,
384 // Not set theVec means Z axis of global CS
385 // Not set theVecMaj means X axis of global CS
386 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
388 //Add a new Ellipse object
389 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
391 //Add a new Ellipse function
392 Handle(GEOM_Function) aFunction =
393 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
394 if (aFunction.IsNull()) return NULL;
396 //Check if the function is set correctly
397 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
399 GEOMImpl_IEllipse aCI (aFunction);
401 if (!thePnt.IsNull()) {
402 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
403 if (aRefPnt.IsNull()) return NULL;
404 aCI.SetCenter(aRefPnt);
407 if (!theVec.IsNull()) {
408 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
409 if (aRefVec.IsNull()) return NULL;
410 aCI.SetVector(aRefVec);
413 aCI.SetRMajor(theRMajor);
414 aCI.SetRMinor(theRMinor);
416 if (!theVecMaj.IsNull()) {
417 Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
418 if (aRefVecMaj.IsNull()) return NULL;
419 aCI.SetVectorMajor(aRefVecMaj);
422 //Compute the Ellipse value
424 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
427 if (!GetSolver()->ComputeFunction(aFunction)) {
428 SetErrorCode("Ellipse driver failed");
432 catch (Standard_Failure) {
433 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
434 SetErrorCode(aFail->GetMessageString());
438 //Make a Python command
439 if (!theVecMaj.IsNull()) {
440 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
441 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
442 << ", " << theVecMaj << ")";
445 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
446 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
453 //=============================================================================
457 //=============================================================================
458 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
459 Handle(GEOM_Object) thePnt2,
460 Handle(GEOM_Object) thePnt3)
464 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
466 //Add a new Circle Arc object
467 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
469 //Add a new Circle Arc function
470 Handle(GEOM_Function) aFunction =
471 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
473 if (aFunction.IsNull()) return NULL;
475 //Check if the function is set correctly
476 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
477 GEOMImpl_IArc aCI (aFunction);
479 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
480 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
481 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
484 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
486 aCI.SetPoint1(aRefPnt1);
487 aCI.SetPoint2(aRefPnt2);
488 aCI.SetPoint3(aRefPnt3);
490 //Compute the Arc value
492 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
495 if (!GetSolver()->ComputeFunction(aFunction)) {
496 SetErrorCode("Arc driver failed");
500 catch (Standard_Failure) {
501 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
502 SetErrorCode(aFail->GetMessageString());
506 //Make a Python command
507 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
508 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
514 //=============================================================================
518 //=============================================================================
519 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
520 Handle(GEOM_Object) thePnt2,
521 Handle(GEOM_Object) thePnt3,
525 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
527 //Add a new Circle Arc object
528 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
530 //Add a new Circle Arc function
531 Handle(GEOM_Function) aFunction =
532 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
533 if (aFunction.IsNull()) return NULL;
535 //Check if the function is set correctly
536 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
538 GEOMImpl_IArc aCI (aFunction);
540 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
541 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
542 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
544 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
546 aCI.SetPoint1(aRefPnt1);
547 aCI.SetPoint2(aRefPnt2);
548 aCI.SetPoint3(aRefPnt3);
549 aCI.SetSense(theSense);
551 //Compute the Arc value
553 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
556 if (!GetSolver()->ComputeFunction(aFunction)) {
557 SetErrorCode("Arc driver failed");
561 catch (Standard_Failure) {
562 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
563 SetErrorCode(aFail->GetMessageString());
566 //Make a Python command
567 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
568 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
574 //=============================================================================
578 //=============================================================================
579 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
580 Handle(GEOM_Object) thePnt2,
581 Handle(GEOM_Object) thePnt3)
585 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
587 //Add a new Circle Arc object
588 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
590 //Add a new Circle Arc function
591 Handle(GEOM_Function) aFunction =
592 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
594 if (aFunction.IsNull()) return NULL;
596 //Check if the function is set correctly
597 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
598 GEOMImpl_IArc aCI (aFunction);
600 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
601 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
602 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
605 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
607 aCI.SetPoint1(aRefPnt1);
608 aCI.SetPoint2(aRefPnt2);
609 aCI.SetPoint3(aRefPnt3);
611 //Compute the Arc value
613 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
616 if (!GetSolver()->ComputeFunction(aFunction)) {
617 SetErrorCode("Arc driver failed");
621 catch (Standard_Failure) {
622 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
623 SetErrorCode(aFail->GetMessageString());
627 //Make a Python command
628 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
629 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
635 //=============================================================================
639 //=============================================================================
640 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
645 //Add a new Polyline object
646 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
648 //Add a new Polyline function for creation a polyline relatively to points set
649 Handle(GEOM_Function) aFunction =
650 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
651 if (aFunction.IsNull()) return NULL;
653 //Check if the function is set correctly
654 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
656 GEOMImpl_IPolyline aCI (aFunction);
658 int aLen = thePoints.size();
660 aCI.SetConstructorType(POINT_CONSTRUCTOR);
663 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
664 for (; it != thePoints.end(); it++, ind++) {
665 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
666 if (aRefPnt.IsNull()) {
667 SetErrorCode("NULL point for Polyline");
670 aCI.SetPoint(ind, aRefPnt);
673 aCI.SetIsClosed(theIsClosed);
675 //Compute the Polyline value
677 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
680 if (!GetSolver()->ComputeFunction(aFunction)) {
681 SetErrorCode("Polyline driver failed");
685 catch (Standard_Failure) {
686 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
687 SetErrorCode(aFail->GetMessageString());
691 //Make a Python command
692 GEOM::TPythonDump pd (aFunction);
693 pd << aPolyline << " = geompy.MakePolyline([";
695 it = thePoints.begin();
697 while (it != thePoints.end()) {
698 pd << ", " << (*it++);
700 pd << "], " << theIsClosed << ")";
706 //=============================================================================
710 //=============================================================================
711 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
712 (std::list<Handle(GEOM_Object)> thePoints,
717 //Add a new Spline object
718 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
720 //Add a new Spline function for creation a bezier curve relatively to points set
721 Handle(GEOM_Function) aFunction =
722 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
723 if (aFunction.IsNull()) return NULL;
725 //Check if the function is set correctly
726 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
728 GEOMImpl_ISpline aCI (aFunction);
730 int aLen = thePoints.size();
732 aCI.SetConstructorType(POINT_CONSTRUCTOR);
735 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
736 for (; it != thePoints.end(); it++, ind++) {
737 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
739 if (aRefPnt.IsNull()) return NULL;
741 aCI.SetPoint(ind, aRefPnt);
744 aCI.SetIsClosed(theIsClosed);
746 //Compute the Spline value
748 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
751 if (!GetSolver()->ComputeFunction(aFunction)) {
752 SetErrorCode("Spline driver failed");
756 catch (Standard_Failure) {
757 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
758 SetErrorCode(aFail->GetMessageString());
762 //Make a Python command
763 GEOM::TPythonDump pd (aFunction);
764 pd << aSpline << " = geompy.MakeBezier([";
766 it = thePoints.begin();
768 while (it != thePoints.end()) {
769 pd << ", " << (*it++);
771 pd << "], " << theIsClosed << ")";
777 //=============================================================================
779 * MakeSplineInterpolation
781 //=============================================================================
782 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
783 (std::list<Handle(GEOM_Object)> thePoints,
785 bool theDoReordering)
789 //Add a new Spline object
790 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
792 //Add a new Spline function for creation a bezier curve relatively to points set
793 Handle(GEOM_Function) aFunction =
794 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
795 if (aFunction.IsNull()) return NULL;
797 //Check if the function is set correctly
798 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
800 GEOMImpl_ISpline aCI (aFunction);
802 int aLen = thePoints.size();
803 aCI.SetConstructorType(POINT_CONSTRUCTOR);
807 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
808 for (; it != thePoints.end(); it++, ind++) {
809 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
811 if (aRefPnt.IsNull()) return NULL;
813 aCI.SetPoint(ind, aRefPnt);
816 aCI.SetIsClosed(theIsClosed);
817 aCI.SetDoReordering(theDoReordering);
819 //Compute the Spline value
821 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
824 if (!GetSolver()->ComputeFunction(aFunction)) {
825 SetErrorCode("Spline driver failed");
829 catch (Standard_Failure) {
830 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
831 SetErrorCode(aFail->GetMessageString());
835 //Make a Python command
836 GEOM::TPythonDump pd (aFunction);
837 pd << aSpline << " = geompy.MakeInterpol([";
839 it = thePoints.begin();
841 while (it != thePoints.end()) {
842 pd << ", " << (*it++);
844 pd << "], " << theIsClosed << ", " << theDoReordering << ")";
850 //=============================================================================
852 * MakeCurveParametric
854 //=============================================================================
855 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr,
856 double theParamMin, double theParamMax, double theParamStep,
857 CurveType theCurveType) {
858 TCollection_AsciiString aPyScript;
859 aPyScript +="from math import * \n";
860 aPyScript +="def X(t): \n";
861 aPyScript +=" return ";
862 aPyScript += thexExpr;
864 aPyScript +="def Y(t): \n";
865 aPyScript +=" return ";
866 aPyScript += theyExpr;
869 aPyScript +="def Z(t): \n";
870 aPyScript +=" return ";
871 aPyScript += thezExpr;
874 aPyScript +="def coordCalucator(tmin, tmax, tstep): \n";
875 aPyScript +=" coords = [] \n";
876 aPyScript +=" while tmin <= tmax : \n";
877 aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
878 aPyScript +=" tmin = tmin + tstep \n";
879 aPyScript +=" return coords \n";
883 if(theParamMin >= theParamMax) {
884 SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
888 if(theParamStep <= 0.0 ) {
889 SetErrorCode("Value of the step must be positive !!!");
893 /* Initialize the Python interpreter */
894 if (! Py_IsInitialized()) {
895 SetErrorCode("Python interpreter is not initialized !!! ");
899 PyGILState_STATE gstate;
900 gstate = PyGILState_Ensure();
902 PyObject* main_mod = PyImport_AddModule("__main__");
903 PyObject* main_dict = PyModule_GetDict(main_mod);
905 PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
908 SetErrorCode("Error during run python script !!!");
909 PyGILState_Release(gstate);
915 PyObject * func = NULL;
916 func = PyObject_GetAttrString(main_mod, "coordCalucator");
919 SetErrorCode("Can't get function from python module !!!");
920 PyGILState_Release(gstate);
924 PyObject* coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
925 PyObject* new_stderr = NULL;
929 std::string err_description="";
930 new_stderr = newPyStdOut(err_description);
931 PySys_SetObject((char*)"stderr", new_stderr);
933 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
934 Py_DECREF(new_stderr);
935 MESSAGE("Can't evaluate coordCalucator()" << " error is " << err_description);
936 SetErrorCode("Can't evaluate the expressions, please check them !!!");
937 PyGILState_Release(gstate);
941 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, PyList_Size( coords ) * 3);
943 if(PyList_Size( coords ) <= 0) {
944 SetErrorCode("Empty list of the points, please check input parameters !!!");
949 for ( Py_ssize_t i = 0; i< PyList_Size( coords ); ++i ) {
950 PyObject* coord = PyList_GetItem( coords, i );
952 for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
953 PyObject* item = PyList_GetItem(coord, j);
954 aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
964 PyGILState_Release(gstate);
966 Handle(GEOM_Object) aCurve;
967 Handle(GEOM_Function) aFunction;
968 TCollection_AsciiString aCurveType;
970 switch(theCurveType) {
972 //Add a new Polyline object
973 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
975 //Add a new Polyline function for creation a polyline relatively to points set
976 aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
977 if (aFunction.IsNull()) return NULL;
979 //Check if the function is set correctly
980 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
982 GEOMImpl_IPolyline aCI (aFunction);
984 aCI.SetLength(PyList_Size( coords ));
985 aCI.SetConstructorType(COORD_CONSTRUCTOR);
986 aCI.SetIsClosed(false);
987 aCI.SetCoordinates(aCoordsArray);
988 aCurveType = "geompy.GEOM.Polyline";
992 //Add a new Spline object
993 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
994 //Add a new Spline function for creation a bezier curve relatively to points set
996 aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
997 if (aFunction.IsNull()) return NULL;
999 //Check if the function is set correctly
1000 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1002 GEOMImpl_ISpline aCI (aFunction);
1004 aCI.SetLength(PyList_Size( coords ));
1005 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1006 aCI.SetIsClosed(false);
1007 aCI.SetCoordinates(aCoordsArray);
1008 aCurveType = "geompy.GEOM.Bezier";
1011 case Interpolation: {
1012 //Add a new Spline object
1013 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1015 //Add a new Spline function for creation a bezier curve relatively to points set
1016 aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
1017 if (aFunction.IsNull()) return NULL;
1019 //Check if the function is set correctly
1020 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1022 GEOMImpl_ISpline aCI (aFunction);
1023 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1024 aCI.SetLength(PyList_Size( coords ));
1025 aCI.SetIsClosed(false);
1026 aCI.SetDoReordering(false);
1027 aCI.SetCoordinates(aCoordsArray);
1028 aCurveType = "geompy.GEOM.Interpolation";
1033 //Compute the Curve value
1035 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1038 if (!GetSolver()->ComputeFunction(aFunction)) {
1039 SetErrorCode("Curve driver failed !!!");
1043 catch (Standard_Failure) {
1044 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1045 SetErrorCode(aFail->GetMessageString());
1049 //Make a Python command
1050 GEOM::TPythonDump pd (aFunction);
1051 pd << aCurve << " = geompy.MakeCurveParametric(";
1052 pd << "\"" << thexExpr << "\", ";
1053 pd << "\"" << theyExpr << "\", ";
1054 pd << "\"" << thezExpr << "\", ";
1056 pd << theParamMin <<", ";
1057 pd << theParamMax <<", ";
1058 pd << theParamStep <<", ";
1059 pd << aCurveType.ToCString() <<")";
1065 //=============================================================================
1069 //=============================================================================
1070 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1071 std::list<double> theWorkingPlane)
1075 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1077 //Add a new Sketcher object
1078 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1080 //Add a new Sketcher function
1081 Handle(GEOM_Function) aFunction =
1082 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1083 if (aFunction.IsNull()) return NULL;
1085 //Check if the function is set correctly
1086 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1088 GEOMImpl_ISketcher aCI (aFunction);
1090 TCollection_AsciiString aCommand((char*) theCommand);
1091 aCI.SetCommand(aCommand);
1094 std::list<double>::iterator it = theWorkingPlane.begin();
1095 for (; it != theWorkingPlane.end(); it++, ind++)
1096 aCI.SetWorkingPlane(ind, *it);
1098 //Compute the Sketcher value
1100 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1103 if (!GetSolver()->ComputeFunction(aFunction)) {
1104 SetErrorCode("Sketcher driver failed");
1108 catch (Standard_Failure) {
1109 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1110 SetErrorCode(aFail->GetMessageString());
1114 //Make a Python command
1115 GEOM::TPythonDump pd (aFunction);
1116 pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1118 it = theWorkingPlane.begin();
1120 while (it != theWorkingPlane.end()) {
1121 pd << ", " << (*it++);
1129 //=============================================================================
1133 //=============================================================================
1134 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1138 //Add a new Sketcher object
1139 Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1141 //Add a new Sketcher function
1142 Handle(GEOM_Function) aFunction =
1143 a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
1144 if (aFunction.IsNull()) return NULL;
1146 //Check if the function is set correctly
1147 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1149 GEOMImpl_I3DSketcher aCI (aFunction);
1152 std::list<double>::iterator it = theCoordinates.begin();
1153 for (; it != theCoordinates.end(); it++)
1156 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1158 it = theCoordinates.begin();
1160 for (; it != theCoordinates.end(); it++, ind++)
1161 aCoordsArray->SetValue(ind, *it);
1163 aCI.SetCoordinates(aCoordsArray);
1165 //Compute the Sketcher value
1167 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1170 if (!GetSolver()->ComputeFunction(aFunction)) {
1171 SetErrorCode("3D Sketcher driver failed");
1175 catch (Standard_Failure) {
1176 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1177 SetErrorCode(aFail->GetMessageString());
1181 //Make a Python command
1182 GEOM::TPythonDump pd (aFunction);
1183 pd << a3DSketcher << " = geompy.Make3DSketcher([";
1185 it = theCoordinates.begin();
1187 while (it != theCoordinates.end()) {
1188 pd << ", " << (*it++);
1196 //=============================================================================
1198 * MakeSketcherOnPlane
1200 //=============================================================================
1201 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1202 (const char* theCommand,
1203 Handle(GEOM_Object) theWorkingPlane)
1207 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1209 //Add a new Sketcher object
1210 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1212 //Add a new Sketcher function
1213 Handle(GEOM_Function) aFunction =
1214 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1215 if (aFunction.IsNull()) return NULL;
1217 //Check if the function is set correctly
1218 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1220 GEOMImpl_ISketcher aCI (aFunction);
1222 TCollection_AsciiString aCommand((char*) theCommand);
1223 aCI.SetCommand(aCommand);
1225 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1226 if (aRefPlane.IsNull()) return NULL;
1227 aCI.SetWorkingPlane( aRefPlane );
1229 //Compute the Sketcher value
1231 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1234 if (!GetSolver()->ComputeFunction(aFunction)) {
1235 SetErrorCode("Sketcher driver failed");
1239 catch (Standard_Failure) {
1240 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1241 SetErrorCode(aFail->GetMessageString());
1245 //Make a Python command
1246 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1247 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";