Salome HOME
Resolve crashes in the release mode under Debian Squeeze linux
[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   /// Registers error during the execution, causes the ExecutionFailed state
59   virtual void setError(const std::string& theError) {
60     data()->setError(theError);
61   }
62
63   /// returns the current results of the feature
64   MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_Result> >& results();
65   /// returns the first result in the list or NULL reference
66   MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> firstResult();
67   /// returns the last result in the list or NULL reference
68   MODELAPI_EXPORT std::shared_ptr<ModelAPI_Result> lastResult();
69   /// sets the alone result
70   MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult);
71   /// sets the result by index (zero based), results before this must be set before
72   MODELAPI_EXPORT void setResult(const std::shared_ptr<ModelAPI_Result>& theResult,
73                                  const int theIndex);
74   /// removes the result from the feature
75   MODELAPI_EXPORT void removeResult(const std::shared_ptr<ModelAPI_Result>& theResult);
76   /// removes all results from the feature
77   MODELAPI_EXPORT void eraseResults();
78   /// removes all fields from this feature: results, data, etc
79   MODELAPI_EXPORT virtual void erase();
80
81   /// Returns true if result is persistent (stored in document) and on undo-redo, save-open
82   /// it is not needed to recompute it.
83   virtual bool isPersistentResult() {return true;}
84
85   /// Returns true if this feature must not be created: this is just an action
86   /// that is not stored in the features history and data model (like "delete part").
87   virtual bool isAction()
88   {
89     return false;
90   }
91
92   /// Must return document where the new feature must be added to
93   /// By default it is current document
94   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Document> documentToAdd();
95
96   /// To virtually destroy the fields of successors
97   MODELAPI_EXPORT virtual ~ModelAPI_Feature();
98
99   MODELAPI_EXPORT static std::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
100
101  //
102  // Helper methods, aliases for data()->method()
103  // -----------------------------------------------------------------------------------------------
104   inline std::string name()
105   {
106     return data()->name();
107   }
108
109   inline std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID)
110   {
111     return data()->boolean(theID);
112   }
113
114   inline std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID)
115   {
116     return data()->document(theID);
117   }
118
119   inline std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID)
120   {
121     return data()->real(theID);
122   }
123
124   inline std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID)
125   {
126     return data()->integer(theID);
127   }
128
129   inline std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
130   {
131     return data()->refattr(theID);
132   }
133
134   inline std::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID)
135   {
136     return data()->reference(theID);
137   }
138
139   inline std::shared_ptr<ModelAPI_AttributeRefList> reflist(const std::string& theID)
140   {
141     return data()->reflist(theID);
142   }
143
144   inline std::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID)
145   {
146     return data()->selection(theID);
147   }
148
149   inline std::shared_ptr<ModelAPI_AttributeSelectionList> selectionList(const std::string& theID)
150   {
151     return data()->selectionList(theID);
152   }
153
154   inline std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID)
155   {
156     return data()->string(theID);
157   }
158
159   inline std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
160   {
161     return data()->attribute(theID);
162   }
163  // -----------------------------------------------------------------------------------------------
164 };
165
166 //! Pointer on feature object
167 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
168
169 #endif
170