3 #include "GEOMImpl_IBasicOperations.hxx"
7 #include "Utils_ExceptHandlers.hxx"
9 #include <TFunction_DriverTable.hxx>
10 #include <TFunction_Driver.hxx>
11 #include <TFunction_Logbook.hxx>
12 #include <TDF_Tool.hxx>
14 #include "GEOM_Function.hxx"
15 #include "GEOM_PythonDump.hxx"
17 #include "GEOMImpl_PointDriver.hxx"
18 #include "GEOMImpl_VectorDriver.hxx"
19 #include "GEOMImpl_LineDriver.hxx"
20 #include "GEOMImpl_PlaneDriver.hxx"
21 #include "GEOMImpl_MarkerDriver.hxx"
23 #include "GEOMImpl_IPoint.hxx"
24 #include "GEOMImpl_IVector.hxx"
25 #include "GEOMImpl_ILine.hxx"
26 #include "GEOMImpl_IPlane.hxx"
27 #include "GEOMImpl_IMarker.hxx"
29 #include "GEOMImpl_Types.hxx"
31 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
33 //=============================================================================
37 //=============================================================================
38 GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations(GEOM_Engine* theEngine, int theDocID)
39 : GEOM_IOperations(theEngine, theDocID)
41 MESSAGE("GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations");
44 //=============================================================================
48 //=============================================================================
49 GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations()
51 MESSAGE("GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations");
55 //=============================================================================
59 //=============================================================================
60 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointXYZ
61 (double theX, double theY, double theZ)
65 //Add a new Point object
66 Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
68 //Add a new Point function with XYZ parameters
69 Handle(GEOM_Function) aFunction =
70 aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ);
71 if (aFunction.IsNull()) return NULL;
73 //Check if the function is set correctly
74 if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
76 GEOMImpl_IPoint aPI(aFunction);
82 //Compute the point value
84 if (!GetSolver()->ComputeFunction(aFunction)) {
85 SetErrorCode("Point driver failed");
89 catch (Standard_Failure) {
90 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
91 SetErrorCode(aFail->GetMessageString());
95 //Make a Python command
96 GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertex("
97 << theX << ", " << theY << ", " << theZ << ")";
103 //=============================================================================
105 * MakePointWithReference
107 //=============================================================================
108 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointWithReference
109 (Handle(GEOM_Object) theReference, double theX, double theY, double theZ)
113 if (theReference.IsNull()) return NULL;
115 //Add a new Point object
116 Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
118 //Add a new Point function for creation a point relativley another point
119 Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ_REF);
121 //Check if the function is set correctly
122 if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
124 GEOMImpl_IPoint aPI(aFunction);
126 Handle(GEOM_Function) aRefFunction = theReference->GetLastFunction();
127 if (aRefFunction.IsNull()) return NULL;
129 aPI.SetRef(aRefFunction);
134 //Compute the point value
136 if (!GetSolver()->ComputeFunction(aFunction)) {
137 SetErrorCode("Point driver failed");
141 catch (Standard_Failure) {
142 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
143 SetErrorCode(aFail->GetMessageString());
147 //Make a Python command
148 GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexWithRef("
149 << theReference << ", " << theX << ", " << theY << ", " << theZ << ")";
155 //=============================================================================
159 //=============================================================================
160 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurve
161 (Handle(GEOM_Object) theCurve, double theParameter)
165 if (theCurve.IsNull()) return NULL;
167 //Add a new Point object
168 Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
170 //Add a new Point function for creation a point relativley another point
171 Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_CURVE_PAR);
173 //Check if the function is set correctly
174 if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
176 GEOMImpl_IPoint aPI (aFunction);
178 Handle(GEOM_Function) aRefFunction = theCurve->GetLastFunction();
179 if (aRefFunction.IsNull()) return NULL;
181 aPI.SetCurve(aRefFunction);
182 aPI.SetParameter(theParameter);
184 //Compute the point value
186 if (!GetSolver()->ComputeFunction(aFunction)) {
187 SetErrorCode("Point driver failed");
191 catch (Standard_Failure) {
192 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
193 SetErrorCode(aFail->GetMessageString());
197 //Make a Python command
198 GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurve("
199 << theCurve << ", " << theParameter << ")";
206 //=============================================================================
210 //=============================================================================
211 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorDXDYDZ
212 (double theDX, double theDY, double theDZ)
216 //Add a new Vector object
217 Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
219 //Add a new Vector function with DXDYDZ parameters
220 Handle(GEOM_Function) aFunction =
221 aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_DX_DY_DZ);
222 if (aFunction.IsNull()) return NULL;
224 //Check if the function is set correctly
225 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
227 GEOMImpl_IVector aPI (aFunction);
233 //Compute the Vector value
235 if (!GetSolver()->ComputeFunction(aFunction)) {
236 SetErrorCode("Vector driver failed");
240 catch (Standard_Failure) {
241 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
242 SetErrorCode(aFail->GetMessageString());
246 //Make a Python command
247 GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVectorDXDYDZ("
248 << theDX << ", " << theDY << ", " << theDZ << ")";
254 //=============================================================================
258 //=============================================================================
259 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorTwoPnt
260 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
264 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
266 //Add a new Vector object
267 Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
269 //Add a new Vector function
270 Handle(GEOM_Function) aFunction =
271 aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
273 //Check if the function is set correctly
274 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
276 GEOMImpl_IVector aPI (aFunction);
278 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
279 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
280 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
282 aPI.SetPoint1(aRef1);
283 aPI.SetPoint2(aRef2);
285 //Compute the Vector value
287 if (!GetSolver()->ComputeFunction(aFunction)) {
288 SetErrorCode("Vector driver failed");
292 catch (Standard_Failure) {
293 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
294 SetErrorCode(aFail->GetMessageString());
298 //Make a Python command
299 GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVector("
300 << thePnt1 << ", " << thePnt2 << ")";
307 //=============================================================================
311 //=============================================================================
312 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLine
313 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theDir)
317 if (thePnt.IsNull() || theDir.IsNull()) return NULL;
319 //Add a new Line object
320 Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
322 //Add a new Line function
323 Handle(GEOM_Function) aFunction =
324 aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_PNT_DIR);
326 //Check if the function is set correctly
327 if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
329 GEOMImpl_ILine aPI (aFunction);
331 Handle(GEOM_Function) aRef1 = thePnt->GetLastFunction();
332 Handle(GEOM_Function) aRef2 = theDir->GetLastFunction();
333 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
335 aPI.SetPoint1(aRef1);
336 aPI.SetPoint2(aRef2);
338 //Compute the Line value
340 if (!GetSolver()->ComputeFunction(aFunction)) {
341 SetErrorCode("Line driver failed");
345 catch (Standard_Failure) {
346 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
347 SetErrorCode(aFail->GetMessageString());
351 //Make a Python command
352 GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLine("
353 << thePnt << ", " << theDir << ")";
359 //=============================================================================
363 //=============================================================================
364 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoPnt
365 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
369 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
371 //Add a new Line object
372 Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
374 //Add a new Line function
375 Handle(GEOM_Function) aFunction =
376 aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_PNT);
378 //Check if the function is set correctly
379 if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
381 GEOMImpl_ILine aPI (aFunction);
383 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
384 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
385 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
387 aPI.SetPoint1(aRef1);
388 aPI.SetPoint2(aRef2);
390 //Compute the Line value
392 if (!GetSolver()->ComputeFunction(aFunction)) {
393 SetErrorCode("Line driver failed");
397 catch (Standard_Failure) {
398 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
399 SetErrorCode(aFail->GetMessageString());
403 //Make a Python command
404 GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoPnt("
405 << thePnt1 << ", " << thePnt2 << ")";
412 //=============================================================================
416 //=============================================================================
417 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneThreePnt
418 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2,
419 Handle(GEOM_Object) thePnt3, double theSize)
423 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
425 //Add a new Plane object
426 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
428 //Add a new Plane function
429 Handle(GEOM_Function) aFunction =
430 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_THREE_PNT);
432 //Check if the function is set correctly
433 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
435 GEOMImpl_IPlane aPI (aFunction);
437 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
438 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
439 Handle(GEOM_Function) aRef3 = thePnt3->GetLastFunction();
440 if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull()) return NULL;
442 aPI.SetPoint1(aRef1);
443 aPI.SetPoint2(aRef2);
444 aPI.SetPoint3(aRef3);
445 aPI.SetSize(theSize);
447 //Compute the Plane value
449 if (!GetSolver()->ComputeFunction(aFunction)) {
450 SetErrorCode("Plane driver failed");
454 catch (Standard_Failure) {
455 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
456 SetErrorCode(aFail->GetMessageString());
460 //Make a Python command
461 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneThreePnt("
462 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ", " << theSize << ")";
468 //=============================================================================
472 //=============================================================================
473 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlanePntVec
474 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
479 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
481 //Add a new Plane object
482 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
484 //Add a new Plane function
485 Handle(GEOM_Function) aFunction =
486 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_PNT_VEC);
488 //Check if the function is set correctly
489 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
491 GEOMImpl_IPlane aPI (aFunction);
493 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
494 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
495 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
497 aPI.SetPoint(aRefPnt);
498 aPI.SetVector(aRefVec);
499 aPI.SetSize(theSize);
501 //Compute the Plane value
503 if (!GetSolver()->ComputeFunction(aFunction)) {
504 SetErrorCode("Plane driver failed");
508 catch (Standard_Failure) {
509 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
510 SetErrorCode(aFail->GetMessageString());
514 //Make a Python command
515 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlane("
516 << thePnt << ", " << theVec << ", " << theSize << ")";
522 //=============================================================================
526 //=============================================================================
527 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneFace
528 (Handle(GEOM_Object) theFace, double theSize)
532 if (theFace.IsNull()) return NULL;
534 //Add a new Plane object
535 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
537 //Add a new Plane function
538 Handle(GEOM_Function) aFunction =
539 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_FACE);
541 //Check if the function is set correctly
542 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
544 GEOMImpl_IPlane aPI (aFunction);
546 Handle(GEOM_Function) aRef = theFace->GetLastFunction();
547 if (aRef.IsNull()) return NULL;
550 aPI.SetSize(theSize);
552 //Compute the Plane value
554 if (!GetSolver()->ComputeFunction(aFunction)) {
555 SetErrorCode("Plane driver failed");
559 catch (Standard_Failure) {
560 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
561 SetErrorCode(aFail->GetMessageString());
565 //Make a Python command
566 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneFace("
567 << theFace << ", " << theSize << ")";
574 //=============================================================================
578 //=============================================================================
579 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarker
580 (double theOX, double theOY, double theOZ,
581 double theXDX, double theXDY, double theXDZ,
582 double theYDX, double theYDY, double theYDZ)
586 //Add a new Marker object
587 Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GetDocID(), GEOM_MARKER);
589 //Add a new Marker function
590 Handle(GEOM_Function) aFunction =
591 aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_CS);
592 if (aFunction.IsNull()) return NULL;
594 //Check if the function is set correctly
595 if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
597 GEOMImpl_IMarker aPI(aFunction);
599 aPI.SetOrigin(theOX, theOY, theOZ);
600 aPI.SetXDir(theXDX, theXDY, theXDZ);
601 aPI.SetYDir(theYDX, theYDY, theYDZ);
603 //Compute the marker value
605 if (!GetSolver()->ComputeFunction(aFunction)) {
606 SetErrorCode("Marker driver failed");
610 catch (Standard_Failure) {
611 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
612 SetErrorCode(aFail->GetMessageString());
616 //Make a Python command
617 GEOM::TPythonDump(aFunction) << aMarker << " = geompy.MakeMarker("
618 << theOX << ", " << theOY << ", " << theOZ << ", "
619 << theXDX << ", " << theXDY << ", " << theXDZ << ", "
620 << theYDX << ", " << theYDY << ", " << theYDZ << ")";