From: szy Date: Thu, 18 Dec 2014 16:16:26 +0000 (+0300) Subject: Building Names. First part (to be debugged). X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FDev_0.6;p=modules%2Fshaper.git Building Names. First part (to be debugged). --- diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index 5a31c28f9..c0c00ca9b 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -127,10 +127,14 @@ void ExchangePlugin_ImportFeature::loadNamingDS( { //load result theResultBody->store(theGeomShape); + std::string aPrefix = data()->name() + "/"; int aTag(1); - theResultBody->loadFirstLevel(theGeomShape, aTag); - theResultBody->loadDisconnectedEdges(theGeomShape, aTag); - theResultBody->loadDisconnectedVertexes(theGeomShape, aTag); + std::string aNameMS = aPrefix + "Shape"; + theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag); + std::string aNameDE = aPrefix + "DiscEdges"; + theResultBody->loadDisconnectedEdges(theGeomShape, aNameDE, aTag); + std::string aNameDV = aPrefix + "DiscVertexes"; + theResultBody->loadDisconnectedVertexes(theGeomShape, aNameDV, aTag); } LibHandle ExchangePlugin_ImportFeature::loadImportPlugin(const std::string& theFormatName) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp index 025f63bab..cf64b0935 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp @@ -101,10 +101,10 @@ void FeaturesPlugin_Boolean::LoadNamingDS(GeomAlgoAPI_Boolean* theFeature, GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape(); theFeature->mapOfShapes(*aSubShapes); - + std::string aPrefix = data()->name() + "/"; // Put in DF modified faces - theResultBody->loadAndOrientModifiedShapes(theFeature->makeShape(), theObject, FACE, _MODIFY_TAG, *aSubShapes); - theResultBody->loadAndOrientModifiedShapes(theFeature->makeShape(), theTool, FACE, _MODIFY_TAG, *aSubShapes); + theResultBody->loadAndOrientModifiedShapes(theFeature->makeShape(), theObject, FACE, _MODIFY_TAG, aPrefix, *aSubShapes); + theResultBody->loadAndOrientModifiedShapes(theFeature->makeShape(), theTool, FACE, _MODIFY_TAG, aPrefix, *aSubShapes); //Put in DF deleted faces theResultBody->loadDeletedShapes(theFeature->makeShape(), theObject, FACE, _DELETED_TAG); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index cebc0bb44..1c5e57e55 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -101,17 +101,17 @@ void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape(); theFeature.mapOfShapes(*aSubShapes); - + std::string aPrefix = data()->name() + "/"; //Insert lateral face : Face from Edge - theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, *aSubShapes); + theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, aPrefix, *aSubShapes); //Insert bottom face std::shared_ptr aBottomFace = theFeature.firstShape(); if (!aBottomFace->isNull()) { if (aSubShapes->isBound(aBottomFace)) { aBottomFace = aSubShapes->find(aBottomFace); - } - theResultBody->generated(aBottomFace, _FIRST_TAG); + } + theResultBody->generated(aBottomFace, aPrefix, _FIRST_TAG); } @@ -122,7 +122,7 @@ void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, if (aSubShapes->isBound(aTopFace)) { aTopFace = aSubShapes->find(aTopFace); } - theResultBody->generated(aTopFace, _LAST_TAG); + theResultBody->generated(aTopFace, aPrefix, _LAST_TAG); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp index 96d52d77b..b439a9f1f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Placement.cpp @@ -124,8 +124,8 @@ void FeaturesPlugin_Placement::LoadNamingDS( GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape(); theFeature.mapOfShapes(*aSubShapes); - + std::string aPrefix = data()->name() + "/"; // put modifed faces in DF - theResultBody->loadAndOrientModifiedShapes(theFeature.makeShape(), theSlaveObject, _FACE, _MODIFIEDF_TAG, *aSubShapes); + theResultBody->loadAndOrientModifiedShapes(theFeature.makeShape(), theSlaveObject, _FACE, _MODIFIEDF_TAG, aPrefix, *aSubShapes); } diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 13db22108..f0e87ba38 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,7 @@ void Model_ResultBody::store(const std::shared_ptr& theShape) if (aShape.IsNull()) return; // null shape inside - aBuilder.Generated(aShape); + aBuilder.Generated(aShape); } } @@ -142,28 +143,39 @@ TNaming_Builder* Model_ResultBody::builder(const int theTag) return myBuilders[theTag]; } +void Model_ResultBody::buildName(const int theTag, const std::string& theName) +{ + std::string aName = data()->name() + "/" + theName; + TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str()); +} void Model_ResultBody::generated( - const std::shared_ptr& theNewShape, const int theTag) + const std::shared_ptr& theNewShape, const std::string& theName, const int theTag) { TopoDS_Shape aShape = theNewShape->impl(); builder(theTag)->Generated(aShape); + if(!theName.empty()) + buildName(theTag, theName); } void Model_ResultBody::generated(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theTag) + const std::shared_ptr& theNewShape, const std::string& theName, const int theTag) { TopoDS_Shape anOldShape = theOldShape->impl(); TopoDS_Shape aNewShape = theNewShape->impl(); builder(theTag)->Generated(anOldShape, aNewShape); + if(!theName.empty()) + buildName(theTag, theName); } void Model_ResultBody::modified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theTag) + const std::shared_ptr& theNewShape, const std::string& theName, const int theTag) { TopoDS_Shape anOldShape = theOldShape->impl(); TopoDS_Shape aNewShape = theNewShape->impl(); builder(theTag)->Modify(anOldShape, aNewShape); + if(!theName.empty()) + buildName(theTag, theName); } void Model_ResultBody::deleted(const std::shared_ptr& theOldShape, @@ -197,10 +209,12 @@ void Model_ResultBody::loadAndOrientModifiedShapes ( std::shared_ptr theShapeIn, const int theKindOfShape, const int theTag, + const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes) { TopoDS_Shape aShapeIn = theShapeIn->impl(); TopTools_MapOfShape aView; + bool isBuilt = theName.empty(); TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape); for (; aShapeExplorer.More(); aShapeExplorer.Next ()) { const TopoDS_Shape& aRoot = aShapeExplorer.Current (); @@ -216,8 +230,11 @@ void Model_ResultBody::loadAndOrientModifiedShapes ( std::shared_ptr aMapShape(theSubShapes.find(*anIt)); aNewShape.Orientation(aMapShape->impl().Orientation()); } - if (!aRoot.IsSame (aNewShape)) + if (!aRoot.IsSame (aNewShape)) { builder(theTag)->Modify(aRoot,aNewShape); + if(!isBuilt) + buildName(theTag, theName); + } } } } @@ -227,10 +244,12 @@ void Model_ResultBody::loadAndOrientGeneratedShapes ( std::shared_ptr theShapeIn, const int theKindOfShape, const int theTag, + const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes) { TopoDS_Shape aShapeIn = theShapeIn->impl(); TopTools_MapOfShape aView; + bool isBuilt = theName.empty(); TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape); for (; aShapeExplorer.More(); aShapeExplorer.Next ()) { const TopoDS_Shape& aRoot = aShapeExplorer.Current (); @@ -246,8 +265,11 @@ void Model_ResultBody::loadAndOrientGeneratedShapes ( std::shared_ptr aMapShape(theSubShapes.find(*anIt)); aNewShape.Orientation(aMapShape->impl().Orientation()); } - if (!aRoot.IsSame (aNewShape)) + if (!aRoot.IsSame (aNewShape)) { builder(theTag)->Generated(aRoot,aNewShape); + if(!isBuilt) + buildName(theTag, theName); + } } } } @@ -287,14 +309,18 @@ void loadGeneratedDangleShapes( //======================================================================= void Model_ResultBody::loadNextLevels(std::shared_ptr theShape, - int& theTag) + const std::string& theName, int& theTag) { if(theShape->isNull()) return; TopoDS_Shape aShape = theShape->impl(); + std::string aName; if (aShape.ShapeType() == TopAbs_SOLID) { TopExp_Explorer expl(aShape, TopAbs_FACE); for (; expl.More(); expl.Next()) - builder(++theTag)->Generated(expl.Current()); + builder(++theTag)->Generated(expl.Current()); + TCollection_AsciiString aStr(theTag); + aName = theName + aStr.ToCString(); + buildName(theTag, aName); } else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) { // load faces and all the free edges @@ -302,8 +328,12 @@ void Model_ResultBody::loadNextLevels(std::shared_ptr theShape, TopExp::MapShapes(aShape, TopAbs_FACE, Faces); if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) { TopExp_Explorer expl(aShape, TopAbs_FACE); - for (; expl.More(); expl.Next()) + for (; expl.More(); expl.Next()) { builder(++theTag)->Generated(expl.Current()); + TCollection_AsciiString aStr(theTag); + aName = theName + aStr.ToCString(); + buildName(theTag, aName); + } } TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces; TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces); @@ -311,13 +341,19 @@ void Model_ResultBody::loadNextLevels(std::shared_ptr theShape, { const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i); if (aLL.Extent() < 2) { - builder(++theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i)); + builder(++theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i)); + TCollection_AsciiString aStr(theTag); + aName = theName + aStr.ToCString(); + buildName(theTag, aName); } 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); } } } @@ -329,11 +365,17 @@ void Model_ResultBody::loadNextLevels(std::shared_ptr theShape, 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); } } 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); } // and load generated vertices. TopTools_DataMapOfShapeShape generated; @@ -347,41 +389,49 @@ void Model_ResultBody::loadNextLevels(std::shared_ptr theShape, 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); } } } //======================================================================= void Model_ResultBody::loadFirstLevel( - std::shared_ptr theShape, int& theTag) + std::shared_ptr theShape, const std::string& theName, int& theTag) { - if(theShape->isNull()) return; - TopoDS_Shape aShape = theShape->impl(); + if(theShape->isNull()) return; + TopoDS_Shape aShape = theShape->impl(); + std::string aName; if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) { TopoDS_Iterator itr(aShape); for (; itr.More(); itr.Next()) { - builder(++theTag)->Generated(itr.Value()); + builder(++theTag)->Generated(itr.Value()); + TCollection_AsciiString aStr(theTag); + aName = theName + aStr.ToCString(); + buildName(theTag, aName); + if(!theName.empty()) buildName(theTag, aName); if (itr.Value().ShapeType() == TopAbs_COMPOUND || itr.Value().ShapeType() == TopAbs_COMPSOLID) { std::shared_ptr itrShape(new GeomAPI_Shape()); itrShape->setImpl(new TopoDS_Shape(itr.Value())); - loadFirstLevel(itrShape, theTag); + loadFirstLevel(itrShape, theName, theTag); } else { std::shared_ptr itrShape(new GeomAPI_Shape()); - itrShape->setImpl(new TopoDS_Shape(itr.Value())); - loadNextLevels(itrShape, theTag); + itrShape->setImpl(new TopoDS_Shape(itr.Value())); + loadNextLevels(itrShape, theName, theTag); } } } else { std::shared_ptr itrShape(new GeomAPI_Shape()); itrShape->setImpl(new TopoDS_Shape(aShape)); - loadNextLevels(itrShape, theTag); + loadNextLevels(itrShape, theName, theTag); } } //======================================================================= void Model_ResultBody::loadDisconnectedEdges( - std::shared_ptr theShape, int& theTag) + std::shared_ptr theShape, const std::string& theName, int& theTag) { if(theShape->isNull()) return; TopoDS_Shape aShape = theShape->impl(); @@ -409,6 +459,7 @@ void Model_ResultBody::loadDisconnectedEdges( TopTools_MapOfShape anEdgesToDelete; TopExp_Explorer anEx(aShape,TopAbs_EDGE); + std::string aName; for(;anEx.More();anEx.Next()) { Standard_Boolean aC0 = Standard_False; TopoDS_Shape anEdge1 = anEx.Current(); @@ -429,8 +480,11 @@ void Model_ResultBody::loadDisconnectedEdges( if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++; if (aMatches == aList1.Extent()) { aC0=Standard_True; - builder(++theTag)->Generated(anEdge2); + builder(++theTag)->Generated(anEdge2); anEdgesToDelete.Add(anEdge2); + TCollection_AsciiString aStr(theTag); + aName = theName + aStr.ToCString(); + buildName(theTag, aName); } } } @@ -439,12 +493,16 @@ void Model_ResultBody::loadDisconnectedEdges( edgeNaborFaces.UnBind(itDelete.Key()); edgeNaborFaces.UnBind(anEdge1); } - if (aC0) - builder(++theTag)->Generated(anEdge1); + if (aC0) { + builder(++theTag)->Generated(anEdge1); + TCollection_AsciiString aStr(theTag); + aName = theName + aStr.ToCString(); + buildName(theTag, aName); + } } } -void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr theShape, int& theTag) +void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr theShape, const std::string& theName, int& theTag) { if(theShape->isNull()) return; TopoDS_Shape aShape = theShape->impl(); @@ -470,11 +528,15 @@ void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr t } } } - + std::string aName; TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborFaces); for (; itr.More(); itr.Next()) { const TopTools_ListOfShape& naborFaces = itr.Value(); - if (naborFaces.Extent() < 3) - builder(++theTag)->Generated(itr.Key()); + if (naborFaces.Extent() < 3) { + builder(++theTag)->Generated(itr.Key()); + TCollection_AsciiString aStr(theTag); + aName = theName + aStr.ToCString(); + buildName(theTag, aName); + } } } \ No newline at end of file diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index 28f268d83..c1ac0b7cd 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -44,19 +44,19 @@ public: /// Records the subshape newShape which was generated during a topological construction. /// As an example, consider the case of a face generated in construction of a box. MODEL_EXPORT virtual void generated(const std::shared_ptr& theNewShape, - const int theTag = 1); + const std::string& theName, const int theTag = 1); /// Records the shape newShape which was generated from the shape oldShape during a topological /// construction. As an example, consider the case of a face generated from an edge in /// construction of a prism. MODEL_EXPORT virtual void generated(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theTag = 1); + const std::shared_ptr& theNewShape, const std::string& theName, const int theTag = 1); /// Records the shape newShape which is a modification of the shape oldShape. /// As an example, consider the case of a face split or merged in a Boolean operation. MODEL_EXPORT virtual void modified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theTag = 1); + const std::shared_ptr& theNewShape, const std::string& theName, const int theTag = 1); /// Records the shape oldShape which was deleted from the current label. /// As an example, consider the case of a face removed by a Boolean operation. @@ -74,6 +74,7 @@ public: std::shared_ptr theShapeIn, const int theKindOfShape, const int theTag, + const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes); /// load and orient generated shapes MODEL_EXPORT virtual void loadAndOrientGeneratedShapes ( @@ -81,16 +82,17 @@ public: std::shared_ptr theShapeIn, const int theKindOfShape, const int theTag, + const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes); /// Loads shapes of the first level (to be used during shape import) - MODEL_EXPORT virtual void loadFirstLevel(std::shared_ptr theShape, int& theTag); + MODEL_EXPORT virtual void loadFirstLevel(std::shared_ptr theShape, const std::string& theName, int& theTag); /// Loads disconnected edges - MODEL_EXPORT virtual void loadDisconnectedEdges(std::shared_ptr theShape, int& theTag); + MODEL_EXPORT virtual void loadDisconnectedEdges(std::shared_ptr theShape, const std::string& theName, int& theTag); /// Loads disconnected vetexes - MODEL_EXPORT virtual void loadDisconnectedVertexes(std::shared_ptr theShape, int& theTag); + MODEL_EXPORT virtual void loadDisconnectedVertexes(std::shared_ptr theShape, const std::string& theName, int& theTag); /// Removes the stored builders MODEL_EXPORT virtual ~Model_ResultBody(); @@ -107,7 +109,10 @@ protected: private: /// Loads shapes of the next level (to be used during shape import) - void loadNextLevels(std::shared_ptr theShape, int& theTag); + void loadNextLevels(std::shared_ptr theShape, const std::string& theName, int& theTag); + + /// builds name for the shape kept at the specified tag + void buildName(const int theTag, const std::string& theName); friend class Model_Document; }; diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index 98350ce37..6ffae24d6 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -50,18 +50,18 @@ public: /// Records the subshape newShape which was generated during a topological construction. /// As an example, consider the case of a face generated in construction of a box. virtual void generated( - const std::shared_ptr& theNewShape, const int theTag = 1) = 0; + const std::shared_ptr& theNewShape, const std::string& theName, const int theTag = 1) = 0; /// Records the shape newShape which was generated from the shape oldShape during a topological /// construction. As an example, consider the case of a face generated from an edge in /// construction of a prism. virtual void generated(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theTag = 1) = 0; + const std::shared_ptr& theNewShape, const std::string& theName, const int theTag = 1) = 0; /// Records the shape newShape which is a modification of the shape oldShape. /// As an example, consider the case of a face split or merged in a Boolean operation. virtual void modified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theTag = 1) = 0; + const std::shared_ptr& theNewShape, const std::string& theName, const int theTag = 1) = 0; /// Records the shape oldShape which was deleted from the current label. /// As an example, consider the case of a face removed by a Boolean operation. @@ -79,6 +79,7 @@ public: std::shared_ptr theShapeIn, const int theKindOfShape, const int theTag, + const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes) = 0; /// load and orient generated shapes virtual void loadAndOrientGeneratedShapes ( @@ -86,16 +87,17 @@ public: std::shared_ptr theShapeIn, const int theKindOfShape, const int theTag, + const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes) = 0; /// load shapes of the first level (to be used during shape import) - virtual void loadFirstLevel(std::shared_ptr theShape, int& theTag) = 0; + virtual void loadFirstLevel(std::shared_ptr theShape, const std::string& theName, int& theTag) = 0; /// load disconnected edges - virtual void loadDisconnectedEdges(std::shared_ptr theShape, int& theTag) = 0; + virtual void loadDisconnectedEdges(std::shared_ptr theShape, const std::string& theName, int& theTag) = 0; /// load disconnected vetexes - virtual void loadDisconnectedVertexes(std::shared_ptr theShape, int& theTag) = 0; + virtual void loadDisconnectedVertexes(std::shared_ptr theShape, const std::string& theName,int& theTag) = 0; protected: };