X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUIT%2FSUIT_Study.cxx;h=8941e3fe238b474cf80bdf2674317a607ea8d170;hb=efe3cdefadc31ad9cdaa9fd7fc368e2931cebdf1;hp=3fb1519029f08350cd588009538e1a41aba8a3ed;hpb=f16039b1923ca92906d4112a3bb0dbd431192807;p=modules%2Fgui.git diff --git a/src/SUIT/SUIT_Study.cxx b/src/SUIT/SUIT_Study.cxx index 3fb151902..8941e3fe2 100755 --- a/src/SUIT/SUIT_Study.cxx +++ b/src/SUIT/SUIT_Study.cxx @@ -1,3 +1,25 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + #include "SUIT_Study.h" #include "SUIT_Desktop.h" @@ -5,7 +27,6 @@ #include "SUIT_DataObject.h" #include "SUIT_MessageBox.h" #include "SUIT_Application.h" -#include /*!\class SUIT_Study * Support study management. Object management. Operation management. @@ -15,9 +36,9 @@ SUIT_Study::SUIT_Study( SUIT_Application* app ) : QObject(), myApp( app ), +myName( "" ), myIsSaved( false ), myIsModified( false ), -myName( "" ), myBlockChangeState( false ) { static int _id = 0; @@ -25,8 +46,6 @@ myBlockChangeState( false ) myId = ++_id; myRoot = new SUIT_DataObject(); - myOperations.setAutoDelete( false ); - myOperations.setAutoDelete( false ); } /*!Destructor.*/ @@ -73,11 +92,11 @@ QString SUIT_Study::studyName() const */ SUIT_Operation* SUIT_Study::activeOperation() const { - return myOperations.count() > 0 ? myOperations.getLast() : 0; + return myOperations.count() > 0 ? myOperations.last() : 0; } /*! - *\retval TRUE - if study saved, else FALSE. + *\retval \c true - if study saved, else \c false. */ bool SUIT_Study::isSaved() const { @@ -85,7 +104,7 @@ bool SUIT_Study::isSaved() const } /*! - *\retval TRUE - if study modified, else FALSE. + *\retval \c true - if study modified, else \c false. */ bool SUIT_Study::isModified() const { @@ -95,19 +114,21 @@ bool SUIT_Study::isModified() const /*! *Close document. NOT IMPLEMENTED. */ -void SUIT_Study::closeDocument(bool permanently) +void SUIT_Study::closeDocument(bool /*permanently*/) { } -void SUIT_Study::createDocument() +/*! + Custom document initialization to be performed \n + within onNewDoc() handler can be put here +*/ +bool SUIT_Study::createDocument( const QString& ) { - /*! Custom document initialization to be performed \n - * within onNewDoc() handler can be put here - */ + return true; } /*! - * Open document. Sets file name. return true. + * Open document. Sets file name. return \c true. */ bool SUIT_Study::openDocument( const QString& fileName ) { @@ -131,7 +152,7 @@ bool SUIT_Study::saveDocumentAs( const QString& fileName ) } /*! - *\retval TRUE - if document saved successful, else FALSE. + *\retval \c true - if document saved successful, else \c false. */ bool SUIT_Study::saveDocument() { @@ -144,8 +165,10 @@ bool SUIT_Study::saveDocument() void SUIT_Study::abortAllOperations() { myBlockChangeState = true; - for( SUIT_Operation* op = myOperations.first(); op; op = myOperations.next() ) - op->abort(); + while ( !myOperations.isEmpty() ) { + Operations::iterator it = myOperations.begin(); + (*it)->abort(); + } myBlockChangeState = false; myOperations.clear(); } @@ -181,6 +204,15 @@ void SUIT_Study::setIsModified( const bool on ) myIsModified = on; } +/*! + Set study modified to \a on. + */ +void SUIT_Study::Modified() +{ + setIsModified( true ); + sendChangesNotification(); +} + /*! Set root object. */ @@ -220,9 +252,10 @@ SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const return 0; Operations tmpOps( myOperations ); - SUIT_Operation* anOp = 0; - for ( anOp = tmpOps.last(); anOp; anOp = tmpOps.prev() ) + for ( Operations::const_iterator it = tmpOps.end(); it != tmpOps.begin(); ) { + it--; + SUIT_Operation* anOp = *it; if ( anOp != 0 && anOp!= theOp && !anOp->isValid( theOp ) ) return anOp; } @@ -233,17 +266,17 @@ SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const /*! * \brief Starts operation * \param theOp - operation to be started - * \param toCheck - if parameters is equal TRUE then checking performed whether + * \param toCheck - if parameters is equal \c true then checking performed whether * all already started operations allow to start this operation above them (default - * value is TRUE - * \return TRUE if operation is started, FALSE otherwise + * value is \c true + * \return \c true if operation is started, \c false otherwise * * Verifies whether theOp operation can be started above already started ones (if toCheck -* parameter is equal TRUE) and starts it +* parameter is equal \c true) and starts it */ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck ) { - if ( !theOp || myOperations.find( theOp ) >= 0 ) + if ( !theOp || myOperations.contains( theOp ) ) return false; theOp->setExecStatus( SUIT_Operation::Rejected ); @@ -254,11 +287,11 @@ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck ) if ( toCheck ) { - while( SUIT_Operation* anOp = blockingOperation( theOp ) ) + while ( SUIT_Operation* anOp = blockingOperation( theOp ) ) { - int anAnsw = SUIT_MessageBox::warn2( application()->desktop(), - tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ), - tr( "CONTINUE" ), tr( "CANCEL" ), 0, 1, 1 ); + int anAnsw = SUIT_MessageBox::question( application()->desktop(), + tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ), + tr( "CONTINUE" ), tr( "CANCEL" ) ); if ( anAnsw == 1 ) return false; @@ -287,14 +320,14 @@ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck ) /*! * \brief Aborts operation * \param theOp - operation to be aborted - * \return TRUE if operation is aborted successfully + * \return \c true if operation is aborted successfully * * Verifies whether operation already started and aborts it in this case (sets execution * status to Rejected and stops operation) */ bool SUIT_Study::abort( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 ) + if ( !theOp || !myOperations.contains( theOp ) ) return false; theOp->setExecStatus( SUIT_Operation::Rejected ); @@ -311,14 +344,14 @@ bool SUIT_Study::abort( SUIT_Operation* theOp ) /*! * \brief Commits operation * \param theOp - operation to be committed - * \return TRUE if operation is committed successfully + * \return \c true if operation is committed successfully * * Verifies whether operation already started and commits it in this case (sets execution * status to Accepted and stops operation) */ bool SUIT_Study::commit( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 ) + if ( !theOp || !myOperations.contains( theOp ) ) return false; theOp->setExecStatus( SUIT_Operation::Accepted ); @@ -337,14 +370,14 @@ bool SUIT_Study::commit( SUIT_Operation* theOp ) /*! * \brief Commits operation * \param theOp - operation to be committed - * \return TRUE if operation is suspended successfully + * \return \c true if operation is suspended successfully * * Verifies whether operation already started and suspends it in this case. Operations * ususlly are suspended to start other one above them. */ bool SUIT_Study::suspend( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 || theOp->state() == SUIT_Operation::Suspended ) + if ( !theOp || !myOperations.contains( theOp ) || theOp->state() == SUIT_Operation::Suspended ) return false; theOp->setState( SUIT_Operation::Suspended ); @@ -357,13 +390,13 @@ bool SUIT_Study::suspend( SUIT_Operation* theOp ) /*! * \brief Resumes operation * \param theOp - operation to be resumed - * \return TRUE if operation is aborted successfully + * \return \c true if operation is aborted successfully * * Verifies whether operation already started but suspended and resumesit in this case. */ bool SUIT_Study::resume( SUIT_Operation* theOp ) { - if ( !theOp || myOperations.find( theOp ) == -1 || + if ( !theOp || !myOperations.contains( theOp ) || theOp->state() == SUIT_Operation::Running || blockingOperation( theOp ) != 0 ) return false; @@ -377,7 +410,7 @@ bool SUIT_Study::resume( SUIT_Operation* theOp ) // Move operation at the end of list in order to sort it in the order of activation. // As result active operation is a last operation of list, operation which was active // before currently active operation is located before it and so on - myOperations.remove( theOp ); + myOperations.removeAll( theOp ); myOperations.append( theOp ); emit theOp->resumed( theOp ); @@ -394,12 +427,16 @@ bool SUIT_Study::resume( SUIT_Operation* theOp ) void SUIT_Study::stop( SUIT_Operation* theOp ) { theOp->setState( SUIT_Operation::Waiting ); - myOperations.remove( theOp ); + myOperations.removeAll( theOp ); // get last operation which can be resumed - SUIT_Operation* anOp, *aResultOp = 0; - for ( anOp = myOperations.last(); anOp; anOp = myOperations.prev() ) + SUIT_Operation* aResultOp = 0; + + QListIterator it (myOperations); + it.toBack(); + while( it.hasPrevious() ) { + SUIT_Operation* anOp = it.previous(); if ( anOp && anOp != theOp && blockingOperation( anOp ) == 0 ) { aResultOp = anOp; @@ -419,7 +456,7 @@ void SUIT_Study::stop( SUIT_Operation* theOp ) * \brief Get all started operations * \return List of all started operations */ -const QPtrList& SUIT_Study::operations() const +const QList& SUIT_Study::operations() const { return myOperations; } @@ -433,7 +470,7 @@ void SUIT_Study::operationStarted( SUIT_Operation* op ) return; if ( op->testFlags( SUIT_Operation::Transaction ) ) - openTransaction(); + op->openTransaction(); } /*! @@ -442,7 +479,7 @@ void SUIT_Study::operationStarted( SUIT_Operation* op ) void SUIT_Study::operationAborted( SUIT_Operation* op ) { if ( op->testFlags( SUIT_Operation::Transaction ) ) - abortTransaction(); + op->abortTransaction(); } /*! @@ -451,7 +488,7 @@ void SUIT_Study::operationAborted( SUIT_Operation* op ) void SUIT_Study::operationCommited( SUIT_Operation* op ) { if ( op->testFlags( SUIT_Operation::Transaction ) ) - commitTransaction( op->operationName() ); + op->commitTransaction( op->operationName() ); } /*! @@ -486,9 +523,16 @@ bool SUIT_Study::commitTransaction( const QString& ) } /*! - * \brief Returns TRUE if transaction is opened. + * \brief Returns \c true if transaction is opened. */ bool SUIT_Study::hasTransaction() const { return false; } + +/*! + * \brief Restores the study state. + */ +void SUIT_Study::restoreState(int /*savePoint*/) +{ +}