1 // File: ModelAPI_Data.hxx
2 // Created: 21 Mar 2014
3 // Author: Mikhail PONIKAROV
5 #ifndef ModelAPI_Data_H_
6 #define ModelAPI_Data_H_
14 class ModelAPI_AttributeDocRef;
15 class ModelAPI_AttributeInteger;
16 class ModelAPI_AttributeDouble;
17 class ModelAPI_AttributeReference;
18 class ModelAPI_AttributeRefAttr;
19 class ModelAPI_AttributeRefList;
20 class ModelAPI_AttributeBoolean;
21 class ModelAPI_AttributeString;
22 class ModelAPI_Document;
23 class ModelAPI_Attribute;
24 class ModelAPI_Feature;
25 class ModelAPI_AttributeSelection;
26 class ModelAPI_AttributeSelectionList;
29 /// Enumeration that contains the execution status of the Object
30 enum ModelAPI_ExecState {
31 ModelAPI_StateDone, ///< execution was performed and result is up to date
32 ModelAPI_StateMustBeUpdated, ///< execution must be performed to obtain the up to date result
33 ModelAPI_StateExecFailed, ///< execution was failed (results are deleted in this case)
34 ModelAPI_StateInvalidArgument, ///< execution was not performed (results are deleted in this case)
35 ModelAPI_StateNothing ///< internal state that actually means that nothing must be changed
38 /**\class ModelAPI_Data
40 * \brief General object of the application that allows
41 * to get/set attributes from the document and compute result of an operation.
44 class MODELAPI_EXPORT ModelAPI_Data
48 /// Returns the name of the feature visible by the user in the object browser
49 virtual std::string name() = 0;
51 /// Defines the name of the feature visible by the user in the object browser
52 virtual void setName(const std::string& theName) = 0;
54 /// Returns the attribute that references to another document
55 virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID) = 0;
56 /// Returns the attribute that contains real value with double precision
57 virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID) = 0;
58 /// Returns the attribute that contains integer value
59 virtual std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
60 /// Returns the attribute that contains reference to a feature
61 virtual std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
62 /// Returns the attribute that contains selection to a shape
63 virtual std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
64 /// Returns the attribute that contains selection to a shape
65 virtual std::shared_ptr<ModelAPI_AttributeSelectionList>
66 selectionList(const std::string& theID) = 0;
67 /// Returns the attribute that contains reference to an attribute of a feature
68 virtual std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
69 /// Returns the attribute that contains list of references to features
70 virtual std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID) = 0;
71 /// Returns the attribute that contains boolean value
72 virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
73 /// Returns the attribute that contains boolean value
74 virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
76 /// Returns the generic attribute by identifier
77 /// \param theID identifier of the attribute
78 virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID) = 0;
79 /// Returns all attributes of the feature of the given type
80 /// or all attributes if "theType" is empty
81 virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
82 attributes(const std::string& theType) = 0;
83 /// Returns all attributes ids of the feature of the given type
84 /// or all attributes if "theType" is empty
85 virtual std::list<std::string> attributesIDs(const std::string& theType) = 0;
86 /// Identifier by the id (not fast, iteration by map)
87 /// \param theAttr attribute already created in this data
88 virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr) = 0;
89 /// Returns true if data belongs to same features
90 virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData) = 0;
91 /// Returns true if it is correctly connected to the data model
92 virtual bool isValid() = 0;
94 /// Initializes object by the attributes: must be called just after the object is created
95 /// for each attribute of the object
96 /// \param theID identifier of the attribute that can be referenced by this ID later
97 /// \param theAttrType type of the created attribute (received from the type method)
98 virtual void addAttribute(const std::string& theID, const std::string theAttrType) = 0;
100 /// Useful method for "set" methods of the attributes: sends an UPDATE event and
101 /// makes attribute initialized
102 virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
104 /// Erases all the data from the data model
105 virtual void erase() = 0;
107 /// To virtually destroy the fields of successors
108 virtual ~ModelAPI_Data()
112 /// Stores the state of the object to execute it later accordingly
113 virtual void execState(const ModelAPI_ExecState theState) = 0;
115 /// Returns the state of the latest execution of the feature
116 virtual ModelAPI_ExecState execState() = 0;
118 /// Registers error during the execution, causes the ExecutionFailed state
119 virtual void setError(const std::string& theError) = 0;
121 /// Returns the identifier of feature-owner, unique in this document
122 virtual int featureId() const = 0;
124 // returns all objects referenced to this
125 virtual const std::set<std::shared_ptr<ModelAPI_Attribute> >& refsToMe() = 0;
128 /// Objects are created for features automatically
134 typedef std::shared_ptr<ModelAPI_Data> DataPtr;