]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/BuildPlugin/BuildPlugin_Shell.cpp
Salome HOME
updated copyright message
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Shell.cpp
index 636807e4d5ec49e13029f8e022fada710c30ed4c..a4950823ae1eee29013b5a535c7409bde15c69af 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -12,9 +12,9 @@
 //
 // 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_Shell.h"
@@ -24,6 +24,7 @@
 #include <ModelAPI_ResultConstruction.h>
 
 #include <GeomAlgoAPI_Sewing.h>
+#include <GeomAlgoAPI_Tools.h>
 #include <GeomAPI_ShapeExplorer.h>
 
 //=================================================================================================
@@ -44,71 +45,37 @@ void BuildPlugin_Shell::execute()
   AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
 
   // Collect base shapes.
-  ListOfShape aShapes;
-  for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+  ListOfShape aShapes, aContexts;
+  getOriginalShapesAndContexts(BASE_OBJECTS_ID(), aShapes, aContexts);
+
+  // Collect sketch faces.
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
     GeomShapePtr aShape = aSelection->value();
-    if(!aShape.get()) {
-      aShape = aSelection->context()->shape();
+    ResultConstructionPtr aContext =
+        std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSelection->context());
+    if (!aShape && aContext) {
+      for (int i = 0; i < aContext->facesNum(); ++i)
+        aShapes.push_back(aContext->face(i));
     }
-    aShapes.push_back(aShape);
   }
 
   // Sew faces.
-  GeomAlgoAPI_Sewing aSewingAlgo(aShapes);
-
-  // Check that algo is done.
-  if(!aSewingAlgo.isDone()) {
-    setError("Error: " + getKind() + " algorithm failed.");
-    return;
-  }
+  GeomMakeShapePtr aSewingAlgo(new GeomAlgoAPI_Sewing(aShapes));
 
-  // Check if shape is not null.
-  if(!aSewingAlgo.shape().get() || aSewingAlgo.shape()->isNull()) {
-    setError("Error: Resulting shape is null.");
-    return;
-  }
-
-  // Check that resulting shape is valid.
-  if(!aSewingAlgo.isValid()) {
-    setError("Error: Resulting shape is not valid.");
+  std::string anError;
+  if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSewingAlgo, getKind(), anError)) {
+    setError(anError);
     return;
   }
 
   // Store result.
-  GeomShapePtr aResult = aSewingAlgo.shape();
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfShapes = aSewingAlgo.mapOfSubShapes();
+  GeomShapePtr aResult = aSewingAlgo->shape();
 
   int anIndex = 0;
   for(GeomAPI_ShapeExplorer anExp(aResult, GeomAPI_Shape::SHELL); anExp.more(); anExp.next()) {
     GeomShapePtr aShell = anExp.current();
-    ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
-    aResultBody->store(aShell);
-    for(ListOfShape::const_iterator anIt = aShapes.cbegin(); anIt != aShapes.cend(); ++anIt) {
-      for(GeomAPI_ShapeExplorer
-          aFaceExp(*anIt, GeomAPI_Shape::FACE); aFaceExp.more(); aFaceExp.next()) {
-        GeomShapePtr aFace = aFaceExp.current();
-        ListOfShape aHistory;
-        aSewingAlgo.modified(aFace, aHistory);
-        for(ListOfShape::const_iterator aHistoryIt = aHistory.cbegin();
-            aHistoryIt != aHistory.cend();
-            ++aHistoryIt) {
-          GeomShapePtr aHistoryShape = *aHistoryIt;
-          if(aMapOfShapes->isBound(aHistoryShape)) {
-            aHistoryShape = aMapOfShapes->find(aHistoryShape);
-          }
-          if(aShell->isSubShape(aHistoryShape)) {
-            aResultBody->loadAndOrientModifiedShapes(&aSewingAlgo, aFace, GeomAPI_Shape::EDGE,
-                                                     1, "Modified_Edge", *aMapOfShapes.get());
-            aResultBody->loadAndOrientModifiedShapes(&aSewingAlgo, aFace, GeomAPI_Shape::FACE,
-                                                     2, "Modified_Face", *aMapOfShapes.get());
-            break;
-          }
-        }
-      }
-    }
-    setResult(aResultBody, anIndex);
-    ++anIndex;
+    storeResult(aSewingAlgo, aShapes, aContexts, aShell, anIndex++);
   }
 
   removeResults(anIndex);