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
33 * \brief Base class for all operations
35 * Base class for all operations. If you perform an action it is reasonable to create
36 * operation intended for this. This is a base class for all operations which provides
37 * mechanism for correct starting operations, starting operations above already started
38 * ones, committing operations and so on. To create own operation it is reasonable to
39 * inherit it from this class and redefines virtual methods to provide own behavior
40 * Main virtual methods are
41 * - virtual bool isReadyToStart();
42 * - virtual void startOperation();
43 * - virtual void abortOperation();
44 * - virtual void commitOperation();
47 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
53 /// \param theId the operation identifier
54 /// \param theParent the QObject parent
55 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
57 virtual ~ModuleBase_Operation();
59 /// Returns the operation description
60 /// /returns the instance of the description class
61 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
64 * Must return true if this operation can be launched as nested for any current operation
65 * and it is not necessary to check this operation on validity. By default
66 * the operation is not granted.
67 * The method has to be redefined for granted operations.
69 virtual bool isGranted(QString theId) const;
72 /// Returns True if data of its feature was modified during operation
73 virtual bool isModified() const { return myIsModified; }
75 /// Returns True id the current operation is launched in editing mode
76 bool isEditOperation() const { return myIsEditing; }
78 /// Returns list of nested features
79 QStringList nestedFeatures() const { return myNestedFeatures; }
81 /// Sets list of nested features
82 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
85 /// Returns operations Id from it's description
88 /// Returns the operation feature
89 /// \return the feature
90 FeaturePtr feature() const;
93 * Must return True if the operation's feature is valid.
94 * Since IOperation does not have any feature returns false.
96 virtual bool isValid() const;
98 /// Sets the operation feature
99 void setFeature(FeaturePtr theFeature);
101 /// Returns True if the current operation works with the given object (feature or result)
102 virtual bool hasObject(ObjectPtr theObj) const;
104 /// Initialisation of operation with preliminary selection
105 /// \param theSelection an instance of Selection class
106 /// \param theViewer a viewer to have the viewer the eye position
107 virtual void initSelection(ModuleBase_ISelection* theSelection,
108 ModuleBase_IViewer* theViewer);
110 /// \brief Set property pane to the operation
111 /// \param theProp a property panel instance
112 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
114 /// \return Currently installed property panel
115 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
117 /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
118 virtual void activateByPreselection();
120 /// If the operation works with feature which is sub-feature of another one
121 /// then this variable has to be initialised by parent feature
122 /// before operation feature creating
123 void setParentFeature(CompositeFeaturePtr theParent) { myParentFeature = theParent; }
125 /// \return Installed parent feature (can be NULL)
126 CompositeFeaturePtr parentFeature() const { return myParentFeature; }
129 /// The operation is started
132 /// The operation is aborted
135 /// The operation is committed
138 /// The operation is aborted or committed
141 /// The operation is resumed
144 /// The operation is postponed
147 /// The operation is filled with existing preselection
148 void activatedByPreselection();
152 /// Public slot. Verifies whether operation can be started and starts operation.
153 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
154 /// to change behavior of operation. There is no point in using this method. It would
155 /// be better to inherit own operator from base one and redefine startOperation method
159 /// Deactivates current operation which can be resumed later.
162 /// Resumes operation
163 /// Public slot. Verifies whether operation can be started and starts operation.
164 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
165 /// to change behavior of operation. There is no point in using this method. It would
166 /// be better to inherit own operator from base one and redefine startOperation method
171 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
172 /// Redefine abortOperation method to change behavior of operation instead
175 /// Commits operation
176 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
177 /// Redefine commitOperation method to change behavior of operation instead
180 /// Alias for start/abort slots
181 /// Public slot. Aborts operation if false, else does nothing.
182 /// Provided for S/S compatibility with QAction's toggle(bool)
183 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
184 void setRunning(bool theState);
187 /// Virtual method called when operation started (see start() method for more description)
188 /// Default impl calls corresponding slot and commits immediately.
189 virtual void startOperation() {}
191 /// Implementation of specific steps on postpone operation
192 virtual void postponeOperation() {}
194 /// Virtual method called when operation stopped - committed or aborted.
195 virtual void stopOperation() {}
197 /// Virtual method called when operation aborted (see abort() method for more description)
198 virtual void abortOperation() {}
200 /// Virtual method called when operation committed (see commit() method for more description)
201 virtual void commitOperation() {}
203 /// Virtual method called after operation committed (see commit() method for more description)
204 virtual void afterCommitOperation() {}
206 /// Virtual method called after operation resume (see resume() method for more description)
207 virtual void resumeOperation() {}
209 /// Send update message by loop
212 /// Send created message by loop
215 /// Creates an operation new feature
216 /// \param theFlushMessage the flag whether the create message should be flushed
217 /// \returns the created feature
218 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
220 /// Verifies whether this operator can be commited.
221 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
222 virtual bool canBeCommitted() const;
224 /// Returns pointer to the root document.
225 std::shared_ptr<ModelAPI_Document> document() const;
227 /// Return a widget value point by the selection and the viewer position
228 /// The default realization returns false
229 /// \param thePrs the presentation
230 /// \param theViewer a viewer to have the viewer the eye position
231 /// \param theX the horizontal coordinate
232 /// \param theY the vertical coordinate
233 /// \return true if the point exits in the selection
234 virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
235 ModuleBase_IViewer* theViewer,
236 double& theX, double& theY);
238 /// Removes the preselection information and clears the map of preselection
239 void clearPreselection();
242 /// The operation feature to be handled
243 FeaturePtr myFeature;
245 /// the container to have the operation description
246 ModuleBase_OperationDescription* myDescription;
248 /// Editing feature flag
251 /// Modified feature flag
254 /// List of nested operations IDs
255 QStringList myNestedFeatures;
257 /// List of pre-selected object
258 QList<ModuleBase_ViewerPrs> myPreSelection;
260 /// Access to property panel
261 ModuleBase_IPropertyPanel* myPropertyPanel;
263 /// If the operation works with feature which is sub-feature of another one
264 /// then this variable has to be initialised by parent feature
265 /// before operation feature creating
266 CompositeFeaturePtr myParentFeature;