Salome HOME
Implementation of "isDisplayed" persistent flag
[modules/shaper.git] / src / ModelAPI / ModelAPI_Object.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Object.hxx
4 // Created:     19 May 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef ModelAPI_Object_H_
8 #define ModelAPI_Object_H_
9
10 #include "ModelAPI.h"
11 #include "ModelAPI_Data.h"
12
13 #include <memory>
14
15 class ModelAPI_Data;
16 class ModelAPI_Document;
17
18 /**\class ModelAPI_Object
19  * \ingroup DataModel
20  * \brief Represents any object in the data model and in the object browser.
21  *
22  * It may be feature or result of the feature. User just may set name for it
23  * or change this name later. Generic class for Feature, Body, Parameter and other
24  * objects related to the features and their results. Contains attributes of this 
25  * object in the "Data".
26  */
27 class ModelAPI_Object
28 {
29   std::shared_ptr<ModelAPI_Data> myData;  ///< manager of the data model of a feature
30   std::shared_ptr<ModelAPI_Document> myDoc;  ///< document this object belongs to
31  public:
32   /// By default object is displayed in the object browser.
33   MODELAPI_EXPORT virtual bool isInHistory();
34
35   /// Makes object presented or not in the history of the created objects
36   /// \param theObject is shared pointer to "this"
37   /// \param theFlag is boolean value: to add or remove from the history
38   MODELAPI_EXPORT virtual void setInHistory(
39     const std::shared_ptr<ModelAPI_Object> theObject, const bool theFlag);
40
41   /// Returns the data manager of this object: attributes
42   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Data> data() const;
43
44   /// Returns true if object refers to the same data model instance
45   MODELAPI_EXPORT virtual bool isSame(const std::shared_ptr<ModelAPI_Object>& theObject);
46
47   /// Returns document this feature belongs to
48   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> document() const;
49
50   /// Returns the group identifier of this object
51   virtual std::string groupName() = 0;
52
53   /// Request for initialization of data model of the object: adding all attributes
54   virtual void initAttributes() = 0;
55
56   /// Returns the feature is disabled or not.
57   virtual bool isDisabled() const = 0;
58
59   /// Called on change of any argument-attribute of this object
60   /// \param theID identifier of changed attribute
61   MODELAPI_EXPORT virtual void attributeChanged(const std::string& theID);
62
63   /// Initializes the default states of the object
64   MODELAPI_EXPORT ModelAPI_Object();
65
66   /// To use virtuality for destructors
67   MODELAPI_EXPORT virtual ~ModelAPI_Object();
68
69  protected:
70   /// Sets the data manager of an object (document does)
71   MODELAPI_EXPORT virtual void setData(std::shared_ptr<ModelAPI_Data> theData);
72
73   /// Sets the data manager of an object (document does)
74   MODELAPI_EXPORT virtual void setDoc(std::shared_ptr<ModelAPI_Document> theDoc);
75
76   /// removes all fields from this feature
77   MODELAPI_EXPORT virtual void erase();
78
79   /// Returns true if object must be displayed in the viewer: flag is stored in the
80   /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps
81   /// the original state i nthe current transaction.
82   MODELAPI_EXPORT virtual bool isDisplayed();
83
84   /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
85   /// signal.
86   MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
87
88   friend class Model_Objects;
89
90 };
91
92 typedef std::shared_ptr<ModelAPI_Object> ObjectPtr;
93
94 #endif