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