From fa55466fc613d390707b930827e821b1346e2b3c Mon Sep 17 00:00:00 2001 From: sln Date: Tue, 12 Jul 2005 13:42:27 +0000 Subject: [PATCH] Mechanism of operations changed --- src/SUIT/SUIT_Operation.cxx | 4 +- src/SUIT/SUIT_Operation.h | 348 ++++++++++++++++++++++++++---------- src/SUIT/SUIT_Study.cxx | 45 +++-- src/SUIT/SUIT_Study.h | 1 + 4 files changed, 288 insertions(+), 110 deletions(-) diff --git a/src/SUIT/SUIT_Operation.cxx b/src/SUIT/SUIT_Operation.cxx index 0929794b7..64e60cd9b 100755 --- a/src/SUIT/SUIT_Operation.cxx +++ b/src/SUIT/SUIT_Operation.cxx @@ -137,7 +137,7 @@ void SUIT_Operation::commit() { commitOperation(); myState = Waiting; - emit commited( this ); + emit committed( this ); emit stopped( this ); } } @@ -230,7 +230,7 @@ void SUIT_Operation::suspendOperation() //======================================================================= // name : commitOperation -// Purpose : Virtual method called when operation commited (see commit() +// Purpose : Virtual method called when operation committed (see commit() // method for more description) //======================================================================= void SUIT_Operation::commitOperation() diff --git a/src/SUIT/SUIT_Operation.h b/src/SUIT/SUIT_Operation.h index 4bebbc928..f3b3c73fb 100755 --- a/src/SUIT/SUIT_Operation.h +++ b/src/SUIT/SUIT_Operation.h @@ -20,24 +20,23 @@ class SUIT_Study; class SUIT_Application; -//============================================================================== -//! Base class for all operations /*! -* Base class for all operations. If you perform an action it is reasonable to create -* operation intended for this. This is a base class for all operations which provides -* mechanism for correct starting operations, starting operations above alredy strated -* ones, commiting operations and so on. To create own operation it is reasonable to -* inherit it from this class and reddefines virtual methods to provide own behaviour -* Main virtual methods are -* - virtual bool isReadyToStart(); -* - virtual void startOperation(); -* - virtual void abortOperation(); -* - virtual void commitOperation(); -* - virtual void resumeOperation(); -* - virtual void suspendOperation(); + * \brief Base class for all operations + * + * Base class for all operations. If you perform an action it is reasonable to create + * operation intended for this. This is a base class for all operations which provides + * mechanism for correct starting operations, starting operations above already started + * ones, committing operations and so on. To create own operation it is reasonable to + * inherit it from this class and redefines virtual methods to provide own behavior + * Main virtual methods are + * - virtual bool isReadyToStart(); + * - virtual void startOperation(); + * - virtual void abortOperation(); + * - virtual void commitOperation(); + * - virtual void resumeOperation(); + * - virtual void suspendOperation(); */ -//============================================================================== -class SUIT_EXPORT SUIT_Operation : public QObject +class SUIT_EXPORT SUIT_Operation : public QObject { Q_OBJECT @@ -46,140 +45,293 @@ public: /*! Enum describes state of operation */ enum OperationState { - Waiting, /*!< Operation is not used (it is not runned or suspended) */ - Running, /*!< Operation is started */ - Suspended /*!< Operation is started but suspended (other operation is performed above it) */ + Waiting, //!< Operation is not used (it is not run or suspended) + Running, //!< Operation is started + Suspended //!< Operation is started but suspended (other operation is performed above it) }; - /*! Enum describes execution status of operation */ + /*! + * Enum describes execution status of operation. Execution status often used after + * ending work of operation which was started from this one. In this case this + * operation can ask previously started operation whether it finished successfully. + */ enum ExecStatus { - Rejected, /*! Operation has not parformed any action (modificetion of data model for example) */ - Accepted /*! Operation has performed an actions and must be stopped */ + Rejected, //!< Operation has not performed any action (modification of data model for example) + Accepted //!< Operation has performed an actions and must be stopped }; public: + /*! + * \brief Constructor + * \param SUIT_Application - application for this operation + * + * Constructs an empty operation. Constructor should work very fast because many + * operators may be created after starting application but only several from them + * may be used. As result this constructor stores given application in myApp field + * and set Waiting status. + */ SUIT_Operation( SUIT_Application* ); - //!< Constructor - + + /*! + * \brief Destructor + */ virtual ~SUIT_Operation(); - //!< Destructor + /*! + * \brief Verifies whether operation is an active one (state()==Running) + * \return TRUE if operation is active, FALSE otherwise + * + * Verifies whether operation is an active on. Returns TRUE if state of operator + * is Running + */ bool isActive() const; - //!< Verifies whether operation is an active one (state()==Running) - + + /*! + * \brief Gets state of operation + * \return Value from OperationState enumeration + * + * Gets state of operation (see OperationState enumeration) + */ OperationState state() const; - //!< Returns state of operation (see OperationState enumeration) - void setState( const OperationState ); - //!< Sets state of operation (see OperationState enumeration) - + + /*! + * \brief Sets state of operation + * \param theState - state of operation to be set + * + * Sets state of operation (see OperationState enumeration) + */ + void setState( const OperationState theState ); + + /*! + * \brief Returns operation study + * \return Pointer to study + * Get study corresponding to this operation i.e. study which starts this operation. + */ SUIT_Study* study() const; - //!< Returns operation study (i.e. study which starts this operation ) - virtual void setStudy( SUIT_Study* ); + + /*! + * \brief Sets operation study + * \param theStudy - study corresponding to this operation + * + * Sets study corresponding to this operation i.e. study which starts this operation. + */ + virtual void setStudy( SUIT_Study* theStudy ); //!< Sets operation study (i.e. study which starts this operation ) - + + /*! + * \brief Gets application + * \return Pointer to application + * + * Gets application for this operation + */ SUIT_Application* application() const; - //!< Returns application - virtual void setApplication( SUIT_Application* ); - //!< Sets application - + + /*! + * \brief Sets application + * \param theApp - application for this operation + * + * Gets application for this operation + */ + virtual void setApplication( SUIT_Application* theApp ); + + /*! + * \brief Sets slot which is called when operation is started + * \param theReceiver - object containing slot + * \param theSlot - slot of theReceiver object + * \return TR if slot was connected successfully, FALSE otherwise + * + * Sets slot which is called when operation is started. There is no point in + * using this method. It would be better to inherit own operator from base + * one and redefine startOperation method + */ bool setSlot( const QObject* theReceiver, const char* theSlot ); - //!< Sets slot which is called when operation is started - /*! Sets slot which is called when operation is started. There is no point in - using this method. It would be better to inherit own operator from base - one and redefine startOperation method. */ - virtual bool isValid( SUIT_Operation* ) const; - //! Returns TRUE if the given operator is valid for (can be started "above") the current one + /*! + * \brief Verifies whether given operator is valid for this one + * \param theOtherOp - other operation + * \return Returns TRUE if the given operator is valid for this one + * + * Verifies whether given operator is valid for this one (i.e. can be started "above" + * this operator) + */ + virtual bool isValid( SUIT_Operation* theOtherOp ) const; + /*! + * \brief Verifies whether this operator can be always started above any already runnig one + * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this ) + * + * This method must be redefined in derived operation if operation of derived class + * must be always can start above any launched one. Default implementation returns FALSE, + * so it is being checked for IsValid, but some operations may overload IsGranted() + * In this case they will always start, no matter what operation is running. + */ virtual bool isGranted() const; - //!< Returns TRUE if current operation must not be checked for ActiveOperation->IsValid(this) - /*!< Returns TRUE if current operation must not be checked for - ActiveOperation->IsValid(this). Default implementation returns FALSE, - so it is being checked for IsValid, but some operations may overload IsGranted() - In this case they will always start, no matter what operation is running. */ public slots: + /*! + * \brief Starts operation + * + * Public slot. Verifies whether operation can be started and starts operation. + * This slot is not virtual and cannot be redefined. Redefine startOperation method + * to change behavior of operation. There is no point in using this method. It would + * be better to inherit own operator from base one and redefine startOperation method + * instead. + */ void start(); - //!< Starts operation. - /*!< Verifies whether operation can be started and starts operation. This slot - is not virtual and cannot be redefined. Redefine startOperation method - to change behaviour of operation instead */ - + + /*! + * \brief Aborts operation + * + * Public slot. Aborts operation. This slot is not virtual and cannot be redefined. + * Redefine abortOperation method to change behavior of operation instead + */ void abort(); - //!< Aborts operation. - /*!< This slot is not virtual and cannot be redefined. Redefine abortOperation - method to change behaviour of operation instead */ - + + /*! + * \brief Commits operation + * + * Public slot. Commits operation. This slot is not virtual and cannot be redefined. + * Redefine commitOperation method to change behavior of operation instead + */ void commit(); - //!< Commits operation. - /*!< This slot is not virtual and cannot be redefined. Redefine commitOperation - method to change behaviour of operation instead */ + /*! + * \brief Suspend operation. + * + * Public slot. Suspend operation. This slot is called when operation is suspended + * (for starting other one, for example) This slot is not virtual and cannot be + * redefined. Redefine suspendOperation method to change behavior of operation instead + */ void suspend(); - //!< Suspend operation. - /*!< This slot is called when operation is suspended (for starting other one, for example) - This slot is not virtual and cannot be redefined. Redefine suspendOperation - method to change behaviour of operation instead */ + /*! + * \brief Resumes operation + * + * Public slot. Resumes operation. This slot is called when operation is resumed after + * previous suspending. This slot is not virtual and cannot be redefined. Redefine + * resumeOperation method to change behavior of operation instead + */ void resume(); - //!< Resume operation. - /*!< This slot is called when operation is resumed after previous suspending. - This slot is not virtual and cannot be redefined. Redefine resumeOperation - method to change behaviour of operation instead */ - + signals: + /*! + * \brief Signal emitted from start method when operation started + */ void started( SUIT_Operation* ); - //!< Signal emited from start method when operation started + + /*! + * \brief Signal emitted from start method when operation aborted + */ void aborted( SUIT_Operation* ); - //!< Signal emited from abort method when operation aborted + + /*! + * \brief Signal emitted from start method when operation resumed + */ void resumed( SUIT_Operation* ); - //!< Signal emited from resume method when operation resumed - void commited( SUIT_Operation* ); - //!< Signal emited from commite method when operation commited + + /*! + * \brief Signal emitted from committed method when operation committed + */ + void committed( SUIT_Operation* ); + + /*! + * \brief Signal emited from suspend method when operation suspended + */ void suspended( SUIT_Operation* ); - //!< Signal emited from suspend method when operation suspended + + /*! + * \brief Signal emited from stop method when operation stopped + */ void stopped( SUIT_Operation* ); - //!< Signal emited from stop method when operation stopped - + + /*! + * \brief Signal emited from default implementation of startOperation method + * + * See setSlot for more description + */ void callSlot(); - //!< Signal emited from default implementation of startOperation method - /*!< See setSlot for more description */ protected: + /*! + * \brief Verifies whether operator is ready to start. + * \return TRUE if operation is ready to start + * + * Default implementation returns TRUE. Redefine this method to add own verifications + */ virtual bool isReadyToStart() const; - //!< Verify whether operator is ready to start. - /*!< Default implementation returns true. Redefine this method to add own verifications */ - + + /*! + * \brief Virtual method called when operation is started + * + * Virtual method called when operation started (see start() method for more description) + */ virtual void startOperation(); - //!< Virtual method called when operation started (see start() method for more description) + + /*! + * \brief Virtual method called when operation aborted + * + * Virtual method called when operation aborted (see abort() method for more description) + */ virtual void abortOperation(); - //!< Virtual method called when operation aborted (see abort() method for more description) + + /*! + * \brief Virtual method called when operation committed + * + * Virtual method called when operation committed (see commit() method for more description) + */ virtual void commitOperation(); - //!< Virtual method called when operation commited (see commit() method for more description) + + /*! + * \brief Virtual method called when operation suspended + * + * Virtual method called when operation suspended (see suspend() method for more description) + */ + virtual void suspendOperation(); - //!< Virtual method called when operation suspended (see suspend() method for more description) + + /*! + * \brief Virtual method called when operation resumed + * + * Virtual method called when operation resumed (see resume() method for more description) + */ virtual void resumeOperation(); - //!< Virtual method called when operation resumed (see resume() method for more description) - - void setExecStatus( const int ); - //!< Sets myExecStatus to the given value + + /*! + * \brief Sets execution status + * \param theStatus - execution status + * + * Sets myExecStatus to the given value + */ + void setExecStatus( const int theStatus ); + + /*! + * \brief Gets execution status + * \return Execution status + * + * Gets execution status + */ int execStatus() const; - //!< Gets execution status - void start( SUIT_Operation* ); - //!< Start operator above this one + /*! + * \brief Starts operator above this one + * \param theOp - operation to be started + * + * Start operator above this one. Use this method if you want to call other operator + * from this one + */ + void start( SUIT_Operation* theOp ); private: - SUIT_Application* myApp; - SUIT_Study* myStudy; - OperationState myState; - ExecStatus myExecStatus; + SUIT_Application* myApp; //!< application for this operation + SUIT_Study* myStudy; //!< study for this operation + OperationState myState; //!< Operation state + ExecStatus myExecStatus; //!< Execution status friend class SUIT_Study; }; diff --git a/src/SUIT/SUIT_Study.cxx b/src/SUIT/SUIT_Study.cxx index e1c34a263..27a94663b 100755 --- a/src/SUIT/SUIT_Study.cxx +++ b/src/SUIT/SUIT_Study.cxx @@ -157,7 +157,7 @@ void SUIT_Study::setStudyName( const QString& name ) //======================================================================= bool SUIT_Study::canActivate( SUIT_Operation* op ) const { - if( !op || myOperations.contains( op ) ) + if( !op ) return false; if( op->isGranted() ) @@ -167,7 +167,7 @@ bool SUIT_Study::canActivate( SUIT_Operation* op ) const SUIT_Operation* anOp = 0; for ( anOp = tmpOps.last(); anOp; anOp = tmpOps.prev() ) { - if ( anOp != 0 && !anOp->isValid( op ) ) + if ( anOp != 0 && anOp!= op && !anOp->isValid( op ) ) return false; } @@ -203,10 +203,13 @@ void SUIT_Study::start( SUIT_Operation* op, const bool check ) activeOperation()->abort(); } } - return; - - if ( activeOperation() ) + + SUIT_Operation* anOp = activeOperation(); + if ( anOp ) + { activeOperation()->suspendOperation(); + anOp->setState( SUIT_Operation::Suspended ); + } op->startOperation(); myOperations.append( op ); @@ -238,7 +241,7 @@ void SUIT_Study::commit( SUIT_Operation* op ) return; op->commitOperation(); - emit op->commited( op ); + emit op->committed( op ); stop( op ); emit studyModified( this ); } @@ -269,11 +272,14 @@ void SUIT_Study::resume( SUIT_Operation* op ) !canActivate( op ) ) return; + if ( myOperations.count() > 0 ) + suspend( myOperations.last() ); + op->setState( SUIT_Operation::Running ); op->resumeOperation(); // 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 + // 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( op ); myOperations.append( op ); @@ -290,12 +296,31 @@ void SUIT_Study::stop( SUIT_Operation* op ) { op->setState( SUIT_Operation::Waiting ); myOperations.remove( op ); - if ( myOperations.count() > 0 && myOperations.getLast() ) - myOperations.getLast()->resumeOperation(); - + + // get last operation which can be resumed + SUIT_Operation* anOp, *aResultOp = 0; + for( anOp = myOperations.last(); anOp; anOp = myOperations.prev() ) + if ( anOp && anOp != op && canActivate( anOp ) ) + { + aResultOp = anOp; + break; + } + emit op->stopped( op ); + if ( aResultOp ) + resume( aResultOp ); } +/*! + * \brief Get all started operations + * \return List of all started operations +*/ +const QPtrList& SUIT_Study::operations() const +{ + return myOperations; +} + + diff --git a/src/SUIT/SUIT_Study.h b/src/SUIT/SUIT_Study.h index ea86de837..9e817c16d 100755 --- a/src/SUIT/SUIT_Study.h +++ b/src/SUIT/SUIT_Study.h @@ -47,6 +47,7 @@ public: SUIT_Operation* activeOperation() const; virtual void abortAllOperations(); virtual bool canActivate( SUIT_Operation* ) const; + const QPtrList& operations() const; void start( SUIT_Operation*, const bool check = true ); //!< Starts operation. -- 2.39.2