From f6df3321ef6745e8bc112bd38d5f97c8ef075d26 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 4 Mar 2020 13:14:31 +0300 Subject: [PATCH] Fix for the order of sketch sub-elements in the selection name. With new OCCT order of internal faces was changed, so, support any order. --- src/Model/Model_Document.cpp | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index cff3d1840..87e7e2f96 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -1718,6 +1718,52 @@ void Model_Document::changeNamingName(const std::string theOldName, } } +// returns true if names consist of the same sub-elements but with different order. +// Sub-elements are separated by "-" symbol. First part must be "Face", second at the same place. +static bool IsExchangedName(const TCollection_ExtendedString& theName1, + const TCollection_ExtendedString& theName2) +{ + static const TCollection_ExtendedString aSepStr("-"); + static const Standard_ExtString aSep = aSepStr.ToExtString(); + static const TCollection_ExtendedString aWireTail("_wire"); + if (theName1.Token(aSep, 1) != "Face" || theName2.Token(aSep, 1) != "Face") + return false; + if (theName1.Token(aSep, 2) != theName2.Token(aSep, 2)) + return false; + // Collect Map of the sub-elements of the first name + NCollection_Map aSubsMap; + TCollection_ExtendedString aWireSuffix; + int a = 3; + for (; true ; a++) { + TCollection_ExtendedString aToken = theName1.Token(aSep, a); + if (aToken.IsEmpty()) + break; + int aTailPos = aToken.Search(aWireTail); + if (aTailPos > 0) { + aWireSuffix = aToken.Split(aTailPos - 1); + } + aSubsMap.Add(aToken); + } + // check all subs in the second name are in the map + for (int a2 = 3; true; a2++) { + TCollection_ExtendedString aToken = theName2.Token(aSep, a2); + if (aToken.IsEmpty()) { + if (a2 != a) // number of sub-elements is not equal + return false; + break; + } + int aTailPos = aToken.Search(aWireTail); + if (aTailPos > 0) { + TCollection_ExtendedString aSuffix = aToken.Split(aTailPos - 1); + if (aWireSuffix != aSuffix) + return false; + } + if (!aSubsMap.Contains(aToken)) + return false; + } + return true; +} + TDF_Label Model_Document::findNamingName(std::string theName, ResultPtr theContext) { std::map >::iterator aFind = myNamingNames.find(theName); @@ -1749,13 +1795,19 @@ TDF_Label Model_Document::findNamingName(std::string theName, ResultPtr theConte } // copy aSubName to avoid incorrect further processing after its suffix cutting TCollection_ExtendedString aSubNameCopy(aSubName); + TDF_Label aFaceLabelWithExchangedSubs; // check also exchanged sub-elements of the name // 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() == aSubNameCopy) return aName->Label(); + if (aName->Get().Length() == aSubNameCopy.Length() && + IsExchangedName(aName->Get(), aSubNameCopy)) + aFaceLabelWithExchangedSubs = aName->Label(); } + if (!aFaceLabelWithExchangedSubs.IsNull()) + return aFaceLabelWithExchangedSubs; // If not found child label with the exact sub-name, then try to find compound with // such sub-name without suffix. Standard_Integer aSuffixPos = aSubNameCopy.SearchFromEnd('_'); -- 2.39.2