1 // File: Model_Data.hxx
2 // Created: 21 Mar 2014
3 // Author: Mikhail PONIKAROV
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Feature.h>
11 #include <TDF_Label.hxx>
15 class ModelAPI_Attribute;
19 * \brief General object of the application that allows
20 * to get/set attributes from the document and compute result of an operation.
23 class Model_Data : public ModelAPI_Data
25 TDF_Label myLab; ///< label of the feature in the document
26 /// All attributes of the object identified by the attribute ID
27 std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> > myAttrs;
29 /// needed here to emit signal that object changed on change of the attribute
34 /// Returns label of this feature
40 friend class Model_Document;
41 friend class Model_AttributeReference;
42 friend class Model_AttributeRefAttr;
43 friend class Model_AttributeRefList;
46 /// Returns the name of the feature visible by the user in the object browser
47 MODEL_EXPORT virtual std::string name();
48 /// Defines the name of the feature visible by the user in the object browser
49 MODEL_EXPORT virtual void setName(const std::string& theName);
50 /// Returns the attribute that references to another document
51 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string& theID);
52 /// Returns the attribute that contains real value with double precision
53 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
54 /// Returns the attribute that contains reference to a feature
55 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
56 reference(const std::string& theID);
57 /// Returns the attribute that contains reference to an attribute of a feature
58 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
59 refattr(const std::string& theID);
60 /// Returns the attribute that contains list of references to features
61 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefList>
62 reflist(const std::string& theID);
63 /// Returns the attribute that contains boolean value
64 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeBoolean>
65 boolean(const std::string& theID);
66 /// Returns the generic attribute by identifier
67 /// \param theID identifier of the attribute
68 MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
69 /// Returns all attributes ofthe feature of the given type
70 /// or all attributes if "theType" is empty
71 MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
72 attributes(const std::string& theType);
74 /// Identifier by the id (not fast, iteration by map)
75 /// \param theAttr attribute already created in this data
76 MODEL_EXPORT virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr);
77 /// Returns true if data belongs to same features
78 MODEL_EXPORT virtual bool isEqual(const boost::shared_ptr<ModelAPI_Data>& theData);
79 /// Returns true if it is correctly connected t othe data model
80 MODEL_EXPORT virtual bool isValid();
82 /// Returns the label where the shape must be stored (used in ResultBody)
88 /// Initializes object by the attributes: must be called just after the object is created
89 /// for each attribute of the object
90 /// \param theID identifier of the attribute that can be referenced by this ID later
91 /// \param theAttrType type of the created attribute (received from the type method)
92 MODEL_EXPORT virtual void addAttribute(const std::string& theID, const std::string theAttrType);
94 /// Useful method for "set" methods of the attributes: sends an UPDATE event and
95 /// makes attribute initialized
96 MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
98 /// Puts feature to the document data sub-structure
99 MODEL_EXPORT void setLabel(TDF_Label theLab);
101 /// Sets the object of this data
102 MODEL_EXPORT virtual void setObject(ObjectPtr theObject)
104 myObject = theObject;