1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_Operation.h
6 * Created on: Apr 2, 2014
10 #ifndef ModuleBase_Operation_H
11 #define ModuleBase_Operation_H
13 #include <ModuleBase.h>
14 #include <ModuleBase_ViewerPrs.h>
16 #include <ModelAPI_CompositeFeature.h>
17 #include <ModelAPI_Document.h>
21 #include <QStringList>
23 class ModuleBase_ModelWidget;
24 class ModuleBase_OperationDescription;
25 class ModuleBase_IPropertyPanel;
26 class ModuleBase_ISelection;
27 class ModuleBase_IViewer;
32 * \class ModuleBase_Operation
34 * \brief Base class for all operations
36 * Base class for all operations. If you perform an action it is reasonable to create
37 * operation intended for this. This is a base class for all operations which provides
38 * mechanism for correct starting operations, starting operations above already started
39 * ones, committing operations and so on. To create own operation it is reasonable to
40 * inherit it from this class and redefines virtual methods to provide own behavior
41 * Main virtual methods are
42 * - virtual bool isReadyToStart();
43 * - virtual void startOperation();
44 * - virtual void abortOperation();
45 * - virtual void commitOperation();
48 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
54 /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
55 static QString EditSuffix() { return "_E"; }
57 /// \param theId the operation identifier
58 /// \param theParent the QObject parent
59 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
61 virtual ~ModuleBase_Operation();
63 /// Returns the operation description
64 /// /returns the instance of the description class
65 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
68 * Must return true if this operation can be launched as nested for any current operation
69 * and it is not necessary to check this operation on validity. By default
70 * the operation is not granted.
71 * The method has to be redefined for granted operations.
73 virtual bool isGranted(QString theId) const;
76 /// Returns True if data of its feature was modified during operation
77 virtual bool isModified() const { return myIsModified; }
79 /// Returns True id the current operation is launched in editing mode
80 bool isEditOperation() const { return myIsEditing; }
82 /// Returns list of nested features
83 QStringList nestedFeatures() const { return myNestedFeatures; }
85 /// Sets list of nested features
86 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
89 /// Returns operations Id from it's description
92 /// Returns the operation feature
93 /// \return the feature
94 FeaturePtr feature() const;
97 * Must return True if the operation's feature is valid.
98 * Since IOperation does not have any feature returns false.
100 virtual bool isValid() const;
102 /// Sets the operation feature
103 void setFeature(FeaturePtr theFeature);
105 /// Returns True if the current operation works with the given object (feature or result)
106 virtual bool hasObject(ObjectPtr theObj) const;
108 /// Initialisation of operation with preliminary selection
109 /// \param theSelection an instance of Selection class
110 /// \param theViewer a viewer to have the viewer the eye position
111 virtual void initSelection(ModuleBase_ISelection* theSelection,
112 ModuleBase_IViewer* theViewer);
114 /// \brief Set property pane to the operation
115 /// \param theProp a property panel instance
116 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
118 /// \return Currently installed property panel
119 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
121 /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
122 virtual void activateByPreselection();
124 /// If the operation works with feature which is sub-feature of another one
125 /// then this variable has to be initialised by parent feature
126 /// before operation feature creating
127 void setParentFeature(CompositeFeaturePtr theParent);
129 /// \return Installed parent feature (can be NULL)
130 CompositeFeaturePtr parentFeature() const;
133 /// The operation is started
136 /// The operation is aborted
139 /// The operation is committed
142 /// The operation is aborted or committed
145 /// The operation is resumed
148 /// The operation is postponed
151 /// The operation is filled with existing preselection
152 void activatedByPreselection();
156 /// Public slot. Verifies whether operation can be started and starts operation.
157 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
158 /// to change behavior of operation. There is no point in using this method. It would
159 /// be better to inherit own operator from base one and redefine startOperation method
163 /// Deactivates current operation which can be resumed later.
166 /// Resumes operation
167 /// Public slot. Verifies whether operation can be started and starts operation.
168 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
169 /// to change behavior of operation. There is no point in using this method. It would
170 /// be better to inherit own operator from base one and redefine startOperation method
175 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
176 /// Redefine abortOperation method to change behavior of operation instead
179 /// Commits operation
180 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
181 /// Redefine commitOperation method to change behavior of operation instead
184 /// Alias for start/abort slots
185 /// Public slot. Aborts operation if false, else does nothing.
186 /// Provided for S/S compatibility with QAction's toggle(bool)
187 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
188 void setRunning(bool theState);
191 /// Virtual method called when operation started (see start() method for more description)
192 /// Default impl calls corresponding slot and commits immediately.
193 virtual void startOperation() {}
195 /// Implementation of specific steps on postpone operation
196 virtual void postponeOperation() {}
198 /// Virtual method called when operation stopped - committed or aborted.
199 virtual void stopOperation() {}
201 /// Virtual method called when operation aborted (see abort() method for more description)
202 virtual void abortOperation() {}
204 /// Virtual method called when operation committed (see commit() method for more description)
205 virtual void commitOperation() {}
207 /// Virtual method called after operation committed (see commit() method for more description)
208 virtual void afterCommitOperation() {}
210 /// Virtual method called after operation resume (see resume() method for more description)
211 virtual void resumeOperation() {}
213 /// Creates an operation new feature
214 /// \param theFlushMessage the flag whether the create message should be flushed
215 /// \returns the created feature
216 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
218 /// Verifies whether this operator can be commited.
219 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
220 virtual bool canBeCommitted() const;
222 /// Return a widget value point by the selection and the viewer position
223 /// The default realization returns false
224 /// \param thePrs the presentation
225 /// \param theViewer a viewer to have the viewer the eye position
226 /// \param theX the horizontal coordinate
227 /// \param theY the vertical coordinate
228 /// \return true if the point exits in the selection
229 virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
230 ModuleBase_IViewer* theViewer,
231 double& theX, double& theY);
233 /// Removes the preselection information and clears the map of preselection
234 void clearPreselection();
237 /// The operation feature to be handled
238 FeaturePtr myFeature;
240 /// the container to have the operation description
241 ModuleBase_OperationDescription* myDescription;
243 /// Editing feature flag
246 /// Modified feature flag
249 /// List of nested operations IDs
250 QStringList myNestedFeatures;
252 /// List of pre-selected object
253 QList<ModuleBase_ViewerPrs> myPreSelection;
255 /// Access to property panel
256 ModuleBase_IPropertyPanel* myPropertyPanel;
258 /// If the operation works with feature which is sub-feature of another one
259 /// then this variable has to be initialised by parent feature
260 /// before operation feature creating
261 CompositeFeaturePtr myParentFeature;