Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.h
1 /*
2  * ModuleBase_Operation.h
3  *
4  *  Created on: Apr 2, 2014
5  *      Author: sbh
6  */
7
8
9 #ifndef ModuleBase_Operation_H
10 #define ModuleBase_Operation_H
11
12 #include <ModuleBase.h>
13 #include <ModuleBase_IOperation.h>
14
15 #include "ModelAPI_Feature.h"
16
17 #include <QObject>
18 #include <QString>
19
20 #include <boost/shared_ptr.hpp>
21
22 class ModelAPI_Document;
23 class ModuleBase_ModelWidget;
24
25 class QKeyEvent;
26
27 /*!
28  \class ModuleBase_Operation
29  * \brief Base class for all operations
30  *
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();
41  */
42
43 class MODULEBASE_EXPORT ModuleBase_Operation: public ModuleBase_IOperation
44 {
45 Q_OBJECT
46
47 public:
48   /// Constructor
49   /// \param theId the operation identifier
50   /// \param theParent the QObject parent
51   ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
52   /// Destructor
53   virtual ~ModuleBase_Operation();
54
55   // Returns operations Id from it's description
56   QString id() const;
57   /// Returns the operation feature
58   /// \return the feature
59   FeaturePtr feature() const;
60
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;
65
66   // Data model methods.
67   /// Stores a custom value in model.
68   void storeCustomValue();
69
70   virtual void keyReleased(std::string theName, QKeyEvent* theEvent) {};
71
72   /// Sets the operation feature
73   void setEditingFeature(FeaturePtr theFeature);
74
75   /// Returns True if the current operation works with the given object (feature or result)
76   virtual bool hasObject(ObjectPtr theObj) const;
77
78 public slots:
79   /// Slots which listen the mode widget activation
80   /// \param theWidget the model widget
81   virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
82
83 signals:
84   /// Signals about the activating of the next widget
85   /// \param theWidget the previous active widget
86   void activateNextWidget(ModuleBase_ModelWidget* theWidget);
87
88 protected:
89   /// Virtual method called when operation started (see start() method for more description)
90   /// Default impl calls corresponding slot and commits immediately.
91   virtual void startOperation();
92   /// Virtual method called when operation stopped - committed or aborted.
93   virtual void stopOperation();
94   /// Virtual method called when operation aborted (see abort() method for more description)
95   virtual void abortOperation();
96   /// Virtual method called when operation committed (see commit() method for more description)
97   virtual void commitOperation();
98   /// Virtual method called after operation committed (see commit() method for more description)
99   virtual void afterCommitOperation();
100
101   /// Send update message by loop
102   void flushUpdated();
103   /// Send created message by loop
104   void flushCreated();
105
106   /// Creates an operation new feature
107   /// \param theFlushMessage the flag whether the create message should be flushed
108   /// \returns the created feature
109   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
110
111 protected:
112   /// Sets the operation feature
113   void setFeature(FeaturePtr theFeature);
114
115   /// Verifies whether this operator can be commited.
116   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
117   virtual bool canBeCommitted() const;
118
119 protected:
120   FeaturePtr myFeature; /// the operation feature to be handled
121 };
122
123 #endif