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