]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make the same-name results distributed in time recognized correctly in loading of...
authormpv <mpv@opencascade.com>
Fri, 3 Nov 2017 11:48:39 +0000 (14:48 +0300)
committermpv <mpv@opencascade.com>
Fri, 3 Nov 2017 11:49:01 +0000 (14:49 +0300)
src/Model/Model_Data.cpp
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_SelectionNaming.cpp

index 867614ca3fb39f5668446b30e6af1b83ef37a38a..e9e55e9905ff79c78afcb7c82672b6f3e0cbef3f 100644 (file)
@@ -134,7 +134,7 @@ void Model_Data::setName(const std::string& theName)
     ModelAPI_ObjectRenamedMessage::send(myObject, anOldName, theName, this);
   if (isModified && myObject && myObject->document()) {
     std::dynamic_pointer_cast<Model_Document>(myObject->document())->
-      changeNamingName(anOldName, theName);
+      changeNamingName(anOldName, theName, myLab);
   }
 #ifdef DEBUG_NAMES
   myObject->myName = theName;
index 03959c2ff7ea4eecc838ee652f242609828701e4..26329090fe34a0bc8f15b4ff40004d425fcdf269 100755 (executable)
@@ -1273,23 +1273,35 @@ Standard_Boolean IsEqual(const TDF_Label& theLab1, const TDF_Label& theLab2)
 
 void Model_Document::addNamingName(const TDF_Label theLabel, std::string theName)
 {
-  myNamingNames[theName] = theLabel;
+  myNamingNames[theName].push_back(theLabel);
 }
 
-void Model_Document::changeNamingName(const std::string theOldName, const std::string theNewName)
+void Model_Document::changeNamingName(const std::string theOldName,
+                                      const std::string theNewName,
+                                      const TDF_Label& theLabel)
 {
-  std::map<std::string, TDF_Label>::iterator aFind = myNamingNames.find(theOldName);
+  std::map<std::string, std::list<TDF_Label> >::iterator aFind = myNamingNames.find(theOldName);
   if (aFind != myNamingNames.end()) {
-    myNamingNames[theNewName] = aFind->second;
-    myNamingNames.erase(theOldName);
+    std::list<TDF_Label>::iterator aLabIter = aFind->second.begin();
+    for(; aLabIter != aFind->second.end(); aLabIter++) {
+      if (theLabel.IsEqual(*aLabIter)) { // found the label
+        myNamingNames[theNewName].push_back(theLabel);
+        if (aFind->second.size() == 1) { // only one element, so, just change the name
+          myNamingNames.erase(theOldName);
+        } else { // remove from the list
+          aFind->second.erase(aLabIter);
+        }
+        return;
+      }
+    }
   }
 }
 
 TDF_Label Model_Document::findNamingName(std::string theName)
 {
-  std::map<std::string, TDF_Label>::iterator aFind = myNamingNames.find(theName);
+  std::map<std::string, std::list<TDF_Label> >::iterator aFind = myNamingNames.find(theName);
   if (aFind != myNamingNames.end()) {
-    return aFind->second;
+    return *(aFind->second.rbegin());
   }
   // not found exact name, try to find by sub-components
   std::string::size_type aSlash = theName.rfind('/');
@@ -1298,24 +1310,28 @@ TDF_Label Model_Document::findNamingName(std::string theName)
     aFind = myNamingNames.find(anObjName);
     if (aFind != myNamingNames.end()) {
       TCollection_ExtendedString aSubName(theName.substr(aSlash + 1).c_str());
-      // searching sub-labels with this name
-      TDF_ChildIDIterator aNamesIter(aFind->second, TDataStd_Name::GetID(), Standard_True);
-      for(; aNamesIter.More(); aNamesIter.Next()) {
-        Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(aNamesIter.Value());
-        if (aName->Get() == aSubName)
-          return aName->Label();
-      }
-      // If not found child label with the exact sub-name, then try to find compound with
-      // such sub-name without suffix.
-      Standard_Integer aSuffixPos = aSubName.SearchFromEnd('_');
-      if (aSuffixPos != -1 && aSuffixPos != aSubName.Length()) {
-        TCollection_ExtendedString anIndexStr = aSubName.Split(aSuffixPos);
-        aSubName.Remove(aSuffixPos);
-        aNamesIter.Initialize(aFind->second, TDataStd_Name::GetID(), Standard_True);
+      // iterate all possible same-named labels starting from the last one (the recent)
+      std::list<TDF_Label>::reverse_iterator aLabIter = aFind->second.rbegin();
+      for(; aLabIter != aFind->second.rend(); aLabIter++) {
+        // searching sub-labels with this name
+        TDF_ChildIDIterator aNamesIter(*aLabIter, TDataStd_Name::GetID(), Standard_True);
         for(; aNamesIter.More(); aNamesIter.Next()) {
           Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(aNamesIter.Value());
-          if (aName->Get() == aSubName) {
+          if (aName->Get() == aSubName)
             return aName->Label();
+        }
+        // If not found child label with the exact sub-name, then try to find compound with
+        // such sub-name without suffix.
+        Standard_Integer aSuffixPos = aSubName.SearchFromEnd('_');
+        if (aSuffixPos != -1 && aSuffixPos != aSubName.Length()) {
+          TCollection_ExtendedString anIndexStr = aSubName.Split(aSuffixPos);
+          aSubName.Remove(aSuffixPos);
+          aNamesIter.Initialize(*aLabIter, TDataStd_Name::GetID(), Standard_True);
+          for(; aNamesIter.More(); aNamesIter.Next()) {
+            Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(aNamesIter.Value());
+            if (aName->Get() == aSubName) {
+              return aName->Label();
+            }
           }
         }
       }
index 67e48301e9fca54d78df0138c05b2875d51de8c8..6114e759b03422ec0bd2c8083573683a23c43431 100644 (file)
@@ -206,7 +206,8 @@ class Model_Document : public ModelAPI_Document
   //! Registers the name of the shape for the topological naming needs
   void addNamingName(const TDF_Label theLabel, std::string theName);
   //! Updates the name of some object
-  void changeNamingName(std::string theOldName, const std::string theNewName);
+  void changeNamingName(std::string theOldName, const std::string theNewName,
+    const TDF_Label& theLabel);
   //! Returns the label, keeper of the name  for the topological naming needs
   TDF_Label findNamingName(std::string theName);
   //! Returns the result by name of the result (names of results must be unique, used for naming
@@ -351,7 +352,8 @@ class Model_Document : public ModelAPI_Document
   std::list<Transaction> myRedos;
 
   //! Optimization for finding the shape-label by topological naming names
-  std::map<std::string, TDF_Label> myNamingNames;
+  //! The name -> list of labels where this name is appeared (the last created name is last here)
+  std::map<std::string, std::list<TDF_Label> > myNamingNames;
   //! If it is true, features are not executed on update (on abort, undo, redo)
   bool myExecuteFeatures;
 
index 89c044cb4ff24e32e9ba24f64c91cdbbabce1347..11473dcaa928360a2336afdc56906a22464d53b3 100644 (file)
@@ -83,7 +83,7 @@ std::string Model_SelectionNaming::getShapeName(
         // indexes are added to sub-shapes not primitives
         // (primitives must not be located at the same label)
         if(!aName.empty() && aNS->Evolution() != TNaming_PRIMITIVE && isNeedContextName) {
-          const TDF_Label& aLabel = aNS->Label();//theDoc->findNamingName(aName);
+          const TDF_Label& aLabel = aNS->Label();
           static const std::string aPostFix("_");
           TNaming_Iterator anItL(aNS);
           for(int i = 1; anItL.More(); anItL.Next(), i++) {
@@ -472,9 +472,6 @@ const TopoDS_Shape findFaceByName(
   const std::string& theSubShapeName, std::shared_ptr<Model_Document> theDoc)
 {
   TopoDS_Shape aFace;
-  //std::string::size_type n, nb = theSubShapeName.rfind('/');
-  //if (nb == std::string::npos) nb = 0;
-  //std::string aSubString = theSubShapeName.substr(nb + 1);
   std::string aSubString = theSubShapeName;
 
   TDF_Label aLabel = theDoc->findNamingName(aSubString);