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