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