Salome HOME
Task 2.11. Ability to impose a midpoint on an arc (refers issue #3002)
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Intersection.cpp
index 73dec6b8a6fd486a3ee8ce9c1540277764c28c68..1fa9079247f632a9cf86732de0a28b271bfada7e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-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 "FeaturesPlugin_Intersection.h"
@@ -27,6 +26,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 
 #include <GeomAlgoAPI_Intersection.h>
+#include <GeomAlgoAPI_Tools.h>
 #include <GeomAPI_ShapeExplorer.h>
 
 #include <sstream>
@@ -68,22 +68,12 @@ void FeaturesPlugin_Intersection::execute()
   int aResultIndex = 0;
 
   // Create result.
-  GeomAlgoAPI_Intersection anIntersectionAlgo(anObjects);
+  GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects));
 
   // Checking that the algorithm worked properly.
-  if (!anIntersectionAlgo.isDone()) {
-    static const std::string aFeatureError = "Error: Intersection algorithm failed.";
-    setError(aFeatureError);
-    return;
-  }
-  if (anIntersectionAlgo.shape()->isNull()) {
-    static const std::string aShapeError = "Error: Resulting shape is Null.";
-    setError(aShapeError);
-    return;
-  }
-  if (!anIntersectionAlgo.isValid()) {
-    std::string aFeatureError = "Error: Resulting shape is not valid.";
-    setError(aFeatureError);
+  std::string anError;
+  if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anIntersectionAlgo, getKind(), anError)) {
+    setError(anError);
     return;
   }
 
@@ -92,71 +82,33 @@ void FeaturesPlugin_Intersection::execute()
   setResult(aResultBody, aResultIndex);
   aResultIndex++;
 
-
   // remove the rest results if there were produced in the previous pass
   removeResults(aResultIndex);
 }
 
 //=================================================================================================
-void FeaturesPlugin_Intersection::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+void FeaturesPlugin_Intersection::loadNamingDS(ResultBodyPtr theResultBody,
                                                const ListOfShape& theObjects,
-                                               GeomAlgoAPI_MakeShape& theMakeShape)
+                                               const GeomMakeShapePtr& theMakeShape)
 {
-  std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape.shape();
-  theResultBody->storeModified(theObjects.front(), aResultShape);
+  std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape->shape();
+
+  if(theObjects.front()->isEqual(aResultShape)) {
+    theResultBody->store(aResultShape, false);
+    return;
+  }
+
+  theResultBody->storeModified(theObjects, aResultShape, theMakeShape);
 
-  GeomAPI_DataMapOfShapeShape aShapesMap; // Map to store {result_shape, original_shape}
-  const int aShapeTypesNb = 2;
-  const GeomAPI_Shape::ShapeType aShapeTypes[aShapeTypesNb] =
-    {GeomAPI_Shape::VERTEX, GeomAPI_Shape::EDGE};
+  const int aShapeTypesNb = 3;
+  const GeomAPI_Shape::ShapeType aShapeTypes[aShapeTypesNb] = {GeomAPI_Shape::VERTEX,
+                                                               GeomAPI_Shape::EDGE,
+                                                               GeomAPI_Shape::FACE };
   for (ListOfShape::const_iterator anIt = theObjects.cbegin(); anIt != theObjects.cend(); ++anIt) {
     const GeomShapePtr aShape = *anIt;
     for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) {
-      for(GeomAPI_ShapeExplorer anOrigShapeExp(aShape, aShapeTypes[anIndex]);
-          anOrigShapeExp.more();
-          anOrigShapeExp.next()) {
-        ListOfShape aHistory;
-        const GeomShapePtr aSubShape = anOrigShapeExp.current();
-        theMakeShape.modified(aSubShape, aHistory);
-        for(ListOfShape::const_iterator aHistoryIt = aHistory.cbegin();
-            aHistoryIt != aHistory.cend();
-            ++aHistoryIt) {
-          aShapesMap.bind(*aHistoryIt, aSubShape);
-        }
-      }
-    }
-  }
-
-  int aModifiedVertexIndex(1),
-      aGeneratedVertexIndex(1),
-      aModifiedEdgeIndex(1),
-      aGeneratedEdgeIndex(1);
-  int aTag = 4;
-  GeomAPI_DataMapOfShapeShape aStoredShapes;
-  for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) {
-    for(GeomAPI_ShapeExplorer aShapeExp(aResultShape, aShapeTypes[anIndex]);
-        aShapeExp.more();
-        aShapeExp.next()) {
-      const GeomShapePtr aSubShape = aShapeExp.current();
-      if(aStoredShapes.isBound(aSubShape)) {
-        continue;
-      }
-      if(aShapesMap.isBound(aSubShape)) {
-        theResultBody->modified(aShapesMap.find(aSubShape),
-          aSubShape,
-          std::string("Modified_")
-            + (anIndex == 0 ? "Vertex_" : "Edge_")
-            + std::to_string((long long)(anIndex == 0 ? aModifiedVertexIndex++
-                                                      : aModifiedEdgeIndex++)));
-      } else {
-        theResultBody->generated(
-          aSubShape,
-          std::string("Generated_")
-            + (anIndex == 0 ? "Vertex_" : "Edge_")
-            + std::to_string((long long)(anIndex == 0 ? aGeneratedVertexIndex++
-                                                      : aGeneratedEdgeIndex++)));
-      }
-      aStoredShapes.bind(aSubShape, aSubShape);
+      theResultBody->loadModifiedShapes(theMakeShape, aShape, aShapeTypes[anIndex]);
+      theResultBody->loadGeneratedShapes(theMakeShape, aShape, aShapeTypes[anIndex]);
     }
   }
 }