Salome HOME
73e00f663d6598a38e078c47053bb97782685854
[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 class QKeyEvent;
24
25 /*!
26  \class ModuleBase_Operation
27  * \brief Base class for all operations
28  *
29  *  Base class for all operations. If you perform an action it is reasonable to create
30  *  operation intended for this. This is a base class for all operations which provides
31  *  mechanism for correct starting operations, starting operations above already started
32  *  ones, committing operations and so on. To create own operation it is reasonable to
33  *  inherit it from this class and redefines virtual methods to provide own behavior
34  *  Main virtual methods are
35  *  - virtual bool      isReadyToStart();
36  *  - virtual void      startOperation();
37  *  - virtual void      abortOperation();
38  *  - virtual void      commitOperation();
39  */
40
41 class MODULEBASE_EXPORT ModuleBase_Operation: public ModuleBase_IOperation
42 {
43 Q_OBJECT
44
45 public:
46   /// Constructor
47   /// \param theId the operation identifier
48   /// \param theParent the QObject parent
49   ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
50   /// Destructor
51   virtual ~ModuleBase_Operation();
52
53   // Returns operations Id from it's description
54   QString id() const;
55   /// Returns the operation feature
56   /// \return the feature
57   boost::shared_ptr<ModelAPI_Feature> feature() const;
58
59   /// Returns whether the nested operations are enabled.
60   /// The state can depend on the operation current state.
61   /// \return enabled state
62   virtual bool isNestedOperationsEnabled() const;
63
64   // Data model methods.
65   /// Stores a real value in model.
66   /// \param theValue - to store
67   void storeReal(double theValue);
68   /// Stores a custom value in model.
69   void storeCustomValue();
70
71   virtual void keyReleased(std::string theName, QKeyEvent* theEvent) {};
72
73   /// Sets the operation feature
74   void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
75
76 protected:
77   /// Virtual method called when operation started (see start() method for more description)
78   /// Default impl calls corresponding slot and commits immediately.
79   virtual void startOperation();
80   /// Virtual method called when operation stopped - committed or aborted.
81   virtual void stopOperation();
82   /// Virtual method called when operation aborted (see abort() method for more description)
83   virtual void abortOperation();
84   /// Virtual method called when operation committed (see commit() method for more description)
85   virtual void commitOperation();
86   /// Virtual method called after operation committed (see commit() method for more description)
87   virtual void afterCommitOperation();
88
89   /// Send update message by loop
90   void flushUpdated();
91   /// Send created message by loop
92   void flushCreated();
93
94   /// Creates an operation new feature
95   /// \param theFlushMessage the flag whether the create message should be flushed
96   /// \returns the created feature
97   virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
98
99 private:
100   boost::shared_ptr<ModelAPI_Feature> myFeature; /// the operation feature to be handled
101 };
102
103 #endif