From: mpv Date: Tue, 5 May 2015 09:57:13 +0000 (+0300) Subject: Added "index" method for ObjectBrowser internal logic and better access X-Git-Tag: V_1.2.0~173 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=af075dd0bac3d02d8a306ecf0b5377baf7a8c2f0;p=modules%2Fshaper.git Added "index" method for ObjectBrowser internal logic and better access --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 836e289b2..0535ef7f2 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -877,6 +877,45 @@ std::shared_ptr Model_Document::objectByName( return ObjectPtr(); } +const int Model_Document::index(std::shared_ptr theObject) +{ + const std::string aGroupName = theObject->groupName(); + if (aGroupName == 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 == theObject) + return anIndex; + if (aFeature->isInHistory()) + anIndex++; + } + } 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 == theObject) + return anIndex; + if ((*aRIter)->groupName() == aGroupName) { + bool isIn = (*aRIter)->isInHistory() && !(*aRIter)->isConcealed(); + if (isIn) { + anIndex++; + } + } + } + } + } + // not found + return -1; +} + 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 453422ffc..a307e7796 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -106,6 +106,10 @@ class Model_Document : public ModelAPI_Document MODEL_EXPORT virtual std::shared_ptr objectByName( const std::string& theGroupID, const std::string& theName); + //! Returns the object index in the group. Object must be visible. Otherwise returns -1. + //! \param theObject object of this document + //! \returns index started from zero, or -1 if object is invisible or belongs to another document + MODEL_EXPORT virtual const int index(std::shared_ptr theObject); //! 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 8093123bd..9fe19db66 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -79,6 +79,11 @@ public: virtual std::shared_ptr objectByName(const std::string& theGroupID, const std::string& theName) = 0; + //! Returns the object index in the group. Object must be visible. Otherwise returns -1. + //! \param theObject object of this document + //! \returns index started from zero, or -1 if object is invisible or belongs to another document + virtual const int index(std::shared_ptr theObject) = 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;