1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef XGUI_OperationMgr_H
22 #define XGUI_OperationMgr_H
26 #include <ModuleBase_Operation.h>
27 #include "ModelAPI_Feature.h"
31 #include <QStringList>
36 class ModuleBase_IWorkshop;
38 class XGUI_ShortCutListener;
40 /**\class XGUI_OperationMgr
42 * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
43 * of started operations. In simple case, if only one operation is started, the stack contains
44 * one operation. It is possible for some kind of operations to start them above already
45 * started one. In that case, the previous active operation becomes suspended, a new one - active.
46 * The new operation is added to the top of the stack. Then it is finished, it is removed from
47 * the stack and the previous operation is activated.
49 class XGUI_EXPORT XGUI_OperationMgr : public QObject
54 /// \param theParent the parent
55 /// \param theWorkshop a reference to workshop
56 XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop);
59 virtual ~XGUI_OperationMgr();
61 /// Switch on short cut listener
63 /// Switch off short cut listener
66 /// Set reference to workshop
67 /// \param theWorkshop reference to workshop
68 void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
69 { myWorkshop = theWorkshop; };
72 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
74 /// Returns the current operation or NULL
75 /// \return the current operation
76 ModuleBase_Operation* currentOperation() const;
78 /// Check if the given operation is active operation.
79 /// Also, returns false is ther is no active operation.
80 bool isCurrentOperation(ModuleBase_Operation* theOperation);
82 /// Returns true is operation manager has at least one non-null operation.
83 bool hasOperation() const;
85 /// Returns true is operation manager has an operation with given Id.
86 bool hasOperation(const QString& theId) const;
88 /// Returns true if the operation can be aborted. If the operation is modified,
89 /// the warning message box is shown.
90 /// \param theOperation an operation which is checked on stop
91 bool canStopOperation(ModuleBase_Operation* theOperation);
93 /// Find and return operation by its Id.
94 ModuleBase_Operation* findOperation(const QString& theId) const;
96 /// Returns number of operations in the stack
97 int operationsCount() const;
99 /// Returns list of all operations IDs
100 QStringList operationList() const;
102 /// Returns previous (parent) operation if given operation started.
103 /// else, or if there is no parent - returns NULL
104 ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
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 /// Slot that commits the current operation.
129 bool onCommitOperation();
131 /// Returns true if SHIFT is pressed
132 /// \param thePressed new boolean state
133 void setSHIFTPressed(const bool thePressed) { mySHIFTPressed = thePressed; }
135 /// Returns true if SHIFT is pressed
136 /// \return boolean value
137 bool hasSHIFTPressed() const { return mySHIFTPressed; }
140 /// Slot that aborts the current operation.
141 void onAbortOperation();
142 /// Slot that validates the current operation using the validateOperation method.
143 void onValidateOperation();
144 /// Commit all operations
145 bool commitAllOperations();
146 /// Abort all operations
147 bool abortAllOperations();
150 /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
151 /// \param theOperation a stopped operation
152 void operationStopped(ModuleBase_Operation* theOperation);
154 /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
155 void operationResumed(ModuleBase_Operation* theOperation);
157 /// Emitted when current operation is Committed
158 void operationCommitted(ModuleBase_Operation* theOperation);
160 /// Emitted when current operation is aborted
161 void operationAborted(ModuleBase_Operation* theOperation);
163 /// Signal is emitted after the key released click.
164 void keyEnterReleased();
166 public: // TEMPORARY, it should be protected and be performed automatically
167 /// Emits nestedStateChange for operations with an information about validity of the operation
168 /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
169 void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
171 /// Commits the current operatin if it is valid
172 bool commitOperation();
174 protected: // TEMPORARY
175 /// Sets the current operation or NULL
176 /// \param theOperation the started operation
177 void resumeOperation(ModuleBase_Operation* theOperation);
179 /// Returns whether the parameter operation is granted in relation to the previous operation
180 /// in a stack of started operations. It is used in canStopOperation to avoid warning message
181 /// when granted operation is aborted, e.g. SketchLine in Sketch
182 /// \param theId id of the operation which is checked
183 /// \return boolean result
184 bool isGrantedOperation(const QString& theId);
186 /// Sets the feature as a current in the document
187 /// \param theFeature a feature
188 void setCurrentFeature(const FeaturePtr& theFeature);
191 /// SLOT, that is called by the key in the property panel is clicked.
192 /// \param theObject a sender of the event
193 /// \param theEvent the mouse event
194 bool onKeyReleased(QObject *theObject, QKeyEvent* theEvent);
196 /// SLOT, that is called by the key in the property panel is clicked.
197 /// \param theObject a sender of the event
198 /// \param theEvent the mouse event
199 bool onKeyPressed(QObject *theObject, QKeyEvent* theEvent);
201 /// The functionaly, that should be done by delete click
202 /// Fistly the active widget processes it, then workshop. If no one does not
203 /// process it, do nothing
204 /// \param theObject a sender of the event
205 bool onProcessDelete(QObject* theObject);
208 /// The functionaly, that should be done by enter click
209 /// Fistly the active widget processes it, then module. If no one does not
210 /// process it, the current operation is committed
211 /// \param theObject a sender of the event
212 bool onProcessEnter(QObject *theObject);
214 /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
215 /// If there is a suspended operation, restart it.
216 void onOperationStopped();
218 /// Slot called before operation started. Stores the previous current feature, set the feature
219 /// of the operation as a current in the document. The previous current feature should be restored
220 /// by the operation abort/commit
221 void onBeforeOperationStarted();
223 /// Slot called after operation started
224 void onOperationStarted();
226 /// Slot called before operation aborted. Restore the previous current operation
227 void onBeforeOperationAborted();
229 /// Slot called after operation aborted
230 void onOperationAborted();
232 /// Slot called before operation committed. Restore the previous current operation
233 void onBeforeOperationCommitted();
235 /// Slot called after operation committed
236 void onOperationCommitted();
238 /// Slot called on operation resume
239 void onOperationResumed();
242 /// Checks if the object is a parent or a child under
243 /// \param theObject an investivated object
244 /// \param theParent a candidate to be a parent
245 static bool isChildObject(const QObject* theObject, const QObject* theParent);
247 /// Creates question message box with OK/Cancel buttons, where Cancel is default button,
248 /// Escape is Null button
249 /// \param theMessage text of the message
250 /// \return message box
251 static QMessageBox* createMessageBox(const QString& theMessage);
254 typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
255 Operations myOperations; ///< a stack of started operations. The active operation is on top,
256 // others are suspended and started by the active is finished
259 ModuleBase_IWorkshop* myWorkshop;
260 QMessageBox* myActiveMessageBox;
261 XGUI_ShortCutListener* myShortCutListener;