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_
10 #ifdef _WINDOWS // to avoid too long decorated name warning
11 #pragma warning( disable : 4503 )
20 class ModelAPI_Attribute;
21 class ModelAPI_AttributeDocRef;
22 class ModelAPI_AttributeInteger;
23 class ModelAPI_AttributeDouble;
24 class ModelAPI_AttributeReference;
25 class ModelAPI_AttributeRefAttr;
26 class ModelAPI_AttributeRefList;
27 class ModelAPI_AttributeBoolean;
28 class ModelAPI_AttributeString;
29 class ModelAPI_Document;
30 class ModelAPI_Attribute;
31 class ModelAPI_Feature;
32 class ModelAPI_AttributeSelection;
33 class ModelAPI_AttributeSelectionList;
34 class ModelAPI_AttributeIntArray;
35 class ModelAPI_Object;
38 /// Enumeration that contains the execution status of the Object
39 enum ModelAPI_ExecState {
40 ModelAPI_StateDone, ///< execution was performed and result is up to date
41 ModelAPI_StateMustBeUpdated, ///< execution must be performed to obtain the up to date result
42 ModelAPI_StateExecFailed, ///< execution was failed (results are deleted in this case)
43 ModelAPI_StateInvalidArgument, ///< execution was not performed (results are deleted in this case)
44 ModelAPI_StateNothing ///< internal state that actually means that nothing must be changed
47 /**\class ModelAPI_Data
49 * \brief General object of the application that allows
50 * to get/set attributes from the document and compute result of an operation.
53 class MODELAPI_EXPORT ModelAPI_Data
57 /// Returns the name of the feature visible by the user in the object browser
58 virtual std::string name() = 0;
60 /// Defines the name of the feature visible by the user in the object browser
61 virtual void setName(const std::string& theName) = 0;
63 /// Returns the attribute that references to another document
64 virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID) = 0;
65 /// Returns the attribute that contains real value with double precision
66 virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID) = 0;
67 /// Returns the attribute that contains integer value
68 virtual std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
69 /// Returns the attribute that contains reference to a feature
70 virtual std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
71 /// Returns the attribute that contains selection to a shape
72 virtual std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
73 /// Returns the attribute that contains selection to a shape
74 virtual std::shared_ptr<ModelAPI_AttributeSelectionList>
75 selectionList(const std::string& theID) = 0;
76 /// Returns the attribute that contains reference to an attribute of a feature
77 virtual std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
78 /// Returns the attribute that contains list of references to features
79 virtual std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID) = 0;
80 /// Returns the attribute that contains boolean value
81 virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
82 /// Returns the attribute that contains boolean value
83 virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
84 /// Returns the attribute that contains integer values array
85 virtual std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID) = 0;
87 /// Returns the generic attribute by identifier
88 /// \param theID identifier of the attribute
89 virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID) = 0;
90 /// Returns all attributes of the feature of the given type
91 /// or all attributes if "theType" is empty
92 virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
93 attributes(const std::string& theType) = 0;
94 /// Returns all attributes ids of the feature of the given type
95 /// or all attributes if "theType" is empty
96 virtual std::list<std::string> attributesIDs(const std::string& theType) = 0;
97 /// Identifier by the id (not fast, iteration by map)
98 /// \param theAttr attribute already created in this data
99 virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr) = 0;
100 /// Returns true if data belongs to same features
101 virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData) = 0;
102 /// Returns true if it is correctly connected to the data model
103 virtual bool isValid() = 0;
105 /// Initializes object by the attributes: must be called just after the object is created
106 /// for each attribute of the object
107 /// \param theID identifier of the attribute that can be referenced by this ID later
108 /// \param theAttrType type of the created attribute (received from the type method)
109 /// \returns the just created attribute
110 virtual std::shared_ptr<ModelAPI_Attribute>
111 addAttribute(const std::string& theID, const std::string theAttrType) = 0;
113 /// Useful method for "set" methods of the attributes: sends an UPDATE event and
114 /// makes attribute initialized
115 virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
116 /// Blocks sending "attribute updated" if theBlock is true
117 virtual void blockSendAttributeUpdated(const bool theBlock) = 0;
119 /// Erases all the data from the data model
120 virtual void erase() = 0;
122 /// To virtually destroy the fields of successors
123 virtual ~ModelAPI_Data();
125 /// Stores the state of the object to execute it later accordingly
126 virtual void execState(const ModelAPI_ExecState theState) = 0;
128 /// Returns the state of the latest execution of the feature
129 virtual ModelAPI_ExecState execState() = 0;
131 /// Registers error during the execution, causes the ExecutionFailed state
132 virtual void setError(const std::string& theError, bool theSend = true) = 0;
134 /// Returns error, arose during the execution
135 virtual std::string error() const = 0;
137 /// Returns the identifier of feature-owner, unique in this document
138 virtual int featureId() const = 0;
140 /// returns all objects referenced to this
141 virtual const std::set<std::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
143 /// returns all references by attributes of this data
144 /// \param theRefs returned list of pairs: id of referenced attribute and list of referenced objects
145 virtual void referencesToObjects(
146 std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > >& theRefs) =0;
148 /// Copies all attributes content into theTarget data
149 virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget) = 0;
151 /// Returns the invalid data pointer (to avoid working with NULL shared ptrs in swig)
152 virtual std::shared_ptr<ModelAPI_Data> invalidPtr() = 0;
154 /// Identifier of the transaction when object (feature or result) was updated last time.
155 virtual int updateID() = 0;
157 /// Identifier of the transaction when object (feature or result) was updated last time.
158 /// This method is called by the updater.
159 virtual void setUpdateID(const int theID) = 0;
161 /// Returns the owner of htis data
162 virtual std::shared_ptr<ModelAPI_Object> owner() = 0;
165 /// Objects are created for features automatically
168 /// Returns true if "is in history" custom behaviors is defined for the feature
169 virtual bool isInHistory() = 0;
171 /// Defines the custom "is in history" behavior
172 virtual void setIsInHistory(const bool theFlag) = 0;
174 /// Returns true if object must be displayed in the viewer: flag is stored in the
175 /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps
176 /// the original state i nthe current transaction.
177 virtual bool isDisplayed() = 0;
179 /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
181 virtual void setDisplayed(const bool theDisplay) = 0;
183 friend class ModelAPI_Object;
186 typedef std::shared_ptr<ModelAPI_Data> DataPtr;