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
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>
37 #include <Standard_Stream.hxx>
39 #include <GEOMImpl_ICurvesOperations.hxx>
40 #include <GEOMImpl_Types.hxx>
42 #include <GEOM_Function.hxx>
43 #include <GEOM_PythonDump.hxx>
45 #include <GEOMImpl_PolylineDriver.hxx>
46 #include <GEOMImpl_CircleDriver.hxx>
47 #include <GEOMImpl_SplineDriver.hxx>
48 #include <GEOMImpl_EllipseDriver.hxx>
49 #include <GEOMImpl_ArcDriver.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>
61 #include <Basics_OCCTVersion.hxx>
63 #include "utilities.h"
65 #include <TDF_Tool.hxx>
66 #include <TColStd_HArray1OfReal.hxx>
68 #include <Standard_Failure.hxx>
69 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
72 /* ==================================
73 * =========== PYTHON ==============
74 * ==================================*/
83 PyStdOut_dealloc(PyStdOut *self)
89 PyStdOut_write(PyStdOut *self, PyObject *args)
93 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
97 *(self->out)=*(self->out)+c;
103 static PyMethodDef PyStdOut_methods[] = {
104 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
105 PyDoc_STR("write(string) -> None")},
106 {NULL, NULL} /* sentinel */
109 static PyMemberDef PyStdOut_memberlist[] = {
110 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
111 (char*)"flag indicating that a space needs to be printed; used by print"},
112 {NULL} /* Sentinel */
115 static PyTypeObject PyStdOut_Type = {
116 /* The ob_type field must be initialized in the module init function
117 * to be portable to Windows without using C++. */
118 PyObject_HEAD_INIT(NULL)
121 sizeof(PyStdOut), /*tp_basicsize*/
124 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
131 0, /*tp_as_sequence*/
136 PyObject_GenericGetAttr, /*tp_getattro*/
137 /* softspace is writable: we must supply tp_setattro */
138 PyObject_GenericSetAttr, /* tp_setattro */
140 Py_TPFLAGS_DEFAULT, /*tp_flags*/
144 0, /*tp_richcompare*/
145 0, /*tp_weaklistoffset*/
148 PyStdOut_methods, /*tp_methods*/
149 PyStdOut_memberlist, /*tp_members*/
163 PyObject * newPyStdOut( std::string& out )
166 self = PyObject_New(PyStdOut, &PyStdOut_Type);
171 return (PyObject*)self;
175 ////////////////////////END PYTHON///////////////////////////
176 //=============================================================================
180 //=============================================================================
181 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
182 : GEOM_IOperations(theEngine, theDocID)
184 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
187 //=============================================================================
191 //=============================================================================
192 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
194 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
198 //=============================================================================
202 //=============================================================================
203 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
204 Handle(GEOM_Object) thePnt2,
205 Handle(GEOM_Object) thePnt3)
209 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
211 //Add a new Circle object
212 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
214 //Add a new Circle function for creation a circle relatively to three points
215 Handle(GEOM_Function) aFunction =
216 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
217 if (aFunction.IsNull()) return NULL;
219 //Check if the function is set correctly
220 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
222 GEOMImpl_ICircle aCI (aFunction);
224 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
225 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
226 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
228 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
230 aCI.SetPoint1(aRefPnt1);
231 aCI.SetPoint2(aRefPnt2);
232 aCI.SetPoint3(aRefPnt3);
234 //Compute the Circle value
236 #if OCC_VERSION_LARGE > 0x06010000
239 if (!GetSolver()->ComputeFunction(aFunction)) {
240 SetErrorCode("Circle driver failed");
244 catch (Standard_Failure) {
245 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
246 SetErrorCode(aFail->GetMessageString());
250 //Make a Python command
251 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
252 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
258 //=============================================================================
260 * MakeCircleCenter2Pnt
262 //=============================================================================
263 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
264 Handle(GEOM_Object) thePnt2,
265 Handle(GEOM_Object) thePnt3)
269 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
271 //Add a new Circle object
272 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
274 //Add a new Circle function for creation a circle relatively to center and 2 points
275 Handle(GEOM_Function) aFunction =
276 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
277 if (aFunction.IsNull()) return NULL;
279 //Check if the function is set correctly
280 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
282 GEOMImpl_ICircle aCI (aFunction);
284 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
285 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
286 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
288 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
290 aCI.SetPoint1(aRefPnt1);
291 aCI.SetPoint2(aRefPnt2);
292 aCI.SetPoint3(aRefPnt3);
294 //Compute the Circle value
296 #if OCC_VERSION_LARGE > 0x06010000
299 if (!GetSolver()->ComputeFunction(aFunction)) {
300 SetErrorCode("Circle driver failed");
304 catch (Standard_Failure) {
305 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
306 SetErrorCode(aFail->GetMessageString());
310 //Make a Python command
311 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
312 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
318 //=============================================================================
322 //=============================================================================
323 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
324 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
328 // Not set thePnt means origin of global CS,
329 // Not set theVec means Z axis of global CS
330 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
332 //Add a new Circle object
333 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
335 //Add a new Circle function for creation a circle relatively to point and vector
336 Handle(GEOM_Function) aFunction =
337 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
338 if (aFunction.IsNull()) return NULL;
340 //Check if the function is set correctly
341 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
343 GEOMImpl_ICircle aCI (aFunction);
345 if (!thePnt.IsNull()) {
346 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
347 if (aRefPnt.IsNull()) return NULL;
348 aCI.SetCenter(aRefPnt);
351 if (!theVec.IsNull()) {
352 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
353 if (aRefVec.IsNull()) return NULL;
354 aCI.SetVector(aRefVec);
359 //Compute the Circle value
361 #if OCC_VERSION_LARGE > 0x06010000
364 if (!GetSolver()->ComputeFunction(aFunction)) {
365 SetErrorCode("Circle driver failed");
369 catch (Standard_Failure) {
370 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
371 SetErrorCode(aFail->GetMessageString());
375 //Make a Python command
376 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
377 << thePnt << ", " << theVec << ", " << theR << ")";
383 //=============================================================================
387 //=============================================================================
388 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
389 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
390 double theRMajor, double theRMinor,
391 Handle(GEOM_Object) theVecMaj)
395 // Not set thePnt means origin of global CS,
396 // Not set theVec means Z axis of global CS
397 // Not set theVecMaj means X axis of global CS
398 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
400 //Add a new Ellipse object
401 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
403 //Add a new Ellipse function
404 Handle(GEOM_Function) aFunction =
405 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
406 if (aFunction.IsNull()) return NULL;
408 //Check if the function is set correctly
409 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
411 GEOMImpl_IEllipse aCI (aFunction);
413 if (!thePnt.IsNull()) {
414 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
415 if (aRefPnt.IsNull()) return NULL;
416 aCI.SetCenter(aRefPnt);
419 if (!theVec.IsNull()) {
420 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
421 if (aRefVec.IsNull()) return NULL;
422 aCI.SetVector(aRefVec);
425 aCI.SetRMajor(theRMajor);
426 aCI.SetRMinor(theRMinor);
428 if (!theVecMaj.IsNull()) {
429 Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
430 if (aRefVecMaj.IsNull()) return NULL;
431 aCI.SetVectorMajor(aRefVecMaj);
434 //Compute the Ellipse value
436 #if OCC_VERSION_LARGE > 0x06010000
439 if (!GetSolver()->ComputeFunction(aFunction)) {
440 SetErrorCode("Ellipse driver failed");
444 catch (Standard_Failure) {
445 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
446 SetErrorCode(aFail->GetMessageString());
450 //Make a Python command
451 if (!theVecMaj.IsNull()) {
452 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
453 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
454 << ", " << theVecMaj << ")";
457 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
458 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
465 //=============================================================================
469 //=============================================================================
470 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
471 Handle(GEOM_Object) thePnt2,
472 Handle(GEOM_Object) thePnt3)
476 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
478 //Add a new Circle Arc object
479 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
481 //Add a new Circle Arc function
482 Handle(GEOM_Function) aFunction =
483 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
485 if (aFunction.IsNull()) return NULL;
487 //Check if the function is set correctly
488 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
489 GEOMImpl_IArc aCI (aFunction);
491 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
492 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
493 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
495 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
497 aCI.SetPoint1(aRefPnt1);
498 aCI.SetPoint2(aRefPnt2);
499 aCI.SetPoint3(aRefPnt3);
501 //Compute the Arc value
503 #if OCC_VERSION_LARGE > 0x06010000
506 if (!GetSolver()->ComputeFunction(aFunction)) {
507 SetErrorCode("Arc driver failed");
511 catch (Standard_Failure) {
512 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
513 SetErrorCode(aFail->GetMessageString());
517 //Make a Python command
518 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
519 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
525 //=============================================================================
529 //=============================================================================
530 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
531 Handle(GEOM_Object) thePnt2,
532 Handle(GEOM_Object) thePnt3,
536 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
538 //Add a new Circle Arc object
539 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
541 //Add a new Circle Arc function
542 Handle(GEOM_Function) aFunction =
543 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
544 if (aFunction.IsNull()) return NULL;
546 //Check if the function is set correctly
547 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
549 GEOMImpl_IArc aCI (aFunction);
551 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
552 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
553 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
555 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
557 aCI.SetPoint1(aRefPnt1);
558 aCI.SetPoint2(aRefPnt2);
559 aCI.SetPoint3(aRefPnt3);
560 aCI.SetSense(theSense);
562 //Compute the Arc value
564 #if OCC_VERSION_LARGE > 0x06010000
567 if (!GetSolver()->ComputeFunction(aFunction)) {
568 SetErrorCode("Arc driver failed");
572 catch (Standard_Failure) {
573 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
574 SetErrorCode(aFail->GetMessageString());
577 //Make a Python command
578 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
579 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
585 //=============================================================================
589 //=============================================================================
590 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
591 Handle(GEOM_Object) thePnt2,
592 Handle(GEOM_Object) thePnt3)
596 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
598 //Add a new Circle Arc object
599 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
601 //Add a new Circle Arc function
602 Handle(GEOM_Function) aFunction =
603 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
605 if (aFunction.IsNull()) return NULL;
607 //Check if the function is set correctly
608 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
609 GEOMImpl_IArc aCI (aFunction);
611 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
612 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
613 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
615 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
617 aCI.SetPoint1(aRefPnt1);
618 aCI.SetPoint2(aRefPnt2);
619 aCI.SetPoint3(aRefPnt3);
621 //Compute the Arc value
623 #if OCC_VERSION_LARGE > 0x06010000
626 if (!GetSolver()->ComputeFunction(aFunction)) {
627 SetErrorCode("Arc driver failed");
631 catch (Standard_Failure) {
632 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
633 SetErrorCode(aFail->GetMessageString());
637 //Make a Python command
638 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
639 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
645 //=============================================================================
649 //=============================================================================
650 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
655 //Add a new Polyline object
656 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
658 //Add a new Polyline function for creation a polyline relatively to points set
659 Handle(GEOM_Function) aFunction =
660 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
661 if (aFunction.IsNull()) return NULL;
663 //Check if the function is set correctly
664 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
666 GEOMImpl_IPolyline aCI (aFunction);
668 int aLen = thePoints.size();
670 aCI.SetConstructorType(POINT_CONSTRUCTOR);
673 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
674 for (; it != thePoints.end(); it++, ind++) {
675 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
676 if (aRefPnt.IsNull()) {
677 SetErrorCode("NULL point for Polyline");
680 aCI.SetPoint(ind, aRefPnt);
683 aCI.SetIsClosed(theIsClosed);
685 //Compute the Polyline value
687 #if OCC_VERSION_LARGE > 0x06010000
690 if (!GetSolver()->ComputeFunction(aFunction)) {
691 SetErrorCode("Polyline driver failed");
695 catch (Standard_Failure) {
696 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
697 SetErrorCode(aFail->GetMessageString());
701 //Make a Python command
702 GEOM::TPythonDump pd (aFunction);
703 pd << aPolyline << " = geompy.MakePolyline([";
705 it = thePoints.begin();
707 while (it != thePoints.end()) {
708 pd << ", " << (*it++);
710 pd << "], " << theIsClosed << ")";
716 //=============================================================================
720 //=============================================================================
721 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
722 (std::list<Handle(GEOM_Object)> thePoints,
727 //Add a new Spline object
728 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
730 //Add a new Spline function for creation a bezier curve relatively to points set
731 Handle(GEOM_Function) aFunction =
732 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
733 if (aFunction.IsNull()) return NULL;
735 //Check if the function is set correctly
736 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
738 GEOMImpl_ISpline aCI (aFunction);
740 int aLen = thePoints.size();
742 aCI.SetConstructorType(POINT_CONSTRUCTOR);
745 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
746 for (; it != thePoints.end(); it++, ind++) {
747 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
749 if (aRefPnt.IsNull()) return NULL;
751 aCI.SetPoint(ind, aRefPnt);
754 aCI.SetIsClosed(theIsClosed);
756 //Compute the Spline value
758 #if OCC_VERSION_LARGE > 0x06010000
761 if (!GetSolver()->ComputeFunction(aFunction)) {
762 SetErrorCode("Spline driver failed");
766 catch (Standard_Failure) {
767 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
768 SetErrorCode(aFail->GetMessageString());
772 //Make a Python command
773 GEOM::TPythonDump pd (aFunction);
774 pd << aSpline << " = geompy.MakeBezier([";
776 it = thePoints.begin();
778 while (it != thePoints.end()) {
779 pd << ", " << (*it++);
781 pd << "], " << theIsClosed << ")";
787 //=============================================================================
789 * MakeSplineInterpolation
791 //=============================================================================
792 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
793 (std::list<Handle(GEOM_Object)> thePoints,
795 bool theDoReordering)
799 //Add a new Spline object
800 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
802 //Add a new Spline function for creation a bezier curve relatively to points set
803 Handle(GEOM_Function) aFunction =
804 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
805 if (aFunction.IsNull()) return NULL;
807 //Check if the function is set correctly
808 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
810 GEOMImpl_ISpline aCI (aFunction);
812 int aLen = thePoints.size();
813 aCI.SetConstructorType(POINT_CONSTRUCTOR);
817 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
818 for (; it != thePoints.end(); it++, ind++) {
819 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
821 if (aRefPnt.IsNull()) return NULL;
823 aCI.SetPoint(ind, aRefPnt);
826 aCI.SetIsClosed(theIsClosed);
827 aCI.SetDoReordering(theDoReordering);
829 //Compute the Spline value
831 #if OCC_VERSION_LARGE > 0x06010000
834 if (!GetSolver()->ComputeFunction(aFunction)) {
835 SetErrorCode("Spline driver failed");
839 catch (Standard_Failure) {
840 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
841 SetErrorCode(aFail->GetMessageString());
845 //Make a Python command
846 GEOM::TPythonDump pd (aFunction);
847 pd << aSpline << " = geompy.MakeInterpol([";
849 it = thePoints.begin();
851 while (it != thePoints.end()) {
852 pd << ", " << (*it++);
854 pd << "], " << theIsClosed << ", " << theDoReordering << ")";
860 //=============================================================================
862 * MakeCurveParametric
864 //=============================================================================
865 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
866 (const char* thexExpr, const char* theyExpr, const char* thezExpr,
867 double theParamMin, double theParamMax, double theParamStep,
868 CurveType theCurveType,
869 int theParamNbStep, bool theNewMethod)
871 TCollection_AsciiString aPyScript;
872 aPyScript +="from math import * \n";
873 aPyScript +="def X(t): \n";
874 aPyScript +=" return ";
875 aPyScript += thexExpr;
877 aPyScript +="def Y(t): \n";
878 aPyScript +=" return ";
879 aPyScript += theyExpr;
882 aPyScript +="def Z(t): \n";
883 aPyScript +=" return ";
884 aPyScript += thezExpr;
889 aPyScript +="def coordCalculator(tmin, tmax, nstep): \n";
890 aPyScript +=" coords = [] \n";
891 aPyScript +=" tstep = (tmax - tmin) / nstep \n";
892 aPyScript +=" n = 0 \n";
893 aPyScript +=" while n <= nstep : \n";
894 aPyScript +=" t = tmin + n*tstep \n";
895 aPyScript +=" coords.append([X(t), Y(t), Z(t)]) \n";
896 aPyScript +=" n = n+1 \n";
897 aPyScript +=" return coords \n";
901 aPyScript +="def coordCalculator(tmin, tmax, tstep): \n";
902 aPyScript +=" coords = [] \n";
903 aPyScript +=" while tmin <= tmax : \n";
904 aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
905 aPyScript +=" tmin = tmin + tstep \n";
906 aPyScript +=" return coords \n";
911 if(theParamMin >= theParamMax) {
912 SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
916 if(!theNewMethod && theParamStep <= 0.0) {
917 SetErrorCode("Value of the step must be positive !!!");
920 else if(theNewMethod && theParamNbStep < 0) {
921 SetErrorCode("The number of steps must be positive !!!");
925 /* Initialize the Python interpreter */
926 if (! Py_IsInitialized()) {
927 SetErrorCode("Python interpreter is not initialized !!! ");
931 PyGILState_STATE gstate;
932 gstate = PyGILState_Ensure();
934 PyObject* main_mod = PyImport_AddModule("__main__");
935 PyObject* main_dict = PyModule_GetDict(main_mod);
937 PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
940 SetErrorCode("Error during executing of python script !!!");
942 PyGILState_Release(gstate);
948 PyObject * func = NULL;
949 func = PyObject_GetAttrString(main_mod, "coordCalculator");
952 SetErrorCode("Can't get function from python module !!!");
953 PyGILState_Release(gstate);
959 coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep );
961 coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
963 PyObject* new_stderr = NULL;
967 std::string err_description="";
968 new_stderr = newPyStdOut(err_description);
969 PySys_SetObject((char*)"stderr", new_stderr);
971 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
972 Py_DECREF(new_stderr);
973 MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description);
974 SetErrorCode("Can't evaluate the expressions, please check them !!!");
975 PyGILState_Release(gstate);
979 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, PyList_Size( coords ) * 3);
981 if(PyList_Size( coords ) <= 0) {
982 SetErrorCode("Empty list of the points, please check input parameters !!!");
987 for ( Py_ssize_t i = 0; i< PyList_Size( coords ); ++i ) {
988 PyObject* coord = PyList_GetItem( coords, i );
990 for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
991 PyObject* item = PyList_GetItem(coord, j);
992 aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
1000 PyGILState_Release(gstate);
1002 Handle(GEOM_Object) aCurve;
1003 Handle(GEOM_Function) aFunction;
1004 TCollection_AsciiString aCurveType;
1006 switch(theCurveType) {
1008 //Add a new Polyline object
1009 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
1011 //Add a new Polyline function for creation a polyline relatively to points set
1012 aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
1013 if (aFunction.IsNull()) return NULL;
1015 //Check if the function is set correctly
1016 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
1018 GEOMImpl_IPolyline aCI (aFunction);
1020 aCI.SetLength(PyList_Size( coords ));
1021 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1022 aCI.SetIsClosed(false);
1023 aCI.SetCoordinates(aCoordsArray);
1024 aCurveType = "geompy.GEOM.Polyline";
1028 //Add a new Spline object
1029 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1030 //Add a new Spline function for creation a bezier curve relatively to points set
1032 aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
1033 if (aFunction.IsNull()) return NULL;
1035 //Check if the function is set correctly
1036 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1038 GEOMImpl_ISpline aCI (aFunction);
1040 aCI.SetLength(PyList_Size( coords ));
1041 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1042 aCI.SetIsClosed(false);
1043 aCI.SetCoordinates(aCoordsArray);
1044 aCurveType = "geompy.GEOM.Bezier";
1047 case Interpolation: {
1048 //Add a new Spline object
1049 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1051 //Add a new Spline function for creation a bezier curve relatively to points set
1052 aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
1053 if (aFunction.IsNull()) return NULL;
1055 //Check if the function is set correctly
1056 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1058 GEOMImpl_ISpline aCI (aFunction);
1059 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1060 aCI.SetLength(PyList_Size( coords ));
1061 aCI.SetIsClosed(false);
1062 aCI.SetDoReordering(false);
1063 aCI.SetCoordinates(aCoordsArray);
1064 aCurveType = "geompy.GEOM.Interpolation";
1069 //Compute the Curve value
1071 #if OCC_VERSION_LARGE > 0x06010000
1074 if (!GetSolver()->ComputeFunction(aFunction)) {
1075 SetErrorCode("Curve driver failed !!!");
1079 catch (Standard_Failure) {
1080 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1081 SetErrorCode(aFail->GetMessageString());
1085 //Make a Python command
1086 GEOM::TPythonDump pd (aFunction);
1087 pd << aCurve << " = geompy.MakeCurveParametric(";
1088 pd << "\"" << thexExpr << "\", ";
1089 pd << "\"" << theyExpr << "\", ";
1090 pd << "\"" << thezExpr << "\", ";
1092 pd << theParamMin <<", ";
1093 pd << theParamMax <<", ";
1095 pd << theParamNbStep <<", ";
1097 pd << theParamStep <<", ";
1098 pd << aCurveType.ToCString() <<", ";
1099 pd << theNewMethod <<")";
1105 //=============================================================================
1109 //=============================================================================
1110 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1111 std::list<double> theWorkingPlane)
1115 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1117 //Add a new Sketcher object
1118 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1120 //Add a new Sketcher function
1121 Handle(GEOM_Function) aFunction =
1122 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1123 if (aFunction.IsNull()) return NULL;
1125 //Check if the function is set correctly
1126 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1128 GEOMImpl_ISketcher aCI (aFunction);
1130 TCollection_AsciiString aCommand((char*) theCommand);
1131 aCI.SetCommand(aCommand);
1134 std::list<double>::iterator it = theWorkingPlane.begin();
1135 for (; it != theWorkingPlane.end(); it++, ind++)
1136 aCI.SetWorkingPlane(ind, *it);
1138 //Compute the Sketcher value
1140 #if OCC_VERSION_LARGE > 0x06010000
1143 if (!GetSolver()->ComputeFunction(aFunction)) {
1144 SetErrorCode("Sketcher driver failed");
1148 catch (Standard_Failure) {
1149 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1150 SetErrorCode(aFail->GetMessageString());
1154 //Make a Python command
1155 GEOM::TPythonDump pd (aFunction);
1156 pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1158 it = theWorkingPlane.begin();
1160 while (it != theWorkingPlane.end()) {
1161 pd << ", " << (*it++);
1169 //=============================================================================
1173 //=============================================================================
1174 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1178 //Add a new Sketcher object
1179 Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1181 //Add a new Sketcher function
1182 Handle(GEOM_Function) aFunction =
1183 a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
1184 if (aFunction.IsNull()) return NULL;
1186 //Check if the function is set correctly
1187 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1189 GEOMImpl_I3DSketcher aCI (aFunction);
1192 std::list<double>::iterator it = theCoordinates.begin();
1193 for (; it != theCoordinates.end(); it++)
1196 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1198 it = theCoordinates.begin();
1200 for (; it != theCoordinates.end(); it++, ind++)
1201 aCoordsArray->SetValue(ind, *it);
1203 aCI.SetCoordinates(aCoordsArray);
1205 //Compute the Sketcher value
1207 #if OCC_VERSION_LARGE > 0x06010000
1210 if (!GetSolver()->ComputeFunction(aFunction)) {
1211 SetErrorCode("3D Sketcher driver failed");
1215 catch (Standard_Failure) {
1216 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1217 SetErrorCode(aFail->GetMessageString());
1221 //Make a Python command
1222 GEOM::TPythonDump pd (aFunction);
1223 pd << a3DSketcher << " = geompy.Make3DSketcher([";
1225 it = theCoordinates.begin();
1227 while (it != theCoordinates.end()) {
1228 pd << ", " << (*it++);
1236 //=============================================================================
1238 * MakeSketcherOnPlane
1240 //=============================================================================
1241 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1242 (const char* theCommand,
1243 Handle(GEOM_Object) theWorkingPlane)
1247 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1249 //Add a new Sketcher object
1250 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1252 //Add a new Sketcher function
1253 Handle(GEOM_Function) aFunction =
1254 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1255 if (aFunction.IsNull()) return NULL;
1257 //Check if the function is set correctly
1258 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1260 GEOMImpl_ISketcher aCI (aFunction);
1262 TCollection_AsciiString aCommand((char*) theCommand);
1263 aCI.SetCommand(aCommand);
1265 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1266 if (aRefPlane.IsNull()) return NULL;
1267 aCI.SetWorkingPlane( aRefPlane );
1269 //Compute the Sketcher value
1271 #if OCC_VERSION_LARGE > 0x06010000
1274 if (!GetSolver()->ComputeFunction(aFunction)) {
1275 SetErrorCode("Sketcher driver failed");
1279 catch (Standard_Failure) {
1280 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1281 SetErrorCode(aFail->GetMessageString());
1285 //Make a Python command
1286 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1287 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";