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 #ifndef ModuleBase_Operation_H
9 #define ModuleBase_Operation_H
10
11 #include <ModuleBase.h>
12 #include <ModuleBase_IOperation.h>
13
14 #include <ModelAPI_Feature.h>
15
16 #include <QObject>
17 #include <QString>
18
19 #include <boost/shared_ptr.hpp>
20
21 class ModelAPI_Document;
22 class ModuleBase_ModelWidget;
23
24 class QKeyEvent;
25
26 /*!
27  \class ModuleBase_Operation
28  * \brief Base class for all operations
29  *
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();
40  */
41
42 class MODULEBASE_EXPORT ModuleBase_Operation : public ModuleBase_IOperation
43 {
44 Q_OBJECT
45
46  public:
47   /// Constructor
48   /// \param theId the operation identifier
49   /// \param theParent the QObject parent
50   ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
51   /// Destructor
52   virtual ~ModuleBase_Operation();
53
54   // Returns operations Id from it's description
55   QString id() const;
56   /// Returns the operation feature
57   /// \return the feature
58   FeaturePtr feature() const;
59
60   /// Returns true is feature of operation is valid.
61   virtual bool isValid() const;
62
63   /// Returns whether the nested operations are enabled.
64   /// The state can depend on the operation current state.
65   /// \return enabled state
66   virtual bool isNestedOperationsEnabled() const;
67
68   // Data model methods.
69   /// Stores a custom value in model.
70   void storeCustomValue();
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   virtual void keyReleased(const int theKey) {};
79
80   virtual void activateNextToCurrentWidget() {};
81
82   /// If operation needs to redisplay its result during operation
83   /// then this method has to return True
84   virtual bool hasPreview() const { return false; }
85
86  public slots:
87   /// Slots which listen the mode widget activation
88   /// \param theWidget the model widget
89   virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
90
91 signals:
92   /// Signals about the activating of the next widget
93   /// \param theWidget the previous active widget
94   void activateNextWidget(ModuleBase_ModelWidget* theWidget);
95
96  protected:
97   /// Virtual method called when operation started (see start() method for more description)
98   /// Default impl calls corresponding slot and commits immediately.
99   virtual void startOperation();
100   /// Virtual method called when operation stopped - committed or aborted.
101   virtual void stopOperation();
102   /// Virtual method called when operation aborted (see abort() method for more description)
103   virtual void abortOperation();
104   /// Virtual method called when operation committed (see commit() method for more description)
105   virtual void commitOperation();
106   /// Virtual method called after operation committed (see commit() method for more description)
107   virtual void afterCommitOperation();
108
109   /// Send update message by loop
110   void flushUpdated();
111   /// Send created message by loop
112   void flushCreated();
113
114   /// Creates an operation new feature
115   /// \param theFlushMessage the flag whether the create message should be flushed
116   /// \returns the created feature
117   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
118
119  protected:
120   /// Sets the operation feature
121   void setFeature(FeaturePtr theFeature);
122
123   /// Verifies whether this operator can be commited.
124   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
125   virtual bool canBeCommitted() const;
126
127  protected:
128   FeaturePtr myFeature;  /// the operation feature to be handled
129 };
130
131 #endif