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