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