From d73d0ed51652cce2355ac6f0106f2d16c71d9d0f Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 24 Nov 2017 09:55:23 +0300 Subject: [PATCH] Ability to get index of the objects according to foldering (Task 2.3. Ability to put consecutive Features in a folder) --- src/Model/Model_Document.cpp | 4 ++-- src/Model/Model_Document.h | 4 +++- src/Model/Model_Objects.cpp | 11 ++++++++++- src/Model/Model_Objects.h | 4 +++- src/ModelAPI/ModelAPI_Document.h | 4 +++- src/ModelAPI/Test/TestFolder_Update.py | 21 +++++++++++++++++++++ 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index f61edd015..58a8b6b42 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -1044,9 +1044,9 @@ std::shared_ptr Model_Document::objectByName( return myObjs->objectByName(theGroupID, theName); } -const int Model_Document::index(std::shared_ptr theObject) +const int Model_Document::index(std::shared_ptr theObject, const bool theAllowFolder) { - return myObjs->index(theObject); + return myObjs->index(theObject, theAllowFolder); } int Model_Document::size(const std::string& theGroupID, const bool theAllowFolder) diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index c0d7a7ad4..300c07d61 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -122,8 +122,10 @@ class Model_Document : public ModelAPI_Document //! Returns the object index in the group. Object must be visible. Otherwise returns -1. //! \param theObject object of this document + //! \param theAllowFolder take into account grouping feature by folders //! \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); + MODEL_EXPORT virtual const int index(std::shared_ptr theObject, + const bool theAllowFolder = false); //! Internal sub-document by ID MODEL_EXPORT virtual std::shared_ptr subDoc(int theDocID); diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 452b202b9..4163c0b51 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -608,10 +608,19 @@ std::shared_ptr Model_Objects::objectByName( return ObjectPtr(); } -const int Model_Objects::index(std::shared_ptr theObject) +const int Model_Objects::index(std::shared_ptr theObject, + const bool theAllowFolder) { std::string aGroup = theObject->groupName(); + // treat folder as feature + if (aGroup == ModelAPI_Folder::group()) + aGroup = ModelAPI_Feature::group(); createHistory(aGroup); + + // get the group of features out of folder (if enabled) + if (theAllowFolder && !groupNameFoldering(aGroup, theAllowFolder).empty()) + aGroup = groupNameFoldering(aGroup, theAllowFolder); + std::vector& allObjs = myHistory[aGroup]; std::vector::iterator anObjIter = allObjs.begin(); // iterate to search object for(int anIndex = 0; anObjIter != allObjs.end(); anObjIter++, anIndex++) { diff --git a/src/Model/Model_Objects.h b/src/Model/Model_Objects.h index 8df42019c..5e1f0b350 100644 --- a/src/Model/Model_Objects.h +++ b/src/Model/Model_Objects.h @@ -91,8 +91,10 @@ class Model_Objects //! Returns the object index in the group. Object must be visible. Otherwise returns -1. //! \param theObject object of this document + //! \param theAllowFolder take into account grouping feature by folders //! \returns index started from zero, or -1 if object is invisible or belongs to another document - const int index(std::shared_ptr theObject); + const int index(std::shared_ptr theObject, + const bool theAllowFolder = false); //! Returns the feature in the group by the index (started from zero) //! \param theGroupID group that contains a feature diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 5e3cc05bc..7ad725416 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -104,8 +104,10 @@ public: //! Returns the object index in the group. Object must be visible. Otherwise returns -1. //! \param theObject object of this document + //! \param theAllowFolder take into account grouping feature by folders //! \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; + virtual const int index(std::shared_ptr theObject, + const bool theAllowFolder = false) = 0; //! Returns the number of objects in the group of objects //! \param theGroupID group of objects diff --git a/src/ModelAPI/Test/TestFolder_Update.py b/src/ModelAPI/Test/TestFolder_Update.py index fa336ec06..1ef1a8c6a 100644 --- a/src/ModelAPI/Test/TestFolder_Update.py +++ b/src/ModelAPI/Test/TestFolder_Update.py @@ -131,6 +131,11 @@ NB_FEATURES_OUT += 1 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) +# index without respect to foldering +assert(aPartDoc.index(aPoint4) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4)) +# index according to folders +assert(aPartDoc.index(aPoint4, True) == 3), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True)) + # add a folder aSession.startOperation() aFolder2 = aPartDoc.addFolder(aPoint3) @@ -143,6 +148,13 @@ assert(aPartDoc.size("Folders") == 3), "Wrong number of folders: {}".format(aPar 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) +# index without respect to foldering +assert(aPartDoc.index(aFolder2) == 4), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2)) +assert(aPartDoc.index(aPoint4) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4)) +# index according to folders +assert(aPartDoc.index(aFolder2, True) == 2), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True)) +assert(aPartDoc.index(aPoint4, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True)) + toFolder = FeatureList() toFolder.append(aPoint3) toFolder.append(aPoint4) @@ -160,6 +172,15 @@ NB_FEATURES_OUT -= 2 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) +# index without respect to foldering +assert(aPartDoc.index(aFolder2) == 4), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2)) +assert(aPartDoc.index(aPoint3) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3)) +assert(aPartDoc.index(aPoint4) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4)) +# index according to folders +assert(aPartDoc.index(aFolder2, True) == 2), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True)) +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)) + from salome.shaper import model assert(model.checkPythonDump()) -- 2.39.2