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