Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom.git into Dev_0.7.1
[modules/shaper.git] / src / ModelAPI / ModelAPI_Data.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Data.hxx
4 // Created:     21 Mar 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef ModelAPI_Data_H_
8 #define ModelAPI_Data_H_
9
10 #include "ModelAPI.h"
11 #include <string>
12 #include <list>
13 #include <set>
14 #include <memory>
15
16 class ModelAPI_AttributeDocRef;
17 class ModelAPI_AttributeInteger;
18 class ModelAPI_AttributeDouble;
19 class ModelAPI_AttributeReference;
20 class ModelAPI_AttributeRefAttr;
21 class ModelAPI_AttributeRefList;
22 class ModelAPI_AttributeBoolean;
23 class ModelAPI_AttributeString;
24 class ModelAPI_Document;
25 class ModelAPI_Attribute;
26 class ModelAPI_Feature;
27 class ModelAPI_AttributeSelection;
28 class ModelAPI_AttributeSelectionList;
29 class ModelAPI_Object;
30 class GeomAPI_Shape;
31
32 /// Enumeration that contains the execution status of the Object
33 enum ModelAPI_ExecState {
34   ModelAPI_StateDone, ///< execution was performed and result is up to date
35   ModelAPI_StateMustBeUpdated, ///< execution must be performed to obtain the up to date result
36   ModelAPI_StateExecFailed, ///< execution was failed (results are deleted in this case)
37   ModelAPI_StateInvalidArgument, ///< execution was not performed (results are deleted in this case)
38   ModelAPI_StateNothing ///< internal state that actually means that nothing must be changed
39 };
40
41 /**\class ModelAPI_Data
42  * \ingroup DataModel
43  * \brief General object of the application that allows
44  * to get/set attributes from the document and compute result of an operation.
45  */
46
47 class MODELAPI_EXPORT ModelAPI_Data
48 {
49  public:
50
51   /// Returns the name of the feature visible by the user in the object browser
52   virtual std::string name() = 0;
53
54   /// Defines the name of the feature visible by the user in the object browser
55   virtual void setName(const std::string& theName) = 0;
56
57   /// Returns the attribute that references to another document
58   virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID) = 0;
59   /// Returns the attribute that contains real value with double precision
60   virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID) = 0;
61   /// Returns the attribute that contains integer value
62   virtual std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
63   /// Returns the attribute that contains reference to a feature
64   virtual std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
65   /// Returns the attribute that contains selection to a shape
66   virtual std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
67   /// Returns the attribute that contains selection to a shape
68   virtual std::shared_ptr<ModelAPI_AttributeSelectionList> 
69     selectionList(const std::string& theID) = 0;
70   /// Returns the attribute that contains reference to an attribute of a feature
71   virtual std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
72   /// Returns the attribute that contains list of references to features
73   virtual std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID) = 0;
74   /// Returns the attribute that contains boolean value
75   virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
76   /// Returns the attribute that contains boolean value
77   virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
78
79   /// Returns the generic attribute by identifier
80   /// \param theID identifier of the attribute
81   virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID) = 0;
82   /// Returns all attributes of the feature of the given type
83   /// or all attributes if "theType" is empty
84   virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
85   attributes(const std::string& theType) = 0;
86   /// Returns all attributes ids of the feature of the given type
87   /// or all attributes if "theType" is empty
88   virtual std::list<std::string> attributesIDs(const std::string& theType) = 0;
89   /// Identifier by the id (not fast, iteration by map)
90   /// \param theAttr attribute already created in this data
91   virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr) = 0;
92   /// Returns true if data belongs to same features
93   virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData) = 0;
94   /// Returns true if it is correctly connected to the data model
95   virtual bool isValid() = 0;
96
97   /// Initializes object by the attributes: must be called just after the object is created
98   /// for each attribute of the object
99   /// \param theID identifier of the attribute that can be referenced by this ID later
100   /// \param theAttrType type of the created attribute (received from the type method)
101   virtual void addAttribute(const std::string& theID, const std::string theAttrType) = 0;
102
103   /// Useful method for "set" methods of the attributes: sends an UPDATE event and
104   /// makes attribute initialized
105   virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
106   /// Blocks sending "attribute updated" if theBlock is true
107   virtual void blockSendAttributeUpdated(const bool theBlock) = 0;
108
109   /// Erases all the data from the data model
110   virtual void erase() = 0;
111
112   /// To virtually destroy the fields of successors
113   virtual ~ModelAPI_Data();
114
115   /// Stores the state of the object to execute it later accordingly
116   virtual void execState(const ModelAPI_ExecState theState) = 0;
117
118   /// Returns the state of the latest execution of the feature
119   virtual ModelAPI_ExecState execState() = 0;
120
121   /// Registers error during the execution, causes the ExecutionFailed state
122   virtual void setError(const std::string& theError) = 0;
123
124   /// Returns the identifier of feature-owner, unique in this document
125   virtual int featureId() const = 0;
126
127  // returns all objects referenced to this
128   virtual const std::set<std::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
129
130   // returns all references by attributes of this data
131   // \param theRefs returned list of pairs: id of referenced attribute and list of referenced objects
132   virtual void referencesToObjects(
133     std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > >& theRefs) = 0;
134  protected:
135   /// Objects are created for features automatically
136   ModelAPI_Data();
137 };
138
139 typedef std::shared_ptr<ModelAPI_Data> DataPtr;
140
141 #endif