Salome HOME
Merge branch 'csgroup_IS2'
[modules/shaper.git] / src / ModelAPI / ModelAPI_Object.h
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModelAPI_Object_H_
21 #define ModelAPI_Object_H_
22
23 #include "ModelAPI.h"
24 #include "ModelAPI_Data.h"
25 #include "ModelAPI_Entity.h"
26
27 #include <memory>
28
29 class ModelAPI_Data;
30 class ModelAPI_Document;
31
32 // sometimes it is useful for debug to see name of each object (bad for memory and performance)
33 //#define DEBUG_NAMES
34
35 /**\class ModelAPI_Object
36  * \ingroup DataModel
37  * \brief Represents any object in the data model and in the object browser.
38  *
39  * It may be feature or result of the feature. User just may set name for it
40  * or change this name later. Generic class for Feature, Body, Parameter and other
41  * objects related to the features and their results. Contains attributes of this 
42  * object in the "Data".
43  */
44 class ModelAPI_Object: public ModelAPI_Entity
45 {
46   std::shared_ptr<ModelAPI_Data> myData;  ///< manager of the data model of a feature
47   std::shared_ptr<ModelAPI_Document> myDoc;  ///< document this object belongs to
48   std::string textureFile = "";
49  public:
50 #ifdef DEBUG_NAMES
51   std::wstring myName; // name of this object
52 #endif
53   /// By default object is displayed in the object browser.
54   MODELAPI_EXPORT virtual bool isInHistory();
55
56   /// Makes object presented or not in the history of the created objects
57   /// \param theObject is shared pointer to "this"
58   /// \param theFlag is boolean value: to add or remove from the history
59   MODELAPI_EXPORT virtual void setInHistory(
60     const std::shared_ptr<ModelAPI_Object> theObject, const bool theFlag);
61
62   /// Returns the data manager of this object: attributes
63   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Data> data() const;
64
65   /// Returns true if object refers to the same data model instance
66   MODELAPI_EXPORT virtual bool isSame(const std::shared_ptr<ModelAPI_Object>& theObject);
67
68   /// Returns document this feature belongs to
69   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> document() const;
70
71   /// Returns the group identifier of this object
72   virtual std::string groupName() = 0;
73
74   /// Request for initialization of data model of the object: adding all attributes
75   virtual void initAttributes() = 0;
76
77   /// Returns the feature is disabled or not.
78   virtual bool isDisabled() = 0;
79
80   /// Returns the parameters of color definition in the resources config manager
81   virtual void colorConfigInfo(std::string& /*theSection*/,
82                                std::string& /*theName*/,
83                                std::string& /*theDefault*/) {}
84
85   /// Called on change of any argument-attribute of this object
86   /// \param theID identifier of changed attribute
87   MODELAPI_EXPORT virtual void attributeChanged(const std::string& theID);
88
89   /// Initializes the default states of the object
90   MODELAPI_EXPORT ModelAPI_Object();
91
92   /// To use virtuality for destructors
93   MODELAPI_EXPORT virtual ~ModelAPI_Object();
94
95   /// Returns true if object must be displayed in the viewer: flag is stored in the
96   /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps
97   /// the original state in the current transaction.
98   MODELAPI_EXPORT virtual bool isDisplayed();
99
100   /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
101   /// signal.
102   MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
103
104   MODELAPI_EXPORT bool hasTextureFile()
105   {
106     return (textureFile != "");
107   }
108
109   MODELAPI_EXPORT virtual void setTextureFile(const std::string & theTextureFile)
110   {
111     textureFile = theTextureFile;
112   }
113
114   MODELAPI_EXPORT const std::string & getTextureFile()
115   {
116     return  textureFile;
117   }
118
119  protected:
120   /// This method is called just after creation of the object: it must initialize
121   /// all fields, normally initialized in the constructor
122   MODELAPI_EXPORT virtual void init() = 0;
123
124   /// Sets the data manager of an object (document does)
125   MODELAPI_EXPORT virtual void setData(std::shared_ptr<ModelAPI_Data> theData);
126
127   /// Sets the data manager of an object (document does)
128   MODELAPI_EXPORT virtual void setDoc(std::shared_ptr<ModelAPI_Document> theDoc);
129
130   /// removes all fields from this feature
131   MODELAPI_EXPORT virtual void erase();
132
133   friend class Model_Objects;
134   friend class ModelAPI_Feature;
135   friend class Model_Document;
136
137 };
138
139 typedef std::shared_ptr<ModelAPI_Object> ObjectPtr;
140
141 #endif