1 // File: Model_Data.hxx
2 // Created: 21 Mar 2014
3 // Author: Mikhail PONIKAROV
9 #include <ModelAPI_Attribute.h>
10 #include <ModelAPI_AttributeBoolean.h>
11 #include <ModelAPI_AttributeDocRef.h>
12 #include <ModelAPI_AttributeDouble.h>
13 #include <ModelAPI_AttributeInteger.h>
14 #include <ModelAPI_AttributeRefAttr.h>
15 #include <ModelAPI_AttributeReference.h>
16 #include <ModelAPI_AttributeRefList.h>
17 #include <ModelAPI_AttributeString.h>
18 #include <ModelAPI_Data.h>
19 #include <ModelAPI_Feature.h>
20 #include <ModelAPI_Object.h>
22 #include <TDF_Label.hxx>
31 class ModelAPI_Attribute;
35 * \brief General object of the application that allows
36 * to get/set attributes from the document and compute result of an operation.
39 class Model_Data : public ModelAPI_Data
41 TDF_Label myLab; ///< label of the feature in the document
42 /// All attributes of the object identified by the attribute ID
43 std::map<std::string, std::shared_ptr<ModelAPI_Attribute> > myAttrs;
45 /// needed here to emit signal that object changed on change of the attribute
48 /// List of attributes referenced to owner (updated only during the transaction change)
49 std::set<AttributePtr> myRefsToMe;
53 /// Returns label of this feature
59 friend class Model_Document;
60 friend class Model_Update;
61 friend class Model_AttributeReference;
62 friend class Model_AttributeRefAttr;
63 friend class Model_AttributeRefList;
64 friend class Model_AttributeSelection;
67 /// Returns the name of the feature visible by the user in the object browser
68 MODEL_EXPORT virtual std::string name();
69 /// Defines the name of the feature visible by the user in the object browser
70 MODEL_EXPORT virtual void setName(const std::string& theName);
71 /// Returns the attribute that references to another document
72 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID);
73 /// Returns the attribute that contains real value with double precision
74 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
75 /// Returns the attribute that contains integer value
76 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeInteger>
77 integer(const std::string& theID);
78 /// Returns the attribute that contains reference to a feature
79 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeReference>
80 reference(const std::string& theID);
81 /// Returns the attribute that contains selection to a shape
82 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection>
83 selection(const std::string& theID);
84 /// Returns the attribute that contains selection to a shape
85 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelectionList>
86 selectionList(const std::string& theID);
87 /// Returns the attribute that contains reference to an attribute of a feature
88 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefAttr>
89 refattr(const std::string& theID);
90 /// Returns the attribute that contains list of references to features
91 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeRefList>
92 reflist(const std::string& theID);
93 /// Returns the attribute that contains boolean value
94 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeBoolean>
95 boolean(const std::string& theID);
96 /// Returns the attribute that contains real value with double precision
97 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeString>
98 string(const std::string& theID);
99 /// Returns the generic attribute by identifier
100 /// \param theID identifier of the attribute
101 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
102 /// Returns all attributes of the feature of the given type
103 /// or all attributes if "theType" is empty
104 MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Attribute> >
105 attributes(const std::string& theType);
106 /// Returns all attributes ids of the feature of the given type
107 /// or all attributes if "theType" is empty
108 MODEL_EXPORT virtual std::list<std::string> attributesIDs(const std::string& theType);
110 /// Identifier by the id (not fast, iteration by map)
111 /// \param theAttr attribute already created in this data
112 MODEL_EXPORT virtual const std::string& id(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
113 /// Returns true if data belongs to same features
114 MODEL_EXPORT virtual bool isEqual(const std::shared_ptr<ModelAPI_Data>& theData);
115 /// Returns true if it is correctly connected t othe data model
116 MODEL_EXPORT virtual bool isValid();
118 /// Returns the label where the shape must be stored (used in ResultBody)
119 TDF_Label& shapeLab()
124 /// Initializes object by the attributes: must be called just after the object is created
125 /// for each attribute of the object
126 /// \param theID identifier of the attribute that can be referenced by this ID later
127 /// \param theAttrType type of the created attribute (received from the type method)
128 MODEL_EXPORT virtual void addAttribute(const std::string& theID, const std::string theAttrType);
130 /// Useful method for "set" methods of the attributes: sends an UPDATE event and
131 /// makes attribute initialized
132 MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
134 /// Puts feature to the document data sub-structure
135 MODEL_EXPORT void setLabel(TDF_Label theLab);
137 /// Sets the object of this data
138 MODEL_EXPORT virtual void setObject(ObjectPtr theObject)
140 myObject = theObject;
143 /// Erases all the data from the data model
144 MODEL_EXPORT virtual void erase();
146 /// Stores the state of the object to execute it later accordingly
147 MODEL_EXPORT virtual void execState(const ModelAPI_ExecState theState);
149 /// Returns the state of the latest execution of the feature
150 MODEL_EXPORT virtual ModelAPI_ExecState execState();
152 /// Registers error during the execution, causes the ExecutionFailed state
153 MODEL_EXPORT virtual void setError(const std::string& theError);
155 /// Returns the identifier of feature-owner, unique in this document
156 MODEL_EXPORT virtual int featureId() const;
158 // returns all objects referenced to this
159 MODEL_EXPORT virtual const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
162 // removes all information about back references
163 void eraseBackReferences();
164 // adds a back reference (with identifier which attribute references to this object
165 void addBackReference(FeaturePtr theFeature, std::string theAttrID);
166 // returns all references by attributes of this data
167 // \param the returned list of pairs: id of referenced attribute and list of referenced objects
168 void referencesToObjects(std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);