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_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 << ")";
224 //=============================================================================
228 //=============================================================================
229 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeTangentOnCurve
230 (const Handle(GEOM_Object)& theCurve, double theParameter)
234 if (theCurve.IsNull()) return NULL;
236 //Add a new Vector object
237 Handle(GEOM_Object) aVec = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
239 //Add a new Point function for creation a point relativley another point
240 Handle(GEOM_Function) aFunction = aVec->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TANGENT_CURVE_PAR);
242 //Check if the function is set correctly
243 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
245 GEOMImpl_IVector aVI (aFunction);
247 Handle(GEOM_Function) aRefFunction = theCurve->GetLastFunction();
248 if (aRefFunction.IsNull()) return NULL;
250 aVI.SetCurve(aRefFunction);
251 aVI.SetParameter(theParameter);
253 //Compute the vector value
255 if (!GetSolver()->ComputeFunction(aFunction)) {
256 SetErrorCode("Vector driver failed");
260 catch (Standard_Failure) {
261 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
262 SetErrorCode(aFail->GetMessageString());
266 //Make a Python command
267 GEOM::TPythonDump(aFunction) << aVec << " = geompy.MakeTangentOnCurve("
268 << theCurve << ", " << theParameter << ")";
274 //=============================================================================
278 //=============================================================================
279 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorDXDYDZ
280 (double theDX, double theDY, double theDZ)
284 //Add a new Vector object
285 Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
287 //Add a new Vector function with DXDYDZ parameters
288 Handle(GEOM_Function) aFunction =
289 aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_DX_DY_DZ);
290 if (aFunction.IsNull()) return NULL;
292 //Check if the function is set correctly
293 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
295 GEOMImpl_IVector aPI (aFunction);
301 //Compute the Vector value
303 if (!GetSolver()->ComputeFunction(aFunction)) {
304 SetErrorCode("Vector driver failed");
308 catch (Standard_Failure) {
309 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
310 SetErrorCode(aFail->GetMessageString());
314 //Make a Python command
315 GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVectorDXDYDZ("
316 << theDX << ", " << theDY << ", " << theDZ << ")";
322 //=============================================================================
326 //=============================================================================
327 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeVectorTwoPnt
328 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
332 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
334 //Add a new Vector object
335 Handle(GEOM_Object) aVector = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
337 //Add a new Vector function
338 Handle(GEOM_Function) aFunction =
339 aVector->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_TWO_PNT);
341 //Check if the function is set correctly
342 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
344 GEOMImpl_IVector aPI (aFunction);
346 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
347 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
348 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
350 aPI.SetPoint1(aRef1);
351 aPI.SetPoint2(aRef2);
353 //Compute the Vector value
355 if (!GetSolver()->ComputeFunction(aFunction)) {
356 SetErrorCode("Vector driver failed");
360 catch (Standard_Failure) {
361 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
362 SetErrorCode(aFail->GetMessageString());
366 //Make a Python command
367 GEOM::TPythonDump(aFunction) << aVector << " = geompy.MakeVector("
368 << thePnt1 << ", " << thePnt2 << ")";
375 //=============================================================================
379 //=============================================================================
380 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLine
381 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theDir)
385 if (thePnt.IsNull() || theDir.IsNull()) return NULL;
387 //Add a new Line object
388 Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
390 //Add a new Line function
391 Handle(GEOM_Function) aFunction =
392 aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_PNT_DIR);
394 //Check if the function is set correctly
395 if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
397 GEOMImpl_ILine aPI (aFunction);
399 Handle(GEOM_Function) aRef1 = thePnt->GetLastFunction();
400 Handle(GEOM_Function) aRef2 = theDir->GetLastFunction();
401 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
403 aPI.SetPoint1(aRef1);
404 aPI.SetPoint2(aRef2);
406 //Compute the Line value
408 if (!GetSolver()->ComputeFunction(aFunction)) {
409 SetErrorCode("Line driver failed");
413 catch (Standard_Failure) {
414 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
415 SetErrorCode(aFail->GetMessageString());
419 //Make a Python command
420 GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLine("
421 << thePnt << ", " << theDir << ")";
427 //=============================================================================
431 //=============================================================================
432 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeLineTwoPnt
433 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2)
437 if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
439 //Add a new Line object
440 Handle(GEOM_Object) aLine = GetEngine()->AddObject(GetDocID(), GEOM_LINE);
442 //Add a new Line function
443 Handle(GEOM_Function) aFunction =
444 aLine->AddFunction(GEOMImpl_LineDriver::GetID(), LINE_TWO_PNT);
446 //Check if the function is set correctly
447 if (aFunction->GetDriverGUID() != GEOMImpl_LineDriver::GetID()) return NULL;
449 GEOMImpl_ILine aPI (aFunction);
451 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
452 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
453 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
455 aPI.SetPoint1(aRef1);
456 aPI.SetPoint2(aRef2);
458 //Compute the Line value
460 if (!GetSolver()->ComputeFunction(aFunction)) {
461 SetErrorCode("Line driver failed");
465 catch (Standard_Failure) {
466 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
467 SetErrorCode(aFail->GetMessageString());
471 //Make a Python command
472 GEOM::TPythonDump(aFunction) << aLine << " = geompy.MakeLineTwoPnt("
473 << thePnt1 << ", " << thePnt2 << ")";
480 //=============================================================================
484 //=============================================================================
485 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneThreePnt
486 (Handle(GEOM_Object) thePnt1, Handle(GEOM_Object) thePnt2,
487 Handle(GEOM_Object) thePnt3, double theSize)
491 if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
493 //Add a new Plane object
494 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
496 //Add a new Plane function
497 Handle(GEOM_Function) aFunction =
498 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_THREE_PNT);
500 //Check if the function is set correctly
501 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
503 GEOMImpl_IPlane aPI (aFunction);
505 Handle(GEOM_Function) aRef1 = thePnt1->GetLastFunction();
506 Handle(GEOM_Function) aRef2 = thePnt2->GetLastFunction();
507 Handle(GEOM_Function) aRef3 = thePnt3->GetLastFunction();
508 if (aRef1.IsNull() || aRef2.IsNull() || aRef3.IsNull()) return NULL;
510 aPI.SetPoint1(aRef1);
511 aPI.SetPoint2(aRef2);
512 aPI.SetPoint3(aRef3);
513 aPI.SetSize(theSize);
515 //Compute the Plane value
517 if (!GetSolver()->ComputeFunction(aFunction)) {
518 SetErrorCode("Plane driver failed");
522 catch (Standard_Failure) {
523 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
524 SetErrorCode(aFail->GetMessageString());
528 //Make a Python command
529 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneThreePnt("
530 << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ", " << theSize << ")";
536 //=============================================================================
540 //=============================================================================
541 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlanePntVec
542 (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
547 if (thePnt.IsNull() || theVec.IsNull()) return NULL;
549 //Add a new Plane object
550 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
552 //Add a new Plane function
553 Handle(GEOM_Function) aFunction =
554 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_PNT_VEC);
556 //Check if the function is set correctly
557 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
559 GEOMImpl_IPlane aPI (aFunction);
561 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
562 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
563 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
565 aPI.SetPoint(aRefPnt);
566 aPI.SetVector(aRefVec);
567 aPI.SetSize(theSize);
569 //Compute the Plane value
571 if (!GetSolver()->ComputeFunction(aFunction)) {
572 SetErrorCode("Plane driver failed");
576 catch (Standard_Failure) {
577 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
578 SetErrorCode(aFail->GetMessageString());
582 //Make a Python command
583 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlane("
584 << thePnt << ", " << theVec << ", " << theSize << ")";
590 //=============================================================================
594 //=============================================================================
595 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakePlaneFace
596 (Handle(GEOM_Object) theFace, double theSize)
600 if (theFace.IsNull()) return NULL;
602 //Add a new Plane object
603 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
605 //Add a new Plane function
606 Handle(GEOM_Function) aFunction =
607 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_FACE);
609 //Check if the function is set correctly
610 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
612 GEOMImpl_IPlane aPI (aFunction);
614 Handle(GEOM_Function) aRef = theFace->GetLastFunction();
615 if (aRef.IsNull()) return NULL;
618 aPI.SetSize(theSize);
620 //Compute the Plane value
622 if (!GetSolver()->ComputeFunction(aFunction)) {
623 SetErrorCode("Plane driver failed");
627 catch (Standard_Failure) {
628 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
629 SetErrorCode(aFail->GetMessageString());
633 //Make a Python command
634 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakePlaneFace("
635 << theFace << ", " << theSize << ")";
642 //=============================================================================
646 //=============================================================================
647 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeMarker
648 (double theOX, double theOY, double theOZ,
649 double theXDX, double theXDY, double theXDZ,
650 double theYDX, double theYDY, double theYDZ)
654 //Add a new Marker object
655 Handle(GEOM_Object) aMarker = GetEngine()->AddObject(GetDocID(), GEOM_MARKER);
657 //Add a new Marker function
658 Handle(GEOM_Function) aFunction =
659 aMarker->AddFunction(GEOMImpl_MarkerDriver::GetID(), MARKER_CS);
660 if (aFunction.IsNull()) return NULL;
662 //Check if the function is set correctly
663 if (aFunction->GetDriverGUID() != GEOMImpl_MarkerDriver::GetID()) return NULL;
665 GEOMImpl_IMarker aPI(aFunction);
667 aPI.SetOrigin(theOX, theOY, theOZ);
668 aPI.SetXDir(theXDX, theXDY, theXDZ);
669 aPI.SetYDir(theYDX, theYDY, theYDZ);
671 //Compute the marker value
673 if (!GetSolver()->ComputeFunction(aFunction)) {
674 SetErrorCode("Marker driver failed");
678 catch (Standard_Failure) {
679 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
680 SetErrorCode(aFail->GetMessageString());
684 //Make a Python command
685 GEOM::TPythonDump(aFunction) << aMarker << " = geompy.MakeMarker("
686 << theOX << ", " << theOY << ", " << theOZ << ", "
687 << theXDX << ", " << theXDY << ", " << theXDZ << ", "
688 << theYDX << ", " << theYDY << ", " << theYDZ << ")";
694 //=============================================================================
696 * MakeTangentPlaneOnFace
698 //=============================================================================
700 Handle(GEOM_Object) GEOMImpl_IBasicOperations::MakeTangentPlaneOnFace(const Handle(GEOM_Object)& theFace,
707 if (theFace.IsNull()) return NULL;
709 //Add a new Plane object
710 Handle(GEOM_Object) aPlane = GetEngine()->AddObject(GetDocID(), GEOM_PLANE);
712 //Add a new Plane function
713 Handle(GEOM_Function) aFunction =
714 aPlane->AddFunction(GEOMImpl_PlaneDriver::GetID(), PLANE_TANGENT_FACE);
716 //Check if the function is set correctly
717 if (aFunction->GetDriverGUID() != GEOMImpl_PlaneDriver::GetID()) return NULL;
719 GEOMImpl_IPlane aPI (aFunction);
721 Handle(GEOM_Function) aRef = theFace->GetLastFunction();
722 if (aRef.IsNull()) return NULL;
725 aPI.SetSize(theSize);
726 aPI.SetParameterU(theParamU);
727 aPI.SetParameterV(theParamV);
729 //Compute the Plane value
731 if (!GetSolver()->ComputeFunction(aFunction)) {
732 SetErrorCode("Plane driver failed");
736 catch (Standard_Failure) {
737 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
738 SetErrorCode(aFail->GetMessageString());
742 //Make a Python command
743 GEOM::TPythonDump(aFunction) << aPlane << " = geompy.MakeTangentPlaneOnFace("
744 << theFace << ", " <<theParamU <<", "<<theParamV <<", "<< theSize << ")";