1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_Data.hxx
4 // Created: 21 Mar 2014
5 // Author: Mikhail PONIKAROV
7 #ifndef ModelAPI_Data_H_
8 #define ModelAPI_Data_H_
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;
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
43 /**\class ModelAPI_Data
45 * \brief General object of the application that allows
46 * to get/set attributes from the document and compute result of an operation.
49 class MODELAPI_EXPORT ModelAPI_Data
53 /// Returns the name of the feature visible by the user in the object browser
54 virtual std::string name() = 0;
56 /// Defines the name of the feature visible by the user in the object browser
57 virtual void setName(const std::string& theName) = 0;
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;
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;
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;
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;
115 /// Erases all the data from the data model
116 virtual void erase() = 0;
118 /// To virtually destroy the fields of successors
119 virtual ~ModelAPI_Data();
121 /// Stores the state of the object to execute it later accordingly
122 virtual void execState(const ModelAPI_ExecState theState) = 0;
124 /// Returns the state of the latest execution of the feature
125 virtual ModelAPI_ExecState execState() = 0;
127 /// Registers error during the execution, causes the ExecutionFailed state
128 virtual void setError(const std::string& theError, bool theSend = true) = 0;
130 /// Returns error, arose during the execution
131 virtual std::string error() const = 0;
133 /// Returns the identifier of feature-owner, unique in this document
134 virtual int featureId() const = 0;
136 /// returns all objects referenced to this
137 virtual const std::set<std::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
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;
144 /// Copies all atributes content into theTarget data
145 virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget) = 0;
147 /// Returns the invalid data pointer (to avoid working with NULL shared ptrs in swig)
148 virtual std::shared_ptr<ModelAPI_Data> invalidPtr() = 0;
150 /// Identifier of the transaction when object (feature or result) was updated last time.
151 virtual int updateID() = 0;
153 /// Identifier of the transaction when object (feature or result) was updated last time.
154 /// This method is called by the updater.
155 virtual void setUpdateID(const int theID) = 0;
158 /// Objects are created for features automatically
161 /// Returns true if "is in history" custom behaviors is defined for the feature
162 virtual bool isInHistory() = 0;
164 /// Defines the custom "is in history" behavior
165 virtual void setIsInHistory(const bool theFlag) = 0;
167 /// Returns true if object must be displayed in the viewer: flag is stored in the
168 /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps
169 /// the original state i nthe current transaction.
170 virtual bool isDisplayed() = 0;
172 /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
174 virtual void setDisplayed(const bool theDisplay) = 0;
176 friend class ModelAPI_Object;
179 typedef std::shared_ptr<ModelAPI_Data> DataPtr;