1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_OperationMgr.h
4 // Created: 20 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #ifndef XGUI_OperationMgr_H
8 #define XGUI_OperationMgr_H
12 #include <ModuleBase_Operation.h>
13 #include "ModelAPI_Feature.h"
17 #include <QStringList>
21 class ModuleBase_IWorkshop;
23 class XGUI_ShortCutListener;
25 /**\class XGUI_OperationMgr
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.
34 class XGUI_EXPORT XGUI_OperationMgr : public QObject
38 /// Enumeration of kind of message that is used when trying to stop the active operation
41 XGUI_AbortOperationMessage, //< warns and give possibility to abort current operation
42 XGUI_InformationMessage //< ask to apply the current operation before performing something
47 /// \param theParent the parent
48 /// \param theWorkshop a reference to workshop
49 XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop);
52 virtual ~XGUI_OperationMgr();
54 /// Switch on short cut listener
56 /// Switch off short cut listener
59 /// Set reference to workshop
60 /// \param theWorkshop reference to workshop
61 void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
62 { myWorkshop = theWorkshop; };
65 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
67 /// Returns the current operation or NULL
68 /// \return the current operation
69 ModuleBase_Operation* currentOperation() const;
71 /// Check if the given operation is active operation.
72 /// Also, returns false is ther is no active operation.
73 bool isCurrentOperation(ModuleBase_Operation* theOperation);
75 /// Returns true is operation manager has at least one non-null operation.
76 bool hasOperation() const;
78 /// Returns true is operation manager has an operation with given Id.
79 bool hasOperation(const QString& theId) const;
81 /// Returns true if the operation can be aborted. If the operation is modified,
82 /// the warning message box is shown.
83 /// \param theOperation an operation which is checked on stop
84 /// \param theMessageKind a kind of message in warning message box
85 bool canStopOperation(ModuleBase_Operation* theOperation,
86 const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage);
88 /// Find and return operation by its Id.
89 ModuleBase_Operation* findOperation(const QString& theId) const;
91 /// Returns number of operations in the stack
92 int operationsCount() const;
94 /// Returns list of all operations IDs
95 QStringList operationList() const;
97 /// Returns previous (parent) operation if given operation started.
98 /// else, or if there is no parent - returns NULL
99 ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
101 /// Redefinition of virtual function
102 /// \param theObject a sender of the event
103 /// \param theEvent the event
104 virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
106 /// Start the operation and append it to the stack of operations
107 /// \param theOperation the started operation
108 /// \return the state whether the current operation is started
109 bool startOperation(ModuleBase_Operation* theOperation);
111 /// Returns whether the operation can be started. Check if there is already started operation and
112 /// the granted parameter of the launched operation
113 /// \param theId id of the operation which is going to start
114 /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
115 bool canStartOperation(const QString& theId, bool& isCommitted);
117 /// If Apply is enabled and operation has modification, it is applyed, otherwise aborted
118 /// \param theOperation the started operation
119 /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
120 void stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted);
122 /// Aborts the parameter operation if it is current, else abort operations from the stack
123 /// of operations until the operation is found. All operations upper the parameter one are
125 /// \param theOperation an aborted operation
126 void abortOperation(ModuleBase_Operation* theOperation);
128 bool abortAllOperations(const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage);
131 /// Slot that aborts the current operation.
132 void onAbortOperation();
133 /// Slot that validates the current operation using the validateOperation method.
134 void onValidateOperation();
135 /// Commit all operations
136 bool commitAllOperations();
137 /// Abort all operations
138 void onAbortAllOperations();
144 /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
145 /// \param theOperation a stopped operation
146 void operationStopped(ModuleBase_Operation* theOperation);
148 /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
149 void operationResumed(ModuleBase_Operation* theOperation);
151 /// Emitted when current operation is Committed
152 void operationCommitted(ModuleBase_Operation* theOperation);
154 /// Emitted when current operation is aborted
155 void operationAborted(ModuleBase_Operation* theOperation);
157 /// Signal is emitted after the key released click.
158 void keyEnterReleased();
160 public: // TEMPORARY, it should be protected and be performed automatically
161 /// Emits nestedStateChange for operations with an information about validity of the operation
162 /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
163 void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
165 /// Commits the current operatin if it is valid
166 bool commitOperation();
168 protected: // TEMPORARY
169 /// Sets the current operation or NULL
170 /// \param theOperation the started operation
171 void resumeOperation(ModuleBase_Operation* theOperation);
173 /// Returns whether the parameter operation is granted in relation to the previous operation
174 /// in a stack of started operations. It is used in canStopOperation to avoid warning message
175 /// when granted operation is aborted, e.g. SketchLine in Sketch
176 /// \param theId id of the operation which is checked
177 /// \return boolean result
178 bool isGrantedOperation(const QString& theId);
180 /// Sets the feature as a current in the document
181 /// \param theFeature a feature
182 void setCurrentFeature(const FeaturePtr& theFeature);
185 /// SLOT, that is called by the key in the property panel is clicked.
186 /// \param theObject a sender of the event
187 /// \param theEvent the mouse event
188 bool onKeyReleased(QObject *theObject, QKeyEvent* theEvent);
190 /// The functionaly, that should be done by delete click
191 /// Fistly the active widget processes it, then workshop. If no one does not
192 /// process it, do nothing
193 /// \param theObject a sender of the event
194 bool onProcessDelete(QObject* theObject);
197 /// The functionaly, that should be done by enter click
198 /// Fistly the active widget processes it, then module. If no one does not
199 /// process it, the current operation is committed
200 /// \param theObject a sender of the event
201 bool onProcessEnter(QObject *theObject);
203 /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
204 /// If there is a suspended operation, restart it.
205 void onOperationStopped();
207 /// Slot called before operation started. Stores the previous current feature, set the feature
208 /// of the operation as a current in the document. The previous current feature should be restored
209 /// by the operation abort/commit
210 void onBeforeOperationStarted();
212 /// Slot called after operation started
213 void onOperationStarted();
215 /// Slot called before operation aborted. Restore the previous current operation
216 void onBeforeOperationAborted();
218 /// Slot called after operation aborted
219 void onOperationAborted();
221 /// Slot called before operation committed. Restore the previous current operation
222 void onBeforeOperationCommitted();
224 /// Slot called after operation committed
225 void onOperationCommitted();
227 /// Slot called on operation resume
228 void onOperationResumed();
231 /// Checks if the object is a parent or a child under
232 /// \param theObject an investivated object
233 /// \param theParent a candidate to be a parent
234 static bool isChildObject(const QObject* theObject, const QObject* theParent);
237 typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
238 Operations myOperations; ///< a stack of started operations. The active operation is on top,
239 // others are suspended and started by the active is finished
242 ModuleBase_IWorkshop* myWorkshop;
244 XGUI_ShortCutListener* myShortCutListener;