Salome HOME
Crash when searching duplicated constraints
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Extrusion.cpp
index 85b5b665deaa103ed604b6e9857b4a82ef6cfc12..c0bcd77f3bcb125d4f58cb8c534c9212ccd66084 100644 (file)
@@ -4,22 +4,16 @@
 // Created:     30 May 2014
 // Author:      Vitaly SMETANNIKOV
 
-#include <FeaturesPlugin_Extrusion.h>
+#include "FeaturesPlugin_Extrusion.h"
 
-#include <ModelAPI_BodyBuilder.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeString.h>
-#include <ModelAPI_AttributeReference.h>
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_Prism.h>
@@ -61,36 +55,26 @@ void FeaturesPlugin_Extrusion::execute()
   ListOfShape aFacesList;
   AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID());
   for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> aFaceSel = aFacesSelectionList->value(anIndex);
-    ResultPtr aContext = aFaceSel->context();
-    std::shared_ptr<GeomAPI_Shape> aContextShape = aContext->shape();
-    if(!aContextShape.get()) {
-      static const std::string aContextError = "The selection context is bad";
-      setError(aContextError);
-      break;
-    }
-
+    AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex);
     std::shared_ptr<GeomAPI_Shape> aFaceShape = aFaceSel->value();
-    int aFacesNum = -1; // this mean that "aFace" is used
-    ResultConstructionPtr aConstruction = 
-      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
-    if(!aFaceShape.get()) { // this may be the whole sketch result selected, check and get faces
-      if (aConstruction.get()) {
-        aFacesNum = aConstruction->facesNum();
-      } else {
+    if(aFaceShape.get() && !aFaceShape->isNull()) { // Getting face.
+      aFacesList.push_back(aFaceShape);
+    } else { // This may be the whole sketch result selected, check and get faces.
+      ResultPtr aContext = aFaceSel->context();
+      std::shared_ptr<GeomAPI_Shape> aContextShape = aContext->shape();
+      if(!aContextShape.get()) {
+        static const std::string aContextError = "The selection context is bad";
+        setError(aContextError);
+        return;
+      }
+      ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+      if(!aConstruction.get()) {
         static const std::string aFaceError = "Can not find basis for extrusion";
         setError(aFaceError);
-        break;
+        return;
       }
-    }
-    for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) {
-      std::shared_ptr<GeomAPI_Shape> aBaseShape;
-      if (aFacesNum == -1) {
-        if (!aFaceShape->isNull()) {
-          aFacesList.push_back(aFaceShape);
-        }
-        break;
-      } else {
+      int aFacesNum = aConstruction->facesNum();
+      for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) {
         aFaceShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
         aFacesList.push_back(aFaceShape);
       }
@@ -181,34 +165,34 @@ void FeaturesPlugin_Extrusion::loadNamingDS(GeomAlgoAPI_Prism& thePrismAlgo,
   //load result
   theResultBody->storeGenerated(theBasis, thePrismAlgo.shape());
 
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = thePrismAlgo.mapOfShapes();
+  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = thePrismAlgo.mapOfSubShapes();
 
   //Insert lateral face : Face from Edge
   const std::string aLatName = "LateralFace";
   const int aLatTag = 1;
-  theResultBody->loadAndOrientGeneratedShapes(thePrismAlgo.makeShape().get(), theBasis, GeomAPI_Shape::EDGE, aLatTag, aLatName, *aSubShapes);
+  theResultBody->loadAndOrientGeneratedShapes(&thePrismAlgo, theBasis, GeomAPI_Shape::EDGE, aLatTag, aLatName, *aSubShapes);
 
   //Insert to faces
   const std::string aToName = "ToFace";
-  const int aToTag = 2;
+  int aToTag = 2;
   const ListOfShape& aToFaces = thePrismAlgo.toFaces();
   for(ListOfShape::const_iterator anIt = aToFaces.cbegin(); anIt != aToFaces.cend(); anIt++) {
     std::shared_ptr<GeomAPI_Shape> aToFace = *anIt;
     if(aSubShapes->isBound(aToFace)) {
       aToFace = aSubShapes->find(aToFace);
     }
-    theResultBody->generated(aToFace, aToName, aToTag);
+    theResultBody->generated(aToFace, aToName, aToTag++);
   }
 
   //Insert from faces
   const std::string aFromName = "FromFace";
-  const int aFromTag = 3;
+  int aFromTag = aToTag > 10000 ? aToTag : 10000;
   const ListOfShape& aFromFaces = thePrismAlgo.fromFaces();
   for(ListOfShape::const_iterator anIt = aFromFaces.cbegin(); anIt != aFromFaces.cend(); anIt++) {
     std::shared_ptr<GeomAPI_Shape> aFromFace = *anIt;
     if(aSubShapes->isBound(aFromFace)) {
       aFromFace = aSubShapes->find(aFromFace);
     }
-    theResultBody->generated(aFromFace, aFromName, aFromTag);
+    theResultBody->generated(aFromFace, aFromName, aFromTag++);
   }
 }