From: mpv Date: Tue, 31 Mar 2015 07:11:14 +0000 (+0300) Subject: Added objectByName method X-Git-Tag: V_1.1.0~70^2~4^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0b47a7b7869366c043e39d6097bf6c71c99e8318;p=modules%2Fshaper.git Added objectByName method --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 0d5a39941..c2da1a479 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -821,6 +821,37 @@ ObjectPtr Model_Document::object(const std::string& theGroupID, const int theInd return ObjectPtr(); } +std::shared_ptr Model_Document::objectByName( + const std::string& theGroupID, const std::string& theName) +{ + if (theGroupID == ModelAPI_Feature::group()) { + int anIndex = 0; + TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID()); + for (; aLabIter.More(); aLabIter.Next()) { + TDF_Label aFLabel = aLabIter.Value()->Label(); + FeaturePtr aFeature = feature(aFLabel); + if (aFeature && aFeature->name() == theName) + return aFeature; + } + } else { + // comment must be in any feature: it is kind + int anIndex = 0; + TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID()); + for (; aLabIter.More(); aLabIter.Next()) { + TDF_Label aFLabel = aLabIter.Value()->Label(); + FeaturePtr aFeature = feature(aFLabel); + const std::list >& aResults = aFeature->results(); + std::list >::const_iterator aRIter = aResults.begin(); + for (; aRIter != aResults.cend(); aRIter++) { + if ((*aRIter)->groupName() == theGroupID && (*aRIter)->data()->name() == theName) + return *aRIter; + } + } + } + // not found + return ObjectPtr(); +} + int Model_Document::size(const std::string& theGroupID, const bool theHidden) { int aResult = 0; diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 7ec9e073e..ef7c98a10 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -98,6 +98,14 @@ class Model_Document : public ModelAPI_Document //! \param theLabel base label of the object MODEL_EXPORT virtual ObjectPtr object(TDF_Label theLabel); + //! Returns the first found object in the group by the object name + //! \param theGroupID group that contains an object + //! \param theName name of the object to search + //! \returns null if such object is not found + MODEL_EXPORT virtual std::shared_ptr objectByName( + const std::string& theGroupID, const std::string& theName); + + //! Adds a new sub-document by the identifier, or returns existing one if it is already exist MODEL_EXPORT virtual std::shared_ptr subDocument(std::string theDocID); diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 9ce3ccd48..cbb1d5b01 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -71,6 +71,13 @@ public: const int theIndex, const bool theHidden = false) = 0; + //! Returns the first found object in the group by the object name + //! \param theGroupID group that contains an object + //! \param theName name of the object to search + //! \returns null if such object is not found + virtual std::shared_ptr objectByName(const std::string& theGroupID, + const std::string& theName) = 0; + //! Returns the number of objects in the group of objects //! If theHidden is true, it counts also the features that are not in tree virtual int size(const std::string& theGroupID, const bool theHidden = false) = 0;