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::MakeLineTwoPnt
345 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
349 if (thePnt1.IsNull() || thePnt2.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_TWO_PNT);
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 = thePnt1->GetLastFunction();
364 Handle(GEOM_Function) aRef2 = thePnt2->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.MakeLineTwoPnt(");
387 TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
388 aDescr += (anEntry+", ");
389 TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
390 aDescr += (anEntry+")");
392 aFunction->SetDescription(aDescr);
399 //=============================================================================
403 //=============================================================================
404 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneThreePnt
405 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2,
406 Handle(GEOM_Object) thePnt3, double theSize)
410 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
412 //Add a new Plane object
413 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
415 //Add a new Plane function
416 Handle(GEOM_Function) aFunction =
417 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_THREE_PNT);
419 //Check if the function is set correctly
420 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
422 GEOMImpl_IPlane aPI (aFunction);
424 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
425 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
426 Handle(GEOM_Function) aRef3 = thePnt3->GetLastFunction();
427 if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull()) return NULL;
429 aPI.SetPoint1(aRef1);
430 aPI.SetPoint2(aRef2);
431 aPI.SetPoint3(aRef3);
432 aPI.SetSize(theSize);
434 //Compute the Plane value
436 if (!GetSolver()->ComputeFunction(aFunction)) {
437 SetErrorCode("Plane driver failed");
441 catch (Standard_Failure) {
442 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
443 SetErrorCode(aFail->GetMessageString());
447 //Make a Python command
448 TCollection_AsciiString anEntry, aDescr;
449 TDF_Tool::Entry(aPlane->GetEntry(), anEntry);
450 aDescr += (anEntry+" = IBasicOperations.MakePlaneThreePnt(");
451 TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
452 aDescr += (anEntry+", ");
453 TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
454 aDescr += (anEntry+", ");
455 TDF_Tool::Entry(thePnt3->GetEntry(), anEntry);
456 aDescr += (anEntry+", ");
457 aDescr += TCollection_AsciiString(theSize) + ")";
459 aFunction->SetDescription(aDescr);
465 //=============================================================================
469 //=============================================================================
470 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlanePntVec
471 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
476 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
478 //Add a new Plane object
479 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
481 //Add a new Plane function
482 Handle(GEOM_Function) aFunction =
483 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_PNT_VEC);
485 //Check if the function is set correctly
486 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
488 GEOMImpl_IPlane aPI (aFunction);
490 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
491 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
492 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
494 aPI.SetPoint(aRefPnt);
495 aPI.SetVector(aRefVec);
496 aPI.SetSize(theSize);
498 //Compute the Plane value
500 if (!GetSolver()->ComputeFunction(aFunction)) {
501 SetErrorCode("Plane driver failed");
505 catch (Standard_Failure) {
506 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
507 SetErrorCode(aFail->GetMessageString());
511 //Make a Python command
512 TCollection_AsciiString anEntry, aDescr;
513 TDF_Tool::Entry(aPlane->GetEntry(), anEntry);
514 aDescr += (anEntry+" = IBasicOperations.MakePlanePntVec(");
515 TDF_Tool::Entry(thePnt->GetEntry(), anEntry);
516 aDescr += (anEntry+", ");
517 TDF_Tool::Entry(theVec->GetEntry(), anEntry);
518 aDescr += (anEntry+", ");
519 aDescr += TCollection_AsciiString(theSize) + ")";
521 aFunction->SetDescription(aDescr);
527 //=============================================================================
531 //=============================================================================
532 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneFace
533 (Handle(GEOM_Object) theFace, double theSize)
537 if (theFace.IsNull()) return NULL;
539 //Add a new Plane object
540 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
542 //Add a new Plane function
543 Handle(GEOM_Function) aFunction =
544 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_FACE);
546 //Check if the function is set correctly
547 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
549 GEOMImpl_IPlane aPI (aFunction);
551 Handle(GEOM_Function) aRef = theFace->GetLastFunction();
552 if (aRef.IsNull()) return NULL;
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.MakePlaneFace(");
574 TDF_Tool::Entry(theFace->GetEntry(), anEntry);
575 aDescr += (anEntry+", ");
576 aDescr += TCollection_AsciiString(theSize) + ")";
578 aFunction->SetDescription(aDescr);
585 //=============================================================================
589 //=============================================================================
590 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarker
591 (double theOX, double theOY, double theOZ,
592 double theXDX, double theXDY, double theXDZ,
593 double theYDX, double theYDY, double theYDZ)
597 //Add a new Marker object
598 Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GetDocID(), GEOM_MARKER);
600 //Add a new Marker function
601 Handle(GEOM_Function) aFunction =
602 aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_CS);
603 if (aFunction.IsNull()) return NULL;
605 //Check if the function is set correctly
606 if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
608 GEOMImpl_IMarker aPI(aFunction);
610 aPI.SetOrigin(theOX, theOY, theOZ);
611 aPI.SetXDir(theXDX, theXDY, theXDZ);
612 aPI.SetYDir(theYDX, theYDY, theYDZ);
614 //Compute the marker value
616 if (!GetSolver()->ComputeFunction(aFunction)) {
617 SetErrorCode("Marker driver failed");
621 catch (Standard_Failure) {
622 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
623 SetErrorCode(aFail->GetMessageString());
627 //Make a Python command
628 TCollection_AsciiString anEntry, aDescr;
629 TDF_Tool::Entry(aMarker->GetEntry(), anEntry);
630 aDescr += anEntry + " = IBasicOperations.MakeMarker(";
631 aDescr += TCollection_AsciiString(theOX) + ", ";
632 aDescr += TCollection_AsciiString(theOY) + ", ";
633 aDescr += TCollection_AsciiString(theOZ) + ", ";
634 aDescr += TCollection_AsciiString(theXDX) + ", ";
635 aDescr += TCollection_AsciiString(theXDY) + ", ";
636 aDescr += TCollection_AsciiString(theXDZ) + ", ";
637 aDescr += TCollection_AsciiString(theYDX) + ", ";
638 aDescr += TCollection_AsciiString(theYDY) + ", ";
639 aDescr += TCollection_AsciiString(theYDZ) + ")";
641 aFunction->SetDescription(aDescr);