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