1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef XGUI_OperationMgr_H
21 #define XGUI_OperationMgr_H
25 #include <ModuleBase_Operation.h>
26 #include "ModelAPI_Feature.h"
30 #include <QStringList>
35 class ModuleBase_IWorkshop;
37 class XGUI_ShortCutListener;
39 /**\class XGUI_OperationMgr
41 * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
42 * of started operations. In simple case, if only one operation is started, the stack contains
43 * one operation. It is possible for some kind of operations to start them above already
44 * started one. In that case, the previous active operation becomes suspended, a new one - active.
45 * The new operation is added to the top of the stack. Then it is finished, it is removed from
46 * the stack and the previous operation is activated.
48 class XGUI_EXPORT XGUI_OperationMgr : public QObject
52 /// Enumeration of kind of message that is used when trying to stop the active operation
55 XGUI_AbortOperationMessage, ///< warns and give possibility to abort current operation
56 XGUI_InformationMessage ///< ask to apply the current operation before performing something
61 /// \param theParent the parent
62 /// \param theWorkshop a reference to workshop
63 XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop);
66 virtual ~XGUI_OperationMgr();
68 /// Switch on short cut listener
70 /// Switch off short cut listener
73 /// Set reference to workshop
74 /// \param theWorkshop reference to workshop
75 void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
76 { myWorkshop = theWorkshop; };
79 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
82 XGUI_Workshop* xworkshop() const;
84 /// Returns the current operation or NULL
85 /// \return the current operation
86 ModuleBase_Operation* currentOperation() const;
88 /// Check if the given operation is active operation.
89 /// Also, returns false is ther is no active operation.
90 bool isCurrentOperation(ModuleBase_Operation* theOperation);
92 /// Returns true is operation manager has at least one non-null operation.
93 bool hasOperation() const;
95 /// Returns true is operation manager has an operation with given Id.
96 bool hasOperation(const QString& theId) const;
98 /// Returns true if the operation can be aborted. If the operation is modified,
99 /// the warning message box is shown.
100 /// \param theOperation an operation which is checked on stop
101 /// \param theMessageKind a kind of message in warning message box
102 bool canStopOperation(ModuleBase_Operation* theOperation,
103 const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage);
105 /// Find and return operation by its Id.
106 ModuleBase_Operation* findOperation(const QString& theId) const;
108 /// Returns number of operations in the stack
109 int operationsCount() const;
111 /// Returns list of all operations IDs
112 QStringList operationList() const;
114 /// Returns previous (parent) operation if given operation started.
115 /// else, or if there is no parent - returns NULL
116 ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
118 /// Returns an active widget of the current operation.
119 /// \return widget or NULL
120 ModuleBase_ModelWidget* activeWidget() const;
122 /// Start the operation and append it to the stack of operations
123 /// \param theOperation the started operation
124 /// \return the state whether the current operation is started
125 bool startOperation(ModuleBase_Operation* theOperation);
127 /// Returns whether the operation can be started. Check if there is already started operation and
128 /// the granted parameter of the launched operation
129 /// \param theId id of the operation which is going to start
130 /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
131 bool canStartOperation(const QString& theId, bool& isCommitted);
133 /// If Apply is enabled and operation has modification, it is applyed, otherwise aborted
134 /// \param theOperation the started operation
135 /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
136 void stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted);
138 /// Aborts the parameter operation if it is current, else abort operations from the stack
139 /// of operations until the operation is found. All operations upper the parameter one are
141 /// \param theOperation an aborted operation
142 void abortOperation(ModuleBase_Operation* theOperation);
144 /// Abort all operations
145 /// \param theMessageKind kind of shown warning message
146 bool abortAllOperations(const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage);
148 /// Commits the current operation.
149 bool commitOperation();
151 /// Returns true if SHIFT is pressed
152 /// \param thePressed new boolean state
153 void setSHIFTPressed(const bool thePressed) { mySHIFTPressed = thePressed; }
155 /// Returns true if SHIFT is pressed
156 /// \return boolean value
157 bool hasSHIFTPressed() const { return mySHIFTPressed; }
160 /// Slot that aborts the current operation.
161 void onAbortOperation();
162 /// Slot that aborts all operations. It shows aborting message
163 void onAbortAllOperation();
164 /// Slot that validates the current operation using the validateOperation method.
165 void onValidateOperation();
166 /// Commit all operations
167 bool commitAllOperations();
170 /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
171 /// \param theOperation a stopped operation
172 void operationStopped(ModuleBase_Operation* theOperation);
174 /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
175 void operationResumed(ModuleBase_Operation* theOperation);
177 /// Emitted when current operation is Committed
178 void operationCommitted(ModuleBase_Operation* theOperation);
180 /// Emitted when current operation is aborted
181 void operationAborted(ModuleBase_Operation* theOperation);
183 /// Signal is emitted after the key released click.
184 void keyEnterReleased();
186 public: // TEMPORARY, it should be protected and be performed automatically
187 /// Emits nestedStateChange for operations with an information about validity of the operation
188 /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
189 void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
191 protected: // TEMPORARY
192 /// Sets the current operation or NULL
193 /// \param theOperation the started operation
194 void resumeOperation(ModuleBase_Operation* theOperation);
196 /// Returns whether the parameter operation is granted in relation to the previous operation
197 /// in a stack of started operations. It is used in canStopOperation to avoid warning message
198 /// when granted operation is aborted, e.g. SketchLine in Sketch
199 /// \param theId id of the operation which is checked
200 /// \return boolean result
201 bool isGrantedOperation(const QString& theId);
203 /// Sets the feature as a current in the document
204 /// \param theFeature a feature
205 void setCurrentFeature(const FeaturePtr& theFeature);
208 /// SLOT, that is called by the key in the property panel is clicked.
209 /// \param theObject a sender of the event
210 /// \param theEvent the mouse event
211 bool onKeyReleased(QObject *theObject, QKeyEvent* theEvent);
213 /// SLOT, that is called by the key in the property panel is clicked.
214 /// \param theObject a sender of the event
215 /// \param theEvent the mouse event
216 bool onKeyPressed(QObject *theObject, QKeyEvent* theEvent);
218 /// The functionaly, that should be done by delete click
219 /// Fistly the active widget processes it, then workshop. If no one does not
220 /// process it, do nothing
221 /// \param theObject a sender of the event
222 bool onProcessDelete(QObject* theObject);
225 /// The functionaly, that should be done by enter click
226 /// Fistly the active widget processes it, then module. If no one does not
227 /// process it, the current operation is committed
228 /// \param theObject a sender of the event
229 bool onProcessEnter(QObject *theObject);
231 /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
232 /// If there is a suspended operation, restart it.
233 void onOperationStopped();
235 /// Slot called before operation started. Stores the previous current feature, set the feature
236 /// of the operation as a current in the document. The previous current feature should be restored
237 /// by the operation abort/commit
238 void onBeforeOperationStarted();
240 /// Slot called after operation started
241 void onOperationStarted();
243 /// Slot called before operation aborted. Restore the previous current operation
244 void onBeforeOperationAborted();
246 /// Slot called after operation aborted
247 void onOperationAborted();
249 /// Slot called before operation committed. Restore the previous current operation
250 void onBeforeOperationCommitted();
252 /// Slot called after operation committed
253 void onOperationCommitted();
255 /// Slot called on operation resume
256 void onOperationResumed();
259 /// Checks if the object is a parent or a child under
260 /// \param theObject an investivated object
261 /// \param theParent a candidate to be a parent
262 static bool isChildObject(const QObject* theObject, const QObject* theParent);
264 /// Creates question message box with OK/Cancel buttons, where Cancel is default button,
265 /// Escape is Null button
266 /// \param theMessage text of the message
267 /// \return message box
268 static QMessageBox* createMessageBox(const QString& theMessage);
270 /// Creates information message box with OK button,
271 /// Escape is Null button
272 /// \param theMessage text of the message
273 /// \return message box
274 static QMessageBox* createInformationBox(const QString& theMessage);
277 typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
278 Operations myOperations; ///< a stack of started operations. The active operation is on top,
279 // others are suspended and started by the active is finished
282 ModuleBase_IWorkshop* myWorkshop;
283 QMessageBox* myActiveMessageBox;
284 XGUI_ShortCutListener* myShortCutListener;