Salome HOME
Merge remote-tracking branch 'origin/Dev_0.6'
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.h
1 // File:        XGUI_OperationMgr.h
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef XGUI_OperationMgr_H
6 #define XGUI_OperationMgr_H
7
8 #include "XGUI.h"
9
10 #include <ModuleBase_Operation.h>
11
12 #include <QList>
13 #include <QObject>
14 #include <QStringList>
15
16 class QKeyEvent;
17
18 /**\class XGUI_OperationMgr
19  * \ingroup GUI
20  * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
21  * of started operations. In simple case, if only one operation is started, the stack contains
22  * one operation. It is possible for some kind of operations to start them above already
23  * started one. In that case, the previous active operation becomes suspended, a new one - active.
24  * The new operation is added to the top of the stack. Then it is finished, it is removed from
25  * the stack and the previous operation is activated.
26  */
27 class XGUI_EXPORT XGUI_OperationMgr : public QObject
28 {
29 Q_OBJECT
30  public:
31   /// Constructor
32   /// \param theParent the parent
33   XGUI_OperationMgr(QObject* theParent);
34   /// Destructor
35   virtual ~XGUI_OperationMgr();
36
37   /// Returns the current operation or NULL
38   /// \return the current operation
39   ModuleBase_Operation* currentOperation() const;
40
41   /// Check if the given operation is active operation.
42   /// Also, returns false is ther is no active operation.
43   bool isCurrentOperation(ModuleBase_Operation* theOperation);
44
45   /// Returns true is operation manager has at least one non-null operation.
46   bool hasOperation() const;
47
48   /// Returns true is operation manager has an operation with given Id.
49   bool hasOperation(const QString& theId) const;
50
51   /// Find and return operation by its Id.
52   ModuleBase_Operation* findOperation(const QString& theId) const;
53
54   /// Returns number of operations in the stack
55   int operationsCount() const;
56
57   /// Returns list of all operations IDs
58   QStringList operationList() const;
59
60   /// Returns previous (parent) operation if given operation started.
61   /// else, or if there is no parent - returns NULL
62   ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
63
64   virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
65
66   /// Start the operation and append it to the stack of operations
67   /// \param theOperation the started operation
68   /// \return the state whether the current operation is started
69   bool startOperation(ModuleBase_Operation* theOperation);
70
71   bool abortAllOperations();
72
73   /// Returns whether the operation can be started. Check if there is already started operation and
74   /// the granted parameter of the launched operation
75   /// \param theId id of the operation which is going to start
76   bool canStartOperation(QString theId);
77
78   bool canStopOperation();
79
80   /// Returns true if the operation can be aborted
81   bool canAbortOperation();
82
83  public slots:
84   /// Slot that commits the current operation.
85   void onCommitOperation();
86   /// Slot that aborts the current operation.
87   void onAbortOperation();
88   /// Slot that validates the current operation using the validateOperation method.
89   void onValidateOperation();
90
91 signals:
92   /// Signal about an operation is started. It is emitted after the start() of operation is done.
93   void operationStarted(ModuleBase_Operation* theOperation);
94
95   /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
96   /// \param theOperation a stopped operation
97   void operationStopped(ModuleBase_Operation* theOperation);
98
99   /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
100   void operationResumed(ModuleBase_Operation* theOperation);
101
102   /// Emitted when current operation is comitted
103   void operationComitted(ModuleBase_Operation* theOperation);
104
105   /// Emitted when current operation is aborted
106   void operationAborted(ModuleBase_Operation* theOperation);
107
108   /// Signal is emitted after the validate methods calls.
109   void operationValidated(bool);
110
111   /// Signal is emitted after the key released click.
112   void keyEnterReleased();
113
114  protected:
115
116   /// Commits the current operatin if it is valid
117   bool commitOperation();
118   /// Sets the current operation or NULL
119   /// \param theOperation the started operation
120   /// \param isCheckBeforeStart the flag whether to check whether the operation can be started
121   /// \return the state whether the operation is resumed
122   void resumeOperation(ModuleBase_Operation* theOperation);
123
124  public slots:
125   /// SLOT, that is called by the key in the property panel is clicked.
126   /// \param theName the attribute name
127   /// \param theEvent the mouse event
128   bool onKeyReleased(QKeyEvent* theEvent);
129
130   protected slots:
131   /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
132   /// If there is a suspended operation, restart it.
133   void onOperationStopped();
134   void onOperationStarted();
135   void onOperationAborted();
136   void onOperationComitted();
137   void onOperationResumed();
138
139  private:
140   typedef QList<ModuleBase_Operation*> Operations;  ///< definition for a list of operations
141   Operations myOperations;  ///< a stack of started operations. The active operation is on top,
142                             // others are suspended and started by the active is finished
143 };
144
145 #endif