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/
22 * Copyright (C) 2005 CEA/DEN, EDF R&D
26 * File : SUIT_Operation.h
31 #include "SUIT_Operation.h"
33 #include "SUIT_Study.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_MessageBox.h"
36 #include "SUIT_Application.h"
40 * \param SUIT_Application - application for this operation
42 * Constructs an empty operation. Constructor should work very fast because many
43 * operators may be created after starting application but only several from them
44 * may be used. As result this constructor stores given application in myApp field
45 * and set Waiting status.
47 SUIT_Operation::SUIT_Operation( SUIT_Application* app )
52 myFlags( Transaction )
59 SUIT_Operation::~SUIT_Operation()
64 * \brief Returns operation study
65 * \return Pointer to study
67 * Get study corresponding to this operation i.e. study which starts this operation.
69 SUIT_Study* SUIT_Operation::study() const
75 * \brief Sets operation study
76 * \param theStudy - study corresponding to this operation
78 * Sets study corresponding to this operation i.e. study which starts this operation.
80 void SUIT_Operation::setStudy( SUIT_Study* theStudy )
86 * \brief Gets application
87 * \return Pointer to application
89 * Gets application for this operation
91 SUIT_Application* SUIT_Operation::application() const
97 * \brief Sets application
98 * \param theApp - application for this operation
100 * Gets application for this operation
102 void SUIT_Operation::setApplication( SUIT_Application* theApp )
108 * \brief Gets state of operation
109 * \return Value from OperationState enumeration
111 * Gets state of operation (see OperationState enumeration)
113 SUIT_Operation::OperationState SUIT_Operation::state() const
119 * \brief Sets state of operation
120 * \param theState - state of operation to be set
122 * Sets state of operation (see OperationState enumeration)
124 void SUIT_Operation::setState( const SUIT_Operation::OperationState theState )
130 * \brief Sets the flags of operation
131 * \param f - flags of operation to be set
133 * Sets flags of operation (see Flags enumeration)
135 void SUIT_Operation::setFlags( const int f )
137 myFlags = myFlags | f;
141 * \brief Clears the flags of operation
142 * \param f - flags of operation to be cleared
144 * Clears flags of operation (see Flags enumeration)
146 void SUIT_Operation::clearFlags( const int f )
148 myFlags = myFlags & ~f;
152 * \brief Test the flags of operation
153 * \param f - flags of operation to be tested
155 * Returns TRUE if the specified flags setted in the operation (see Flags enumeration)
157 bool SUIT_Operation::testFlags( const int f ) const
159 return ( myFlags & f ) == f;
163 * \brief Name of the operation
165 * Returns string name of the operation. This name will be used for
166 * automatically commited transaction.
168 QString SUIT_Operation::operationName() const
170 return QString::null;
174 * \brief Starts operation
176 * Public slot. Verifies whether operation can be started and starts operation.
177 * This slot is not virtual and cannot be redefined. Redefine startOperation method
178 * to change behavior of operation. There is no point in using this method. It would
179 * be better to inherit own operator from base one and redefine startOperation method
182 void SUIT_Operation::start()
185 study()->start( this );
189 emit started( this );
194 * \brief Aborts operation
196 * Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
197 * Redefine abortOperation method to change behavior of operation instead
199 void SUIT_Operation::abort()
202 study()->abort( this );
207 emit aborted( this );
210 emit stopped( this );
215 * \brief Commits operation
217 * Public slot. Commits operation. This slot is not virtual and cannot be redefined.
218 * Redefine commitOperation method to change behavior of operation instead
220 void SUIT_Operation::commit()
223 study()->commit( this );
228 emit committed( this );
231 emit stopped( this );
236 * \brief Resumes operation
238 * Public slot. Resumes operation. This slot is called when operation is resumed after
239 * previous suspending. This slot is not virtual and cannot be redefined. Redefine
240 * resumeOperation method to change behavior of operation instead
242 void SUIT_Operation::resume()
245 study()->resume( this );
250 emit resumed( this );
255 * \brief Suspend operation.
257 * Public slot. Suspend operation. This slot is called when operation is suspended
258 * (for starting other one, for example) This slot is not virtual and cannot be
259 * redefined. Redefine suspendOperation method to change behavior of operation instead
261 void SUIT_Operation::suspend()
264 study()->suspend( this );
269 emit suspended( this );
274 * \brief Verifies whether operator is ready to start.
275 * \return TRUE if operation is ready to start
277 * Default implementation returns TRUE. Redefine this method to add own verifications
279 bool SUIT_Operation::isReadyToStart() const
285 * \brief Virtual method called when operation is started
287 * Virtual method called when operation started (see start() method for more description)
289 void SUIT_Operation::startOperation()
296 * \brief Virtual method called when operation is started
298 * Virtual method called when operation stopped - comitted or aborted.
300 void SUIT_Operation::stopOperation()
305 * \brief Virtual method called when operation aborted
307 * Virtual method called when operation aborted (see abort() method for more description)
309 void SUIT_Operation::abortOperation()
314 * \brief Virtual method called when operation resumed
316 * Virtual method called when operation resumed (see resume() method for more description)
318 void SUIT_Operation::resumeOperation()
323 * \brief Virtual method called when operation suspended
325 * Virtual method called when operation suspended (see suspend() method for more description)
327 void SUIT_Operation::suspendOperation()
332 * \brief Virtual method called when operation committed
334 * Virtual method called when operation committed (see commit() method for more description)
336 void SUIT_Operation::commitOperation()
341 * \brief Sets slot which is called when operation is started
342 * \param theReceiver - object containing slot
343 * \param theSlot - slot of theReceiver object
344 * \return TR if slot was connected successfully, FALSE otherwise
346 * Sets slot which is called when operation is started. There is no point in
347 * using this method. It would be better to inherit own operator from base
348 * one and redefine startOperation method
350 bool SUIT_Operation::setSlot( const QObject* theReceiver, const char* theSlot )
352 return connect( this, SIGNAL( callSlot() ), theReceiver, theSlot );
356 * \brief Verifies whether given operator is valid for this one
357 * \param theOtherOp - other operation
358 * \return Returns TRUE if the given operator is valid for this one
360 * Verifies whether given operator is valid for this one (i.e. can be started "above"
363 bool SUIT_Operation::isValid( SUIT_Operation* ) const
369 * \brief Verifies whether this operator can be always started above any already runnig one
370 * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
372 * This method must be redefined in derived operation if operation of derived class
373 * must be always can start above any launched one. Default implementation returns FALSE,
374 * so it is being checked for IsValid, but some operations may overload IsGranted()
375 * In this case they will always start, no matter what operation is running.
377 bool SUIT_Operation::isGranted() const
383 * \brief Verifies whether operation is an runned one (state()==Running)
384 * \return TRUE if operation is active, FALSE otherwise
386 * Verifies whether operation is an running. Returns TRUE if state of operator
389 bool SUIT_Operation::isRunning() const
391 return state() == Running;
395 * \brief Verifies whether operation is an active for study.
396 * \return TRUE if operation is active, FALSE otherwise
398 * Verifies whether operation is an active on. Returns TRUE if this operator
399 * is active for study
401 bool SUIT_Operation::isActive() const
403 return study() ? study()->activeOperation() == this : false;
407 * \brief Starts operator above this one
408 * \param theOp - operation to be started
410 * Start operator above this one. Use this method if you want to call other operator
413 void SUIT_Operation::start( SUIT_Operation* op, const bool check )
419 study()->start( op, false );
422 connect( this, SIGNAL( stopped( SUIT_Operation* ) ), op, SLOT( abort() ) );
428 * \brief Sets execution status
429 * \param theStatus - execution status
431 * Sets myExecStatus to the given value
433 void SUIT_Operation::setExecStatus( const int theVal )
435 myExecStatus = (ExecStatus)theVal;
439 * \brief Gets execution status
440 * \return Execution status
442 * Gets execution status
444 int SUIT_Operation::execStatus() const
450 * \brief Opens transaction for data modifications.
452 bool SUIT_Operation::openTransaction()
457 return study()->openTransaction();
461 * \brief Aborts transaction and all performed data modifications.
463 bool SUIT_Operation::abortTransaction()
468 return study()->abortTransaction();
472 * \brief Commits transaction and all performed data modifications.
474 bool SUIT_Operation::commitTransaction( const QString& name )
479 return study()->commitTransaction( name );
483 * \brief Returns TRUE if transaction is opened.
485 bool SUIT_Operation::hasTransaction() const
490 return study()->hasTransaction();