Back to index

salome-gui  6.5.0
SUIT_Operation.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "SUIT_Operation.h"
00024 
00025 #include "SUIT_Study.h"
00026 #include "SUIT_Application.h"
00027 
00037 SUIT_Operation::SUIT_Operation( SUIT_Application* app )
00038 : QObject(),
00039 myApp( app ),
00040 myFlags( Transaction ),
00041 myStudy( 0 ),
00042 myState( Waiting )
00043 {
00044 }
00045 
00049 SUIT_Operation::~SUIT_Operation()
00050 {
00051 }
00052 
00059 SUIT_Study* SUIT_Operation::study() const
00060 {
00061   return myStudy;
00062 }
00063 
00070 void SUIT_Operation::setStudy( SUIT_Study* theStudy )
00071 {
00072   myStudy = theStudy;
00073 }
00074 
00081 SUIT_Application* SUIT_Operation::application() const
00082 {
00083   return myApp;
00084 }
00085 
00092 void SUIT_Operation::setApplication( SUIT_Application* theApp )
00093 {
00094   myApp = theApp;
00095 }
00096 
00103 SUIT_Operation::OperationState SUIT_Operation::state() const
00104 {
00105   return myState;
00106 }
00107 
00114 void SUIT_Operation::setState( const SUIT_Operation::OperationState theState )
00115 {
00116   myState = theState;
00117 }
00118 
00125 void SUIT_Operation::setFlags( const int f )
00126 {
00127   myFlags = myFlags | f;
00128 }
00129 
00136 void SUIT_Operation::clearFlags( const int f )
00137 {
00138   myFlags = myFlags & ~f;
00139 }
00140 
00147 bool SUIT_Operation::testFlags( const int f ) const
00148 {
00149   return ( myFlags & f ) == f;
00150 }
00151 
00158 QString SUIT_Operation::operationName() const
00159 {
00160   return QString();
00161 }
00162 
00172 void SUIT_Operation::start()
00173 {
00174   if ( study() )
00175     study()->start( this );
00176   else
00177   {
00178     startOperation();
00179     emit started( this );
00180   }
00181 }
00182 
00189 void SUIT_Operation::abort()
00190 {
00191   if ( study() )
00192     study()->abort( this );
00193   else
00194   {
00195     abortOperation();
00196     myState = Waiting;
00197     emit aborted( this );
00198 
00199     stopOperation();
00200     emit stopped( this );
00201   }
00202 }
00203 
00210 void SUIT_Operation::commit()
00211 {
00212   if ( study() )
00213     study()->commit( this );
00214   else
00215   {
00216     commitOperation();
00217     myState = Waiting;
00218     emit committed( this );
00219 
00220     stopOperation();
00221     emit stopped( this );
00222   }
00223 }
00224 
00232 void SUIT_Operation::resume()
00233 {
00234   if ( study() )
00235     study()->resume( this );
00236   else
00237   {
00238     resumeOperation();
00239     myState = Running;
00240     emit resumed( this );
00241   }
00242 }
00243 
00251 void SUIT_Operation::suspend()
00252 {
00253   if ( study() )
00254     study()->suspend( this );
00255   else
00256   {
00257     suspendOperation();
00258     myState = Suspended;
00259     emit suspended( this );
00260   }
00261 }
00262 
00269 bool SUIT_Operation::isReadyToStart() const
00270 {
00271   return true;
00272 }
00273 
00279 void SUIT_Operation::startOperation()
00280 {
00281   emit callSlot();
00282   commit();
00283 }
00284 
00290 void SUIT_Operation::stopOperation()
00291 {
00292 }
00293 
00299 void SUIT_Operation::abortOperation()
00300 {
00301 }
00302 
00308 void SUIT_Operation::resumeOperation()
00309 {
00310 }
00311 
00317 void SUIT_Operation::suspendOperation()
00318 {
00319 }
00320 
00326 void SUIT_Operation::commitOperation()
00327 {
00328 }
00329 
00340 bool SUIT_Operation::setSlot( const QObject* theReceiver, const char* theSlot )
00341 {
00342   return connect( this, SIGNAL( callSlot() ), theReceiver, theSlot );
00343 }
00344 
00353 bool SUIT_Operation::isValid( SUIT_Operation* ) const
00354 {
00355   return false;
00356 }
00357 
00367 bool SUIT_Operation::isGranted() const
00368 {
00369   return false;
00370 }
00371 
00379 bool SUIT_Operation::isRunning() const
00380 {
00381   return state() == Running;
00382 }
00383 
00391 bool SUIT_Operation::isActive() const
00392 {
00393   return study() ? study()->activeOperation() == this : false;
00394 }
00395 
00403 void SUIT_Operation::start( SUIT_Operation* op, const bool check )
00404 {
00405   if ( !op )
00406     return;
00407     
00408   if ( study() )
00409     study()->start( op, check );
00410   else
00411   {
00412     connect( this, SIGNAL( stopped( SUIT_Operation* ) ), op, SLOT( abort() ) );
00413     op->start();
00414   }
00415 }
00416 
00423 void SUIT_Operation::setExecStatus( const int theVal )
00424 {
00425   myExecStatus = (ExecStatus)theVal;
00426 }
00427 
00434 int SUIT_Operation::execStatus() const
00435 {
00436   return myExecStatus;
00437 }
00438 
00442 bool SUIT_Operation::openTransaction()
00443 {
00444   if ( !study() )
00445     return false;
00446 
00447   return study()->openTransaction();
00448 }
00449 
00453 bool SUIT_Operation::abortTransaction()
00454 {
00455   if ( !study() )
00456     return false;
00457 
00458   return study()->abortTransaction();
00459 }
00460 
00464 bool SUIT_Operation::commitTransaction( const QString& name )
00465 {
00466   if ( !study() )
00467     return false;
00468 
00469   return study()->commitTransaction( name );
00470 }
00471 
00475 bool SUIT_Operation::hasTransaction() const
00476 {
00477   if ( !study() )
00478     return false;
00479 
00480   return study()->hasTransaction();
00481 }