#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)
{
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()
}
}
-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);
}
}
#include <ModelAPI_Object.h>
#include <TDF_Label.hxx>
+#include <TDataStd_BooleanArray.hxx>
#include <memory>
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;
/// \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.
/// 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();
/// 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;
};
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++;
+ }
}
}
{
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;
#include "ModelAPI_Object.h"
#include "ModelAPI_Document.h"
+#include "ModelAPI_Data.h"
+#include "ModelAPI_Events.h"
+#include <Events_Loop.h>
bool ModelAPI_Object::isInHistory()
{
if (myData) myData->erase();
setData(DataPtr());
}
+
+bool ModelAPI_Object::isDisplayed()
+{
+ return myData->isDisplayed();
+}
+
+void ModelAPI_Object::setDisplayed(const bool theDisplay)
+{
+ myData->setDisplayed(theDisplay);
+}
/// 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;
};