Salome HOME
Fix for bug 10438: Crash during Explode on Blocks operation (Global selection on...
[modules/gui.git] / src / SUIT / SUIT_Operation.h
1 /**
2 *  SALOME SalomeApp
3 *
4 *  Copyright (C) 2005  CEA/DEN, EDF R&D
5 *
6 *
7 *
8 *  File   : SUIT_Operation.h
9 *  Author : Unknown
10 *  Module : SALOME
11 */
12
13 #ifndef SUIT_OPERATION_H
14 #define SUIT_OPERATION_H
15
16 #include <qobject.h>
17
18 #include "SUIT.h"
19
20 class SUIT_Study;
21 class SUIT_Application;
22
23 /*!
24  * \brief Base class for all operations
25  *
26  *  Base class for all operations. If you perform an action it is reasonable to create
27  *  operation intended for this. This is a base class for all operations which provides
28  *  mechanism for correct starting operations, starting operations above already started
29  *  ones, committing operations and so on. To create own operation it is reasonable to
30  *  inherit it from this class and redefines virtual methods to provide own behavior
31  *  Main virtual methods are
32  *  - virtual bool      isReadyToStart();
33  *  - virtual void      startOperation();
34  *  - virtual void      abortOperation();
35  *  - virtual void      commitOperation();
36  *  - virtual void      resumeOperation();
37  *  - virtual void      suspendOperation();
38 */
39 class SUIT_EXPORT SUIT_Operation : public QObject
40 {
41   Q_OBJECT
42
43 public:
44
45   /*! Enum describes state of operation */
46   enum OperationState
47   {
48     Waiting,  //!< Operation is not used (it is not run or suspended)
49     Running,  //!< Operation is started
50     Suspended //!< Operation is started but suspended (other operation is performed above it)
51   };
52
53   /*!
54   * Enum describes execution status of operation. Execution status often used after
55   * ending work of operation which was started from this one. In this case this
56   * operation can ask previously started operation whether it finished successfully.
57   */
58   enum ExecStatus
59   {
60     Rejected, //!< Operation has not performed any action (modification of data model for example)
61     Accepted  //!< Operation has performed an actions and must be stopped
62   };
63
64 public:
65
66   SUIT_Operation( SUIT_Application* );
67   virtual ~SUIT_Operation();
68
69   OperationState    state() const;
70   bool              isActive() const;
71
72   SUIT_Study*       study() const;
73   virtual void      setStudy( SUIT_Study* theStudy );
74   
75   SUIT_Application* application() const;
76   virtual void      setApplication( SUIT_Application* theApp );
77
78   virtual bool      isValid( SUIT_Operation* theOtherOp ) const;
79   virtual bool      isGranted() const;
80
81   bool              setSlot( const QObject* theReceiver, const char* theSlot );
82
83 public slots:
84
85   void              start();
86   void              abort();
87   void              commit();
88   void              suspend();
89   void              resume();
90
91 signals:
92
93   void              started( SUIT_Operation* );
94   void              aborted( SUIT_Operation* );
95   void              resumed( SUIT_Operation* );
96   void              committed( SUIT_Operation* );
97   void              suspended( SUIT_Operation* );
98   void              stopped( SUIT_Operation* );
99   
100   void              callSlot();
101
102 protected:
103
104   virtual bool      isReadyToStart() const;
105   
106   virtual void      startOperation();
107   virtual void      abortOperation();
108   virtual void      commitOperation();
109   virtual void      suspendOperation();
110   virtual void      resumeOperation();
111
112   void              setExecStatus( const int theStatus );
113   int               execStatus() const;
114
115   void              setState( const OperationState theState );
116
117   void              start( SUIT_Operation* theOp );
118
119 private:
120
121   SUIT_Application* myApp;        //!< application for this operation
122   SUIT_Study*       myStudy;      //!< study for this operation
123   OperationState    myState;      //!< Operation state
124   ExecStatus        myExecStatus; //!< Execution status
125
126   friend class SUIT_Study;
127 };
128
129 #endif