Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / ModelAPI / ModelAPI_Object.h
1 // File:        ModelAPI_Object.hxx
2 // Created:     19 May 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef ModelAPI_Object_H_
6 #define ModelAPI_Object_H_
7
8 #include "ModelAPI.h"
9 #include "ModelAPI_Data.h"
10
11 #include <boost/shared_ptr.hpp>
12
13 class ModelAPI_Data;
14 class ModelAPI_Document;
15
16 /**\class ModelAPI_Object
17  * \ingroup DataModel
18  * \brief Represents any object in the data model and in the object browser.
19  *
20  * It may be feature or result of the feature. User just may set name for it
21  * or change this name later. Generic class for Feature, Body, Parameter and other
22  * objects related to the features and their results. Contains attributes of this 
23  * object in the "Data".
24  */
25 class ModelAPI_Object
26 {
27   boost::shared_ptr<ModelAPI_Data> myData;  ///< manager of the data model of a feature
28   boost::shared_ptr<ModelAPI_Document> myDoc;  ///< document this object belongs to
29  public:
30   /// By default object is displayed in the object browser.
31   virtual bool isInHistory()
32   {
33     return true;
34   }
35
36   /// Returns the data manager of this object: attributes
37   virtual boost::shared_ptr<ModelAPI_Data> data() const
38   {
39     return myData;
40   }
41
42   /// Returns true if object refers to the same data model instance
43   virtual bool isSame(const boost::shared_ptr<ModelAPI_Object>& theObject)
44   {
45     return theObject.get() == this;
46   }
47
48   /// Returns document this feature belongs to
49   virtual boost::shared_ptr<ModelAPI_Document> document() const
50   {
51     return myDoc;
52   }
53
54   /// Returns the group identifier of this object
55   virtual std::string groupName() = 0;
56
57   /// To use virtuality for destructors
58   virtual ~ModelAPI_Object() {}
59
60  protected:
61   /// Sets the data manager of an object (document does)
62   virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
63   {
64     myData = theData;
65   }
66
67   /// Sets the data manager of an object (document does)
68   virtual void setDoc(boost::shared_ptr<ModelAPI_Document> theDoc)
69   {
70     myDoc = theDoc;
71   }
72
73   /// removes all fields from this feature
74   MODELAPI_EXPORT virtual void erase() {
75     if (myData) myData->erase();
76     setData(DataPtr());
77   }
78
79   friend class Model_Document;
80
81 };
82
83 typedef boost::shared_ptr<ModelAPI_Object> ObjectPtr;
84
85 #endif