]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_Data.h
Salome HOME
The list of selection attributes is added
[modules/shaper.git] / src / Model / Model_Data.h
1 // File:        Model_Data.hxx
2 // Created:     21 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef Model_Data_H_
6 #define Model_Data_H_
7
8 #include <Model.h>
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>
21
22 #include <TDF_Label.hxx>
23
24 #include <boost/smart_ptr/shared_ptr.hpp>
25
26 #include <map>
27 #include <list>
28 #include <string>
29
30 class ModelAPI_Attribute;
31
32 /**\class Model_Data
33  * \ingroup DataModel
34  * \brief General object of the application that allows
35  * to get/set attributes from the document and compute result of an operation.
36  */
37
38 class Model_Data : public ModelAPI_Data
39 {
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;
43
44   /// needed here to emit signal that object changed on change of the attribute
45   ObjectPtr myObject;
46
47   Model_Data();
48
49   /// Returns label of this feature
50   TDF_Label label()
51   {
52     return myLab;
53   }
54
55   friend class Model_Document;
56   friend class Model_AttributeReference;
57   friend class Model_AttributeRefAttr;
58   friend class Model_AttributeRefList;
59   friend class Model_AttributeSelection;
60
61  public:
62   /// Returns the name of the feature visible by the user in the object browser
63   MODEL_EXPORT virtual std::string name();
64   /// Defines the name of the feature visible by the user in the object browser
65   MODEL_EXPORT virtual void setName(const std::string& theName);
66   /// Returns the attribute that references to another document
67   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID);
68   /// Returns the attribute that contains real value with double precision
69   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
70   /// Returns the attribute that contains integer value
71   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeInteger>
72     integer(const std::string& theID);
73   /// Returns the attribute that contains reference to a feature
74   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
75     reference(const std::string& theID);
76   /// Returns the attribute that contains selection to a shape
77   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection>
78     selection(const std::string& theID);
79   /// Returns the attribute that contains selection to a shape
80   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelectionList> 
81     selectionList(const std::string& theID);
82   /// Returns the attribute that contains reference to an attribute of a feature
83   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
84     refattr(const std::string& theID);
85   /// Returns the attribute that contains list of references to features
86   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefList>
87     reflist(const std::string& theID);
88   /// Returns the attribute that contains boolean value
89   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeBoolean>
90     boolean(const std::string& theID);
91   /// Returns the attribute that contains real value with double precision
92   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeString>
93     string(const std::string& theID);
94   /// Returns the generic attribute by identifier
95   /// \param theID identifier of the attribute
96   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
97   /// Returns all attributes of the feature of the given type
98   /// or all attributes if "theType" is empty
99   MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
100     attributes(const std::string& theType);
101   /// Returns all attributes ids of the feature of the given type
102   /// or all attributes if "theType" is empty
103   MODEL_EXPORT virtual std::list<std::string> attributesIDs(const std::string& theType);
104
105   /// Identifier by the id (not fast, iteration by map)
106   /// \param theAttr attribute already created in this data
107   MODEL_EXPORT virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute>& theAttr);
108   /// Returns true if data belongs to same features
109   MODEL_EXPORT virtual bool isEqual(const boost::shared_ptr<ModelAPI_Data>& theData);
110   /// Returns true if it is correctly connected t othe data model
111   MODEL_EXPORT virtual bool isValid();
112
113   /// Returns the label where the shape must be stored (used in ResultBody)
114   TDF_Label& shapeLab()
115   {
116     return myLab;
117   }
118
119   /// Initializes object by the attributes: must be called just after the object is created
120   /// for each attribute of the object
121   /// \param theID identifier of the attribute that can be referenced by this ID later
122   /// \param theAttrType type of the created attribute (received from the type method)
123   MODEL_EXPORT virtual void addAttribute(const std::string& theID, const std::string theAttrType);
124
125   /// Useful method for "set" methods of the attributes: sends an UPDATE event and
126   /// makes attribute initialized
127   MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
128
129   /// Puts feature to the document data sub-structure
130   MODEL_EXPORT void setLabel(TDF_Label theLab);
131
132   /// Sets the object of this data
133   MODEL_EXPORT virtual void setObject(ObjectPtr theObject)
134   {
135     myObject = theObject;
136   }
137
138   MODEL_EXPORT virtual void erase();
139
140   /// Makes feature must be updated later (on rebuild). Normally the Updater must call it
141   /// in case of not-automatic update to true
142   MODEL_EXPORT virtual void mustBeUpdated(const bool theFlag);
143
144   /// Returns true if feature must be updated (re-executed) on rebuild
145   MODEL_EXPORT virtual bool mustBeUpdated();
146
147   /// Returns true if this data attributes are referenced to the given feature or its results
148   MODEL_EXPORT virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature);
149 };
150
151 #endif