Salome HOME
Construction elements are auxiliary entities:
[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 XGUI_OperationMgr
21  * \ingroup GUI
22  * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
23  * of started operations. In simple case, if only one operation is started, the stack contains
24  * one operation. It is possible for some kind of operations to start them above already
25  * started one. In that case, the previous active operation becomes suspended, a new one - active.
26  * The new operation is added to the top of the stack. Then it is finished, it is removed from
27  * the stack and the previous operation is activated.
28  */
29 class XGUI_EXPORT XGUI_OperationMgr : public QObject
30 {
31 Q_OBJECT
32  public:
33   /// Constructor
34   /// \param theParent the parent
35   XGUI_OperationMgr(QObject* theParent);
36   /// Destructor
37   virtual ~XGUI_OperationMgr();
38
39   /// Returns the current operation or NULL
40   /// \return the current operation
41   ModuleBase_Operation* currentOperation() const;
42
43   /// Check if the given operation is active operation.
44   /// Also, returns false is ther is no active operation.
45   bool isCurrentOperation(ModuleBase_Operation* theOperation);
46
47   /// Returns true is operation manager has at least one non-null operation.
48   bool hasOperation() const;
49
50   /// Returns true is operation manager has an operation with given Id.
51   bool hasOperation(const QString& theId) const;
52
53   /// Returns true if the operation can be aborted
54   bool canStopOperation();
55
56   /// Find and return operation by its Id.
57   ModuleBase_Operation* findOperation(const QString& theId) const;
58
59   /// Returns number of operations in the stack
60   int operationsCount() const;
61
62   /// Returns list of all operations IDs
63   QStringList operationList() const;
64
65   /// Returns previous (parent) operation if given operation started.
66   /// else, or if there is no parent - returns NULL
67   ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
68
69   /// Redefinition of virtual function
70   virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
71
72   /// Start the operation and append it to the stack of operations
73   /// \param theOperation the started operation
74   /// \return the state whether the current operation is started
75   bool startOperation(ModuleBase_Operation* theOperation);
76
77   /// Returns whether the operation can be started. Check if there is already started operation and
78   /// the granted parameter of the launched operation
79   /// \param theId id of the operation which is going to start
80   bool canStartOperation(QString theId);
81
82   /// Blocking/unblocking enabling of Ok button in property panel.
83   /// It is used when operation can not be validated even all attributes are valid
84   void setLockValidating(bool toLock) { myIsValidationLock = toLock; }
85
86   /// Returns state of validation locking
87   bool isValidationLocked() const { return myIsValidationLock; }
88
89   /// Sets apply state to the value and emit signal about this state is changed
90   /// \param theEnabled the state value
91   void setApplyEnabled(const bool theEnabled);
92
93   /// Returns enable apply state 
94   /// \return theEnabled a boolean value
95   bool isApplyEnabled() const;
96
97   public slots:
98   /// Slot that commits the current operation.
99   void onCommitOperation();
100   /// Slot that aborts the current operation.
101   void onAbortOperation();
102   /// Slot that validates the current operation using the validateOperation method.
103   void onValidateOperation();
104   /// Commit all operations
105   bool commitAllOperations();
106   /// Abort all operations
107   bool abortAllOperations();
108
109 signals:
110   /// Signal about an operation is started. It is emitted after the start() of operation is done.
111   void operationStarted(ModuleBase_Operation* theOperation);
112
113   /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
114   /// \param theOperation a stopped operation
115   void operationStopped(ModuleBase_Operation* theOperation);
116
117   /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
118   void operationResumed(ModuleBase_Operation* theOperation);
119
120   /// Emitted when current operation is Committed
121   void operationCommitted(ModuleBase_Operation* theOperation);
122
123   /// Emitted when current operation is aborted
124   void operationAborted(ModuleBase_Operation* theOperation);
125
126   /// Signal is emitted after the apply enable state changed.
127   void validationStateChanged(bool);
128
129   /// Signal is emitted after the apply enable state changed.
130   void nestedStateChanged(bool);
131
132   /// Signal is emitted after the current operation is filled with existing preselection.
133   void operationActivatedByPreselection();
134
135   /// Signal is emitted after the key released click.
136   void keyEnterReleased();
137
138  protected:
139   /// Commits the current operatin if it is valid
140   bool commitOperation();
141
142   /// Sets the current operation or NULL
143   /// \param theOperation the started operation
144   void resumeOperation(ModuleBase_Operation* theOperation);
145
146  public slots:
147   /// SLOT, that is called by the key in the property panel is clicked.
148   /// \param theEvent the mouse event
149   bool onKeyReleased(QKeyEvent* theEvent);
150
151   protected slots:
152   /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
153   /// If there is a suspended operation, restart it.
154   void onOperationStopped();
155
156   /// Slot called on operation start
157   void onOperationStarted();
158
159   /// Slot called on operation abort
160   void onOperationAborted();
161
162   /// Slot called on operation commit
163   void onOperationCommitted();
164
165   /// Slot called on operation resume
166   void onOperationResumed();
167
168  private:
169   typedef QList<ModuleBase_Operation*> Operations;  ///< definition for a list of operations
170   Operations myOperations;  ///< a stack of started operations. The active operation is on top,
171                             // others are suspended and started by the active is finished
172
173   /// Lock/Unlock access to Ok button in property panel
174   bool myIsValidationLock;
175   /// Lock/Unlock access to Ok button in property panel
176   bool myIsApplyEnabled;
177 };
178
179 #endif