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;
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(ModuleBase_ISelection* theSelection);
122 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
124 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
126 /// Activates widgets by preselection if it is accepted
127 virtual bool activateByPreselection();
130 void started(); /// the operation is started
131 void aborted(); /// the operation is aborted
132 void committed(); /// the operation is committed
133 void stopped(); /// the operation is aborted or committed
134 void resumed(); /// the operation is resumed
138 /// Public slot. Verifies whether operation can be started and starts operation.
139 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
140 /// to change behavior of operation. There is no point in using this method. It would
141 /// be better to inherit own operator from base one and redefine startOperation method
144 /// Resumes operation
145 /// Public slot. Verifies whether operation can be started and starts operation.
146 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
147 /// to change behavior of operation. There is no point in using this method. It would
148 /// be better to inherit own operator from base one and redefine startOperation method
152 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
153 /// Redefine abortOperation method to change behavior of operation instead
155 /// Commits operation
156 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
157 /// Redefine commitOperation method to change behavior of operation instead
160 /// Alias for start/abort slots
161 /// Public slot. Aborts operation if false, else does nothing.
162 /// Provided for S/S compatibility with QAction's toggle(bool)
163 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
164 void setRunning(bool theState);
166 // Data model methods.
167 /// Stores a custom value in model.
168 virtual void storeCustomValue();
170 /// Slots which listen the mode widget activation
171 /// \param theWidget the model widget
172 virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
175 /// Virtual method called when operation started (see start() method for more description)
176 /// Default impl calls corresponding slot and commits immediately.
177 virtual void startOperation();
179 /// Virtual method called when operation stopped - committed or aborted.
180 virtual void stopOperation();
182 /// Virtual method called when operation aborted (see abort() method for more description)
183 virtual void abortOperation();
185 /// Virtual method called when operation committed (see commit() method for more description)
186 virtual void commitOperation();
188 /// Virtual method called after operation committed (see commit() method for more description)
189 virtual void afterCommitOperation();
191 /// Send update message by loop
193 /// Send created message by loop
196 /// Creates an operation new feature
197 /// \param theFlushMessage the flag whether the create message should be flushed
198 /// \param theCompositeFeature the feature that must be used for adding the created object or null
199 /// \returns the created
200 virtual FeaturePtr createFeature(const bool theFlushMessage = true,
201 CompositeFeaturePtr theCompositeFeature = CompositeFeaturePtr());
203 /// Verifies whether this operator can be commited.
204 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
205 virtual bool canBeCommitted() const;
207 /// Returns pointer to the root document.
208 boost::shared_ptr<ModelAPI_Document> document() const;
210 /// Set value to the active widget
211 /// \param theFeature the feature
212 /// \param theX the horizontal coordinate
213 /// \param theY the vertical coordinate
214 /// \return true if the point is set
215 virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
218 FeaturePtr myFeature; /// the operation feature to be handled
220 /// the container to have the operation description
221 ModuleBase_OperationDescription* myDescription;
223 /// Editing feature flag
226 /// Modified feature flag
229 /// List of nested operations IDs
230 QStringList myNestedFeatures;
232 /// List of pre-selected object
233 QList<ModuleBase_ViewerPrs> myPreSelection;
235 /// Access to property panel
236 ModuleBase_IPropertyPanel* myPropertyPanel;