]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Operation.h
Salome HOME
Provide editing of Point and Extrusion objects
[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
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 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;
64
65   // Data model methods.
66   /// Stores a real value in model.
67   /// \param theValue - to store
68   void storeReal(double theValue);
69   /// Stores a custom value in model.
70   void storeCustomValue();
71
72   virtual void keyReleased(std::string theName, QKeyEvent* theEvent) {};
73
74   /// Sets the operation feature
75   void setEditingFeature(FeaturePtr theFeature);
76
77   bool isEditOperation() const { return myIsEditing; }
78
79 protected:
80   /// Virtual method called when operation started (see start() method for more description)
81   /// Default impl calls corresponding slot and commits immediately.
82   virtual void startOperation();
83   /// Virtual method called when operation stopped - committed or aborted.
84   virtual void stopOperation();
85   /// Virtual method called when operation aborted (see abort() method for more description)
86   virtual void abortOperation();
87   /// Virtual method called when operation committed (see commit() method for more description)
88   virtual void commitOperation();
89   /// Virtual method called after operation committed (see commit() method for more description)
90   virtual void afterCommitOperation();
91
92   /// Send update message by loop
93   void flushUpdated();
94   /// Send created message by loop
95   void flushCreated();
96
97   /// Creates an operation new feature
98   /// \param theFlushMessage the flag whether the create message should be flushed
99   /// \returns the created feature
100   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
101
102   /// Sets the operation feature
103   void setFeature(FeaturePtr theFeature);
104
105 private:
106   FeaturePtr myFeature; /// the operation feature to be handled
107
108   bool myIsEditing;
109 };
110
111 #endif