2 * ModuleBase_Operation.h
4 * Created on: Apr 2, 2014
9 #ifndef ModuleBase_Operation_H
10 #define ModuleBase_Operation_H
12 #include <ModuleBase.h>
13 #include <ModuleBase_IOperation.h>
15 #include "ModelAPI_Feature.h"
20 #include <boost/shared_ptr.hpp>
22 class ModelAPI_Document;
23 class ModuleBase_ModelWidget;
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 ModuleBase_IOperation
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 operations Id from it's description
57 /// Returns the operation feature
58 /// \return the feature
59 FeaturePtr feature() const;
61 /// Returns whether the nested operations are enabled.
62 /// The state can depend on the operation current state.
63 /// \return enabled state
64 virtual bool isNestedOperationsEnabled() const;
66 // Data model methods.
67 /// Stores a custom value in model.
68 void storeCustomValue();
70 virtual void keyReleased(std::string theName, QKeyEvent* theEvent) {};
72 /// Sets the operation feature
73 void setEditingFeature(FeaturePtr theFeature);
75 bool isEditOperation() const { return myIsEditing; }
78 /// Slots which listen the mode widget activation
79 /// \param theWidget the model widget
80 virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
83 /// Signals about the activating of the next widget
84 /// \param theWidget the previous active widget
85 void activateNextWidget(ModuleBase_ModelWidget* theWidget);
88 /// Virtual method called when operation started (see start() method for more description)
89 /// Default impl calls corresponding slot and commits immediately.
90 virtual void startOperation();
91 /// Virtual method called when operation stopped - committed or aborted.
92 virtual void stopOperation();
93 /// Virtual method called when operation aborted (see abort() method for more description)
94 virtual void abortOperation();
95 /// Virtual method called when operation committed (see commit() method for more description)
96 virtual void commitOperation();
97 /// Virtual method called after operation committed (see commit() method for more description)
98 virtual void afterCommitOperation();
100 /// Send update message by loop
102 /// Send created message by loop
105 /// Creates an operation new feature
106 /// \param theFlushMessage the flag whether the create message should be flushed
107 /// \returns the created feature
108 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
111 /// Sets the operation feature
112 void setFeature(FeaturePtr theFeature);
115 FeaturePtr myFeature; /// the operation feature to be handled