1 // Copyright (C) 2007-2012 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 // E.A. : On windows with python 2.6, there is a conflict
24 // E.A. : between pymath.h and Standard_math.h which define
25 // E.A. : some same symbols : acosh, asinh, ...
26 #include <Standard_math.hxx>
31 #include <structmember.h>
36 #include <Standard_Stream.hxx>
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_SketcherDriver.hxx>
50 #include <GEOMImpl_3DSketcherDriver.hxx>
52 #include <GEOMImpl_IPolyline.hxx>
53 #include <GEOMImpl_ICircle.hxx>
54 #include <GEOMImpl_ISpline.hxx>
55 #include <GEOMImpl_IEllipse.hxx>
56 #include <GEOMImpl_IArc.hxx>
57 #include <GEOMImpl_ISketcher.hxx>
58 #include <GEOMImpl_I3DSketcher.hxx>
60 #include <Basics_OCCTVersion.hxx>
62 #include "utilities.h"
64 #include <TDF_Tool.hxx>
65 #include <TColStd_HArray1OfReal.hxx>
67 #include <Standard_Failure.hxx>
68 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
71 /* ==================================
72 * =========== PYTHON ==============
73 * ==================================*/
82 PyStdOut_dealloc(PyStdOut *self)
88 PyStdOut_write(PyStdOut *self, PyObject *args)
92 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
96 *(self->out)=*(self->out)+c;
102 static PyMethodDef PyStdOut_methods[] = {
103 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
104 PyDoc_STR("write(string) -> None")},
105 {NULL, NULL} /* sentinel */
108 static PyMemberDef PyStdOut_memberlist[] = {
109 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
110 (char*)"flag indicating that a space needs to be printed; used by print"},
111 {NULL} /* Sentinel */
114 static PyTypeObject PyStdOut_Type = {
115 /* The ob_type field must be initialized in the module init function
116 * to be portable to Windows without using C++. */
117 PyObject_HEAD_INIT(NULL)
120 sizeof(PyStdOut), /*tp_basicsize*/
123 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
130 0, /*tp_as_sequence*/
135 PyObject_GenericGetAttr, /*tp_getattro*/
136 /* softspace is writable: we must supply tp_setattro */
137 PyObject_GenericSetAttr, /* tp_setattro */
139 Py_TPFLAGS_DEFAULT, /*tp_flags*/
143 0, /*tp_richcompare*/
144 0, /*tp_weaklistoffset*/
147 PyStdOut_methods, /*tp_methods*/
148 PyStdOut_memberlist, /*tp_members*/
162 PyObject * newPyStdOut( std::string& out )
165 self = PyObject_New(PyStdOut, &PyStdOut_Type);
170 return (PyObject*)self;
174 ////////////////////////END PYTHON///////////////////////////
175 //=============================================================================
179 //=============================================================================
180 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
181 : GEOM_IOperations(theEngine, theDocID)
183 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
186 //=============================================================================
190 //=============================================================================
191 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
193 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
197 //=============================================================================
201 //=============================================================================
202 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
203 Handle(GEOM_Object) thePnt2,
204 Handle(GEOM_Object) thePnt3)
208 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
210 //Add a new Circle object
211 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
213 //Add a new Circle function for creation a circle relatively to three points
214 Handle(GEOM_Function) aFunction =
215 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
216 if (aFunction.IsNull()) return NULL;
218 //Check if the function is set correctly
219 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
221 GEOMImpl_ICircle aCI (aFunction);
223 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
224 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
225 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
227 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
229 aCI.SetPoint1(aRefPnt1);
230 aCI.SetPoint2(aRefPnt2);
231 aCI.SetPoint3(aRefPnt3);
233 //Compute the Circle value
235 #if OCC_VERSION_LARGE > 0x06010000
238 if (!GetSolver()->ComputeFunction(aFunction)) {
239 SetErrorCode("Circle driver failed");
243 catch (Standard_Failure) {
244 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
245 SetErrorCode(aFail->GetMessageString());
249 //Make a Python command
250 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
251 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
257 //=============================================================================
259 * MakeCircleCenter2Pnt
261 //=============================================================================
262 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
263 Handle(GEOM_Object) thePnt2,
264 Handle(GEOM_Object) thePnt3)
268 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
270 //Add a new Circle object
271 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
273 //Add a new Circle function for creation a circle relatively to center and 2 points
274 Handle(GEOM_Function) aFunction =
275 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
276 if (aFunction.IsNull()) return NULL;
278 //Check if the function is set correctly
279 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
281 GEOMImpl_ICircle aCI (aFunction);
283 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
284 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
285 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
287 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
289 aCI.SetPoint1(aRefPnt1);
290 aCI.SetPoint2(aRefPnt2);
291 aCI.SetPoint3(aRefPnt3);
293 //Compute the Circle value
295 #if OCC_VERSION_LARGE > 0x06010000
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
360 #if OCC_VERSION_LARGE > 0x06010000
363 if (!GetSolver()->ComputeFunction(aFunction)) {
364 SetErrorCode("Circle driver failed");
368 catch (Standard_Failure) {
369 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
370 SetErrorCode(aFail->GetMessageString());
374 //Make a Python command
375 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
376 << thePnt << ", " << theVec << ", " << theR << ")";
382 //=============================================================================
386 //=============================================================================
387 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
388 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
389 double theRMajor, double theRMinor,
390 Handle(GEOM_Object) theVecMaj)
394 // Not set thePnt means origin of global CS,
395 // Not set theVec means Z axis of global CS
396 // Not set theVecMaj means X axis of global CS
397 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
399 //Add a new Ellipse object
400 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
402 //Add a new Ellipse function
403 Handle(GEOM_Function) aFunction =
404 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
405 if (aFunction.IsNull()) return NULL;
407 //Check if the function is set correctly
408 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
410 GEOMImpl_IEllipse aCI (aFunction);
412 if (!thePnt.IsNull()) {
413 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
414 if (aRefPnt.IsNull()) return NULL;
415 aCI.SetCenter(aRefPnt);
418 if (!theVec.IsNull()) {
419 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
420 if (aRefVec.IsNull()) return NULL;
421 aCI.SetVector(aRefVec);
424 aCI.SetRMajor(theRMajor);
425 aCI.SetRMinor(theRMinor);
427 if (!theVecMaj.IsNull()) {
428 Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
429 if (aRefVecMaj.IsNull()) return NULL;
430 aCI.SetVectorMajor(aRefVecMaj);
433 //Compute the Ellipse value
435 #if OCC_VERSION_LARGE > 0x06010000
438 if (!GetSolver()->ComputeFunction(aFunction)) {
439 SetErrorCode("Ellipse driver failed");
443 catch (Standard_Failure) {
444 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
445 SetErrorCode(aFail->GetMessageString());
449 //Make a Python command
450 if (!theVecMaj.IsNull()) {
451 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
452 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
453 << ", " << theVecMaj << ")";
456 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
457 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
464 //=============================================================================
468 //=============================================================================
469 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
470 Handle(GEOM_Object) thePnt2,
471 Handle(GEOM_Object) thePnt3)
475 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
477 //Add a new Circle Arc object
478 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
480 //Add a new Circle Arc function
481 Handle(GEOM_Function) aFunction =
482 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
484 if (aFunction.IsNull()) return NULL;
486 //Check if the function is set correctly
487 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
488 GEOMImpl_IArc aCI (aFunction);
490 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
491 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
492 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
494 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
496 aCI.SetPoint1(aRefPnt1);
497 aCI.SetPoint2(aRefPnt2);
498 aCI.SetPoint3(aRefPnt3);
500 //Compute the Arc value
502 #if OCC_VERSION_LARGE > 0x06010000
505 if (!GetSolver()->ComputeFunction(aFunction)) {
506 SetErrorCode("Arc driver failed");
510 catch (Standard_Failure) {
511 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
512 SetErrorCode(aFail->GetMessageString());
516 //Make a Python command
517 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
518 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
524 //=============================================================================
528 //=============================================================================
529 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
530 Handle(GEOM_Object) thePnt2,
531 Handle(GEOM_Object) thePnt3,
535 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
537 //Add a new Circle Arc object
538 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
540 //Add a new Circle Arc function
541 Handle(GEOM_Function) aFunction =
542 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
543 if (aFunction.IsNull()) return NULL;
545 //Check if the function is set correctly
546 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
548 GEOMImpl_IArc aCI (aFunction);
550 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
551 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
552 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
554 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
556 aCI.SetPoint1(aRefPnt1);
557 aCI.SetPoint2(aRefPnt2);
558 aCI.SetPoint3(aRefPnt3);
559 aCI.SetSense(theSense);
561 //Compute the Arc value
563 #if OCC_VERSION_LARGE > 0x06010000
566 if (!GetSolver()->ComputeFunction(aFunction)) {
567 SetErrorCode("Arc driver failed");
571 catch (Standard_Failure) {
572 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
573 SetErrorCode(aFail->GetMessageString());
576 //Make a Python command
577 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
578 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
584 //=============================================================================
588 //=============================================================================
589 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
590 Handle(GEOM_Object) thePnt2,
591 Handle(GEOM_Object) thePnt3)
595 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
597 //Add a new Circle Arc object
598 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
600 //Add a new Circle Arc function
601 Handle(GEOM_Function) aFunction =
602 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
604 if (aFunction.IsNull()) return NULL;
606 //Check if the function is set correctly
607 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
608 GEOMImpl_IArc aCI (aFunction);
610 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
611 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
612 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
614 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
616 aCI.SetPoint1(aRefPnt1);
617 aCI.SetPoint2(aRefPnt2);
618 aCI.SetPoint3(aRefPnt3);
620 //Compute the Arc value
622 #if OCC_VERSION_LARGE > 0x06010000
625 if (!GetSolver()->ComputeFunction(aFunction)) {
626 SetErrorCode("Arc driver failed");
630 catch (Standard_Failure) {
631 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
632 SetErrorCode(aFail->GetMessageString());
636 //Make a Python command
637 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
638 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
644 //=============================================================================
648 //=============================================================================
649 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
654 //Add a new Polyline object
655 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
657 //Add a new Polyline function for creation a polyline relatively to points set
658 Handle(GEOM_Function) aFunction =
659 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
660 if (aFunction.IsNull()) return NULL;
662 //Check if the function is set correctly
663 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
665 GEOMImpl_IPolyline aCI (aFunction);
667 int aLen = thePoints.size();
669 aCI.SetConstructorType(POINT_CONSTRUCTOR);
672 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
673 for (; it != thePoints.end(); it++, ind++) {
674 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
675 if (aRefPnt.IsNull()) {
676 SetErrorCode("NULL point for Polyline");
679 aCI.SetPoint(ind, aRefPnt);
682 aCI.SetIsClosed(theIsClosed);
684 //Compute the Polyline value
686 #if OCC_VERSION_LARGE > 0x06010000
689 if (!GetSolver()->ComputeFunction(aFunction)) {
690 SetErrorCode("Polyline driver failed");
694 catch (Standard_Failure) {
695 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
696 SetErrorCode(aFail->GetMessageString());
700 //Make a Python command
701 GEOM::TPythonDump pd (aFunction);
702 pd << aPolyline << " = geompy.MakePolyline([";
704 it = thePoints.begin();
706 while (it != thePoints.end()) {
707 pd << ", " << (*it++);
709 pd << "], " << theIsClosed << ")";
715 //=============================================================================
719 //=============================================================================
720 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
721 (std::list<Handle(GEOM_Object)> thePoints,
726 //Add a new Spline object
727 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
729 //Add a new Spline function for creation a bezier curve relatively to points set
730 Handle(GEOM_Function) aFunction =
731 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
732 if (aFunction.IsNull()) return NULL;
734 //Check if the function is set correctly
735 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
737 GEOMImpl_ISpline aCI (aFunction);
739 aCI.SetConstructorType(POINT_CONSTRUCTOR);
741 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
742 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
743 for (; it != thePoints.end(); it++) {
744 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
745 if (aRefPnt.IsNull()) {
746 SetErrorCode("NULL point for Besier curve");
749 aPoints->Append(aRefPnt);
751 aCI.SetPoints(aPoints);
753 aCI.SetIsClosed(theIsClosed);
755 //Compute the Spline value
757 #if OCC_VERSION_LARGE > 0x06010000
760 if (!GetSolver()->ComputeFunction(aFunction)) {
761 SetErrorCode("Spline driver failed");
765 catch (Standard_Failure) {
766 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
767 SetErrorCode(aFail->GetMessageString());
771 //Make a Python command
772 GEOM::TPythonDump pd (aFunction);
773 pd << aSpline << " = geompy.MakeBezier([";
775 it = thePoints.begin();
777 while (it != thePoints.end()) {
778 pd << ", " << (*it++);
780 pd << "], " << theIsClosed << ")";
786 //=============================================================================
788 * MakeSplineInterpolation
790 //=============================================================================
791 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
792 (std::list<Handle(GEOM_Object)> thePoints,
794 bool theDoReordering)
798 //Add a new Spline object
799 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
801 //Add a new Spline function for interpolation type
802 Handle(GEOM_Function) aFunction =
803 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
804 if (aFunction.IsNull()) return NULL;
806 //Check if the function is set correctly
807 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
809 GEOMImpl_ISpline aCI (aFunction);
811 aCI.SetConstructorType(POINT_CONSTRUCTOR);
813 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
814 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
815 for (; it != thePoints.end(); it++) {
816 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
817 if (aRefPnt.IsNull()) {
820 aPoints->Append(aRefPnt);
822 aCI.SetPoints(aPoints);
824 aCI.SetIsClosed(theIsClosed);
825 aCI.SetDoReordering(theDoReordering);
827 //Compute the Spline value
829 #if OCC_VERSION_LARGE > 0x06010000
832 if (!GetSolver()->ComputeFunction(aFunction)) {
833 SetErrorCode("Spline driver failed");
837 catch (Standard_Failure) {
838 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
839 SetErrorCode(aFail->GetMessageString());
843 //Make a Python command
844 GEOM::TPythonDump pd (aFunction);
845 pd << aSpline << " = geompy.MakeInterpol([";
847 it = thePoints.begin();
849 while (it != thePoints.end()) {
850 pd << ", " << (*it++);
852 pd << "], " << theIsClosed << ", " << theDoReordering << ")";
859 //=============================================================================
861 * MakeSplineInterpolWithTangents
863 //=============================================================================
864 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolWithTangents
865 (std::list<Handle(GEOM_Object)> thePoints,
866 Handle(GEOM_Object) theFirstVec,
867 Handle(GEOM_Object) theLastVec)
871 //Add a new Spline object
872 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
874 //Add a new Spline function for interpolation type
875 Handle(GEOM_Function) aFunction =
876 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOL_TANGENTS);
877 if (aFunction.IsNull()) return NULL;
879 //Check if the function is set correctly
880 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
882 GEOMImpl_ISpline aCI (aFunction);
884 aCI.SetConstructorType(POINT_CONSTRUCTOR);
886 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
887 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
888 for (; it != thePoints.end(); it++) {
889 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
890 if (aRefPnt.IsNull()) {
891 SetErrorCode("NULL point for Interpolation");
894 aPoints->Append(aRefPnt);
896 aCI.SetPoints(aPoints);
898 Handle(GEOM_Function) aVec1 = theFirstVec->GetLastFunction();
899 Handle(GEOM_Function) aVec2 = theLastVec->GetLastFunction();
901 if (aVec1.IsNull() || aVec2.IsNull()) return NULL;
903 aCI.SetFirstVector(aVec1);
904 aCI.SetLastVector(aVec2);
906 //Compute the Spline value
908 #if OCC_VERSION_LARGE > 0x06010000
911 if (!GetSolver()->ComputeFunction(aFunction)) {
912 SetErrorCode("Spline driver failed");
916 catch (Standard_Failure) {
917 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
918 SetErrorCode(aFail->GetMessageString());
922 //Make a Python command
923 GEOM::TPythonDump pd (aFunction);
924 pd << aSpline << " = geompy.MakeInterpolWithTangents([";
926 it = thePoints.begin();
928 while (it != thePoints.end()) {
929 pd << ", " << (*it++);
931 pd << "], " << theFirstVec << ", " << theLastVec << ")";
937 //=============================================================================
939 * MakeCurveParametric
941 //=============================================================================
942 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
943 (const char* thexExpr, const char* theyExpr, const char* thezExpr,
944 double theParamMin, double theParamMax, double theParamStep,
945 CurveType theCurveType,
946 int theParamNbStep, bool theNewMethod)
948 TCollection_AsciiString aPyScript;
949 aPyScript +="from math import * \n";
950 aPyScript +="def X(t): \n";
951 aPyScript +=" return ";
952 aPyScript += thexExpr;
954 aPyScript +="def Y(t): \n";
955 aPyScript +=" return ";
956 aPyScript += theyExpr;
959 aPyScript +="def Z(t): \n";
960 aPyScript +=" return ";
961 aPyScript += thezExpr;
966 aPyScript +="def coordCalculator(tmin, tmax, nstep): \n";
967 aPyScript +=" coords = [] \n";
968 aPyScript +=" tstep = (tmax - tmin) / nstep \n";
969 aPyScript +=" n = 0 \n";
970 aPyScript +=" while n <= nstep : \n";
971 aPyScript +=" t = tmin + n*tstep \n";
972 aPyScript +=" coords.append([X(t), Y(t), Z(t)]) \n";
973 aPyScript +=" n = n+1 \n";
974 aPyScript +=" return coords \n";
978 aPyScript +="def coordCalculator(tmin, tmax, tstep): \n";
979 aPyScript +=" coords = [] \n";
980 aPyScript +=" while tmin <= tmax : \n";
981 aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
982 aPyScript +=" tmin = tmin + tstep \n";
983 aPyScript +=" return coords \n";
988 if(theParamMin >= theParamMax) {
989 SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
993 if(!theNewMethod && theParamStep <= 0.0) {
994 SetErrorCode("Value of the step must be positive !!!");
997 else if(theNewMethod && theParamNbStep < 0) {
998 SetErrorCode("The number of steps must be positive !!!");
1002 /* Initialize the Python interpreter */
1003 if (! Py_IsInitialized()) {
1004 SetErrorCode("Python interpreter is not initialized !!! ");
1008 PyGILState_STATE gstate;
1009 gstate = PyGILState_Ensure();
1011 PyObject* main_mod = PyImport_AddModule("__main__");
1012 PyObject* main_dict = PyModule_GetDict(main_mod);
1014 PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
1017 SetErrorCode("Error during executing of python script !!!");
1019 PyGILState_Release(gstate);
1025 PyObject * func = NULL;
1026 func = PyObject_GetAttrString(main_mod, "coordCalculator");
1029 SetErrorCode("Can't get function from python module !!!");
1030 PyGILState_Release(gstate);
1036 coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep );
1038 coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
1040 PyObject* new_stderr = NULL;
1042 if (coords == NULL){
1044 std::string err_description="";
1045 new_stderr = newPyStdOut(err_description);
1046 PySys_SetObject((char*)"stderr", new_stderr);
1048 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1049 Py_DECREF(new_stderr);
1050 MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description);
1051 SetErrorCode("Can't evaluate the expressions, please check them !!!");
1052 PyGILState_Release(gstate);
1056 int lsize = PyList_Size( coords );
1059 SetErrorCode("Empty list of the points, please check input parameters !!!");
1063 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, lsize * 3);
1066 for ( Py_ssize_t i = 0; i < lsize; ++i ) {
1067 PyObject* coord = PyList_GetItem( coords, i );
1068 if (coord != NULL) {
1069 for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
1070 PyObject* item = PyList_GetItem(coord, j);
1071 aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
1079 PyGILState_Release(gstate);
1081 Handle(GEOM_Object) aCurve;
1082 Handle(GEOM_Function) aFunction;
1083 TCollection_AsciiString aCurveType;
1085 switch(theCurveType) {
1087 //Add a new Polyline object
1088 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
1090 //Add a new Polyline function for creation a polyline relatively to points set
1091 aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
1092 if (aFunction.IsNull()) return NULL;
1094 //Check if the function is set correctly
1095 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
1097 GEOMImpl_IPolyline aCI (aFunction);
1099 aCI.SetLength(lsize);
1100 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1101 aCI.SetIsClosed(false);
1102 aCI.SetCoordinates(aCoordsArray);
1103 aCurveType = "geompy.GEOM.Polyline";
1107 //Add a new Spline object
1108 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1109 //Add a new Spline function for creation a bezier curve relatively to points set
1111 aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
1112 if (aFunction.IsNull()) return NULL;
1114 //Check if the function is set correctly
1115 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1117 GEOMImpl_ISpline aCI (aFunction);
1119 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1120 aCI.SetIsClosed(false);
1121 aCI.SetCoordinates(aCoordsArray);
1122 aCurveType = "geompy.GEOM.Bezier";
1125 case Interpolation: {
1126 //Add a new Spline object
1127 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1129 //Add a new Spline function for creation a bezier curve relatively to points set
1130 aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
1131 if (aFunction.IsNull()) return NULL;
1133 //Check if the function is set correctly
1134 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1136 GEOMImpl_ISpline aCI (aFunction);
1137 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1138 aCI.SetIsClosed(false);
1139 aCI.SetDoReordering(false);
1140 aCI.SetCoordinates(aCoordsArray);
1141 aCurveType = "geompy.GEOM.Interpolation";
1146 //Compute the Curve value
1148 #if OCC_VERSION_LARGE > 0x06010000
1151 if (!GetSolver()->ComputeFunction(aFunction)) {
1152 SetErrorCode("Curve driver failed !!!");
1156 catch (Standard_Failure) {
1157 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1158 SetErrorCode(aFail->GetMessageString());
1162 //Make a Python command
1163 GEOM::TPythonDump pd (aFunction);
1164 pd << aCurve << " = geompy.MakeCurveParametric(";
1165 pd << "\"" << thexExpr << "\", ";
1166 pd << "\"" << theyExpr << "\", ";
1167 pd << "\"" << thezExpr << "\", ";
1169 pd << theParamMin <<", ";
1170 pd << theParamMax <<", ";
1172 pd << theParamNbStep <<", ";
1174 pd << theParamStep <<", ";
1175 pd << aCurveType.ToCString() <<", ";
1176 pd << theNewMethod <<")";
1182 //=============================================================================
1186 //=============================================================================
1187 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1188 std::list<double> theWorkingPlane)
1192 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1194 //Add a new Sketcher object
1195 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1197 //Add a new Sketcher function
1198 Handle(GEOM_Function) aFunction =
1199 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1200 if (aFunction.IsNull()) return NULL;
1202 //Check if the function is set correctly
1203 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1205 GEOMImpl_ISketcher aCI (aFunction);
1207 TCollection_AsciiString aCommand((char*) theCommand);
1208 aCI.SetCommand(aCommand);
1211 std::list<double>::iterator it = theWorkingPlane.begin();
1212 for (; it != theWorkingPlane.end(); it++, ind++)
1213 aCI.SetWorkingPlane(ind, *it);
1215 //Compute the Sketcher value
1217 #if OCC_VERSION_LARGE > 0x06010000
1220 if (!GetSolver()->ComputeFunction(aFunction)) {
1221 SetErrorCode("Sketcher driver failed");
1225 catch (Standard_Failure) {
1226 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1227 SetErrorCode(aFail->GetMessageString());
1231 //Make a Python command
1232 GEOM::TPythonDump pd (aFunction);
1233 pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1235 it = theWorkingPlane.begin();
1237 while (it != theWorkingPlane.end()) {
1238 pd << ", " << (*it++);
1246 //=============================================================================
1248 * MakeSketcherOnPlane
1250 //=============================================================================
1251 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1252 (const char* theCommand,
1253 Handle(GEOM_Object) theWorkingPlane)
1257 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1259 //Add a new Sketcher object
1260 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1262 //Add a new Sketcher function
1263 Handle(GEOM_Function) aFunction =
1264 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1265 if (aFunction.IsNull()) return NULL;
1267 //Check if the function is set correctly
1268 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1270 GEOMImpl_ISketcher aCI (aFunction);
1272 TCollection_AsciiString aCommand((char*) theCommand);
1273 aCI.SetCommand(aCommand);
1275 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1276 if (aRefPlane.IsNull()) return NULL;
1277 aCI.SetWorkingPlane( aRefPlane );
1279 //Compute the Sketcher value
1281 #if OCC_VERSION_LARGE > 0x06010000
1284 if (!GetSolver()->ComputeFunction(aFunction)) {
1285 SetErrorCode("Sketcher driver failed");
1289 catch (Standard_Failure) {
1290 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1291 SetErrorCode(aFail->GetMessageString());
1295 //Make a Python command
1296 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1297 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
1303 //=============================================================================
1305 * Make3DSketcherCommand
1307 //=============================================================================
1308 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcherCommand (const char* theCommand)
1312 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1314 //Add a new Sketcher object
1315 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1317 //Add a new Sketcher function
1318 Handle(GEOM_Function) aFunction =
1319 aSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COMMAND);
1320 if (aFunction.IsNull()) return NULL;
1322 //Check if the function is set correctly
1323 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1325 GEOMImpl_I3DSketcher aCI (aFunction);
1327 TCollection_AsciiString aCommand ((char*) theCommand);
1328 aCI.SetCommand(aCommand);
1330 //Compute the 3D Sketcher value
1332 #if OCC_VERSION_LARGE > 0x06010000
1335 if (!GetSolver()->ComputeFunction(aFunction)) {
1336 SetErrorCode("3D Sketcher driver failed");
1340 catch (Standard_Failure) {
1341 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1342 SetErrorCode(aFail->GetMessageString());
1346 //Make a Python command
1347 GEOM::TPythonDump pd (aFunction);
1348 pd << aSketcher << " = geompy.Make3DSketcherCommand(\"" << aCommand.ToCString() << "\")";
1354 //=============================================================================
1358 //=============================================================================
1359 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1363 //Add a new Sketcher object
1364 Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1366 //Add a new Sketcher function
1367 Handle(GEOM_Function) aFunction =
1368 a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COORDS);
1369 if (aFunction.IsNull()) return NULL;
1371 //Check if the function is set correctly
1372 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1374 GEOMImpl_I3DSketcher aCI (aFunction);
1377 std::list<double>::iterator it = theCoordinates.begin();
1378 for (; it != theCoordinates.end(); it++)
1381 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1383 it = theCoordinates.begin();
1385 for (; it != theCoordinates.end(); it++, ind++)
1386 aCoordsArray->SetValue(ind, *it);
1388 aCI.SetCoordinates(aCoordsArray);
1390 //Compute the Sketcher value
1392 #if OCC_VERSION_LARGE > 0x06010000
1395 if (!GetSolver()->ComputeFunction(aFunction)) {
1396 SetErrorCode("3D Sketcher driver failed");
1400 catch (Standard_Failure) {
1401 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1402 SetErrorCode(aFail->GetMessageString());
1406 //Make a Python command
1407 GEOM::TPythonDump pd (aFunction);
1408 pd << a3DSketcher << " = geompy.Make3DSketcher([";
1410 it = theCoordinates.begin();
1412 while (it != theCoordinates.end()) {
1413 pd << ", " << (*it++);