From 83bbce5aee090aed21034874cd38c0c838f1733f Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 19 May 2015 16:05:10 +0300 Subject: [PATCH] Implementation of "isDisplayed" persistent flag --- src/Model/Model_Data.cpp | 38 +++++++++++++++++++++++-------- src/Model/Model_Data.h | 12 ++++++++++ src/ModelAPI/ModelAPI_Data.h | 10 ++++++++ src/ModelAPI/ModelAPI_Feature.cpp | 19 +++++++++++++--- src/ModelAPI/ModelAPI_Object.cpp | 13 +++++++++++ src/ModelAPI/ModelAPI_Object.h | 9 ++++++++ 6 files changed, 89 insertions(+), 12 deletions(-) diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 504f310d7..608aedc7a 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -33,14 +33,17 @@ #include #include #include -#include -#include #include // myLab contains: // TDataStd_Name - name of the object // TDataStd_Integer - state of the object execution +// TDataStd_BooleanArray - array of flags of this data: +// 0 - is in history or not +static const int kFlagInHistory = 0; +// 1 - is displayed or not +static const int kFlagDisplayed = 1; Model_Data::Model_Data() : mySendAttributeUpdated(true) { @@ -49,6 +52,13 @@ Model_Data::Model_Data() : mySendAttributeUpdated(true) void Model_Data::setLabel(TDF_Label theLab) { myLab = theLab; + // set or get the default flags + if (!myLab.FindAttribute(TDataStd_BooleanArray::GetID(), myFlags)) { + // set default values if not found + Handle(TDataStd_BooleanArray) myFlags = TDataStd_BooleanArray::Set(myLab, 0, 1); + myFlags->SetValue(kFlagInHistory, Standard_True); // is in history by default is true + myFlags->SetValue(kFlagDisplayed, Standard_True); // is displayed by default is true + } } std::string Model_Data::name() @@ -372,18 +382,28 @@ void Model_Data::copyTo(std::shared_ptr theTarget) } } -const Standard_GUID kIsInHistory("9275e461-4aca-46c7-ad84-1efb569d8144"); - bool Model_Data::isInHistory() { - return !myLab.IsAttribute(kIsInHistory); + return myFlags->Value(kFlagInHistory) == Standard_True; } void Model_Data::setIsInHistory(const bool theFlag) { - if (theFlag) { // is in histiry true: default behavior, so, remove GUID - myLab.ForgetAttribute(kIsInHistory); - } else { // not standard behavior is defined by special GUID attribute - TDataStd_UAttribute::Set(myLab, kIsInHistory); + return myFlags->SetValue(kFlagInHistory, theFlag); +} + +bool Model_Data::isDisplayed() +{ + return myFlags->Value(kFlagDisplayed) == Standard_True; +} + +void Model_Data::setDisplayed(const bool theDisplay) +{ + if (theDisplay != isDisplayed()) { + myFlags->SetValue(kFlagDisplayed, theDisplay); + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + aECreator->sendUpdated(myObject, EVENT_DISP); } } diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 40deee668..10464cabd 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -23,6 +23,7 @@ #include #include +#include #include @@ -44,6 +45,8 @@ class Model_Data : public ModelAPI_Data TDF_Label myLab; ///< label of the feature in the document /// All attributes of the object identified by the attribute ID std::map > myAttrs; + /// Array of flags of this data + Handle(TDataStd_BooleanArray) myFlags; /// needed here to emit signal that object changed on change of the attribute ObjectPtr myObject; @@ -204,6 +207,15 @@ private: /// \param theApplyConcealment applies consealment flag changes void addBackReference(FeaturePtr theFeature, std::string theAttrID, const bool theApplyConcealment = true); + + /// Returns true if object must be displayed in the viewer: flag is stored in the + /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps + /// the original state i nthe current transaction. + MODEL_EXPORT virtual bool isDisplayed(); + + /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay" + /// signal. + MODEL_EXPORT virtual void setDisplayed(const bool theDisplay); }; /// Generic method to register back reference, used in referencing attributes. diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index a9d2d6222..5d952ebfa 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -143,6 +143,7 @@ class MODELAPI_EXPORT ModelAPI_Data /// Copies all atributes content into theTarget data virtual void copyTo(std::shared_ptr theTarget) = 0; + protected: /// Objects are created for features automatically ModelAPI_Data(); @@ -153,6 +154,15 @@ class MODELAPI_EXPORT ModelAPI_Data /// Defines the custom "is in history" behavior virtual void setIsInHistory(const bool theFlag) = 0; + /// Returns true if object must be displayed in the viewer: flag is stored in the + /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps + /// the original state i nthe current transaction. + virtual bool isDisplayed() = 0; + + /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay" + /// signal. + virtual void setDisplayed(const bool theDisplay) = 0; + friend class ModelAPI_Object; }; diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 3a85d388a..3002d889e 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -75,8 +75,14 @@ void ModelAPI_Feature::removeResults(const int theSinceIndex) for(int anIndex = 0; anIndex < theSinceIndex && aResIter != myResults.end(); anIndex++) aResIter++; std::list >::iterator aNextIter = aResIter; - for(; aNextIter != myResults.end(); aNextIter++) { - (*aNextIter)->setDisabled(*aNextIter, true); // just disable results + while( aNextIter != myResults.end()) { + // remove previously erased results: to enable later if needed only actual (of history change) + if (theSinceIndex == 0 && (*aNextIter)->isDisabled()) { + aNextIter = myResults.erase(aNextIter); + } else { + (*aNextIter)->setDisabled(*aNextIter, true); // just disable results + aNextIter++; + } } } @@ -135,8 +141,15 @@ bool ModelAPI_Feature::setDisabled(const bool theFlag) { if (myIsDisabled != theFlag) { myIsDisabled = theFlag; - if (myIsDisabled) + if (myIsDisabled) { eraseResults(); + } else { + // enable all disabled previously results + std::list >::iterator aResIter = myResults.begin(); + for(; aResIter != myResults.end(); aResIter++) { + (*aResIter)->setDisabled(*aResIter, false); // just enable results + } + } return true; } return false; diff --git a/src/ModelAPI/ModelAPI_Object.cpp b/src/ModelAPI/ModelAPI_Object.cpp index e1b490b42..24a2b2d55 100644 --- a/src/ModelAPI/ModelAPI_Object.cpp +++ b/src/ModelAPI/ModelAPI_Object.cpp @@ -6,6 +6,9 @@ #include "ModelAPI_Object.h" #include "ModelAPI_Document.h" +#include "ModelAPI_Data.h" +#include "ModelAPI_Events.h" +#include bool ModelAPI_Object::isInHistory() { @@ -68,3 +71,13 @@ void ModelAPI_Object::erase() if (myData) myData->erase(); setData(DataPtr()); } + +bool ModelAPI_Object::isDisplayed() +{ + return myData->isDisplayed(); +} + +void ModelAPI_Object::setDisplayed(const bool theDisplay) +{ + myData->setDisplayed(theDisplay); +} diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index e0f4ebb0f..e755f532d 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -76,6 +76,15 @@ class ModelAPI_Object /// removes all fields from this feature MODELAPI_EXPORT virtual void erase(); + /// Returns true if object must be displayed in the viewer: flag is stored in the + /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps + /// the original state i nthe current transaction. + MODELAPI_EXPORT virtual bool isDisplayed(); + + /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay" + /// signal. + MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay); + friend class Model_Objects; }; -- 2.39.2