1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // E.A. : On windows with python 2.6, there is a conflict
25 // E.A. : between pymath.h and Standard_math.h which define
26 // E.A. : some same symbols : acosh, asinh, ...
27 #include <Standard_math.hxx>
32 #include <structmember.h>
38 #include "GEOMImpl_ICurvesOperations.hxx"
39 #include "GEOMImpl_Types.hxx"
41 #include "GEOM_Function.hxx"
42 #include "GEOM_PythonDump.hxx"
44 #include "GEOMImpl_PolylineDriver.hxx"
45 #include "GEOMImpl_CircleDriver.hxx"
46 #include "GEOMImpl_SplineDriver.hxx"
47 #include "GEOMImpl_EllipseDriver.hxx"
48 #include "GEOMImpl_ArcDriver.hxx"
49 #include "GEOMImpl_ShapeDriver.hxx"
50 #include "GEOMImpl_SketcherDriver.hxx"
51 #include "GEOMImpl_3DSketcherDriver.hxx"
53 #include "GEOMImpl_IPolyline.hxx"
54 #include "GEOMImpl_ICircle.hxx"
55 #include "GEOMImpl_ISpline.hxx"
56 #include "GEOMImpl_IEllipse.hxx"
57 #include "GEOMImpl_IArc.hxx"
58 #include "GEOMImpl_ISketcher.hxx"
59 #include "GEOMImpl_I3DSketcher.hxx"
60 #include "GEOMImpl_ICurveParametric.hxx"
61 #include "GEOMImpl_IIsoline.hxx"
63 #include <Basics_OCCTVersion.hxx>
65 #include "utilities.h"
67 #include <TDF_Tool.hxx>
68 #include <TColStd_HArray1OfReal.hxx>
70 #include <Standard_Failure.hxx>
71 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
74 /* ==================================
75 * =========== PYTHON ==============
76 * ==================================*/
85 PyStdOut_dealloc(PyStdOut *self)
91 PyStdOut_write(PyStdOut *self, PyObject *args)
95 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
99 *(self->out)=*(self->out)+c;
105 static PyMethodDef PyStdOut_methods[] = {
106 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
107 PyDoc_STR("write(string) -> None")},
108 {NULL, NULL} /* sentinel */
111 static PyMemberDef PyStdOut_memberlist[] = {
112 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
113 (char*)"flag indicating that a space needs to be printed; used by print"},
114 {NULL} /* Sentinel */
117 static PyTypeObject PyStdOut_Type = {
118 /* The ob_type field must be initialized in the module init function
119 * to be portable to Windows without using C++. */
120 PyObject_HEAD_INIT(NULL)
123 sizeof(PyStdOut), /*tp_basicsize*/
126 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
133 0, /*tp_as_sequence*/
138 PyObject_GenericGetAttr, /*tp_getattro*/
139 /* softspace is writable: we must supply tp_setattro */
140 PyObject_GenericSetAttr, /* tp_setattro */
142 Py_TPFLAGS_DEFAULT, /*tp_flags*/
146 0, /*tp_richcompare*/
147 0, /*tp_weaklistoffset*/
150 PyStdOut_methods, /*tp_methods*/
151 PyStdOut_memberlist, /*tp_members*/
165 PyObject * newPyStdOut( std::string& out )
168 self = PyObject_New(PyStdOut, &PyStdOut_Type);
173 return (PyObject*)self;
177 ////////////////////////END PYTHON///////////////////////////
178 //=============================================================================
182 //=============================================================================
183 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
184 : GEOM_IOperations(theEngine, theDocID)
186 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
189 //=============================================================================
193 //=============================================================================
194 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
196 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
200 //=============================================================================
204 //=============================================================================
205 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
206 Handle(GEOM_Object) thePnt2,
207 Handle(GEOM_Object) thePnt3)
211 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
213 //Add a new Circle object
214 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
216 //Add a new Circle function for creation a circle relatively to three points
217 Handle(GEOM_Function) aFunction =
218 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
219 if (aFunction.IsNull()) return NULL;
221 //Check if the function is set correctly
222 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
224 GEOMImpl_ICircle aCI (aFunction);
226 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
227 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
228 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
230 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
232 aCI.SetPoint1(aRefPnt1);
233 aCI.SetPoint2(aRefPnt2);
234 aCI.SetPoint3(aRefPnt3);
236 //Compute the Circle value
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
297 if (!GetSolver()->ComputeFunction(aFunction)) {
298 SetErrorCode("Circle driver failed");
302 catch (Standard_Failure) {
303 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
304 SetErrorCode(aFail->GetMessageString());
308 //Make a Python command
309 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
310 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
316 //=============================================================================
320 //=============================================================================
321 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
322 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
326 // Not set thePnt means origin of global CS,
327 // Not set theVec means Z axis of global CS
328 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
330 //Add a new Circle object
331 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
333 //Add a new Circle function for creation a circle relatively to point and vector
334 Handle(GEOM_Function) aFunction =
335 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
336 if (aFunction.IsNull()) return NULL;
338 //Check if the function is set correctly
339 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
341 GEOMImpl_ICircle aCI (aFunction);
343 if (!thePnt.IsNull()) {
344 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
345 if (aRefPnt.IsNull()) return NULL;
346 aCI.SetCenter(aRefPnt);
349 if (!theVec.IsNull()) {
350 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
351 if (aRefVec.IsNull()) return NULL;
352 aCI.SetVector(aRefVec);
357 //Compute the Circle value
360 if (!GetSolver()->ComputeFunction(aFunction)) {
361 SetErrorCode("Circle driver failed");
365 catch (Standard_Failure) {
366 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
367 SetErrorCode(aFail->GetMessageString());
371 //Make a Python command
372 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
373 << thePnt << ", " << theVec << ", " << theR << ")";
379 //=============================================================================
383 //=============================================================================
384 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
385 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
386 double theRMajor, double theRMinor,
387 Handle(GEOM_Object) theVecMaj)
391 // Not set thePnt means origin of global CS,
392 // Not set theVec means Z axis of global CS
393 // Not set theVecMaj means X axis of global CS
394 //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
396 //Add a new Ellipse object
397 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
399 //Add a new Ellipse function
400 Handle(GEOM_Function) aFunction =
401 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
402 if (aFunction.IsNull()) return NULL;
404 //Check if the function is set correctly
405 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
407 GEOMImpl_IEllipse aCI (aFunction);
409 if (!thePnt.IsNull()) {
410 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
411 if (aRefPnt.IsNull()) return NULL;
412 aCI.SetCenter(aRefPnt);
415 if (!theVec.IsNull()) {
416 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
417 if (aRefVec.IsNull()) return NULL;
418 aCI.SetVector(aRefVec);
421 aCI.SetRMajor(theRMajor);
422 aCI.SetRMinor(theRMinor);
424 if (!theVecMaj.IsNull()) {
425 Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
426 if (aRefVecMaj.IsNull()) return NULL;
427 aCI.SetVectorMajor(aRefVecMaj);
430 //Compute the Ellipse value
433 if (!GetSolver()->ComputeFunction(aFunction)) {
434 SetErrorCode("Ellipse driver failed");
438 catch (Standard_Failure) {
439 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
440 SetErrorCode(aFail->GetMessageString());
444 //Make a Python command
445 if (!theVecMaj.IsNull()) {
446 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
447 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
448 << ", " << theVecMaj << ")";
451 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
452 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
459 //=============================================================================
463 //=============================================================================
464 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
465 Handle(GEOM_Object) thePnt2,
466 Handle(GEOM_Object) thePnt3)
470 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
472 //Add a new Circle Arc object
473 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
475 //Add a new Circle Arc function
476 Handle(GEOM_Function) aFunction =
477 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
479 if (aFunction.IsNull()) return NULL;
481 //Check if the function is set correctly
482 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
483 GEOMImpl_IArc aCI (aFunction);
485 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
486 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
487 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
489 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
491 aCI.SetPoint1(aRefPnt1);
492 aCI.SetPoint2(aRefPnt2);
493 aCI.SetPoint3(aRefPnt3);
495 //Compute the Arc value
498 if (!GetSolver()->ComputeFunction(aFunction)) {
499 SetErrorCode("Arc driver failed");
503 catch (Standard_Failure) {
504 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
505 SetErrorCode(aFail->GetMessageString());
509 //Make a Python command
510 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
511 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
517 //=============================================================================
521 //=============================================================================
522 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
523 Handle(GEOM_Object) thePnt2,
524 Handle(GEOM_Object) thePnt3,
528 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
530 //Add a new Circle Arc object
531 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
533 //Add a new Circle Arc function
534 Handle(GEOM_Function) aFunction =
535 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
536 if (aFunction.IsNull()) return NULL;
538 //Check if the function is set correctly
539 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
541 GEOMImpl_IArc aCI (aFunction);
543 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
544 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
545 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
547 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
549 aCI.SetPoint1(aRefPnt1);
550 aCI.SetPoint2(aRefPnt2);
551 aCI.SetPoint3(aRefPnt3);
552 aCI.SetSense(theSense);
554 //Compute the Arc value
557 if (!GetSolver()->ComputeFunction(aFunction)) {
558 SetErrorCode("Arc driver failed");
562 catch (Standard_Failure) {
563 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
564 SetErrorCode(aFail->GetMessageString());
567 //Make a Python command
568 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
569 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
575 //=============================================================================
579 //=============================================================================
580 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
581 Handle(GEOM_Object) thePnt2,
582 Handle(GEOM_Object) thePnt3)
586 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
588 //Add a new Circle Arc object
589 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
591 //Add a new Circle Arc function
592 Handle(GEOM_Function) aFunction =
593 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
595 if (aFunction.IsNull()) return NULL;
597 //Check if the function is set correctly
598 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
599 GEOMImpl_IArc aCI (aFunction);
601 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
602 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
603 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
605 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
607 aCI.SetPoint1(aRefPnt1);
608 aCI.SetPoint2(aRefPnt2);
609 aCI.SetPoint3(aRefPnt3);
611 //Compute the Arc value
614 if (!GetSolver()->ComputeFunction(aFunction)) {
615 SetErrorCode("Arc driver failed");
619 catch (Standard_Failure) {
620 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
621 SetErrorCode(aFail->GetMessageString());
625 //Make a Python command
626 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
627 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
633 //=============================================================================
637 //=============================================================================
638 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
643 //Add a new Polyline object
644 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
646 //Add a new Polyline function for creation a polyline relatively to points set
647 Handle(GEOM_Function) aFunction =
648 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
649 if (aFunction.IsNull()) return NULL;
651 //Check if the function is set correctly
652 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
654 GEOMImpl_IPolyline aCI (aFunction);
656 int aLen = thePoints.size();
658 aCI.SetConstructorType(POINT_CONSTRUCTOR);
661 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
662 for (; it != thePoints.end(); it++, ind++) {
663 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
664 if (aRefPnt.IsNull()) {
665 SetErrorCode("NULL point for Polyline");
668 aCI.SetPoint(ind, aRefPnt);
671 aCI.SetIsClosed(theIsClosed);
673 //Compute the Polyline value
676 if (!GetSolver()->ComputeFunction(aFunction)) {
677 SetErrorCode("Polyline driver failed");
681 catch (Standard_Failure) {
682 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
683 SetErrorCode(aFail->GetMessageString());
687 //Make a Python command
688 GEOM::TPythonDump pd (aFunction);
689 pd << aPolyline << " = geompy.MakePolyline([";
691 it = thePoints.begin();
693 while (it != thePoints.end()) {
694 pd << ", " << (*it++);
696 pd << "], " << theIsClosed << ")";
702 //=============================================================================
706 //=============================================================================
707 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
708 (std::list<Handle(GEOM_Object)> thePoints,
713 //Add a new Spline object
714 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
716 //Add a new Spline function for creation a bezier curve relatively to points set
717 Handle(GEOM_Function) aFunction =
718 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
719 if (aFunction.IsNull()) return NULL;
721 //Check if the function is set correctly
722 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
724 GEOMImpl_ISpline aCI (aFunction);
726 aCI.SetConstructorType(POINT_CONSTRUCTOR);
728 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
729 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
730 for (; it != thePoints.end(); it++) {
731 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
732 if (aRefPnt.IsNull()) {
733 SetErrorCode("NULL point for Besier curve");
736 aPoints->Append(aRefPnt);
738 aCI.SetPoints(aPoints);
740 aCI.SetIsClosed(theIsClosed);
742 //Compute the Spline value
745 if (!GetSolver()->ComputeFunction(aFunction)) {
746 SetErrorCode("Spline driver failed");
750 catch (Standard_Failure) {
751 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
752 SetErrorCode(aFail->GetMessageString());
756 //Make a Python command
757 GEOM::TPythonDump pd (aFunction);
758 pd << aSpline << " = geompy.MakeBezier([";
760 it = thePoints.begin();
762 while (it != thePoints.end()) {
763 pd << ", " << (*it++);
765 pd << "], " << theIsClosed << ")";
771 //=============================================================================
773 * MakeSplineInterpolation
775 //=============================================================================
776 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
777 (std::list<Handle(GEOM_Object)> thePoints,
779 bool theDoReordering)
783 //Add a new Spline object
784 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
786 //Add a new Spline function for interpolation type
787 Handle(GEOM_Function) aFunction =
788 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
789 if (aFunction.IsNull()) return NULL;
791 //Check if the function is set correctly
792 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
794 GEOMImpl_ISpline aCI (aFunction);
796 aCI.SetConstructorType(POINT_CONSTRUCTOR);
798 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
799 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
800 for (; it != thePoints.end(); it++) {
801 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
802 if (aRefPnt.IsNull()) {
805 aPoints->Append(aRefPnt);
807 aCI.SetPoints(aPoints);
809 aCI.SetIsClosed(theIsClosed);
810 aCI.SetDoReordering(theDoReordering);
812 //Compute the Spline value
815 if (!GetSolver()->ComputeFunction(aFunction)) {
816 SetErrorCode("Spline driver failed");
820 catch (Standard_Failure) {
821 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
822 SetErrorCode(aFail->GetMessageString());
826 //Make a Python command
827 GEOM::TPythonDump pd (aFunction);
828 pd << aSpline << " = geompy.MakeInterpol([";
830 it = thePoints.begin();
832 while (it != thePoints.end()) {
833 pd << ", " << (*it++);
835 pd << "], " << theIsClosed << ", " << theDoReordering << ")";
842 //=============================================================================
844 * MakeSplineInterpolWithTangents
846 //=============================================================================
847 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolWithTangents
848 (std::list<Handle(GEOM_Object)> thePoints,
849 Handle(GEOM_Object) theFirstVec,
850 Handle(GEOM_Object) theLastVec)
854 //Add a new Spline object
855 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
857 //Add a new Spline function for interpolation type
858 Handle(GEOM_Function) aFunction =
859 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOL_TANGENTS);
860 if (aFunction.IsNull()) return NULL;
862 //Check if the function is set correctly
863 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
865 GEOMImpl_ISpline aCI (aFunction);
867 aCI.SetConstructorType(POINT_CONSTRUCTOR);
869 Handle(TColStd_HSequenceOfTransient) aPoints = new TColStd_HSequenceOfTransient;
870 std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
871 for (; it != thePoints.end(); it++) {
872 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
873 if (aRefPnt.IsNull()) {
874 SetErrorCode("NULL point for Interpolation");
877 aPoints->Append(aRefPnt);
879 aCI.SetPoints(aPoints);
881 Handle(GEOM_Function) aVec1 = theFirstVec->GetLastFunction();
882 Handle(GEOM_Function) aVec2 = theLastVec->GetLastFunction();
884 if (aVec1.IsNull() || aVec2.IsNull()) return NULL;
886 aCI.SetFirstVector(aVec1);
887 aCI.SetLastVector(aVec2);
889 //Compute the Spline value
892 if (!GetSolver()->ComputeFunction(aFunction)) {
893 SetErrorCode("Spline driver failed");
897 catch (Standard_Failure) {
898 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
899 SetErrorCode(aFail->GetMessageString());
903 //Make a Python command
904 GEOM::TPythonDump pd (aFunction);
905 pd << aSpline << " = geompy.MakeInterpolWithTangents([";
907 it = thePoints.begin();
909 while (it != thePoints.end()) {
910 pd << ", " << (*it++);
912 pd << "], " << theFirstVec << ", " << theLastVec << ")";
918 //=============================================================================
920 * MakeCurveParametric
922 //=============================================================================
923 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
924 (const char* thexExpr, const char* theyExpr, const char* thezExpr,
925 double theParamMin, double theParamMax, double theParamStep,
926 CurveType theCurveType,
927 int theParamNbStep, bool theNewMethod)
929 TCollection_AsciiString aPyScript;
930 aPyScript +="from math import * \n";
931 aPyScript +="def X(t): \n";
932 aPyScript +=" return ";
933 aPyScript += thexExpr;
935 aPyScript +="def Y(t): \n";
936 aPyScript +=" return ";
937 aPyScript += theyExpr;
940 aPyScript +="def Z(t): \n";
941 aPyScript +=" return ";
942 aPyScript += thezExpr;
947 aPyScript +="def coordCalculator(tmin, tmax, nstep): \n";
948 aPyScript +=" coords = [] \n";
949 aPyScript +=" tstep = (tmax - tmin) / nstep \n";
950 aPyScript +=" n = 0 \n";
951 aPyScript +=" while n <= nstep : \n";
952 aPyScript +=" t = tmin + n*tstep \n";
953 aPyScript +=" coords.append([X(t), Y(t), Z(t)]) \n";
954 aPyScript +=" n = n+1 \n";
955 aPyScript +=" return coords \n";
959 aPyScript +="def coordCalculator(tmin, tmax, tstep): \n";
960 aPyScript +=" coords = [] \n";
961 aPyScript +=" while tmin <= tmax : \n";
962 aPyScript +=" coords.append([X(tmin), Y(tmin), Z(tmin)]) \n";
963 aPyScript +=" tmin = tmin + tstep \n";
964 aPyScript +=" return coords \n";
969 if(theParamMin >= theParamMax) {
970 SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
974 if(!theNewMethod && theParamStep <= 0.0) {
975 SetErrorCode("Value of the step must be positive !!!");
978 else if(theNewMethod && theParamNbStep < 0) {
979 SetErrorCode("The number of steps must be positive !!!");
983 /* Initialize the Python interpreter */
984 if (! Py_IsInitialized()) {
985 SetErrorCode("Python interpreter is not initialized !!! ");
989 PyGILState_STATE gstate;
990 gstate = PyGILState_Ensure();
992 PyObject* main_mod = PyImport_AddModule("__main__");
993 PyObject* main_dict = PyModule_GetDict(main_mod);
995 PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
998 SetErrorCode("Error during executing of python script !!!");
1000 PyGILState_Release(gstate);
1006 PyObject * func = NULL;
1007 func = PyObject_GetAttrString(main_mod, "coordCalculator");
1010 SetErrorCode("Can't get function from python module !!!");
1011 PyGILState_Release(gstate);
1017 coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep );
1019 coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
1021 PyObject* new_stderr = NULL;
1023 if (coords == NULL){
1025 std::string err_description="";
1026 new_stderr = newPyStdOut(err_description);
1027 PySys_SetObject((char*)"stderr", new_stderr);
1029 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1030 Py_DECREF(new_stderr);
1031 MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description);
1032 SetErrorCode("Can't evaluate the expressions, please check them !!!");
1033 PyGILState_Release(gstate);
1037 int lsize = PyList_Size( coords );
1040 SetErrorCode("Empty list of the points, please check input parameters !!!");
1044 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, lsize * 3);
1047 for ( Py_ssize_t i = 0; i < lsize; ++i ) {
1048 PyObject* coord = PyList_GetItem( coords, i );
1049 if (coord != NULL) {
1050 for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
1051 PyObject* item = PyList_GetItem(coord, j);
1052 aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
1060 PyGILState_Release(gstate);
1062 Handle(GEOM_Object) aCurve;
1063 Handle(GEOM_Function) aFunction;
1064 TCollection_AsciiString aCurveType;
1066 switch(theCurveType) {
1068 //Add a new Polyline object
1069 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
1071 //Add a new Polyline function for creation a polyline relatively to points set
1072 aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
1073 if (aFunction.IsNull()) return NULL;
1075 //Check if the function is set correctly
1076 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
1078 GEOMImpl_IPolyline aCI (aFunction);
1080 aCI.SetLength(lsize);
1081 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1082 aCI.SetIsClosed(false);
1083 aCI.SetCoordinates(aCoordsArray);
1084 aCurveType = "GEOM.Polyline";
1088 //Add a new Spline object
1089 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1090 //Add a new Spline function for creation a bezier curve relatively to points set
1092 aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
1093 if (aFunction.IsNull()) return NULL;
1095 //Check if the function is set correctly
1096 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1098 GEOMImpl_ISpline aCI (aFunction);
1100 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1101 aCI.SetIsClosed(false);
1102 aCI.SetCoordinates(aCoordsArray);
1103 aCurveType = "GEOM.Bezier";
1106 case Interpolation: {
1107 //Add a new Spline object
1108 aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1110 //Add a new Spline function for creation a bezier curve relatively to points set
1111 aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
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);
1118 aCI.SetConstructorType(COORD_CONSTRUCTOR);
1119 aCI.SetIsClosed(false);
1120 aCI.SetDoReordering(false);
1121 aCI.SetCoordinates(aCoordsArray);
1122 aCurveType = "GEOM.Interpolation";
1127 GEOMImpl_ICurveParametric aIP(aFunction);
1128 aIP.SetExprX (thexExpr);
1129 aIP.SetExprY (theyExpr);
1130 aIP.SetExprZ (thezExpr);
1131 aIP.SetParamMin (theParamMin);
1132 aIP.SetParamMax (theParamMax);
1134 aIP.SetParamNbStep(theParamNbStep);
1136 aIP.SetParamStep (theParamStep);
1138 //Compute the Curve value
1141 if (!GetSolver()->ComputeFunction(aFunction)) {
1142 SetErrorCode("Curve driver failed !!!");
1146 catch (Standard_Failure) {
1147 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1148 SetErrorCode(aFail->GetMessageString());
1152 //Make a Python command
1153 GEOM::TPythonDump pd (aFunction);
1154 pd << aCurve << " = geompy.MakeCurveParametric(";
1155 pd << "\"" << thexExpr << "\", ";
1156 pd << "\"" << theyExpr << "\", ";
1157 pd << "\"" << thezExpr << "\", ";
1159 pd << theParamMin <<", ";
1160 pd << theParamMax <<", ";
1162 pd << theParamNbStep <<", ";
1164 pd << theParamStep <<", ";
1165 pd << aCurveType.ToCString() <<", ";
1166 pd << theNewMethod <<")";
1172 //=============================================================================
1176 //=============================================================================
1177 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1178 std::list<double> theWorkingPlane)
1182 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1184 //Add a new Sketcher object
1185 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1187 //Add a new Sketcher function
1188 Handle(GEOM_Function) aFunction =
1189 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1190 if (aFunction.IsNull()) return NULL;
1192 //Check if the function is set correctly
1193 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1195 GEOMImpl_ISketcher aCI (aFunction);
1197 TCollection_AsciiString aCommand((char*) theCommand);
1198 aCI.SetCommand(aCommand);
1201 std::list<double>::iterator it = theWorkingPlane.begin();
1202 for (; it != theWorkingPlane.end(); it++, ind++)
1203 aCI.SetWorkingPlane(ind, *it);
1205 //Compute the Sketcher value
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 pd (aFunction);
1221 pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1223 it = theWorkingPlane.begin();
1225 while (it != theWorkingPlane.end()) {
1226 pd << ", " << (*it++);
1234 //=============================================================================
1236 * MakeSketcherOnPlane
1238 //=============================================================================
1239 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1240 (const char* theCommand,
1241 Handle(GEOM_Object) theWorkingPlane)
1245 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1247 //Add a new Sketcher object
1248 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1250 //Add a new Sketcher function
1251 Handle(GEOM_Function) aFunction =
1252 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1253 if (aFunction.IsNull()) return NULL;
1255 //Check if the function is set correctly
1256 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1258 GEOMImpl_ISketcher aCI (aFunction);
1260 TCollection_AsciiString aCommand((char*) theCommand);
1261 aCI.SetCommand(aCommand);
1263 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1264 if (aRefPlane.IsNull()) return NULL;
1265 aCI.SetWorkingPlane( aRefPlane );
1267 //Compute the Sketcher value
1270 if (!GetSolver()->ComputeFunction(aFunction)) {
1271 SetErrorCode("Sketcher driver failed");
1275 catch (Standard_Failure) {
1276 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1277 SetErrorCode(aFail->GetMessageString());
1281 //Make a Python command
1282 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1283 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
1289 //=============================================================================
1291 * Make3DSketcherCommand
1293 //=============================================================================
1294 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcherCommand (const char* theCommand)
1298 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1300 //Add a new Sketcher object
1301 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1303 //Add a new Sketcher function
1304 Handle(GEOM_Function) aFunction =
1305 aSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COMMAND);
1306 if (aFunction.IsNull()) return NULL;
1308 //Check if the function is set correctly
1309 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1311 GEOMImpl_I3DSketcher aCI (aFunction);
1313 TCollection_AsciiString aCommand ((char*) theCommand);
1314 aCI.SetCommand(aCommand);
1316 //Compute the 3D Sketcher value
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 << aSketcher << " = geompy.Make3DSketcherCommand(\"" << aCommand.ToCString() << "\")";
1338 //=============================================================================
1342 //=============================================================================
1343 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1347 //Add a new Sketcher object
1348 Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1350 //Add a new Sketcher function
1351 Handle(GEOM_Function) aFunction =
1352 a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COORDS);
1353 if (aFunction.IsNull()) return NULL;
1355 //Check if the function is set correctly
1356 if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1358 GEOMImpl_I3DSketcher aCI (aFunction);
1361 std::list<double>::iterator it = theCoordinates.begin();
1362 for (; it != theCoordinates.end(); it++)
1365 Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1367 it = theCoordinates.begin();
1369 for (; it != theCoordinates.end(); it++, ind++)
1370 aCoordsArray->SetValue(ind, *it);
1372 aCI.SetCoordinates(aCoordsArray);
1374 //Compute the Sketcher value
1377 if (!GetSolver()->ComputeFunction(aFunction)) {
1378 SetErrorCode("3D Sketcher driver failed");
1382 catch (Standard_Failure) {
1383 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1384 SetErrorCode(aFail->GetMessageString());
1388 //Make a Python command
1389 GEOM::TPythonDump pd (aFunction);
1390 pd << a3DSketcher << " = geompy.Make3DSketcher([";
1392 it = theCoordinates.begin();
1394 while (it != theCoordinates.end()) {
1395 pd << ", " << (*it++);
1403 //=============================================================================
1407 //=============================================================================
1408 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeIsoline
1409 (const Handle(GEOM_Object) &theFace,
1411 const double theParameter)
1415 if (theFace.IsNull()) {
1419 //Add a new Spline object
1420 Handle(GEOM_Object) anIsoline =
1421 GetEngine()->AddObject(GetDocID(), GEOM_ISOLINE);
1423 //Add a new Spline function for interpolation type
1424 Handle(GEOM_Function) aFunction =
1425 anIsoline->AddFunction(GEOMImpl_ShapeDriver::GetID(), SHAPE_ISOLINE);
1427 if (aFunction.IsNull()) {
1431 //Check if the function is set correctly
1432 if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) {
1436 GEOMImpl_IIsoline aCI (aFunction);
1437 Handle(GEOM_Function) aRefFace = theFace->GetLastFunction();
1439 if (aRefFace.IsNull()) {
1443 aCI.SetFace(aRefFace);
1444 aCI.SetIsUIso(IsUIso);
1445 aCI.SetParameter(theParameter);
1447 //Compute the isoline curve
1450 if (!GetSolver()->ComputeFunction(aFunction)) {
1451 SetErrorCode("Shape driver failed");
1455 catch (Standard_Failure) {
1456 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1457 SetErrorCode(aFail->GetMessageString());
1461 //Make a Python command
1462 GEOM::TPythonDump (aFunction) << anIsoline << " = geompy.MakeIsoline( "
1463 << theFace << ", " << IsUIso << ", " << theParameter << " )";