Salome HOME
Implementation of "isDisplayed" persistent flag
authormpv <mpv@opencascade.com>
Tue, 19 May 2015 13:05:10 +0000 (16:05 +0300)
committermpv <mpv@opencascade.com>
Tue, 19 May 2015 13:05:10 +0000 (16:05 +0300)
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Object.cpp
src/ModelAPI/ModelAPI_Object.h

index 504f310d75a53b7b38891b865bef520ee8a266dd..608aedc7a131025393bc97779f4865107edc5427 100644 (file)
 #include <TDF_AttributeIterator.hxx>
 #include <TDF_ChildIterator.hxx>
 #include <TDF_RelocationTable.hxx>
-#include <Standard_GUID.hxx>
-#include <TDataStd_UAttribute.hxx>
 
 #include <string>
 
 // 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<ModelAPI_Data> 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);
   }
 }
index 40deee668b49554fffc54a2220d859d39a2c5357..10464cabdba9c7b620c0197f3c91a4186d1773cf 100644 (file)
@@ -23,6 +23,7 @@
 #include <ModelAPI_Object.h>
 
 #include <TDF_Label.hxx>
+#include <TDataStd_BooleanArray.hxx>
 
 #include <memory>
 
@@ -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<std::string, std::shared_ptr<ModelAPI_Attribute> > 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.
index a9d2d6222351193dd7d55110ebb2be11b0a7ff6c..5d952ebfad0e004b8228e7e99a5a0120b30fe3d7 100644 (file)
@@ -143,6 +143,7 @@ class MODELAPI_EXPORT ModelAPI_Data
 
   /// Copies all atributes content into theTarget data
   virtual void copyTo(std::shared_ptr<ModelAPI_Data> 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;
 };
 
index 3a85d388a2e54262679958aa408957f8c581f950..3002d889e840e5358a867786c069d17b1a23e13a 100644 (file)
@@ -75,8 +75,14 @@ void ModelAPI_Feature::removeResults(const int theSinceIndex)
   for(int anIndex = 0; anIndex < theSinceIndex && aResIter != myResults.end(); anIndex++)
     aResIter++;
   std::list<std::shared_ptr<ModelAPI_Result> >::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<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
+      for(; aResIter != myResults.end(); aResIter++) {
+        (*aResIter)->setDisabled(*aResIter, false); // just enable results
+      }
+    }
     return true;
   }
   return false;
index e1b490b42e37dc47154fd85ecaaf045b216c62a3..24a2b2d55c32740f5976a67d7bb7fc97c0f94b6b 100644 (file)
@@ -6,6 +6,9 @@
 
 #include "ModelAPI_Object.h"
 #include "ModelAPI_Document.h"
+#include "ModelAPI_Data.h"
+#include "ModelAPI_Events.h"
+#include <Events_Loop.h>
 
 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);
+}
index e0f4ebb0f878db2d6629744172e131fa70ac752b..e755f532d23c28adfb9d7b6d168c669ead443b5f 100644 (file)
@@ -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;
 
 };