1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_ICurvesOperations.hxx>
24 #include <GEOM_Function.hxx>
25 #include <GEOM_PythonDump.hxx>
27 #include <GEOMImpl_Types.hxx>
29 #include <GEOMImpl_PolylineDriver.hxx>
30 #include <GEOMImpl_CircleDriver.hxx>
31 #include <GEOMImpl_SplineDriver.hxx>
32 #include <GEOMImpl_EllipseDriver.hxx>
33 #include <GEOMImpl_ArcDriver.hxx>
34 #include <GEOMImpl_SketcherDriver.hxx>
36 #include <GEOMImpl_IPolyline.hxx>
37 #include <GEOMImpl_ICircle.hxx>
38 #include <GEOMImpl_ISpline.hxx>
39 #include <GEOMImpl_IEllipse.hxx>
40 #include <GEOMImpl_IArc.hxx>
41 #include <GEOMImpl_ISketcher.hxx>
43 #include "utilities.h"
45 #include <TDF_Tool.hxx>
47 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
49 //=============================================================================
53 //=============================================================================
54 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
55 : GEOM_IOperations(theEngine, theDocID)
57 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
60 //=============================================================================
64 //=============================================================================
65 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
67 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
71 //=============================================================================
75 //=============================================================================
76 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (list<Handle(GEOM_Object)> thePoints)
80 //Add a new Polyline object
81 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
83 //Add a new Polyline function for creation a polyline relatively to points set
84 Handle(GEOM_Function) aFunction =
85 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
86 if (aFunction.IsNull()) return NULL;
88 //Check if the function is set correctly
89 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
91 GEOMImpl_IPolyline aCI (aFunction);
93 int aLen = thePoints.size();
97 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
98 for (; it != thePoints.end(); it++, ind++) {
99 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
100 if (aRefPnt.IsNull()) {
101 SetErrorCode("NULL point for Polyline");
104 aCI.SetPoint(ind, aRefPnt);
107 //Compute the Polyline value
109 if (!GetSolver()->ComputeFunction(aFunction)) {
110 SetErrorCode("Polyline driver failed");
114 catch (Standard_Failure) {
115 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
116 SetErrorCode(aFail->GetMessageString());
120 //Make a Python command
121 GEOM::TPythonDump pd (aFunction);
122 pd << aPolyline << " = geompy.MakePolyline([";
124 it = thePoints.begin();
126 while (it != thePoints.end()) {
127 pd << ", " << (*it++);
135 //=============================================================================
139 //=============================================================================
140 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
141 Handle(GEOM_Object) thePnt2,
142 Handle(GEOM_Object) thePnt3)
146 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
148 //Add a new Circle object
149 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
151 //Add a new Circle function for creation a circle relatively to three points
152 Handle(GEOM_Function) aFunction =
153 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
154 if (aFunction.IsNull()) return NULL;
156 //Check if the function is set correctly
157 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
159 GEOMImpl_ICircle aCI (aFunction);
161 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
162 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
163 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
165 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
167 aCI.SetPoint1(aRefPnt1);
168 aCI.SetPoint2(aRefPnt2);
169 aCI.SetPoint3(aRefPnt3);
171 //Compute the Circle value
173 if (!GetSolver()->ComputeFunction(aFunction)) {
174 SetErrorCode("Circle driver failed");
178 catch (Standard_Failure) {
179 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
180 SetErrorCode(aFail->GetMessageString());
184 //Make a Python command
185 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
186 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
192 //=============================================================================
196 //=============================================================================
197 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
198 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
202 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
204 //Add a new Circle object
205 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
207 //Add a new Circle function for creation a circle relatively to point and vector
208 Handle(GEOM_Function) aFunction =
209 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
210 if (aFunction.IsNull()) return NULL;
212 //Check if the function is set correctly
213 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
215 GEOMImpl_ICircle aCI (aFunction);
217 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
218 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
220 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
222 aCI.SetCenter(aRefPnt);
223 aCI.SetVector(aRefVec);
226 //Compute the Circle value
228 if (!GetSolver()->ComputeFunction(aFunction)) {
229 SetErrorCode("Circle driver failed");
233 catch (Standard_Failure) {
234 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
235 SetErrorCode(aFail->GetMessageString());
239 //Make a Python command
240 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
241 << thePnt << ", " << theVec << ", " << theR << ")";
247 //=============================================================================
251 //=============================================================================
252 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
253 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
254 double theRMajor, double theRMinor)
258 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
260 //Add a new Ellipse object
261 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
263 //Add a new Ellipse function
264 Handle(GEOM_Function) aFunction =
265 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
266 if (aFunction.IsNull()) return NULL;
268 //Check if the function is set correctly
269 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
271 GEOMImpl_IEllipse aCI (aFunction);
273 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
274 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
276 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
278 aCI.SetCenter(aRefPnt);
279 aCI.SetVector(aRefVec);
280 aCI.SetRMajor(theRMajor);
281 aCI.SetRMinor(theRMinor);
283 //Compute the Ellipse value
285 if (!GetSolver()->ComputeFunction(aFunction)) {
286 SetErrorCode("Ellipse driver failed");
290 catch (Standard_Failure) {
291 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
292 SetErrorCode(aFail->GetMessageString());
296 //Make a Python command
297 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
298 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
304 //=============================================================================
308 //=============================================================================
309 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
310 Handle(GEOM_Object) thePnt2,
311 Handle(GEOM_Object) thePnt3)
315 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
317 //Add a new Circle Arc object
318 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
320 //Add a new Circle Arc function
321 Handle(GEOM_Function) aFunction =
322 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
323 if (aFunction.IsNull()) return NULL;
325 //Check if the function is set correctly
326 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
328 GEOMImpl_IArc aCI (aFunction);
330 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
331 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
332 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
334 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
336 aCI.SetPoint1(aRefPnt1);
337 aCI.SetPoint2(aRefPnt2);
338 aCI.SetPoint3(aRefPnt3);
340 //Compute the Arc value
342 if (!GetSolver()->ComputeFunction(aFunction)) {
343 SetErrorCode("Arc driver failed");
347 catch (Standard_Failure) {
348 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
349 SetErrorCode(aFail->GetMessageString());
353 //Make a Python command
354 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
355 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
361 //=============================================================================
365 //=============================================================================
366 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
367 (list<Handle(GEOM_Object)> thePoints)
371 //Add a new Spline object
372 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
374 //Add a new Spline function for creation a bezier curve relatively to points set
375 Handle(GEOM_Function) aFunction =
376 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
377 if (aFunction.IsNull()) return NULL;
379 //Check if the function is set correctly
380 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
382 GEOMImpl_ISpline aCI (aFunction);
384 int aLen = thePoints.size();
388 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
389 for (; it != thePoints.end(); it++, ind++) {
390 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
392 if (aRefPnt.IsNull()) return NULL;
394 aCI.SetPoint(ind, aRefPnt);
397 //Compute the Spline value
399 if (!GetSolver()->ComputeFunction(aFunction)) {
400 SetErrorCode("Spline driver failed");
404 catch (Standard_Failure) {
405 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
406 SetErrorCode(aFail->GetMessageString());
410 //Make a Python command
411 GEOM::TPythonDump pd (aFunction);
412 pd << aSpline << " = geompy.MakeBezier([";
414 it = thePoints.begin();
416 while (it != thePoints.end()) {
417 pd << ", " << (*it++);
425 //=============================================================================
427 * MakeSplineInterpolation
429 //=============================================================================
430 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
431 (list<Handle(GEOM_Object)> thePoints)
435 //Add a new Spline object
436 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
438 //Add a new Spline function for creation a bezier curve relatively to points set
439 Handle(GEOM_Function) aFunction =
440 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
441 if (aFunction.IsNull()) return NULL;
443 //Check if the function is set correctly
444 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
446 GEOMImpl_ISpline aCI (aFunction);
448 int aLen = thePoints.size();
452 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
453 for (; it != thePoints.end(); it++, ind++) {
454 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
456 if (aRefPnt.IsNull()) return NULL;
458 aCI.SetPoint(ind, aRefPnt);
461 //Compute the Spline value
463 if (!GetSolver()->ComputeFunction(aFunction)) {
464 SetErrorCode("Spline driver failed");
468 catch (Standard_Failure) {
469 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
470 SetErrorCode(aFail->GetMessageString());
474 //Make a Python command
475 GEOM::TPythonDump pd (aFunction);
476 pd << aSpline << " = geompy.MakeInterpol([";
478 it = thePoints.begin();
480 while (it != thePoints.end()) {
481 pd << ", " << (*it++);
489 //=============================================================================
493 //=============================================================================
494 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
495 (const TCollection_AsciiString& theCommand,
496 list<double> theWorkingPlane)
500 if (theCommand.IsEmpty()) return NULL;
502 //Add a new Sketcher object
503 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
505 //Add a new Sketcher function
506 Handle(GEOM_Function) aFunction =
507 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
508 if (aFunction.IsNull()) return NULL;
510 //Check if the function is set correctly
511 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
513 GEOMImpl_ISketcher aCI (aFunction);
515 aCI.SetCommand(theCommand);
518 list<double>::iterator it = theWorkingPlane.begin();
519 for (; it != theWorkingPlane.end(); it++, ind++)
520 aCI.SetWorkingPlane(ind, *it);
522 //Compute the Sketcher value
524 if (!GetSolver()->ComputeFunction(aFunction)) {
525 SetErrorCode("Sketcher driver failed");
529 catch (Standard_Failure) {
530 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
531 SetErrorCode(aFail->GetMessageString());
535 //Make a Python command
536 GEOM::TPythonDump pd (aFunction);
537 pd << aSketcher << " = geompy.MakeSketcher(\"" << theCommand.ToCString() << "\", [";
539 it = theWorkingPlane.begin();
541 while (it != theWorkingPlane.end()) {
542 pd << ", " << (*it++);
550 //=============================================================================
552 * MakeSketcherOnPlane
554 //=============================================================================
555 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
556 (const TCollection_AsciiString& theCommand,
557 Handle(GEOM_Object) theWorkingPlane)
561 if (theCommand.IsEmpty()) return NULL;
563 //Add a new Sketcher object
564 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
566 //Add a new Sketcher function
567 Handle(GEOM_Function) aFunction =
568 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
569 if (aFunction.IsNull()) return NULL;
571 //Check if the function is set correctly
572 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
574 GEOMImpl_ISketcher aCI (aFunction);
575 aCI.SetCommand(theCommand);
577 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
578 if (aRefPlane.IsNull()) return NULL;
579 aCI.SetWorkingPlane( aRefPlane );
581 //Compute the Sketcher value
583 if (!GetSolver()->ComputeFunction(aFunction)) {
584 SetErrorCode("Sketcher driver failed");
588 catch (Standard_Failure) {
589 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
590 SetErrorCode(aFail->GetMessageString());
594 //Make a Python command
595 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
596 << theCommand.ToCString() << "\", " << theWorkingPlane << " )";