1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 Copyright (C) 2005 CEA/DEN, EDF R&D
25 File : SUIT_Operation.h
30 #include "SUIT_Operation.h"
32 #include "SUIT_Study.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_MessageBox.h"
35 #include "SUIT_Application.h"
39 \param SUIT_Application - application for this operation
41 Constructs an empty operation. Constructor should work very fast because many
42 operators may be created after starting application but only several from them
43 may be used. As result this constructor stores given application in myApp field
44 and set Waiting status.
46 SUIT_Operation::SUIT_Operation( SUIT_Application* app )
51 myFlags( Transaction )
58 SUIT_Operation::~SUIT_Operation()
63 * \brief Returns operation study
64 * \return Pointer to study
66 * Get study corresponding to this operation i.e. study which starts this operation.
68 SUIT_Study* SUIT_Operation::study() const
74 * \brief Sets operation study
75 * \param theStudy - study corresponding to this operation
77 * Sets study corresponding to this operation i.e. study which starts this operation.
79 void SUIT_Operation::setStudy( SUIT_Study* theStudy )
85 * \brief Gets application
86 * \return Pointer to application
88 * Gets application for this operation
90 SUIT_Application* SUIT_Operation::application() const
96 * \brief Sets application
97 * \param theApp - application for this operation
99 * Gets application for this operation
101 void SUIT_Operation::setApplication( SUIT_Application* theApp )
107 * \brief Gets state of operation
108 * \return Value from OperationState enumeration
110 * Gets state of operation (see OperationState enumeration)
112 SUIT_Operation::OperationState SUIT_Operation::state() const
118 * \brief Sets state of operation
119 * \param theState - state of operation to be set
121 * Sets state of operation (see OperationState enumeration)
123 void SUIT_Operation::setState( const SUIT_Operation::OperationState theState )
129 * \brief Sets the flags of operation
130 * \param f - flags of operation to be set
132 * Sets flags of operation (see Flags enumeration)
134 void SUIT_Operation::setFlags( const int f )
136 myFlags = myFlags | f;
140 * \brief Clears the flags of operation
141 * \param f - flags of operation to be cleared
143 * Clears flags of operation (see Flags enumeration)
145 void SUIT_Operation::clearFlags( const int f )
147 myFlags = myFlags & ~f;
151 * \brief Test the flags of operation
152 * \param f - flags of operation to be tested
154 * Returns TRUE if the specified flags setted in the operation (see Flags enumeration)
156 bool SUIT_Operation::testFlags( const int f ) const
158 return ( myFlags & f ) == f;
162 * \brief Name of the operation
164 * Returns string name of the operation. This name will be used for
165 * automatically commited transaction.
167 QString SUIT_Operation::operationName() const
169 return QString::null;
173 * \brief Starts operation
175 * Public slot. Verifies whether operation can be started and starts operation.
176 * This slot is not virtual and cannot be redefined. Redefine startOperation method
177 * to change behavior of operation. There is no point in using this method. It would
178 * be better to inherit own operator from base one and redefine startOperation method
181 void SUIT_Operation::start()
184 study()->start( this );
188 emit started( this );
193 * \brief Aborts operation
195 * Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
196 * Redefine abortOperation method to change behavior of operation instead
198 void SUIT_Operation::abort()
201 study()->abort( this );
206 emit aborted( this );
209 emit stopped( this );
214 * \brief Commits operation
216 * Public slot. Commits operation. This slot is not virtual and cannot be redefined.
217 * Redefine commitOperation method to change behavior of operation instead
219 void SUIT_Operation::commit()
222 study()->commit( this );
227 emit committed( this );
230 emit stopped( this );
235 * \brief Resumes operation
237 * Public slot. Resumes operation. This slot is called when operation is resumed after
238 * previous suspending. This slot is not virtual and cannot be redefined. Redefine
239 * resumeOperation method to change behavior of operation instead
241 void SUIT_Operation::resume()
244 study()->resume( this );
249 emit resumed( this );
254 * \brief Suspend operation.
256 * Public slot. Suspend operation. This slot is called when operation is suspended
257 * (for starting other one, for example) This slot is not virtual and cannot be
258 * redefined. Redefine suspendOperation method to change behavior of operation instead
260 void SUIT_Operation::suspend()
263 study()->suspend( this );
268 emit suspended( this );
273 * \brief Verifies whether operator is ready to start.
274 * \return TRUE if operation is ready to start
276 * Default implementation returns TRUE. Redefine this method to add own verifications
278 bool SUIT_Operation::isReadyToStart() const
284 * \brief Virtual method called when operation is started
286 * Virtual method called when operation started (see start() method for more description)
288 void SUIT_Operation::startOperation()
295 * \brief Virtual method called when operation is started
297 * Virtual method called when operation stopped - comitted or aborted.
299 void SUIT_Operation::stopOperation()
304 * \brief Virtual method called when operation aborted
306 * Virtual method called when operation aborted (see abort() method for more description)
308 void SUIT_Operation::abortOperation()
313 * \brief Virtual method called when operation resumed
315 * Virtual method called when operation resumed (see resume() method for more description)
317 void SUIT_Operation::resumeOperation()
322 * \brief Virtual method called when operation suspended
324 * Virtual method called when operation suspended (see suspend() method for more description)
326 void SUIT_Operation::suspendOperation()
331 * \brief Virtual method called when operation committed
333 * Virtual method called when operation committed (see commit() method for more description)
335 void SUIT_Operation::commitOperation()
340 * \brief Sets slot which is called when operation is started
341 * \param theReceiver - object containing slot
342 * \param theSlot - slot of theReceiver object
343 * \return TR if slot was connected successfully, FALSE otherwise
345 * Sets slot which is called when operation is started. There is no point in
346 * using this method. It would be better to inherit own operator from base
347 * one and redefine startOperation method
349 bool SUIT_Operation::setSlot( const QObject* theReceiver, const char* theSlot )
351 return connect( this, SIGNAL( callSlot() ), theReceiver, theSlot );
355 * \brief Verifies whether given operator is valid for this one
356 * \param theOtherOp - other operation
357 * \return Returns TRUE if the given operator is valid for this one
359 * Verifies whether given operator is valid for this one (i.e. can be started "above"
362 bool SUIT_Operation::isValid( SUIT_Operation* ) const
368 * \brief Verifies whether this operator can be always started above any already runnig one
369 * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
371 * This method must be redefined in derived operation if operation of derived class
372 * must be always can start above any launched one. Default implementation returns FALSE,
373 * so it is being checked for IsValid, but some operations may overload IsGranted()
374 * In this case they will always start, no matter what operation is running.
376 bool SUIT_Operation::isGranted() const
382 * \brief Verifies whether operation is an runned one (state()==Running)
383 * \return TRUE if operation is active, FALSE otherwise
385 * Verifies whether operation is an running. Returns TRUE if state of operator
388 bool SUIT_Operation::isRunning() const
390 return state() == Running;
394 * \brief Verifies whether operation is an active for study.
395 * \return TRUE if operation is active, FALSE otherwise
397 * Verifies whether operation is an active on. Returns TRUE if this operator
398 * is active for study
400 bool SUIT_Operation::isActive() const
402 return study() ? study()->activeOperation() == this : false;
406 * \brief Starts operator above this one
407 * \param theOp - operation to be started
409 * Start operator above this one. Use this method if you want to call other operator
412 void SUIT_Operation::start( SUIT_Operation* op, const bool check )
418 study()->start( op, check );
421 connect( this, SIGNAL( stopped( SUIT_Operation* ) ), op, SLOT( abort() ) );
427 * \brief Sets execution status
428 * \param theStatus - execution status
430 * Sets myExecStatus to the given value
432 void SUIT_Operation::setExecStatus( const int theVal )
434 myExecStatus = (ExecStatus)theVal;
438 * \brief Gets execution status
439 * \return Execution status
441 * Gets execution status
443 int SUIT_Operation::execStatus() const
449 * \brief Opens transaction for data modifications.
451 bool SUIT_Operation::openTransaction()
456 return study()->openTransaction();
460 * \brief Aborts transaction and all performed data modifications.
462 bool SUIT_Operation::abortTransaction()
467 return study()->abortTransaction();
471 * \brief Commits transaction and all performed data modifications.
473 bool SUIT_Operation::commitTransaction( const QString& name )
478 return study()->commitTransaction( name );
482 * \brief Returns TRUE if transaction is opened.
484 bool SUIT_Operation::hasTransaction() const
489 return study()->hasTransaction();