Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Boolean.cpp
index 27f0399180af3a76924736e1e202fbc78a5c03ee..63a7834b008c638ce8d1285f03fc9ff96b4dcdb0 100644 (file)
@@ -24,7 +24,6 @@
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Session.h>
 #include <map>
 
 //=================================================================================================
-FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
+FeaturesPlugin_Boolean::FeaturesPlugin_Boolean(const OperationType theOperationType)
+: myOperationType(theOperationType)
 {
 }
 
 //=================================================================================================
 void FeaturesPlugin_Boolean::initAttributes()
 {
-  data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::typeId());
-
   AttributeSelectionListPtr aSelection =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
     FeaturesPlugin_Boolean::OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
@@ -80,15 +78,14 @@ std::shared_ptr<GeomAPI_Shape> FeaturesPlugin_Boolean::getShape(const std::strin
 }
 
 //=================================================================================================
-void FeaturesPlugin_Boolean::execute()
+FeaturesPlugin_Boolean::OperationType FeaturesPlugin_Boolean::operationType()
 {
-  // Getting operation type.
-  std::shared_ptr<ModelAPI_AttributeInteger> aTypeAttr = std::dynamic_pointer_cast<
-      ModelAPI_AttributeInteger>(data()->attribute(FeaturesPlugin_Boolean::TYPE_ID()));
-  if (!aTypeAttr)
-    return;
-  OperationType aType = (FeaturesPlugin_Boolean::OperationType)aTypeAttr->value();
+  return myOperationType;
+}
 
+//=================================================================================================
+void FeaturesPlugin_Boolean::execute()
+{
   ListOfShape anObjects, aTools, anEdgesAndFaces, aPlanes;
   std::map<std::shared_ptr<GeomAPI_Shape>, ListOfShape> aCompSolidsObjects;
 
@@ -102,7 +99,7 @@ void FeaturesPlugin_Boolean::execute()
       return;
     }
     ResultPtr aContext = anObjectAttr->context();
-    ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
+    ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aContext);
     if(aResCompSolidPtr.get()
         && aResCompSolidPtr->shape()->shapeType() == GeomAPI_Shape::COMPSOLID) {
       std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
@@ -118,7 +115,7 @@ void FeaturesPlugin_Boolean::execute()
         aCompSolidsObjects[aContextShape].push_back(anObject);
       }
     } else {
-      if(aType != BOOL_FILL
+      if(myOperationType != BOOL_FILL
         && (anObject->shapeType() == GeomAPI_Shape::EDGE
           || anObject->shapeType() == GeomAPI_Shape::FACE))
       {
@@ -141,7 +138,7 @@ void FeaturesPlugin_Boolean::execute()
       ResultPtr aContext = aToolAttr->context();
       aPlanes.push_back(aToolAttr->context()->shape());
     }
-    else if(aType != BOOL_FILL
+    else if (myOperationType != BOOL_FILL
       && (aTool->shapeType() == GeomAPI_Shape::EDGE
         || aTool->shapeType() == GeomAPI_Shape::FACE))
     {
@@ -153,7 +150,7 @@ void FeaturesPlugin_Boolean::execute()
 
   int aResultIndex = 0;
 
-  switch(aType) {
+  switch(myOperationType) {
     case BOOL_CUT:
     case BOOL_COMMON:
     case BOOL_FILL: {
@@ -170,11 +167,11 @@ void FeaturesPlugin_Boolean::execute()
         std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
         ListOfShape aListWithObject;
         aListWithObject.push_back(anObject);
-        GeomAlgoAPI_MakeShapeList aMakeShapeList;
+        std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
         std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
         GeomShapePtr aResShape;
 
-        switch(aType) {
+        switch(myOperationType) {
           case BOOL_CUT: {
             aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aListWithObject,
                                                     aTools,
@@ -204,13 +201,13 @@ void FeaturesPlugin_Boolean::execute()
               std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aMkShCustom(
                 new GeomAlgoAPI_MakeShapeCustom);
               aMkShCustom->addModified(aPlane, aTool);
-              aMakeShapeList.appendAlgo(aMkShCustom);
+              aMakeShapeList->appendAlgo(aMkShCustom);
               aToolsWithPlanes.push_back(aTool);
             }
 
             aBoolAlgo.reset(new GeomAlgoAPI_Partition(aListWithObject, aToolsWithPlanes));
             aResShape = aBoolAlgo->shape();
-            if(aResShape->shapeType() == GeomAPI_Shape::COMPOUND) {
+            if (aResShape.get() && aResShape->shapeType() == GeomAPI_Shape::COMPOUND) {
               int aSubResultsNb = 0;
               GeomAPI_ShapeIterator anIt(aResShape);
               for(; anIt.more(); anIt.next()) {
@@ -244,21 +241,20 @@ void FeaturesPlugin_Boolean::execute()
           return;
         }
 
-        aMakeShapeList.appendAlgo(aBoolAlgo);
+        aMakeShapeList->appendAlgo(aBoolAlgo);
 
         if(GeomAlgoAPI_ShapeTools::volume(aResShape) > 1.e-27
-          || (aType != BOOL_CUT && aType != BOOL_COMMON))
+           || (myOperationType != BOOL_CUT && myOperationType != BOOL_COMMON))
         {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody =
             document()->createBody(data(), aResultIndex);
 
           ListOfShape aUsedTools = aTools;
-          if (aType == BOOL_FILL) {
+          if (myOperationType == BOOL_FILL) {
             aUsedTools.insert(aUsedTools.end(), aPlanes.begin(), aPlanes.end());
           }
 
-          loadNamingDS(aResultBody, anObject, aUsedTools, aResShape,
-                       aMakeShapeList, *(aBoolAlgo->mapOfSubShapes()), aType == BOOL_FILL);
+          loadNamingDS(aResultBody, anObject, aUsedTools, aResShape, aMakeShapeList);
           setResult(aResultBody, aResultIndex);
           aResultIndex++;
         }
@@ -287,10 +283,10 @@ void FeaturesPlugin_Boolean::execute()
           }
         }
 
-        GeomAlgoAPI_MakeShapeList aMakeShapeList;
+        std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
         std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
 
-        switch(aType) {
+        switch(myOperationType) {
           case BOOL_CUT: {
             aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
                                                     aTools,
@@ -318,7 +314,7 @@ void FeaturesPlugin_Boolean::execute()
               std::shared_ptr<GeomAlgoAPI_MakeShapeCustom> aMkShCustom(
                 new GeomAlgoAPI_MakeShapeCustom);
               aMkShCustom->addModified(aPlane, aTool);
-              aMakeShapeList.appendAlgo(aMkShCustom);
+              aMakeShapeList->appendAlgo(aMkShCustom);
               aToolsWithPlanes.push_back(aTool);
             }
 
@@ -344,9 +340,7 @@ void FeaturesPlugin_Boolean::execute()
           return;
         }
 
-        aMakeShapeList.appendAlgo(aBoolAlgo);
-        GeomAPI_DataMapOfShapeShape aMapOfShapes;
-        aMapOfShapes.merge(aBoolAlgo->mapOfSubShapes());
+        aMakeShapeList->appendAlgo(aBoolAlgo);
         GeomShapePtr aResultShape = aBoolAlgo->shape();
 
         // Add result to not used solids from compsolid.
@@ -361,19 +355,18 @@ void FeaturesPlugin_Boolean::execute()
             return;
           }
 
-          aMakeShapeList.appendAlgo(aFillerAlgo);
-          aMapOfShapes.merge(aFillerAlgo->mapOfSubShapes());
+          aMakeShapeList->appendAlgo(aFillerAlgo);
           aResultShape = aFillerAlgo->shape();
         }
 
         if(GeomAlgoAPI_ShapeTools::volume(aResultShape) > 1.e-27
-          || (aType != BOOL_CUT && aType != BOOL_COMMON))
+           || (myOperationType != BOOL_CUT && myOperationType != BOOL_COMMON))
         {
           std::shared_ptr<ModelAPI_ResultBody> aResultBody =
             document()->createBody(data(), aResultIndex);
 
           ListOfShape aUsedTools = aTools;
-          if (aType == BOOL_FILL) {
+          if (myOperationType == BOOL_FILL) {
             aUsedTools.insert(aUsedTools.end(), aPlanes.begin(), aPlanes.end());
           }
 
@@ -381,9 +374,7 @@ void FeaturesPlugin_Boolean::execute()
                        aCompSolid,
                        aUsedTools,
                        aResultShape,
-                       aMakeShapeList,
-                       aMapOfShapes,
-                       aType == BOOL_FILL);
+                       aMakeShapeList);
           setResult(aResultBody, aResultIndex);
           aResultIndex++;
         }
@@ -434,16 +425,14 @@ void FeaturesPlugin_Boolean::execute()
       anOriginalShapes.insert(anOriginalShapes.end(), aShapesToAdd.begin(), aShapesToAdd.end());
 
       // Cut edges and faces(if we have any) with solids.
-      GeomAlgoAPI_MakeShapeList aMakeShapeList;
-      GeomAPI_DataMapOfShapeShape aMapOfShapes;
+      std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
       std::shared_ptr<GeomAPI_Shape> aCuttedEdgesAndFaces;
       if(!anEdgesAndFaces.empty()) {
         std::shared_ptr<GeomAlgoAPI_Boolean> aCutAlgo(new GeomAlgoAPI_Boolean(anEdgesAndFaces,
                                             anOriginalShapes, GeomAlgoAPI_Boolean::BOOL_CUT));
         if(aCutAlgo->isDone()) {
           aCuttedEdgesAndFaces = aCutAlgo->shape();
-          aMakeShapeList.appendAlgo(aCutAlgo);
-          aMapOfShapes.merge(aCutAlgo->mapOfSubShapes());
+          aMakeShapeList->appendAlgo(aCutAlgo);
         }
       }
       anOriginalShapes.insert(anOriginalShapes.end(), anEdgesAndFaces.begin(),
@@ -461,8 +450,7 @@ void FeaturesPlugin_Boolean::execute()
 
           if(GeomAlgoAPI_ShapeTools::volume(aCutAlgo->shape()) > 1.e-27) {
             aSolidsToFuse.push_back(aCutAlgo->shape());
-            aMakeShapeList.appendAlgo(aCutAlgo);
-            aMapOfShapes.merge(aCutAlgo->mapOfSubShapes());
+            aMakeShapeList->appendAlgo(aCutAlgo);
           }
         }
       }
@@ -503,8 +491,7 @@ void FeaturesPlugin_Boolean::execute()
         }
 
         aShape = aFuseAlgo->shape();
-        aMakeShapeList.appendAlgo(aFuseAlgo);
-        aMapOfShapes.merge(aFuseAlgo->mapOfSubShapes());
+        aMakeShapeList->appendAlgo(aFuseAlgo);
       }
 
       // Combine result with not used solids from compsolid and edges and faces (if we have any).
@@ -536,8 +523,7 @@ void FeaturesPlugin_Boolean::execute()
         }
 
         aShape = aFillerAlgo->shape();
-        aMakeShapeList.appendAlgo(aFillerAlgo);
-        aMapOfShapes.merge(aFillerAlgo->mapOfSubShapes());
+        aMakeShapeList->appendAlgo(aFillerAlgo);
       }
 
       std::shared_ptr<GeomAPI_Shape> aBackShape = anOriginalShapes.back();
@@ -545,7 +531,7 @@ void FeaturesPlugin_Boolean::execute()
       std::shared_ptr<ModelAPI_ResultBody> aResultBody =
         document()->createBody(data(), aResultIndex);
       loadNamingDS(aResultBody, aBackShape, anOriginalShapes,
-                   aShape, aMakeShapeList, aMapOfShapes);
+                   aShape, aMakeShapeList);
       setResult(aResultBody, aResultIndex);
       aResultIndex++;
       break;
@@ -594,8 +580,7 @@ void FeaturesPlugin_Boolean::execute()
         }
       }
 
-      GeomAlgoAPI_MakeShapeList aMakeShapeList;
-      GeomAPI_DataMapOfShapeShape aMapOfShapes;
+      std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList;
       if(!aShapesToAdd.empty()) {
         // Cut objects with not used solids.
         std::shared_ptr<GeomAlgoAPI_Boolean> anObjectsCutAlgo(new GeomAlgoAPI_Boolean(
@@ -606,8 +591,7 @@ void FeaturesPlugin_Boolean::execute()
         if(GeomAlgoAPI_ShapeTools::volume(anObjectsCutAlgo->shape()) > 1.e-27) {
           aShapesToSmash.clear();
           aShapesToSmash.push_back(anObjectsCutAlgo->shape());
-          aMakeShapeList.appendAlgo(anObjectsCutAlgo);
-          aMapOfShapes.merge(anObjectsCutAlgo->mapOfSubShapes());
+          aMakeShapeList->appendAlgo(anObjectsCutAlgo);
         }
 
         // Cut tools with not used solids.
@@ -618,8 +602,7 @@ void FeaturesPlugin_Boolean::execute()
         if(GeomAlgoAPI_ShapeTools::volume(aToolsCutAlgo->shape()) > 1.e-27) {
           aTools.clear();
           aTools.push_back(aToolsCutAlgo->shape());
-          aMakeShapeList.appendAlgo(aToolsCutAlgo);
-          aMapOfShapes.merge(aToolsCutAlgo->mapOfSubShapes());
+          aMakeShapeList->appendAlgo(aToolsCutAlgo);
         }
       }
 
@@ -644,8 +627,7 @@ void FeaturesPlugin_Boolean::execute()
         setError(aFeatureError);
         return;
       }
-      aMakeShapeList.appendAlgo(aBoolAlgo);
-      aMapOfShapes.merge(aBoolAlgo->mapOfSubShapes());
+      aMakeShapeList->appendAlgo(aBoolAlgo);
 
       // Put all (cut result, tools and not used solids) to PaveFiller.
       aShapesToAdd.push_back(aBoolAlgo->shape());
@@ -670,15 +652,13 @@ void FeaturesPlugin_Boolean::execute()
       }
 
       std::shared_ptr<GeomAPI_Shape> aShape = aFillerAlgo->shape();
-      aMakeShapeList.appendAlgo(aFillerAlgo);
-      aMapOfShapes.merge(aFillerAlgo->mapOfSubShapes());
+      aMakeShapeList->appendAlgo(aFillerAlgo);
 
       std::shared_ptr<GeomAPI_Shape> aFrontShape = anOriginalShapes.front();
       anOriginalShapes.pop_front();
       std::shared_ptr<ModelAPI_ResultBody> aResultBody =
         document()->createBody(data(), aResultIndex);
-      loadNamingDS(aResultBody, aFrontShape, anOriginalShapes,
-        aShape, aMakeShapeList, aMapOfShapes);
+      loadNamingDS(aResultBody, aFrontShape, anOriginalShapes, aShape, aMakeShapeList);
       setResult(aResultBody, aResultIndex);
       aResultIndex++;
 
@@ -699,53 +679,30 @@ void FeaturesPlugin_Boolean::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> t
                                           const std::shared_ptr<GeomAPI_Shape> theBaseShape,
                                           const ListOfShape& theTools,
                                           const std::shared_ptr<GeomAPI_Shape> theResultShape,
-                                          GeomAlgoAPI_MakeShape& theMakeShape,
-                                          GeomAPI_DataMapOfShapeShape& theMapOfShapes,
-                                          const bool theIsStoreAsGenerated)
+                                          const GeomMakeShapePtr& theMakeShape)
 {
   //load result
   if(theBaseShape->isEqual(theResultShape)) {
     theResultBody->store(theResultShape, false);
-  } else {
-    const int aModifyTag = 1;
-    const int aModifyEdgeTag = 2;
-    const int aModifyFaceTag = 3;
-    const int aDeletedTag = 4;
-    /// sub solids will be placed at labels 5, 6, etc. if result is compound of solids
-    const int aSubsolidsTag = 5;
-
-    theResultBody->storeModified(theBaseShape, theResultShape, aSubsolidsTag);
-
-    const std::string aModName = "Modified";
-    const std::string aModEName = "Modified_Edge";
-    const std::string aModFName = "Modified_Face";
-
-    theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::EDGE,
-      aModifyEdgeTag, aModEName, theMapOfShapes, false, theIsStoreAsGenerated, true);
-    theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::FACE,
-      aModifyFaceTag, aModFName, theMapOfShapes, false, theIsStoreAsGenerated, true);
-    theResultBody->loadDeletedShapes(&theMakeShape, theBaseShape,
-                                     GeomAPI_Shape::FACE, aDeletedTag);
-
-    int aTag;
-    std::string aName;
-    for(ListOfShape::const_iterator
-        anIter = theTools.begin(); anIter != theTools.end(); anIter++) {
-      if((*anIter)->shapeType() == GeomAPI_Shape::EDGE) {
-        aTag = aModifyEdgeTag;
-        aName = aModEName;
-      }
-      else if((*anIter)->shapeType() == GeomAPI_Shape::FACE) {
-        aTag = aModifyFaceTag;
-        aName = aModFName;
-      } else {
-        aTag = aModifyFaceTag;
-        aName = aModFName;
-      }
-      theResultBody->loadAndOrientModifiedShapes(&theMakeShape, *anIter,
-        aName == aModEName ? GeomAPI_Shape::EDGE : GeomAPI_Shape::FACE,
-        aTag, aName, theMapOfShapes, false, theIsStoreAsGenerated, true);
-      theResultBody->loadDeletedShapes(&theMakeShape, *anIter, GeomAPI_Shape::FACE, aDeletedTag);
-    }
+    return;
+  }
+
+  theResultBody->storeModified(theBaseShape, theResultShape);
+
+  theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::EDGE);
+  theResultBody->loadModifiedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
+
+  theResultBody->loadDeletedShapes(theMakeShape, theBaseShape, GeomAPI_Shape::FACE);
+
+  for (ListOfShape::const_iterator anIter = theTools.begin();
+       anIter != theTools.end();
+       ++anIter)
+  {
+    GeomAPI_Shape::ShapeType aShapeType =
+      (*anIter)->shapeType() <= GeomAPI_Shape::FACE ? GeomAPI_Shape::FACE
+                                                    : GeomAPI_Shape::EDGE;
+    theResultBody->loadModifiedShapes(theMakeShape, *anIter, aShapeType);
+
+    theResultBody->loadDeletedShapes(theMakeShape, *anIter, GeomAPI_Shape::FACE);
   }
 }