Salome HOME
2.17. Improved management of overconstraint situation: Processing added arguments...
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_CompositeSketch.cpp
index f2edb24b4749fcef10426ee92bdd3264ba84cc58..3f95c49e857afc88cbc4d517705847699e4b2939 100644 (file)
@@ -115,7 +115,10 @@ void FeaturesPlugin_CompositeSketch::execute()
   if(!aConstruction.get()) {
     return;
   }
-  selection(SKETCH_SELECTION_ID())->setValue(aSketchRes, std::shared_ptr<GeomAPI_Shape>());
+
+  if (!selection(SKETCH_SELECTION_ID())->isInitialized() || selection(SKETCH_SELECTION_ID())->context() != aSketchRes) {
+    selection(SKETCH_SELECTION_ID())->setValue(aSketchRes, std::shared_ptr<GeomAPI_Shape>());
+  }
   int aSketchFacesNum = aConstruction->facesNum();
   if(aSketchFacesNum == 0) {
     return;
@@ -137,20 +140,17 @@ void FeaturesPlugin_CompositeSketch::execute()
   int aErrorsNum = 0;
   int aResultIndex = 0;
   for(ListOfShape::const_iterator anIter = aShells.cbegin(); anIter != aShells.cend(); anIter++) {
-    std::shared_ptr<GeomAPI_Shape> aResult;
-    ListOfShape aFromFaces, aToFaces;
     std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape;
-    std::shared_ptr<GeomAPI_DataMapOfShapeShape> aDataMap;
 
     std::shared_ptr<GeomAPI_Shape> aBaseFace = *anIter;
-    makeSolid(aBaseFace, aResult, aFromFaces, aToFaces, aMakeShape, aDataMap);
-    if(!aResult.get()) {
+    makeSolid(aBaseFace, aMakeShape);
+    if(!aMakeShape.get()) {
       aErrorsNum++;
       continue;
     }
 
     ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
-    loadNamingDS(aResultBody, aBaseFace, aResult, aFromFaces, aToFaces, aMakeShape, aDataMap);
+    loadNamingDS(aResultBody, aBaseFace, aMakeShape);
     setResult(aResultBody, aResultIndex);
     aResultIndex++;
   }
@@ -168,39 +168,41 @@ void FeaturesPlugin_CompositeSketch::execute()
 //=================================================================================================
 void FeaturesPlugin_CompositeSketch::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
                                                   const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
-                                                  const std::shared_ptr<GeomAPI_Shape>& theResult,
-                                                  const ListOfShape& theFromFaces,
-                                                  const ListOfShape& theToFaces,
-                                                  const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
-                                                  const std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap)
+                                                  const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape)
 {
   //load result
-  theResultBody->storeGenerated(theBaseShape, theResult);
+  theResultBody->storeGenerated(theBaseShape, theMakeShape->shape());
 
   //Insert lateral face : Face from Edge
   const std::string aLatName = "LateralFace";
   const int aLatTag = 1;
-  theResultBody->loadAndOrientGeneratedShapes(theMakeShape.get(), theBaseShape, GeomAPI_Shape::EDGE, aLatTag, aLatName, *theDataMap);
-
-  //Insert to faces
-  const std::string aToName = "ToFace";
-  int aToTag = 2;
-  for(ListOfShape::const_iterator anIt = theToFaces.cbegin(); anIt != theToFaces.cend(); anIt++) {
-    std::shared_ptr<GeomAPI_Shape> aToFace = *anIt;
-    if(theDataMap->isBound(aToFace)) {
-      aToFace = theDataMap->find(aToFace);
+  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aDataMap = theMakeShape->mapOfSubShapes();
+  theResultBody->loadAndOrientGeneratedShapes(theMakeShape.get(), theBaseShape, GeomAPI_Shape::EDGE, aLatTag, aLatName, *aDataMap.get());
+
+  std::shared_ptr<GeomAlgoAPI_MakeSweep> aSweepAlgo = std::dynamic_pointer_cast<GeomAlgoAPI_MakeSweep>(theMakeShape);
+  if(aSweepAlgo.get()) {
+    //Insert to faces
+    const std::string aToName = "ToFace";
+    int aToTag = 2;
+    const ListOfShape& aToFaces = aSweepAlgo->toFaces();
+    for(ListOfShape::const_iterator anIt = aToFaces.cbegin(); anIt != aToFaces.cend(); anIt++) {
+      std::shared_ptr<GeomAPI_Shape> aToFace = *anIt;
+      if(aDataMap->isBound(aToFace)) {
+        aToFace = aDataMap->find(aToFace);
+      }
+      theResultBody->generated(aToFace, aToName, aToTag++);
     }
-    theResultBody->generated(aToFace, aToName, aToTag++);
-  }
 
-  //Insert from faces
-  const std::string aFromName = "FromFace";
-  int aFromTag = aToTag > 10000 ? aToTag : 10000;
-  for(ListOfShape::const_iterator anIt = theFromFaces.cbegin(); anIt != theFromFaces.cend(); anIt++) {
-    std::shared_ptr<GeomAPI_Shape> aFromFace = *anIt;
-    if(theDataMap->isBound(aFromFace)) {
-      aFromFace = theDataMap->find(aFromFace);
+    //Insert from faces
+    const std::string aFromName = "FromFace";
+    int aFromTag = aToTag > 10000 ? aToTag : 10000;
+    const ListOfShape& aFromFaces = aSweepAlgo->fromFaces();
+    for(ListOfShape::const_iterator anIt = aFromFaces.cbegin(); anIt != aFromFaces.cend(); anIt++) {
+      std::shared_ptr<GeomAPI_Shape> aFromFace = *anIt;
+      if(aDataMap->isBound(aFromFace)) {
+        aFromFace = aDataMap->find(aFromFace);
+      }
+      theResultBody->generated(aFromFace, aFromName, aFromTag++);
     }
-    theResultBody->generated(aFromFace, aFromName, aFromTag++);
   }
 }