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_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
56 //=============================================================================
60 //=============================================================================
61 GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations (GEOM_Engine* theEngine, int theDocID)
62 : GEOM_IOperations(theEngine, theDocID)
64 MESSAGE("GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations");
67 //=============================================================================
71 //=============================================================================
72 GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations()
74 MESSAGE("GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations");
78 //=============================================================================
82 //=============================================================================
83 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletAll
84 (Handle(GEOM_Object) theShape, double theR)
88 //Add a new Fillet object
89 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
91 //Add a new Fillet function
92 Handle(GEOM_Function) aFunction =
93 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_ALL);
94 if (aFunction.IsNull()) return NULL;
96 //Check if the function is set correctly
97 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
99 GEOMImpl_IFillet aCI (aFunction);
101 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
102 if (aRefShape.IsNull()) return NULL;
104 aCI.SetShape(aRefShape);
107 //Compute the Fillet value
109 if (!GetSolver()->ComputeFunction(aFunction)) {
110 SetErrorCode("Fillet driver failed");
114 catch (Standard_Failure) {
115 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
116 SetErrorCode(aFail->GetMessageString());
120 //Make a Python command
121 GEOM::TPythonDump(aFunction) << aFillet << " = geompy.MakeFilletAll("
122 << theShape << ", " << theR << ")";
128 //=============================================================================
132 //=============================================================================
133 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
134 (Handle(GEOM_Object) theShape, double theR, list<int> theEdges)
138 //Add a new Fillet object
139 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
141 //Add a new Fillet function
142 Handle(GEOM_Function) aFunction =
143 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES);
144 if (aFunction.IsNull()) return NULL;
146 //Check if the function is set correctly
147 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
149 GEOMImpl_IFillet aCI (aFunction);
151 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
152 if (aRefShape.IsNull()) return NULL;
154 aCI.SetShape(aRefShape);
156 int aLen = theEdges.size();
160 list<int>::iterator it = theEdges.begin();
161 for (; it != theEdges.end(); it++, ind++) {
162 aCI.SetEdge(ind, (*it));
165 //Compute the Fillet value
167 if (!GetSolver()->ComputeFunction(aFunction)) {
168 SetErrorCode("Fillet driver failed");
172 catch (Standard_Failure) {
173 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
174 SetErrorCode(aFail->GetMessageString());
178 //Make a Python command
179 GEOM::TPythonDump pd (aFunction);
180 pd << aFillet << " = geompy.MakeFillet(" << theShape
181 << ", " << theR << ", geompy.ShapeType[\"EDGE\"], [";
183 it = theEdges.begin();
185 while (it != theEdges.end()) {
186 pd << ", " << (*it++);
194 //=============================================================================
198 //=============================================================================
199 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFaces
200 (Handle(GEOM_Object) theShape, double theR, list<int> theFaces)
204 //Add a new Fillet object
205 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
207 //Add a new Fillet function
208 Handle(GEOM_Function) aFunction =
209 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES);
210 if (aFunction.IsNull()) return NULL;
212 //Check if the function is set correctly
213 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
215 GEOMImpl_IFillet aCI (aFunction);
217 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
218 if (aRefShape.IsNull()) return NULL;
220 aCI.SetShape(aRefShape);
222 int aLen = theFaces.size();
226 list<int>::iterator it = theFaces.begin();
227 for (; it != theFaces.end(); it++, ind++) {
228 aCI.SetFace(ind, (*it));
231 //Compute the Fillet value
233 if (!GetSolver()->ComputeFunction(aFunction)) {
234 SetErrorCode("Fillet driver failed");
238 catch (Standard_Failure) {
239 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
240 SetErrorCode(aFail->GetMessageString());
244 //Make a Python command
245 GEOM::TPythonDump pd (aFunction);
246 pd << aFillet << " = geompy.MakeFillet(" << theShape
247 << ", " << theR << ", geompy.ShapeType[\"FACE\"], [";
249 it = theFaces.begin();
251 while (it != theFaces.end()) {
252 pd << ", " << (*it++);
260 //=============================================================================
264 //=============================================================================
265 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, double theD)
269 //Add a new Chamfer object
270 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
272 //Add a new Chamfer function
273 Handle(GEOM_Function) aFunction =
274 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
275 if (aFunction.IsNull()) return NULL;
277 //Check if the function is set correctly
278 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
280 GEOMImpl_IChamfer aCI (aFunction);
282 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
283 if (aRefShape.IsNull()) return NULL;
285 aCI.SetShape(aRefShape);
288 //Compute the Chamfer value
290 if (!GetSolver()->ComputeFunction(aFunction)) {
291 SetErrorCode("Chamfer driver failed");
295 catch (Standard_Failure) {
296 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
297 SetErrorCode(aFail->GetMessageString());
301 //Make a Python command
302 GEOM::TPythonDump(aFunction) << aChamfer << " = geompy.MakeChamferAll("
303 << theShape << ", " << theD << ")";
309 //=============================================================================
313 //=============================================================================
314 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
315 (Handle(GEOM_Object) theShape, double theD1, double theD2,
316 int theFace1, int theFace2)
320 //Add a new Chamfer object
321 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
323 //Add a new Chamfer function
324 Handle(GEOM_Function) aFunction =
325 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
326 if (aFunction.IsNull()) return NULL;
328 //Check if the function is set correctly
329 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
331 GEOMImpl_IChamfer aCI (aFunction);
333 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
334 if (aRefShape.IsNull()) return NULL;
336 aCI.SetShape(aRefShape);
339 aCI.SetFace1(theFace1);
340 aCI.SetFace2(theFace2);
342 //Compute the Chamfer value
344 if (!GetSolver()->ComputeFunction(aFunction)) {
345 SetErrorCode("Chamfer driver failed");
349 catch (Standard_Failure) {
350 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
351 SetErrorCode(aFail->GetMessageString());
355 //Make a Python command
356 GEOM::TPythonDump(aFunction) << aChamfer
357 << " = geompy.MakeChamferEdge(" << theShape << ", " << theD1
358 << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
364 //=============================================================================
368 //=============================================================================
369 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
370 (Handle(GEOM_Object) theShape, double theD1, double theD2,
375 //Add a new Chamfer object
376 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
378 //Add a new Chamfer function
379 Handle(GEOM_Function) aFunction =
380 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
381 if (aFunction.IsNull()) return NULL;
383 //Check if the function is set correctly
384 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
386 GEOMImpl_IChamfer aCI (aFunction);
388 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
389 if (aRefShape.IsNull()) return NULL;
391 aCI.SetShape(aRefShape);
394 int aLen = theFaces.size();
398 list<int>::iterator it = theFaces.begin();
399 for (; it != theFaces.end(); it++, ind++) {
400 aCI.SetFace(ind, (*it));
403 //Compute the Chamfer value
405 if (!GetSolver()->ComputeFunction(aFunction)) {
406 SetErrorCode("Chamfer driver failed");
410 catch (Standard_Failure) {
411 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
412 SetErrorCode(aFail->GetMessageString());
416 //Make a Python command
417 GEOM::TPythonDump pd (aFunction);
418 pd << aChamfer << " = geompy.MakeChamferFaces(" << theShape
419 << ", " << theD1 << ", " << theD2 << ", [";
421 it = theFaces.begin();
423 while (it != theFaces.end()) {
424 pd << ", " << (*it++);
432 //=============================================================================
436 //=============================================================================
437 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
439 double theWaterDensity,
440 double theMeshingDeflection)
444 //Add a new Archimede object
445 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_ARCHIMEDE);
447 //Add a new Archimede function
448 Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
449 if (aFunction.IsNull()) return NULL;
451 //Check if the function is set correctly
452 if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
454 GEOMImpl_IArchimede aAI (aFunction);
456 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
457 if (aRefShape.IsNull()) return NULL;
459 aAI.SetBasicShape(aRefShape);
460 aAI.SetWeight(theWeight);
461 aAI.SetDensity(theWaterDensity);
462 aAI.SetDeflection(theMeshingDeflection);
464 //Compute the Archimede value
466 if (!GetSolver()->ComputeFunction(aFunction)) {
467 SetErrorCode("Archimede driver failed");
471 catch (Standard_Failure) {
472 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
473 SetErrorCode(aFail->GetMessageString());
477 //Make a Python command
478 GEOM::TPythonDump(aFunction) << aChamfer
479 << " = geompy.Archimede(" << theShape << ", " << theWeight << ", "
480 << theWaterDensity << ", " << theMeshingDeflection << ")";
486 //=============================================================================
490 //=============================================================================
491 bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
492 TopoDS_Shape& theSubShape)
494 if (theShape.IsNull() || theIndex < 1)
497 TopTools_IndexedMapOfShape anIndices;
498 TopExp::MapShapes(theShape, anIndices);
499 if (theIndex > anIndices.Extent()) return false;
500 theSubShape = anIndices.FindKey(theIndex);
505 //=============================================================================
509 //=============================================================================
510 Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
511 Handle(GEOM_Object) theSubShape)
515 Standard_Integer anInd = -1;
516 GEOM_Engine* anEngine = GetEngine();
517 //GEOMImpl_Gen* aGen = dynamic_cast<GEOMImpl_Gen*>(anEngine);
518 GEOMImpl_Gen* aGen = (GEOMImpl_Gen*)anEngine;
521 GEOMImpl_IShapesOperations* anIShapesOperations =
522 aGen->GetIShapesOperations(GetDocID());
523 anInd = anIShapesOperations->GetSubShapeIndex(theShape, theSubShape);
524 SetErrorCode(anIShapesOperations->GetErrorCode());