return myObjs->findFolder(theFeatures, true);
}
+std::shared_ptr<ModelAPI_Folder> Model_Document::findContainingFolder(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ int& theIndexInFolder)
+{
+ return myObjs->findContainingFolder(theFeature, theIndexInFolder);
+}
+
bool Model_Document::moveToFolder(
const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
const std::shared_ptr<ModelAPI_Folder>& theFolder)
//! \return Empty pointer if there is no applicable folder
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Folder> findFolderBelow(
const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures);
+ //! Search a folder containing the given feature.
+ //! Addtionally calculates a zero-based index of the feature in this folder.
+ //! \param theFeature feature to search
+ //! \param theIndexInFolder zero-based index in the folder or -1 if the feature is top-level.
+ //! \return the folder containing the feature or empty pointer if the feature is top-level.
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Folder> findContainingFolder(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ int& theIndexInFolder);
//! Add a list of features to the folder. The correctness of the adding is not performed
//! (such checks have been done in corresponding find.. method).
//! \return \c true if the movement is successfull
return true;
}
+FolderPtr Model_Objects::findContainingFolder(const FeaturePtr& theFeature, int& theIndexInFolder)
+{
+ // search the label in the list of references
+ TDF_Label aFeaturesLab = featuresLabel();
+ Handle(TDataStd_ReferenceArray) aRefs;
+ if (!aFeaturesLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
+ return FolderPtr(); // no reference array (something is wrong)
+
+ std::shared_ptr<Model_Data> aData =
+ std::static_pointer_cast<Model_Data>(theFeature->data());
+ if (!aData || !aData->isValid())
+ return FolderPtr();
+ TDF_Label aLabelToFind = aData->label().Father();
+
+ theIndexInFolder = -1;
+ FolderPtr aFoundFolder;
+ TDF_Label aLastFeatureLabel;
+
+ for (int aRefIndex = aRefs->Lower(); aRefIndex <= aRefs->Upper(); ++aRefIndex) {
+ if (aFoundFolder)
+ ++theIndexInFolder;
+
+ TDF_Label aCurLabel = aRefs->Value(aRefIndex);
+ if (aCurLabel == aLabelToFind) // the feature is reached
+ return aFoundFolder;
+
+ if (!aFoundFolder) {
+ // if the current label refers to a folder, feel all necessary data
+ aFoundFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(folder(aCurLabel));
+ if (aFoundFolder) {
+ theIndexInFolder = -1;
+
+ AttributeReferencePtr aLastRef =
+ aFoundFolder->reference(ModelAPI_Folder::LAST_FEATURE_ID());
+ if (aLastRef->value()) {
+ aData = std::static_pointer_cast<Model_Data>(aLastRef->value()->data());
+ if (aData && aData->isValid())
+ aLastFeatureLabel = aData->label().Father();
+ } else // folder is empty
+ aFoundFolder = FolderPtr();
+ }
+ } else if (aLastFeatureLabel == aCurLabel) {
+ // folder is finished, clear all stored data
+ theIndexInFolder = -1;
+ aFoundFolder = FolderPtr();
+ }
+ }
+
+ // folder is not found
+ theIndexInFolder = -1;
+ return FolderPtr();
+}
+
std::shared_ptr<ModelAPI_Feature> Model_Objects::feature(
const std::shared_ptr<ModelAPI_Result>& theResult)
std::shared_ptr<ModelAPI_Folder> findFolder(
const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
const bool theBelow);
+ //! Search a folder containing the given feature.
+ //! Addtionally calculates a zero-based index of the feature in this folder.
+ //! \param theFeature feature to search
+ //! \param theIndexInFolder zero-based index in the folder or -1 if the feature is top-level.
+ //! \return the folder containing the feature or empty pointer if the feature is top-level.
+ std::shared_ptr<ModelAPI_Folder> findContainingFolder(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ int& theIndexInFolder);
//! Add a list of features to the folder. The correctness of the adding is not performed
//! (such checks have been done in corresponding find.. method).
//! \return \c true if the movement is successfull
}
}
+%apply int& OUTPUT {int&};
+
// all supported interfaces
%include "ModelAPI_Entity.h"
%include "ModelAPI_Document.h"
//! \return Empty pointer if there is no applicable folder
virtual std::shared_ptr<ModelAPI_Folder> findFolderBelow(
const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures) = 0;
+ //! Search a folder containing the given feature.
+ //! Addtionally calculates a zero-based index of the feature in this folder.
+ //! \param theFeature feature to search
+ //! \param theIndexInFolder zero-based index in the folder or -1 if the feature is top-level.
+ //! \return the folder containing the feature or empty pointer if the feature is top-level.
+ virtual std::shared_ptr<ModelAPI_Folder> findContainingFolder(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ int& theIndexInFolder) = 0;
//! Add a list of features to the folder. The correctness of the adding is not performed
//! (such checks have been done in corresponding find.. method).
//! \return \c true if the movement is successfull
# number of features outside the folder
assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
+# check the index of the point in the folder
+aFound = aPartDoc.findContainingFolder(aPoint1)
+assert(aFound[0].data().isEqual(aFolder1.data()))
+assert(aFound[1] == 0)
+
#=========================================================================
# Test 2. Add a point into a folder below
#=========================================================================
assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
+# check the index of the point in the folder
+aFound = aPartDoc.findContainingFolder(aPoint2)
+assert(aFound[0].data().isEqual(aFolder2.data()))
+assert(aFound[1] == 0)
+aFound = aPartDoc.findContainingFolder(aPoint3)
+assert(aFound == -1)
+
#=========================================================================
# Test 3. Add several points into a folder
#=========================================================================
assert(aPartDoc.index(aPoint3, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
assert(aPartDoc.index(aPoint4, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
+# check the index of the point in the folder
+aFound = aPartDoc.findContainingFolder(aPoint3)
+assert(aFound[0].data().isEqual(aFolder3.data()))
+assert(aFound[1] == 0)
+aFound = aPartDoc.findContainingFolder(aPoint4)
+assert(aFound[0].data().isEqual(aFolder3.data()))
+assert(aFound[1] == 1)
+
# add more points to the folder to move them out
aPoint5 = newPoint(aPartDoc, 0., 0., 10.)