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