From f8de1b061e64dbe3f368920050b88372dd688518 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 22 Nov 2016 15:52:55 +0300 Subject: [PATCH] For the issue #1856 : prepare the persistence mechanism for nodes states --- src/Model/Model_Document.cpp | 29 ++++++++++++++++++++++++++++- src/Model/Model_Document.h | 8 ++++++++ src/ModelAPI/ModelAPI_Document.h | 8 ++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index c8b567cf7..79febfc4e 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -67,9 +67,10 @@ static const int TAG_GENERAL = 1; // general properties tag // general sub-labels /// where the reference to the current feature label is located (or no attribute if null feature) -static const int TAG_CURRENT_FEATURE = 1; +static const int TAG_CURRENT_FEATURE = 1; ///< reference to the current feature static const int TAG_CURRENT_TRANSACTION = 2; ///< integer, index of the transaction static const int TAG_SELECTION_FEATURE = 3; ///< integer, tag of the selection feature label +static const int TAG_NODES_STATE = 4; ///< array, tag of the Object Browser nodes states Model_Document::Model_Document(const int theID, const std::string theKind) : myID(theID), myKind(theKind), myIsActive(false), @@ -1538,3 +1539,29 @@ bool Model_Document::isLater(FeaturePtr theLater, FeaturePtr theCurrent) const { return myObjs->isLater(theLater, theCurrent); } + +void Model_Document::storeNodesState(const std::list& theStates) +{ + TDF_Label aLab = generalLabel().FindChild(TAG_NODES_STATE); + aLab.ForgetAllAttributes(); + if (!theStates.empty()) { + Handle(TDataStd_BooleanArray) anArray = + TDataStd_BooleanArray::Set(aLab, 0, int(theStates.size()) - 1); + std::list::const_iterator aState = theStates.begin(); + for(int anIndex = 0; aState != theStates.end(); aState++, anIndex++) { + anArray->SetValue(anIndex, *aState); + } + } +} + +void Model_Document::restoreNodesState(std::list& theStates) const +{ + TDF_Label aLab = generalLabel().FindChild(TAG_NODES_STATE); + Handle(TDataStd_BooleanArray) anArray; + if (aLab.FindAttribute(TDataStd_BooleanArray::GetID(), anArray)) { + int anUpper = anArray->Upper(); + for(int anIndex = 0; anIndex <= anUpper; anIndex++) { + theStates.push_back(anArray->Value(anIndex) == Standard_True); + } + } +} diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 80daeb237..1356f5c09 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -280,6 +280,14 @@ class Model_Document : public ModelAPI_Document //! for calculation of selection externally from the document std::shared_ptr selectionInPartFeature(); + /// Stores in the document boolean flags: states of the nodes in the object browser. + /// Normally is called outside of the transaction, just before "save". + void storeNodesState(const std::list& theStates); + + /// Returns the stored nodes states. Normally it is calles just after "open". + /// Appends the values to theStates list. + void restoreNodesState(std::list& theStates) const; + friend class Model_Application; friend class Model_Session; friend class Model_Update; diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 90b87621b..6b0d2d1ea 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -176,6 +176,14 @@ public: //! Internally makes document know that feature was removed or added in history after creation MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0; + /// Stores in the document boolean flags: states of the nodes in the object browser. + /// Normally is called outside of the transaction, just before "save". + MODELAPI_EXPORT void storeNodesState(const std::list& theStates); + + /// Returns the stored nodes states. Normally it is calles just after "open". + /// Appends the values to theStates list. + MODELAPI_EXPORT void restoreNodesState(std::list& theStates) const; + protected: //! Only for SWIG wrapping it is here MODELAPI_EXPORT ModelAPI_Document(); -- 2.39.2