]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_IOperation.h
Salome HOME
Merge remote-tracking branch 'remotes/origin/GeomAPI'
[modules/shaper.git] / src / ModuleBase / ModuleBase_IOperation.h
1 /*
2  * ModuleBase_IOperation.h
3  *
4  *  Created on: May 5, 2014
5  *      Author: nds
6  */
7
8
9 #ifndef ModuleBase_IOperation_H
10 #define ModuleBase_IOperation_H
11
12 #include <ModuleBase.h>
13
14 #include <QObject>
15 #include <QString>
16
17 #include <boost/shared_ptr.hpp>
18
19 class ModelAPI_Document;
20 class ModuleBase_OperationDescription;
21
22 /*!
23  \class ModuleBase_IOperation
24  * \brief Base class for all operations
25  *
26  *  Base class for all operations. If you perform an action it is reasonable to create
27  *  operation intended for this. This is a base class for all operations which provides
28  *  mechanism for correct starting operations, starting operations above already started
29  *  ones, committing operations and so on. To create own operation it is reasonable to
30  *  inherit it from this class and redefines virtual methods to provide own behavior
31  *  Main virtual methods are
32  *  - virtual bool      isReadyToStart();
33  *  - virtual void      startOperation();
34  *  - virtual void      abortOperation();
35  *  - virtual void      commitOperation();
36  */
37
38 class MODULEBASE_EXPORT ModuleBase_IOperation: public QObject
39 {
40 Q_OBJECT
41
42 public:
43   /// Constructor
44   /// Constructs an empty operation. Constructor should work very fast because many
45   /// operators may be created after starting workshop but only several from them
46   /// may be used. As result this constructor stores given workshop in myApp field
47   /// and set Waiting status.
48   /// \param theId the operation identifier
49   /// \param theParent the QObject parent
50   ModuleBase_IOperation(const QString& theId = "", QObject* theParent = 0);
51   /// Destructor
52   virtual ~ModuleBase_IOperation();
53
54   /// Returns the operation description
55   /// /returns the instance of the description class
56   ModuleBase_OperationDescription* getDescription() const;
57
58   /// Verifies whether this operator can be commited.
59   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
60   virtual bool canBeCommitted() const;
61
62   /// Verifies whether this operator can be always started above any already running one
63   /// \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
64   /// This method must be redefined in derived operation if operation of derived class
65   /// must be always can start above any launched one. Default impl returns FALSE,
66   /// so it is being checked for IsValid, but some operations may overload IsGranted()
67   /// In this case they will always start, no matter what operation is running.
68   /// \param theOperation the previous running operation
69   virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
70
71 signals:
72   void started(); /// the operation is started
73   void aborted(); /// the operation is aborted
74   void committed(); /// the operation is committed
75   void stopped(); /// the operation is aborted or committed
76   void resumed(); /// the operation is resumed
77
78 public slots:
79   /// Starts operation
80   /// Public slot. Verifies whether operation can be started and starts operation.
81   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
82   /// to change behavior of operation. There is no point in using this method. It would
83   /// be better to inherit own operator from base one and redefine startOperation method
84   /// instead.
85   void start();
86   /// Resumes operation
87   /// Public slot. Verifies whether operation can be started and starts operation.
88   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
89   /// to change behavior of operation. There is no point in using this method. It would
90   /// be better to inherit own operator from base one and redefine startOperation method
91   /// instead.
92   void resume();
93   /// Aborts operation
94   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
95   /// Redefine abortOperation method to change behavior of operation instead
96   void abort();
97   /// Commits operation
98   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
99   /// Redefine commitOperation method to change behavior of operation instead
100   void commit();
101
102   /// Alias for start/abort slots
103   /// Public slot. Aborts operation if false, else does nothing.
104   /// Provided for S/S compatibility with QAction's toggle(bool)
105   /// \param theState th flag to abort, if it is true, do nothing, overwise abort
106   void setRunning(bool theState);
107
108   // Data model methods.
109   /// Stores a real value in model.
110   /// \param theValue - to store
111   virtual void storeReal(double theValue) = 0;
112   /// Stores a custom value in model.
113   virtual void storeCustomValue() = 0;
114
115 protected:
116   /// Virtual method called when operation started (see start() method for more description)
117   /// Default impl calls corresponding slot and commits immediately.
118   virtual void startOperation() = 0;
119   /// Virtual method called when operation stopped - committed or aborted.
120   virtual void stopOperation() = 0;
121   /// Virtual method called when operation aborted (see abort() method for more description)
122   virtual void abortOperation() = 0;
123   /// Virtual method called when operation committed (see commit() method for more description)
124   virtual void commitOperation() = 0;
125   /// Virtual method called after operation committed (see commit() method for more description)
126   /// it is important that the method is called after the stop() signal is emitted
127   virtual void afterCommitOperation() = 0;
128
129   /// Returns pointer to the root document.
130   boost::shared_ptr<ModelAPI_Document> document() const;
131
132 private:
133   ModuleBase_OperationDescription* myDescription; /// the container to have the operation description
134 };
135
136 #endif