Salome HOME
Copyrights update
[modules/gui.git] / src / SUIT / SUIT_Operation.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 /**
20 *  SALOME SalomeApp
21 *
22 *  Copyright (C) 2005  CEA/DEN, EDF R&D
23 *
24 *
25 *
26 *  File   : SUIT_Operation.h
27 *  Author : Unknown
28 *  Module : SALOME
29 */
30
31 #ifndef SUIT_OPERATION_H
32 #define SUIT_OPERATION_H
33
34 #include <qobject.h>
35
36 #include "SUIT.h"
37
38 class SUIT_Study;
39 class SUIT_Application;
40
41 /*!
42  * \brief Base class for all operations
43  *
44  *  Base class for all operations. If you perform an action it is reasonable to create
45  *  operation intended for this. This is a base class for all operations which provides
46  *  mechanism for correct starting operations, starting operations above already started
47  *  ones, committing operations and so on. To create own operation it is reasonable to
48  *  inherit it from this class and redefines virtual methods to provide own behavior
49  *  Main virtual methods are
50  *  - virtual bool      isReadyToStart();
51  *  - virtual void      startOperation();
52  *  - virtual void      abortOperation();
53  *  - virtual void      commitOperation();
54  *  - virtual void      resumeOperation();
55  *  - virtual void      suspendOperation();
56 */
57 class SUIT_EXPORT SUIT_Operation : public QObject
58 {
59   Q_OBJECT
60
61 public:
62   /*! Enum describes state of operation */
63   enum OperationState
64   {
65     Waiting,  //!< Operation is not used (it is not run or suspended)
66     Running,  //!< Operation is started
67     Suspended //!< Operation is started but suspended (other operation is performed above it)
68   };
69
70   /*!
71   * Enum describes execution status of operation. Execution status often used after
72   * ending work of operation which was started from this one. In this case this
73   * operation can ask previously started operation whether it finished successfully.
74   */
75   enum ExecStatus
76   {
77     Rejected, //!< Operation has not performed any action (modification of data model for example)
78     Accepted  //!< Operation has performed an actions and must be stopped
79   };
80
81   /*!
82   * Enum describes setting of the operation.
83   */
84   enum Flags
85   {
86     None        = 0x00, //!< None options
87     Transaction = 0x01  //!< Automatically open (commit/abort) transaction during start (commit/abort).
88   };
89
90 public:
91   SUIT_Operation( SUIT_Application* );
92   virtual ~SUIT_Operation();
93
94   OperationState    state() const;
95   bool              isActive() const;
96   bool              isRunning() const;
97
98   SUIT_Study*       study() const;
99   virtual void      setStudy( SUIT_Study* theStudy );
100   
101   SUIT_Application* application() const;
102   virtual void      setApplication( SUIT_Application* theApp );
103
104   virtual bool      isValid( SUIT_Operation* theOtherOp ) const;
105   virtual bool      isGranted() const;
106
107   bool              setSlot( const QObject* theReceiver, const char* theSlot );
108
109   void              setFlags( const int );
110   void              clearFlags( const int );
111   bool              testFlags( const int ) const;
112
113   virtual QString   operationName() const;
114
115 signals:
116   void              started( SUIT_Operation* );
117   void              aborted( SUIT_Operation* );
118   void              committed( SUIT_Operation* );
119
120   void              stopped( SUIT_Operation* );
121   void              resumed( SUIT_Operation* );
122   void              suspended( SUIT_Operation* );
123
124   void              callSlot();
125
126 public slots:
127   void              start();
128   void              abort();
129   void              commit();
130   void              resume();
131   void              suspend();
132
133 protected:
134   virtual bool      isReadyToStart() const;
135
136   virtual void      stopOperation();
137   virtual void      startOperation();
138   virtual void      abortOperation();
139   virtual void      commitOperation();
140   virtual void      resumeOperation();
141   virtual void      suspendOperation();
142
143   virtual bool      openTransaction();
144   virtual bool      abortTransaction();
145   virtual bool      hasTransaction() const;
146   virtual bool      commitTransaction( const QString& = QString::null );
147
148   int               execStatus() const;
149   void              setExecStatus( const int );
150
151   void              setState( const OperationState );
152
153   void              start( SUIT_Operation*, const bool = false );
154
155 private:
156   SUIT_Application* myApp;        //!< application for this operation
157   int               myFlags;      //!< operation flags
158   SUIT_Study*       myStudy;      //!< study for this operation
159   OperationState    myState;      //!< Operation state
160   ExecStatus        myExecStatus; //!< Execution status
161
162   friend class SUIT_Study;
163 };
164
165 #endif