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