From 9b2d78cb08922282d21bc87f418d03824653ce3f Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 30 Dec 2014 11:18:07 +0300 Subject: [PATCH] Added findByName method for naming issue --- src/Model/Model_Document.cpp | 20 ++++++++++++++++++++ src/Model/Model_Document.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 1f5eedfe9..7b1b6db85 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -1130,3 +1130,23 @@ TDF_Label Model_Document::findNamingName(std::string theName) return TDF_Label(); // not found return aFind->second; } + +ResultPtr Model_Document::findByName(const std::string theName) +{ + NCollection_DataMap::Iterator anObjIter(myObjs); + for(; anObjIter.More(); anObjIter.Next()) { + FeaturePtr& aFeature = anObjIter.ChangeValue(); + if (!aFeature) // may be on close + continue; + const std::list >& aResults = aFeature->results(); + std::list >::const_iterator aRIter = aResults.begin(); + for (; aRIter != aResults.cend(); aRIter++) { + if (aRIter->get() && (*aRIter)->data() && (*aRIter)->data()->isValid() && + (*aRIter)->data()->name() == theName) { + return *aRIter; + } + } + } + // not found + return ResultPtr(); +} diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 6aa9ef4e8..ad309ce94 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -140,6 +140,9 @@ class Model_Document : public ModelAPI_Document void addNamingName(const TDF_Label theLabel, std::string theName); //! 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 + //! selection by name. + ResultPtr findByName(const std::string theName); protected: -- 2.39.2