2 * ModuleBase_Operation.h
4 * Created on: Apr 2, 2014
8 #ifndef ModuleBase_Operation_H
9 #define ModuleBase_Operation_H
11 #include <ModuleBase.h>
12 #include <ModuleBase_ViewerPrs.h>
14 #include <ModelAPI_CompositeFeature.h>
15 #include <ModelAPI_Document.h>
19 #include <QStringList>
21 class ModuleBase_ModelWidget;
22 class ModuleBase_OperationDescription;
23 class ModuleBase_IPropertyPanel;
24 class ModuleBase_ISelection;
25 class ModuleBase_IViewer;
30 \class ModuleBase_Operation
31 * \brief Base class for all operations
33 * Base class for all operations. If you perform an action it is reasonable to create
34 * operation intended for this. This is a base class for all operations which provides
35 * mechanism for correct starting operations, starting operations above already started
36 * ones, committing operations and so on. To create own operation it is reasonable to
37 * inherit it from this class and redefines virtual methods to provide own behavior
38 * Main virtual methods are
39 * - virtual bool isReadyToStart();
40 * - virtual void startOperation();
41 * - virtual void abortOperation();
42 * - virtual void commitOperation();
45 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
51 /// \param theId the operation identifier
52 /// \param theParent the QObject parent
53 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
55 virtual ~ModuleBase_Operation();
57 /// Returns the operation description
58 /// /returns the instance of the description class
59 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
62 * Must return true if this operation can be launched as nested for any current operation
63 * and it is not necessary to check this operation on validity. By default
64 * the operation is not granted.
65 * The method has to be redefined for granted operations.
67 virtual bool isGranted(ModuleBase_Operation* theOperation) const { return false; }
69 /// Sets a list of model widgets, according to the operation feature xml definition
70 /// \param theXmlRepresentation an xml feature definition
71 /// \param theWidgets a list of widgets
72 //void setModelWidgets(const std::string& theXmlRepresentation,
73 // QList<ModuleBase_ModelWidget*> theWidgets);
75 /// Returns True if data of its feature was modified during operation
76 virtual bool isModified() const { return myIsModified; }
78 /// Returns True id the current operation is launched in editing mode
79 bool isEditOperation() const { return myIsEditing; }
81 /// Returns list of nested features
82 QStringList nestedFeatures() const { return myNestedFeatures; }
84 /// Sets list of nested features
85 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
88 // Returns operations Id from it's description
91 /// Returns the operation feature
92 /// \return the feature
93 FeaturePtr feature() const;
96 * Must return True if the operation's feature is valid.
97 * Since IOperation does not have any feature returns false.
99 virtual bool isValid() const;
101 /// Returns whether the nested operations are enabled.
102 /// The state can depend on the operation current state.
103 /// \return enabled state
104 virtual bool isNestedOperationsEnabled() const;
106 /// Sets the operation feature
107 void setFeature(FeaturePtr theFeature);
109 /// Returns True if the current operation works with the given object (feature or result)
110 virtual bool hasObject(ObjectPtr theObj) const;
112 virtual void keyReleased(const int theKey) {};
114 /// If operation needs to redisplay its result during operation
115 /// then this method has to return True
116 virtual bool hasPreview() const { return false; }
118 /// Initialisation of operation with preliminary selection
119 /// \param theSelected the list of selected presentations
120 /// \param theHighlighted the list of highlighted presentations
121 /// \param theViewer a viewer to have the viewer the eye position
122 virtual void initSelection(ModuleBase_ISelection* theSelection,
123 ModuleBase_IViewer* /* theViewer*/);
125 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
127 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
129 /// Activates widgets by preselection if it is accepted
130 virtual bool activateByPreselection();
133 void started(); /// the operation is started
134 void aborted(); /// the operation is aborted
135 void committed(); /// the operation is committed
136 void stopped(); /// the operation is aborted or committed
137 void resumed(); /// the operation is resumed
141 /// Public slot. Verifies whether operation can be started and starts operation.
142 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
143 /// to change behavior of operation. There is no point in using this method. It would
144 /// be better to inherit own operator from base one and redefine startOperation method
147 /// Resumes operation
148 /// Public slot. Verifies whether operation can be started and starts operation.
149 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
150 /// to change behavior of operation. There is no point in using this method. It would
151 /// be better to inherit own operator from base one and redefine startOperation method
155 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
156 /// Redefine abortOperation method to change behavior of operation instead
158 /// Commits operation
159 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
160 /// Redefine commitOperation method to change behavior of operation instead
163 /// Alias for start/abort slots
164 /// Public slot. Aborts operation if false, else does nothing.
165 /// Provided for S/S compatibility with QAction's toggle(bool)
166 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
167 void setRunning(bool theState);
169 // Data model methods.
170 /// Stores a custom value in model.
171 virtual void storeCustomValue();
173 /// Slots which listen the mode widget activation
174 /// \param theWidget the model widget
175 virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
178 /// Virtual method called when operation started (see start() method for more description)
179 /// Default impl calls corresponding slot and commits immediately.
180 virtual void startOperation();
182 /// Virtual method called when operation stopped - committed or aborted.
183 virtual void stopOperation();
185 /// Virtual method called when operation aborted (see abort() method for more description)
186 virtual void abortOperation();
188 /// Virtual method called when operation committed (see commit() method for more description)
189 virtual void commitOperation();
191 /// Virtual method called after operation committed (see commit() method for more description)
192 virtual void afterCommitOperation();
194 /// Send update message by loop
196 /// Send created message by loop
199 /// Creates an operation new feature
200 /// \param theFlushMessage the flag whether the create message should be flushed
201 /// \param theCompositeFeature the feature that must be used for adding the created object or null
202 /// \returns the created
203 virtual FeaturePtr createFeature(const bool theFlushMessage = true,
204 CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
206 /// Verifies whether this operator can be commited.
207 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
208 virtual bool canBeCommitted() const;
210 /// Returns pointer to the root document.
211 boost::shared_ptr<ModelAPI_Document> document() const;
213 /// Set value to the active widget
214 /// \param theFeature the feature
215 /// \param theX the horizontal coordinate
216 /// \param theY the vertical coordinate
217 /// \return true if the point is set
218 virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
221 FeaturePtr myFeature; /// the operation feature to be handled
223 /// the container to have the operation description
224 ModuleBase_OperationDescription* myDescription;
226 /// Editing feature flag
229 /// Modified feature flag
232 /// List of nested operations IDs
233 QStringList myNestedFeatures;
235 /// List of pre-selected object
236 QList<ModuleBase_ViewerPrs> myPreSelection;
238 /// Access to property panel
239 ModuleBase_IPropertyPanel* myPropertyPanel;