Salome HOME
5ea3af47cfd2b36fc3013142bbb1ad614f02a901
[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 ModuleBase_IWorkshop;
21 class XGUI_Workshop;
22
23 /**\class XGUI_OperationMgr
24  * \ingroup GUI
25  * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
26  * of started operations. In simple case, if only one operation is started, the stack contains
27  * one operation. It is possible for some kind of operations to start them above already
28  * started one. In that case, the previous active operation becomes suspended, a new one - active.
29  * The new operation is added to the top of the stack. Then it is finished, it is removed from
30  * the stack and the previous operation is activated.
31  */
32 class XGUI_EXPORT XGUI_OperationMgr : public QObject
33 {
34 Q_OBJECT
35  public:
36   /// Constructor
37   /// \param theParent the parent
38   /// \param theWorkshop a reference to workshop
39   XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop);
40
41   /// Destructor
42   virtual ~XGUI_OperationMgr();
43
44   /// Set reference to workshop
45   /// \param theWorkshop reference to workshop
46   void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
47   { myWorkshop = theWorkshop; };
48
49   /// Returns the current operation or NULL
50   /// \return the current operation
51   ModuleBase_Operation* currentOperation() const;
52
53   /// Check if the given operation is active operation.
54   /// Also, returns false is ther is no active operation.
55   bool isCurrentOperation(ModuleBase_Operation* theOperation);
56
57   /// Returns true is operation manager has at least one non-null operation.
58   bool hasOperation() const;
59
60   /// Returns true is operation manager has an operation with given Id.
61   bool hasOperation(const QString& theId) const;
62
63   /// Returns true if the operation can be aborted. If the operation is modified,
64   /// the warning message box is shown.
65   /// \param theOperation an operation which is checked on stop
66   bool canStopOperation(ModuleBase_Operation* theOperation);
67
68   /// Find and return operation by its Id.
69   ModuleBase_Operation* findOperation(const QString& theId) const;
70
71   /// Returns number of operations in the stack
72   int operationsCount() const;
73
74   /// Returns list of all operations IDs
75   QStringList operationList() const;
76
77   /// Returns previous (parent) operation if given operation started.
78   /// else, or if there is no parent - returns NULL
79   ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
80
81   /// Redefinition of virtual function
82   virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
83
84   /// Start the operation and append it to the stack of operations
85   /// \param theOperation the started operation
86   /// \return the state whether the current operation is started
87   bool startOperation(ModuleBase_Operation* theOperation);
88
89   /// Returns whether the operation can be started. Check if there is already started operation and
90   /// the granted parameter of the launched operation
91   /// \param theId id of the operation which is going to start
92   /// \param isAdditionallyGranted a boolean flag whether the id operation is granted in the previous one
93   bool canStartOperation(const QString& theId, const bool isAdditionallyGranted = false);
94
95   /// Aborts the parameter operation if it is current, else abort operations from the stack
96   /// of operations until the operation is found. All operations upper the parameter one are
97   /// not aborted.
98   /// \param theOperation an aborted operation
99   void abortOperation(ModuleBase_Operation* theOperation);
100
101   /// Blocking/unblocking enabling of Ok button in property panel.
102   /// It is used when operation can not be validated even all attributes are valid
103   void setLockValidating(bool toLock);
104
105   /// Returns state of validation locking
106   bool isValidationLocked() const { return myIsValidationLock; }
107
108   /// Returns enable apply state 
109   /// \return theEnabled a boolean value
110   bool isApplyEnabled() const;
111
112   /// Returns valid state of the parent operation. If the current operation is the last one
113   /// it returns the valid state of the operation
114   /// \return boolean value
115   bool isParentOperationValid() const;
116
117 public slots:
118   /// Slot that commits the current operation.
119   void onCommitOperation();
120   /// Slot that aborts the current operation.
121   void onAbortOperation();
122   /// Slot that validates the current operation using the validateOperation method.
123   void onValidateOperation();
124   /// Commit all operations
125   bool commitAllOperations();
126   /// Abort all operations
127   bool abortAllOperations();
128
129 signals:
130   /// Signal about an operation is started. It is emitted after the start() of operation is done.
131   void operationStarted(ModuleBase_Operation* theOperation);
132
133   /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
134   /// \param theOperation a stopped operation
135   void operationStopped(ModuleBase_Operation* theOperation);
136
137   /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
138   void operationResumed(ModuleBase_Operation* theOperation);
139
140   /// Emitted when current operation is Committed
141   void operationCommitted(ModuleBase_Operation* theOperation);
142
143   /// Emitted when current operation is aborted
144   void operationAborted(ModuleBase_Operation* theOperation);
145
146   /// Signal is emitted after the current operation is filled with existing preselection.
147   void operationActivatedByPreselection();
148
149   /// Signal is emitted after the key released click.
150   void keyEnterReleased();
151
152  protected:
153   /// Sets apply state to the value and emit signal about this state is changed
154   /// \param theEnabled the state value
155   void setApplyEnabled(const bool theEnabled);
156
157 public: // TEMPORARY, it should be protected and be performed automatically
158   /// Emits nestedStateChange for operations with an information about validity of the operation
159   /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
160   void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
161
162   /// Commits the current operatin if it is valid
163   bool commitOperation();
164
165 protected: // TEMPORARY
166   /// Sets the current operation or NULL
167   /// \param theOperation the started operation
168   void resumeOperation(ModuleBase_Operation* theOperation);
169
170   /// Returns whether the parameter operation is granted in relation to the previous operation
171   /// in a stack of started operations. It is used in canStopOperation to avoid warning message
172   /// when granted operation is aborted, e.g. SketchLine in Sketch
173   /// \param theOperation the started operation
174   /// \return boolean result
175   bool isGrantedOperation(ModuleBase_Operation* theOperation);
176
177  public slots:
178   /// SLOT, that is called by the key in the property panel is clicked.
179   /// \param theEvent the mouse event
180   bool onKeyReleased(QKeyEvent* theEvent);
181
182   protected slots:
183   /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
184   /// If there is a suspended operation, restart it.
185   void onOperationStopped();
186
187   /// Slot called on operation start
188   void onOperationStarted();
189
190   /// Slot called on operation abort
191   void onOperationAborted();
192
193   /// Slot called on operation commit
194   void onOperationCommitted();
195
196   /// Slot called on operation resume
197   void onOperationResumed();
198
199 private:
200   XGUI_Workshop* workshop() const;
201
202  private:
203   typedef QList<ModuleBase_Operation*> Operations;  ///< definition for a list of operations
204   Operations myOperations;  ///< a stack of started operations. The active operation is on top,
205                             // others are suspended and started by the active is finished
206
207   /// Current workshop
208   ModuleBase_IWorkshop* myWorkshop;
209
210
211   /// Lock/Unlock access to Ok button in property panel
212   bool myIsValidationLock;
213   /// Lock/Unlock access to Ok button in property panel
214   bool myIsApplyEnabled;
215 };
216
217 #endif