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"
16 #include "GEOMImpl_PointDriver.hxx"
17 #include "GEOMImpl_VectorDriver.hxx"
18 #include "GEOMImpl_LineDriver.hxx"
19 #include "GEOMImpl_PlaneDriver.hxx"
20 #include "GEOMImpl_MarkerDriver.hxx"
22 #include "GEOMImpl_IPoint.hxx"
23 #include "GEOMImpl_IVector.hxx"
24 #include "GEOMImpl_ILine.hxx"
25 #include "GEOMImpl_IPlane.hxx"
26 #include "GEOMImpl_IMarker.hxx"
28 #include "GEOMImpl_Types.hxx"
30 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
32 //=============================================================================
36 //=============================================================================
37 GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations(GEOM_Engine* theEngine, int theDocID)
38 : GEOM_IOperations(theEngine, theDocID)
40 MESSAGE("GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations");
43 //=============================================================================
47 //=============================================================================
48 GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations()
50 MESSAGE("GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations");
54 //=============================================================================
58 //=============================================================================
59 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointXYZ
60 (double theX, double theY, double theZ)
64 //Add a new Point object
65 Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
67 //Add a new Point function with XYZ parameters
68 Handle(GEOM_Function) aFunction =
69 aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ);
70 if (aFunction.IsNull()) return NULL;
72 //Check if the function is set correctly
73 if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
75 GEOMImpl_IPoint aPI(aFunction);
81 //Compute the point value
83 if (!GetSolver()->ComputeFunction(aFunction)) {
84 SetErrorCode("Point driver failed");
88 catch (Standard_Failure) {
89 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
90 SetErrorCode(aFail->GetMessageString());
94 //Make a Python command
95 TCollection_AsciiString anEntry, aDescr;
96 TDF_Tool::Entry(aPoint->GetEntry(), anEntry);
97 aDescr += (anEntry+" = IBasicOperations.MakePointXYZ(");
98 aDescr += (TCollection_AsciiString(theX)+", ");
99 aDescr += (TCollection_AsciiString(theY)+", ");
100 aDescr += (TCollection_AsciiString(theZ)+")");
102 aFunction->SetDescription(aDescr);
108 //=============================================================================
110 * MakePointWithReference
112 //=============================================================================
113 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointWithReference
114 (Handle(GEOM_Object) theReference, double theX, double theY, double theZ)
118 if (theReference.IsNull()) return NULL;
120 //Add a new Point object
121 Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
123 //Add a new Point function for creation a point relativley another point
124 Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ_REF);
126 //Check if the function is set correctly
127 if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
129 GEOMImpl_IPoint aPI(aFunction);
131 Handle(GEOM_Function) aRefFunction = theReference->GetLastFunction();
132 if (aRefFunction.IsNull()) return NULL;
134 aPI.SetRef(aRefFunction);
139 //Compute the point value
141 if (!GetSolver()->ComputeFunction(aFunction)) {
142 SetErrorCode("Point driver failed");
146 catch (Standard_Failure) {
147 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
148 SetErrorCode(aFail->GetMessageString());
152 //Make a Python command
153 TCollection_AsciiString anEntry, aDescr;
154 TDF_Tool::Entry(aPoint->GetEntry(), anEntry);
155 aDescr += (anEntry+" = IBasicOperations.MakePointReference(");
156 TDF_Tool::Entry(theReference->GetEntry(), anEntry);
157 aDescr += (anEntry+", ");
158 aDescr += (TCollection_AsciiString(theX)+", ");
159 aDescr += (TCollection_AsciiString(theY)+", ");
160 aDescr += (TCollection_AsciiString(theZ)+")");
162 aFunction->SetDescription(aDescr);
168 //=============================================================================
172 //=============================================================================
173 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurve
174 (Handle(GEOM_Object) theCurve, double theParameter)
178 if (theCurve.IsNull()) return NULL;
180 //Add a new Point object
181 Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
183 //Add a new Point function for creation a point relativley another point
184 Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_CURVE_PAR);
186 //Check if the function is set correctly
187 if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
189 GEOMImpl_IPoint aPI (aFunction);
191 Handle(GEOM_Function) aRefFunction = theCurve->GetLastFunction();
192 if (aRefFunction.IsNull()) return NULL;
194 aPI.SetCurve(aRefFunction);
195 aPI.SetParameter(theParameter);
197 //Compute the point value
199 if (!GetSolver()->ComputeFunction(aFunction)) {
200 SetErrorCode("Point driver failed");
204 catch (Standard_Failure) {
205 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
206 SetErrorCode(aFail->GetMessageString());
210 //Make a Python command
211 TCollection_AsciiString anEntry, aDescr;
212 TDF_Tool::Entry(aPoint->GetEntry(), anEntry);
213 aDescr += (anEntry+" = IBasicOperations.MakePointReference(");
214 TDF_Tool::Entry(theCurve->GetEntry(), anEntry);
215 aDescr += (anEntry+", ");
216 aDescr += (TCollection_AsciiString(theParameter)+")");
218 aFunction->SetDescription(aDescr);
225 //=============================================================================
229 //=============================================================================
230 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorDXDYDZ
231 (double theDX, double theDY, double theDZ)
235 //Add a new Vector object
236 Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
238 //Add a new Vector function with DXDYDZ parameters
239 Handle(GEOM_Function) aFunction =
240 aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_DX_DY_DZ);
241 if (aFunction.IsNull()) return NULL;
243 //Check if the function is set correctly
244 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
246 GEOMImpl_IVector aPI (aFunction);
252 //Compute the Vector value
254 if (!GetSolver()->ComputeFunction(aFunction)) {
255 SetErrorCode("Vector driver failed");
259 catch (Standard_Failure) {
260 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
261 SetErrorCode(aFail->GetMessageString());
265 //Make a Python command
266 TCollection_AsciiString anEntry, aDescr;
267 TDF_Tool::Entry(aVector->GetEntry(), anEntry);
268 aDescr += (anEntry+" = IBasicOperations.MakeVectorDXDYDZ(");
269 aDescr += (TCollection_AsciiString(theDX)+", ");
270 aDescr += (TCollection_AsciiString(theDY)+", ");
271 aDescr += (TCollection_AsciiString(theDZ)+")");
273 aFunction->SetDescription(aDescr);
279 //=============================================================================
283 //=============================================================================
284 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorTwoPnt
285 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
289 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
291 //Add a new Vector object
292 Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
294 //Add a new Vector function
295 Handle(GEOM_Function) aFunction =
296 aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
298 //Check if the function is set correctly
299 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
301 GEOMImpl_IVector aPI (aFunction);
303 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
304 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
305 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
307 aPI.SetPoint1(aRef1);
308 aPI.SetPoint2(aRef2);
310 //Compute the Vector value
312 if (!GetSolver()->ComputeFunction(aFunction)) {
313 SetErrorCode("Vector driver failed");
317 catch (Standard_Failure) {
318 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
319 SetErrorCode(aFail->GetMessageString());
323 //Make a Python command
324 TCollection_AsciiString anEntry, aDescr;
325 TDF_Tool::Entry(aVector->GetEntry(), anEntry);
326 aDescr += (anEntry+" = IBasicOperations.MakeVectorTwoPnt(");
327 TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
328 aDescr += (anEntry+", ");
329 TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
330 aDescr += (anEntry+")");
332 aFunction->SetDescription(aDescr);
339 //=============================================================================
343 //=============================================================================
344 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLine
345 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theDir)
349 if (thePnt.IsNull() || theDir.IsNull()) return NULL;
351 //Add a new Line object
352 Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
354 //Add a new Line function
355 Handle(GEOM_Function) aFunction =
356 aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_PNT_DIR);
358 //Check if the function is set correctly
359 if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
361 GEOMImpl_ILine aPI (aFunction);
363 Handle(GEOM_Function) aRef1 = thePnt->GetLastFunction();
364 Handle(GEOM_Function) aRef2 = theDir->GetLastFunction();
365 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
367 aPI.SetPoint1(aRef1);
368 aPI.SetPoint2(aRef2);
370 //Compute the Line value
372 if (!GetSolver()->ComputeFunction(aFunction)) {
373 SetErrorCode("Line driver failed");
377 catch (Standard_Failure) {
378 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
379 SetErrorCode(aFail->GetMessageString());
383 //Make a Python command
384 TCollection_AsciiString anEntry, aDescr;
385 TDF_Tool::Entry(aLine->GetEntry(), anEntry);
386 aDescr += (anEntry+" = IBasicOperations.MakeLine(");
387 TDF_Tool::Entry(thePnt->GetEntry(), anEntry);
388 aDescr += (anEntry+", ");
389 TDF_Tool::Entry(theDir->GetEntry(), anEntry);
390 aDescr += (anEntry+")");
392 aFunction->SetDescription(aDescr);
398 //=============================================================================
402 //=============================================================================
403 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoPnt
404 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
408 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
410 //Add a new Line object
411 Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
413 //Add a new Line function
414 Handle(GEOM_Function) aFunction =
415 aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_PNT);
417 //Check if the function is set correctly
418 if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
420 GEOMImpl_ILine aPI (aFunction);
422 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
423 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
424 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
426 aPI.SetPoint1(aRef1);
427 aPI.SetPoint2(aRef2);
429 //Compute the Line value
431 if (!GetSolver()->ComputeFunction(aFunction)) {
432 SetErrorCode("Line driver failed");
436 catch (Standard_Failure) {
437 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
438 SetErrorCode(aFail->GetMessageString());
442 //Make a Python command
443 TCollection_AsciiString anEntry, aDescr;
444 TDF_Tool::Entry(aLine->GetEntry(), anEntry);
445 aDescr += (anEntry+" = IBasicOperations.MakeLineTwoPnt(");
446 TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
447 aDescr += (anEntry+", ");
448 TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
449 aDescr += (anEntry+")");
451 aFunction->SetDescription(aDescr);
458 //=============================================================================
462 //=============================================================================
463 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneThreePnt
464 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2,
465 Handle(GEOM_Object) thePnt3, double theSize)
469 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
471 //Add a new Plane object
472 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
474 //Add a new Plane function
475 Handle(GEOM_Function) aFunction =
476 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_THREE_PNT);
478 //Check if the function is set correctly
479 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
481 GEOMImpl_IPlane aPI (aFunction);
483 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
484 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
485 Handle(GEOM_Function) aRef3 = thePnt3->GetLastFunction();
486 if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull()) return NULL;
488 aPI.SetPoint1(aRef1);
489 aPI.SetPoint2(aRef2);
490 aPI.SetPoint3(aRef3);
491 aPI.SetSize(theSize);
493 //Compute the Plane value
495 if (!GetSolver()->ComputeFunction(aFunction)) {
496 SetErrorCode("Plane 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(aPlane->GetEntry(), anEntry);
509 aDescr += (anEntry+" = IBasicOperations.MakePlaneThreePnt(");
510 TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
511 aDescr += (anEntry+", ");
512 TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
513 aDescr += (anEntry+", ");
514 TDF_Tool::Entry(thePnt3->GetEntry(), anEntry);
515 aDescr += (anEntry+", ");
516 aDescr += TCollection_AsciiString(theSize) + ")";
518 aFunction->SetDescription(aDescr);
524 //=============================================================================
528 //=============================================================================
529 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlanePntVec
530 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
535 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
537 //Add a new Plane object
538 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
540 //Add a new Plane function
541 Handle(GEOM_Function) aFunction =
542 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_PNT_VEC);
544 //Check if the function is set correctly
545 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
547 GEOMImpl_IPlane aPI (aFunction);
549 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
550 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
551 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
553 aPI.SetPoint(aRefPnt);
554 aPI.SetVector(aRefVec);
555 aPI.SetSize(theSize);
557 //Compute the Plane value
559 if (!GetSolver()->ComputeFunction(aFunction)) {
560 SetErrorCode("Plane driver failed");
564 catch (Standard_Failure) {
565 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
566 SetErrorCode(aFail->GetMessageString());
570 //Make a Python command
571 TCollection_AsciiString anEntry, aDescr;
572 TDF_Tool::Entry(aPlane->GetEntry(), anEntry);
573 aDescr += (anEntry+" = IBasicOperations.MakePlanePntVec(");
574 TDF_Tool::Entry(thePnt->GetEntry(), anEntry);
575 aDescr += (anEntry+", ");
576 TDF_Tool::Entry(theVec->GetEntry(), anEntry);
577 aDescr += (anEntry+", ");
578 aDescr += TCollection_AsciiString(theSize) + ")";
580 aFunction->SetDescription(aDescr);
586 //=============================================================================
590 //=============================================================================
591 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneFace
592 (Handle(GEOM_Object) theFace, double theSize)
596 if (theFace.IsNull()) return NULL;
598 //Add a new Plane object
599 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
601 //Add a new Plane function
602 Handle(GEOM_Function) aFunction =
603 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_FACE);
605 //Check if the function is set correctly
606 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
608 GEOMImpl_IPlane aPI (aFunction);
610 Handle(GEOM_Function) aRef = theFace->GetLastFunction();
611 if (aRef.IsNull()) return NULL;
614 aPI.SetSize(theSize);
616 //Compute the Plane value
618 if (!GetSolver()->ComputeFunction(aFunction)) {
619 SetErrorCode("Plane driver failed");
623 catch (Standard_Failure) {
624 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
625 SetErrorCode(aFail->GetMessageString());
629 //Make a Python command
630 TCollection_AsciiString anEntry, aDescr;
631 TDF_Tool::Entry(aPlane->GetEntry(), anEntry);
632 aDescr += (anEntry+" = IBasicOperations.MakePlaneFace(");
633 TDF_Tool::Entry(theFace->GetEntry(), anEntry);
634 aDescr += (anEntry+", ");
635 aDescr += TCollection_AsciiString(theSize) + ")";
637 aFunction->SetDescription(aDescr);
644 //=============================================================================
648 //=============================================================================
649 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarker
650 (double theOX, double theOY, double theOZ,
651 double theXDX, double theXDY, double theXDZ,
652 double theYDX, double theYDY, double theYDZ)
656 //Add a new Marker object
657 Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GetDocID(), GEOM_MARKER);
659 //Add a new Marker function
660 Handle(GEOM_Function) aFunction =
661 aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_CS);
662 if (aFunction.IsNull()) return NULL;
664 //Check if the function is set correctly
665 if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
667 GEOMImpl_IMarker aPI(aFunction);
669 aPI.SetOrigin(theOX, theOY, theOZ);
670 aPI.SetXDir(theXDX, theXDY, theXDZ);
671 aPI.SetYDir(theYDX, theYDY, theYDZ);
673 //Compute the marker value
675 if (!GetSolver()->ComputeFunction(aFunction)) {
676 SetErrorCode("Marker driver failed");
680 catch (Standard_Failure) {
681 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
682 SetErrorCode(aFail->GetMessageString());
686 //Make a Python command
687 TCollection_AsciiString anEntry, aDescr;
688 TDF_Tool::Entry(aMarker->GetEntry(), anEntry);
689 aDescr += anEntry + " = IBasicOperations.MakeMarker(";
690 aDescr += TCollection_AsciiString(theOX) + ", ";
691 aDescr += TCollection_AsciiString(theOY) + ", ";
692 aDescr += TCollection_AsciiString(theOZ) + ", ";
693 aDescr += TCollection_AsciiString(theXDX) + ", ";
694 aDescr += TCollection_AsciiString(theXDY) + ", ";
695 aDescr += TCollection_AsciiString(theXDZ) + ", ";
696 aDescr += TCollection_AsciiString(theYDX) + ", ";
697 aDescr += TCollection_AsciiString(theYDY) + ", ";
698 aDescr += TCollection_AsciiString(theYDZ) + ")";
700 aFunction->SetDescription(aDescr);