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 int aLen = thePoints.size();
741 aCI.SetConstructorType(POINT_CONSTRUCTOR);
744 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
745 for (; it != thePoints.end(); it++, ind++) {
746 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
748 if (aRefPnt.IsNull()) return NULL;
750 aCI.SetPoint(ind, aRefPnt);
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 creation a bezier curve relatively to points set
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 int aLen = thePoints.size();
812 aCI.SetConstructorType(POINT_CONSTRUCTOR);
816 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
817 for (; it != thePoints.end(); it++, ind++) {
818 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
820 if (aRefPnt.IsNull()) return NULL;
822 aCI.SetPoint(ind, aRefPnt);
825 aCI.SetIsClosed(theIsClosed);
826 aCI.SetDoReordering(theDoReordering);
828 //Compute the Spline value
830 #if OCC_VERSION_LARGE > 0x06010000
833 if (!GetSolver()->ComputeFunction(aFunction)) {
834 SetErrorCode("Spline driver failed");
838 catch (Standard_Failure) {
839 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
840 SetErrorCode(aFail->GetMessageString());
844 //Make a Python command
845 GEOM::TPythonDump pd (aFunction);
846 pd << aSpline << " = geompy.MakeInterpol([";
848 it = thePoints.begin();
850 while (it != thePoints.end()) {
851 pd << ", " << (*it++);
853 pd << "], " << theIsClosed << ", " << theDoReordering << ")";
859 //=============================================================================
861 * MakeCurveParametric
863 //=============================================================================
864 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
865 (const char* thexExpr, const char* theyExpr, const char* thezExpr,
866 double theParamMin, double theParamMax, double theParamStep,
867 CurveType theCurveType,
868 int theParamNbStep, bool theNewMethod)
870 TCollection_AsciiString aPyScript;
871 aPyScript +="from math import * \n";
872 aPyScript +="def X(t): \n";
873 aPyScript +=" return ";
874 aPyScript += thexExpr;
876 aPyScript +="def Y(t): \n";
877 aPyScript +=" return ";
878 aPyScript += theyExpr;
881 aPyScript +="def Z(t): \n";
882 aPyScript +=" return ";
883 aPyScript += thezExpr;
888 aPyScript +="def coordCalculator(tmin, tmax, nstep): \n";
889 aPyScript +=" coords = [] \n";
890 aPyScript +=" tstep = (tmax - tmin) / nstep \n";
891 aPyScript +=" n = 0 \n";
892 aPyScript +=" while n <= nstep : \n";
893 aPyScript +=" t = tmin + n*tstep \n";
894 aPyScript +=" coords.append([X(t), Y(t), Z(t)]) \n";
895 aPyScript +=" n = n+1 \n";
896 aPyScript +=" return coords \n";
900 aPyScript +="def coordCalculator(tmin, tmax, tstep): \n";
901 aPyScript +=" coords = [] \n";
902 aPyScript +=" while tmin <= tmax : \n";
903 aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
904 aPyScript +=" tmin = tmin + tstep \n";
905 aPyScript +=" return coords \n";
910 if(theParamMin >= theParamMax) {
911 SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
915 if(!theNewMethod && theParamStep <= 0.0) {
916 SetErrorCode("Value of the step must be positive !!!");
919 else if(theNewMethod && theParamNbStep < 0) {
920 SetErrorCode("The number of steps must be positive !!!");
924 /* Initialize the Python interpreter */
925 if (! Py_IsInitialized()) {
926 SetErrorCode("Python interpreter is not initialized !!! ");
930 PyGILState_STATE gstate;
931 gstate = PyGILState_Ensure();
933 PyObject* main_mod = PyImport_AddModule("__main__");
934 PyObject* main_dict = PyModule_GetDict(main_mod);
936 PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
939 SetErrorCode("Error during executing of python script !!!");
941 PyGILState_Release(gstate);
947 PyObject * func = NULL;
948 func = PyObject_GetAttrString(main_mod, "coordCalculator");
951 SetErrorCode("Can't get function from python module !!!");
952 PyGILState_Release(gstate);
958 coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep );
960 coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
962 PyObject* new_stderr = NULL;
966 std::string err_description="";
967 new_stderr = newPyStdOut(err_description);
968 PySys_SetObject((char*)"stderr", new_stderr);
970 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
971 Py_DECREF(new_stderr);
972 MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description);
973 SetErrorCode("Can't evaluate the expressions, please check them !!!");
974 PyGILState_Release(gstate);
978 int lsize = PyList_Size( coords );
981 SetErrorCode("Empty list of the points, please check input parameters !!!");
985 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, lsize * 3);
988 for ( Py_ssize_t i = 0; i < lsize; ++i ) {
989 PyObject* coord = PyList_GetItem( coords, i );
991 for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
992 PyObject* item = PyList_GetItem(coord, j);
993 aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
1001 PyGILState_Release(gstate);
1003 Handle(GEOM_Object) aCurve;
1004 Handle(GEOM_Function) aFunction;
1005 TCollection_AsciiString aCurveType;
1007 switch(theCurveType) {
1009 //Add a new Polyline object
1010 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
1012 //Add a new Polyline function for creation a polyline relatively to points set
1013 aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
1014 if (aFunction.IsNull()) return NULL;
1016 //Check if the function is set correctly
1017 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
1019 GEOMImpl_IPolyline aCI (aFunction);
1021 aCI.SetLength(lsize);
1022 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1023 aCI.SetIsClosed(false);
1024 aCI.SetCoordinates(aCoordsArray);
1025 aCurveType = "geompy.GEOM.Polyline";
1029 //Add a new Spline object
1030 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1031 //Add a new Spline function for creation a bezier curve relatively to points set
1033 aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
1034 if (aFunction.IsNull()) return NULL;
1036 //Check if the function is set correctly
1037 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1039 GEOMImpl_ISpline aCI (aFunction);
1041 aCI.SetLength(lsize);
1042 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1043 aCI.SetIsClosed(false);
1044 aCI.SetCoordinates(aCoordsArray);
1045 aCurveType = "geompy.GEOM.Bezier";
1048 case Interpolation: {
1049 //Add a new Spline object
1050 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1052 //Add a new Spline function for creation a bezier curve relatively to points set
1053 aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
1054 if (aFunction.IsNull()) return NULL;
1056 //Check if the function is set correctly
1057 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1059 GEOMImpl_ISpline aCI (aFunction);
1060 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1061 aCI.SetLength(lsize);
1062 aCI.SetIsClosed(false);
1063 aCI.SetDoReordering(false);
1064 aCI.SetCoordinates(aCoordsArray);
1065 aCurveType = "geompy.GEOM.Interpolation";
1070 //Compute the Curve value
1072 #if OCC_VERSION_LARGE > 0x06010000
1075 if (!GetSolver()->ComputeFunction(aFunction)) {
1076 SetErrorCode("Curve driver failed !!!");
1080 catch (Standard_Failure) {
1081 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1082 SetErrorCode(aFail->GetMessageString());
1086 //Make a Python command
1087 GEOM::TPythonDump pd (aFunction);
1088 pd << aCurve << " = geompy.MakeCurveParametric(";
1089 pd << "\"" << thexExpr << "\", ";
1090 pd << "\"" << theyExpr << "\", ";
1091 pd << "\"" << thezExpr << "\", ";
1093 pd << theParamMin <<", ";
1094 pd << theParamMax <<", ";
1096 pd << theParamNbStep <<", ";
1098 pd << theParamStep <<", ";
1099 pd << aCurveType.ToCString() <<", ";
1100 pd << theNewMethod <<")";
1106 //=============================================================================
1110 //=============================================================================
1111 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1112 std::list<double> theWorkingPlane)
1116 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1118 //Add a new Sketcher object
1119 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1121 //Add a new Sketcher function
1122 Handle(GEOM_Function) aFunction =
1123 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1124 if (aFunction.IsNull()) return NULL;
1126 //Check if the function is set correctly
1127 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1129 GEOMImpl_ISketcher aCI (aFunction);
1131 TCollection_AsciiString aCommand((char*) theCommand);
1132 aCI.SetCommand(aCommand);
1135 std::list<double>::iterator it = theWorkingPlane.begin();
1136 for (; it != theWorkingPlane.end(); it++, ind++)
1137 aCI.SetWorkingPlane(ind, *it);
1139 //Compute the Sketcher value
1141 #if OCC_VERSION_LARGE > 0x06010000
1144 if (!GetSolver()->ComputeFunction(aFunction)) {
1145 SetErrorCode("Sketcher driver failed");
1149 catch (Standard_Failure) {
1150 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1151 SetErrorCode(aFail->GetMessageString());
1155 //Make a Python command
1156 GEOM::TPythonDump pd (aFunction);
1157 pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1159 it = theWorkingPlane.begin();
1161 while (it != theWorkingPlane.end()) {
1162 pd << ", " << (*it++);
1170 //=============================================================================
1172 * MakeSketcherOnPlane
1174 //=============================================================================
1175 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1176 (const char* theCommand,
1177 Handle(GEOM_Object) theWorkingPlane)
1181 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1183 //Add a new Sketcher object
1184 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1186 //Add a new Sketcher function
1187 Handle(GEOM_Function) aFunction =
1188 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1189 if (aFunction.IsNull()) return NULL;
1191 //Check if the function is set correctly
1192 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1194 GEOMImpl_ISketcher aCI (aFunction);
1196 TCollection_AsciiString aCommand((char*) theCommand);
1197 aCI.SetCommand(aCommand);
1199 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1200 if (aRefPlane.IsNull()) return NULL;
1201 aCI.SetWorkingPlane( aRefPlane );
1203 //Compute the Sketcher value
1205 #if OCC_VERSION_LARGE > 0x06010000
1208 if (!GetSolver()->ComputeFunction(aFunction)) {
1209 SetErrorCode("Sketcher driver failed");
1213 catch (Standard_Failure) {
1214 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1215 SetErrorCode(aFail->GetMessageString());
1219 //Make a Python command
1220 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1221 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
1227 //=============================================================================
1229 * Make3DSketcherCommand
1231 //=============================================================================
1232 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcherCommand (const char* theCommand)
1236 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1238 //Add a new Sketcher object
1239 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1241 //Add a new Sketcher function
1242 Handle(GEOM_Function) aFunction =
1243 aSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COMMAND);
1244 if (aFunction.IsNull()) return NULL;
1246 //Check if the function is set correctly
1247 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1249 GEOMImpl_I3DSketcher aCI (aFunction);
1251 TCollection_AsciiString aCommand ((char*) theCommand);
1252 aCI.SetCommand(aCommand);
1254 //Compute the 3D Sketcher value
1256 #if OCC_VERSION_LARGE > 0x06010000
1259 if (!GetSolver()->ComputeFunction(aFunction)) {
1260 SetErrorCode("3D Sketcher driver failed");
1264 catch (Standard_Failure) {
1265 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1266 SetErrorCode(aFail->GetMessageString());
1270 //Make a Python command
1271 GEOM::TPythonDump pd (aFunction);
1272 pd << aSketcher << " = geompy.Make3DSketcherCommand(\"" << aCommand.ToCString() << "\")";
1278 //=============================================================================
1282 //=============================================================================
1283 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1287 //Add a new Sketcher object
1288 Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1290 //Add a new Sketcher function
1291 Handle(GEOM_Function) aFunction =
1292 a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COORDS);
1293 if (aFunction.IsNull()) return NULL;
1295 //Check if the function is set correctly
1296 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1298 GEOMImpl_I3DSketcher aCI (aFunction);
1301 std::list<double>::iterator it = theCoordinates.begin();
1302 for (; it != theCoordinates.end(); it++)
1305 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1307 it = theCoordinates.begin();
1309 for (; it != theCoordinates.end(); it++, ind++)
1310 aCoordsArray->SetValue(ind, *it);
1312 aCI.SetCoordinates(aCoordsArray);
1314 //Compute the Sketcher value
1316 #if OCC_VERSION_LARGE > 0x06010000
1319 if (!GetSolver()->ComputeFunction(aFunction)) {
1320 SetErrorCode("3D Sketcher driver failed");
1324 catch (Standard_Failure) {
1325 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1326 SetErrorCode(aFail->GetMessageString());
1330 //Make a Python command
1331 GEOM::TPythonDump pd (aFunction);
1332 pd << a3DSketcher << " = geompy.Make3DSketcher([";
1334 it = theCoordinates.begin();
1336 while (it != theCoordinates.end()) {
1337 pd << ", " << (*it++);