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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 * ModuleBase_Operation.h
23 * Created on: Apr 2, 2014
27 #ifndef ModuleBase_Operation_H
28 #define ModuleBase_Operation_H
30 #include <ModuleBase.h>
34 #include <QStringList>
36 class ModuleBase_ModelWidget;
37 class ModuleBase_OperationDescription;
38 class ModuleBase_IPropertyPanel;
43 * \class ModuleBase_Operation
45 * \brief Base class for all operations
47 * Base class for all operations. If you perform an action it is reasonable to create
48 * operation intended for this. This is a base class for all operations which provides
49 * mechanism for correct starting operations, starting operations above already started
50 * ones, committing operations and so on. To create own operation it is reasonable to
51 * inherit it from this class and redefines virtual methods to provide own behavior
52 * Main virtual methods are
53 * - virtual bool isReadyToStart();
54 * - virtual void startOperation();
55 * - virtual void abortOperation();
56 * - virtual void commitOperation();
59 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
65 /// \param theId the operation identifier
66 /// \param theParent the QObject parent
67 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
70 virtual ~ModuleBase_Operation();
72 /// Returns the operation description
73 /// /returns the instance of the description class
74 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
76 /// Returns list of granted operation indices
77 const QStringList& grantedOperationIds() const;
79 /// Sets list of operation indices, which can be started without the current operation stop
80 /// \param theList an ids
81 void setGrantedOperationIds(const QStringList& theList);
83 /// Must return true if this operation can be launched as nested for any current operation
84 /// and it is not necessary to check this operation on validity. By default
85 /// the operation is not granted.
86 /// The method has to be redefined for granted operations.
87 virtual bool isGranted(QString theId) const;
89 /// Returns True if data of its feature was modified during operation
90 virtual bool isModified() const { return myIsModified; }
92 /// Change the modified state of the operation
93 void setIsModified(const bool theIsModified) { myIsModified = theIsModified; }
95 /// Returns operations Id from it's description
98 /// Must return True if the operation's feature is valid.
99 /// Since IOperation does not have any feature returns false.
100 virtual bool isValid() const;
102 /// \brief Set property pane to the operation
103 /// \param theProp a property panel instance
104 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
106 /// \return Currently installed property panel
107 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
110 /// The operation is started
111 void beforeStarted();
112 /// The operation is started
115 /// The operation is aborted
116 void beforeAborted();
117 /// The operation is aborted
120 /// The operation is committed
121 void beforeCommitted();
122 /// The operation is committed
125 /// The operation is aborted or committed
128 /// The operation is resumed
131 /// The operation is postponed
136 /// Public slot. Verifies whether operation can be started and starts operation.
137 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
138 /// to change behavior of operation. There is no point in using this method. It would
139 /// be better to inherit own operator from base one and redefine startOperation method
141 /// \return true if the start is successful
142 virtual bool start();
144 /// Deactivates current operation which can be resumed later.
145 virtual void postpone();
147 /// Resumes operation
148 /// Public slot. Verifies whether operation can be started and starts operation.
149 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
150 /// to change behavior of operation. There is no point in using this method. It would
151 /// be better to inherit own operator from base one and redefine startOperation method
153 virtual void resume();
156 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
157 /// Redefine abortOperation method to change behavior of operation instead
158 virtual void abort();
160 /// Commits operation
161 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
162 /// Redefine commitOperation method to change behavior of operation instead
163 virtual bool commit();
165 /// Changes the modified flag of the operation
166 void onValuesChanged();
168 /// Changes the modified flag of the operation if the current state of the widget is modified
169 /// \param thePreviousState the previous vlaue state of the widget
170 void onValueStateChanged(int thePreviousState);
173 /// Virtual method called when operation started (see start() method for more description)
174 /// Default impl calls corresponding slot and commits immediately.
175 virtual void startOperation() {}
177 /// Implementation of specific steps on postpone operation
178 virtual void postponeOperation() {}
180 /// Virtual method called when operation stopped - committed or aborted.
181 virtual void stopOperation() {}
183 /// Virtual method called when operation aborted (see abort() method for more description)
184 virtual void abortOperation() {}
186 /// Virtual method called when operation committed (see commit() method for more description)
187 virtual void commitOperation() {};
189 /// Virtual method called after operation committed (see commit() method for more description)
190 virtual void afterCommitOperation() {}
192 /// Virtual method called after operation resume (see resume() method for more description)
193 virtual void resumeOperation() {}
195 /// Verifies whether this operator can be commited.
196 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
197 virtual bool canBeCommitted() const;
200 /// the container to have the operation description
201 ModuleBase_OperationDescription* myDescription;
203 /// Modified feature flag
206 /// List of operations IDs which are granted of the current operation
207 QStringList myGrantedIds;
209 /// Access to property panel
210 ModuleBase_IPropertyPanel* myPropertyPanel;