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_ILocalOperations.hxx>
24 #include <GEOM_Function.hxx>
25 #include <GEOM_PythonDump.hxx>
27 #include <GEOMImpl_Types.hxx>
29 #include <GEOMImpl_FilletDriver.hxx>
30 #include <GEOMImpl_ChamferDriver.hxx>
32 #include <GEOMImpl_IFillet.hxx>
33 #include <GEOMImpl_IChamfer.hxx>
35 #include <GEOMImpl_IArchimede.hxx>
36 #include <GEOMImpl_ArchimedeDriver.hxx>
38 #include <GEOMImpl_Gen.hxx>
39 #include <GEOMImpl_IShapesOperations.hxx>
41 #include "utilities.h"
43 #include <Utils_ExceptHandlers.hxx>
45 #include <TFunction_DriverTable.hxx>
46 #include <TFunction_Driver.hxx>
47 #include <TFunction_Logbook.hxx>
48 #include <TDF_Tool.hxx>
51 #include <TopoDS_TShape.hxx>
52 #include <TopTools_IndexedMapOfShape.hxx>
54 #include <Standard_Failure.hxx>
55 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
57 //=============================================================================
61 //=============================================================================
62 GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations (GEOM_Engine* theEngine, int theDocID)
63 : GEOM_IOperations(theEngine, theDocID)
65 MESSAGE("GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations");
68 //=============================================================================
72 //=============================================================================
73 GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations()
75 MESSAGE("GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations");
79 //=============================================================================
83 //=============================================================================
84 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletAll
85 (Handle(GEOM_Object) theShape, double theR)
89 //Add a new Fillet object
90 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
92 //Add a new Fillet function
93 Handle(GEOM_Function) aFunction =
94 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_ALL);
95 if (aFunction.IsNull()) return NULL;
97 //Check if the function is set correctly
98 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
100 GEOMImpl_IFillet aCI (aFunction);
102 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
103 if (aRefShape.IsNull()) return NULL;
105 aCI.SetShape(aRefShape);
108 //Compute the Fillet value
110 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
113 if (!GetSolver()->ComputeFunction(aFunction)) {
114 SetErrorCode("Fillet driver failed");
118 catch (Standard_Failure) {
119 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
120 SetErrorCode(aFail->GetMessageString());
124 //Make a Python command
125 GEOM::TPythonDump(aFunction) << aFillet << " = geompy.MakeFilletAll("
126 << theShape << ", " << theR << ")";
132 //=============================================================================
136 //=============================================================================
137 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
138 (Handle(GEOM_Object) theShape, double theR, list<int> theEdges)
142 //Add a new Fillet object
143 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
145 //Add a new Fillet function
146 Handle(GEOM_Function) aFunction =
147 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES);
148 if (aFunction.IsNull()) return NULL;
150 //Check if the function is set correctly
151 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
153 GEOMImpl_IFillet aCI (aFunction);
155 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
156 if (aRefShape.IsNull()) return NULL;
158 aCI.SetShape(aRefShape);
160 int aLen = theEdges.size();
164 list<int>::iterator it = theEdges.begin();
165 for (; it != theEdges.end(); it++, ind++) {
166 aCI.SetEdge(ind, (*it));
169 //Compute the Fillet value
171 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
174 if (!GetSolver()->ComputeFunction(aFunction)) {
175 SetErrorCode("Fillet driver failed");
179 catch (Standard_Failure) {
180 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
181 SetErrorCode(aFail->GetMessageString());
185 //Make a Python command
186 GEOM::TPythonDump pd (aFunction);
187 pd << aFillet << " = geompy.MakeFillet(" << theShape
188 << ", " << theR << ", geompy.ShapeType[\"EDGE\"], [";
190 it = theEdges.begin();
192 while (it != theEdges.end()) {
193 pd << ", " << (*it++);
201 //=============================================================================
205 //=============================================================================
206 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFaces
207 (Handle(GEOM_Object) theShape, double theR, list<int> theFaces)
211 //Add a new Fillet object
212 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
214 //Add a new Fillet function
215 Handle(GEOM_Function) aFunction =
216 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES);
217 if (aFunction.IsNull()) return NULL;
219 //Check if the function is set correctly
220 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
222 GEOMImpl_IFillet aCI (aFunction);
224 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
225 if (aRefShape.IsNull()) return NULL;
227 aCI.SetShape(aRefShape);
229 int aLen = theFaces.size();
233 list<int>::iterator it = theFaces.begin();
234 for (; it != theFaces.end(); it++, ind++) {
235 aCI.SetFace(ind, (*it));
238 //Compute the Fillet value
240 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
243 if (!GetSolver()->ComputeFunction(aFunction)) {
244 SetErrorCode("Fillet driver failed");
248 catch (Standard_Failure) {
249 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
250 SetErrorCode(aFail->GetMessageString());
254 //Make a Python command
255 GEOM::TPythonDump pd (aFunction);
256 pd << aFillet << " = geompy.MakeFillet(" << theShape
257 << ", " << theR << ", geompy.ShapeType[\"FACE\"], [";
259 it = theFaces.begin();
261 while (it != theFaces.end()) {
262 pd << ", " << (*it++);
270 //=============================================================================
274 //=============================================================================
275 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, double theD)
279 //Add a new Chamfer object
280 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
282 //Add a new Chamfer function
283 Handle(GEOM_Function) aFunction =
284 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
285 if (aFunction.IsNull()) return NULL;
287 //Check if the function is set correctly
288 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
290 GEOMImpl_IChamfer aCI (aFunction);
292 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
293 if (aRefShape.IsNull()) return NULL;
295 aCI.SetShape(aRefShape);
298 //Compute the Chamfer value
300 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
303 if (!GetSolver()->ComputeFunction(aFunction)) {
304 SetErrorCode("Chamfer 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) << aChamfer << " = geompy.MakeChamferAll("
316 << theShape << ", " << theD << ")";
322 //=============================================================================
326 //=============================================================================
327 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
328 (Handle(GEOM_Object) theShape, double theD1, double theD2,
329 int theFace1, int theFace2)
333 //Add a new Chamfer object
334 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
336 //Add a new Chamfer function
337 Handle(GEOM_Function) aFunction =
338 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
339 if (aFunction.IsNull()) return NULL;
341 //Check if the function is set correctly
342 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
344 GEOMImpl_IChamfer aCI (aFunction);
346 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
347 if (aRefShape.IsNull()) return NULL;
349 aCI.SetShape(aRefShape);
352 aCI.SetFace1(theFace1);
353 aCI.SetFace2(theFace2);
355 //Compute the Chamfer value
357 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
360 if (!GetSolver()->ComputeFunction(aFunction)) {
361 SetErrorCode("Chamfer driver failed");
365 catch (Standard_Failure) {
366 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
367 SetErrorCode(aFail->GetMessageString());
371 //Make a Python command
372 GEOM::TPythonDump(aFunction) << aChamfer
373 << " = geompy.MakeChamferEdge(" << theShape << ", " << theD1
374 << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
380 //=============================================================================
384 //=============================================================================
385 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
386 (Handle(GEOM_Object) theShape, double theD1, double theD2,
391 //Add a new Chamfer object
392 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
394 //Add a new Chamfer function
395 Handle(GEOM_Function) aFunction =
396 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
397 if (aFunction.IsNull()) return NULL;
399 //Check if the function is set correctly
400 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
402 GEOMImpl_IChamfer aCI (aFunction);
404 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
405 if (aRefShape.IsNull()) return NULL;
407 aCI.SetShape(aRefShape);
410 int aLen = theFaces.size();
414 list<int>::iterator it = theFaces.begin();
415 for (; it != theFaces.end(); it++, ind++) {
416 aCI.SetFace(ind, (*it));
419 //Compute the Chamfer value
421 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
424 if (!GetSolver()->ComputeFunction(aFunction)) {
425 SetErrorCode("Chamfer driver failed");
429 catch (Standard_Failure) {
430 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
431 SetErrorCode(aFail->GetMessageString());
435 //Make a Python command
436 GEOM::TPythonDump pd (aFunction);
437 pd << aChamfer << " = geompy.MakeChamferFaces(" << theShape
438 << ", " << theD1 << ", " << theD2 << ", [";
440 it = theFaces.begin();
442 while (it != theFaces.end()) {
443 pd << ", " << (*it++);
451 //=============================================================================
455 //=============================================================================
456 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
458 double theWaterDensity,
459 double theMeshingDeflection)
463 //Add a new Archimede object
464 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_ARCHIMEDE);
466 //Add a new Archimede function
467 Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
468 if (aFunction.IsNull()) return NULL;
470 //Check if the function is set correctly
471 if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
473 GEOMImpl_IArchimede aAI (aFunction);
475 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
476 if (aRefShape.IsNull()) return NULL;
478 aAI.SetBasicShape(aRefShape);
479 aAI.SetWeight(theWeight);
480 aAI.SetDensity(theWaterDensity);
481 aAI.SetDeflection(theMeshingDeflection);
483 //Compute the Archimede value
485 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
488 if (!GetSolver()->ComputeFunction(aFunction)) {
489 SetErrorCode("Archimede driver failed");
493 catch (Standard_Failure) {
494 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
495 SetErrorCode(aFail->GetMessageString());
499 //Make a Python command
500 GEOM::TPythonDump(aFunction) << aChamfer
501 << " = geompy.Archimede(" << theShape << ", " << theWeight << ", "
502 << theWaterDensity << ", " << theMeshingDeflection << ")";
508 //=============================================================================
512 //=============================================================================
513 bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
514 TopoDS_Shape& theSubShape)
516 if (theShape.IsNull() || theIndex < 1)
519 TopTools_IndexedMapOfShape anIndices;
520 TopExp::MapShapes(theShape, anIndices);
521 if (theIndex > anIndices.Extent()) return false;
522 theSubShape = anIndices.FindKey(theIndex);
527 //=============================================================================
531 //=============================================================================
532 Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
533 Handle(GEOM_Object) theSubShape)
537 Standard_Integer anInd = -1;
538 GEOM_Engine* anEngine = GetEngine();
539 //GEOMImpl_Gen* aGen = dynamic_cast<GEOMImpl_Gen*>(anEngine);
540 GEOMImpl_Gen* aGen = (GEOMImpl_Gen*)anEngine;
543 GEOMImpl_IShapesOperations* anIShapesOperations =
544 aGen->GetIShapesOperations(GetDocID());
545 anInd = anIShapesOperations->GetSubShapeIndex(theShape, theSubShape);
546 SetErrorCode(anIShapesOperations->GetErrorCode());