1 // Copyright (C) 2007-2008 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
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_ICurvesOperations.hxx>
26 #include <GEOM_Function.hxx>
27 #include <GEOM_PythonDump.hxx>
29 #include <GEOMImpl_Types.hxx>
31 #include <GEOMImpl_PolylineDriver.hxx>
32 #include <GEOMImpl_CircleDriver.hxx>
33 #include <GEOMImpl_SplineDriver.hxx>
34 #include <GEOMImpl_EllipseDriver.hxx>
35 #include <GEOMImpl_ArcDriver.hxx>
36 #include <GEOMImpl_SketcherDriver.hxx>
38 #include <GEOMImpl_IPolyline.hxx>
39 #include <GEOMImpl_ICircle.hxx>
40 #include <GEOMImpl_ISpline.hxx>
41 #include <GEOMImpl_IEllipse.hxx>
42 #include <GEOMImpl_IArc.hxx>
43 #include <GEOMImpl_ISketcher.hxx>
45 #include "utilities.h"
47 #include <TDF_Tool.hxx>
49 #include <Standard_Failure.hxx>
50 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
54 //=============================================================================
58 //=============================================================================
59 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
60 : GEOM_IOperations(theEngine, theDocID)
62 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
65 //=============================================================================
69 //=============================================================================
70 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
72 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
76 //=============================================================================
80 //=============================================================================
81 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (list<Handle(GEOM_Object)> thePoints)
85 //Add a new Polyline object
86 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
88 //Add a new Polyline function for creation a polyline relatively to points set
89 Handle(GEOM_Function) aFunction =
90 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
91 if (aFunction.IsNull()) return NULL;
93 //Check if the function is set correctly
94 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
96 GEOMImpl_IPolyline aCI (aFunction);
98 int aLen = thePoints.size();
102 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
103 for (; it != thePoints.end(); it++, ind++) {
104 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
105 if (aRefPnt.IsNull()) {
106 SetErrorCode("NULL point for Polyline");
109 aCI.SetPoint(ind, aRefPnt);
112 //Compute the Polyline value
114 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
117 if (!GetSolver()->ComputeFunction(aFunction)) {
118 SetErrorCode("Polyline driver failed");
122 catch (Standard_Failure) {
123 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
124 SetErrorCode(aFail->GetMessageString());
128 //Make a Python command
129 GEOM::TPythonDump pd (aFunction);
130 pd << aPolyline << " = geompy.MakePolyline([";
132 it = thePoints.begin();
134 while (it != thePoints.end()) {
135 pd << ", " << (*it++);
143 //=============================================================================
147 //=============================================================================
148 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
149 Handle(GEOM_Object) thePnt2,
150 Handle(GEOM_Object) thePnt3)
154 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
156 //Add a new Circle object
157 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
159 //Add a new Circle function for creation a circle relatively to three points
160 Handle(GEOM_Function) aFunction =
161 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
162 if (aFunction.IsNull()) return NULL;
164 //Check if the function is set correctly
165 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
167 GEOMImpl_ICircle aCI (aFunction);
169 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
170 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
171 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
173 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
175 aCI.SetPoint1(aRefPnt1);
176 aCI.SetPoint2(aRefPnt2);
177 aCI.SetPoint3(aRefPnt3);
179 //Compute the Circle value
181 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
184 if (!GetSolver()->ComputeFunction(aFunction)) {
185 SetErrorCode("Circle driver failed");
189 catch (Standard_Failure) {
190 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
191 SetErrorCode(aFail->GetMessageString());
195 //Make a Python command
196 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
197 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
203 //=============================================================================
205 * MakeCircleCenter2Pnt
207 //=============================================================================
208 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
209 Handle(GEOM_Object) thePnt2,
210 Handle(GEOM_Object) thePnt3)
214 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
216 //Add a new Circle object
217 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
219 //Add a new Circle function for creation a circle relatively to center and 2 points
220 Handle(GEOM_Function) aFunction =
221 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
222 if (aFunction.IsNull()) return NULL;
224 //Check if the function is set correctly
225 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
227 GEOMImpl_ICircle aCI (aFunction);
229 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
230 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
231 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
233 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
235 aCI.SetPoint1(aRefPnt1);
236 aCI.SetPoint2(aRefPnt2);
237 aCI.SetPoint3(aRefPnt3);
239 //Compute the Circle value
241 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
244 if (!GetSolver()->ComputeFunction(aFunction)) {
245 SetErrorCode("Circle driver failed");
249 catch (Standard_Failure) {
250 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
251 SetErrorCode(aFail->GetMessageString());
255 //Make a Python command
256 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
257 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
263 //=============================================================================
267 //=============================================================================
268 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
269 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
273 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
275 //Add a new Circle object
276 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
278 //Add a new Circle function for creation a circle relatively to point and vector
279 Handle(GEOM_Function) aFunction =
280 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
281 if (aFunction.IsNull()) return NULL;
283 //Check if the function is set correctly
284 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
286 GEOMImpl_ICircle aCI (aFunction);
288 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
289 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
291 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
293 aCI.SetCenter(aRefPnt);
294 aCI.SetVector(aRefVec);
297 //Compute the Circle value
299 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
302 if (!GetSolver()->ComputeFunction(aFunction)) {
303 SetErrorCode("Circle driver failed");
307 catch (Standard_Failure) {
308 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
309 SetErrorCode(aFail->GetMessageString());
313 //Make a Python command
314 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
315 << thePnt << ", " << theVec << ", " << theR << ")";
321 //=============================================================================
325 //=============================================================================
326 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
327 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
328 double theRMajor, double theRMinor,
329 Handle(GEOM_Object) theVecMaj)
333 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
335 //Add a new Ellipse object
336 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
338 //Add a new Ellipse function
339 Handle(GEOM_Function) aFunction =
340 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
341 if (aFunction.IsNull()) return NULL;
343 //Check if the function is set correctly
344 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
346 GEOMImpl_IEllipse aCI (aFunction);
348 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
349 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
351 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
353 aCI.SetCenter(aRefPnt);
354 aCI.SetVector(aRefVec);
355 aCI.SetRMajor(theRMajor);
356 aCI.SetRMinor(theRMinor);
358 // vector of major axis is optional parameter
359 if (!theVecMaj.IsNull()) {
360 Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
361 if (aRefVecMaj.IsNull()) return NULL;
362 aCI.SetVectorMajor(aRefVecMaj);
365 //Compute the Ellipse value
367 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
370 if (!GetSolver()->ComputeFunction(aFunction)) {
371 SetErrorCode("Ellipse driver failed");
375 catch (Standard_Failure) {
376 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
377 SetErrorCode(aFail->GetMessageString());
381 //Make a Python command
382 //Make a Python command
383 if (!theVecMaj.IsNull()) {
384 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
385 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
386 << ", " << theVecMaj << ")";
389 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
390 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
397 //=============================================================================
401 //=============================================================================
402 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
403 Handle(GEOM_Object) thePnt2,
404 Handle(GEOM_Object) thePnt3)
408 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
410 //Add a new Circle Arc object
411 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
413 //Add a new Circle Arc function
414 Handle(GEOM_Function) aFunction =
415 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
417 if (aFunction.IsNull()) return NULL;
419 //Check if the function is set correctly
420 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
421 GEOMImpl_IArc aCI (aFunction);
423 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
424 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
425 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
428 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
430 aCI.SetPoint1(aRefPnt1);
431 aCI.SetPoint2(aRefPnt2);
432 aCI.SetPoint3(aRefPnt3);
434 //Compute the Arc value
436 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
439 if (!GetSolver()->ComputeFunction(aFunction)) {
440 SetErrorCode("Arc driver failed");
444 catch (Standard_Failure) {
445 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
446 SetErrorCode(aFail->GetMessageString());
450 //Make a Python command
451 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
452 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
458 //=============================================================================
462 //=============================================================================
463 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
464 Handle(GEOM_Object) thePnt2,
465 Handle(GEOM_Object) thePnt3,
469 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
471 //Add a new Circle Arc object
472 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
474 //Add a new Circle Arc function
475 Handle(GEOM_Function) aFunction =
476 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
477 if (aFunction.IsNull()) return NULL;
479 //Check if the function is set correctly
480 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
482 GEOMImpl_IArc aCI (aFunction);
484 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
485 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
486 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
488 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
490 aCI.SetPoint1(aRefPnt1);
491 aCI.SetPoint2(aRefPnt2);
492 aCI.SetPoint3(aRefPnt3);
493 aCI.SetSense(theSense);
495 //Compute the Arc value
497 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
500 if (!GetSolver()->ComputeFunction(aFunction)) {
501 SetErrorCode("Arc driver failed");
505 catch (Standard_Failure) {
506 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
507 SetErrorCode(aFail->GetMessageString());
510 //Make a Python command
511 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
512 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
518 //=============================================================================
522 //=============================================================================
523 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
524 (list<Handle(GEOM_Object)> thePoints)
528 //Add a new Spline object
529 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
531 //Add a new Spline function for creation a bezier curve relatively to points set
532 Handle(GEOM_Function) aFunction =
533 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
534 if (aFunction.IsNull()) return NULL;
536 //Check if the function is set correctly
537 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
539 GEOMImpl_ISpline aCI (aFunction);
541 int aLen = thePoints.size();
545 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
546 for (; it != thePoints.end(); it++, ind++) {
547 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
549 if (aRefPnt.IsNull()) return NULL;
551 aCI.SetPoint(ind, aRefPnt);
554 //Compute the Spline value
556 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
559 if (!GetSolver()->ComputeFunction(aFunction)) {
560 SetErrorCode("Spline driver failed");
564 catch (Standard_Failure) {
565 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
566 SetErrorCode(aFail->GetMessageString());
570 //Make a Python command
571 GEOM::TPythonDump pd (aFunction);
572 pd << aSpline << " = geompy.MakeBezier([";
574 it = thePoints.begin();
576 while (it != thePoints.end()) {
577 pd << ", " << (*it++);
585 //=============================================================================
587 * MakeSplineInterpolation
589 //=============================================================================
590 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
591 (list<Handle(GEOM_Object)> thePoints)
595 //Add a new Spline object
596 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
598 //Add a new Spline function for creation a bezier curve relatively to points set
599 Handle(GEOM_Function) aFunction =
600 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
601 if (aFunction.IsNull()) return NULL;
603 //Check if the function is set correctly
604 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
606 GEOMImpl_ISpline aCI (aFunction);
608 int aLen = thePoints.size();
612 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
613 for (; it != thePoints.end(); it++, ind++) {
614 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
616 if (aRefPnt.IsNull()) return NULL;
618 aCI.SetPoint(ind, aRefPnt);
621 //Compute the Spline value
623 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
626 if (!GetSolver()->ComputeFunction(aFunction)) {
627 SetErrorCode("Spline 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 pd (aFunction);
639 pd << aSpline << " = geompy.MakeInterpol([";
641 it = thePoints.begin();
643 while (it != thePoints.end()) {
644 pd << ", " << (*it++);
652 //=============================================================================
656 //=============================================================================
657 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
658 list<double> theWorkingPlane)
662 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
664 //Add a new Sketcher object
665 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
667 //Add a new Sketcher function
668 Handle(GEOM_Function) aFunction =
669 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
670 if (aFunction.IsNull()) return NULL;
672 //Check if the function is set correctly
673 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
675 GEOMImpl_ISketcher aCI (aFunction);
677 TCollection_AsciiString aCommand((char*) theCommand);
678 aCI.SetCommand(aCommand);
681 list<double>::iterator it = theWorkingPlane.begin();
682 for (; it != theWorkingPlane.end(); it++, ind++)
683 aCI.SetWorkingPlane(ind, *it);
685 //Compute the Sketcher value
687 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
690 if (!GetSolver()->ComputeFunction(aFunction)) {
691 SetErrorCode("Sketcher 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 << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
705 it = theWorkingPlane.begin();
707 while (it != theWorkingPlane.end()) {
708 pd << ", " << (*it++);
716 //=============================================================================
718 * MakeSketcherOnPlane
720 //=============================================================================
721 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane (const char* theCommand,
722 Handle(GEOM_Object) theWorkingPlane)
726 if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
728 //Add a new Sketcher object
729 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
731 //Add a new Sketcher function
732 Handle(GEOM_Function) aFunction =
733 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
734 if (aFunction.IsNull()) return NULL;
736 //Check if the function is set correctly
737 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
739 GEOMImpl_ISketcher aCI (aFunction);
741 TCollection_AsciiString aCommand((char*) theCommand);
742 aCI.SetCommand(aCommand);
744 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
745 if (aRefPlane.IsNull()) return NULL;
746 aCI.SetWorkingPlane( aRefPlane );
748 //Compute the Sketcher value
750 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
753 if (!GetSolver()->ComputeFunction(aFunction)) {
754 SetErrorCode("Sketcher driver failed");
758 catch (Standard_Failure) {
759 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
760 SetErrorCode(aFail->GetMessageString());
764 //Make a Python command
765 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
766 << aCommand.ToCString() << "\", " << theWorkingPlane << " )";