1 // Copyright (C) 2007-2014 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_ICircle.hxx"
55 #include "GEOMImpl_ISpline.hxx"
56 #include "GEOMImpl_IEllipse.hxx"
57 #include "GEOMImpl_IArc.hxx"
58 #include "GEOMImpl_ISketcher.hxx"
59 #include "GEOMImpl_I3DSketcher.hxx"
60 #include "GEOMImpl_ICurveParametric.hxx"
61 #include "GEOMImpl_IIsoline.hxx"
63 #include <Basics_OCCTVersion.hxx>
65 #include "utilities.h"
67 #include <TDF_Tool.hxx>
68 #include <TColStd_HArray1OfReal.hxx>
70 #include <Standard_Failure.hxx>
71 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
74 /* ==================================
75 * =========== PYTHON ==============
76 * ==================================*/
85 PyStdOut_dealloc(PyStdOut *self)
91 PyStdOut_write(PyStdOut *self, PyObject *args)
95 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
99 *(self->out)=*(self->out)+c;
105 static PyMethodDef PyStdOut_methods[] = {
106 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
107 PyDoc_STR("write(string) -> None")},
108 {NULL, NULL} /* sentinel */
111 static PyMemberDef PyStdOut_memberlist[] = {
112 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
113 (char*)"flag indicating that a space needs to be printed; used by print"},
114 {NULL} /* Sentinel */
117 static PyTypeObject PyStdOut_Type = {
118 /* The ob_type field must be initialized in the module init function
119 * to be portable to Windows without using C++. */
120 PyObject_HEAD_INIT(NULL)
123 sizeof(PyStdOut), /*tp_basicsize*/
126 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
133 0, /*tp_as_sequence*/
138 PyObject_GenericGetAttr, /*tp_getattro*/
139 /* softspace is writable: we must supply tp_setattro */
140 PyObject_GenericSetAttr, /* tp_setattro */
142 Py_TPFLAGS_DEFAULT, /*tp_flags*/
146 0, /*tp_richcompare*/
147 0, /*tp_weaklistoffset*/
150 PyStdOut_methods, /*tp_methods*/
151 PyStdOut_memberlist, /*tp_members*/
165 PyObject * newPyStdOut( std::string& out )
168 self = PyObject_New(PyStdOut, &PyStdOut_Type);
173 return (PyObject*)self;
177 ////////////////////////END PYTHON///////////////////////////
178 //=============================================================================
182 //=============================================================================
183 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
184 : GEOM_IOperations(theEngine, theDocID)
186 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
189 //=============================================================================
193 //=============================================================================
194 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
196 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
200 //=============================================================================
204 //=============================================================================
205 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
206 Handle(GEOM_Object) thePnt2,
207 Handle(GEOM_Object) thePnt3)
211 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
213 //Add a new Circle object
214 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
216 //Add a new Circle function for creation a circle relatively to three points
217 Handle(GEOM_Function) aFunction =
218 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
219 if (aFunction.IsNull()) return NULL;
221 //Check if the function is set correctly
222 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
224 GEOMImpl_ICircle aCI (aFunction);
226 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
227 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
228 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
230 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
232 aCI.SetPoint1(aRefPnt1);
233 aCI.SetPoint2(aRefPnt2);
234 aCI.SetPoint3(aRefPnt3);
236 //Compute the Circle value
238 #if OCC_VERSION_LARGE > 0x06010000
241 if (!GetSolver()->ComputeFunction(aFunction)) {
242 SetErrorCode("Circle driver failed");
246 catch (Standard_Failure) {
247 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
248 SetErrorCode(aFail->GetMessageString());
252 //Make a Python command
253 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
254 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
260 //=============================================================================
262 * MakeCircleCenter2Pnt
264 //=============================================================================
265 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
266 Handle(GEOM_Object) thePnt2,
267 Handle(GEOM_Object) thePnt3)
271 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
273 //Add a new Circle object
274 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
276 //Add a new Circle function for creation a circle relatively to center and 2 points
277 Handle(GEOM_Function) aFunction =
278 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
279 if (aFunction.IsNull()) return NULL;
281 //Check if the function is set correctly
282 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
284 GEOMImpl_ICircle aCI (aFunction);
286 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
287 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
288 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
290 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
292 aCI.SetPoint1(aRefPnt1);
293 aCI.SetPoint2(aRefPnt2);
294 aCI.SetPoint3(aRefPnt3);
296 //Compute the Circle value
298 #if OCC_VERSION_LARGE > 0x06010000
301 if (!GetSolver()->ComputeFunction(aFunction)) {
302 SetErrorCode("Circle driver failed");
306 catch (Standard_Failure) {
307 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
308 SetErrorCode(aFail->GetMessageString());
312 //Make a Python command
313 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
314 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
320 //=============================================================================
324 //=============================================================================
325 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
326 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
330 // Not set thePnt means origin of global CS,
331 // Not set theVec means Z axis of global CS
332 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
334 //Add a new Circle object
335 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
337 //Add a new Circle function for creation a circle relatively to point and vector
338 Handle(GEOM_Function) aFunction =
339 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
340 if (aFunction.IsNull()) return NULL;
342 //Check if the function is set correctly
343 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
345 GEOMImpl_ICircle aCI (aFunction);
347 if (!thePnt.IsNull()) {
348 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
349 if (aRefPnt.IsNull()) return NULL;
350 aCI.SetCenter(aRefPnt);
353 if (!theVec.IsNull()) {
354 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
355 if (aRefVec.IsNull()) return NULL;
356 aCI.SetVector(aRefVec);
361 //Compute the Circle value
363 #if OCC_VERSION_LARGE > 0x06010000
366 if (!GetSolver()->ComputeFunction(aFunction)) {
367 SetErrorCode("Circle driver failed");
371 catch (Standard_Failure) {
372 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
373 SetErrorCode(aFail->GetMessageString());
377 //Make a Python command
378 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
379 << thePnt << ", " << theVec << ", " << theR << ")";
385 //=============================================================================
389 //=============================================================================
390 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
391 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
392 double theRMajor, double theRMinor,
393 Handle(GEOM_Object) theVecMaj)
397 // Not set thePnt means origin of global CS,
398 // Not set theVec means Z axis of global CS
399 // Not set theVecMaj means X axis of global CS
400 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
402 //Add a new Ellipse object
403 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
405 //Add a new Ellipse function
406 Handle(GEOM_Function) aFunction =
407 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
408 if (aFunction.IsNull()) return NULL;
410 //Check if the function is set correctly
411 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
413 GEOMImpl_IEllipse aCI (aFunction);
415 if (!thePnt.IsNull()) {
416 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
417 if (aRefPnt.IsNull()) return NULL;
418 aCI.SetCenter(aRefPnt);
421 if (!theVec.IsNull()) {
422 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
423 if (aRefVec.IsNull()) return NULL;
424 aCI.SetVector(aRefVec);
427 aCI.SetRMajor(theRMajor);
428 aCI.SetRMinor(theRMinor);
430 if (!theVecMaj.IsNull()) {
431 Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
432 if (aRefVecMaj.IsNull()) return NULL;
433 aCI.SetVectorMajor(aRefVecMaj);
436 //Compute the Ellipse value
438 #if OCC_VERSION_LARGE > 0x06010000
441 if (!GetSolver()->ComputeFunction(aFunction)) {
442 SetErrorCode("Ellipse driver failed");
446 catch (Standard_Failure) {
447 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
448 SetErrorCode(aFail->GetMessageString());
452 //Make a Python command
453 if (!theVecMaj.IsNull()) {
454 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
455 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
456 << ", " << theVecMaj << ")";
459 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
460 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
467 //=============================================================================
471 //=============================================================================
472 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
473 Handle(GEOM_Object) thePnt2,
474 Handle(GEOM_Object) thePnt3)
478 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
480 //Add a new Circle Arc object
481 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
483 //Add a new Circle Arc function
484 Handle(GEOM_Function) aFunction =
485 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
487 if (aFunction.IsNull()) return NULL;
489 //Check if the function is set correctly
490 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
491 GEOMImpl_IArc aCI (aFunction);
493 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
494 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
495 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
497 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
499 aCI.SetPoint1(aRefPnt1);
500 aCI.SetPoint2(aRefPnt2);
501 aCI.SetPoint3(aRefPnt3);
503 //Compute the Arc value
505 #if OCC_VERSION_LARGE > 0x06010000
508 if (!GetSolver()->ComputeFunction(aFunction)) {
509 SetErrorCode("Arc driver failed");
513 catch (Standard_Failure) {
514 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
515 SetErrorCode(aFail->GetMessageString());
519 //Make a Python command
520 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
521 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
527 //=============================================================================
531 //=============================================================================
532 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
533 Handle(GEOM_Object) thePnt2,
534 Handle(GEOM_Object) thePnt3,
538 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
540 //Add a new Circle Arc object
541 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
543 //Add a new Circle Arc function
544 Handle(GEOM_Function) aFunction =
545 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
546 if (aFunction.IsNull()) return NULL;
548 //Check if the function is set correctly
549 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
551 GEOMImpl_IArc aCI (aFunction);
553 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
554 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
555 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
557 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
559 aCI.SetPoint1(aRefPnt1);
560 aCI.SetPoint2(aRefPnt2);
561 aCI.SetPoint3(aRefPnt3);
562 aCI.SetSense(theSense);
564 //Compute the Arc value
566 #if OCC_VERSION_LARGE > 0x06010000
569 if (!GetSolver()->ComputeFunction(aFunction)) {
570 SetErrorCode("Arc driver failed");
574 catch (Standard_Failure) {
575 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
576 SetErrorCode(aFail->GetMessageString());
579 //Make a Python command
580 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
581 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
587 //=============================================================================
591 //=============================================================================
592 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
593 Handle(GEOM_Object) thePnt2,
594 Handle(GEOM_Object) thePnt3)
598 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
600 //Add a new Circle Arc object
601 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
603 //Add a new Circle Arc function
604 Handle(GEOM_Function) aFunction =
605 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
607 if (aFunction.IsNull()) return NULL;
609 //Check if the function is set correctly
610 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
611 GEOMImpl_IArc aCI (aFunction);
613 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
614 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
615 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
617 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
619 aCI.SetPoint1(aRefPnt1);
620 aCI.SetPoint2(aRefPnt2);
621 aCI.SetPoint3(aRefPnt3);
623 //Compute the Arc value
625 #if OCC_VERSION_LARGE > 0x06010000
628 if (!GetSolver()->ComputeFunction(aFunction)) {
629 SetErrorCode("Arc driver failed");
633 catch (Standard_Failure) {
634 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
635 SetErrorCode(aFail->GetMessageString());
639 //Make a Python command
640 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
641 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
647 //=============================================================================
651 //=============================================================================
652 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
657 //Add a new Polyline object
658 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
660 //Add a new Polyline function for creation a polyline relatively to points set
661 Handle(GEOM_Function) aFunction =
662 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
663 if (aFunction.IsNull()) return NULL;
665 //Check if the function is set correctly
666 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
668 GEOMImpl_IPolyline aCI (aFunction);
670 int aLen = thePoints.size();
672 aCI.SetConstructorType(POINT_CONSTRUCTOR);
675 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
676 for (; it != thePoints.end(); it++, ind++) {
677 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
678 if (aRefPnt.IsNull()) {
679 SetErrorCode("NULL point for Polyline");
682 aCI.SetPoint(ind, aRefPnt);
685 aCI.SetIsClosed(theIsClosed);
687 //Compute the Polyline value
689 #if OCC_VERSION_LARGE > 0x06010000
692 if (!GetSolver()->ComputeFunction(aFunction)) {
693 SetErrorCode("Polyline driver failed");
697 catch (Standard_Failure) {
698 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
699 SetErrorCode(aFail->GetMessageString());
703 //Make a Python command
704 GEOM::TPythonDump pd (aFunction);
705 pd << aPolyline << " = geompy.MakePolyline([";
707 it = thePoints.begin();
709 while (it != thePoints.end()) {
710 pd << ", " << (*it++);
712 pd << "], " << theIsClosed << ")";
718 //=============================================================================
722 //=============================================================================
723 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
724 (std::list<Handle(GEOM_Object)> thePoints,
729 //Add a new Spline object
730 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
732 //Add a new Spline function for creation a bezier curve relatively to points set
733 Handle(GEOM_Function) aFunction =
734 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
735 if (aFunction.IsNull()) return NULL;
737 //Check if the function is set correctly
738 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
740 GEOMImpl_ISpline aCI (aFunction);
742 aCI.SetConstructorType(POINT_CONSTRUCTOR);
744 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
745 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
746 for (; it != thePoints.end(); it++) {
747 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
748 if (aRefPnt.IsNull()) {
749 SetErrorCode("NULL point for Besier curve");
752 aPoints->Append(aRefPnt);
754 aCI.SetPoints(aPoints);
756 aCI.SetIsClosed(theIsClosed);
758 //Compute the Spline value
760 #if OCC_VERSION_LARGE > 0x06010000
763 if (!GetSolver()->ComputeFunction(aFunction)) {
764 SetErrorCode("Spline driver failed");
768 catch (Standard_Failure) {
769 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
770 SetErrorCode(aFail->GetMessageString());
774 //Make a Python command
775 GEOM::TPythonDump pd (aFunction);
776 pd << aSpline << " = geompy.MakeBezier([";
778 it = thePoints.begin();
780 while (it != thePoints.end()) {
781 pd << ", " << (*it++);
783 pd << "], " << theIsClosed << ")";
789 //=============================================================================
791 * MakeSplineInterpolation
793 //=============================================================================
794 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
795 (std::list<Handle(GEOM_Object)> thePoints,
797 bool theDoReordering)
801 //Add a new Spline object
802 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
804 //Add a new Spline function for interpolation type
805 Handle(GEOM_Function) aFunction =
806 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
807 if (aFunction.IsNull()) return NULL;
809 //Check if the function is set correctly
810 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
812 GEOMImpl_ISpline aCI (aFunction);
814 aCI.SetConstructorType(POINT_CONSTRUCTOR);
816 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
817 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
818 for (; it != thePoints.end(); it++) {
819 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
820 if (aRefPnt.IsNull()) {
823 aPoints->Append(aRefPnt);
825 aCI.SetPoints(aPoints);
827 aCI.SetIsClosed(theIsClosed);
828 aCI.SetDoReordering(theDoReordering);
830 //Compute the Spline value
832 #if OCC_VERSION_LARGE > 0x06010000
835 if (!GetSolver()->ComputeFunction(aFunction)) {
836 SetErrorCode("Spline driver failed");
840 catch (Standard_Failure) {
841 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
842 SetErrorCode(aFail->GetMessageString());
846 //Make a Python command
847 GEOM::TPythonDump pd (aFunction);
848 pd << aSpline << " = geompy.MakeInterpol([";
850 it = thePoints.begin();
852 while (it != thePoints.end()) {
853 pd << ", " << (*it++);
855 pd << "], " << theIsClosed << ", " << theDoReordering << ")";
862 //=============================================================================
864 * MakeSplineInterpolWithTangents
866 //=============================================================================
867 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolWithTangents
868 (std::list<Handle(GEOM_Object)> thePoints,
869 Handle(GEOM_Object) theFirstVec,
870 Handle(GEOM_Object) theLastVec)
874 //Add a new Spline object
875 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
877 //Add a new Spline function for interpolation type
878 Handle(GEOM_Function) aFunction =
879 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOL_TANGENTS);
880 if (aFunction.IsNull()) return NULL;
882 //Check if the function is set correctly
883 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
885 GEOMImpl_ISpline aCI (aFunction);
887 aCI.SetConstructorType(POINT_CONSTRUCTOR);
889 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
890 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
891 for (; it != thePoints.end(); it++) {
892 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
893 if (aRefPnt.IsNull()) {
894 SetErrorCode("NULL point for Interpolation");
897 aPoints->Append(aRefPnt);
899 aCI.SetPoints(aPoints);
901 Handle(GEOM_Function) aVec1 = theFirstVec->GetLastFunction();
902 Handle(GEOM_Function) aVec2 = theLastVec->GetLastFunction();
904 if (aVec1.IsNull() || aVec2.IsNull()) return NULL;
906 aCI.SetFirstVector(aVec1);
907 aCI.SetLastVector(aVec2);
909 //Compute the Spline value
911 #if OCC_VERSION_LARGE > 0x06010000
914 if (!GetSolver()->ComputeFunction(aFunction)) {
915 SetErrorCode("Spline driver failed");
919 catch (Standard_Failure) {
920 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
921 SetErrorCode(aFail->GetMessageString());
925 //Make a Python command
926 GEOM::TPythonDump pd (aFunction);
927 pd << aSpline << " = geompy.MakeInterpolWithTangents([";
929 it = thePoints.begin();
931 while (it != thePoints.end()) {
932 pd << ", " << (*it++);
934 pd << "], " << theFirstVec << ", " << theLastVec << ")";
940 //=============================================================================
942 * MakeCurveParametric
944 //=============================================================================
945 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
946 (const char* thexExpr, const char* theyExpr, const char* thezExpr,
947 double theParamMin, double theParamMax, double theParamStep,
948 CurveType theCurveType,
949 int theParamNbStep, bool theNewMethod)
951 TCollection_AsciiString aPyScript;
952 aPyScript +="from math import * \n";
953 aPyScript +="def X(t): \n";
954 aPyScript +=" return ";
955 aPyScript += thexExpr;
957 aPyScript +="def Y(t): \n";
958 aPyScript +=" return ";
959 aPyScript += theyExpr;
962 aPyScript +="def Z(t): \n";
963 aPyScript +=" return ";
964 aPyScript += thezExpr;
969 aPyScript +="def coordCalculator(tmin, tmax, nstep): \n";
970 aPyScript +=" coords = [] \n";
971 aPyScript +=" tstep = (tmax - tmin) / nstep \n";
972 aPyScript +=" n = 0 \n";
973 aPyScript +=" while n <= nstep : \n";
974 aPyScript +=" t = tmin + n*tstep \n";
975 aPyScript +=" coords.append([X(t), Y(t), Z(t)]) \n";
976 aPyScript +=" n = n+1 \n";
977 aPyScript +=" return coords \n";
981 aPyScript +="def coordCalculator(tmin, tmax, tstep): \n";
982 aPyScript +=" coords = [] \n";
983 aPyScript +=" while tmin <= tmax : \n";
984 aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
985 aPyScript +=" tmin = tmin + tstep \n";
986 aPyScript +=" return coords \n";
991 if(theParamMin >= theParamMax) {
992 SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
996 if(!theNewMethod && theParamStep <= 0.0) {
997 SetErrorCode("Value of the step must be positive !!!");
1000 else if(theNewMethod && theParamNbStep < 0) {
1001 SetErrorCode("The number of steps must be positive !!!");
1005 /* Initialize the Python interpreter */
1006 if (! Py_IsInitialized()) {
1007 SetErrorCode("Python interpreter is not initialized !!! ");
1011 PyGILState_STATE gstate;
1012 gstate = PyGILState_Ensure();
1014 PyObject* main_mod = PyImport_AddModule("__main__");
1015 PyObject* main_dict = PyModule_GetDict(main_mod);
1017 PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
1020 SetErrorCode("Error during executing of python script !!!");
1022 PyGILState_Release(gstate);
1028 PyObject * func = NULL;
1029 func = PyObject_GetAttrString(main_mod, "coordCalculator");
1032 SetErrorCode("Can't get function from python module !!!");
1033 PyGILState_Release(gstate);
1039 coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep );
1041 coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
1043 PyObject* new_stderr = NULL;
1045 if (coords == NULL){
1047 std::string err_description="";
1048 new_stderr = newPyStdOut(err_description);
1049 PySys_SetObject((char*)"stderr", new_stderr);
1051 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1052 Py_DECREF(new_stderr);
1053 MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description);
1054 SetErrorCode("Can't evaluate the expressions, please check them !!!");
1055 PyGILState_Release(gstate);
1059 int lsize = PyList_Size( coords );
1062 SetErrorCode("Empty list of the points, please check input parameters !!!");
1066 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, lsize * 3);
1069 for ( Py_ssize_t i = 0; i < lsize; ++i ) {
1070 PyObject* coord = PyList_GetItem( coords, i );
1071 if (coord != NULL) {
1072 for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
1073 PyObject* item = PyList_GetItem(coord, j);
1074 aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
1082 PyGILState_Release(gstate);
1084 Handle(GEOM_Object) aCurve;
1085 Handle(GEOM_Function) aFunction;
1086 TCollection_AsciiString aCurveType;
1088 switch(theCurveType) {
1090 //Add a new Polyline object
1091 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
1093 //Add a new Polyline function for creation a polyline relatively to points set
1094 aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
1095 if (aFunction.IsNull()) return NULL;
1097 //Check if the function is set correctly
1098 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
1100 GEOMImpl_IPolyline aCI (aFunction);
1102 aCI.SetLength(lsize);
1103 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1104 aCI.SetIsClosed(false);
1105 aCI.SetCoordinates(aCoordsArray);
1106 aCurveType = "GEOM.Polyline";
1110 //Add a new Spline object
1111 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1112 //Add a new Spline function for creation a bezier curve relatively to points set
1114 aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
1115 if (aFunction.IsNull()) return NULL;
1117 //Check if the function is set correctly
1118 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1120 GEOMImpl_ISpline aCI (aFunction);
1122 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1123 aCI.SetIsClosed(false);
1124 aCI.SetCoordinates(aCoordsArray);
1125 aCurveType = "GEOM.Bezier";
1128 case Interpolation: {
1129 //Add a new Spline object
1130 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1132 //Add a new Spline function for creation a bezier curve relatively to points set
1133 aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
1134 if (aFunction.IsNull()) return NULL;
1136 //Check if the function is set correctly
1137 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1139 GEOMImpl_ISpline aCI (aFunction);
1140 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1141 aCI.SetIsClosed(false);
1142 aCI.SetDoReordering(false);
1143 aCI.SetCoordinates(aCoordsArray);
1144 aCurveType = "GEOM.Interpolation";
1149 GEOMImpl_ICurveParametric aIP(aFunction);
1150 aIP.SetExprX (thexExpr);
1151 aIP.SetExprY (theyExpr);
1152 aIP.SetExprZ (thezExpr);
1153 aIP.SetParamMin (theParamMin);
1154 aIP.SetParamMax (theParamMax);
1156 aIP.SetParamNbStep(theParamNbStep);
1158 aIP.SetParamStep (theParamStep);
1160 //Compute the Curve value
1162 #if OCC_VERSION_LARGE > 0x06010000
1165 if (!GetSolver()->ComputeFunction(aFunction)) {
1166 SetErrorCode("Curve driver failed !!!");
1170 catch (Standard_Failure) {
1171 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1172 SetErrorCode(aFail->GetMessageString());
1176 //Make a Python command
1177 GEOM::TPythonDump pd (aFunction);
1178 pd << aCurve << " = geompy.MakeCurveParametric(";
1179 pd << "\"" << thexExpr << "\", ";
1180 pd << "\"" << theyExpr << "\", ";
1181 pd << "\"" << thezExpr << "\", ";
1183 pd << theParamMin <<", ";
1184 pd << theParamMax <<", ";
1186 pd << theParamNbStep <<", ";
1188 pd << theParamStep <<", ";
1189 pd << aCurveType.ToCString() <<", ";
1190 pd << theNewMethod <<")";
1196 //=============================================================================
1200 //=============================================================================
1201 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1202 std::list<double> theWorkingPlane)
1206 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1208 //Add a new Sketcher object
1209 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1211 //Add a new Sketcher function
1212 Handle(GEOM_Function) aFunction =
1213 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1214 if (aFunction.IsNull()) return NULL;
1216 //Check if the function is set correctly
1217 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1219 GEOMImpl_ISketcher aCI (aFunction);
1221 TCollection_AsciiString aCommand((char*) theCommand);
1222 aCI.SetCommand(aCommand);
1225 std::list<double>::iterator it = theWorkingPlane.begin();
1226 for (; it != theWorkingPlane.end(); it++, ind++)
1227 aCI.SetWorkingPlane(ind, *it);
1229 //Compute the Sketcher value
1231 #if OCC_VERSION_LARGE > 0x06010000
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 pd (aFunction);
1247 pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1249 it = theWorkingPlane.begin();
1251 while (it != theWorkingPlane.end()) {
1252 pd << ", " << (*it++);
1260 //=============================================================================
1262 * MakeSketcherOnPlane
1264 //=============================================================================
1265 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1266 (const char* theCommand,
1267 Handle(GEOM_Object) theWorkingPlane)
1271 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1273 //Add a new Sketcher object
1274 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1276 //Add a new Sketcher function
1277 Handle(GEOM_Function) aFunction =
1278 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1279 if (aFunction.IsNull()) return NULL;
1281 //Check if the function is set correctly
1282 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1284 GEOMImpl_ISketcher aCI (aFunction);
1286 TCollection_AsciiString aCommand((char*) theCommand);
1287 aCI.SetCommand(aCommand);
1289 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1290 if (aRefPlane.IsNull()) return NULL;
1291 aCI.SetWorkingPlane( aRefPlane );
1293 //Compute the Sketcher value
1295 #if OCC_VERSION_LARGE > 0x06010000
1298 if (!GetSolver()->ComputeFunction(aFunction)) {
1299 SetErrorCode("Sketcher driver failed");
1303 catch (Standard_Failure) {
1304 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1305 SetErrorCode(aFail->GetMessageString());
1309 //Make a Python command
1310 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1311 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
1317 //=============================================================================
1319 * Make3DSketcherCommand
1321 //=============================================================================
1322 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcherCommand (const char* theCommand)
1326 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1328 //Add a new Sketcher object
1329 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1331 //Add a new Sketcher function
1332 Handle(GEOM_Function) aFunction =
1333 aSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COMMAND);
1334 if (aFunction.IsNull()) return NULL;
1336 //Check if the function is set correctly
1337 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1339 GEOMImpl_I3DSketcher aCI (aFunction);
1341 TCollection_AsciiString aCommand ((char*) theCommand);
1342 aCI.SetCommand(aCommand);
1344 //Compute the 3D Sketcher value
1346 #if OCC_VERSION_LARGE > 0x06010000
1349 if (!GetSolver()->ComputeFunction(aFunction)) {
1350 SetErrorCode("3D Sketcher driver failed");
1354 catch (Standard_Failure) {
1355 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1356 SetErrorCode(aFail->GetMessageString());
1360 //Make a Python command
1361 GEOM::TPythonDump pd (aFunction);
1362 pd << aSketcher << " = geompy.Make3DSketcherCommand(\"" << aCommand.ToCString() << "\")";
1368 //=============================================================================
1372 //=============================================================================
1373 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1377 //Add a new Sketcher object
1378 Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1380 //Add a new Sketcher function
1381 Handle(GEOM_Function) aFunction =
1382 a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COORDS);
1383 if (aFunction.IsNull()) return NULL;
1385 //Check if the function is set correctly
1386 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1388 GEOMImpl_I3DSketcher aCI (aFunction);
1391 std::list<double>::iterator it = theCoordinates.begin();
1392 for (; it != theCoordinates.end(); it++)
1395 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1397 it = theCoordinates.begin();
1399 for (; it != theCoordinates.end(); it++, ind++)
1400 aCoordsArray->SetValue(ind, *it);
1402 aCI.SetCoordinates(aCoordsArray);
1404 //Compute the Sketcher value
1406 #if OCC_VERSION_LARGE > 0x06010000
1409 if (!GetSolver()->ComputeFunction(aFunction)) {
1410 SetErrorCode("3D Sketcher driver failed");
1414 catch (Standard_Failure) {
1415 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1416 SetErrorCode(aFail->GetMessageString());
1420 //Make a Python command
1421 GEOM::TPythonDump pd (aFunction);
1422 pd << a3DSketcher << " = geompy.Make3DSketcher([";
1424 it = theCoordinates.begin();
1426 while (it != theCoordinates.end()) {
1427 pd << ", " << (*it++);
1435 //=============================================================================
1439 //=============================================================================
1440 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeIsoline
1441 (const Handle(GEOM_Object) &theFace,
1443 const double theParameter)
1447 if (theFace.IsNull()) {
1451 //Add a new Spline object
1452 Handle(GEOM_Object) anIsoline =
1453 GetEngine()->AddObject(GetDocID(), GEOM_ISOLINE);
1455 //Add a new Spline function for interpolation type
1456 Handle(GEOM_Function) aFunction =
1457 anIsoline->AddFunction(GEOMImpl_ShapeDriver::GetID(), SHAPE_ISOLINE);
1459 if (aFunction.IsNull()) {
1463 //Check if the function is set correctly
1464 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) {
1468 GEOMImpl_IIsoline aCI (aFunction);
1469 Handle(GEOM_Function) aRefFace = theFace->GetLastFunction();
1471 if (aRefFace.IsNull()) {
1475 aCI.SetFace(aRefFace);
1476 aCI.SetIsUIso(IsUIso);
1477 aCI.SetParameter(theParameter);
1479 //Compute the isoline curve
1481 #if OCC_VERSION_LARGE > 0x06010000
1484 if (!GetSolver()->ComputeFunction(aFunction)) {
1485 SetErrorCode("Shape driver failed");
1489 catch (Standard_Failure) {
1490 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1491 SetErrorCode(aFail->GetMessageString());
1495 //Make a Python command
1496 GEOM::TPythonDump (aFunction) << anIsoline << " = geompy.MakeIsoline( "
1497 << theFace << ", " << IsUIso << ", " << theParameter << " )";