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