Salome HOME
Merge branch 'master' of newgeom:newgeom
[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_HeaderFile
6 #define Model_Data_HeaderFile
7
8 #include "Model.h"
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Feature.h>
11 #include <TDF_Label.hxx>
12
13 #include <map>
14
15 class ModelAPI_Attribute;
16
17 /**\class Model_Data
18  * \ingroup DataModel
19  * \brief General object of the application that allows
20  * to get/set attributes from the document and compute result of an operation.
21  */
22
23 class Model_Data: public ModelAPI_Data
24 {
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;
28
29   /// needed here to emit signal that feature changed on change of the attribute
30   FeaturePtr myFeature;
31
32   Model_Data();
33
34   /// Returns label of this feature
35   TDF_Label label() {return myLab;}
36
37   friend class Model_Document;
38   friend class Model_AttributeReference;
39   friend class Model_AttributeRefAttr;
40   friend class Model_AttributeRefList;
41
42 public:
43   /// Returns the name of the feature visible by the user in the object browser
44   MODEL_EXPORT virtual std::string getName();
45   /// Defines the name of the feature visible by the user in the object browser
46   MODEL_EXPORT virtual void setName(std::string theName);
47   /// Returns the attribute that references to another document
48   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDocRef> docRef(const std::string theID);
49   /// Returns the attribute that contains real value with double precision
50   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeDouble> real(const std::string theID);
51   /// Returns the attribute that contains reference to a feature
52   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference> 
53     reference(const std::string theID);
54   /// Returns the attribute that contains reference to an attribute of a feature
55   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
56     refattr(const std::string theID);
57   /// Returns the attribute that contains list of references to features
58   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefList> 
59     reflist(const std::string theID);
60   /// Returns the attribute that contains boolean value
61   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeBoolean> 
62     boolean(const std::string theID);
63   /// Returns the generic attribute by identifier
64   /// \param theID identifier of the attribute
65   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attribute(const std::string theID);
66   /// Returns all attributes ofthe feature of the given type
67   /// or all attributes if "theType" is empty
68   MODEL_EXPORT virtual std::list<boost::shared_ptr<ModelAPI_Attribute> >
69     attributes(const std::string theType);
70
71   /// Identifier by the id (not fast, iteration by map)
72   /// \param theAttr attribute already created in this data
73   MODEL_EXPORT virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute> theAttr);
74   /// Returns true if data belongs to same features
75   MODEL_EXPORT virtual bool isEqual(const boost::shared_ptr<ModelAPI_Data> theData);
76   /// Returns true if it is correctly connected t othe data model
77   MODEL_EXPORT virtual bool isValid();
78
79   /// Stores the shape (called by the execution method).
80   MODEL_EXPORT virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape);
81   /// Returns the shape-result produced by this feature
82   MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
83
84   /// Initializes object by the attributes: must be called just after the object is created
85   /// for each attribute of the object
86   /// \param theID identifier of the attribute that can be referenced by this ID later
87   /// \param theAttrType type of the created attribute (received from the type method)
88   MODEL_EXPORT virtual void addAttribute(std::string theID, std::string theAttrType);
89
90   /// Useful method for "set" methods of the attributes: sends an UPDATE event and
91   /// makes attribute initialized
92   MODEL_EXPORT virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr);
93
94   /// Puts feature to the document data sub-structure
95   MODEL_EXPORT void setLabel(TDF_Label& theLab);
96
97   /// Sets the feature of this data
98   MODEL_EXPORT virtual void setFeature(FeaturePtr theFeature)
99     {myFeature = theFeature;}
100 };
101
102 #endif