Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Partition.cpp
index 3ef472216f53143c2598369fd6724ab0dc04e991..ca91f21b63008e36e0cb6c115c9b09cd225a6b60 100755 (executable)
@@ -204,26 +204,18 @@ void FeaturesPlugin_Partition::storeResult(
     return;
   }
 
-  const int aDelTag = 1;
-  /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids
-  const int aSubTag = 2;
-  int aModTag = aSubTag + 10000;
-  const std::string aModName = "Modified";
-
-  aResultBody->storeModified(aBaseShape, theResultShape, aSubTag);
+  aResultBody->storeModified(aBaseShape, theResultShape);
 
   std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfSubShapes = theMakeShape->mapOfSubShapes();
   theObjects.insert(theObjects.end(), thePlanes.begin(), thePlanes.end());
-  int anIndex = 1;
-  for(ListOfShape::const_iterator anIt = theObjects.cbegin(); anIt != theObjects.cend(); ++anIt) {
+  for (ListOfShape::const_iterator anIt = theObjects.cbegin();
+       anIt != theObjects.cend();
+       ++anIt)
+  {
     GeomShapePtr aShape = *anIt;
-    std::string aModEdgeName = aModName + "_Edge_" + std::to_string((long long)anIndex);
-    aResultBody->loadAndOrientModifiedShapes(theMakeShape.get(), aShape, GeomAPI_Shape::EDGE,
-      aModTag, aModEdgeName, *aMapOfSubShapes.get(), false, true, true);
-    std::string aModFaceName = aModName + "_Face_" + std::to_string((long long)anIndex++);
-    aResultBody->loadAndOrientModifiedShapes(theMakeShape.get(), aShape, GeomAPI_Shape::FACE,
-      aModTag + 1, aModFaceName, *aMapOfSubShapes.get(), false, true, true);
-    aResultBody->loadDeletedShapes(theMakeShape.get(), aShape, GeomAPI_Shape::FACE, aDelTag);
+    aResultBody->loadModifiedShapes(theMakeShape, aShape, GeomAPI_Shape::EDGE);
+    aResultBody->loadModifiedShapes(theMakeShape, aShape, GeomAPI_Shape::FACE);
+    aResultBody->loadDeletedShapes(theMakeShape, aShape, GeomAPI_Shape::FACE);
   }
 
   setResult(aResultBody, theIndex);
@@ -366,40 +358,60 @@ void unusedSubsOfComposolid(const CompsolidSubs& theObjects, CompsolidSubs& theN
   }
 }
 
-bool cutUnusedSubs(CompsolidSubs& theObjects, CompsolidSubs& theNotUsed,
-                   std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theMakeShapeList,
-                   std::string& theError)
+static bool cutSubs(const GeomShapePtr& theFirstArgument,
+                    CompsolidSubs& theSubsToCut,
+                    const ListOfShape& theTools,
+                    std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theMakeShapeList,
+                    std::string& theError)
 {
+  if (theTools.empty())
+    return true;
+
   std::shared_ptr<GeomAlgoAPI_MakeShape> aCutAlgo;
 
-  for (CompsolidSubs::iterator anObjIt = theObjects.begin();
-       anObjIt != theObjects.end(); ++anObjIt) {
-    // get list of unused subs of composolids except the current
-    ListOfShape aTools;
-    for (CompsolidSubs::const_iterator aUIt = theNotUsed.begin();
-         aUIt != theNotUsed.end(); ++aUIt) {
-      if (aUIt->first != anObjIt->first)
-        aTools.insert(aTools.end(), aUIt->second.begin(), aUIt->second.end());
-    }
-    if (aTools.empty())
-      continue;
+  for (CompsolidSubs::iterator aUIt= theSubsToCut.begin(); aUIt != theSubsToCut.end(); ++aUIt) {
+    if (aUIt->first == theFirstArgument)
+      continue; // no need to split unused subs of the first compsolid
 
     // cut from current list of solids
     aCutAlgo.reset(
-        new GeomAlgoAPI_Boolean(anObjIt->second, aTools, GeomAlgoAPI_Boolean::BOOL_CUT));
+        new GeomAlgoAPI_Boolean(aUIt->second, theTools, GeomAlgoAPI_Boolean::BOOL_CUT));
     if (isAlgoFailed(aCutAlgo, theError))
       return false;
     theMakeShapeList->appendAlgo(aCutAlgo);
 
-    // update list of objects of the partition
-    GeomAPI_Shape::ShapeType aType = anObjIt->second.front()->shapeType();
-    anObjIt->second.clear();
+    // update list of un-selected objects of the partition
+    GeomAPI_Shape::ShapeType aType = aUIt->second.front()->shapeType();
+    aUIt->second.clear();
     for (GeomAPI_ShapeExplorer anExp(aCutAlgo->shape(), aType); anExp.more(); anExp.next())
-      anObjIt->second.push_back(anExp.current());
+      aUIt->second.push_back(anExp.current());
   }
   return true;
 }
 
+bool cutUnusedSubs(CompsolidSubs& theObjects, CompsolidSubs& theNotUsed,
+                   std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theMakeShapeList,
+                   std::string& theError)
+{
+  GeomShapePtr aFirstArgument = theObjects.front().first;
+
+  // compose a set of tools for the CUT operation:
+  // find the list of unused subs of the first argument or use itself
+  ListOfShape aToolsForUsed;
+  CompsolidSubs::iterator aUIt = theNotUsed.begin();
+  for (; aUIt != theNotUsed.end(); ++aUIt)
+    if (aUIt->first == aFirstArgument) {
+      aToolsForUsed.insert(aToolsForUsed.end(), aUIt->second.begin(), aUIt->second.end());
+      break;
+    }
+  ListOfShape aToolsForUnused;
+  aToolsForUnused.push_back(aFirstArgument);
+
+  // cut subs
+  return cutSubs(aFirstArgument, theObjects, aToolsForUsed, theMakeShapeList, theError)
+      && cutSubs(aFirstArgument, theNotUsed, aToolsForUnused, theMakeShapeList, theError);
+}
+
 bool isAlgoFailed(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo, std::string& theError)
 {
   if (!theAlgo->isDone()) {