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>
24 #include <boost/smart_ptr/shared_ptr.hpp>
30 class ModelAPI_Attribute;
34 * \brief General object of the application that allows
35 * to get/set attributes from the document and compute result of an operation.
38 class Model_Data : public ModelAPI_Data
40 TDF_Label myLab; ///< label of the feature in the document
41 /// All attributes of the object identified by the attribute ID
42 std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> > myAttrs;
44 /// needed here to emit signal that object changed on change of the attribute
49 /// Returns label of this feature
55 friend class Model_Document;
56 friend class Model_AttributeReference;
57 friend class Model_AttributeRefAttr;
58 friend class Model_AttributeRefList;
61 /// Returns the name of the feature visible by the user in the object browser
62 MODEL_EXPORT virtual std::string name();
63 /// Defines the name of the feature visible by the user in the object browser
64 MODEL_EXPORT virtual void setName(const std::string& theName);
65 /// Returns the attribute that references to another document
66 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID);
67 /// Returns the attribute that contains real value with double precision
68 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
69 /// Returns the attribute that contains integer value
70 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeInteger>
71 integer(const std::string& theID);
72 /// Returns the attribute that contains reference to a feature
73 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
74 reference(const std::string& theID);
75 /// Returns the attribute that contains selection to a shape
76 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection>
77 selection(const std::string& theID);
78 /// Returns the attribute that contains reference to an attribute of a feature
79 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
80 refattr(const std::string& theID);
81 /// Returns the attribute that contains list of references to features
82 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefList>
83 reflist(const std::string& theID);
84 /// Returns the attribute that contains boolean value
85 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeBoolean>
86 boolean(const std::string& theID);
87 /// Returns the attribute that contains real value with double precision
88 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeString>
89 string(const std::string& theID);
90 /// Returns the generic attribute by identifier
91 /// \param theID identifier of the attribute
92 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
93 /// Returns all attributes of the feature of the given type
94 /// or all attributes if "theType" is empty
95 MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
96 attributes(const std::string& theType);
97 /// Returns all attributes ids of the feature of the given type
98 /// or all attributes if "theType" is empty
99 MODEL_EXPORT virtual std::list<std::string> attributesIDs(const std::string& theType);
101 /// Identifier by the id (not fast, iteration by map)
102 /// \param theAttr attribute already created in this data
103 MODEL_EXPORT virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr);
104 /// Returns true if data belongs to same features
105 MODEL_EXPORT virtual bool isEqual(const boost::shared_ptr<ModelAPI_Data>& theData);
106 /// Returns true if it is correctly connected t othe data model
107 MODEL_EXPORT virtual bool isValid();
109 /// Returns the label where the shape must be stored (used in ResultBody)
110 TDF_Label& shapeLab()
115 /// Initializes object by the attributes: must be called just after the object is created
116 /// for each attribute of the object
117 /// \param theID identifier of the attribute that can be referenced by this ID later
118 /// \param theAttrType type of the created attribute (received from the type method)
119 MODEL_EXPORT virtual void addAttribute(const std::string& theID, const std::string theAttrType);
121 /// Useful method for "set" methods of the attributes: sends an UPDATE event and
122 /// makes attribute initialized
123 MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
125 /// Puts feature to the document data sub-structure
126 MODEL_EXPORT void setLabel(TDF_Label theLab);
128 /// Sets the object of this data
129 MODEL_EXPORT virtual void setObject(ObjectPtr theObject)
131 myObject = theObject;
134 MODEL_EXPORT virtual void erase();
136 /// Makes feature must be updated later (on rebuild). Normally the Updater must call it
137 /// in case of not-automatic update to true
138 MODEL_EXPORT virtual void mustBeUpdated(const bool theFlag);
140 /// Returns true if feature must be updated (re-executed) on rebuild
141 MODEL_EXPORT virtual bool mustBeUpdated();
143 /// Returns true if this data attributes are referenced to the given feature or its results
144 MODEL_EXPORT virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature);