Salome HOME
2.17. Improved management of overconstraint situation: dimension constraints are...
[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 #include "ModelAPI_Entity.h"
13
14 #include <memory>
15
16 class ModelAPI_Data;
17 class ModelAPI_Document;
18
19 /**\class ModelAPI_Object
20  * \ingroup DataModel
21  * \brief Represents any object in the data model and in the object browser.
22  *
23  * It may be feature or result of the feature. User just may set name for it
24  * or change this name later. Generic class for Feature, Body, Parameter and other
25  * objects related to the features and their results. Contains attributes of this 
26  * object in the "Data".
27  */
28 class ModelAPI_Object: public ModelAPI_Entity
29 {
30   std::shared_ptr<ModelAPI_Data> myData;  ///< manager of the data model of a feature
31   std::shared_ptr<ModelAPI_Document> myDoc;  ///< document this object belongs to
32  public:
33   /// By default object is displayed in the object browser.
34   MODELAPI_EXPORT virtual bool isInHistory();
35
36   /// Makes object presented or not in the history of the created objects
37   /// \param theObject is shared pointer to "this"
38   /// \param theFlag is boolean value: to add or remove from the history
39   MODELAPI_EXPORT virtual void setInHistory(
40     const std::shared_ptr<ModelAPI_Object> theObject, const bool theFlag);
41
42   /// Returns the data manager of this object: attributes
43   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Data> data() const;
44
45   /// Returns true if object refers to the same data model instance
46   MODELAPI_EXPORT virtual bool isSame(const std::shared_ptr<ModelAPI_Object>& theObject);
47
48   /// Returns document this feature belongs to
49   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> document() const;
50
51   /// Returns the group identifier of this object
52   virtual std::string groupName() = 0;
53
54   /// Request for initialization of data model of the object: adding all attributes
55   virtual void initAttributes() = 0;
56
57   /// Returns the feature is disabled or not.
58   virtual bool isDisabled() = 0;
59
60   /// Returns the parameters of color definition in the resources config manager
61   virtual void colorConfigInfo(std::string& theSection, std::string& theName,
62                                std::string& theDefault) {}
63
64   /// Called on change of any argument-attribute of this object
65   /// \param theID identifier of changed attribute
66   MODELAPI_EXPORT virtual void attributeChanged(const std::string& theID);
67
68   /// Initializes the default states of the object
69   MODELAPI_EXPORT ModelAPI_Object();
70
71   /// To use virtuality for destructors
72   MODELAPI_EXPORT virtual ~ModelAPI_Object();
73
74   /// Returns true if object must be displayed in the viewer: flag is stored in the
75   /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps
76   /// the original state in the current transaction.
77   MODELAPI_EXPORT virtual bool isDisplayed();
78
79   /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
80   /// signal.
81   MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
82
83  protected:
84   /// This method is called just after creation of the object: it must initialize
85   /// all fields, normally initialized in the constructor
86   MODELAPI_EXPORT virtual void init() = 0;
87
88   /// Sets the data manager of an object (document does)
89   MODELAPI_EXPORT virtual void setData(std::shared_ptr<ModelAPI_Data> theData);
90
91   /// Sets the data manager of an object (document does)
92   MODELAPI_EXPORT virtual void setDoc(std::shared_ptr<ModelAPI_Document> theDoc);
93
94   /// removes all fields from this feature
95   MODELAPI_EXPORT virtual void erase();
96
97   friend class Model_Objects;
98   friend class Model_Document;
99
100 };
101
102 typedef std::shared_ptr<ModelAPI_Object> ObjectPtr;
103
104 #endif