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