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