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>
22 class ModuleBase_ModelWidget;
23 class ModuleBase_OperationDescription;
24 class ModuleBase_IPropertyPanel;
29 \class ModuleBase_Operation
30 * \brief Base class for all operations
32 * Base class for all operations. If you perform an action it is reasonable to create
33 * operation intended for this. This is a base class for all operations which provides
34 * mechanism for correct starting operations, starting operations above already started
35 * ones, committing operations and so on. To create own operation it is reasonable to
36 * inherit it from this class and redefines virtual methods to provide own behavior
37 * Main virtual methods are
38 * - virtual bool isReadyToStart();
39 * - virtual void startOperation();
40 * - virtual void abortOperation();
41 * - virtual void commitOperation();
44 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
50 /// \param theId the operation identifier
51 /// \param theParent the QObject parent
52 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
54 virtual ~ModuleBase_Operation();
56 /// Returns the operation description
57 /// /returns the instance of the description class
58 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
61 * Must return true if this operation can be launched as nested for any current operation
62 * and it is not necessary to check this operation on validity. By default
63 * the operation is not granted.
64 * The method has to be redefined for granted operations.
66 virtual bool isGranted(ModuleBase_Operation* theOperation) const { return false; }
68 /// Sets a list of model widgets, according to the operation feature xml definition
69 /// \param theXmlRepresentation an xml feature definition
70 /// \param theWidgets a list of widgets
71 //void setModelWidgets(const std::string& theXmlRepresentation,
72 // QList<ModuleBase_ModelWidget*> theWidgets);
74 /// Returns True if data of its feature was modified during operation
75 virtual bool isModified() const { return myIsModified; }
77 /// Returns True id the current operation is launched in editing mode
78 bool isEditOperation() const { return myIsEditing; }
80 /// Returns list of nested features
81 QStringList nestedFeatures() const { return myNestedFeatures; }
83 /// Sets list of nested features
84 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
87 // Returns operations Id from it's description
90 /// Returns the operation feature
91 /// \return the feature
92 FeaturePtr feature() const;
95 * Must return True if the operation's feature is valid.
96 * Since IOperation does not have any feature returns false.
98 virtual bool isValid() const;
100 /// Returns whether the nested operations are enabled.
101 /// The state can depend on the operation current state.
102 /// \return enabled state
103 virtual bool isNestedOperationsEnabled() const;
105 /// Sets the operation feature
106 void setFeature(FeaturePtr theFeature);
108 /// Returns True if the current operation works with the given object (feature or result)
109 virtual bool hasObject(ObjectPtr theObj) const;
111 virtual void keyReleased(const int theKey) {};
113 /// If operation needs to redisplay its result during operation
114 /// then this method has to return True
115 virtual bool hasPreview() const { return false; }
117 /// Initialisation of operation with preliminary selection
118 /// \param theSelected the list of selected presentations
119 /// \param theHighlighted the list of highlighted presentations
120 virtual void initSelection(const QList<ModuleBase_ViewerPrs>& theSelected,
121 const QList<ModuleBase_ViewerPrs>& theHighlighted);
123 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
125 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
128 void started(); /// the operation is started
129 void aborted(); /// the operation is aborted
130 void committed(); /// the operation is committed
131 void stopped(); /// the operation is aborted or committed
132 void resumed(); /// the operation is resumed
136 /// Public slot. Verifies whether operation can be started and starts operation.
137 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
138 /// to change behavior of operation. There is no point in using this method. It would
139 /// be better to inherit own operator from base one and redefine startOperation method
142 /// Resumes operation
143 /// Public slot. Verifies whether operation can be started and starts operation.
144 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
145 /// to change behavior of operation. There is no point in using this method. It would
146 /// be better to inherit own operator from base one and redefine startOperation method
150 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
151 /// Redefine abortOperation method to change behavior of operation instead
153 /// Commits operation
154 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
155 /// Redefine commitOperation method to change behavior of operation instead
158 /// Alias for start/abort slots
159 /// Public slot. Aborts operation if false, else does nothing.
160 /// Provided for S/S compatibility with QAction's toggle(bool)
161 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
162 void setRunning(bool theState);
164 // Data model methods.
165 /// Stores a custom value in model.
166 virtual void storeCustomValue();
168 /// Slots which listen the mode widget activation
169 /// \param theWidget the model widget
170 virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
173 /// Virtual method called when operation started (see start() method for more description)
174 /// Default impl calls corresponding slot and commits immediately.
175 virtual void startOperation();
177 /// Virtual method called when operation stopped - committed or aborted.
178 virtual void stopOperation();
180 /// Virtual method called when operation aborted (see abort() method for more description)
181 virtual void abortOperation();
183 /// Virtual method called when operation committed (see commit() method for more description)
184 virtual void commitOperation();
186 /// Virtual method called after operation committed (see commit() method for more description)
187 virtual void afterCommitOperation();
189 /// Send update message by loop
191 /// Send created message by loop
194 /// Creates an operation new feature
195 /// \param theFlushMessage the flag whether the create message should be flushed
196 /// \param theCompositeFeature the feature that must be used for adding the created object or null
197 /// \returns the created
198 virtual FeaturePtr createFeature(const bool theFlushMessage = true,
199 CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
201 /// Verifies whether this operator can be commited.
202 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
203 virtual bool canBeCommitted() const;
205 /// Returns pointer to the root document.
206 boost::shared_ptr<ModelAPI_Document> document() const;
208 /// Activates widgets by preselection if it is accepted
209 virtual void activateByPreselection();
211 /// Set value to the active widget
212 /// \param theFeature the feature
213 /// \param theX the horizontal coordinate
214 /// \param theY the vertical coordinate
215 /// \return true if the point is set
216 virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
219 FeaturePtr myFeature; /// the operation feature to be handled
221 /// the container to have the operation description
222 ModuleBase_OperationDescription* myDescription;
224 /// Editing feature flag
227 /// Modified feature flag
230 /// List of nested operations IDs
231 QStringList myNestedFeatures;
233 /// List of pre-selected object
234 QList<ModuleBase_ViewerPrs> myPreSelection;
236 /// Access to property panel
237 ModuleBase_IPropertyPanel* myPropertyPanel;