Salome HOME
Merge branch 'master' into BR_PYTHON_PLUGIN
[modules/shaper.git] / src / ModelAPI / ModelAPI_Data.h
1 // File:        ModelAPI_Data.hxx
2 // Created:     21 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef ModelAPI_Data_H_
6 #define ModelAPI_Data_H_
7
8 #include "ModelAPI.h"
9 #include <string>
10 #include <list>
11 #include <set>
12 #include <boost/shared_ptr.hpp>
13
14 class ModelAPI_AttributeDocRef;
15 class ModelAPI_AttributeInteger;
16 class ModelAPI_AttributeDouble;
17 class ModelAPI_AttributeReference;
18 class ModelAPI_AttributeRefAttr;
19 class ModelAPI_AttributeRefList;
20 class ModelAPI_AttributeBoolean;
21 class ModelAPI_AttributeString;
22 class ModelAPI_Document;
23 class ModelAPI_Attribute;
24 class ModelAPI_Feature;
25 class ModelAPI_AttributeSelection;
26 class ModelAPI_AttributeSelectionList;
27 class GeomAPI_Shape;
28
29 /**\class ModelAPI_Data
30  * \ingroup DataModel
31  * \brief General object of the application that allows
32  * to get/set attributes from the document and compute result of an operation.
33  */
34
35 class MODELAPI_EXPORT ModelAPI_Data
36 {
37  public:
38
39   /// Returns the name of the feature visible by the user in the object browser
40   virtual std::string name() = 0;
41
42   /// Defines the name of the feature visible by the user in the object browser
43   virtual void setName(const std::string& theName) = 0;
44
45   /// Returns the attribute that references to another document
46   virtual boost::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID) = 0;
47   /// Returns the attribute that contains real value with double precision
48   virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID) = 0;
49   /// Returns the attribute that contains integer value
50   virtual boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
51   /// Returns the attribute that contains reference to a feature
52   virtual boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
53   /// Returns the attribute that contains selection to a shape
54   virtual boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
55   /// Returns the attribute that contains selection to a shape
56   virtual boost::shared_ptr<ModelAPI_AttributeSelectionList> 
57     selectionList(const std::string& theID) = 0;
58   /// Returns the attribute that contains reference to an attribute of a feature
59   virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
60   /// Returns the attribute that contains list of references to features
61   virtual boost::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID) = 0;
62   /// Returns the attribute that contains boolean value
63   virtual boost::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
64   /// Returns the attribute that contains boolean value
65   virtual boost::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
66
67   /// Returns the generic attribute by identifier
68   /// \param theID identifier of the attribute
69   virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID) = 0;
70   /// Returns all attributes of the feature of the given type
71   /// or all attributes if "theType" is empty
72   virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
73   attributes(const std::string& theType) = 0;
74   /// Returns all attributes ids of the feature of the given type
75   /// or all attributes if "theType" is empty
76   virtual std::list<std::string> attributesIDs(const std::string& theType) = 0;
77   /// Identifier by the id (not fast, iteration by map)
78   /// \param theAttr attribute already created in this data
79   virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr) = 0;
80   /// Returns true if data belongs to same features
81   virtual bool isEqual(const boost::shared_ptr<ModelAPI_Data>& theData) = 0;
82   /// Returns true if it is correctly connected to the data model
83   virtual bool isValid() = 0;
84
85   /// Initializes object by the attributes: must be called just after the object is created
86   /// for each attribute of the object
87   /// \param theID identifier of the attribute that can be referenced by this ID later
88   /// \param theAttrType type of the created attribute (received from the type method)
89   virtual void addAttribute(const std::string& theID, const std::string theAttrType) = 0;
90
91   /// Useful method for "set" methods of the attributes: sends an UPDATE event and
92   /// makes attribute initialized
93   virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
94
95   /// Erases all the data from the data model
96   virtual void erase() = 0;
97
98   /// To virtually destroy the fields of successors
99   virtual ~ModelAPI_Data()
100   {
101   }
102
103   /// Makes feature must be updated later (on rebuild). Normally the Updater must call it
104   /// in case of not-automatic update to true
105   virtual void mustBeUpdated(const bool theFlag) = 0;
106
107   /// Returns true if feature must be updated (re-executed) on rebuild
108   virtual bool mustBeUpdated() = 0;
109
110   /// Returns the identifier of feature-owner, unique in this document
111   virtual int featureId() const = 0;
112
113  // returns all objects referenced to this
114   virtual const std::set<boost::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
115
116  protected:
117   /// Objects are created for features automatically
118   ModelAPI_Data()
119   {
120   }
121 };
122
123 typedef boost::shared_ptr<ModelAPI_Data> DataPtr;
124
125 #endif