1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ModuleBase_Operation_H
22 #define ModuleBase_Operation_H
24 #include <ModuleBase.h>
28 #include <QStringList>
30 class ModuleBase_ModelWidget;
31 class ModuleBase_OperationDescription;
32 class ModuleBase_IPropertyPanel;
37 * \class ModuleBase_Operation
39 * \brief Base class for all operations
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();
53 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
59 /// \param theId the operation identifier
60 /// \param theParent the QObject parent
61 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
64 virtual ~ModuleBase_Operation();
66 /// Returns the operation description
67 /// /returns the instance of the description class
68 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
70 /// Returns list of granted operation indices
71 const QStringList& grantedOperationIds() const;
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);
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;
83 /// Returns True if data of its feature was modified during operation
84 virtual bool isModified() const { return myIsModified; }
86 /// Change the modified state of the operation
87 void setIsModified(const bool theIsModified) { myIsModified = theIsModified; }
89 /// Returns operations Id from it's description
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;
96 /// \brief Set property pane to the operation
97 /// \param theProp a property panel instance
98 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
100 /// \return Currently installed property panel
101 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
104 /// The operation is started
105 void beforeStarted();
106 /// The operation is started
109 /// The operation is aborted
110 void beforeAborted();
111 /// The operation is aborted
114 /// The operation is committed
115 void beforeCommitted();
116 /// The operation is committed
119 /// The operation is aborted or committed
122 /// The operation is resumed
125 /// The operation is postponed
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
135 /// \return true if the start is successful
136 virtual bool start();
138 /// Deactivates current operation which can be resumed later.
139 virtual void postpone();
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
147 virtual void resume();
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();
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();
159 /// Changes the modified flag of the operation
160 void onValuesChanged();
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);
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() {}
171 /// Implementation of specific steps on postpone operation
172 virtual void postponeOperation() {}
174 /// Virtual method called when operation stopped - committed or aborted.
175 virtual void stopOperation() {}
177 /// Virtual method called when operation aborted (see abort() method for more description)
178 virtual void abortOperation() {}
180 /// Virtual method called when operation committed (see commit() method for more description)
181 virtual void commitOperation() {};
183 /// Virtual method called after operation committed (see commit() method for more description)
184 virtual void afterCommitOperation() {}
186 /// Virtual method called after operation resume (see resume() method for more description)
187 virtual void resumeOperation() {}
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;
194 /// the container to have the operation description
195 ModuleBase_OperationDescription* myDescription;
197 /// Modified feature flag
200 /// List of operations IDs which are granted of the current operation
201 QStringList myGrantedIds;
203 /// Access to property panel
204 ModuleBase_IPropertyPanel* myPropertyPanel;