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