From 23ba0f447aa677ed1b87347be5ab2693d3b553bb Mon Sep 17 00:00:00 2001 From: dbv Date: Wed, 24 Oct 2018 17:02:14 +0300 Subject: [PATCH] Fixed naming for primitives --- .../FeaturesPlugin_CompositeSketch.cpp | 30 ++++--------------- src/Model/Model_BodyBuilder.cpp | 18 ++++++++++- src/Model/Model_BodyBuilder.h | 7 +++++ 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index 5df959f46..4ddac51f8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -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); } } diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index d4e81b0eb..fbfd692a8 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -314,7 +314,23 @@ void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape, TopoDS_Shape aShape = theNewShape->impl(); 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; } diff --git a/src/Model/Model_BodyBuilder.h b/src/Model/Model_BodyBuilder.h index 899fe1cc3..78aac0349 100755 --- a/src/Model/Model_BodyBuilder.h +++ b/src/Model/Model_BodyBuilder.h @@ -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 tags; + }; + private: int myFreePrimitiveTag; + std::map myPrimitivesNamesIndexMap; private: friend class Model_ResultBody; -- 2.39.2