return ObjectPtr();
}
+const int Model_Document::index(std::shared_ptr<ModelAPI_Object> 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<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
+ std::list<std::shared_ptr<ModelAPI_Result> >::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;
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Object> 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<ModelAPI_Object> theObject);
//! Adds a new sub-document by the identifier, or returns existing one if it is already exist
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID);
virtual std::shared_ptr<ModelAPI_Object> 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<ModelAPI_Object> 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;