From 5c26efca3b9c3eb7fb17dda66871e6b81ec6df18 Mon Sep 17 00:00:00 2001 From: sln Date: Tue, 12 Jul 2005 13:44:24 +0000 Subject: [PATCH] Mechanism of operations changed. New file SalomeApp_SwitchOp added to control switching between started operations. --- src/SalomeApp/Makefile.in | 9 +- src/SalomeApp/SalomeApp_Dialog.cxx | 3 +- src/SalomeApp/SalomeApp_Dialog.h | 8 +- src/SalomeApp/SalomeApp_Module.cxx | 10 +- src/SalomeApp/SalomeApp_Module.h | 2 + src/SalomeApp/SalomeApp_Operation.cxx | 27 ++-- src/SalomeApp/SalomeApp_Operation.h | 14 +-- src/SalomeApp/SalomeApp_SwitchOp.cxx | 171 ++++++++++++++++++++++++++ src/SalomeApp/SalomeApp_SwitchOp.h | 76 ++++++++++++ 9 files changed, 296 insertions(+), 24 deletions(-) create mode 100755 src/SalomeApp/SalomeApp_SwitchOp.cxx create mode 100755 src/SalomeApp/SalomeApp_SwitchOp.h diff --git a/src/SalomeApp/Makefile.in b/src/SalomeApp/Makefile.in index f5f7ac834..b95b93c2a 100755 --- a/src/SalomeApp/Makefile.in +++ b/src/SalomeApp/Makefile.in @@ -43,7 +43,8 @@ EXPORT_HEADERS= SalomeApp.h \ SalomeApp_CheckFileDlg.h \ SalomeApp_Operation.h \ SalomeApp_Dialog.h \ - SalomeApp_UpdateFlags.h + SalomeApp_UpdateFlags.h \ + SalomeApp_SwitchOp.cxx # .po files to transform in .qm PO_FILES = SalomeApp_images.po \ @@ -83,7 +84,8 @@ LIB_SRC= SalomeApp_Module.cxx \ SalomeApp_ListView.cxx \ SalomeApp_CheckFileDlg.cxx \ SalomeApp_Operation.cxx \ - SalomeApp_Dialog.cxx + SalomeApp_Dialog.cxx \ + SalomeApp_SwitchOp.cxx LIB_MOC = SalomeApp_AboutDlg.h \ SalomeApp_Application.h \ @@ -104,7 +106,8 @@ LIB_MOC = SalomeApp_AboutDlg.h \ SalomeApp_ListView.h \ SalomeApp_CheckFileDlg.h \ SalomeApp_Operation.h \ - SalomeApp_Dialog.h + SalomeApp_Dialog.h \ + SalomeApp_SwitchOp.h LIB_CLIENT_IDL = SALOMEDS.idl \ SALOME_Exception.idl \ diff --git a/src/SalomeApp/SalomeApp_Dialog.cxx b/src/SalomeApp/SalomeApp_Dialog.cxx index 8fb0786b2..ceaea4a61 100644 --- a/src/SalomeApp/SalomeApp_Dialog.cxx +++ b/src/SalomeApp/SalomeApp_Dialog.cxx @@ -20,7 +20,8 @@ SalomeApp_Dialog::SalomeApp_Dialog( QWidget* parent, const char* name, bool modal, bool allowResize, const int f, WFlags wf ) : QtxDialog( parent, name, modal, allowResize, f, wf ), - myIsExclusive( true ) + myIsExclusive( true ), + myIsAutoResumed( false ) { setObjectPixmap( "SalomeApp", tr( "ICON_SELECT" ) ); } diff --git a/src/SalomeApp/SalomeApp_Dialog.h b/src/SalomeApp/SalomeApp_Dialog.h index c52c9966b..e0e5cfe52 100644 --- a/src/SalomeApp/SalomeApp_Dialog.h +++ b/src/SalomeApp/SalomeApp_Dialog.h @@ -51,6 +51,12 @@ public: //! Set exclusive state void setExclusive( const bool ); + //! Check if operation according to dialog will be resumed automatically when mouse enter the dialog + bool isAutoResumed() const; + + //! Set auto resumed state + void setAutoResumed( const bool ); + //! Show widgets corresponding to id void showObject( const int ); @@ -203,7 +209,7 @@ private: private: ObjectMap myObjects; QMap myTypeNames; - bool myIsExclusive; + bool myIsExclusive, myIsAutoResumed; QPixmap myPixmap; }; diff --git a/src/SalomeApp/SalomeApp_Module.cxx b/src/SalomeApp/SalomeApp_Module.cxx index c1728e3f4..f3a8e6f1f 100644 --- a/src/SalomeApp/SalomeApp_Module.cxx +++ b/src/SalomeApp/SalomeApp_Module.cxx @@ -11,6 +11,7 @@ #include "SalomeApp_Preferences.h" #include "SalomeApp_UpdateFlags.h" #include "SalomeApp_Operation.h" +#include "SalomeApp_SwitchOp.h" #include @@ -30,7 +31,8 @@ SalomeApp_Module::SalomeApp_Module( const QString& name ) : CAM_Module( name ), -myPopupMgr( 0 ) +myPopupMgr( 0 ), +mySwitchOp( 0 ) { } @@ -232,6 +234,12 @@ void SalomeApp_Module::startOperation( const int id ) op->setModule( this ); connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) ); connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) ); + if ( mySwitchOp == 0 ) + { + mySwitchOp = new SalomeApp_SwitchOp( this ); + printf( "sln: new SalomeApp_SwitchOp\n" ); + } + mySwitchOp->connect( op ); } } diff --git a/src/SalomeApp/SalomeApp_Module.h b/src/SalomeApp/SalomeApp_Module.h index abbce5b97..d174902ac 100644 --- a/src/SalomeApp/SalomeApp_Module.h +++ b/src/SalomeApp/SalomeApp_Module.h @@ -29,6 +29,7 @@ class SalomeApp_Application; class SalomeApp_Preferences; class SalomeApp_SelectionManager; class SalomeApp_Operation; +class SalomeApp_SwitchOp; /* Class : SalomeApp_Module @@ -122,6 +123,7 @@ private: private: QtxPopupMgr* myPopupMgr; MapOfOperation myOperations; + SalomeApp_SwitchOp* mySwitchOp; }; #endif diff --git a/src/SalomeApp/SalomeApp_Operation.cxx b/src/SalomeApp/SalomeApp_Operation.cxx index e8177867b..ca16c894c 100755 --- a/src/SalomeApp/SalomeApp_Operation.cxx +++ b/src/SalomeApp/SalomeApp_Operation.cxx @@ -17,6 +17,8 @@ #include +#include + /* Class : SalomeApp_Operation Description : Base class for all operations @@ -195,18 +197,18 @@ bool SalomeApp_Operation::eventFilter( QObject* obj, QEvent* e ) { if( e ) { - if( isAutoResumed() && - ( e->type()==QEvent::Enter || - e->type()==QEvent::WindowActivate || - e->type()==QEvent::MouseButtonPress || - e->type()==QEvent::MouseButtonDblClick ) ) - resume(); +// if( isAutoResumed() && +// ( e->type()==QEvent::Enter || +// e->type()==QEvent::WindowActivate || +// e->type()==QEvent::MouseButtonPress || +// e->type()==QEvent::MouseButtonDblClick ) ) +// resume(); - else if( e->type()==QEvent::MouseButtonRelease || - e->type()==QEvent::MouseButtonDblClick || - e->type()==QEvent::MouseMove || - e->type()==QEvent::KeyPress || - e->type()==QEvent::KeyRelease ) + if( e->type()==QEvent::MouseButtonRelease || + e->type()==QEvent::MouseButtonDblClick || + e->type()==QEvent::MouseMove || + e->type()==QEvent::KeyPress || + e->type()==QEvent::KeyRelease ) return true; } @@ -230,13 +232,16 @@ void SalomeApp_Operation::update( const int flags ) void SalomeApp_Operation::setDialogActive( const bool active ) { if( dlg() ) + { if( active ) { dlg()->removeEventFilter( this ); activateSelection(); + dlg()->setActiveWindow(); } else dlg()->installEventFilter( this ); + } } //======================================================================= diff --git a/src/SalomeApp/SalomeApp_Operation.h b/src/SalomeApp/SalomeApp_Operation.h index e5138c000..175b51db2 100755 --- a/src/SalomeApp/SalomeApp_Operation.h +++ b/src/SalomeApp/SalomeApp_Operation.h @@ -42,13 +42,6 @@ public: //! Check if operation will be resumed automatically when mouse enter the dialog bool isAutoResumed() const; - -protected: - - //! Set auto resumed state - void setAutoResumed( const bool ); - - // Important virtual methods (should be redefined in the derived classes) virtual SalomeApp_Dialog* dlg() const; // Get dialog. This method should be redefined in derived classes @@ -58,6 +51,13 @@ protected: // 2. activated in resumeOperation method // 3. hidden in abortOperation and commitOperation methods +protected: + + //! Set auto resumed state + void setAutoResumed( const bool ); + + // Important virtual methods (should be redefined in the derived classes) + virtual void setDialogActive( const bool ); // Change the active state of dialog (given by dlg()) diff --git a/src/SalomeApp/SalomeApp_SwitchOp.cxx b/src/SalomeApp/SalomeApp_SwitchOp.cxx new file mode 100755 index 000000000..ac40a53ba --- /dev/null +++ b/src/SalomeApp/SalomeApp_SwitchOp.cxx @@ -0,0 +1,171 @@ +/** +* SALOME SalomeApp +* +* Copyright (C) 2005 CEA/DEN, EDF R&D +* +* +* +* File : SalomeApp_SwitchOp.h +* Author : Sergey LITONIN +* Module : SALOME +*/ + +#include "SalomeApp_SwitchOp.h" +#include "SalomeApp_Module.h" +#include "SalomeApp_Operation.h" +#include "SalomeApp_Dialog.h" +#include +#include +#include +#include +#include +#include +#include + +/*! + * \brief Constructor + * \param theParent - parent of object +* +* Creates instance of the object. Connects signals and slots. Install eveny filter +* on application +*/ +SalomeApp_SwitchOp::SalomeApp_SwitchOp( SalomeApp_Module* theModule ) +: QObject( theModule ) +{ + qApp->installEventFilter( this ); +} + +/*! + * \brief Destructor +*/ +SalomeApp_SwitchOp::~SalomeApp_SwitchOp() +{ + +} + +/*! + * \brief SLOT. Called when number of operations changed +* +* +*/ +void SalomeApp_SwitchOp::onOperation() +{ +} + +/*! + * \brief Get module +* +* Get module. Module is a parent of this class +*/ +SalomeApp_Module* SalomeApp_SwitchOp::module() const +{ + return ( SalomeApp_Module* )parent(); +} + +/*! + * \brief Get study + * \return Active study of application (in current realisation) +* +* Get study +*/ +SUIT_Study* SalomeApp_SwitchOp::study() const +{ + return module()->application()->activeStudy(); +} + +/*! + * \brief Get operation by widget + * \param theWg - key widget to find operation + * \return Pointer to the operations if it is found or zero +* +* Find operation containing dialog with given widget +*/ +SalomeApp_Operation* SalomeApp_SwitchOp::operation( QWidget* theWg ) const +{ + // get dialog from widget + SalomeApp_Dialog* aDlg = 0; + QWidget* aParent = theWg; + while( aParent && !aParent->inherits( "SalomeApp_Dialog" ) ) + aParent = aParent->parentWidget(); + + if ( aParent && aParent->inherits( "SalomeApp_Dialog" ) ) + aDlg = (SalomeApp_Dialog*)aParent; + + // try to find operation corresponding to the dialog + if ( aDlg != 0 && study() != 0 ) + { + QPtrListIterator anIter( study()->operations() ); + while( SUIT_Operation* anOp = anIter.current() ) + { + if ( anOp->inherits( "SalomeApp_Operation" ) && + ((SalomeApp_Operation*)anOp)->dlg() == aDlg ) + return ((SalomeApp_Operation*)anOp); + ++anIter; + } + } + + return 0; +} + +/*! + * \brief Connect signals of operation on the slots of object + * \param theOp - operation for connection +* +* Connect signals of operation on the slots of object. This method is called by module +* when it creates operation +*/ +void SalomeApp_SwitchOp::connect( SalomeApp_Operation* theOp ) +{ +// to do: ??? +// void started( SUIT_Operation* ); +// void aborted( SUIT_Operation* ); +// void resumed( SUIT_Operation* ); +// void committed( SUIT_Operation* ); +// void suspended( SUIT_Operation* ); +// void stopped( SUIT_Operation* ); +} + +/*! + * \brief Event filter + * \param theObj - object + * \param theEv - event +* +* Event filter. Catched signals off application. If event concerns to dialog then +* corresponding operation is found and activated. +*/ +bool SalomeApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv ) +{ + if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) ) + { + SalomeApp_Operation* anOp = operation( (QWidget*)theObj ); + if ( anOp && !anOp->isActive() && anOp->isAutoResumed() ) + { + if ( study() ) + { + if ( study()->canActivate( anOp ) ) + study()->resume( anOp ); + } + } + } + + return QObject::eventFilter( theObj, theEv ); +} + + + + + + + + + + + + + + + + + + + diff --git a/src/SalomeApp/SalomeApp_SwitchOp.h b/src/SalomeApp/SalomeApp_SwitchOp.h new file mode 100755 index 000000000..8a0b2c95d --- /dev/null +++ b/src/SalomeApp/SalomeApp_SwitchOp.h @@ -0,0 +1,76 @@ +/** +* SALOME SalomeApp +* +* Copyright (C) 2005 CEA/DEN, EDF R&D +* +* +* +* File : SalomeApp_SwitchOp.h +* Author : Sergey LITONIN +* Module : SALOME +*/ + + + +#ifndef SalomeApp_SwitchOp_H +#define SalomeApp_SwitchOp_H + +#include + +class SalomeApp_Module; +class SalomeApp_Operation; +class QEvent; +class SUIT_Study; + +/*! + * \brief This class is intended for controling switching between operation + * + * Several operation may be launched simultaneously. This class is intended for + * controlling switching between such operations. This class works with operations having + * dialogs (activation of other operations is performed by SUIT_Study). When several + * operations is launched simultaneously corresponding dialogs are shown on the screen. + * Only one operation from the launched ones can be active (active operation). Other + * operations are suspended. As result only one dialog from shown ones can be active too. + * Other dialogs are disabled. This class installs event filter on application. When mouse + * cursor is moved above disabled dialog corresponding event is catched by this class. + * It finds corresponding operation and verify whether operation can be resumed (see + * SUIT_Study::canActivate( SUIT_Operation* ) method). If yes then current active + * operation is suspended and new operation activated. Module contains this class as a + * field. Then module is created instance of this class created too. + */ +class SalomeApp_SwitchOp : public QObject +{ + Q_OBJECT + +public: + + SalomeApp_SwitchOp( SalomeApp_Module* ); + virtual ~SalomeApp_SwitchOp(); + + void connect( SalomeApp_Operation* ); + + // Redefined from base class + bool eventFilter( QObject*, QEvent* ); + +private slots: + + void onOperation(); + +private: + + SalomeApp_Module* module() const; + SalomeApp_Operation* operation( QWidget* ) const; + SUIT_Study* study() const; + +private: + + +}; + +#endif + + + + + + -- 2.39.2