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