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 email : webmaster.salome@opencascade.com<mailto: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>
34 class ModuleBase_IWorkshop;
36 class XGUI_ShortCutListener;
38 /**\class XGUI_OperationMgr
40 * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
41 * of started operations. In simple case, if only one operation is started, the stack contains
42 * one operation. It is possible for some kind of operations to start them above already
43 * started one. In that case, the previous active operation becomes suspended, a new one - active.
44 * The new operation is added to the top of the stack. Then it is finished, it is removed from
45 * the stack and the previous operation is activated.
47 class XGUI_EXPORT XGUI_OperationMgr : public QObject
52 /// \param theParent the parent
53 /// \param theWorkshop a reference to workshop
54 XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop);
57 virtual ~XGUI_OperationMgr();
59 /// Switch on short cut listener
61 /// Switch off short cut listener
64 /// Set reference to workshop
65 /// \param theWorkshop reference to workshop
66 void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
67 { myWorkshop = theWorkshop; };
70 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
72 /// Returns the current operation or NULL
73 /// \return the current operation
74 ModuleBase_Operation* currentOperation() const;
76 /// Check if the given operation is active operation.
77 /// Also, returns false is ther is no active operation.
78 bool isCurrentOperation(ModuleBase_Operation* theOperation);
80 /// Returns true is operation manager has at least one non-null operation.
81 bool hasOperation() const;
83 /// Returns true is operation manager has an operation with given Id.
84 bool hasOperation(const QString& theId) const;
86 /// Returns true if the operation can be aborted. If the operation is modified,
87 /// the warning message box is shown.
88 /// \param theOperation an operation which is checked on stop
89 bool canStopOperation(ModuleBase_Operation* theOperation);
91 /// Find and return operation by its Id.
92 ModuleBase_Operation* findOperation(const QString& theId) const;
94 /// Returns number of operations in the stack
95 int operationsCount() const;
97 /// Returns list of all operations IDs
98 QStringList operationList() const;
100 /// Returns previous (parent) operation if given operation started.
101 /// else, or if there is no parent - returns NULL
102 ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
104 /// Start the operation and append it to the stack of operations
105 /// \param theOperation the started operation
106 /// \return the state whether the current operation is started
107 bool startOperation(ModuleBase_Operation* theOperation);
109 /// Returns whether the operation can be started. Check if there is already started operation and
110 /// the granted parameter of the launched operation
111 /// \param theId id of the operation which is going to start
112 /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
113 bool canStartOperation(const QString& theId, bool& isCommitted);
115 /// If Apply is enabled and operation has modification, it is applyed, otherwise aborted
116 /// \param theOperation the started operation
117 /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
118 void stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted);
120 /// Aborts the parameter operation if it is current, else abort operations from the stack
121 /// of operations until the operation is found. All operations upper the parameter one are
123 /// \param theOperation an aborted operation
124 void abortOperation(ModuleBase_Operation* theOperation);
126 /// Slot that commits the current operation.
127 bool onCommitOperation();
130 /// Slot that aborts the current operation.
131 void onAbortOperation();
132 /// Slot that validates the current operation using the validateOperation method.
133 void onValidateOperation();
134 /// Commit all operations
135 bool commitAllOperations();
136 /// Abort all operations
137 bool abortAllOperations();
140 /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
141 /// \param theOperation a stopped operation
142 void operationStopped(ModuleBase_Operation* theOperation);
144 /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
145 void operationResumed(ModuleBase_Operation* theOperation);
147 /// Emitted when current operation is Committed
148 void operationCommitted(ModuleBase_Operation* theOperation);
150 /// Emitted when current operation is aborted
151 void operationAborted(ModuleBase_Operation* theOperation);
153 /// Signal is emitted after the key released click.
154 void keyEnterReleased();
156 public: // TEMPORARY, it should be protected and be performed automatically
157 /// Emits nestedStateChange for operations with an information about validity of the operation
158 /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
159 void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
161 /// Commits the current operatin if it is valid
162 bool commitOperation();
164 protected: // TEMPORARY
165 /// Sets the current operation or NULL
166 /// \param theOperation the started operation
167 void resumeOperation(ModuleBase_Operation* theOperation);
169 /// Returns whether the parameter operation is granted in relation to the previous operation
170 /// in a stack of started operations. It is used in canStopOperation to avoid warning message
171 /// when granted operation is aborted, e.g. SketchLine in Sketch
172 /// \param theId id of the operation which is checked
173 /// \return boolean result
174 bool isGrantedOperation(const QString& theId);
176 /// Sets the feature as a current in the document
177 /// \param theFeature a feature
178 void setCurrentFeature(const FeaturePtr& theFeature);
181 /// SLOT, that is called by the key in the property panel is clicked.
182 /// \param theObject a sender of the event
183 /// \param theEvent the mouse event
184 bool onKeyReleased(QObject *theObject, QKeyEvent* theEvent);
186 /// The functionaly, that should be done by delete click
187 /// Fistly the active widget processes it, then workshop. If no one does not
188 /// process it, do nothing
189 /// \param theObject a sender of the event
190 bool onProcessDelete(QObject* theObject);
193 /// The functionaly, that should be done by enter click
194 /// Fistly the active widget processes it, then module. If no one does not
195 /// process it, the current operation is committed
196 /// \param theObject a sender of the event
197 bool onProcessEnter(QObject *theObject);
199 /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
200 /// If there is a suspended operation, restart it.
201 void onOperationStopped();
203 /// Slot called before operation started. Stores the previous current feature, set the feature
204 /// of the operation as a current in the document. The previous current feature should be restored
205 /// by the operation abort/commit
206 void onBeforeOperationStarted();
208 /// Slot called after operation started
209 void onOperationStarted();
211 /// Slot called before operation aborted. Restore the previous current operation
212 void onBeforeOperationAborted();
214 /// Slot called after operation aborted
215 void onOperationAborted();
217 /// Slot called before operation committed. Restore the previous current operation
218 void onBeforeOperationCommitted();
220 /// Slot called after operation committed
221 void onOperationCommitted();
223 /// Slot called on operation resume
224 void onOperationResumed();
227 /// Checks if the object is a parent or a child under
228 /// \param theObject an investivated object
229 /// \param theParent a candidate to be a parent
230 static bool isChildObject(const QObject* theObject, const QObject* theParent);
233 typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
234 Operations myOperations; ///< a stack of started operations. The active operation is on top,
235 // others are suspended and started by the active is finished
238 ModuleBase_IWorkshop* myWorkshop;
240 XGUI_ShortCutListener* myShortCutListener;