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