]> SALOME platform Git repositories - modules/gui.git/blob - src/SUIT/SUIT_Operation.h
Salome HOME
4f1b617b98575ddb0e62199f5a4b621974b86d76
[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 "SUIT.h"
35
36 #include <qobject.h>
37 #include <qguardedptr.h>
38
39 class SUIT_Study;
40 class SUIT_Application;
41
42 /*!
43  * \brief Base class for all operations
44  *
45  *  Base class for all operations. If you perform an action it is reasonable to create
46  *  operation intended for this. This is a base class for all operations which provides
47  *  mechanism for correct starting operations, starting operations above already started
48  *  ones, committing operations and so on. To create own operation it is reasonable to
49  *  inherit it from this class and redefines virtual methods to provide own behavior
50  *  Main virtual methods are
51  *  - virtual bool      isReadyToStart();
52  *  - virtual void      startOperation();
53  *  - virtual void      abortOperation();
54  *  - virtual void      commitOperation();
55  *  - virtual void      resumeOperation();
56  *  - virtual void      suspendOperation();
57 */
58 #ifdef WIN32
59 #pragma warning( disable:4251 )
60 #endif
61
62 class SUIT_EXPORT SUIT_Operation : public QObject
63 {
64   Q_OBJECT
65
66 public:
67   /*! Enum describes state of operation */
68   enum OperationState
69   {
70     Waiting,  //!< Operation is not used (it is not run or suspended)
71     Running,  //!< Operation is started
72     Suspended //!< Operation is started but suspended (other operation is performed above it)
73   };
74
75   /*!
76   * Enum describes execution status of operation. Execution status often used after
77   * ending work of operation which was started from this one. In this case this
78   * operation can ask previously started operation whether it finished successfully.
79   */
80   enum ExecStatus
81   {
82     Rejected, //!< Operation has not performed any action (modification of data model for example)
83     Accepted  //!< Operation has performed an actions and must be stopped
84   };
85
86   /*!
87   * Enum describes setting of the operation.
88   */
89   enum Flags
90   {
91     None        = 0x00, //!< None options
92     Transaction = 0x01  //!< Automatically open (commit/abort) transaction during start (commit/abort).
93   };
94
95 public:
96   SUIT_Operation( SUIT_Application* );
97   virtual ~SUIT_Operation();
98
99   OperationState    state() const;
100   bool              isActive() const;
101   bool              isRunning() const;
102
103   SUIT_Study*       study() const;
104   virtual void      setStudy( SUIT_Study* theStudy );
105   
106   SUIT_Application* application() const;
107   virtual void      setApplication( SUIT_Application* theApp );
108
109   virtual bool      isValid( SUIT_Operation* theOtherOp ) const;
110   virtual bool      isGranted() const;
111
112   bool              setSlot( const QObject* theReceiver, const char* theSlot );
113
114   void              setFlags( const int );
115   void              clearFlags( const int );
116   bool              testFlags( const int ) const;
117
118   virtual QString   operationName() const;
119
120 signals:
121   void              started( SUIT_Operation* );
122   void              aborted( SUIT_Operation* );
123   void              committed( SUIT_Operation* );
124
125   void              stopped( SUIT_Operation* );
126   void              resumed( SUIT_Operation* );
127   void              suspended( SUIT_Operation* );
128
129   void              callSlot();
130
131 public slots:
132   void              start();
133   void              abort();
134   void              commit();
135   void              resume();
136   void              suspend();
137
138 protected:
139   virtual bool      isReadyToStart() const;
140
141   virtual void      stopOperation();
142   virtual void      startOperation();
143   virtual void      abortOperation();
144   virtual void      commitOperation();
145   virtual void      resumeOperation();
146   virtual void      suspendOperation();
147
148   virtual bool      openTransaction();
149   virtual bool      abortTransaction();
150   virtual bool      hasTransaction() const;
151   virtual bool      commitTransaction( const QString& = QString::null );
152
153   int               execStatus() const;
154   void              setExecStatus( const int );
155
156   void              setState( const OperationState );
157
158   void              start( SUIT_Operation*, const bool = false );
159
160 private:
161   typedef QGuardedPtr<SUIT_Study> StudyPtr;
162
163 private:
164   SUIT_Application* myApp;        //!< application for this operation
165   int               myFlags;      //!< operation flags
166   StudyPtr          myStudy;      //!< study for this operation
167   OperationState    myState;      //!< Operation state
168   ExecStatus        myExecStatus; //!< Execution status
169
170   friend class SUIT_Study;
171 };
172
173 #ifdef WIN32
174 #pragma warning( default:4251 )
175 #endif
176
177 #endif