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;
23 /**\class XGUI_OperationMgr
25 * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
26 * of started operations. In simple case, if only one operation is started, the stack contains
27 * one operation. It is possible for some kind of operations to start them above already
28 * started one. In that case, the previous active operation becomes suspended, a new one - active.
29 * The new operation is added to the top of the stack. Then it is finished, it is removed from
30 * the stack and the previous operation is activated.
32 class XGUI_EXPORT XGUI_OperationMgr : public QObject
37 /// \param theParent the parent
38 XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop);
40 virtual ~XGUI_OperationMgr();
42 void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
43 { myWorkshop = theWorkshop; };
45 /// Returns the current operation or NULL
46 /// \return the current operation
47 ModuleBase_Operation* currentOperation() const;
49 /// Check if the given operation is active operation.
50 /// Also, returns false is ther is no active operation.
51 bool isCurrentOperation(ModuleBase_Operation* theOperation);
53 /// Returns true is operation manager has at least one non-null operation.
54 bool hasOperation() const;
56 /// Returns true is operation manager has an operation with given Id.
57 bool hasOperation(const QString& theId) const;
59 /// Returns true if the operation can be aborted. If the operation is modified,
60 /// the warning message box is shown.
61 /// \param theOperation an operation which is checked on stop
62 bool canStopOperation(ModuleBase_Operation* theOperation);
64 /// Find and return operation by its Id.
65 ModuleBase_Operation* findOperation(const QString& theId) const;
67 /// Returns number of operations in the stack
68 int operationsCount() const;
70 /// Returns list of all operations IDs
71 QStringList operationList() const;
73 /// Returns previous (parent) operation if given operation started.
74 /// else, or if there is no parent - returns NULL
75 ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
77 /// Redefinition of virtual function
78 virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
80 /// Start the operation and append it to the stack of operations
81 /// \param theOperation the started operation
82 /// \return the state whether the current operation is started
83 bool startOperation(ModuleBase_Operation* theOperation);
85 /// Returns whether the operation can be started. Check if there is already started operation and
86 /// the granted parameter of the launched operation
87 /// \param theId id of the operation which is going to start
88 /// \param isAdditionallyGranted a boolean flag whether the id operation is granted in the previous one
89 bool canStartOperation(const QString& theId, const bool isAdditionallyGranted = false);
91 /// Aborts the parameter operation if it is current, else abort operations from the stack
92 /// of operations until the operation is found. All operations upper the parameter one are
94 /// \param theOperation an aborted operation
95 void abortOperation(ModuleBase_Operation* theOperation);
97 /// Blocking/unblocking enabling of Ok button in property panel.
98 /// It is used when operation can not be validated even all attributes are valid
99 void setLockValidating(bool toLock);
101 /// Returns state of validation locking
102 bool isValidationLocked() const { return myIsValidationLock; }
104 /// Returns enable apply state
105 /// \return theEnabled a boolean value
106 bool isApplyEnabled() const;
108 /// Returns valid state of the parent operation. If the current operation is the last one
109 /// it returns the valid state of the operation
110 /// \return boolean value
111 bool isParentOperationValid() const;
114 /// Slot that commits the current operation.
115 void onCommitOperation();
116 /// Slot that aborts the current operation.
117 void onAbortOperation();
118 /// Slot that validates the current operation using the validateOperation method.
119 void onValidateOperation();
120 /// Commit all operations
121 bool commitAllOperations();
122 /// Abort all operations
123 bool abortAllOperations();
126 /// Signal about an operation is started. It is emitted after the start() of operation is done.
127 void operationStarted(ModuleBase_Operation* theOperation);
129 /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
130 /// \param theOperation a stopped operation
131 void operationStopped(ModuleBase_Operation* theOperation);
133 /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
134 void operationResumed(ModuleBase_Operation* theOperation);
136 /// Emitted when current operation is Committed
137 void operationCommitted(ModuleBase_Operation* theOperation);
139 /// Emitted when current operation is aborted
140 void operationAborted(ModuleBase_Operation* theOperation);
142 /// Signal is emitted after the apply enable state changed.
143 //void validationStateChanged(bool);
145 /// Signal is emitted after the model is modified. It is emitted for all active operations.
146 /// \param theFeatureKind a feature id
147 /// \param theState validity of the operation with the feature kind
148 //void nestedStateChanged(const std::string& theFeatureKind, const bool theState);
150 /// Signal is emitted after the current operation is filled with existing preselection.
151 void operationActivatedByPreselection();
153 /// Signal is emitted after the key released click.
154 void keyEnterReleased();
157 /// Sets apply state to the value and emit signal about this state is changed
158 /// \param theEnabled the state value
159 void setApplyEnabled(const bool theEnabled);
161 public: // TEMPORARY, it should be protected and be performed automatically
162 /// Emits nestedStateChange for operations with an information about validity of the operation
163 /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
164 void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
166 /// Commits the current operatin if it is valid
167 bool commitOperation();
169 protected: // TEMPORARY
170 /// Sets the current operation or NULL
171 /// \param theOperation the started operation
172 void resumeOperation(ModuleBase_Operation* theOperation);
174 /// Returns whether the parameter operation is granted in relation to the previous operation
175 /// in a stack of started operations. It is used in canStopOperation to avoid warning message
176 /// when granted operation is aborted, e.g. SketchLine in Sketch
177 /// \param theOperation the started operation
178 /// \return boolean result
179 bool isGrantedOperation(ModuleBase_Operation* theOperation);
182 /// SLOT, that is called by the key in the property panel is clicked.
183 /// \param theEvent the mouse event
184 bool onKeyReleased(QKeyEvent* theEvent);
187 /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
188 /// If there is a suspended operation, restart it.
189 void onOperationStopped();
191 /// Slot called on operation start
192 void onOperationStarted();
194 /// Slot called on operation abort
195 void onOperationAborted();
197 /// Slot called on operation commit
198 void onOperationCommitted();
200 /// Slot called on operation resume
201 void onOperationResumed();
204 XGUI_Workshop* workshop() const;
207 typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
208 Operations myOperations; ///< a stack of started operations. The active operation is on top,
209 // others are suspended and started by the active is finished
212 ModuleBase_IWorkshop* myWorkshop;
215 /// Lock/Unlock access to Ok button in property panel
216 bool myIsValidationLock;
217 /// Lock/Unlock access to Ok button in property panel
218 bool myIsApplyEnabled;