Salome HOME
Issue #2565: CEA 2018-1 Intersection
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Intersection.cpp
index e557498945a3add650f18bbbd6c4fa805341670b..7a33f2d463cf4e09dd340ae3ee9a247beac11f3e 100644 (file)
@@ -39,20 +39,17 @@ FeaturesPlugin_Intersection::FeaturesPlugin_Intersection()
 //=================================================================================================
 void FeaturesPlugin_Intersection::initAttributes()
 {
-  data()->addAttribute(FeaturesPlugin_Intersection::OBJECT_LIST_ID(),
-                       ModelAPI_AttributeSelectionList::typeId());
-  data()->addAttribute(FeaturesPlugin_Intersection::TOOL_LIST_ID(),
+  data()->addAttribute(OBJECT_LIST_ID(),
                        ModelAPI_AttributeSelectionList::typeId());
 }
 
 //=================================================================================================
 void FeaturesPlugin_Intersection::execute()
 {
-  ListOfShape anObjects, aTools;
+  ListOfShape anObjects;
 
   // Getting objects.
-  AttributeSelectionListPtr anObjectsSelList =
-    selectionList(FeaturesPlugin_Intersection::OBJECT_LIST_ID());
+  AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECT_LIST_ID());
   for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
     std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
       anObjectsSelList->value(anObjectsIndex);
@@ -63,54 +60,38 @@ void FeaturesPlugin_Intersection::execute()
     anObjects.push_back(anObject);
   }
 
-  // Getting tools.
-  AttributeSelectionListPtr aToolsSelList =
-    selectionList(FeaturesPlugin_Intersection::TOOL_LIST_ID());
-  for (int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> aToolAttr = aToolsSelList->value(aToolsIndex);
-    std::shared_ptr<GeomAPI_Shape> aTool = aToolAttr->value();
-    if (!aTool.get()) {
-      return;
-    }
-    aTools.push_back(aTool);
-  }
-
-  if(anObjects.empty() || aTools.empty()) {
+  if(anObjects.empty()) {
     setError("Error: Objects or tools are empty.");
     return;
   }
 
   int aResultIndex = 0;
 
-  // Create result for each object.
-  for (ListOfShape::iterator
-       anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
-    std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
-    ListOfShape aListWithObject; aListWithObject.push_back(anObject);
-    GeomAlgoAPI_Intersection anIntersectionAlgo(aListWithObject, aTools);
-
-    // 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);
-      return;
-    }
+  // Create result.
+  GeomAlgoAPI_Intersection anIntersectionAlgo(anObjects);
 
-    std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-    loadNamingDS(aResultBody, anObject, aTools, anIntersectionAlgo);
-    setResult(aResultBody, aResultIndex);
-    aResultIndex++;
+  // 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);
+    return;
+  }
+
+  std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+  loadNamingDS(aResultBody, anObjects, anIntersectionAlgo);
+  setResult(aResultBody, aResultIndex);
+  aResultIndex++;
+
 
   // remove the rest results if there were produced in the previous pass
   removeResults(aResultIndex);
@@ -118,37 +99,17 @@ void FeaturesPlugin_Intersection::execute()
 
 //=================================================================================================
 void FeaturesPlugin_Intersection::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                                               const std::shared_ptr<GeomAPI_Shape> theBaseShape,
-                                               const ListOfShape& theTools,
+                                               const ListOfShape& theObjects,
                                                GeomAlgoAPI_MakeShape& theMakeShape)
 {
   std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape.shape();
-  theResultBody->storeModified(theBaseShape, aResultShape);
-
-  const int aDeletedVertexTag = 1;
-  const int aDeletedEdgeTag   = 2;
-  const int aDeletedFaceTag   = 3;
-
-  theResultBody->loadDeletedShapes(&theMakeShape,
-                                   theBaseShape,
-                                   GeomAPI_Shape::VERTEX,
-                                   aDeletedVertexTag);
-  theResultBody->loadDeletedShapes(&theMakeShape,
-                                   theBaseShape,
-                                   GeomAPI_Shape::EDGE,
-                                   aDeletedEdgeTag);
-  theResultBody->loadDeletedShapes(&theMakeShape,
-                                   theBaseShape,
-                                   GeomAPI_Shape::FACE,
-                                   aDeletedFaceTag);
-
-  ListOfShape aShapes = theTools;
-  aShapes.push_back(theBaseShape);
+  theResultBody->storeModified(theObjects.front(), aResultShape);
+
   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};
-  for(ListOfShape::const_iterator anIt = aShapes.cbegin(); anIt != aShapes.cend(); ++anIt) {
+  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]);