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('/');
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();
+ }
}
}
}
//! 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
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;
// 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++) {
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);