Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / ModelAPI / ModelAPI_Feature.h
1 // File:        ModelAPI_Feature.hxx
2 // Created:     21 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef ModelAPI_Feature_HeaderFile
6 #define ModelAPI_Feature_HeaderFile
7
8 #include "ModelAPI.h"
9 #include "ModelAPI_PluginManager.h"
10
11 #include <string>
12 #include <boost/shared_ptr.hpp>
13
14 class ModelAPI_Data;
15 class ModelAPI_Document;
16
17 /**\class ModelAPI_Feature
18  * \ingroup DataModel
19  * \brief Functionality of the model object: to update result,
20  * to initialize attributes, etc.
21  */
22 class ModelAPI_Feature
23 {
24   boost::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
25   boost::shared_ptr<ModelAPI_Document> myDoc; ///< document this feature belongs to
26
27 public:
28   /// Returns the kind of a feature (like "Point")
29   MODELAPI_EXPORT virtual const std::string& getKind() = 0;
30
31   /// Returns to which group in the document must be added feature
32   MODELAPI_EXPORT virtual const std::string& getGroup() = 0;
33
34   /// Request for initialization of data model of the feature: adding all attributes
35   MODELAPI_EXPORT virtual void initAttributes() = 0;
36
37   /// Computes or recomputes the result
38   MODELAPI_EXPORT virtual void execute() = 0;
39
40   /// Returns true if this feature must be displayed in the history (top level of Part tree)
41   MODELAPI_EXPORT virtual bool isInHistory() {return true;}
42
43   /// Returns true if this feature must not be created: this is just an action
44   /// that is not stored in the features history (like delete part).
45   MODELAPI_EXPORT virtual bool isAction() {return false;}
46
47   /// Returns the data manager of this feature
48   MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Data> data() {return myData;}
49
50   /// Must return document where the new feature must be added to
51   /// By default it is current document
52   MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> documentToAdd()
53   {return ModelAPI_PluginManager::get()->currentDocument();}
54
55   /// Returns document this feature belongs to
56   MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document()
57   {return myDoc;}
58
59   /// To virtually destroy the fields of successors
60   virtual ~ModelAPI_Feature() {}
61
62 protected:
63   /// Use plugin manager for features creation: this method is 
64   /// defined here only for SWIG-wrapping
65   ModelAPI_Feature()
66   {}
67
68   /// Sets the data manager of an object (document does)
69   MODELAPI_EXPORT virtual void setData(boost::shared_ptr<ModelAPI_Data> theData) 
70   {myData = theData;}
71   /// Sets the data manager of an object (document does)
72   MODELAPI_EXPORT void setDoc(boost::shared_ptr<ModelAPI_Document> theDoc) {myDoc = theDoc;}
73
74   friend class Model_Document;
75 };
76
77 //! Pointer on feature object
78 typedef boost::shared_ptr<ModelAPI_Feature> FeaturePtr;
79
80
81 #endif