]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Operation.h
Salome HOME
Providing Action class to have a common approach to start/finish/abort model transact...
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_Operation.h
5  *
6  *  Created on: Apr 2, 2014
7  *      Author: sbh
8  */
9
10 #ifndef ModuleBase_Operation_H
11 #define ModuleBase_Operation_H
12
13 #include <ModuleBase.h>
14
15 #include <QObject>
16 #include <QString>
17 #include <QStringList>
18
19 class ModuleBase_ModelWidget;
20 class ModuleBase_OperationDescription;
21 class ModuleBase_IPropertyPanel;
22
23 class QKeyEvent;
24
25 /*!
26  * \class ModuleBase_Operation
27  * \ingroup GUI
28  * \brief Base class for all operations
29  *
30  *  Base class for all operations. If you perform an action it is reasonable to create
31  *  operation intended for this. This is a base class for all operations which provides
32  *  mechanism for correct starting operations, starting operations above already started
33  *  ones, committing operations and so on. To create own operation it is reasonable to
34  *  inherit it from this class and redefines virtual methods to provide own behavior
35  *  Main virtual methods are
36  *  - virtual bool      isReadyToStart();
37  *  - virtual void      startOperation();
38  *  - virtual void      abortOperation();
39  *  - virtual void      commitOperation();
40  */
41
42 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
43 {
44 Q_OBJECT
45
46  public:
47   /// Constructor
48   /// \param theId the operation identifier
49   /// \param theParent the QObject parent
50   ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
51
52   /// Destructor
53   virtual ~ModuleBase_Operation();
54
55   /// Returns the operation description
56   /// /returns the instance of the description class
57   ModuleBase_OperationDescription* getDescription() const { return myDescription; }
58
59   /// Returns list of granted operation indices
60   const QStringList& grantedOperationIds() const;
61
62   /// Sets list of operation indices, which can be started without the current operation stop
63   /// \param theList an ids
64   void setGrantedOperationIds(const QStringList& theList);
65
66   /// Appends an operation index to be granted
67   /// \param theId an index
68   void addGrantedOperationId(const QString& theId);
69
70   /// Removes an operation index from the granted
71   /// \param theId an index
72   void removeGrantedOperationId(const QString& theId);
73
74   /// Must return true if this operation can be launched as nested for any current operation
75   /// and it is not necessary to check this operation on validity. By default 
76   /// the operation is not granted.
77   /// The method has to be redefined for granted operations.
78   virtual bool isGranted(QString theId) const;
79
80   /// Returns True if data of its feature was modified during operation
81   virtual bool isModified() const { return myIsModified; }
82
83   /// Change the modified state of the operation
84   void setIsModified(const bool theIsModified) { myIsModified = theIsModified;  }
85
86   /// Returns operations Id from it's description
87   QString id() const;
88
89   /// Must return True if the operation's feature is valid.
90   /// Since IOperation does not have any feature returns false.
91   virtual bool isValid() const;
92
93   /// \brief Set property pane to the operation
94   /// \param theProp a property panel instance
95   virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
96
97   /// \return Currently installed property panel
98   ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
99
100 signals:
101   /// The operation is started
102   void started();
103
104   /// The operation is aborted
105   void aborted();
106
107   /// The operation is committed
108   void committed();
109
110   /// The operation is aborted or committed
111   void stopped();
112
113   /// The operation is resumed
114   void resumed();
115
116   /// The operation is postponed
117   void postponed();
118
119  public slots:
120   /// Starts operation
121   /// Public slot. Verifies whether operation can be started and starts operation.
122   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
123   /// to change behavior of operation. There is no point in using this method. It would
124   /// be better to inherit own operator from base one and redefine startOperation method
125   /// instead.
126   virtual void start();
127
128   /// Deactivates current operation which can be resumed later.
129   virtual void postpone();
130
131   /// Resumes operation
132   /// Public slot. Verifies whether operation can be started and starts operation.
133   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
134   /// to change behavior of operation. There is no point in using this method. It would
135   /// be better to inherit own operator from base one and redefine startOperation method
136   /// instead.
137   virtual void resume();
138
139   /// Aborts operation
140   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
141   /// Redefine abortOperation method to change behavior of operation instead
142   virtual void abort();
143
144   /// Commits operation
145   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
146   /// Redefine commitOperation method to change behavior of operation instead
147   virtual bool commit();
148
149   /// Changes the modified flag of the operation
150   void onValuesChanged();
151
152  protected:
153   /// Virtual method called when operation started (see start() method for more description)
154   /// Default impl calls corresponding slot and commits immediately.
155    virtual void startOperation() {}
156
157   /// Implementation of specific steps on postpone operation
158   virtual void postponeOperation() {}
159
160   /// Virtual method called when operation stopped - committed or aborted.
161   virtual void stopOperation() {}
162
163   /// Virtual method called when operation aborted (see abort() method for more description)
164   virtual void abortOperation() {}
165
166   /// Virtual method called when operation committed (see commit() method for more description)
167   virtual void commitOperation() {};
168
169   /// Virtual method called after operation committed (see commit() method for more description)
170   virtual void afterCommitOperation() {}
171
172   /// Virtual method called after operation resume (see resume() method for more description)
173   virtual void resumeOperation() {}
174
175   /// Verifies whether this operator can be commited.
176   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
177   virtual bool canBeCommitted() const;
178
179 private:
180   /// the container to have the operation description
181   ModuleBase_OperationDescription* myDescription;
182
183   /// Modified feature flag
184   bool myIsModified;
185
186   /// List of operations IDs which are granted of the current operation
187   QStringList myGrantedIds;
188
189   /// Access to property panel
190   ModuleBase_IPropertyPanel* myPropertyPanel;
191 };
192
193 #endif