1 #include <Standard_Stream.hxx>
3 #include <GEOMImpl_ICurvesOperations.hxx>
5 #include <GEOM_Function.hxx>
6 #include <GEOM_PythonDump.hxx>
8 #include <GEOMImpl_Types.hxx>
10 #include <GEOMImpl_PolylineDriver.hxx>
11 #include <GEOMImpl_CircleDriver.hxx>
12 #include <GEOMImpl_SplineDriver.hxx>
13 #include <GEOMImpl_EllipseDriver.hxx>
14 #include <GEOMImpl_ArcDriver.hxx>
15 #include <GEOMImpl_SketcherDriver.hxx>
17 #include <GEOMImpl_IPolyline.hxx>
18 #include <GEOMImpl_ICircle.hxx>
19 #include <GEOMImpl_ISpline.hxx>
20 #include <GEOMImpl_IEllipse.hxx>
21 #include <GEOMImpl_IArc.hxx>
22 #include <GEOMImpl_ISketcher.hxx>
24 #include "utilities.h"
26 #include <TDF_Tool.hxx>
28 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
30 //=============================================================================
34 //=============================================================================
35 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
36 : GEOM_IOperations(theEngine, theDocID)
38 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
41 //=============================================================================
45 //=============================================================================
46 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
48 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
52 //=============================================================================
56 //=============================================================================
57 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (list<Handle(GEOM_Object)> thePoints)
61 //Add a new Polyline object
62 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
64 //Add a new Polyline function for creation a polyline relatively to points set
65 Handle(GEOM_Function) aFunction =
66 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
67 if (aFunction.IsNull()) return NULL;
69 //Check if the function is set correctly
70 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
72 GEOMImpl_IPolyline aCI (aFunction);
74 int aLen = thePoints.size();
78 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
79 for (; it != thePoints.end(); it++, ind++) {
80 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
81 if (aRefPnt.IsNull()) {
82 SetErrorCode("NULL point for Polyline");
85 aCI.SetPoint(ind, aRefPnt);
88 //Compute the Polyline value
90 if (!GetSolver()->ComputeFunction(aFunction)) {
91 SetErrorCode("Polyline driver failed");
95 catch (Standard_Failure) {
96 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
97 SetErrorCode(aFail->GetMessageString());
101 //Make a Python command
102 GEOM::TPythonDump pd (aFunction);
103 pd << aPolyline << " = geompy.MakePolyline([";
105 it = thePoints.begin();
107 while (it != thePoints.end()) {
108 pd << ", " << (*it++);
116 //=============================================================================
120 //=============================================================================
121 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
122 Handle(GEOM_Object) thePnt2,
123 Handle(GEOM_Object) thePnt3)
127 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
129 //Add a new Circle object
130 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
132 //Add a new Circle function for creation a circle relatively to three points
133 Handle(GEOM_Function) aFunction =
134 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
135 if (aFunction.IsNull()) return NULL;
137 //Check if the function is set correctly
138 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
140 GEOMImpl_ICircle aCI (aFunction);
142 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
143 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
144 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
146 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
148 aCI.SetPoint1(aRefPnt1);
149 aCI.SetPoint2(aRefPnt2);
150 aCI.SetPoint3(aRefPnt3);
152 //Compute the Circle value
154 if (!GetSolver()->ComputeFunction(aFunction)) {
155 SetErrorCode("Circle driver failed");
159 catch (Standard_Failure) {
160 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
161 SetErrorCode(aFail->GetMessageString());
165 //Make a Python command
166 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
167 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
173 //=============================================================================
177 //=============================================================================
178 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
179 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
183 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
185 //Add a new Circle object
186 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
188 //Add a new Circle function for creation a circle relatively to point and vector
189 Handle(GEOM_Function) aFunction =
190 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
191 if (aFunction.IsNull()) return NULL;
193 //Check if the function is set correctly
194 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
196 GEOMImpl_ICircle aCI (aFunction);
198 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
199 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
201 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
203 aCI.SetCenter(aRefPnt);
204 aCI.SetVector(aRefVec);
207 //Compute the Circle value
209 if (!GetSolver()->ComputeFunction(aFunction)) {
210 SetErrorCode("Circle driver failed");
214 catch (Standard_Failure) {
215 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
216 SetErrorCode(aFail->GetMessageString());
220 //Make a Python command
221 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
222 << thePnt << ", " << theVec << ", " << theR << ")";
228 //=============================================================================
232 //=============================================================================
233 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
234 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
235 double theRMajor, double theRMinor)
239 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
241 //Add a new Ellipse object
242 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
244 //Add a new Ellipse function
245 Handle(GEOM_Function) aFunction =
246 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
247 if (aFunction.IsNull()) return NULL;
249 //Check if the function is set correctly
250 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
252 GEOMImpl_IEllipse aCI (aFunction);
254 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
255 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
257 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
259 aCI.SetCenter(aRefPnt);
260 aCI.SetVector(aRefVec);
261 aCI.SetRMajor(theRMajor);
262 aCI.SetRMinor(theRMinor);
264 //Compute the Ellipse value
266 if (!GetSolver()->ComputeFunction(aFunction)) {
267 SetErrorCode("Ellipse driver failed");
271 catch (Standard_Failure) {
272 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
273 SetErrorCode(aFail->GetMessageString());
277 //Make a Python command
278 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
279 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
285 //=============================================================================
289 //=============================================================================
290 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
291 Handle(GEOM_Object) thePnt2,
292 Handle(GEOM_Object) thePnt3)
296 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
298 //Add a new Circle Arc object
299 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
301 //Add a new Circle Arc function
302 Handle(GEOM_Function) aFunction =
303 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
304 if (aFunction.IsNull()) return NULL;
306 //Check if the function is set correctly
307 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
309 GEOMImpl_IArc aCI (aFunction);
311 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
312 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
313 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
315 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
317 aCI.SetPoint1(aRefPnt1);
318 aCI.SetPoint2(aRefPnt2);
319 aCI.SetPoint3(aRefPnt3);
321 //Compute the Arc value
323 if (!GetSolver()->ComputeFunction(aFunction)) {
324 SetErrorCode("Arc driver failed");
328 catch (Standard_Failure) {
329 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
330 SetErrorCode(aFail->GetMessageString());
334 //Make a Python command
335 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
336 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
342 //=============================================================================
346 //=============================================================================
347 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
348 (list<Handle(GEOM_Object)> thePoints)
352 //Add a new Spline object
353 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
355 //Add a new Spline function for creation a bezier curve relatively to points set
356 Handle(GEOM_Function) aFunction =
357 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
358 if (aFunction.IsNull()) return NULL;
360 //Check if the function is set correctly
361 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
363 GEOMImpl_ISpline aCI (aFunction);
365 int aLen = thePoints.size();
369 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
370 for (; it != thePoints.end(); it++, ind++) {
371 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
373 if (aRefPnt.IsNull()) return NULL;
375 aCI.SetPoint(ind, aRefPnt);
378 //Compute the Spline value
380 if (!GetSolver()->ComputeFunction(aFunction)) {
381 SetErrorCode("Spline driver failed");
385 catch (Standard_Failure) {
386 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
387 SetErrorCode(aFail->GetMessageString());
391 //Make a Python command
392 GEOM::TPythonDump pd (aFunction);
393 pd << aSpline << " = geompy.MakeBezier([";
395 it = thePoints.begin();
397 while (it != thePoints.end()) {
398 pd << ", " << (*it++);
406 //=============================================================================
408 * MakeSplineInterpolation
410 //=============================================================================
411 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
412 (list<Handle(GEOM_Object)> thePoints)
416 //Add a new Spline object
417 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
419 //Add a new Spline function for creation a bezier curve relatively to points set
420 Handle(GEOM_Function) aFunction =
421 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
422 if (aFunction.IsNull()) return NULL;
424 //Check if the function is set correctly
425 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
427 GEOMImpl_ISpline aCI (aFunction);
429 int aLen = thePoints.size();
433 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
434 for (; it != thePoints.end(); it++, ind++) {
435 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
437 if (aRefPnt.IsNull()) return NULL;
439 aCI.SetPoint(ind, aRefPnt);
442 //Compute the Spline value
444 if (!GetSolver()->ComputeFunction(aFunction)) {
445 SetErrorCode("Spline driver failed");
449 catch (Standard_Failure) {
450 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
451 SetErrorCode(aFail->GetMessageString());
455 //Make a Python command
456 GEOM::TPythonDump pd (aFunction);
457 pd << aSpline << " = geompy.MakeInterpol([";
459 it = thePoints.begin();
461 while (it != thePoints.end()) {
462 pd << ", " << (*it++);
470 //=============================================================================
474 //=============================================================================
475 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
476 (const TCollection_AsciiString& theCommand,
477 list<double> theWorkingPlane)
481 if (theCommand.IsEmpty()) return NULL;
483 //Add a new Sketcher object
484 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
486 //Add a new Sketcher function
487 Handle(GEOM_Function) aFunction =
488 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
489 if (aFunction.IsNull()) return NULL;
491 //Check if the function is set correctly
492 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
494 GEOMImpl_ISketcher aCI (aFunction);
496 aCI.SetCommand(theCommand);
499 list<double>::iterator it = theWorkingPlane.begin();
500 for (; it != theWorkingPlane.end(); it++, ind++)
501 aCI.SetWorkingPlane(ind, *it);
503 //Compute the Sketcher value
505 if (!GetSolver()->ComputeFunction(aFunction)) {
506 SetErrorCode("Sketcher driver failed");
510 catch (Standard_Failure) {
511 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
512 SetErrorCode(aFail->GetMessageString());
516 //Make a Python command
517 GEOM::TPythonDump pd (aFunction);
518 pd << aSketcher << " = geompy.MakeSketcher(\"" << theCommand.ToCString() << "\", [";
520 it = theWorkingPlane.begin();
522 while (it != theWorkingPlane.end()) {
523 pd << ", " << (*it++);
531 //=============================================================================
533 * MakeSketcherOnPlane
535 //=============================================================================
536 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
537 (const TCollection_AsciiString& theCommand,
538 Handle(GEOM_Object) theWorkingPlane)
542 if (theCommand.IsEmpty()) return NULL;
544 //Add a new Sketcher object
545 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
547 //Add a new Sketcher function
548 Handle(GEOM_Function) aFunction =
549 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
550 if (aFunction.IsNull()) return NULL;
552 //Check if the function is set correctly
553 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
555 GEOMImpl_ISketcher aCI (aFunction);
556 aCI.SetCommand(theCommand);
558 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
559 if (aRefPlane.IsNull()) return NULL;
560 aCI.SetWorkingPlane( aRefPlane );
562 //Compute the Sketcher value
564 if (!GetSolver()->ComputeFunction(aFunction)) {
565 SetErrorCode("Sketcher driver failed");
569 catch (Standard_Failure) {
570 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
571 SetErrorCode(aFail->GetMessageString());
575 //Make a Python command
576 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
577 << theCommand.ToCString() << "\", " << theWorkingPlane << " )";