Salome HOME
Merge branch 'master' of newgeom:newgeom.git into BR_PYTHON_PLUGIN
[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_H_
6 #define ModelAPI_Feature_H_
7
8 #include <ModelAPI.h>
9 #include <ModelAPI_Object.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_Document.h>
12
13 #include <memory>
14
15 #include <list>
16 #include <string>
17
18 /**\class ModelAPI_Feature
19  * \ingroup DataModel
20  * \brief Feature function that represents the particular functionality
21  * of this operation. Produces results by the arguments.
22  */
23 class ModelAPI_Feature : public ModelAPI_Object
24 {
25   ///< list of current results of this feature
26   std::list<std::shared_ptr<ModelAPI_Result> > myResults;
27  public:
28   /// Returns the unique kind of a feature (like "Point")
29   virtual const std::string& getKind() = 0;
30
31   /// Returns the group identifier of all features
32   static std::string group()
33   {
34     static std::string MY_GROUP = "Features";
35     return MY_GROUP;
36   }
37
38   /// Returns document this feature belongs to
39   virtual std::shared_ptr<ModelAPI_Document> document() const
40   {
41     return ModelAPI_Object::document();
42   }
43
44   /// Returns the group identifier of this result
45   virtual std::string groupName()
46   {
47     return group();
48   }
49
50   /// Request for initialization of data model of the feature: adding all attributes
51   virtual void initAttributes() = 0;
52
53   /// Computes or recomputes the results
54   virtual void execute() = 0;
55
56   /// returns the current results of the feature
57   MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_Result> >& results();
58   /// returns the first result in the list or NULL reference
59   MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> firstResult();
60   /// returns the last result in the list or NULL reference
61   MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> lastResult();
62   /// sets the alone result
63   MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult);
64   /// sets the result by index (zero based), results before this must be set before
65   MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult,
66                                  const int theIndex);
67   /// removes the result from the feature
68   MODELAPI_EXPORT void removeResult(const std::shared_ptr<ModelAPI_Result>& theResult);
69   /// removes all results from the feature
70   MODELAPI_EXPORT void eraseResults();
71   /// removes all fields from this feature: results, data, etc
72   MODELAPI_EXPORT virtual void erase();
73
74   /// Returns true if result is persistent (stored in document) and on undo-redo, save-open
75   /// it is not needed to recompute it.
76   virtual bool isPersistentResult() {return true;}
77
78   /// Returns true if this feature must not be created: this is just an action
79   /// that is not stored in the features history and data model (like "delete part").
80   virtual bool isAction()
81   {
82     return false;
83   }
84
85   /// Must return document where the new feature must be added to
86   /// By default it is current document
87   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> documentToAdd();
88
89   /// To virtually destroy the fields of successors
90   MODELAPI_EXPORT virtual ~ModelAPI_Feature();
91
92   MODELAPI_EXPORT static std::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
93
94  //
95  // Helper methods, aliases for data()->method()
96  // -----------------------------------------------------------------------------------------------
97   inline std::string name()
98   {
99     return data()->name();
100   }
101
102   inline std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
103   {
104     return data()->boolean(theID);
105   }
106
107   inline std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
108   {
109     return data()->document(theID);
110   }
111
112   inline std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
113   {
114     return data()->real(theID);
115   }
116
117   inline std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
118   {
119     return data()->integer(theID);
120   }
121
122   inline std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
123   {
124     return data()->refattr(theID);
125   }
126
127   inline std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
128   {
129     return data()->reference(theID);
130   }
131
132   inline std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
133   {
134     return data()->reflist(theID);
135   }
136
137   inline std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
138   {
139     return data()->selection(theID);
140   }
141
142   inline std::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
143   {
144     return data()->selectionList(theID);
145   }
146
147   inline std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
148   {
149     return data()->string(theID);
150   }
151
152   inline std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
153   {
154     return data()->attribute(theID);
155   }
156  // -----------------------------------------------------------------------------------------------
157 };
158
159 //! Pointer on feature object
160 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
161
162 #endif
163