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   /// Must return true if this operation can be launched as nested for any current operation
60   /// and it is not necessary to check this operation on validity. By default 
61   /// the operation is not granted.
62   /// The method has to be redefined for granted operations.
63   virtual bool isGranted(QString theId) const;
64
65   /// Returns True if data of its feature was modified during operation
66   virtual bool isModified() const { return myIsModified; }
67
68   /// Change the modified state of the operation
69   void setIsModified(const bool theIsModified) { myIsModified = theIsModified;  }
70
71   /// Returns operations Id from it's description
72   QString id() const;
73
74   /// Must return True if the operation's feature is valid.
75   /// Since IOperation does not have any feature returns false.
76   virtual bool isValid() const;
77
78   /// \brief Set property pane to the operation
79   /// \param theProp a property panel instance
80   virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
81
82   /// \return Currently installed property panel
83   ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
84
85 signals:
86   /// The operation is started
87   void started();
88
89   /// The operation is aborted
90   void aborted();
91
92   /// The operation is committed
93   void committed();
94
95   /// The operation is aborted or committed
96   void stopped();
97
98   /// The operation is resumed
99   void resumed();
100
101   /// The operation is postponed
102   void postponed();
103
104  public slots:
105   /// Starts operation
106   /// Public slot. Verifies whether operation can be started and starts operation.
107   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
108   /// to change behavior of operation. There is no point in using this method. It would
109   /// be better to inherit own operator from base one and redefine startOperation method
110   /// instead.
111   virtual void start();
112
113   /// Deactivates current operation which can be resumed later.
114   virtual void postpone();
115
116   /// Resumes operation
117   /// Public slot. Verifies whether operation can be started and starts operation.
118   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
119   /// to change behavior of operation. There is no point in using this method. It would
120   /// be better to inherit own operator from base one and redefine startOperation method
121   /// instead.
122   virtual void resume();
123
124   /// Aborts operation
125   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
126   /// Redefine abortOperation method to change behavior of operation instead
127   virtual void abort();
128
129   /// Commits operation
130   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
131   /// Redefine commitOperation method to change behavior of operation instead
132   virtual bool commit();
133
134   /// Changes the modified flag of the operation
135   void onValuesChanged();
136
137  protected:
138   /// Virtual method called when operation started (see start() method for more description)
139   /// Default impl calls corresponding slot and commits immediately.
140    virtual void startOperation() {}
141
142   /// Implementation of specific steps on postpone operation
143   virtual void postponeOperation() {}
144
145   /// Virtual method called when operation stopped - committed or aborted.
146   virtual void stopOperation() {}
147
148   /// Virtual method called when operation aborted (see abort() method for more description)
149   virtual void abortOperation() {}
150
151   /// Virtual method called when operation committed (see commit() method for more description)
152   virtual void commitOperation() {};
153
154   /// Virtual method called after operation committed (see commit() method for more description)
155   virtual void afterCommitOperation() {}
156
157   /// Virtual method called after operation resume (see resume() method for more description)
158   virtual void resumeOperation() {}
159
160   /// Verifies whether this operator can be commited.
161   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
162   virtual bool canBeCommitted() const;
163
164 private:
165   /// the container to have the operation description
166   ModuleBase_OperationDescription* myDescription;
167
168   /// Modified feature flag
169   bool myIsModified;
170
171   /// Access to property panel
172   ModuleBase_IPropertyPanel* myPropertyPanel;
173 };
174
175 #endif