From 9e91b9bd6045a1531587acfb25848b1fb3eee95b Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 23 Aug 2019 15:34:52 +0300 Subject: [PATCH] Added removeFolder high level API level and make folders correctly refreshed in the Object Browser even without transaction end. --- src/ModelHighAPI/ModelHighAPI_Folder.cpp | 9 +++++++++ src/ModelHighAPI/ModelHighAPI_Folder.h | 11 +++++++++++ src/PythonAPI/model/services/__init__.py | 2 +- src/PythonAddons/macros/compoundVertices/feature.py | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ModelHighAPI/ModelHighAPI_Folder.cpp b/src/ModelHighAPI/ModelHighAPI_Folder.cpp index 3640677a3..b47d4b48d 100644 --- a/src/ModelHighAPI/ModelHighAPI_Folder.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Folder.cpp @@ -24,6 +24,7 @@ #include #include +#include //-------------------------------------------------------------------------------------- @@ -109,5 +110,13 @@ std::shared_ptr addFolder(const std::shared_ptrreference(ModelAPI_Folder::LAST_FEATURE_ID()); fillAttribute(theLastFeature.feature(), aLastFeatAttr); + // to update the folder state in the Object Browser + theDoc->updateHistory(ModelAPI_Feature::group()); + return std::shared_ptr(new ModelHighAPI_Folder(aFolder)); } + +void removeFolder(std::shared_ptr& theFolder) +{ + theFolder->folder()->document()->removeFolder(theFolder->folder()); +} diff --git a/src/ModelHighAPI/ModelHighAPI_Folder.h b/src/ModelHighAPI/ModelHighAPI_Folder.h index 66fe99b3c..2f99aabf8 100644 --- a/src/ModelHighAPI/ModelHighAPI_Folder.h +++ b/src/ModelHighAPI/ModelHighAPI_Folder.h @@ -46,6 +46,7 @@ public: static std::string ID() { return ModelAPI_Folder::ID(); } virtual std::string getID() { return ID(); } + const std::shared_ptr& folder() const {return myFolder;} /// First feature reference std::shared_ptr firstFeature() const @@ -63,6 +64,11 @@ public: MODELHIGHAPI_EXPORT std::string name() const; + /// To update the folder state + /// \param isForce start execution of feature instead of sending events + //MODELHIGHAPI_EXPORT void execute(); + + /// Dump wrapped feature MODELHIGHAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; @@ -90,5 +96,10 @@ MODELHIGHAPI_EXPORT std::shared_ptr addFolder(const std::shared_ptr& theDoc, const ModelHighAPI_Reference& theFirstFeature, const ModelHighAPI_Reference& theLastFeature); +/**\ingroup CPPHighAPI +* \brief Removes Folder feature +*/ +MODELHIGHAPI_EXPORT +void removeFolder(std::shared_ptr& theFolder); //-------------------------------------------------------------------------------------- #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_FOLDER_H_ */ diff --git a/src/PythonAPI/model/services/__init__.py b/src/PythonAPI/model/services/__init__.py index 743362959..d585c1891 100644 --- a/src/PythonAPI/model/services/__init__.py +++ b/src/PythonAPI/model/services/__init__.py @@ -26,6 +26,6 @@ from ModelHighAPI import apply as do from ModelHighAPI import updateFeatures from ModelHighAPI import undo, redo from ModelHighAPI import reset -from ModelHighAPI import addFolder +from ModelHighAPI import addFolder, removeFolder from ModelHighAPI import ModelHighAPI_Selection as selection from ModelHighAPI import checkPythonDump as checkPythonDump diff --git a/src/PythonAddons/macros/compoundVertices/feature.py b/src/PythonAddons/macros/compoundVertices/feature.py index 0f2189c1e..224a21313 100644 --- a/src/PythonAddons/macros/compoundVertices/feature.py +++ b/src/PythonAddons/macros/compoundVertices/feature.py @@ -65,7 +65,7 @@ class compoundVertices(model.Feature): for feature in self.lfeatures: part.removeFeature(feature.feature()) self.lfeatures = [] - #part.removeFeature(self.folder.feature()) + model.removeFolder(self.folder) from os.path import basename filename = basename(filepath) -- 2.39.2