3 #include "GEOMImpl_ICurvesOperations.hxx"
5 #include "GEOM_Function.hxx"
6 #include "GEOMImpl_Types.hxx"
8 #include "GEOMImpl_PolylineDriver.hxx"
9 #include "GEOMImpl_CircleDriver.hxx"
10 #include "GEOMImpl_SplineDriver.hxx"
11 #include "GEOMImpl_EllipseDriver.hxx"
12 #include "GEOMImpl_ArcDriver.hxx"
13 #include "GEOMImpl_SketcherDriver.hxx"
15 #include "GEOMImpl_IPolyline.hxx"
16 #include "GEOMImpl_ICircle.hxx"
17 #include "GEOMImpl_ISpline.hxx"
18 #include "GEOMImpl_IEllipse.hxx"
19 #include "GEOMImpl_IArc.hxx"
20 #include "GEOMImpl_ISketcher.hxx"
22 #include "utilities.h"
24 #include <TDF_Tool.hxx>
26 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
28 //=============================================================================
32 //=============================================================================
33 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
34 : GEOM_IOperations(theEngine, theDocID)
36 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
39 //=============================================================================
43 //=============================================================================
44 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
46 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
50 //=============================================================================
54 //=============================================================================
55 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (list<Handle(GEOM_Object)> thePoints)
59 //Add a new Polyline object
60 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
62 //Add a new Polyline function for creation a polyline relatively to points set
63 Handle(GEOM_Function) aFunction =
64 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
65 if (aFunction.IsNull()) return NULL;
67 //Check if the function is set correctly
68 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
70 GEOMImpl_IPolyline aCI (aFunction);
72 int aLen = thePoints.size();
76 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
77 for (; it != thePoints.end(); it++, ind++) {
78 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
79 if (aRefPnt.IsNull()) {
80 SetErrorCode("NULL point for Polyline");
83 aCI.SetPoint(ind, aRefPnt);
86 //Compute the Polyline value
88 if (!GetSolver()->ComputeFunction(aFunction)) {
89 SetErrorCode("Polyline driver failed");
93 catch (Standard_Failure) {
94 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
95 SetErrorCode(aFail->GetMessageString());
99 //Make a Python command
100 TCollection_AsciiString anEntry, aDescr("");
101 TDF_Tool::Entry(aPolyline->GetEntry(), anEntry);
103 aDescr += " = ICurvesOperations.MakePolyline([";
104 it = thePoints.begin();
105 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
107 aDescr += (anEntry+", ");
108 for (; it != thePoints.end(); it++) {
110 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
115 aFunction->SetDescription(aDescr);
121 //=============================================================================
125 //=============================================================================
126 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
127 Handle(GEOM_Object) thePnt2,
128 Handle(GEOM_Object) thePnt3)
132 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
134 //Add a new Circle object
135 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
137 //Add a new Circle function for creation a circle relatively to three points
138 Handle(GEOM_Function) aFunction =
139 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
140 if (aFunction.IsNull()) return NULL;
142 //Check if the function is set correctly
143 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
145 GEOMImpl_ICircle aCI (aFunction);
147 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
148 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
149 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
151 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
153 aCI.SetPoint1(aRefPnt1);
154 aCI.SetPoint2(aRefPnt2);
155 aCI.SetPoint3(aRefPnt3);
157 //Compute the Circle value
159 if (!GetSolver()->ComputeFunction(aFunction)) {
160 SetErrorCode("Circle driver failed");
164 catch (Standard_Failure) {
165 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
166 SetErrorCode(aFail->GetMessageString());
170 //Make a Python command
171 TCollection_AsciiString anEntry, aDescr("");
172 TDF_Tool::Entry(aCircle->GetEntry(), anEntry);
174 aDescr += " = ICurvesOperations.MakeCircleThreePnt(";
175 TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
176 aDescr += (anEntry+", ");
177 TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
178 aDescr += (anEntry+", ");
179 TDF_Tool::Entry(thePnt3->GetEntry(), anEntry);
180 aDescr += (anEntry+")");
182 aFunction->SetDescription(aDescr);
188 //=============================================================================
192 //=============================================================================
193 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
194 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
198 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
200 //Add a new Circle object
201 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
203 //Add a new Circle function for creation a circle relatively to point and vector
204 Handle(GEOM_Function) aFunction =
205 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
206 if (aFunction.IsNull()) return NULL;
208 //Check if the function is set correctly
209 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
211 GEOMImpl_ICircle aCI (aFunction);
213 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
214 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
216 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
218 aCI.SetCenter(aRefPnt);
219 aCI.SetVector(aRefVec);
222 //Compute the Circle value
224 if (!GetSolver()->ComputeFunction(aFunction)) {
225 SetErrorCode("Circle driver failed");
229 catch (Standard_Failure) {
230 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
231 SetErrorCode(aFail->GetMessageString());
235 //Make a Python command
236 TCollection_AsciiString anEntry, aDescr("");
237 TDF_Tool::Entry(aCircle->GetEntry(), anEntry);
239 aDescr += " = ICurvesOperations.MakeCirclePntVecR(";
240 TDF_Tool::Entry(thePnt->GetEntry(), anEntry);
241 aDescr += (anEntry+", ");
242 TDF_Tool::Entry(theVec->GetEntry(), anEntry);
243 aDescr += (anEntry+", ");
244 aDescr += (TCollection_AsciiString(theR)+")");
246 aFunction->SetDescription(aDescr);
252 //=============================================================================
256 //=============================================================================
257 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
258 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
259 double theRMajor, double theRMinor)
263 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
265 //Add a new Ellipse object
266 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
268 //Add a new Ellipse function
269 Handle(GEOM_Function) aFunction =
270 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
271 if (aFunction.IsNull()) return NULL;
273 //Check if the function is set correctly
274 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
276 GEOMImpl_IEllipse aCI (aFunction);
278 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
279 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
281 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
283 aCI.SetCenter(aRefPnt);
284 aCI.SetVector(aRefVec);
285 aCI.SetRMajor(theRMajor);
286 aCI.SetRMinor(theRMinor);
288 //Compute the Ellipse value
290 if (!GetSolver()->ComputeFunction(aFunction)) {
291 SetErrorCode("Ellipse driver failed");
295 catch (Standard_Failure) {
296 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
297 SetErrorCode(aFail->GetMessageString());
301 //Make a Python command
302 TCollection_AsciiString anEntry, aDescr("");
303 TDF_Tool::Entry(anEll->GetEntry(), anEntry);
305 aDescr += " = ICurvesOperations.MakeEllipse(";
306 TDF_Tool::Entry(thePnt->GetEntry(), anEntry);
307 aDescr += (anEntry+", ");
308 TDF_Tool::Entry(theVec->GetEntry(), anEntry);
309 aDescr += (anEntry+", ");
310 aDescr += (TCollection_AsciiString(theRMajor)+", ");
311 aDescr += (TCollection_AsciiString(theRMinor)+")");
313 aFunction->SetDescription(aDescr);
319 //=============================================================================
323 //=============================================================================
324 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
325 Handle(GEOM_Object) thePnt2,
326 Handle(GEOM_Object) thePnt3)
330 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
332 //Add a new Circle Arc object
333 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
335 //Add a new Circle Arc function
336 Handle(GEOM_Function) aFunction =
337 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
338 if (aFunction.IsNull()) return NULL;
340 //Check if the function is set correctly
341 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
343 GEOMImpl_IArc aCI (aFunction);
345 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
346 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
347 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
349 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
351 aCI.SetPoint1(aRefPnt1);
352 aCI.SetPoint2(aRefPnt2);
353 aCI.SetPoint3(aRefPnt3);
355 //Compute the Arc value
357 if (!GetSolver()->ComputeFunction(aFunction)) {
358 SetErrorCode("Arc driver failed");
362 catch (Standard_Failure) {
363 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
364 SetErrorCode(aFail->GetMessageString());
368 //Make a Python command
369 TCollection_AsciiString anEntry, aDescr("");
370 TDF_Tool::Entry(anArc->GetEntry(), anEntry);
372 aDescr += " = ICurvesOperations.MakeArc(";
373 TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
374 aDescr += (anEntry+", ");
375 TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
376 aDescr += (anEntry+", ");
377 TDF_Tool::Entry(thePnt3->GetEntry(), anEntry);
378 aDescr += (anEntry+")");
380 aFunction->SetDescription(aDescr);
386 //=============================================================================
390 //=============================================================================
391 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
392 (list<Handle(GEOM_Object)> thePoints)
396 //Add a new Spline object
397 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
399 //Add a new Spline function for creation a bezier curve relatively to points set
400 Handle(GEOM_Function) aFunction =
401 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
402 if (aFunction.IsNull()) return NULL;
404 //Check if the function is set correctly
405 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
407 GEOMImpl_ISpline aCI (aFunction);
409 int aLen = thePoints.size();
413 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
414 for (; it != thePoints.end(); it++, ind++) {
415 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
417 if (aRefPnt.IsNull()) return NULL;
419 aCI.SetPoint(ind, aRefPnt);
422 //Compute the Spline value
424 if (!GetSolver()->ComputeFunction(aFunction)) {
425 SetErrorCode("Spline driver failed");
429 catch (Standard_Failure) {
430 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
431 SetErrorCode(aFail->GetMessageString());
435 //Make a Python command
436 TCollection_AsciiString anEntry, aDescr("");
437 TDF_Tool::Entry(aSpline->GetEntry(), anEntry);
439 aDescr += " = ICurvesOperations.MakeSplineBezier([";
440 it = thePoints.begin();
441 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
443 aDescr += (anEntry+", ");
444 for (; it != thePoints.end(); it++) {
446 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
451 aFunction->SetDescription(aDescr);
457 //=============================================================================
459 * MakeSplineInterpolation
461 //=============================================================================
462 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
463 (list<Handle(GEOM_Object)> thePoints)
467 //Add a new Spline object
468 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
470 //Add a new Spline function for creation a bezier curve relatively to points set
471 Handle(GEOM_Function) aFunction =
472 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
473 if (aFunction.IsNull()) return NULL;
475 //Check if the function is set correctly
476 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
478 GEOMImpl_ISpline aCI (aFunction);
480 int aLen = thePoints.size();
484 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
485 for (; it != thePoints.end(); it++, ind++) {
486 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
488 if (aRefPnt.IsNull()) return NULL;
490 aCI.SetPoint(ind, aRefPnt);
493 //Compute the Spline value
495 if (!GetSolver()->ComputeFunction(aFunction)) {
496 SetErrorCode("Spline driver failed");
500 catch (Standard_Failure) {
501 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
502 SetErrorCode(aFail->GetMessageString());
506 //Make a Python command
507 TCollection_AsciiString anEntry, aDescr("");
508 TDF_Tool::Entry(aSpline->GetEntry(), anEntry);
510 aDescr += " = ICurvesOperations.MakeSplineInterpolation([";
511 it = thePoints.begin();
512 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
514 aDescr += (anEntry+", ");
515 for (; it != thePoints.end(); it++) {
517 TDF_Tool::Entry((*it)->GetEntry(), anEntry);
522 aFunction->SetDescription(aDescr);
528 //=============================================================================
532 //=============================================================================
533 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
534 list<double> theWorkingPlane)
538 if (!theCommand) return NULL;
539 if (strcmp(theCommand, "") == 0) return NULL;
541 //Add a new Sketcher object
542 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
544 //Add a new Sketcher function
545 Handle(GEOM_Function) aFunction =
546 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_COMMAND);
547 if (aFunction.IsNull()) return NULL;
549 //Check if the function is set correctly
550 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
552 GEOMImpl_ISketcher aCI (aFunction);
554 TCollection_AsciiString aCommand ((char*) theCommand);
555 aCI.SetCommand(aCommand);
558 list<double>::iterator it = theWorkingPlane.begin();
559 for (; it != theWorkingPlane.end(); it++, ind++)
560 aCI.SetWorkingPlane(ind, *it);
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 TCollection_AsciiString anEntry, aDescr;
577 TDF_Tool::Entry(aSketcher->GetEntry(), anEntry);
579 aDescr += " = ICurvesOperations.MakeSketcher(";
580 aDescr += aCommand+", [";
582 it = theWorkingPlane.begin();
583 aDescr += TCollection_AsciiString(*it);
585 for (; it != theWorkingPlane.end(); it++) {
587 aDescr += TCollection_AsciiString(*it);
592 aFunction->SetDescription(aDescr);