Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModuleBase_Operation_H
22 #define ModuleBase_Operation_H
23
24 #include <ModuleBase.h>
25
26 #include <QObject>
27 #include <QString>
28 #include <QStringList>
29
30 class ModuleBase_ModelWidget;
31 class ModuleBase_OperationDescription;
32 class ModuleBase_IPropertyPanel;
33
34 class QKeyEvent;
35
36 /*!
37  * \class ModuleBase_Operation
38  * \ingroup GUI
39  * \brief Base class for all operations
40  *
41  *  Base class for all operations. If you perform an action it is reasonable to create
42  *  operation intended for this. This is a base class for all operations which provides
43  *  mechanism for correct starting operations, starting operations above already started
44  *  ones, committing operations and so on. To create own operation it is reasonable to
45  *  inherit it from this class and redefines virtual methods to provide own behavior
46  *  Main virtual methods are
47  *  - virtual bool      isReadyToStart();
48  *  - virtual void      startOperation();
49  *  - virtual void      abortOperation();
50  *  - virtual void      commitOperation();
51  */
52
53 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
54 {
55 Q_OBJECT
56
57  public:
58   /// Constructor
59   /// \param theId the operation identifier
60   /// \param theParent the QObject parent
61   ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
62
63   /// Destructor
64   virtual ~ModuleBase_Operation();
65
66   /// Returns the operation description
67   /// /returns the instance of the description class
68   ModuleBase_OperationDescription* getDescription() const { return myDescription; }
69
70   /// Returns list of granted operation indices
71   const QStringList& grantedOperationIds() const;
72
73   /// Sets list of operation indices, which can be started without the current operation stop
74   /// \param theList an ids
75   void setGrantedOperationIds(const QStringList& theList);
76
77   /// Must return true if this operation can be launched as nested for any current operation
78   /// and it is not necessary to check this operation on validity. By default
79   /// the operation is not granted.
80   /// The method has to be redefined for granted operations.
81   virtual bool isGranted(QString theId) const;
82
83   /// Returns True if data of its feature was modified during operation
84   virtual bool isModified() const { return myIsModified; }
85
86   /// Change the modified state of the operation
87   void setIsModified(const bool theIsModified) { myIsModified = theIsModified;  }
88
89   /// Returns operations Id from it's description
90   QString id() const;
91
92   /// Must return True if the operation's feature is valid.
93   /// Since IOperation does not have any feature returns false.
94   virtual bool isValid() const;
95
96   /// \brief Set property pane to the operation
97   /// \param theProp a property panel instance
98   virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
99
100   /// \return Currently installed property panel
101   ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
102
103 signals:
104   /// The operation is started
105   void beforeStarted();
106   /// The operation is started
107   void started();
108
109   /// The operation is aborted
110   void beforeAborted();
111   /// The operation is aborted
112   void aborted();
113
114   /// The operation is committed
115   void beforeCommitted();
116   /// The operation is committed
117   void committed();
118
119   /// The operation is aborted or committed
120   void stopped();
121
122   /// The operation is resumed
123   void resumed();
124
125   /// The operation is postponed
126   void postponed();
127
128  public slots:
129   /// Starts operation
130   /// Public slot. Verifies whether operation can be started and starts operation.
131   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
132   /// to change behavior of operation. There is no point in using this method. It would
133   /// be better to inherit own operator from base one and redefine startOperation method
134   /// instead.
135   /// \return true if the start is successful
136   virtual bool start();
137
138   /// Deactivates current operation which can be resumed later.
139   virtual void postpone();
140
141   /// Resumes operation
142   /// Public slot. Verifies whether operation can be started and starts operation.
143   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
144   /// to change behavior of operation. There is no point in using this method. It would
145   /// be better to inherit own operator from base one and redefine startOperation method
146   /// instead.
147   virtual void resume();
148
149   /// Aborts operation
150   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
151   /// Redefine abortOperation method to change behavior of operation instead
152   virtual void abort();
153
154   /// Commits operation
155   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
156   /// Redefine commitOperation method to change behavior of operation instead
157   virtual bool commit();
158
159   /// Changes the modified flag of the operation
160   void onValuesChanged();
161
162   /// Changes the modified flag of the operation if the current state of the widget is modified
163   /// \param thePreviousState the previous vlaue state of the widget
164   void onValueStateChanged(int thePreviousState);
165
166  protected:
167   /// Virtual method called when operation started (see start() method for more description)
168   /// Default impl calls corresponding slot and commits immediately.
169    virtual void startOperation() {}
170
171   /// Implementation of specific steps on postpone operation
172   virtual void postponeOperation() {}
173
174   /// Virtual method called when operation stopped - committed or aborted.
175   virtual void stopOperation() {}
176
177   /// Virtual method called when operation aborted (see abort() method for more description)
178   virtual void abortOperation() {}
179
180   /// Virtual method called when operation committed (see commit() method for more description)
181   virtual void commitOperation() {};
182
183   /// Virtual method called after operation committed (see commit() method for more description)
184   virtual void afterCommitOperation() {}
185
186   /// Virtual method called after operation resume (see resume() method for more description)
187   virtual void resumeOperation() {}
188
189   /// Verifies whether this operator can be commited.
190   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
191   virtual bool canBeCommitted() const;
192
193 private:
194   /// the container to have the operation description
195   ModuleBase_OperationDescription* myDescription;
196
197   /// Modified feature flag
198   bool myIsModified;
199
200   /// List of operations IDs which are granted of the current operation
201   QStringList myGrantedIds;
202
203   /// Access to property panel
204   ModuleBase_IPropertyPanel* myPropertyPanel;
205 };
206
207 #endif