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 /// \param theId the operation identifier
55 /// \param theParent the QObject parent
56 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
58 virtual ~ModuleBase_Operation();
60 /// Returns the operation description
61 /// /returns the instance of the description class
62 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
65 * Must return true if this operation can be launched as nested for any current operation
66 * and it is not necessary to check this operation on validity. By default
67 * the operation is not granted.
68 * The method has to be redefined for granted operations.
70 virtual bool isGranted(QString theId) const;
73 /// Returns True if data of its feature was modified during operation
74 virtual bool isModified() const { return myIsModified; }
76 /// Returns True id the current operation is launched in editing mode
77 bool isEditOperation() const { return myIsEditing; }
79 /// Returns list of nested features
80 QStringList nestedFeatures() const { return myNestedFeatures; }
82 /// Sets list of nested features
83 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
86 /// Returns operations Id from it's description
89 /// Returns the operation feature
90 /// \return the feature
91 FeaturePtr feature() const;
94 * Must return True if the operation's feature is valid.
95 * Since IOperation does not have any feature returns false.
97 virtual bool isValid() const;
99 /// Sets the operation feature
100 void setFeature(FeaturePtr theFeature);
102 /// Returns True if the current operation works with the given object (feature or result)
103 virtual bool hasObject(ObjectPtr theObj) const;
105 /// Initialisation of operation with preliminary selection
106 /// \param theSelection an instance of Selection class
107 /// \param theViewer a viewer to have the viewer the eye position
108 virtual void initSelection(ModuleBase_ISelection* theSelection,
109 ModuleBase_IViewer* theViewer);
111 /// \brief Set property pane to the operation
112 /// \param theProp a property panel instance
113 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
115 /// \return Currently installed property panel
116 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
118 /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
119 virtual void activateByPreselection();
121 /// If the operation works with feature which is sub-feature of another one
122 /// then this variable has to be initialised by parent feature
123 /// before operation feature creating
124 void setParentFeature(CompositeFeaturePtr theParent);
126 /// \return Installed parent feature (can be NULL)
127 CompositeFeaturePtr parentFeature() const;
130 /// The operation is started
133 /// The operation is aborted
136 /// The operation is committed
139 /// The operation is aborted or committed
142 /// The operation is resumed
145 /// The operation is postponed
148 /// The operation is filled with existing preselection
149 void activatedByPreselection();
153 /// Public slot. Verifies whether operation can be started and starts operation.
154 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
155 /// to change behavior of operation. There is no point in using this method. It would
156 /// be better to inherit own operator from base one and redefine startOperation method
160 /// Deactivates current operation which can be resumed later.
163 /// Resumes operation
164 /// Public slot. Verifies whether operation can be started and starts operation.
165 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
166 /// to change behavior of operation. There is no point in using this method. It would
167 /// be better to inherit own operator from base one and redefine startOperation method
172 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
173 /// Redefine abortOperation method to change behavior of operation instead
176 /// Commits operation
177 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
178 /// Redefine commitOperation method to change behavior of operation instead
181 /// Alias for start/abort slots
182 /// Public slot. Aborts operation if false, else does nothing.
183 /// Provided for S/S compatibility with QAction's toggle(bool)
184 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
185 void setRunning(bool theState);
188 /// Virtual method called when operation started (see start() method for more description)
189 /// Default impl calls corresponding slot and commits immediately.
190 virtual void startOperation() {}
192 /// Implementation of specific steps on postpone operation
193 virtual void postponeOperation() {}
195 /// Virtual method called when operation stopped - committed or aborted.
196 virtual void stopOperation() {}
198 /// Virtual method called when operation aborted (see abort() method for more description)
199 virtual void abortOperation() {}
201 /// Virtual method called when operation committed (see commit() method for more description)
202 virtual void commitOperation() {}
204 /// Virtual method called after operation committed (see commit() method for more description)
205 virtual void afterCommitOperation() {}
207 /// Virtual method called after operation resume (see resume() method for more description)
208 virtual void resumeOperation() {}
210 /// Send update message by loop
213 /// Send created message by loop
216 /// Creates an operation new feature
217 /// \param theFlushMessage the flag whether the create message should be flushed
218 /// \returns the created feature
219 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
221 /// Verifies whether this operator can be commited.
222 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
223 virtual bool canBeCommitted() const;
225 /// Returns pointer to the root document.
226 std::shared_ptr<ModelAPI_Document> document() const;
228 /// Return a widget value point by the selection and the viewer position
229 /// The default realization returns false
230 /// \param thePrs the presentation
231 /// \param theViewer a viewer to have the viewer the eye position
232 /// \param theX the horizontal coordinate
233 /// \param theY the vertical coordinate
234 /// \return true if the point exits in the selection
235 virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
236 ModuleBase_IViewer* theViewer,
237 double& theX, double& theY);
239 /// Removes the preselection information and clears the map of preselection
240 void clearPreselection();
243 /// The operation feature to be handled
244 FeaturePtr myFeature;
246 /// the container to have the operation description
247 ModuleBase_OperationDescription* myDescription;
249 /// Editing feature flag
252 /// Modified feature flag
255 /// List of nested operations IDs
256 QStringList myNestedFeatures;
258 /// List of pre-selected object
259 QList<ModuleBase_ViewerPrs> myPreSelection;
261 /// Access to property panel
262 ModuleBase_IPropertyPanel* myPropertyPanel;
264 /// If the operation works with feature which is sub-feature of another one
265 /// then this variable has to be initialised by parent feature
266 /// before operation feature creating
267 CompositeFeaturePtr myParentFeature;