Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / SALOMEGUI / QAD_Operation.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : QAD_Operation.cxx
25 //  Author : UI team
26 //  Module : SALOME
27 //  $Header$
28
29 /*!
30   \class QAD_Operation QAD_Operation.h
31   \brief Base class for OCAF operations in QAD-based application.
32 */
33
34 #include "QAD.h"
35 #include "QAD_Operation.h"
36 #include "QAD_Study.h"
37 #include "QAD_Application.h"
38
39 // QT Include
40 #include <qapplication.h>
41 using namespace std;
42
43 /*!
44     Constructor 
45 */
46 QAD_Operation::QAD_Operation (QAD_Study* doc) :
47 myDoc ( doc )
48 {
49   /* this class is useless without valid doc */
50   QAD_ASSERT_DEBUG_ONLY( myDoc );
51 }
52
53 /*!
54     Destructor 
55 */
56 QAD_Operation::~QAD_Operation ()
57 {
58 }
59
60 /*!
61     Returns reference to the document
62 */
63 QAD_Study* QAD_Operation::getDoc() const
64 {
65   return myDoc;
66 }
67
68 /*!
69     Returns reference to the application
70 */
71 QAD_Application* QAD_Operation::getApp() const
72 {
73   return myDoc->getApp();
74 }
75
76 /*!
77     Checks compatibility with the other launched operations.
78     Returns \true if appointed operation can be performed.
79     By default returns \false for all operations.
80 */
81 bool QAD_Operation::compatibleWith( QAD_Operation* op ) const
82 {
83   return false; 
84 }
85
86 /*!
87     Returns true if operation can be aborted by pressing "Escape" key
88     (default behaviour).
89 */
90 bool QAD_Operation::supportCancelByEscape() const
91 {
92   return true;
93 }
94
95 /*!
96     Returns true if operation changes document data. In this case it won't be
97     launched if document is opened as "read only". Value by default is true.
98 */
99 bool QAD_Operation::changesData() const
100 {
101   return true;
102 }
103
104 /*!
105     Starts this operation.
106 */
107 bool QAD_Operation::start()
108 {    
109   /* open transaction */
110   if ( !myDoc->onOperationStarted( this ) ) 
111     return false;
112   
113   /* started OK */
114   onStartOperation();                     
115   return true;
116 }
117
118 /*!
119     Called after operation started. Does nothing by default. 
120     Override to set a desired behaviour.
121 */
122 void QAD_Operation::onStartOperation()
123 {
124 }
125
126 /*!
127     Ends the operation.
128 */
129 void QAD_Operation::finish()
130 {    
131   QApplication::setOverrideCursor( Qt::waitCursor );    
132   
133   onFinishOperation();                /* customization */    
134   myDoc->onOperationFinished( this ); /* close transaction */
135   
136   QApplication::restoreOverrideCursor();
137 }
138
139 /*!
140     Called after operation finished. Does nothing by default. 
141     Override to set a desired behaviour.
142 */
143 void QAD_Operation::onFinishOperation()
144 {
145 }
146
147 /*!
148     Suspends operation process when the document is deactivated.
149 */
150 void QAD_Operation::suspend()
151 {    
152   onSuspendOperation();                /* customization */
153   myDoc->onOperationSuspended( this ); /* notification */
154 }
155
156 /*!
157     Called after operation suspended. Does nothing by default. 
158     Override to set a desired behaviour.
159 */
160 void QAD_Operation::onSuspendOperation()
161 {
162 }
163
164 /*!
165     Resumes operation performing process when the document became active
166     (if the operation wasn't aborted earlier).
167 */
168 void QAD_Operation::resume()
169 {
170   onResumeOperation();                /* customization */
171   myDoc->onOperationResumed( this );  /* notification */
172 }
173
174 /*!
175     Called after operation resumed. Does nothing by default. 
176     Override to set a desired behaviour.
177 */
178 void QAD_Operation::onResumeOperation()
179 {
180 }
181
182 /*!
183     Cancels operation performing process without ending.
184 */
185 void QAD_Operation::abort()
186 {
187   QApplication::setOverrideCursor( Qt::waitCursor );    
188   
189   onAbortOperation();                 /* customization */    
190   myDoc->onOperationAborted( this );  /* abort transaction */
191   
192   QApplication::restoreOverrideCursor();
193 }
194
195 /*!
196     Called after operation aborted. Does nothing by default. 
197     Override to set a desired behaviour.
198 */
199 void QAD_Operation::onAbortOperation()
200 {
201 }