Salome HOME
Make bodies list updated on undo/redo/open/abort
[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_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   {
35     static std::string MY_GROUP = "Features";
36     return MY_GROUP;
37   }
38
39   /// Returns the group identifier of this result
40   virtual std::string groupName()
41   {
42     return group();
43   }
44
45   /// Request for initialization of data model of the feature: adding all attributes
46   virtual void initAttributes() = 0;
47
48   /// Computes or recomputes the results
49   virtual void execute() = 0;
50
51   /// returns the current results of the feature
52   MODELAPI_EXPORT const std::list<boost::shared_ptr<ModelAPI_Result> >& results();
53   /// returns the first result in the list or NULL reference
54   MODELAPI_EXPORT boost::shared_ptr<ModelAPI_Result> firstResult();
55   /// sets the alone result
56   MODELAPI_EXPORT void setResult(const boost::shared_ptr<ModelAPI_Result>& theResult);
57   /// sets the result by index (zero based), results before this must be set before
58   MODELAPI_EXPORT void setResult(const boost::shared_ptr<ModelAPI_Result>& theResult,
59                                  const int theIndex);
60   /// removes the result from the feature
61   MODELAPI_EXPORT void removeResult(const boost::shared_ptr<ModelAPI_Result>& theResult);
62
63   /// Returns true if result is persistent (stored in document) and on undo-redo, save-open
64   /// it is not needed to recompute it.
65   virtual bool isPersistentResult() {return true;}
66
67   /// Returns true if this feature must not be created: this is just an action
68   /// that is not stored in the features history and data model (like "delete part").
69   virtual bool isAction()
70   {
71     return false;
72   }
73
74   /// Must return document where the new feature must be added to
75   /// By default it is current document
76   MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> documentToAdd();
77
78   /// To virtually destroy the fields of successors
79   MODELAPI_EXPORT virtual ~ModelAPI_Feature();
80
81   MODELAPI_EXPORT static boost::shared_ptr<ModelAPI_Feature> feature(ObjectPtr theObject);
82
83 };
84
85 //! Pointer on feature object
86 typedef boost::shared_ptr<ModelAPI_Feature> FeaturePtr;
87
88 #endif