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;
71 /// Sets a list of model widgets, according to the operation feature xml definition
72 /// \param theXmlRepresentation an xml feature definition
73 /// \param theWidgets a list of widgets
74 //void setModelWidgets(const std::string& theXmlRepresentation,
75 // QList<ModuleBase_ModelWidget*> theWidgets);
77 /// Returns True if data of its feature was modified during operation
78 virtual bool isModified() const { return myIsModified; }
80 /// Returns True id the current operation is launched in editing mode
81 bool isEditOperation() const { return myIsEditing; }
83 /// Returns list of nested features
84 QStringList nestedFeatures() const { return myNestedFeatures; }
86 /// Sets list of nested features
87 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
90 // Returns operations Id from it's description
93 /// Returns the operation feature
94 /// \return the feature
95 FeaturePtr feature() const;
98 * Must return True if the operation's feature is valid.
99 * Since IOperation does not have any feature returns false.
101 virtual bool isValid() const;
103 /// Sets the operation feature
104 void setFeature(FeaturePtr theFeature);
106 /// Returns True if the current operation works with the given object (feature or result)
107 virtual bool hasObject(ObjectPtr theObj) const;
109 //virtual void keyReleased(const int theKey) {};
111 /// If operation needs to redisplay its result during operation
112 /// then this method has to return True
113 //virtual bool hasPreview() const { return false; }
115 /// Initialisation of operation with preliminary selection
116 /// \param theSelected the list of selected presentations
117 /// \param theHighlighted the list of highlighted presentations
118 /// \param theViewer a viewer to have the viewer the eye position
119 virtual void initSelection(ModuleBase_ISelection* theSelection,
120 ModuleBase_IViewer* /* theViewer*/);
122 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
124 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
126 /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
127 virtual void activateByPreselection();
129 /// If the operation works with feature which is sub-feature of another one
130 /// then this variable has to be initialised by parent feature
131 /// before operation feature creating
132 void setParentFeature(CompositeFeaturePtr theParent) { myParentFeature = theParent; }
133 CompositeFeaturePtr parentFeature() const { return myParentFeature; }
136 void started(); /// the operation is started
137 void aborted(); /// the operation is aborted
138 void committed(); /// the operation is committed
139 void stopped(); /// the operation is aborted or committed
140 void resumed(); /// the operation is resumed
141 void postponed(); /// the operation is postponed
142 void activatedByPreselection(); /// the operation is filled with existing preselection
146 /// Public slot. Verifies whether operation can be started and starts operation.
147 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
148 /// to change behavior of operation. There is no point in using this method. It would
149 /// be better to inherit own operator from base one and redefine startOperation method
153 /// Deactivates current operation which can be resumed later.
156 /// Resumes operation
157 /// Public slot. Verifies whether operation can be started and starts operation.
158 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
159 /// to change behavior of operation. There is no point in using this method. It would
160 /// be better to inherit own operator from base one and redefine startOperation method
165 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
166 /// Redefine abortOperation method to change behavior of operation instead
169 /// Commits operation
170 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
171 /// Redefine commitOperation method to change behavior of operation instead
174 /// Alias for start/abort slots
175 /// Public slot. Aborts operation if false, else does nothing.
176 /// Provided for S/S compatibility with QAction's toggle(bool)
177 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
178 void setRunning(bool theState);
180 // Data model methods.
181 /// Stores a custom value in model.
182 //virtual void storeCustomValue();
184 /// Slots which listen the mode widget activation
185 /// \param theWidget the model widget
186 //virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
189 /// Virtual method called when operation started (see start() method for more description)
190 /// Default impl calls corresponding slot and commits immediately.
191 virtual void startOperation() {}
193 /// Implementation of specific steps on postpone operation
194 virtual void postponeOperation() {}
196 /// Virtual method called when operation stopped - committed or aborted.
197 virtual void stopOperation() {}
199 /// Virtual method called when operation aborted (see abort() method for more description)
200 virtual void abortOperation() {}
202 /// Virtual method called when operation committed (see commit() method for more description)
203 virtual void commitOperation() {}
205 /// Virtual method called after operation committed (see commit() method for more description)
206 virtual void afterCommitOperation() {}
208 /// Virtual method called after operation resume (see resume() method for more description)
209 virtual void resumeOperation() {}
211 /// Send update message by loop
214 /// Send created message by loop
217 /// Creates an operation new feature
218 /// \param theFlushMessage the flag whether the create message should be flushed
219 /// \param theCompositeFeature the feature that must be used for adding the created object or null
220 /// \returns the created
221 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
223 /// Verifies whether this operator can be commited.
224 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
225 virtual bool canBeCommitted() const;
227 /// Returns pointer to the root document.
228 std::shared_ptr<ModelAPI_Document> document() const;
230 /// Set value to the active widget
231 /// \param theFeature the feature
232 /// \param theX the horizontal coordinate
233 /// \param theY the vertical coordinate
234 /// \return true if the point is set
235 //virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
237 /// Return a widget value point by the selection and the viewer position
238 /// The default realization returns false
239 /// \param thePrs the presentation
240 /// \param theViewer a viewer to have the viewer the eye position
241 /// \param theX the horizontal coordinate
242 /// \param theY the vertical coordinate
243 /// \return true if the point exits in the selection
244 virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
245 ModuleBase_IViewer* theViewer,
246 double& theX, double& theY);
248 // Removes the preselection information and clears the map of preselection
249 void clearPreselection();
252 FeaturePtr myFeature; /// the operation feature to be handled
254 /// the container to have the operation description
255 ModuleBase_OperationDescription* myDescription;
257 /// Editing feature flag
260 /// Modified feature flag
263 /// List of nested operations IDs
264 QStringList myNestedFeatures;
266 /// List of pre-selected object
267 QList<ModuleBase_ViewerPrs> myPreSelection;
269 /// Access to property panel
270 ModuleBase_IPropertyPanel* myPropertyPanel;
272 /// If the operation works with feature which is sub-feature of another one
273 /// then this variable has to be initialised by parent feature
274 /// before operation feature creating
275 CompositeFeaturePtr myParentFeature;