Salome HOME
Make SHAPER STUDY fields exported in SMESH into MED file
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Compound.cpp
index 4df84ee1f77a96b588399785685da2be9cd70066..7aa9a81641d78c6c47d0f58ae41f17c78968e6d5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-20xx  CEA/DEN, EDF R&D
+// Copyright (C) 2017-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "BuildPlugin_Compound.h"
@@ -23,6 +22,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_ResultBody.h>
 
+#include <GeomAlgoAPI_Copy.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
 
@@ -56,28 +56,29 @@ 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);
+  // Copy shape.
+  GeomMakeShapePtr aCopyAlgo(new GeomAlgoAPI_Copy(aCompound));
+  GeomShapePtr aCopyCompound = aCopyAlgo->shape();
+
   int anIndexToRemove = 0;
-  if (aCompound) {
+  if (aCopyCompound) {
     ResultBodyPtr aResultBody = document()->createBody(data(), anIndexToRemove++);
-    aResultBody->store(aCompound);
-
-////    // 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);
-////    }
-
+    aResultBody->storeModified(anOriginalShapes, aCopyCompound, aCopyAlgo);
+    aResultBody->loadModifiedShapes(aCopyAlgo, aCompound, GeomAPI_Shape::VERTEX);
+    aResultBody->loadModifiedShapes(aCopyAlgo, aCompound, GeomAPI_Shape::EDGE);
+    aResultBody->loadModifiedShapes(aCopyAlgo, aCompound, GeomAPI_Shape::FACE);
     setResult(aResultBody);
   }
   removeResults(anIndexToRemove);