Salome HOME
Issue #2660: Update data model before save.
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Compound.cpp
index 4df84ee1f77a96b588399785685da2be9cd70066..69c8551bbbc6ee15bb9625feb7433c0858631ea6 100644 (file)
@@ -23,6 +23,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_ResultBody.h>
 
+#include <GeomAlgoAPI_Copy.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
 
@@ -56,28 +57,37 @@ void BuildPlugin_Compound::execute()
   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
     GeomShapePtr aShape = aSelection->value();
-    if (!aShape.get())
+    if (!aShape.get()) {
+      if (!aSelection->context().get()) {
+        setError("Invalid selection");
+        return;
+      }
       aShape = aSelection->context()->shape();
+    }
     anOriginalShapes.push_back(aShape);
   }
 
   // Build compound.
   GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(anOriginalShapes);
-  int anIndexToRemove = 0;
-  if (aCompound) {
-    ResultBodyPtr aResultBody = document()->createBody(data(), anIndexToRemove++);
-    aResultBody->store(aCompound);
+  // Copy shape.
+  GeomAlgoAPI_Copy aCopyAlgo(aCompound);
+  GeomShapePtr aCopyCompound = aCopyAlgo.shape();
 
-////    // Store faces
-////    std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfSubs = theAlgorithm->mapOfSubShapes();
-////    int aModifiedTag = 1;
-////    for(ListOfShape::const_iterator anIt = theOriginalShapes.cbegin();
-////        anIt != theOriginalShapes.cend(); ++anIt) {
-////      GeomShapePtr aShape = *anIt;
-////      aResultBody->loadAndOrientModifiedShapes(theAlgorithm.get(), aShape, GeomAPI_Shape::FACE,
-////          aModifiedTag, "Modified_Face", *aMapOfSubs.get(), false, true, true);
-////    }
+  int anIndexToRemove = 0;
+  if (aCopyCompound) {
+    std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfShapes = aCopyAlgo.mapOfSubShapes();
 
+    ResultBodyPtr aResultBody = document()->createBody(data(), anIndexToRemove++);
+    aResultBody->store(aCopyCompound);
+    aResultBody->loadAndOrientModifiedShapes(&aCopyAlgo, aCompound, GeomAPI_Shape::VERTEX,
+                                              1, "Modified_Vertex", *aMapOfShapes.get(),
+                                              true, false, true);
+    aResultBody->loadAndOrientModifiedShapes(&aCopyAlgo, aCompound, GeomAPI_Shape::EDGE,
+                                              100000, "Modified_Edge", *aMapOfShapes.get(),
+                                              true, false, true);
+    aResultBody->loadAndOrientModifiedShapes(&aCopyAlgo, aCompound, GeomAPI_Shape::FACE,
+                                              200000, "Modified_Face", *aMapOfShapes.get(),
+                                              true, false, true);
     setResult(aResultBody);
   }
   removeResults(anIndexToRemove);