1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 #include "SUIT_Operation.h"
25 #include "SUIT_Study.h"
26 #include "SUIT_Application.h"
30 \param SUIT_Application - application for this operation
32 Constructs an empty operation. Constructor should work very fast because many
33 operators may be created after starting application but only several from them
34 may be used. As result this constructor stores given application in myApp field
35 and set Waiting status.
37 SUIT_Operation::SUIT_Operation( SUIT_Application* app )
40 myFlags( Transaction ),
49 SUIT_Operation::~SUIT_Operation()
54 * \brief Returns operation study
55 * \return Pointer to study
57 * Get study corresponding to this operation i.e. study which starts this operation.
59 SUIT_Study* SUIT_Operation::study() const
65 * \brief Sets operation study
66 * \param theStudy - study corresponding to this operation
68 * Sets study corresponding to this operation i.e. study which starts this operation.
70 void SUIT_Operation::setStudy( SUIT_Study* theStudy )
76 * \brief Gets application
77 * \return Pointer to application
79 * Gets application for this operation
81 SUIT_Application* SUIT_Operation::application() const
87 * \brief Sets application
88 * \param theApp - application for this operation
90 * Gets application for this operation
92 void SUIT_Operation::setApplication( SUIT_Application* theApp )
98 * \brief Gets state of operation
99 * \return Value from OperationState enumeration
101 * Gets state of operation (see OperationState enumeration)
103 SUIT_Operation::OperationState SUIT_Operation::state() const
109 * \brief Sets state of operation
110 * \param theState - state of operation to be set
112 * Sets state of operation (see OperationState enumeration)
114 void SUIT_Operation::setState( const SUIT_Operation::OperationState theState )
120 * \brief Sets the flags of operation
121 * \param f - flags of operation to be set
123 * Sets flags of operation (see Flags enumeration)
125 void SUIT_Operation::setFlags( const int f )
127 myFlags = myFlags | f;
131 * \brief Clears the flags of operation
132 * \param f - flags of operation to be cleared
134 * Clears flags of operation (see Flags enumeration)
136 void SUIT_Operation::clearFlags( const int f )
138 myFlags = myFlags & ~f;
142 * \brief Test the flags of operation
143 * \param f - flags of operation to be tested
145 * Returns \c true if the specified flags setted in the operation (see Flags enumeration)
147 bool SUIT_Operation::testFlags( const int f ) const
149 return ( myFlags & f ) == f;
153 * \brief Name of the operation
155 * Returns string name of the operation. This name will be used for
156 * automatically commited transaction.
158 QString SUIT_Operation::operationName() const
164 * \brief Starts operation
166 * Public slot. Verifies whether operation can be started and starts operation.
167 * This slot is not virtual and cannot be redefined. Redefine startOperation method
168 * to change behavior of operation. There is no point in using this method. It would
169 * be better to inherit own operator from base one and redefine startOperation method
172 void SUIT_Operation::start()
175 study()->start( this );
179 emit started( this );
184 * \brief Aborts operation
186 * Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
187 * Redefine abortOperation method to change behavior of operation instead
189 void SUIT_Operation::abort()
192 study()->abort( this );
197 emit aborted( this );
200 emit stopped( this );
205 * \brief Commits operation
207 * Public slot. Commits operation. This slot is not virtual and cannot be redefined.
208 * Redefine commitOperation method to change behavior of operation instead
210 void SUIT_Operation::commit()
213 study()->commit( this );
218 emit committed( this );
221 emit stopped( this );
226 * \brief Resumes operation
228 * Public slot. Resumes operation. This slot is called when operation is resumed after
229 * previous suspending. This slot is not virtual and cannot be redefined. Redefine
230 * resumeOperation method to change behavior of operation instead
232 void SUIT_Operation::resume()
235 study()->resume( this );
240 emit resumed( this );
245 * \brief Suspend operation.
247 * Public slot. Suspend operation. This slot is called when operation is suspended
248 * (for starting other one, for example) This slot is not virtual and cannot be
249 * redefined. Redefine suspendOperation method to change behavior of operation instead
251 void SUIT_Operation::suspend()
254 study()->suspend( this );
259 emit suspended( this );
264 * \brief Verifies whether operator is ready to start.
265 * \return \c true if operation is ready to start
267 * Default implementation returns \c true. Redefine this method to add own verifications
269 bool SUIT_Operation::isReadyToStart() const
275 * \brief Virtual method called when operation is started
277 * Virtual method called when operation started (see start() method for more description)
279 void SUIT_Operation::startOperation()
286 * \brief Virtual method called when operation is started
288 * Virtual method called when operation stopped - comitted or aborted.
290 void SUIT_Operation::stopOperation()
295 * \brief Virtual method called when operation aborted
297 * Virtual method called when operation aborted (see abort() method for more description)
299 void SUIT_Operation::abortOperation()
304 * \brief Virtual method called when operation resumed
306 * Virtual method called when operation resumed (see resume() method for more description)
308 void SUIT_Operation::resumeOperation()
313 * \brief Virtual method called when operation suspended
315 * Virtual method called when operation suspended (see suspend() method for more description)
317 void SUIT_Operation::suspendOperation()
322 * \brief Virtual method called when operation committed
324 * Virtual method called when operation committed (see commit() method for more description)
326 void SUIT_Operation::commitOperation()
331 * \brief Sets slot which is called when operation is started
332 * \param theReceiver - object containing slot
333 * \param theSlot - slot of theReceiver object
334 * \return \c true if slot was connected successfully, \c false otherwise
336 * Sets slot which is called when operation is started. There is no point in
337 * using this method. It would be better to inherit own operator from base
338 * one and redefine startOperation method
340 bool SUIT_Operation::setSlot( const QObject* theReceiver, const char* theSlot )
342 return connect( this, SIGNAL( callSlot() ), theReceiver, theSlot );
346 * \brief Verifies whether given operator is valid for this one
347 * \param theOtherOp - other operation
348 * \return Returns \c true if the given operator is valid for this one
350 * Verifies whether given operator is valid for this one (i.e. can be started "above"
353 bool SUIT_Operation::isValid( SUIT_Operation* ) const
359 * \brief Verifies whether this operator can be always started above any already runnig one
360 * \return Returns \c true if current operation must not be checked for ActiveOperation->IsValid( this )
362 * This method must be redefined in derived operation if operation of derived class
363 * must be always can start above any launched one. Default implementation returns \c false,
364 * so it is being checked for IsValid, but some operations may overload IsGranted()
365 * In this case they will always start, no matter what operation is running.
367 bool SUIT_Operation::isGranted() const
373 * \brief Verifies whether operation is an runned one (state()==Running)
374 * \return \c true if operation is active, \c false otherwise
376 * Verifies whether operation is an running. Returns \c true if state of operator
379 bool SUIT_Operation::isRunning() const
381 return state() == Running;
385 * \brief Verifies whether operation is an active for study.
386 * \return \c true if operation is active, \c false otherwise
388 * Verifies whether operation is an active on. Returns \c true if this operator
389 * is active for study
391 bool SUIT_Operation::isActive() const
393 return study() ? study()->activeOperation() == this : false;
397 * \brief Starts operator above this one
398 * \param theOp - operation to be started
400 * Start operator above this one. Use this method if you want to call other operator
403 void SUIT_Operation::start( SUIT_Operation* op, const bool check )
409 study()->start( op, check );
412 connect( this, SIGNAL( stopped( SUIT_Operation* ) ), op, SLOT( abort() ) );
418 * \brief Sets execution status
419 * \param theStatus - execution status
421 * Sets myExecStatus to the given value
423 void SUIT_Operation::setExecStatus( const int theVal )
425 myExecStatus = (ExecStatus)theVal;
429 * \brief Gets execution status
430 * \return Execution status
432 * Gets execution status
434 int SUIT_Operation::execStatus() const
440 * \brief Opens transaction for data modifications.
442 bool SUIT_Operation::openTransaction()
447 return study()->openTransaction();
451 * \brief Aborts transaction and all performed data modifications.
453 bool SUIT_Operation::abortTransaction()
458 return study()->abortTransaction();
462 * \brief Commits transaction and all performed data modifications.
464 bool SUIT_Operation::commitTransaction( const QString& name )
469 return study()->commitTransaction( name );
473 * \brief Returns \c true if transaction is opened.
475 bool SUIT_Operation::hasTransaction() const
480 return study()->hasTransaction();