]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_OperationMgr.h
Salome HOME
1. CanStopOperation knows which operation is stopped. Scenario: Unpress Sketch in...
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_OperationMgr.h
4 // Created:     20 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef XGUI_OperationMgr_H
8 #define XGUI_OperationMgr_H
9
10 #include "XGUI.h"
11
12 #include <ModuleBase_Operation.h>
13
14 #include <QList>
15 #include <QObject>
16 #include <QStringList>
17
18 class QKeyEvent;
19
20 class ModuleBase_IWorkshop;
21
22 /**\class XGUI_OperationMgr
23  * \ingroup GUI
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.
30  */
31 class XGUI_EXPORT XGUI_OperationMgr : public QObject
32 {
33 Q_OBJECT
34  public:
35   /// Constructor
36   /// \param theParent the parent
37   XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop);
38   /// Destructor
39   virtual ~XGUI_OperationMgr();
40
41   void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
42   { myWorkshop = theWorkshop; };
43
44   /// Returns the current operation or NULL
45   /// \return the current operation
46   ModuleBase_Operation* currentOperation() const;
47
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);
51
52   /// Returns true is operation manager has at least one non-null operation.
53   bool hasOperation() const;
54
55   /// Returns true is operation manager has an operation with given Id.
56   bool hasOperation(const QString& theId) const;
57
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);
62
63   /// Find and return operation by its Id.
64   ModuleBase_Operation* findOperation(const QString& theId) const;
65
66   /// Returns number of operations in the stack
67   int operationsCount() const;
68
69   /// Returns list of all operations IDs
70   QStringList operationList() const;
71
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;
75
76   /// Redefinition of virtual function
77   virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
78
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);
83
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   bool canStartOperation(QString theId);
88
89   /// Aborts the parameter operation if it is current, else abort operations from the stack
90   /// of operations until the operation is found. All operations upper the parameter one are
91   /// not aborted.
92   /// \param theOperation an aborted operation
93   void abortOperation(ModuleBase_Operation* theOperation);
94
95   /// Blocking/unblocking enabling of Ok button in property panel.
96   /// It is used when operation can not be validated even all attributes are valid
97   void setLockValidating(bool toLock);
98
99   /// Returns state of validation locking
100   bool isValidationLocked() const { return myIsValidationLock; }
101
102   /// Returns enable apply state 
103   /// \return theEnabled a boolean value
104   bool isApplyEnabled() const;
105
106   /// Returns valid state of the parent operation. If the current operation is the last one
107   /// it returns the valid state of the operation
108   /// \return boolean value
109   bool isParentOperationValid() const;
110
111 public slots:
112   /// Slot that commits the current operation.
113   void onCommitOperation();
114   /// Slot that aborts the current operation.
115   void onAbortOperation();
116   /// Slot that validates the current operation using the validateOperation method.
117   void onValidateOperation();
118   /// Commit all operations
119   bool commitAllOperations();
120   /// Abort all operations
121   bool abortAllOperations();
122
123 signals:
124   /// Signal about an operation is started. It is emitted after the start() of operation is done.
125   void operationStarted(ModuleBase_Operation* theOperation);
126
127   /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
128   /// \param theOperation a stopped operation
129   void operationStopped(ModuleBase_Operation* theOperation);
130
131   /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
132   void operationResumed(ModuleBase_Operation* theOperation);
133
134   /// Emitted when current operation is Committed
135   void operationCommitted(ModuleBase_Operation* theOperation);
136
137   /// Emitted when current operation is aborted
138   void operationAborted(ModuleBase_Operation* theOperation);
139
140   /// Signal is emitted after the apply enable state changed.
141   void validationStateChanged(bool);
142
143   /// Signal is emitted after the model is modified. It is emitted for all active operations.
144   /// \param theFeatureKind a feature id
145   /// \param theState validity of the operation with the feature kind
146   void nestedStateChanged(const std::string& theFeatureKind, const bool theState);
147
148   /// Signal is emitted after the current operation is filled with existing preselection.
149   void operationActivatedByPreselection();
150
151   /// Signal is emitted after the key released click.
152   void keyEnterReleased();
153
154  protected:
155   /// Sets apply state to the value and emit signal about this state is changed
156   /// \param theEnabled the state value
157   void setApplyEnabled(const bool theEnabled);
158
159 public: // TEMPORARY, it should be protected and be performed automatically
160   /// Emits nestedStateChange for operations with an information about validity of the operation
161   /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
162   void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
163
164   /// Commits the current operatin if it is valid
165   bool commitOperation();
166
167 protected: // TEMPORARY
168   /// Sets the current operation or NULL
169   /// \param theOperation the started operation
170   void resumeOperation(ModuleBase_Operation* theOperation);
171
172   /// Returns whether the parameter operation is granted in relation to the previous operation
173   /// in a stack of started operations. It is used in canStopOperation to avoid warning message
174   /// when granted operation is aborted, e.g. SketchLine in Sketch
175   /// \param theOperation the started operation
176   /// \return boolean result
177   bool isGrantedOperation(ModuleBase_Operation* theOperation);
178
179  public slots:
180   /// SLOT, that is called by the key in the property panel is clicked.
181   /// \param theEvent the mouse event
182   bool onKeyReleased(QKeyEvent* theEvent);
183
184   protected slots:
185   /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
186   /// If there is a suspended operation, restart it.
187   void onOperationStopped();
188
189   /// Slot called on operation start
190   void onOperationStarted();
191
192   /// Slot called on operation abort
193   void onOperationAborted();
194
195   /// Slot called on operation commit
196   void onOperationCommitted();
197
198   /// Slot called on operation resume
199   void onOperationResumed();
200
201  private:
202   typedef QList<ModuleBase_Operation*> Operations;  ///< definition for a list of operations
203   Operations myOperations;  ///< a stack of started operations. The active operation is on top,
204                             // others are suspended and started by the active is finished
205
206   /// Current workshop
207   ModuleBase_IWorkshop* myWorkshop;
208
209
210   /// Lock/Unlock access to Ok button in property panel
211   bool myIsValidationLock;
212   /// Lock/Unlock access to Ok button in property panel
213   bool myIsApplyEnabled;
214 };
215
216 #endif