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>
16 #include <QStringList>
20 class ModuleBase_IWorkshop;
22 /**\class XGUI_OperationMgr
24 * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
25 * of started operations. In simple case, if only one operation is started, the stack contains
26 * one operation. It is possible for some kind of operations to start them above already
27 * started one. In that case, the previous active operation becomes suspended, a new one - active.
28 * The new operation is added to the top of the stack. Then it is finished, it is removed from
29 * the stack and the previous operation is activated.
31 class XGUI_EXPORT XGUI_OperationMgr : public QObject
36 /// \param theParent the parent
37 XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop);
39 virtual ~XGUI_OperationMgr();
41 void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
42 { myWorkshop = theWorkshop; };
44 /// Returns the current operation or NULL
45 /// \return the current operation
46 ModuleBase_Operation* currentOperation() const;
48 /// Check if the given operation is active operation.
49 /// Also, returns false is ther is no active operation.
50 bool isCurrentOperation(ModuleBase_Operation* theOperation);
52 /// Returns true is operation manager has at least one non-null operation.
53 bool hasOperation() const;
55 /// Returns true is operation manager has an operation with given Id.
56 bool hasOperation(const QString& theId) const;
58 /// Returns true if the operation can be aborted. If the operation is modified,
59 /// the warning message box is shown.
60 /// \param theOperation an operation which is checked on stop
61 bool canStopOperation(ModuleBase_Operation* theOperation);
63 /// Find and return operation by its Id.
64 ModuleBase_Operation* findOperation(const QString& theId) const;
66 /// Returns number of operations in the stack
67 int operationsCount() const;
69 /// Returns list of all operations IDs
70 QStringList operationList() const;
72 /// Returns previous (parent) operation if given operation started.
73 /// else, or if there is no parent - returns NULL
74 ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
76 /// Redefinition of virtual function
77 virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
79 /// Start the operation and append it to the stack of operations
80 /// \param theOperation the started operation
81 /// \return the state whether the current operation is started
82 bool startOperation(ModuleBase_Operation* theOperation);
84 /// Returns whether the operation can be started. Check if there is already started operation and
85 /// the granted parameter of the launched operation
86 /// \param theId id of the operation which is going to start
87 /// \param isAdditionallyGranted a boolean flag whether the id operation is granted in the previous one
88 bool canStartOperation(const QString& theId, const bool isAdditionallyGranted = false);
90 /// Aborts the parameter operation if it is current, else abort operations from the stack
91 /// of operations until the operation is found. All operations upper the parameter one are
93 /// \param theOperation an aborted operation
94 void abortOperation(ModuleBase_Operation* theOperation);
96 /// Blocking/unblocking enabling of Ok button in property panel.
97 /// It is used when operation can not be validated even all attributes are valid
98 void setLockValidating(bool toLock);
100 /// Returns state of validation locking
101 bool isValidationLocked() const { return myIsValidationLock; }
103 /// Returns enable apply state
104 /// \return theEnabled a boolean value
105 bool isApplyEnabled() const;
107 /// Returns valid state of the parent operation. If the current operation is the last one
108 /// it returns the valid state of the operation
109 /// \return boolean value
110 bool isParentOperationValid() const;
113 /// Slot that commits the current operation.
114 void onCommitOperation();
115 /// Slot that aborts the current operation.
116 void onAbortOperation();
117 /// Slot that validates the current operation using the validateOperation method.
118 void onValidateOperation();
119 /// Commit all operations
120 bool commitAllOperations();
121 /// Abort all operations
122 bool abortAllOperations();
125 /// Signal about an operation is started. It is emitted after the start() of operation is done.
126 void operationStarted(ModuleBase_Operation* theOperation);
128 /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
129 /// \param theOperation a stopped operation
130 void operationStopped(ModuleBase_Operation* theOperation);
132 /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
133 void operationResumed(ModuleBase_Operation* theOperation);
135 /// Emitted when current operation is Committed
136 void operationCommitted(ModuleBase_Operation* theOperation);
138 /// Emitted when current operation is aborted
139 void operationAborted(ModuleBase_Operation* theOperation);
141 /// Signal is emitted after the apply enable state changed.
142 void validationStateChanged(bool);
144 /// Signal is emitted after the model is modified. It is emitted for all active operations.
145 /// \param theFeatureKind a feature id
146 /// \param theState validity of the operation with the feature kind
147 void nestedStateChanged(const std::string& theFeatureKind, const bool theState);
149 /// Signal is emitted after the current operation is filled with existing preselection.
150 void operationActivatedByPreselection();
152 /// Signal is emitted after the key released click.
153 void keyEnterReleased();
156 /// Sets apply state to the value and emit signal about this state is changed
157 /// \param theEnabled the state value
158 void setApplyEnabled(const bool theEnabled);
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 theOperation the started operation
177 /// \return boolean result
178 bool isGrantedOperation(ModuleBase_Operation* theOperation);
181 /// SLOT, that is called by the key in the property panel is clicked.
182 /// \param theEvent the mouse event
183 bool onKeyReleased(QKeyEvent* theEvent);
186 /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
187 /// If there is a suspended operation, restart it.
188 void onOperationStopped();
190 /// Slot called on operation start
191 void onOperationStarted();
193 /// Slot called on operation abort
194 void onOperationAborted();
196 /// Slot called on operation commit
197 void onOperationCommitted();
199 /// Slot called on operation resume
200 void onOperationResumed();
203 typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
204 Operations myOperations; ///< a stack of started operations. The active operation is on top,
205 // others are suspended and started by the active is finished
208 ModuleBase_IWorkshop* myWorkshop;
211 /// Lock/Unlock access to Ok button in property panel
212 bool myIsValidationLock;
213 /// Lock/Unlock access to Ok button in property panel
214 bool myIsApplyEnabled;