]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fixed naming for primitives
authordbv <dbv@opencascade.com>
Wed, 24 Oct 2018 14:02:14 +0000 (17:02 +0300)
committerdbv <dbv@opencascade.com>
Wed, 24 Oct 2018 14:02:39 +0000 (17:02 +0300)
src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp
src/Model/Model_BodyBuilder.cpp
src/Model/Model_BodyBuilder.h

index 5df959f46cf8d91e17607432bee00214179a13bf..4ddac51f8e867af90f5eae03150fd691db6eeede 100644 (file)
@@ -42,8 +42,7 @@
 static void storeSubShape(ResultBodyPtr theResultBody,
                           const GeomShapePtr theShape,
                           const GeomAPI_Shape::ShapeType theType,
-                          const std::string theName,
-                          int& theShapeIndex);
+                          const std::string& theName);
 
 //=================================================================================================
 void FeaturesPlugin_CompositeSketch::initCompositeSketchAttribtues(const int theInitFlags)
@@ -362,32 +361,18 @@ void FeaturesPlugin_CompositeSketch::storeShapes(ResultBodyPtr theResultBody,
   }
 
   // Store shapes.
-  int aShapeIndex = 1;
-  int aFaceIndex = 1;
   for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
     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);
+      storeSubShape(theResultBody, aShape, aShape->shapeType(), aName);
     } else {
       std::string aName = theName + aShapeTypeStr;
-      storeSubShape(theResultBody,
-                    aShape,
-                    aShapeTypeToExplore,
-                    aName,
-                    aShapeIndex);
+      storeSubShape(theResultBody, aShape, aShapeTypeToExplore, aName);
       if (theBaseShapeType == GeomAPI_Shape::WIRE) { // issue 2289: special names also for vertices
         aName = theName + "Vertex";
-        storeSubShape(theResultBody,
-                      aShape,
-                      GeomAPI_Shape::VERTEX,
-                      aName,
-                      aShapeIndex);
+        storeSubShape(theResultBody, aShape, GeomAPI_Shape::VERTEX, aName);
       }
     }
   }
@@ -396,13 +381,10 @@ void FeaturesPlugin_CompositeSketch::storeShapes(ResultBodyPtr theResultBody,
 void storeSubShape(ResultBodyPtr theResultBody,
                    const GeomShapePtr theShape,
                    const GeomAPI_Shape::ShapeType theType,
-                   const std::string theName,
-                   int& theShapeIndex)
+                   const std::string& theName)
 {
   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());
+    theResultBody->generated(aSubShape, theName);
   }
 }
index d4e81b0eb42961a146f7925b76e780dbec70a704..fbfd692a87964c6593802433ccc58443ab46e4b7 100755 (executable)
@@ -314,7 +314,23 @@ void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape,
   TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
   builder(myFreePrimitiveTag)->Generated(aShape);
   if (!theName.empty()) {
-    buildName(myFreePrimitiveTag, theName);
+    std::string aName = theName;
+    if (myPrimitivesNamesIndexMap.find(theName) != myPrimitivesNamesIndexMap.end()) {
+      IndexTags& anIndexTags = myPrimitivesNamesIndexMap.find(theName)->second;
+      aName += "_" + std::to_string(++(anIndexTags.index));
+      anIndexTags.tags.push_back(myFreePrimitiveTag);
+      if (anIndexTags.index == 2) {
+        buildName(anIndexTags.tags.front(), theName + "_1");
+      }
+    }
+    else {
+      IndexTags anIndexTags;
+      anIndexTags.index = 1;
+      anIndexTags.tags.push_back(myFreePrimitiveTag);
+      myPrimitivesNamesIndexMap[theName] = anIndexTags;
+    }
+
+    buildName(myFreePrimitiveTag, aName);
   }
   ++myFreePrimitiveTag;
 }
index 899fe1cc390e197c7a722aaac0a76da725a075c4..78aac03490d176709bc78b2f3ab1fc2cca75e6de 100755 (executable)
@@ -145,8 +145,15 @@ private:
   /// builds name for the shape kept at the specified tag
   void buildName(const int theTag, const std::string& theName);
 
+private:
+  struct IndexTags {
+    int index;
+    std::vector<int> tags;
+  };
+
 private:
   int myFreePrimitiveTag;
+  std::map<std::string, IndexTags> myPrimitivesNamesIndexMap;
 
 private:
   friend class Model_ResultBody;