Salome HOME
Updates for stability of application
[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 XGUI_OperationMgr
17  * \ingroup GUI
18  * \brief Operation manager. Servers to manupulate to the workshop operations. Contains a stack
19  * of started operations. In simple case, if only one operration is started, the stack contains
20  * one operation. It is possible for some kind of operations to start them above already
21  * started one. In that case, the previous active operation becames suspended, a new one - active.
22  * The new operation is added to the top of the stack. Then it is finished, it is removed from
23  * the stack and the previous operation is activated.
24  */
25 class XGUI_EXPORT XGUI_OperationMgr : public QObject
26 {
27   Q_OBJECT
28 public:
29   /// Constructor
30   /// \param theParent the parent
31   XGUI_OperationMgr(QObject* theParent);
32   /// Destructor
33   virtual ~XGUI_OperationMgr();
34
35   /// Returns the current operation or NULL
36   /// \return the current operation
37   ModuleBase_Operation* currentOperation() const;
38   /// Returns true is operation manager has at least one non-null operation.
39   bool hasOperation() const;
40   /// Returns number of operations in the stack
41   int operationsCount() const;
42   /// Start the operation and append it to the stack of operations
43   /// \param theOperation the started operation
44   /// \return the state whether the current operation is started
45   bool startOperation(ModuleBase_Operation* theOperation);
46
47   /// Abort the operation and append it to the stack of operations
48   /// \return the state whether the current operation is aborted
49   bool abortOperation();
50   ///Returns list of all operations IDs
51   QStringList operationList();
52
53 signals:
54   /// Signal about an operation is started. It is emitted after the start() of operation is done.
55   void operationStarted();
56   /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
57   /// \param theOperation a stopped operation
58   void operationStopped(ModuleBase_Operation* theOperation);
59   /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
60   void operationResumed();
61
62 protected:
63   /// Sets the current operation or NULL
64   /// \param theOperation the started operation
65   /// \param isCheckBeforeStart the flag whether to check whether the operation can be started
66   /// \return the state whether the operation is resumed
67   void resumeOperation(ModuleBase_Operation* theOperation);
68
69   /// Returns whether the operation can be started. Check if there is already started operation and
70   /// the granted parameter of the launched operation
71   /// \param theOperation an operation to check
72   bool canStartOperation(ModuleBase_Operation* theOperation);
73
74   /// Returns whether the operation can be stopped.
75   bool canStopOperation();
76
77 protected slots:
78   /// Slot that commits the current operation.
79   void onCommitOperation();
80   /// Slot that aborts the current operation.
81   void onAbortOperation();
82
83   /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
84   /// If there is a suspended operation, restart it.
85   void onOperationStopped();
86
87 private:
88   typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
89   Operations myOperations; ///< a stack of started operations. The active operation is on top,
90                            // others are suspended and started by the active is finished
91 };
92
93 #endif