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_Failure.hxx>
48 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
50 //=============================================================================
54 //=============================================================================
55 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
56 : GEOM_IOperations(theEngine, theDocID)
58 MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
61 //=============================================================================
65 //=============================================================================
66 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
68 MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
72 //=============================================================================
76 //=============================================================================
77 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (list<Handle(GEOM_Object)> thePoints)
81 //Add a new Polyline object
82 Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
84 //Add a new Polyline function for creation a polyline relatively to points set
85 Handle(GEOM_Function) aFunction =
86 aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
87 if (aFunction.IsNull()) return NULL;
89 //Check if the function is set correctly
90 if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
92 GEOMImpl_IPolyline aCI (aFunction);
94 int aLen = thePoints.size();
98 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
99 for (; it != thePoints.end(); it++, ind++) {
100 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
101 if (aRefPnt.IsNull()) {
102 SetErrorCode("NULL point for Polyline");
105 aCI.SetPoint(ind, aRefPnt);
108 //Compute the Polyline value
110 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
113 if (!GetSolver()->ComputeFunction(aFunction)) {
114 SetErrorCode("Polyline driver failed");
118 catch (Standard_Failure) {
119 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
120 SetErrorCode(aFail->GetMessageString());
124 //Make a Python command
125 GEOM::TPythonDump pd (aFunction);
126 pd << aPolyline << " = geompy.MakePolyline([";
128 it = thePoints.begin();
130 while (it != thePoints.end()) {
131 pd << ", " << (*it++);
139 //=============================================================================
143 //=============================================================================
144 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
145 Handle(GEOM_Object) thePnt2,
146 Handle(GEOM_Object) thePnt3)
150 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
152 //Add a new Circle object
153 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
155 //Add a new Circle function for creation a circle relatively to three points
156 Handle(GEOM_Function) aFunction =
157 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
158 if (aFunction.IsNull()) return NULL;
160 //Check if the function is set correctly
161 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
163 GEOMImpl_ICircle aCI (aFunction);
165 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
166 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
167 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
169 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
171 aCI.SetPoint1(aRefPnt1);
172 aCI.SetPoint2(aRefPnt2);
173 aCI.SetPoint3(aRefPnt3);
175 //Compute the Circle value
177 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
180 if (!GetSolver()->ComputeFunction(aFunction)) {
181 SetErrorCode("Circle driver failed");
185 catch (Standard_Failure) {
186 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
187 SetErrorCode(aFail->GetMessageString());
191 //Make a Python command
192 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
193 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
199 //=============================================================================
203 //=============================================================================
204 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
205 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
209 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
211 //Add a new Circle object
212 Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
214 //Add a new Circle function for creation a circle relatively to point and vector
215 Handle(GEOM_Function) aFunction =
216 aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
217 if (aFunction.IsNull()) return NULL;
219 //Check if the function is set correctly
220 if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
222 GEOMImpl_ICircle aCI (aFunction);
224 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
225 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
227 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
229 aCI.SetCenter(aRefPnt);
230 aCI.SetVector(aRefVec);
233 //Compute the Circle value
235 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
238 if (!GetSolver()->ComputeFunction(aFunction)) {
239 SetErrorCode("Circle driver failed");
243 catch (Standard_Failure) {
244 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
245 SetErrorCode(aFail->GetMessageString());
249 //Make a Python command
250 GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
251 << thePnt << ", " << theVec << ", " << theR << ")";
257 //=============================================================================
261 //=============================================================================
262 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
263 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
264 double theRMajor, double theRMinor)
268 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
270 //Add a new Ellipse object
271 Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
273 //Add a new Ellipse function
274 Handle(GEOM_Function) aFunction =
275 anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
276 if (aFunction.IsNull()) return NULL;
278 //Check if the function is set correctly
279 if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
281 GEOMImpl_IEllipse aCI (aFunction);
283 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
284 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
286 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
288 aCI.SetCenter(aRefPnt);
289 aCI.SetVector(aRefVec);
290 aCI.SetRMajor(theRMajor);
291 aCI.SetRMinor(theRMinor);
293 //Compute the Ellipse value
295 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
298 if (!GetSolver()->ComputeFunction(aFunction)) {
299 SetErrorCode("Ellipse driver failed");
303 catch (Standard_Failure) {
304 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
305 SetErrorCode(aFail->GetMessageString());
309 //Make a Python command
310 GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
311 << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
317 //=============================================================================
321 //=============================================================================
322 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
323 Handle(GEOM_Object) thePnt2,
324 Handle(GEOM_Object) thePnt3)
328 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
330 //Add a new Circle Arc object
331 Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
333 //Add a new Circle Arc function
334 Handle(GEOM_Function) aFunction =
335 anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
336 if (aFunction.IsNull()) return NULL;
338 //Check if the function is set correctly
339 if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
341 GEOMImpl_IArc aCI (aFunction);
343 Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
344 Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
345 Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
347 if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
349 aCI.SetPoint1(aRefPnt1);
350 aCI.SetPoint2(aRefPnt2);
351 aCI.SetPoint3(aRefPnt3);
353 //Compute the Arc value
355 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
358 if (!GetSolver()->ComputeFunction(aFunction)) {
359 SetErrorCode("Arc driver failed");
363 catch (Standard_Failure) {
364 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
365 SetErrorCode(aFail->GetMessageString());
369 //Make a Python command
370 GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
371 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
377 //=============================================================================
381 //=============================================================================
382 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
383 (list<Handle(GEOM_Object)> thePoints)
387 //Add a new Spline object
388 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
390 //Add a new Spline function for creation a bezier curve relatively to points set
391 Handle(GEOM_Function) aFunction =
392 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
393 if (aFunction.IsNull()) return NULL;
395 //Check if the function is set correctly
396 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
398 GEOMImpl_ISpline aCI (aFunction);
400 int aLen = thePoints.size();
404 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
405 for (; it != thePoints.end(); it++, ind++) {
406 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
408 if (aRefPnt.IsNull()) return NULL;
410 aCI.SetPoint(ind, aRefPnt);
413 //Compute the Spline value
415 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
418 if (!GetSolver()->ComputeFunction(aFunction)) {
419 SetErrorCode("Spline driver failed");
423 catch (Standard_Failure) {
424 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
425 SetErrorCode(aFail->GetMessageString());
429 //Make a Python command
430 GEOM::TPythonDump pd (aFunction);
431 pd << aSpline << " = geompy.MakeBezier([";
433 it = thePoints.begin();
435 while (it != thePoints.end()) {
436 pd << ", " << (*it++);
444 //=============================================================================
446 * MakeSplineInterpolation
448 //=============================================================================
449 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
450 (list<Handle(GEOM_Object)> thePoints)
454 //Add a new Spline object
455 Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
457 //Add a new Spline function for creation a bezier curve relatively to points set
458 Handle(GEOM_Function) aFunction =
459 aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
460 if (aFunction.IsNull()) return NULL;
462 //Check if the function is set correctly
463 if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
465 GEOMImpl_ISpline aCI (aFunction);
467 int aLen = thePoints.size();
471 list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
472 for (; it != thePoints.end(); it++, ind++) {
473 Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
475 if (aRefPnt.IsNull()) return NULL;
477 aCI.SetPoint(ind, aRefPnt);
480 //Compute the Spline value
482 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
485 if (!GetSolver()->ComputeFunction(aFunction)) {
486 SetErrorCode("Spline driver failed");
490 catch (Standard_Failure) {
491 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
492 SetErrorCode(aFail->GetMessageString());
496 //Make a Python command
497 GEOM::TPythonDump pd (aFunction);
498 pd << aSpline << " = geompy.MakeInterpol([";
500 it = thePoints.begin();
502 while (it != thePoints.end()) {
503 pd << ", " << (*it++);
511 //=============================================================================
515 //=============================================================================
516 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
517 (const TCollection_AsciiString& theCommand,
518 list<double> theWorkingPlane)
522 if (theCommand.IsEmpty()) return NULL;
524 //Add a new Sketcher object
525 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
527 //Add a new Sketcher function
528 Handle(GEOM_Function) aFunction =
529 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
530 if (aFunction.IsNull()) return NULL;
532 //Check if the function is set correctly
533 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
535 GEOMImpl_ISketcher aCI (aFunction);
537 aCI.SetCommand(theCommand);
540 list<double>::iterator it = theWorkingPlane.begin();
541 for (; it != theWorkingPlane.end(); it++, ind++)
542 aCI.SetWorkingPlane(ind, *it);
544 //Compute the Sketcher value
546 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
549 if (!GetSolver()->ComputeFunction(aFunction)) {
550 SetErrorCode("Sketcher driver failed");
554 catch (Standard_Failure) {
555 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
556 SetErrorCode(aFail->GetMessageString());
560 //Make a Python command
561 GEOM::TPythonDump pd (aFunction);
562 pd << aSketcher << " = geompy.MakeSketcher(\"" << theCommand.ToCString() << "\", [";
564 it = theWorkingPlane.begin();
566 while (it != theWorkingPlane.end()) {
567 pd << ", " << (*it++);
575 //=============================================================================
577 * MakeSketcherOnPlane
579 //=============================================================================
580 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
581 (const TCollection_AsciiString& theCommand,
582 Handle(GEOM_Object) theWorkingPlane)
586 if (theCommand.IsEmpty()) return NULL;
588 //Add a new Sketcher object
589 Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
591 //Add a new Sketcher function
592 Handle(GEOM_Function) aFunction =
593 aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
594 if (aFunction.IsNull()) return NULL;
596 //Check if the function is set correctly
597 if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
599 GEOMImpl_ISketcher aCI (aFunction);
600 aCI.SetCommand(theCommand);
602 Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
603 if (aRefPlane.IsNull()) return NULL;
604 aCI.SetWorkingPlane( aRefPlane );
606 //Compute the Sketcher value
608 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
611 if (!GetSolver()->ComputeFunction(aFunction)) {
612 SetErrorCode("Sketcher driver failed");
616 catch (Standard_Failure) {
617 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
618 SetErrorCode(aFail->GetMessageString());
622 //Make a Python command
623 GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
624 << theCommand.ToCString() << "\", " << theWorkingPlane << " )";