From 829f5e4f8e73d12e98dcf9aff006ed4c023bd7b7 Mon Sep 17 00:00:00 2001 From: dbv Date: Wed, 17 Oct 2018 18:29:21 +0300 Subject: [PATCH] Updated primitives shapes storing. --- .../ExchangePlugin_ImportFeature.cpp | 2 +- src/FeaturesPlugin/FeaturesPlugin_Recover.cpp | 2 +- src/Model/Model_BodyBuilder.cpp | 159 ++++++++---------- src/Model/Model_BodyBuilder.h | 17 +- src/ModelAPI/ModelAPI_BodyBuilder.h | 9 +- src/ModelAPI/ModelAPI_ResultBody.cpp | 15 +- src/ModelAPI/ModelAPI_ResultBody.h | 9 +- 7 files changed, 93 insertions(+), 120 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index ef70f9a66..b8b864acc 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -410,5 +410,5 @@ void ExchangePlugin_ImportFeature::loadNamingDS( int aTag(1); std::string aNameMS = "Shape"; - theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag); + theResultBody->loadFirstLevel(theGeomShape, aNameMS); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp index cf16130b9..ba575fbea 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Recover.cpp @@ -83,7 +83,7 @@ void FeaturesPlugin_Recover::execute() // like in import: forget any history int aTag(1); std::string aNameMS = "Shape"; - aResultBody->loadFirstLevel(aCopyAlgo.shape(), aNameMS, aTag); + aResultBody->loadFirstLevel(aCopyAlgo.shape(), aNameMS); setResult(aResultBody, aResultIndex); ++aResultIndex; diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index cc4f64f65..6d7fe12db 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -125,11 +125,7 @@ static bool isAlreadyStored(const TNaming_Builder* theBuilder, Model_BodyBuilder::Model_BodyBuilder(ModelAPI_Object* theOwner) : ModelAPI_BodyBuilder(theOwner), - myPrimitiveTag(PRIMITIVES_START_TAG), - myDividedIndex(1), - myVIndex(1), - myEIndex(1), - myFIndex(1) + myFreePrimitiveTag(PRIMITIVES_START_TAG) { } @@ -289,11 +285,7 @@ void Model_BodyBuilder::clean() myBuilders.clear(); // remove the old reference (if any) aLab.ForgetAttribute(TDF_Reference::GetID()); - myPrimitiveTag = PRIMITIVES_START_TAG; - myDividedIndex = 1; - myVIndex = 1; - myEIndex = 1; - myFIndex = 1; + myFreePrimitiveTag = PRIMITIVES_START_TAG; } Model_BodyBuilder::~Model_BodyBuilder() @@ -322,12 +314,12 @@ void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape, const std::string& theName) { TopoDS_Shape aShape = theNewShape->impl(); - builder(myPrimitiveTag)->Generated(aShape); + builder(myFreePrimitiveTag)->Generated(aShape); if (!theName.empty()) { - buildName(myPrimitiveTag, theName); + buildName(myFreePrimitiveTag, theName); } - ++myPrimitiveTag; + ++myFreePrimitiveTag; } void Model_BodyBuilder::generated(const GeomShapePtr& theOldShape, @@ -640,7 +632,7 @@ void loadGeneratedDangleShapes( //======================================================================= void Model_BodyBuilder::loadNextLevels(GeomShapePtr theShape, - const std::string& theName, int& theTag) + const std::string& theName) { if(theShape->isNull()) return; TopoDS_Shape aShape = theShape->impl(); @@ -648,11 +640,11 @@ void Model_BodyBuilder::loadNextLevels(GeomShapePtr theShape, if (aShape.ShapeType() == TopAbs_SOLID) { TopExp_Explorer expl(aShape, TopAbs_FACE); for (; expl.More(); expl.Next()) { - builder(theTag)->Generated(expl.Current()); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(expl.Current()); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } } else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) { @@ -662,11 +654,11 @@ void Model_BodyBuilder::loadNextLevels(GeomShapePtr theShape, if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) { TopExp_Explorer expl(aShape, TopAbs_FACE); for (; expl.More(); expl.Next()) { - builder(theTag)->Generated(expl.Current()); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(expl.Current()); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } } TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces; @@ -677,21 +669,21 @@ void Model_BodyBuilder::loadNextLevels(GeomShapePtr theShape, if (aLL.Extent() < 2) { if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeAndNeighbourFaces.FindKey(i)))) continue; - builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i)); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i)); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } else { TopTools_ListIteratorOfListOfShape anIter(aLL); const TopoDS_Face& aFace = TopoDS::Face(anIter.Value()); anIter.Next(); if(aFace.IsEqual(anIter.Value())) { - builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i)); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i)); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } } } @@ -699,40 +691,40 @@ void Model_BodyBuilder::loadNextLevels(GeomShapePtr theShape, TopTools_IndexedMapOfShape Edges; BRepTools::Map3DEdges(aShape, Edges); if (Edges.Extent() == 1) { - builder(theTag++)->Generated(Edges.FindKey(1)); + builder(myFreePrimitiveTag++)->Generated(Edges.FindKey(1)); TopExp_Explorer expl(aShape, TopAbs_VERTEX); for (; expl.More(); expl.Next()) { - builder(theTag)->Generated(expl.Current()); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(expl.Current()); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } } else { TopExp_Explorer expl(aShape, TopAbs_EDGE); for (; expl.More(); expl.Next()) { - builder(theTag)->Generated(expl.Current()); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(expl.Current()); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } // and load generated vertices. TopTools_DataMapOfShapeShape generated; if (getDangleShapes(aShape, TopAbs_EDGE, generated)) { - TNaming_Builder* pBuilder = builder(theTag++); + TNaming_Builder* pBuilder = builder(myFreePrimitiveTag++); loadGeneratedDangleShapes(aShape, TopAbs_EDGE, pBuilder); } } } else if (aShape.ShapeType() == TopAbs_EDGE) { TopExp_Explorer expl(aShape, TopAbs_VERTEX); for (; expl.More(); expl.Next()) { - builder(theTag)->Generated(expl.Current()); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(expl.Current()); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } } } @@ -795,8 +787,7 @@ int findAmbiguities(const TopoDS_Shape& theShapeIn, } //======================================================================= -void Model_BodyBuilder::loadFirstLevel( - GeomShapePtr theShape, const std::string& theName, int& theTag) +void Model_BodyBuilder::loadFirstLevel(GeomShapePtr theShape, const std::string& theName) { if(theShape->isNull()) return; TopoDS_Shape aShape = theShape->impl(); @@ -804,44 +795,42 @@ void Model_BodyBuilder::loadFirstLevel( if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) { TopoDS_Iterator itr(aShape); for (; itr.More(); itr.Next()) { - builder(theTag)->Generated(itr.Value()); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - if(!theName.empty()) buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(itr.Value()); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; if (itr.Value().ShapeType() == TopAbs_COMPOUND || itr.Value().ShapeType() == TopAbs_COMPSOLID) { GeomShapePtr itrShape(new GeomAPI_Shape()); itrShape->setImpl(new TopoDS_Shape(itr.Value())); - loadFirstLevel(itrShape, theName, theTag); + loadFirstLevel(itrShape, theName); } else { GeomShapePtr itrShape(new GeomAPI_Shape()); itrShape->setImpl(new TopoDS_Shape(itr.Value())); - loadNextLevels(itrShape, theName, theTag); + loadNextLevels(itrShape, theName); } } } else { GeomShapePtr itrShape(new GeomAPI_Shape()); itrShape->setImpl(new TopoDS_Shape(aShape)); - loadNextLevels(itrShape, theName, theTag); + loadNextLevels(itrShape, theName); } TopTools_ListOfShape aList; if(findAmbiguities(aShape, aList)) { TopTools_ListIteratorOfListOfShape it(aList); - for (; it.More(); it.Next(),theTag++) { - builder(theTag)->Generated(it.Value()); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); + for (; it.More(); it.Next(), ++myFreePrimitiveTag) { + builder(myFreePrimitiveTag)->Generated(it.Value()); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); } } } //======================================================================= -void Model_BodyBuilder::loadDisconnectedEdges( - GeomShapePtr theShape, const std::string& theName, int& theTag) +void Model_BodyBuilder::loadDisconnectedEdges(GeomShapePtr theShape, const std::string& theName) { if(theShape->isNull()) return; TopoDS_Shape aShape = theShape->impl(); @@ -890,12 +879,12 @@ void Model_BodyBuilder::loadDisconnectedEdges( if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++; if (aMatches == aList1.Extent()) { aC0=Standard_True; - builder(theTag)->Generated(anEdge2); + builder(myFreePrimitiveTag)->Generated(anEdge2); anEdgesToDelete.Add(anEdge2); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } } } @@ -905,17 +894,17 @@ void Model_BodyBuilder::loadDisconnectedEdges( edgeNaborFaces.UnBind(anEdge1); } if (aC0) { - builder(theTag)->Generated(anEdge1); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(anEdge1); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } } } void Model_BodyBuilder::loadDisconnectedVertexes(GeomShapePtr theShape, - const std::string& theName, int& theTag) + const std::string& theName) { if(theShape->isNull()) return; TopoDS_Shape aShape = theShape->impl(); @@ -946,11 +935,11 @@ void Model_BodyBuilder::loadDisconnectedVertexes(GeomShapePtr theShape, for (; itr.More(); itr.Next()) { const TopTools_ListOfShape& naborEdges = itr.Value(); if (naborEdges.Extent() < 2) { - builder(theTag)->Generated(itr.Key()); - TCollection_AsciiString aStr(theTag); - aName = theName + aStr.ToCString(); - buildName(theTag, aName); - theTag++; + builder(myFreePrimitiveTag)->Generated(itr.Key()); + TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1); + aName = theName + "_" + aStr.ToCString(); + buildName(myFreePrimitiveTag, aName); + ++myFreePrimitiveTag; } } } diff --git a/src/Model/Model_BodyBuilder.h b/src/Model/Model_BodyBuilder.h index 60e345fee..899fe1cc3 100755 --- a/src/Model/Model_BodyBuilder.h +++ b/src/Model/Model_BodyBuilder.h @@ -110,18 +110,15 @@ public: /// Loads shapes of the first level (to be used during shape import) MODEL_EXPORT virtual void loadFirstLevel(GeomShapePtr theShape, - const std::string& theName, - int& theTag); + const std::string& theName) override; /// Loads disconnected edges MODEL_EXPORT virtual void loadDisconnectedEdges(GeomShapePtr theShape, - const std::string& theName, - int& theTag); + const std::string& theName) override; /// Loads disconnected vetexes MODEL_EXPORT virtual void loadDisconnectedVertexes(GeomShapePtr theShape, - const std::string& theName, - int& theTag); + const std::string& theName) override; /// Removes the stored builders MODEL_EXPORT virtual ~Model_BodyBuilder(); @@ -143,17 +140,13 @@ protected: private: /// Loads shapes of the next level (to be used during shape import) void loadNextLevels(GeomShapePtr theShape, - const std::string& theName, int& theTag); + const std::string& theName); /// builds name for the shape kept at the specified tag void buildName(const int theTag, const std::string& theName); private: - int myPrimitiveTag; - int myDividedIndex; - int myVIndex; - int myEIndex; - int myFIndex; + int myFreePrimitiveTag; private: friend class Model_ResultBody; diff --git a/src/ModelAPI/ModelAPI_BodyBuilder.h b/src/ModelAPI/ModelAPI_BodyBuilder.h index 84e9400c7..b44e0d2b9 100755 --- a/src/ModelAPI/ModelAPI_BodyBuilder.h +++ b/src/ModelAPI/ModelAPI_BodyBuilder.h @@ -102,18 +102,15 @@ public: /// load shapes of the first level (to be used during shape import) virtual void loadFirstLevel(GeomShapePtr theShape, - const std::string& theName, - int& theTag) = 0; + const std::string& theName) = 0; /// load disconnected edges virtual void loadDisconnectedEdges(GeomShapePtr theShape, - const std::string& theName, - int& theTag) = 0; + const std::string& theName) = 0; /// load disconnected vetexes virtual void loadDisconnectedVertexes(GeomShapePtr theShape, - const std::string& theName, - int& theTag) = 0; + const std::string& theName) = 0; /// Returns true if the latest modification of this body in the naming history // is equal to the given shape diff --git a/src/ModelAPI/ModelAPI_ResultBody.cpp b/src/ModelAPI/ModelAPI_ResultBody.cpp index cdc10a703..806df516e 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.cpp +++ b/src/ModelAPI/ModelAPI_ResultBody.cpp @@ -149,24 +149,21 @@ void ModelAPI_ResultBody::loadGeneratedShapes(const GeomMakeShapePtr& theAlgo, } void ModelAPI_ResultBody::loadFirstLevel(GeomShapePtr theShape, - const std::string& theName, - int& theTag) + const std::string& theName) { - myBuilder->loadFirstLevel(theShape, theName, theTag); + myBuilder->loadFirstLevel(theShape, theName); } void ModelAPI_ResultBody::loadDisconnectedEdges(GeomShapePtr theShape, - const std::string& theName, - int& theTag) + const std::string& theName) { - myBuilder->loadDisconnectedEdges(theShape, theName, theTag); + myBuilder->loadDisconnectedEdges(theShape, theName); } void ModelAPI_ResultBody::loadDisconnectedVertexes(GeomShapePtr theShape, - const std::string& theName, - int& theTag) + const std::string& theName) { - myBuilder->loadDisconnectedVertexes(theShape, theName, theTag); + myBuilder->loadDisconnectedVertexes(theShape, theName); } bool ModelAPI_ResultBody::isConnectedTopology() diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index e7d13c8f8..aaf1bbecc 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -158,18 +158,15 @@ public: /// load shapes of the first level (to be used during shape import) MODELAPI_EXPORT virtual void loadFirstLevel(GeomShapePtr theShape, - const std::string& theName, - int& theTag); + const std::string& theName); /// load disconnected edges MODELAPI_EXPORT virtual void loadDisconnectedEdges(GeomShapePtr theShape, - const std::string& theName, - int& theTag); + const std::string& theName); /// load disconnected vetexes MODELAPI_EXPORT virtual void loadDisconnectedVertexes(GeomShapePtr theShape, - const std::string& theName, - int& theTag); + const std::string& theName); /// Returns true if the latest modification of this body in the naming history // is equal to the given shape -- 2.39.2