]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Operation.h
Salome HOME
833dbf57c80872c4234aafdf4a3191b3da4d0c68
[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 <QObject>
16 #include <QString>
17
18 #include <boost/shared_ptr.hpp>
19
20 class ModelAPI_Feature;
21 class ModelAPI_Document;
22
23 class QKeyEvent;
24
25 /*!
26  \class ModuleBase_Operation
27  * \brief Base class for all operations
28  *
29  *  Base class for all operations. If you perform an action it is reasonable to create
30  *  operation intended for this. This is a base class for all operations which provides
31  *  mechanism for correct starting operations, starting operations above already started
32  *  ones, committing operations and so on. To create own operation it is reasonable to
33  *  inherit it from this class and redefines virtual methods to provide own behavior
34  *  Main virtual methods are
35  *  - virtual bool      isReadyToStart();
36  *  - virtual void      startOperation();
37  *  - virtual void      abortOperation();
38  *  - virtual void      commitOperation();
39  */
40
41 class MODULEBASE_EXPORT ModuleBase_Operation: public ModuleBase_IOperation
42 {
43 Q_OBJECT
44
45 public:
46   /// Constructor
47   /// \param theId the operation identifier
48   /// \param theParent the QObject parent
49   ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
50   /// Destructor
51   virtual ~ModuleBase_Operation();
52
53   // Returns operations Id from it's description
54   QString id() const;
55   /// Returns the operation feature
56   /// \return the feature
57   boost::shared_ptr<ModelAPI_Feature> feature() const;
58
59   /// Returns whether the nested operations are enabled.
60   /// The state can depend on the operation current state.
61   /// \return enabled state
62   virtual bool isNestedOperationsEnabled() const;
63
64   // Data model methods.
65   /// Stores a real value in model.
66   /// \param theValue - to store
67   void storeReal(double theValue);
68   /// Stores a custom value in model.
69   void storeCustomValue();
70
71   virtual void keyReleased(std::string theName, QKeyEvent* theEvent) {};
72
73 protected:
74   /// Virtual method called when operation started (see start() method for more description)
75   /// Default impl calls corresponding slot and commits immediately.
76   virtual void startOperation();
77   /// Virtual method called when operation stopped - committed or aborted.
78   virtual void stopOperation();
79   /// Virtual method called when operation aborted (see abort() method for more description)
80   virtual void abortOperation();
81   /// Virtual method called when operation committed (see commit() method for more description)
82   virtual void commitOperation();
83   /// Virtual method called after operation committed (see commit() method for more description)
84   virtual void afterCommitOperation();
85
86   /// Send update message by loop
87   void flushUpdated();
88   /// Send created message by loop
89   void flushCreated();
90
91   /// Creates an operation new feature
92   /// \param theFlushMessage the flag whether the create message should be flushed
93   /// \returns the created feature
94   virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
95
96   /// Returns the operation feature
97   /// \return the feature
98   void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
99
100 private:
101   boost::shared_ptr<ModelAPI_Feature> myFeature; /// the operation feature to be handled
102 };
103
104 #endif