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/
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_IBasicOperations.hxx>
24 #include "utilities.h"
26 #include <Utils_ExceptHandlers.hxx>
28 #include <TFunction_DriverTable.hxx>
29 #include <TFunction_Driver.hxx>
30 #include <TFunction_Logbook.hxx>
31 #include <TDF_Tool.hxx>
33 #include <GEOM_Function.hxx>
34 #include <GEOM_PythonDump.hxx>
36 #include <GEOMImpl_PointDriver.hxx>
37 #include <GEOMImpl_VectorDriver.hxx>
38 #include <GEOMImpl_LineDriver.hxx>
39 #include <GEOMImpl_PlaneDriver.hxx>
40 #include <GEOMImpl_MarkerDriver.hxx>
42 #include <GEOMImpl_IPoint.hxx>
43 #include <GEOMImpl_IVector.hxx>
44 #include <GEOMImpl_ILine.hxx>
45 #include <GEOMImpl_IPlane.hxx>
46 #include <GEOMImpl_IMarker.hxx>
48 #include <GEOMImpl_Types.hxx>
50 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
52 //=============================================================================
56 //=============================================================================
57 GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations(GEOM_Engine* theEngine, int theDocID)
58 : GEOM_IOperations(theEngine, theDocID)
60 MESSAGE("GEOMImpl_IBasicOperations::GEOMImpl_IBasicOperations");
63 //=============================================================================
67 //=============================================================================
68 GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations()
70 MESSAGE("GEOMImpl_IBasicOperations::~GEOMImpl_IBasicOperations");
74 //=============================================================================
78 //=============================================================================
79 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointXYZ
80 (double theX, double theY, double theZ)
84 //Add a new Point object
85 Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
87 //Add a new Point function with XYZ parameters
88 Handle(GEOM_Function) aFunction =
89 aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ);
90 if (aFunction.IsNull()) return NULL;
92 //Check if the function is set correctly
93 if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
95 GEOMImpl_IPoint aPI(aFunction);
101 //Compute the point value
103 if (!GetSolver()->ComputeFunction(aFunction)) {
104 SetErrorCode("Point driver failed");
108 catch (Standard_Failure) {
109 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
110 SetErrorCode(aFail->GetMessageString());
114 //Make a Python command
115 GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertex("
116 << theX << ", " << theY << ", " << theZ << ")";
122 //=============================================================================
124 * MakePointWithReference
126 //=============================================================================
127 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointWithReference
128 (Handle(GEOM_Object) theReference, double theX, double theY, double theZ)
132 if (theReference.IsNull()) return NULL;
134 //Add a new Point object
135 Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
137 //Add a new Point function for creation a point relativley another point
138 Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_XYZ_REF);
140 //Check if the function is set correctly
141 if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
143 GEOMImpl_IPoint aPI(aFunction);
145 Handle(GEOM_Function) aRefFunction = theReference->GetLastFunction();
146 if (aRefFunction.IsNull()) return NULL;
148 aPI.SetRef(aRefFunction);
153 //Compute the point value
155 if (!GetSolver()->ComputeFunction(aFunction)) {
156 SetErrorCode("Point driver failed");
160 catch (Standard_Failure) {
161 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
162 SetErrorCode(aFail->GetMessageString());
166 //Make a Python command
167 GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexWithRef("
168 << theReference << ", " << theX << ", " << theY << ", " << theZ << ")";
174 //=============================================================================
178 //=============================================================================
179 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePointOnCurve
180 (Handle(GEOM_Object) theCurve, double theParameter)
184 if (theCurve.IsNull()) return NULL;
186 //Add a new Point object
187 Handle(GEOM_Object) aPoint = GetEngine()->AddObject(GetDocID(), GEOM_POINT);
189 //Add a new Point function for creation a point relativley another point
190 Handle(GEOM_Function) aFunction = aPoint->AddFunction(GEOMImpl_PointDriver::GetID(), POINT_CURVE_PAR);
192 //Check if the function is set correctly
193 if (aFunction->GetDriverGUID() != GEOMImpl_PointDriver::GetID()) return NULL;
195 GEOMImpl_IPoint aPI (aFunction);
197 Handle(GEOM_Function) aRefFunction = theCurve->GetLastFunction();
198 if (aRefFunction.IsNull()) return NULL;
200 aPI.SetCurve(aRefFunction);
201 aPI.SetParameter(theParameter);
203 //Compute the point value
205 if (!GetSolver()->ComputeFunction(aFunction)) {
206 SetErrorCode("Point driver failed");
210 catch (Standard_Failure) {
211 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
212 SetErrorCode(aFail->GetMessageString());
216 //Make a Python command
217 GEOM::TPythonDump(aFunction) << aPoint << " = geompy.MakeVertexOnCurve("
218 << theCurve << ", " << theParameter << ")";
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 GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVectorDXDYDZ("
267 << theDX << ", " << theDY << ", " << theDZ << ")";
273 //=============================================================================
277 //=============================================================================
278 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorTwoPnt
279 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
283 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
285 //Add a new Vector object
286 Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
288 //Add a new Vector function
289 Handle(GEOM_Function) aFunction =
290 aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
292 //Check if the function is set correctly
293 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
295 GEOMImpl_IVector aPI (aFunction);
297 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
298 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
299 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
301 aPI.SetPoint1(aRef1);
302 aPI.SetPoint2(aRef2);
304 //Compute the Vector value
306 if (!GetSolver()->ComputeFunction(aFunction)) {
307 SetErrorCode("Vector driver failed");
311 catch (Standard_Failure) {
312 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
313 SetErrorCode(aFail->GetMessageString());
317 //Make a Python command
318 GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVector("
319 << thePnt1 << ", " << thePnt2 << ")";
326 //=============================================================================
330 //=============================================================================
331 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLine
332 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theDir)
336 if (thePnt.IsNull() || theDir.IsNull()) return NULL;
338 //Add a new Line object
339 Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
341 //Add a new Line function
342 Handle(GEOM_Function) aFunction =
343 aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_PNT_DIR);
345 //Check if the function is set correctly
346 if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
348 GEOMImpl_ILine aPI (aFunction);
350 Handle(GEOM_Function) aRef1 = thePnt->GetLastFunction();
351 Handle(GEOM_Function) aRef2 = theDir->GetLastFunction();
352 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
354 aPI.SetPoint1(aRef1);
355 aPI.SetPoint2(aRef2);
357 //Compute the Line value
359 if (!GetSolver()->ComputeFunction(aFunction)) {
360 SetErrorCode("Line driver failed");
364 catch (Standard_Failure) {
365 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
366 SetErrorCode(aFail->GetMessageString());
370 //Make a Python command
371 GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLine("
372 << thePnt << ", " << theDir << ")";
378 //=============================================================================
382 //=============================================================================
383 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoPnt
384 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
388 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
390 //Add a new Line object
391 Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
393 //Add a new Line function
394 Handle(GEOM_Function) aFunction =
395 aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_PNT);
397 //Check if the function is set correctly
398 if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
400 GEOMImpl_ILine aPI (aFunction);
402 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
403 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
404 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
406 aPI.SetPoint1(aRef1);
407 aPI.SetPoint2(aRef2);
409 //Compute the Line value
411 if (!GetSolver()->ComputeFunction(aFunction)) {
412 SetErrorCode("Line driver failed");
416 catch (Standard_Failure) {
417 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
418 SetErrorCode(aFail->GetMessageString());
422 //Make a Python command
423 GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoPnt("
424 << thePnt1 << ", " << thePnt2 << ")";
431 //=============================================================================
435 //=============================================================================
436 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneThreePnt
437 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2,
438 Handle(GEOM_Object) thePnt3, double theSize)
442 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
444 //Add a new Plane object
445 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
447 //Add a new Plane function
448 Handle(GEOM_Function) aFunction =
449 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_THREE_PNT);
451 //Check if the function is set correctly
452 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
454 GEOMImpl_IPlane aPI (aFunction);
456 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
457 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
458 Handle(GEOM_Function) aRef3 = thePnt3->GetLastFunction();
459 if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull()) return NULL;
461 aPI.SetPoint1(aRef1);
462 aPI.SetPoint2(aRef2);
463 aPI.SetPoint3(aRef3);
464 aPI.SetSize(theSize);
466 //Compute the Plane value
468 if (!GetSolver()->ComputeFunction(aFunction)) {
469 SetErrorCode("Plane driver failed");
473 catch (Standard_Failure) {
474 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
475 SetErrorCode(aFail->GetMessageString());
479 //Make a Python command
480 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneThreePnt("
481 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ", " << theSize << ")";
487 //=============================================================================
491 //=============================================================================
492 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlanePntVec
493 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
498 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
500 //Add a new Plane object
501 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
503 //Add a new Plane function
504 Handle(GEOM_Function) aFunction =
505 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_PNT_VEC);
507 //Check if the function is set correctly
508 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
510 GEOMImpl_IPlane aPI (aFunction);
512 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
513 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
514 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
516 aPI.SetPoint(aRefPnt);
517 aPI.SetVector(aRefVec);
518 aPI.SetSize(theSize);
520 //Compute the Plane value
522 if (!GetSolver()->ComputeFunction(aFunction)) {
523 SetErrorCode("Plane driver failed");
527 catch (Standard_Failure) {
528 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
529 SetErrorCode(aFail->GetMessageString());
533 //Make a Python command
534 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlane("
535 << thePnt << ", " << theVec << ", " << theSize << ")";
541 //=============================================================================
545 //=============================================================================
546 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneFace
547 (Handle(GEOM_Object) theFace, double theSize)
551 if (theFace.IsNull()) return NULL;
553 //Add a new Plane object
554 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
556 //Add a new Plane function
557 Handle(GEOM_Function) aFunction =
558 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_FACE);
560 //Check if the function is set correctly
561 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
563 GEOMImpl_IPlane aPI (aFunction);
565 Handle(GEOM_Function) aRef = theFace->GetLastFunction();
566 if (aRef.IsNull()) return NULL;
569 aPI.SetSize(theSize);
571 //Compute the Plane value
573 if (!GetSolver()->ComputeFunction(aFunction)) {
574 SetErrorCode("Plane driver failed");
578 catch (Standard_Failure) {
579 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
580 SetErrorCode(aFail->GetMessageString());
584 //Make a Python command
585 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneFace("
586 << theFace << ", " << theSize << ")";
593 //=============================================================================
597 //=============================================================================
598 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarker
599 (double theOX, double theOY, double theOZ,
600 double theXDX, double theXDY, double theXDZ,
601 double theYDX, double theYDY, double theYDZ)
605 //Add a new Marker object
606 Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GetDocID(), GEOM_MARKER);
608 //Add a new Marker function
609 Handle(GEOM_Function) aFunction =
610 aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_CS);
611 if (aFunction.IsNull()) return NULL;
613 //Check if the function is set correctly
614 if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
616 GEOMImpl_IMarker aPI(aFunction);
618 aPI.SetOrigin(theOX, theOY, theOZ);
619 aPI.SetXDir(theXDX, theXDY, theXDZ);
620 aPI.SetYDir(theYDX, theYDY, theYDZ);
622 //Compute the marker value
624 if (!GetSolver()->ComputeFunction(aFunction)) {
625 SetErrorCode("Marker driver failed");
629 catch (Standard_Failure) {
630 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
631 SetErrorCode(aFail->GetMessageString());
635 //Make a Python command
636 GEOM::TPythonDump(aFunction) << aMarker << " = geompy.MakeMarker("
637 << theOX << ", " << theOY << ", " << theOZ << ", "
638 << theXDX << ", " << theXDY << ", " << theXDZ << ", "
639 << theYDX << ", " << theYDY << ", " << theYDZ << ")";