Salome HOME
Get rid of compilation warnings. Part I.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Pipe.cpp
index 3e46113b1933d88f41c2f4756e86c42f9da1e089..be47490ad99760318c70c71c917308dae3719e51 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        FeaturesPlugin_Pipe.cpp
-// Created:     16 March 2016
-// Author:      Dmitry Bobylev
+// Copyright (C) 2014-2020  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// 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
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "FeaturesPlugin_Pipe.h"
 
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_Pipe.h>
-#include <GeomAPI_ShapeExplorer.h>
 #include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_Tools.h>
 
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_ShapeExplorer.h>
+
+#include <map>
 #include <sstream>
 
-//=================================================================================================
+static void storeSubShape(ResultBodyPtr theResultBody,
+                          const GeomShapePtr theShape,
+                          const GeomAPI_Shape::ShapeType theType,
+                          const std::string theName,
+                          int& theShapeIndex);
+
+//==================================================================================================
 FeaturesPlugin_Pipe::FeaturesPlugin_Pipe()
 {
 }
 
-//=================================================================================================
+//==================================================================================================
 void FeaturesPlugin_Pipe::initAttributes()
 {
   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
@@ -39,7 +62,7 @@ void FeaturesPlugin_Pipe::initAttributes()
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LOCATIONS_ID());
 }
 
-//=================================================================================================
+//==================================================================================================
 void FeaturesPlugin_Pipe::execute()
 {
   // Getting creation method.
@@ -47,6 +70,7 @@ void FeaturesPlugin_Pipe::execute()
 
   // Getting base objects.
   ListOfShape aBaseShapesList, aBaseFacesList;
+  std::map<ResultConstructionPtr, ListOfShape> aSketchWiresMap;
   AttributeSelectionListPtr aBaseObjectsSelectionList = selectionList(BASE_OBJECTS_ID());
   if(!aBaseObjectsSelectionList.get()) {
     setError("Error: Could not get base objects selection list.");
@@ -64,11 +88,22 @@ void FeaturesPlugin_Pipe::execute()
     }
     std::shared_ptr<GeomAPI_Shape> aBaseShape = aBaseObjectSelection->value();
     if(aBaseShape.get() && !aBaseShape->isNull()) {
-      aBaseShape->shapeType() == GeomAPI_Shape::FACE ? aBaseFacesList.push_back(aBaseShape) :
-                                                       aBaseShapesList.push_back(aBaseShape);
+      GeomAPI_Shape::ShapeType aST = aBaseShape->shapeType();
+      ResultConstructionPtr aConstruction =
+        std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseObjectSelection->context());
+      if(aConstruction.get() && !aBaseShape->isEqual(aConstruction->shape()) &&
+          aST == GeomAPI_Shape::WIRE) {
+        // It is a wire on the sketch, store it to make face later.
+        aSketchWiresMap[aConstruction].push_back(aBaseShape);
+        continue;
+      } else {
+      aST == GeomAPI_Shape::FACE ? aBaseFacesList.push_back(aBaseShape) :
+                                   aBaseShapesList.push_back(aBaseShape);
+      }
     } else {
       // This may be the whole sketch result selected, check and get faces.
-      ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseObjectSelection->context());
+      ResultConstructionPtr aConstruction =
+        std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseObjectSelection->context());
       if(!aConstruction.get()) {
         setError("Error: One of selected sketches does not have results.");
         return;
@@ -83,7 +118,8 @@ void FeaturesPlugin_Pipe::execute()
         }
       } else {
         for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
-          std::shared_ptr<GeomAPI_Shape> aBaseFace = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
+          std::shared_ptr<GeomAPI_Shape> aBaseFace =
+            std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
           if(!aBaseFace.get() || aBaseFace->isNull()) {
             setError("Error: One of the faces on selected sketch is Null.");
             return;
@@ -94,14 +130,25 @@ void FeaturesPlugin_Pipe::execute()
     }
   }
 
+  // Make faces from sketch wires.
+  for(std::map<ResultConstructionPtr, ListOfShape>::const_iterator anIt = aSketchWiresMap.cbegin();
+      anIt != aSketchWiresMap.cend(); ++anIt) {
+    const std::shared_ptr<GeomAPI_PlanarEdges> aSketchPlanarEdges =
+      std::dynamic_pointer_cast<GeomAPI_PlanarEdges>((*anIt).first->shape());
+    const ListOfShape& aWiresList = (*anIt).second;
+    ListOfShape aFaces;
+    GeomAlgoAPI_ShapeTools::makeFacesWithHoles(aSketchPlanarEdges->origin(),
+                                               aSketchPlanarEdges->norm(),
+                                               aWiresList,
+                                               aFaces);
+    aBaseFacesList.insert(aBaseFacesList.end(), aFaces.begin(), aFaces.end());
+  }
+
   // Searching faces with common edges.
-  if(aCreationMethod == "simple") {
-    ListOfShape aShells;
-    ListOfShape aFreeFaces;
-    std::shared_ptr<GeomAPI_Shape> aFacesCompound = GeomAlgoAPI_CompoundBuilder::compound(aBaseFacesList);
-    GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL, aShells, aFreeFaces);
-    aBaseShapesList.insert(aBaseShapesList.end(), aFreeFaces.begin(), aFreeFaces.end());
-    aBaseShapesList.insert(aBaseShapesList.end(), aShells.begin(), aShells.end());
+  if(aCreationMethod == CREATION_METHOD_SIMPLE()) {
+    std::shared_ptr<GeomAPI_Shape> aFacesCompound =
+      GeomAlgoAPI_CompoundBuilder::compound(aBaseFacesList);
+    GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL, aBaseShapesList);
   } else {
     aBaseShapesList.insert(aBaseShapesList.end(), aBaseFacesList.begin(), aBaseFacesList.end());
   }
@@ -112,9 +159,10 @@ void FeaturesPlugin_Pipe::execute()
     setError("Error: Path selection is empty.");
     return;
   }
-  std::shared_ptr<GeomAPI_Shape> aPathShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aPathSelection->value());
-  if(!aPathShape.get()) {
-    // Probaply it is a construction.
+  std::shared_ptr<GeomAPI_Shape> aPathShape =
+    std::dynamic_pointer_cast<GeomAPI_Shape>(aPathSelection->value());
+  if(!aPathShape.get() && aPathSelection->context().get()) {
+    // Probably it is a construction.
     aPathShape = aPathSelection->context()->shape();
   }
   if(!aPathShape.get() || aPathShape->isNull()) {
@@ -124,14 +172,14 @@ void FeaturesPlugin_Pipe::execute()
 
   // Getting Bi-Normal
   std::shared_ptr<GeomAPI_Shape> aBiNormal;
-  if(aCreationMethod == "binormal") {
+  if(aCreationMethod == CREATION_METHOD_BINORMAL()) {
     AttributeSelectionPtr aBiNormalSelection = selection(BINORMAL_ID());
     if(!aBiNormalSelection.get()) {
       setError("Error: Bi-Normal selection is empty.");
       return;
     }
     aBiNormal = std::dynamic_pointer_cast<GeomAPI_Shape>(aBiNormalSelection->value());
-    if(!aBiNormal.get()) {
+    if(!aBiNormal.get() && aBiNormalSelection->context().get()) {
       // Probably it is a construction.
       aBiNormal = aBiNormalSelection->context()->shape();
     }
@@ -143,7 +191,7 @@ void FeaturesPlugin_Pipe::execute()
 
   // Getting locations.
   ListOfShape aLocations;
-  if(aCreationMethod == "locations") {
+  if(aCreationMethod == CREATION_METHOD_LOCATIONS()) {
     AttributeSelectionListPtr aLocationsSelectionList = selectionList(LOCATIONS_ID());
     if(!aLocationsSelectionList.get()) {
       setError("Error: Could not get locations selection list.");
@@ -156,7 +204,7 @@ void FeaturesPlugin_Pipe::execute()
         return;
       }
       std::shared_ptr<GeomAPI_Shape> aLocationShape = aLocationSelection->value();
-      if(!aLocationShape.get()) {
+      if(!aLocationShape.get() && aLocationSelection->context().get()) {
         // Probably it is a construction.
         aLocationShape = aLocationSelection->context()->shape();
       }
@@ -170,55 +218,40 @@ void FeaturesPlugin_Pipe::execute()
 
   // Generating result for each object.
   int aResultIndex = 0;
-  if(aCreationMethod == "simple" || aCreationMethod == "binormal") {
-    for(ListOfShape::const_iterator anIter = aBaseShapesList.cbegin(); anIter != aBaseShapesList.cend(); anIter++) {
+  std::string anError;
+  if(aCreationMethod == CREATION_METHOD_SIMPLE() ||
+      aCreationMethod == CREATION_METHOD_BINORMAL()) {
+    for(ListOfShape::const_iterator
+        anIter = aBaseShapesList.cbegin(); anIter != aBaseShapesList.cend(); anIter++) {
       std::shared_ptr<GeomAPI_Shape> aBaseShape = *anIter;
 
-      GeomAlgoAPI_Pipe aPipeAlgo = aCreationMethod == "simple" ? GeomAlgoAPI_Pipe(aBaseShape, aPathShape) :
-                                                                 GeomAlgoAPI_Pipe(aBaseShape, aPathShape, aBiNormal);
-
-      if(!aPipeAlgo.isDone()) {
-        setError("Error: Pipe algorithm failed.");
-        aResultIndex = 0;
-        break;
-      }
+      std::shared_ptr<GeomAlgoAPI_Pipe> aPipeAlgo(
+        aCreationMethod == CREATION_METHOD_SIMPLE() ? new GeomAlgoAPI_Pipe(aBaseShape,
+                                                                           aPathShape)
+                                                    : new GeomAlgoAPI_Pipe(aBaseShape,
+                                                                           aPathShape,
+                                                                           aBiNormal));
 
-      // Check if shape is valid
-      if(!aPipeAlgo.shape().get() || aPipeAlgo.shape()->isNull()) {
-        setError("Error: Resulting shape is Null.");
-        aResultIndex = 0;
-        break;
-      }
-      if(!aPipeAlgo.isValid()) {
-        setError("Error: Resulting shape is not valid.");
+      if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPipeAlgo, getKind(), anError)) {
+        setError(anError);
         aResultIndex = 0;
         break;
       }
 
-      storeResult(aBaseShape, aPipeAlgo, aResultIndex++);
+      storeResult(aBaseShape, aPathShape, aPipeAlgo, aResultIndex++);
     }
-  } else if(aCreationMethod == "locations") {
-    GeomAlgoAPI_Pipe aPipeAlgo = GeomAlgoAPI_Pipe(aBaseShapesList, aLocations, aPathShape);
+  } else if(aCreationMethod == CREATION_METHOD_LOCATIONS()) {
+    std::shared_ptr<GeomAlgoAPI_Pipe> aPipeAlgo(new GeomAlgoAPI_Pipe(aBaseShapesList,
+                                                                     aLocations,
+                                                                     aPathShape));
 
-    if(!aPipeAlgo.isDone()) {
-      setError("Error: Pipe algorithm failed.");
+    if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aPipeAlgo, getKind(), anError)) {
+      setError(anError);
       removeResults(0);
       return;
     }
 
-    // Check if shape is valid
-    if(!aPipeAlgo.shape().get() || aPipeAlgo.shape()->isNull()) {
-      setError("Error: Resulting shape is Null.");
-      removeResults(0);
-      return;
-    }
-    if(!aPipeAlgo.isValid()) {
-      setError("Error: Resulting shape is not valid.");
-      removeResults(0);
-      return;
-    }
-
-    storeResult(aBaseShapesList, aPipeAlgo, aResultIndex++);
+    storeResult(aBaseShapesList, aPathShape, aPipeAlgo, aResultIndex++);
   } else {
     setError("Error: Wrong creation method.");
     return;
@@ -227,28 +260,25 @@ void FeaturesPlugin_Pipe::execute()
   removeResults(aResultIndex);
 }
 
-//=================================================================================================
+//==================================================================================================
 void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
-                                      GeomAlgoAPI_Pipe& thePipeAlgo,
+                                      const std::shared_ptr<GeomAPI_Shape> thePathShape,
+                                      const std::shared_ptr<GeomAlgoAPI_Pipe> thePipeAlgo,
                                       const int theResultIndex)
 {
   // Create result body.
   ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex);
 
   // Store generated shape.
-  aResultBody->storeGenerated(theBaseShape, thePipeAlgo.shape());
+  aResultBody->storeGenerated(theBaseShape, thePipeAlgo->shape());
 
   // Store generated edges/faces.
   GeomAPI_Shape::ShapeType aBaseShapeType = theBaseShape->shapeType();
-  GeomAPI_Shape::ShapeType aShapeTypeToExplode;
-  int aGenTag = 1;
-  std::string aGenName = "Generated_";
+  GeomAPI_Shape::ShapeType aShapeTypeToExplode = GeomAPI_Shape::SHAPE;
 
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfSubShapes = thePipeAlgo.mapOfSubShapes();
   switch(aBaseShapeType) {
     case GeomAPI_Shape::VERTEX: {
       aShapeTypeToExplode = GeomAPI_Shape::VERTEX;
-      aGenName += "Edge";
       break;
     }
     case GeomAPI_Shape::EDGE:
@@ -256,55 +286,70 @@ void FeaturesPlugin_Pipe::storeResult(const std::shared_ptr<GeomAPI_Shape> theBa
       std::shared_ptr<GeomAPI_Vertex> aV1, aV2;
       GeomAlgoAPI_ShapeTools::findBounds(theBaseShape, aV1, aV2);
       ListOfShape aV1History, aV2History;
-      thePipeAlgo.generated(aV1, aV1History);
-      thePipeAlgo.generated(aV2, aV2History);
-      aResultBody->generated(aV1, aV1History.front(), aGenName + "Edge_1", aGenTag++);
-      aResultBody->generated(aV2, aV2History.front(), aGenName + "Edge_2", aGenTag++);
+      thePipeAlgo->generated(aV1, aV1History);
+      thePipeAlgo->generated(aV2, aV2History);
+      if(!aV1History.empty()) {
+        aResultBody->generated(aV1, aV1History.front());
+      }
+      if(!aV2History.empty()) {
+        aResultBody->generated(aV2, aV2History.front());
+      }
     }
     case GeomAPI_Shape::FACE:
     case GeomAPI_Shape::SHELL: {
       aShapeTypeToExplode = GeomAPI_Shape::EDGE;
-      aGenName += "Face";
       break;
     }
+    case GeomAPI_Shape::COMPOUND: {
+      aShapeTypeToExplode = GeomAPI_Shape::COMPOUND;
+    }
+    default:
+      return; // unsupported type of shape
   }
-  aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, theBaseShape, aShapeTypeToExplode, aGenTag++, aGenName, *aMapOfSubShapes.get());
+
+  if(aShapeTypeToExplode == GeomAPI_Shape::VERTEX ||
+      aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) {
+    aResultBody->loadGeneratedShapes(thePipeAlgo, theBaseShape, GeomAPI_Shape::VERTEX);
+  }
+  if(aShapeTypeToExplode == GeomAPI_Shape::EDGE ||
+      aShapeTypeToExplode == GeomAPI_Shape::COMPOUND) {
+    aResultBody->loadGeneratedShapes(thePipeAlgo, theBaseShape, GeomAPI_Shape::EDGE);
+  }
+  if (thePathShape.get())
+    aResultBody->loadGeneratedShapes(thePipeAlgo, thePathShape, GeomAPI_Shape::EDGE);
 
   // Store from shapes.
-  int aFromTag = aGenTag;
-  storeShapes(aResultBody, aBaseShapeType, aMapOfSubShapes, thePipeAlgo.fromShapes(), "From_", aFromTag);
+  storeShapes(aResultBody, aBaseShapeType, thePipeAlgo->fromShapes(), "From_");
 
   // Store to shapes.
-  int aToTag = aFromTag;
-  storeShapes(aResultBody, aBaseShapeType, aMapOfSubShapes, thePipeAlgo.toShapes(), "To_", aToTag);
+  storeShapes(aResultBody, aBaseShapeType, thePipeAlgo->toShapes(), "To_");
 
   setResult(aResultBody, theResultIndex);
 }
 
-//=================================================================================================
+//==================================================================================================
 void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes,
-                                      GeomAlgoAPI_Pipe& thePipeAlgo,
+                                      const std::shared_ptr<GeomAPI_Shape> thePathShape,
+                                      const std::shared_ptr<GeomAlgoAPI_Pipe> thePipeAlgo,
                                       const int theResultIndex)
 {
   // Create result body.
   ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex);
 
   // Store generated shape.
-  aResultBody->storeGenerated(theBaseShapes.front(), thePipeAlgo.shape());
+  aResultBody->storeGenerated(theBaseShapes.front(), thePipeAlgo->shape());
 
   // Store generated edges/faces.
-  int aGenTag = 1;
-  std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfSubShapes = thePipeAlgo.mapOfSubShapes();
-
-  for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin(); anIter != theBaseShapes.cend(); anIter++) {
+  for(ListOfShape::const_iterator anIter = theBaseShapes.cbegin();
+      anIter != theBaseShapes.cend();
+      ++anIter)
+  {
     GeomShapePtr aBaseShape = *anIter;
     GeomAPI_Shape::ShapeType aBaseShapeType = aBaseShape->shapeType();
-    GeomAPI_Shape::ShapeType aShapeTypeToExplode;
-    std::string aGenName = "Generated_";
+    GeomAPI_Shape::ShapeType aShapeTypeToExplode = GeomAPI_Shape::SHAPE;
     switch(aBaseShapeType) {
       case GeomAPI_Shape::VERTEX: {
         aShapeTypeToExplode = GeomAPI_Shape::VERTEX;
-        aGenName += "Edge";
         break;
       }
       case GeomAPI_Shape::EDGE:
@@ -312,40 +357,42 @@ void FeaturesPlugin_Pipe::storeResult(const ListOfShape& theBaseShapes,
         std::shared_ptr<GeomAPI_Vertex> aV1, aV2;
         GeomAlgoAPI_ShapeTools::findBounds(aBaseShape, aV1, aV2);
         ListOfShape aV1History, aV2History;
-        thePipeAlgo.generated(aV1, aV1History);
-        thePipeAlgo.generated(aV2, aV2History);
-        aResultBody->generated(aV1, aV1History.front(), aGenName + "Edge_1", aGenTag++);
-        aResultBody->generated(aV2, aV2History.front(), aGenName + "Edge_2", aGenTag++);
+        thePipeAlgo->generated(aV1, aV1History);
+        thePipeAlgo->generated(aV2, aV2History);
+        if (!aV1History.empty())
+          aResultBody->generated(aV1, aV1History.front());
+        if (!aV2History.empty())
+          aResultBody->generated(aV2, aV2History.front());
       }
       case GeomAPI_Shape::FACE:
       case GeomAPI_Shape::SHELL: {
         aShapeTypeToExplode = GeomAPI_Shape::EDGE;
-        aGenName += "Face";
         break;
       }
+      default:
+        return; // unsupported type of shape
     }
-    aResultBody->loadAndOrientGeneratedShapes(&thePipeAlgo, aBaseShape, aShapeTypeToExplode, aGenTag++, aGenName, *aMapOfSubShapes.get());
+    aResultBody->loadGeneratedShapes(thePipeAlgo, aBaseShape, aShapeTypeToExplode);
   }
 
+  if (thePathShape.get())
+    aResultBody->loadGeneratedShapes(thePipeAlgo, thePathShape, GeomAPI_Shape::EDGE);
+
   // Store from shapes.
-  int aFromTag = aGenTag;
-  storeShapes(aResultBody, theBaseShapes.front()->shapeType(), aMapOfSubShapes, thePipeAlgo.fromShapes(), "From", aFromTag);
+  storeShapes(aResultBody, theBaseShapes.front()->shapeType(), thePipeAlgo->fromShapes(), "From_");
 
   // Store to shapes.
-  int aToTag = aFromTag;
-  storeShapes(aResultBody, theBaseShapes.back()->shapeType(), aMapOfSubShapes, thePipeAlgo.toShapes(), "To", aToTag);
+  storeShapes(aResultBody, theBaseShapes.back()->shapeType(), thePipeAlgo->toShapes(), "To_");
 
 
   setResult(aResultBody, theResultIndex);
 }
 
-//=================================================================================================
+//==================================================================================================
 void FeaturesPlugin_Pipe::storeShapes(ResultBodyPtr theResultBody,
                                       const GeomAPI_Shape::ShapeType theBaseShapeType,
-                                      const std::shared_ptr<GeomAPI_DataMapOfShapeShape> theMapOfSubShapes,
                                       const ListOfShape& theShapes,
-                                      const std::string theName,
-                                      int& theTag)
+                                      const std::string theName)
 {
   GeomAPI_Shape::ShapeType aShapeTypeToExplore = GeomAPI_Shape::FACE;
   std::string aShapeTypeStr = "Face";
@@ -367,21 +414,44 @@ void FeaturesPlugin_Pipe::storeShapes(ResultBodyPtr theResultBody,
       aShapeTypeStr = "Face";
       break;
     }
+    case GeomAPI_Shape::COMPOUND: {
+      aShapeTypeToExplore = GeomAPI_Shape::COMPOUND;
+      break;
+    }
+    default:
+      return; // unsupported type of shape
   }
 
   // Store shapes.
   int aShapeIndex = 1;
-  std::string aName = theName + aShapeTypeStr;
+  int aFaceIndex = 1;
   for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
-    std::shared_ptr<GeomAPI_Shape> aShape = *anIt;
-    for(GeomAPI_ShapeExplorer anExp(aShape, aShapeTypeToExplore); anExp.more(); anExp.next()) {
-      std::shared_ptr<GeomAPI_Shape> aSubShape = anExp.current();
-      if(theMapOfSubShapes->isBound(aSubShape)) {
-        aSubShape = theMapOfSubShapes->find(aSubShape);
-      }
-      std::ostringstream aStr;
-      aStr << aName << "_" << aShapeIndex++;
-      theResultBody->generated(aSubShape, aStr.str(), theTag++);
+    GeomShapePtr aShape = *anIt;
+
+    if(aShapeTypeToExplore == GeomAPI_Shape::COMPOUND) {
+      std::string aName = theName + (aShape->shapeType() == GeomAPI_Shape::EDGE ? "Edge" : "Face");
+      storeSubShape(theResultBody, aShape,
+                    aShape->shapeType(),
+                    aName,
+                    aShape->shapeType() == GeomAPI_Shape::EDGE ? aShapeIndex : aFaceIndex);
+    } else {
+      std::string aName = theName + aShapeTypeStr;
+      storeSubShape(theResultBody, aShape, aShapeTypeToExplore, aName, aShapeIndex);
     }
   }
 }
+
+//==================================================================================================
+void storeSubShape(ResultBodyPtr theResultBody,
+                   const GeomShapePtr theShape,
+                   const GeomAPI_Shape::ShapeType theType,
+                   const std::string theName,
+                   int& theShapeIndex)
+{
+  for(GeomAPI_ShapeExplorer anExp(theShape, theType); anExp.more(); anExp.next()) {
+    GeomShapePtr aSubShape = anExp.current();
+    std::ostringstream aStr;
+    aStr << theName << "_" << theShapeIndex++;
+    theResultBody->generated(aSubShape, aStr.str());
+  }
+}