Salome HOME
PAL10125 - by double click on reference original object becomes selected
[modules/gui.git] / src / SUIT / SUIT_Operation.cxx
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 #include "SUIT_Operation.h"
14
15 #include "SUIT_Study.h"
16 #include "SUIT_Application.h"
17 #include "SUIT_MessageBox.h"
18 #include "SUIT_Desktop.h"
19
20 /*!
21  * \brief Constructor
22   * \param SUIT_Application - application for this operation
23 *
24 * Constructs an empty operation. Constructor should work very fast because many
25 * operators may be created after starting application but only several from them
26 * may be used. As result this constructor stores given application in myApp field
27 * and set Waiting status.
28 */
29 SUIT_Operation::SUIT_Operation( SUIT_Application* app )
30 : QObject(),
31 myApp( app ),
32 myStudy( 0 ),
33 myState( Waiting )
34 {
35 }
36
37 /*!
38    * \brief Destructor
39 */
40 SUIT_Operation::~SUIT_Operation()
41 {
42 }
43
44 /*!
45  * \brief Returns operation study
46   * \return Pointer to study
47 *
48 * Get study corresponding to this operation i.e. study which starts this operation.
49 */
50 SUIT_Study* SUIT_Operation::study() const
51 {
52   return myStudy;
53 }
54
55 /*!
56  * \brief Sets operation study
57   * \param theStudy - study corresponding to this operation
58 *
59 * Sets study corresponding to this operation i.e. study which starts this operation.
60 */
61 void SUIT_Operation::setStudy( SUIT_Study* theStudy )
62 {
63   myStudy = theStudy;
64 }
65
66 /*!
67  * \brief Gets application
68   * \return Pointer to application
69 *
70 * Gets application for this operation
71 */
72 SUIT_Application* SUIT_Operation::application() const
73 {
74   return myApp;
75 }
76
77 /*!
78  * \brief Sets application
79   * \param theApp - application for this operation
80 *
81 * Gets application for this operation
82 */
83 void SUIT_Operation::setApplication( SUIT_Application* theApp )
84 {
85   myApp = theApp;
86 }
87
88 /*!
89  * \brief Gets state of operation
90   * \return Value from OperationState enumeration
91 *
92 * Gets state of operation (see OperationState enumeration)
93 */
94 SUIT_Operation::OperationState SUIT_Operation::state() const
95 {
96   return myState;
97 }
98
99 /*!
100  * \brief Sets state of operation
101   * \param theState - state of operation to be set
102 *
103 *  Sets state of operation (see OperationState enumeration)
104 */
105 void SUIT_Operation::setState( const SUIT_Operation::OperationState theState )
106 {
107   myState = theState;
108 }
109
110 /*!
111  * \brief Starts operation
112 *
113 * Public slot. Verifies whether operation can be started and starts operation.
114 * This slot is not virtual and cannot be redefined. Redefine startOperation method
115 * to change behavior of operation. There is no point in using this method. It would
116 * be better to inherit own operator from base one and redefine startOperation method
117 * instead.
118 */
119 void SUIT_Operation::start()
120 {
121   if ( study() )
122     study()->start( this );
123   else
124   {
125     startOperation();
126     emit started( this );
127   }
128 }
129
130 /*!
131  * \brief Aborts operation
132 *
133 * Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
134 * Redefine abortOperation method to change behavior of operation instead
135 */
136 void SUIT_Operation::abort()
137 {
138   if ( study() )
139     study()->abort( this );
140   else
141   {
142     abortOperation();
143     myState = Waiting;
144     emit aborted( this );
145     emit stopped( this );
146   }
147 }
148
149 /*!
150  * \brief Commits operation
151 *
152 * Public slot. Commits operation. This slot is not virtual and cannot be redefined.
153 * Redefine commitOperation method to change behavior of operation instead
154 */
155 void SUIT_Operation::commit()
156 {
157   if ( study() )
158     study()->commit( this );
159   else
160   {
161     commitOperation();
162     myState = Waiting;
163     emit committed( this );
164     emit stopped( this );
165   }
166 }
167
168 /*!
169  * \brief Resumes operation
170 *
171 * Public slot. Resumes operation. This slot is called when operation is resumed after
172 * previous suspending. This slot is not virtual and cannot be redefined. Redefine
173 * resumeOperation method to change behavior of operation instead
174 */
175 void SUIT_Operation::resume()
176 {
177   if ( study() )
178     study()->resume( this );
179   else
180   {
181     resumeOperation();
182     myState = Running;
183     emit resumed( this );
184   }
185 }
186
187 /*!
188  * \brief Suspend operation.
189 *
190 * Public slot. Suspend operation. This slot is called when operation is suspended
191 * (for starting other one, for example) This slot is not virtual and cannot be
192 * redefined. Redefine suspendOperation method to change behavior of operation instead
193 */
194 void SUIT_Operation::suspend()
195 {
196   if ( study() )
197     study()->suspend( this );
198   else
199   {
200     suspendOperation();
201     myState = Suspended;
202     emit suspended( this );
203   }
204 }
205
206 /*!
207  * \brief Verifies whether operator is ready to start.
208  * \return TRUE if operation is ready to start
209 *
210 * Default implementation returns TRUE. Redefine this method to add own verifications
211 */
212 bool SUIT_Operation::isReadyToStart() const
213 {
214   return true;
215 }
216
217 /*!
218  * \brief Virtual method called when operation is started
219 *
220 * Virtual method called when operation started (see start() method for more description)
221 */
222 void SUIT_Operation::startOperation()
223 {
224   emit callSlot();
225   commit();
226 }
227
228 /*!
229  * \brief Virtual method called when operation aborted
230 *
231 * Virtual method called when operation aborted (see abort() method for more description)
232 */
233 void SUIT_Operation::abortOperation()
234 {
235 }
236
237 /*!
238  * \brief Virtual method called when operation resumed
239 *
240 * Virtual method called when operation resumed (see resume() method for more description)
241 */
242 void SUIT_Operation::resumeOperation()
243 {
244 }
245
246 /*!
247  * \brief Virtual method called when operation suspended
248 *
249 * Virtual method called when operation suspended (see suspend() method for more description)
250 */
251 void SUIT_Operation::suspendOperation()
252 {
253 }
254
255 /*!
256  * \brief Virtual method called when operation committed
257 *
258 * Virtual method called when operation committed (see commit() method for more description)
259 */
260 void SUIT_Operation::commitOperation()
261 {
262 }
263
264 /*!
265  * \brief Sets slot which is called when operation is started
266   * \param theReceiver - object containing slot
267   * \param theSlot - slot of theReceiver object
268   * \return TR if slot was connected successfully, FALSE otherwise
269 *
270 * Sets slot which is called when operation is started. There is no point in
271 * using this method. It would be better to inherit own operator from base
272 * one and redefine startOperation method
273 */
274 bool SUIT_Operation::setSlot( const QObject* theReceiver, const char* theSlot )
275 {
276   return connect( this, SIGNAL( callSlot() ), theReceiver, theSlot );
277 }
278
279 /*!
280  * \brief Verifies whether given operator is valid for this one
281   * \param theOtherOp - other operation
282   * \return Returns TRUE if the given operator is valid for this one
283 *
284 * Verifies whether given operator is valid for this one (i.e. can be started "above"
285 * this operator)
286 */
287 bool SUIT_Operation::isValid( SUIT_Operation* ) const
288 {
289   return false;
290 }
291
292 /*!
293  * \brief Verifies whether this operator can be always started above any already runnig one
294   * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
295 *
296 * This method must be redefined in derived operation if operation of derived class
297 * must be always can start above any launched one. Default implementation returns FALSE,
298 * so it is being checked for IsValid, but some operations may overload IsGranted()
299 * In this case they will always start, no matter what operation is running.
300 */
301 bool SUIT_Operation::isGranted() const
302 {
303   return false;
304 }
305
306 /*!
307  * \brief Verifies whether operation is an active one (state()==Running)
308   * \return TRUE if operation is active, FALSE otherwise
309 *
310 * Verifies whether operation is an active on. Returns TRUE if state of operator
311 * is Running
312 */
313 bool SUIT_Operation::isActive() const
314 {
315   return state()==Running;
316 }
317
318 /*!
319  * \brief Starts operator above this one
320   * \param theOp - operation to be started
321 *
322 * Start operator above this one. Use this method if you want to call other operator
323 * from this one
324 */
325 void SUIT_Operation::start( SUIT_Operation* op )
326 {
327   if ( !op )
328     return;
329     
330   if ( study() )
331     study()->start( op, false );
332   else
333   {
334     connect( this, SIGNAL( stopped( SUIT_Operation* ) ), op, SLOT( abort() ) );
335     op->start();
336   }
337 }
338
339 /*!
340  * \brief Sets execution status
341   * \param theStatus - execution status
342 *
343 * Sets myExecStatus to the given value
344 */
345 void SUIT_Operation::setExecStatus( const int theVal )
346 {
347   myExecStatus = (ExecStatus)theVal;
348 }
349
350 /*!
351  * \brief Gets execution status
352  * \return Execution status
353 *
354 * Gets execution status
355 */
356 int SUIT_Operation::execStatus() const
357 {
358   return myExecStatus;
359 }
360
361
362
363
364
365
366
367