1 // Copyright (C) 2014-2019 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
20 #ifndef ModuleBase_Operation_H
21 #define ModuleBase_Operation_H
23 #include <ModuleBase.h>
27 #include <QStringList>
29 class ModuleBase_ModelWidget;
30 class ModuleBase_OperationDescription;
31 class ModuleBase_IPropertyPanel;
36 * \class ModuleBase_Operation
38 * \brief Base class for all operations
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();
52 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
58 /// \param theId the operation identifier
59 /// \param theParent the QObject parent
60 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
63 virtual ~ModuleBase_Operation();
65 /// Returns the operation description
66 /// /returns the instance of the description class
67 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
69 /// Returns list of granted operation indices
70 const QStringList& grantedOperationIds() const;
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);
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;
82 /// Returns True if data of its feature was modified during operation
83 virtual bool isModified() const { return myIsModified; }
85 /// Change the modified state of the operation
86 void setIsModified(const bool theIsModified) { myIsModified = theIsModified; }
88 /// Returns operations Id from it's description
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;
95 /// \brief Set property pane to the operation
96 /// \param theProp a property panel instance
97 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
99 /// \return Currently installed property panel
100 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
102 QString helpFileName() const { return myHelpFileName; }
104 void setHelpFileName(QString theName) {
105 myHelpFileName = theName;
108 void setHideFacesVisible(bool isVisible) { myHideFacesVisibilityState = isVisible; }
110 bool isHideFacesVisible() const { return myHideFacesVisibilityState; }
113 /// The operation is started
114 void beforeStarted();
115 /// The operation is started
118 /// The operation is aborted
119 void beforeAborted();
120 /// The operation is aborted
123 /// The operation is committed
124 void beforeCommitted();
125 /// The operation is committed
128 /// The operation is aborted or committed
131 /// The operation is resumed
134 /// The operation is postponed
139 /// Public slot. Verifies whether operation can be started and starts operation.
140 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
141 /// to change behavior of operation. There is no point in using this method. It would
142 /// be better to inherit own operator from base one and redefine startOperation method
144 /// \return true if the start is successful
145 virtual bool start();
147 /// Deactivates current operation which can be resumed later.
148 virtual void postpone();
150 /// Resumes operation
151 /// Public slot. Verifies whether operation can be started and starts operation.
152 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
153 /// to change behavior of operation. There is no point in using this method. It would
154 /// be better to inherit own operator from base one and redefine startOperation method
156 virtual void resume();
159 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
160 /// Redefine abortOperation method to change behavior of operation instead
161 virtual void abort();
163 /// Commits operation
164 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
165 /// Redefine commitOperation method to change behavior of operation instead
166 virtual bool commit();
168 /// Changes the modified flag of the operation
169 void onValuesChanged();
171 /// Changes the modified flag of the operation if the current state of the widget is modified
172 /// \param thePreviousState the previous vlaue state of the widget
173 void onValueStateChanged(int thePreviousState);
176 /// Virtual method called when operation started (see start() method for more description)
177 /// Default impl calls corresponding slot and commits immediately.
178 virtual void startOperation() {}
180 /// Implementation of specific steps on postpone operation
181 virtual void postponeOperation() {}
183 /// Virtual method called when operation stopped - committed or aborted.
184 virtual void stopOperation() {}
186 /// Virtual method called when operation aborted (see abort() method for more description)
187 virtual void abortOperation() {}
189 /// Virtual method called when operation committed (see commit() method for more description)
190 virtual void commitOperation() {};
192 /// Virtual method called after operation committed (see commit() method for more description)
193 virtual void afterCommitOperation() {}
195 /// Virtual method called after operation resume (see resume() method for more description)
196 virtual void resumeOperation() {}
198 /// Verifies whether this operator can be commited.
199 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
200 virtual bool canBeCommitted() const;
203 /// the container to have the operation description
204 ModuleBase_OperationDescription* myDescription;
206 /// Modified feature flag
209 /// List of operations IDs which are granted of the current operation
210 QStringList myGrantedIds;
212 /// Access to property panel
213 ModuleBase_IPropertyPanel* myPropertyPanel;
215 QString myHelpFileName;
217 /// Visibility state of HideFaces panel before the operation launch
218 bool myHideFacesVisibilityState;