Salome HOME
SketchShapePlugin package is removed as not used.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_CompositeBoolean.cpp
index 02e977af90e13c09822ae5d6ebbec6910c44fe6d..b47952c5dbbc97c950b8c92bc3d073e7e7038287 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_MakeShapeList.h>
+#include <GeomAlgoAPI_MakeSweep.h>
 #include <GeomAlgoAPI_PaveFiller.h>
 #include <GeomAlgoAPI_Prism.h>
 #include <GeomAlgoAPI_Revolution.h>
@@ -142,7 +143,7 @@ void FeaturesPlugin_CompositeBoolean::execute()
 
   // Pass shells/faces to solids creation function.
   ListOfShape aTools;
-  std::list<std::shared_ptr<GeomAPI_Interface>> aSolidsAlgos;
+  ListOfMakeShape aSolidsAlgos;
   makeSolids(aShells, aTools, aSolidsAlgos);
   if(aTools.empty()) {
     return;
@@ -202,7 +203,7 @@ void FeaturesPlugin_CompositeBoolean::execute()
         if(GeomAlgoAPI_ShapeTools::volume(aBoolAlgo.shape()) > 1.e-7) {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
           loadNamingDS(aResultBody, aShells, aSolidsAlgos, anObject, aTools, aBoolAlgo.shape(),
-                       *aBoolAlgo.makeShape(), *aBoolAlgo.mapOfShapes());
+                       aBoolAlgo, *aBoolAlgo.mapOfSubShapes().get());
           setResult(aResultBody, aResultIndex);
           aResultIndex++;
         }
@@ -229,35 +230,35 @@ void FeaturesPlugin_CompositeBoolean::execute()
           }
         }
 
-        GeomAlgoAPI_Boolean aBoolAlgo(aUsedInOperationSolids, aTools, myBooleanOperationType);
+        std::shared_ptr<GeomAlgoAPI_Boolean> aBoolAlgo(new GeomAlgoAPI_Boolean(aUsedInOperationSolids, aTools, myBooleanOperationType));
 
         // Checking that the algorithm worked properly.
-        if(!aBoolAlgo.isDone() || aBoolAlgo.shape()->isNull() || !aBoolAlgo.isValid()) {
+        if(!aBoolAlgo->isDone() || aBoolAlgo->shape()->isNull() || !aBoolAlgo->isValid()) {
           setError("Boolean algorithm failed");
           return;
         }
 
         GeomAlgoAPI_MakeShapeList aMakeShapeList;
-        aMakeShapeList.appendAlgo(aBoolAlgo.makeShape());
+        aMakeShapeList.appendAlgo(aBoolAlgo);
         GeomAPI_DataMapOfShapeShape aMapOfShapes;
-        aMapOfShapes.merge(aBoolAlgo.mapOfShapes());
+        aMapOfShapes.merge(aBoolAlgo->mapOfSubShapes());
 
         // Add result to not used solids from compsolid.
         ListOfShape aShapesToAdd = aNotUsedSolids;
-        aShapesToAdd.push_back(aBoolAlgo.shape());
-        GeomAlgoAPI_PaveFiller aFillerAlgo(aShapesToAdd, true);
-        if(!aFillerAlgo.isDone()) {
+        aShapesToAdd.push_back(aBoolAlgo->shape());
+        std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(new GeomAlgoAPI_PaveFiller(aShapesToAdd, true));
+        if(!aFillerAlgo->isDone()) {
           std::string aFeatureError = "PaveFiller algorithm failed";
           setError(aFeatureError);
           return;
         }
 
-        aMakeShapeList.appendAlgo(aFillerAlgo.makeShape());
-        aMapOfShapes.merge(aFillerAlgo.mapOfShapes());
+        aMakeShapeList.appendAlgo(aFillerAlgo);
+        aMapOfShapes.merge(aFillerAlgo->mapOfSubShapes());
 
-        if(GeomAlgoAPI_ShapeTools::volume(aFillerAlgo.shape()) > 1.e-7) {
+        if(GeomAlgoAPI_ShapeTools::volume(aFillerAlgo->shape()) > 1.e-7) {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-          loadNamingDS(aResultBody, aShells, aSolidsAlgos, aCompSolid, aTools, aFillerAlgo.shape(), aMakeShapeList, aMapOfShapes);
+          loadNamingDS(aResultBody, aShells, aSolidsAlgos, aCompSolid, aTools, aFillerAlgo->shape(), aMakeShapeList, aMapOfShapes);
           setResult(aResultBody, aResultIndex);
           aResultIndex++;
         }
@@ -304,12 +305,12 @@ void FeaturesPlugin_CompositeBoolean::execute()
         for(ListOfShape::iterator anIt = anOriginalSolids.begin(); anIt != anOriginalSolids.end(); anIt++) {
           ListOfShape aOneObjectList;
           aOneObjectList.push_back(*anIt);
-          GeomAlgoAPI_Boolean aCutAlgo(aOneObjectList, aNotUsedSolids, GeomAlgoAPI_Boolean::BOOL_CUT);
+          std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(new GeomAlgoAPI_Boolean(aOneObjectList, aNotUsedSolids, GeomAlgoAPI_Boolean::BOOL_CUT));
 
-          if(GeomAlgoAPI_ShapeTools::volume(aCutAlgo.shape()) > 1.e-7) {
-            aSolidsToFuse.push_back(aCutAlgo.shape());
-            aMakeShapeList.appendAlgo(aCutAlgo.makeShape());
-            aMapOfShapes.merge(aCutAlgo.mapOfShapes());
+          if(GeomAlgoAPI_ShapeTools::volume(aCutAlgo->shape()) > 1.e-7) {
+            aSolidsToFuse.push_back(aCutAlgo->shape());
+            aMakeShapeList.appendAlgo(aCutAlgo);
+            aMapOfShapes.merge(aCutAlgo->mapOfSubShapes());
           }
         }
       }
@@ -320,42 +321,42 @@ void FeaturesPlugin_CompositeBoolean::execute()
       aTools = aSolidsToFuse;
 
       // Fuse all objects and all tools.
-      GeomAlgoAPI_Boolean aFuseAlgo(anObjects, aTools, myBooleanOperationType);
+      std::shared_ptr<GeomAlgoAPI_Boolean> aFuseAlgo(new GeomAlgoAPI_Boolean(anObjects, aTools, myBooleanOperationType));
 
       // Checking that the algorithm worked properly.
-      if(!aFuseAlgo.isDone() || aFuseAlgo.shape()->isNull() || !aFuseAlgo.isValid()) {
+      if(!aFuseAlgo->isDone() || aFuseAlgo->shape()->isNull() || !aFuseAlgo->isValid()) {
         static const std::string aFeatureError = "Boolean algorithm failed";
         setError(aFeatureError);
         return;
       }
 
-      std::shared_ptr<GeomAPI_Shape> aShape = aFuseAlgo.shape();
-      aMakeShapeList.appendAlgo(aFuseAlgo.makeShape());
-      aMapOfShapes.merge(aFuseAlgo.mapOfShapes());
+      std::shared_ptr<GeomAPI_Shape> aShape = aFuseAlgo->shape();
+      aMakeShapeList.appendAlgo(aFuseAlgo);
+      aMapOfShapes.merge(aFuseAlgo->mapOfSubShapes());
 
       // Add result to not used solids from compsolid (if we have any).
       if(!aNotUsedSolids.empty()) {
         aNotUsedSolids.push_back(aShape);
-        GeomAlgoAPI_PaveFiller aFillerAlgo(aNotUsedSolids, true);
-        if(!aFillerAlgo.isDone()) {
+        std::shared_ptr<GeomAlgoAPI_PaveFiller> aFillerAlgo(new GeomAlgoAPI_PaveFiller(aNotUsedSolids, true));
+        if(!aFillerAlgo->isDone()) {
           std::string aFeatureError = "PaveFiller algorithm failed";
           setError(aFeatureError);
           return;
         }
-        if(aFillerAlgo.shape()->isNull()) {
+        if(aFillerAlgo->shape()->isNull()) {
           static const std::string aShapeError = "Resulting shape is Null";
           setError(aShapeError);
           return;
         }
-        if(!aFillerAlgo.isValid()) {
+        if(!aFillerAlgo->isValid()) {
           std::string aFeatureError = "Warning: resulting shape is not valid";
           setError(aFeatureError);
           return;
         }
 
-        aShape = aFillerAlgo.shape();
-        aMakeShapeList.appendAlgo(aFillerAlgo.makeShape());
-        aMapOfShapes.merge(aFillerAlgo.mapOfShapes());
+        aShape = aFillerAlgo->shape();
+        aMakeShapeList.appendAlgo(aFillerAlgo);
+        aMapOfShapes.merge(aFillerAlgo->mapOfSubShapes());
       }
 
       std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
@@ -377,7 +378,7 @@ void FeaturesPlugin_CompositeBoolean::execute()
 //=================================================================================================
 void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
                                                    const ListOfShape& theShells,
-                                                   const std::list<std::shared_ptr<GeomAPI_Interface>>& theSolidsAlgos,
+                                                   ListOfMakeShape& theSolidsAlgos,
                                                    const std::shared_ptr<GeomAPI_Shape> theBaseShape,
                                                    const ListOfShape& theTools,
                                                    const std::shared_ptr<GeomAPI_Shape> theResultShape,
@@ -392,7 +393,7 @@ void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr<ModelAPI_Resu
     const int aModTag = 2;
     const int aDelTag = 3;
     const int aSubsolidsTag=4; /// sub solids will be placed at labels 6, 7, etc. if result is compound of solids
-    int aToTag = 5; // may be many labels, starting from this index
+    int aToTag = 5000; // may be many labels, starting from this index
     int aFromTag = 10000; // may be many labels, starting from this index or last aToTag index
     const std::string aGenName = "Generated";
     const std::string aModName = "Modified";
@@ -403,47 +404,39 @@ void FeaturesPlugin_CompositeBoolean::loadNamingDS(std::shared_ptr<ModelAPI_Resu
     theResultBody->storeModified(theBaseShape, theResultShape, aSubsolidsTag);
 
     ListOfShape::const_iterator aShellsIter = theShells.begin();
-    std::list<std::shared_ptr<GeomAPI_Interface>>::const_iterator aSolidsAlgosIter = theSolidsAlgos.begin();
+    ListOfMakeShape::const_iterator aSolidsAlgosIter = theSolidsAlgos.begin();
     for(; aShellsIter != theShells.end() && aSolidsAlgosIter != theSolidsAlgos.end(); aShellsIter++, aSolidsAlgosIter++) {
-      ListOfShape aFromFaces;
-      ListOfShape aToFaces;
-      std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes;
-
       //Insert lateral face : Face from Edge
-      if(std::dynamic_pointer_cast<GeomAlgoAPI_Prism>(*aSolidsAlgosIter)) {
-        std::shared_ptr<GeomAlgoAPI_Prism> aPrismAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_Prism>(*aSolidsAlgosIter);
-        aSubShapes = aPrismAlgo->mapOfSubShapes();
-        theResultBody->loadAndOrientGeneratedShapes(aPrismAlgo.get(), *aShellsIter, GeomAPI_Shape::EDGE, aGenTag,
+      std::shared_ptr<GeomAlgoAPI_MakeShape> aSolidAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_MakeShape>(*aSolidsAlgosIter);
+      if(aSolidAlgo.get()) {
+        std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = aSolidAlgo->mapOfSubShapes();
+        theResultBody->loadAndOrientGeneratedShapes(aSolidAlgo.get(), *aShellsIter, GeomAPI_Shape::EDGE, aGenTag,
                                                     aLatName, *aSubShapes.get());
 
-        aFromFaces = aPrismAlgo->fromFaces();
-        aToFaces = aPrismAlgo->toFaces();
-      } else if(std::dynamic_pointer_cast<GeomAlgoAPI_Revolution>(*aSolidsAlgosIter)) {
-        std::shared_ptr<GeomAlgoAPI_Revolution> aRevolAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_Revolution>(*aSolidsAlgosIter);
-        aSubShapes = aRevolAlgo->mapOfShapes();
-        theResultBody->loadAndOrientGeneratedShapes(aRevolAlgo->makeShape().get(), *aShellsIter, GeomAPI_Shape::EDGE, aGenTag,
-                                                    aLatName, *aSubShapes.get());
-        aFromFaces = aRevolAlgo->fromFaces();
-        aToFaces = aRevolAlgo->toFaces();
-      }
 
-      //Insert to faces
-      for(ListOfShape::const_iterator anIt = aToFaces.cbegin(); anIt != aToFaces.cend(); anIt++) {
-        std::shared_ptr<GeomAPI_Shape> aToFace = *anIt;
-        if(aSubShapes->isBound(aToFace)) {
-          aToFace = aSubShapes->find(aToFace);
-        }
-        theResultBody->generated(aToFace, aToName, aToTag++);
-      }
+        std::shared_ptr<GeomAlgoAPI_MakeSweep> aSweepAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_MakeSweep>(aSolidAlgo);
+        if(aSweepAlgo.get()) {
+          //Insert to faces
+          const ListOfShape& aToFaces = aSweepAlgo->toFaces();
+          for(ListOfShape::const_iterator anIt = aToFaces.cbegin(); anIt != aToFaces.cend(); anIt++) {
+            std::shared_ptr<GeomAPI_Shape> aToFace = *anIt;
+            if(aSubShapes->isBound(aToFace)) {
+              aToFace = aSubShapes->find(aToFace);
+            }
+            theResultBody->generated(aToFace, aToName, aToTag++);
+          }
 
-      //Insert from faces
-      if (aFromTag < aToTag) aFromTag = aToTag;
-      for(ListOfShape::const_iterator anIt = aFromFaces.cbegin(); anIt != aFromFaces.cend(); anIt++) {
-        std::shared_ptr<GeomAPI_Shape> aFromFace = *anIt;
-        if(aSubShapes->isBound(aFromFace)) {
-          aFromFace = aSubShapes->find(aFromFace);
+          //Insert from faces
+          const ListOfShape& aFromFaces = aSweepAlgo->fromFaces();
+          if (aFromTag < aToTag) aFromTag = aToTag;
+          for(ListOfShape::const_iterator anIt = aFromFaces.cbegin(); anIt != aFromFaces.cend(); anIt++) {
+            std::shared_ptr<GeomAPI_Shape> aFromFace = *anIt;
+            if(aSubShapes->isBound(aFromFace)) {
+              aFromFace = aSubShapes->find(aFromFace);
+            }
+            theResultBody->generated(aFromFace, aFromName, aFromTag++);
+          }
         }
-        theResultBody->generated(aFromFace, aFromName, aFromTag++);
       }
     }