Salome HOME
Fix of activation/deactivation of documents
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.h
1 /*
2  * ModuleBase_Operation.h
3  *
4  *  Created on: Apr 2, 2014
5  *      Author: sbh
6  */
7
8
9 #ifndef ModuleBase_Operation_H
10 #define ModuleBase_Operation_H
11
12 #include <ModuleBase.h>
13 #include <ModuleBase_IOperation.h>
14
15 #include <QObject>
16 #include <QString>
17
18 #include <boost/shared_ptr.hpp>
19
20 class ModelAPI_Feature;
21 class ModelAPI_Document;
22
23 /*!
24  \class ModuleBase_Operation
25  * \brief Base class for all operations
26  *
27  *  Base class for all operations. If you perform an action it is reasonable to create
28  *  operation intended for this. This is a base class for all operations which provides
29  *  mechanism for correct starting operations, starting operations above already started
30  *  ones, committing operations and so on. To create own operation it is reasonable to
31  *  inherit it from this class and redefines virtual methods to provide own behavior
32  *  Main virtual methods are
33  *  - virtual bool      isReadyToStart();
34  *  - virtual void      startOperation();
35  *  - virtual void      abortOperation();
36  *  - virtual void      commitOperation();
37  */
38
39 class MODULEBASE_EXPORT ModuleBase_Operation: public ModuleBase_IOperation
40 {
41 Q_OBJECT
42
43 public:
44   /// Constructor
45   /// \param theId the operation identifier
46   /// \param theParent the QObject parent
47   ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
48   /// Destructor
49   virtual ~ModuleBase_Operation();
50
51   // Returns operations Id from it's description
52   QString id() const;
53   /// Returns the operation feature
54   /// \return the feature
55   boost::shared_ptr<ModelAPI_Feature> feature() const;
56
57   /// Returns whether the nested operations are enabled.
58   /// The state can depend on the operation current state.
59   /// \return enabled state
60   virtual bool isNestedOperationsEnabled() const;
61
62   // Data model methods.
63   /// Stores a real value in model.
64   /// \param theValue - to store
65   void storeReal(double theValue);
66   /// Stores a custom value in model.
67   void storeCustomValue();
68
69 protected:
70   /// Virtual method called when operation started (see start() method for more description)
71   /// Default impl calls corresponding slot and commits immediately.
72   virtual void startOperation();
73   /// Virtual method called when operation stopped - committed or aborted.
74   virtual void stopOperation();
75   /// Virtual method called when operation aborted (see abort() method for more description)
76   virtual void abortOperation();
77   /// Virtual method called when operation committed (see commit() method for more description)
78   virtual void commitOperation();
79
80   /// Send update message by loop
81   void flushUpdated();
82   /// Send created message by loop
83   void flushCreated();
84
85   /// Creates an operation new feature
86   /// \param theFlushMessage the flag whether the create message should be flushed
87   /// \returns the created feature
88   virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
89
90   /// Returns the operation feature
91   /// \return the feature
92   void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
93
94 private:
95   boost::shared_ptr<ModelAPI_Feature> myFeature; /// the operation feature to be handled
96 };
97
98 #endif