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