1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SUIT_Operation.h"
24 #include "SUIT_Study.h"
25 #include "SUIT_Application.h"
29 \param SUIT_Application - application for this operation
31 Constructs an empty operation. Constructor should work very fast because many
32 operators may be created after starting application but only several from them
33 may be used. As result this constructor stores given application in myApp field
34 and set Waiting status.
36 SUIT_Operation::SUIT_Operation( SUIT_Application* app )
39 myFlags( Transaction ),
48 SUIT_Operation::~SUIT_Operation()
53 * \brief Returns operation study
54 * \return Pointer to study
56 * Get study corresponding to this operation i.e. study which starts this operation.
58 SUIT_Study* SUIT_Operation::study() const
64 * \brief Sets operation study
65 * \param theStudy - study corresponding to this operation
67 * Sets study corresponding to this operation i.e. study which starts this operation.
69 void SUIT_Operation::setStudy( SUIT_Study* theStudy )
75 * \brief Gets application
76 * \return Pointer to application
78 * Gets application for this operation
80 SUIT_Application* SUIT_Operation::application() const
86 * \brief Sets application
87 * \param theApp - application for this operation
89 * Gets application for this operation
91 void SUIT_Operation::setApplication( SUIT_Application* theApp )
97 * \brief Gets state of operation
98 * \return Value from OperationState enumeration
100 * Gets state of operation (see OperationState enumeration)
102 SUIT_Operation::OperationState SUIT_Operation::state() const
108 * \brief Sets state of operation
109 * \param theState - state of operation to be set
111 * Sets state of operation (see OperationState enumeration)
113 void SUIT_Operation::setState( const SUIT_Operation::OperationState theState )
119 * \brief Sets the flags of operation
120 * \param f - flags of operation to be set
122 * Sets flags of operation (see Flags enumeration)
124 void SUIT_Operation::setFlags( const int f )
126 myFlags = myFlags | f;
130 * \brief Clears the flags of operation
131 * \param f - flags of operation to be cleared
133 * Clears flags of operation (see Flags enumeration)
135 void SUIT_Operation::clearFlags( const int f )
137 myFlags = myFlags & ~f;
141 * \brief Test the flags of operation
142 * \param f - flags of operation to be tested
144 * Returns TRUE if the specified flags setted in the operation (see Flags enumeration)
146 bool SUIT_Operation::testFlags( const int f ) const
148 return ( myFlags & f ) == f;
152 * \brief Name of the operation
154 * Returns string name of the operation. This name will be used for
155 * automatically commited transaction.
157 QString SUIT_Operation::operationName() const
163 * \brief Starts operation
165 * Public slot. Verifies whether operation can be started and starts operation.
166 * This slot is not virtual and cannot be redefined. Redefine startOperation method
167 * to change behavior of operation. There is no point in using this method. It would
168 * be better to inherit own operator from base one and redefine startOperation method
171 void SUIT_Operation::start()
174 study()->start( this );
178 emit started( this );
183 * \brief Aborts operation
185 * Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
186 * Redefine abortOperation method to change behavior of operation instead
188 void SUIT_Operation::abort()
191 study()->abort( this );
196 emit aborted( this );
199 emit stopped( this );
204 * \brief Commits operation
206 * Public slot. Commits operation. This slot is not virtual and cannot be redefined.
207 * Redefine commitOperation method to change behavior of operation instead
209 void SUIT_Operation::commit()
212 study()->commit( this );
217 emit committed( this );
220 emit stopped( this );
225 * \brief Resumes operation
227 * Public slot. Resumes operation. This slot is called when operation is resumed after
228 * previous suspending. This slot is not virtual and cannot be redefined. Redefine
229 * resumeOperation method to change behavior of operation instead
231 void SUIT_Operation::resume()
234 study()->resume( this );
239 emit resumed( this );
244 * \brief Suspend operation.
246 * Public slot. Suspend operation. This slot is called when operation is suspended
247 * (for starting other one, for example) This slot is not virtual and cannot be
248 * redefined. Redefine suspendOperation method to change behavior of operation instead
250 void SUIT_Operation::suspend()
253 study()->suspend( this );
258 emit suspended( this );
263 * \brief Verifies whether operator is ready to start.
264 * \return TRUE if operation is ready to start
266 * Default implementation returns TRUE. Redefine this method to add own verifications
268 bool SUIT_Operation::isReadyToStart() const
274 * \brief Virtual method called when operation is started
276 * Virtual method called when operation started (see start() method for more description)
278 void SUIT_Operation::startOperation()
285 * \brief Virtual method called when operation is started
287 * Virtual method called when operation stopped - comitted or aborted.
289 void SUIT_Operation::stopOperation()
294 * \brief Virtual method called when operation aborted
296 * Virtual method called when operation aborted (see abort() method for more description)
298 void SUIT_Operation::abortOperation()
303 * \brief Virtual method called when operation resumed
305 * Virtual method called when operation resumed (see resume() method for more description)
307 void SUIT_Operation::resumeOperation()
312 * \brief Virtual method called when operation suspended
314 * Virtual method called when operation suspended (see suspend() method for more description)
316 void SUIT_Operation::suspendOperation()
321 * \brief Virtual method called when operation committed
323 * Virtual method called when operation committed (see commit() method for more description)
325 void SUIT_Operation::commitOperation()
330 * \brief Sets slot which is called when operation is started
331 * \param theReceiver - object containing slot
332 * \param theSlot - slot of theReceiver object
333 * \return TR if slot was connected successfully, FALSE otherwise
335 * Sets slot which is called when operation is started. There is no point in
336 * using this method. It would be better to inherit own operator from base
337 * one and redefine startOperation method
339 bool SUIT_Operation::setSlot( const QObject* theReceiver, const char* theSlot )
341 return connect( this, SIGNAL( callSlot() ), theReceiver, theSlot );
345 * \brief Verifies whether given operator is valid for this one
346 * \param theOtherOp - other operation
347 * \return Returns TRUE if the given operator is valid for this one
349 * Verifies whether given operator is valid for this one (i.e. can be started "above"
352 bool SUIT_Operation::isValid( SUIT_Operation* ) const
358 * \brief Verifies whether this operator can be always started above any already runnig one
359 * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
361 * This method must be redefined in derived operation if operation of derived class
362 * must be always can start above any launched one. Default implementation returns FALSE,
363 * so it is being checked for IsValid, but some operations may overload IsGranted()
364 * In this case they will always start, no matter what operation is running.
366 bool SUIT_Operation::isGranted() const
372 * \brief Verifies whether operation is an runned one (state()==Running)
373 * \return TRUE if operation is active, FALSE otherwise
375 * Verifies whether operation is an running. Returns TRUE if state of operator
378 bool SUIT_Operation::isRunning() const
380 return state() == Running;
384 * \brief Verifies whether operation is an active for study.
385 * \return TRUE if operation is active, FALSE otherwise
387 * Verifies whether operation is an active on. Returns TRUE if this operator
388 * is active for study
390 bool SUIT_Operation::isActive() const
392 return study() ? study()->activeOperation() == this : false;
396 * \brief Starts operator above this one
397 * \param theOp - operation to be started
399 * Start operator above this one. Use this method if you want to call other operator
402 void SUIT_Operation::start( SUIT_Operation* op, const bool check )
408 study()->start( op, check );
411 connect( this, SIGNAL( stopped( SUIT_Operation* ) ), op, SLOT( abort() ) );
417 * \brief Sets execution status
418 * \param theStatus - execution status
420 * Sets myExecStatus to the given value
422 void SUIT_Operation::setExecStatus( const int theVal )
424 myExecStatus = (ExecStatus)theVal;
428 * \brief Gets execution status
429 * \return Execution status
431 * Gets execution status
433 int SUIT_Operation::execStatus() const
439 * \brief Opens transaction for data modifications.
441 bool SUIT_Operation::openTransaction()
446 return study()->openTransaction();
450 * \brief Aborts transaction and all performed data modifications.
452 bool SUIT_Operation::abortTransaction()
457 return study()->abortTransaction();
461 * \brief Commits transaction and all performed data modifications.
463 bool SUIT_Operation::commitTransaction( const QString& name )
468 return study()->commitTransaction( name );
472 * \brief Returns TRUE if transaction is opened.
474 bool SUIT_Operation::hasTransaction() const
479 return study()->hasTransaction();