Salome HOME
daa59c05ca89f93762f514ff06d48b33f430af0d
[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_HeaderFile
6 #define ModelAPI_Feature_HeaderFile
7
8 #include "ModelAPI_Object.h"
9 #include "ModelAPI_PluginManager.h"
10
11 #include <string>
12 #include <list>
13 #include <boost/shared_ptr.hpp>
14
15 class ModelAPI_Data;
16 class ModelAPI_Document;
17 class ModelAPI_Result;
18
19 /**\class ModelAPI_Feature
20  * \ingroup DataModel
21  * \brief Feature function that represents the particular functionality
22  * of this operation. Produces results by the arguments.
23  */
24 class ModelAPI_Feature : public ModelAPI_Object
25 {
26   ///< list of current results of this feature
27   std::list<boost::shared_ptr<ModelAPI_Result> > myResults;
28 public:
29   /// Returns the unique kind of a feature (like "Point")
30   virtual const std::string& getKind() = 0;
31
32   /// Returns the group identifier of all features
33   static std::string group()
34     {static std::string MY_GROUP = "Features"; return MY_GROUP;}
35
36   /// Request for initialization of data model of the feature: adding all attributes
37   virtual void initAttributes() = 0;
38
39   /// Computes or recomputes the results
40   virtual void execute() = 0;
41
42   // returns the current results of the feature
43   std::list<boost::shared_ptr<ModelAPI_Result> >& results() {return myResults;}
44   // returns the first result in the list or NULL reference
45   boost::shared_ptr<ModelAPI_Result> firstResult() 
46   {return myResults.size() ? *(myResults.begin()) : boost::shared_ptr<ModelAPI_Result>();}
47
48   /// Returns true if this feature must not be created: this is just an action
49   /// that is not stored in the features history and data model (like "delete part").
50   virtual bool isAction() {return false;}
51
52   /// Must return document where the new feature must be added to
53   /// By default it is current document
54   virtual boost::shared_ptr<ModelAPI_Document> documentToAdd()
55   {return ModelAPI_PluginManager::get()->currentDocument();}
56
57   /// To virtually destroy the fields of successors
58   virtual ~ModelAPI_Feature() {}
59 };
60
61 //! Pointer on feature object
62 typedef boost::shared_ptr<ModelAPI_Feature> FeaturePtr;
63
64 #endif