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_IOperation.h>
14 #include "ModelAPI_Feature.h"
19 #include <boost/shared_ptr.hpp>
21 class ModelAPI_Document;
22 class ModuleBase_ModelWidget;
27 \class ModuleBase_Operation
28 * \brief Base class for all operations
30 * Base class for all operations. If you perform an action it is reasonable to create
31 * operation intended for this. This is a base class for all operations which provides
32 * mechanism for correct starting operations, starting operations above already started
33 * ones, committing operations and so on. To create own operation it is reasonable to
34 * inherit it from this class and redefines virtual methods to provide own behavior
35 * Main virtual methods are
36 * - virtual bool isReadyToStart();
37 * - virtual void startOperation();
38 * - virtual void abortOperation();
39 * - virtual void commitOperation();
42 class MODULEBASE_EXPORT ModuleBase_Operation : public ModuleBase_IOperation
48 /// \param theId the operation identifier
49 /// \param theParent the QObject parent
50 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
52 virtual ~ModuleBase_Operation();
54 // Returns operations Id from it's description
56 /// Returns the operation feature
57 /// \return the feature
58 FeaturePtr feature() const;
60 /// Returns whether the nested operations are enabled.
61 /// The state can depend on the operation current state.
62 /// \return enabled state
63 virtual bool isNestedOperationsEnabled() const;
65 // Data model methods.
66 /// Stores a custom value in model.
67 void storeCustomValue();
69 /// Sets the operation feature
70 void setEditingFeature(FeaturePtr theFeature);
72 /// Returns True if the current operation works with the given object (feature or result)
73 virtual bool hasObject(ObjectPtr theObj) const;
75 virtual void keyReleased(const int theKey) {};
77 virtual void activateNextToCurrentWidget() {};
80 /// Slots which listen the mode widget activation
81 /// \param theWidget the model widget
82 virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
85 /// Signals about the activating of the next widget
86 /// \param theWidget the previous active widget
87 void activateNextWidget(ModuleBase_ModelWidget* theWidget);
90 /// Virtual method called when operation started (see start() method for more description)
91 /// Default impl calls corresponding slot and commits immediately.
92 virtual void startOperation();
93 /// Virtual method called when operation stopped - committed or aborted.
94 virtual void stopOperation();
95 /// Virtual method called when operation aborted (see abort() method for more description)
96 virtual void abortOperation();
97 /// Virtual method called when operation committed (see commit() method for more description)
98 virtual void commitOperation();
99 /// Virtual method called after operation committed (see commit() method for more description)
100 virtual void afterCommitOperation();
102 /// Send update message by loop
104 /// Send created message by loop
107 /// Creates an operation new feature
108 /// \param theFlushMessage the flag whether the create message should be flushed
109 /// \returns the created feature
110 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
113 /// Sets the operation feature
114 void setFeature(FeaturePtr theFeature);
116 /// Verifies whether this operator can be commited.
117 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
118 virtual bool canBeCommitted() const;
121 FeaturePtr myFeature; /// the operation feature to be handled