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