2 * ModuleBase_Operation.h
4 * Created on: Apr 2, 2014
8 #ifndef ModuleBase_Operation_H
9 #define ModuleBase_Operation_H
11 #include <ModuleBase.h>
13 #include <ModelAPI_Feature.h>
17 #include <QStringList>
19 #include <boost/shared_ptr.hpp>
21 class ModelAPI_Document;
22 class ModuleBase_ModelWidget;
23 class ModuleBase_OperationDescription;
28 \class ModuleBase_Operation
29 * \brief Base class for all operations
31 * Base class for all operations. If you perform an action it is reasonable to create
32 * operation intended for this. This is a base class for all operations which provides
33 * mechanism for correct starting operations, starting operations above already started
34 * ones, committing operations and so on. To create own operation it is reasonable to
35 * inherit it from this class and redefines virtual methods to provide own behavior
36 * Main virtual methods are
37 * - virtual bool isReadyToStart();
38 * - virtual void startOperation();
39 * - virtual void abortOperation();
40 * - virtual void commitOperation();
43 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
49 /// \param theId the operation identifier
50 /// \param theParent the QObject parent
51 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
53 virtual ~ModuleBase_Operation();
55 /// Returns the operation description
56 /// /returns the instance of the description class
57 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
60 * Must return true if this operation can be launched as nested for any current operation
61 * and it is not necessary to check this operation on validity. By default
62 * the operation is not granted.
63 * The method has to be redefined for granted operations.
65 virtual bool isGranted(ModuleBase_Operation* theOperation) const { return false; }
67 /// Sets a list of model widgets, according to the operation feature xml definition
68 /// \param theXmlRepresentation an xml feature definition
69 /// \param theWidgets a list of widgets
70 //void setModelWidgets(const std::string& theXmlRepresentation,
71 // QList<ModuleBase_ModelWidget*> theWidgets);
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 /// Returns whether the nested operations are enabled.
100 /// The state can depend on the operation current state.
101 /// \return enabled state
102 virtual bool isNestedOperationsEnabled() const;
104 /// Sets the operation feature
105 void setEditingFeature(FeaturePtr theFeature);
107 /// Returns True if the current operation works with the given object (feature or result)
108 virtual bool hasObject(ObjectPtr theObj) const;
110 virtual void keyReleased(const int theKey) {};
112 virtual void activateNextToCurrentWidget() {};
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; }
119 void started(); /// the operation is started
120 void aborted(); /// the operation is aborted
121 void committed(); /// the operation is committed
122 void stopped(); /// the operation is aborted or committed
123 void resumed(); /// the operation is resumed
125 /// Signals about the activating of the next widget
126 /// \param theWidget the previous active widget
127 void activateNextWidget(ModuleBase_ModelWidget* theWidget);
131 /// Public slot. Verifies whether operation can be started and starts operation.
132 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
133 /// to change behavior of operation. There is no point in using this method. It would
134 /// be better to inherit own operator from base one and redefine startOperation method
137 /// Resumes operation
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
145 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
146 /// Redefine abortOperation method to change behavior of operation instead
148 /// Commits operation
149 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
150 /// Redefine commitOperation method to change behavior of operation instead
153 /// Alias for start/abort slots
154 /// Public slot. Aborts operation if false, else does nothing.
155 /// Provided for S/S compatibility with QAction's toggle(bool)
156 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
157 void setRunning(bool theState);
159 // Data model methods.
160 /// Stores a custom value in model.
161 virtual void storeCustomValue();
163 /// Slots which listen the mode widget activation
164 /// \param theWidget the model widget
165 virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
168 /// Virtual method called when operation started (see start() method for more description)
169 /// Default impl calls corresponding slot and commits immediately.
170 virtual void startOperation();
172 /// Virtual method called when operation stopped - committed or aborted.
173 virtual void stopOperation();
175 /// Virtual method called when operation aborted (see abort() method for more description)
176 virtual void abortOperation();
178 /// Virtual method called when operation committed (see commit() method for more description)
179 virtual void commitOperation();
181 /// Virtual method called after operation committed (see commit() method for more description)
182 virtual void afterCommitOperation();
184 /// Send update message by loop
186 /// Send created message by loop
189 /// Creates an operation new feature
190 /// \param theFlushMessage the flag whether the create message should be flushed
191 /// \returns the created feature
192 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
194 /// Sets the operation feature
195 void setFeature(FeaturePtr theFeature);
197 /// Verifies whether this operator can be commited.
198 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
199 virtual bool canBeCommitted() const;
201 /// Returns pointer to the root document.
202 boost::shared_ptr<ModelAPI_Document> document() const;
206 FeaturePtr myFeature; /// the operation feature to be handled
208 /// the container to have the operation description
209 ModuleBase_OperationDescription* myDescription;
211 /// Editing feature flag
214 /// Modified feature flag
217 /// List of nested operations IDs
218 QStringList myNestedFeatures;