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