From 402f390a89914f9a83eed4085b3cb525a72936fe Mon Sep 17 00:00:00 2001 From: sln Date: Fri, 1 Jul 2005 06:21:32 +0000 Subject: [PATCH] new files for dialog and operation --- src/SalomeApp/Makefile.in | 13 +- src/SalomeApp/SalomeApp_Dialog.cxx | 357 ++++++++++++++++++++++++++ src/SalomeApp/SalomeApp_Dialog.h | 99 +++++++ src/SalomeApp/SalomeApp_Operation.cxx | 229 +++++++++++++++++ src/SalomeApp/SalomeApp_Operation.h | 113 ++++++++ 5 files changed, 808 insertions(+), 3 deletions(-) create mode 100644 src/SalomeApp/SalomeApp_Dialog.cxx create mode 100644 src/SalomeApp/SalomeApp_Dialog.h create mode 100755 src/SalomeApp/SalomeApp_Operation.cxx create mode 100755 src/SalomeApp/SalomeApp_Operation.h diff --git a/src/SalomeApp/Makefile.in b/src/SalomeApp/Makefile.in index d2f586bc1..832308710 100755 --- a/src/SalomeApp/Makefile.in +++ b/src/SalomeApp/Makefile.in @@ -40,7 +40,9 @@ EXPORT_HEADERS= SalomeApp.h \ SalomeApp_TypeFilter.h \ SalomeApp_OBFilter.h \ SalomeApp_StudyPropertiesDlg.h \ - SalomeApp_CheckFileDlg.h + SalomeApp_CheckFileDlg.h \ + SalomeApp_Operation.h \ + SalomeApp_Dialog.h # .po files to transform in .qm PO_FILES = SalomeApp_images.po \ @@ -78,7 +80,9 @@ LIB_SRC= SalomeApp_AboutDlg.cxx \ SalomeApp_OBFilter.cxx \ SalomeApp_StudyPropertiesDlg.cxx \ SalomeApp_ListView.cxx \ - SalomeApp_CheckFileDlg.cxx + SalomeApp_CheckFileDlg.cxx \ + SalomeApp_Operation.cxx \ + SalomeApp_Dialog.cxx LIB_MOC = SalomeApp_AboutDlg.h \ SalomeApp_Application.h \ @@ -97,7 +101,9 @@ LIB_MOC = SalomeApp_AboutDlg.h \ SalomeApp_ModuleDlg.h \ SalomeApp_StudyPropertiesDlg.h \ SalomeApp_ListView.h \ - SalomeApp_CheckFileDlg.h + SalomeApp_CheckFileDlg.h \ + SalomeApp_Operation.h \ + SalomeApp_Dialog.h LIB_CLIENT_IDL = SALOMEDS.idl \ SALOME_Exception.idl \ @@ -108,6 +114,7 @@ RESOURCES_FILES = icon_about.png \ icon_default.png \ icon_module.png \ icon_module_big.png \ + icon_select.png \ SalomeApp.ini \ SalomeApp.xml diff --git a/src/SalomeApp/SalomeApp_Dialog.cxx b/src/SalomeApp/SalomeApp_Dialog.cxx new file mode 100644 index 000000000..8ea2747a2 --- /dev/null +++ b/src/SalomeApp/SalomeApp_Dialog.cxx @@ -0,0 +1,357 @@ +// File: SalomeApp_Dialog.cxx +// Author: Alexander SOLOVYOV + +#include +#include + +#include +#include +#include + +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 ) +{ + setObjectPixmap( "SalomeApp", tr( "ICON_SELECT" ) ); +} + +SalomeApp_Dialog::~SalomeApp_Dialog() +{ +} + +void SalomeApp_Dialog::show() +{ + QtxDialog::show(); +} + +bool SalomeApp_Dialog::isExclusive() const +{ + return myIsExclusive; +} + +void SalomeApp_Dialog::updateButtons( const int _id ) +{ + if( !myIsExclusive ) + return; + + int id = _id; + + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + QPushButton* but = anIt.data().btn; + if( but && but->isOn() ) + { + if( id==-1 ) + id = anIt.key(); + + if( anIt.key()!=id ) + but->setOn( false ); + } + } +} + +void SalomeApp_Dialog::setExclusive( const bool ex ) +{ + myIsExclusive = ex; + updateButtons(); +} + +void SalomeApp_Dialog::showObject( const int id ) +{ + setObjectShown( id, true ); +} + +void SalomeApp_Dialog::hideObject( const int id ) +{ + setObjectShown( id, false ); +} + +void SalomeApp_Dialog::setObjectShown( const int id, const bool shown ) +{ + if( myObjects.contains( id ) && isObjectShown( id )!=shown ) + { + Object& obj = myObjects[ id ]; + obj.edit->setShown( shown ); + obj.btn->setShown( shown ); + obj.label->setShown( shown ); + if( !shown ) + obj.btn->setOn( false ); + } +} + +bool SalomeApp_Dialog::isObjectShown( const int id ) const +{ + return myObjects.contains( id ) && myObjects[ id ].edit->isShown(); +} + +void SalomeApp_Dialog::selectObject( const QString& name, const int type, const QString& entry ) +{ + ObjectMap::iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data().btn->isOn() ) + { + if( isCorrectType( anIt.key(), type ) ) + { + anIt.data().edit->setText( name ); + anIt.data().type = type; + anIt.data().entry = entry; + } + else + { + anIt.data().edit->setText( QString::null ); + anIt.data().type = -1; + anIt.data().entry = QString::null; + } + emit selectionChanged( anIt.key() ); + } +} + +bool SalomeApp_Dialog::hasSelection( const int id ) const +{ + return myObjects.contains( id ) && !myObjects[ id ].entry.isEmpty(); +} + +void SalomeApp_Dialog::clearSelection( const int id ) +{ + if( myObjects.contains( id ) ) + { + myObjects[ id ].entry = QString::null; + myObjects[ id ].type = -1; + myObjects[ id ].edit->setText( QString::null ); + emit selectionChanged( id ); + } +} + +QString SalomeApp_Dialog::selectedObject( const int id ) const +{ + if( myObjects.contains( id ) ) + return myObjects[ id ].entry; + else + return QString::null; +} + +void SalomeApp_Dialog::objectSelection( SelectedObjects& objs ) const +{ + //objs.clear(); + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + QString entry = selectedObject( anIt.key() ); + if( !entry.isEmpty() ) + objs.insert( anIt.key(), entry ); + } +} + +int SalomeApp_Dialog::createObject( const QString& label, QWidget* parent, const int id ) +{ + static int _id = -1; + + int nid = id>=0 ? id : --_id; + if( !myObjects.contains( nid ) ) + { + QLabel* lab = new QLabel( label, parent ); + myObjects[ nid ].label = lab; + + QPushButton* but = new QPushButton( parent ); + but->setIconSet( QIconSet( myPixmap ) ); + but->setToggleButton( true ); + connect( but, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) ); + myObjects[ nid ].btn = but; + + QLineEdit* ne = new QLineEdit( parent ); + ne->setReadOnly( true ); + myObjects[ nid ].edit = ne; + } + return nid; +} + +void SalomeApp_Dialog::renameObject( const int id, const QString& label ) +{ + if( myObjects.contains( id ) ) + myObjects[ id ].label->setText( label ); +} + +void SalomeApp_Dialog::setObjectType( const int id, const int type1, ... ) +{ + TypesList types; + + const int* tt = &type1; + while( *tt>=0 ) + { + types.append( *tt ); + tt++; + } + + setObjectType( id, types ); +} + +void SalomeApp_Dialog::setObjectType( const int id, const TypesList& list ) +{ + if( !myObjects.contains( id ) ) + return; + + TypesList& internal = myObjects[ id ].types; + + QMap types; + TypesList::const_iterator anIt = list.begin(), + aLast = list.end(); + for( ; anIt!=aLast; anIt++ ) + types.insert( *anIt, 0 ); + + + internal.clear(); + QMap::const_iterator aMIt = types.begin(), + aMLast = types.end(); + for( ; aMIt!=aMLast; aMIt++ ) + internal.append( aMIt.key() ); + + updateObject( id ); +} + +void SalomeApp_Dialog::addObjectType( const int id, const int type1, const int, ... ) +{ + TypesList types; objectTypes( id, types ); + + const int* tt = &type1; + while( *tt>=0 ) + { + types.append( *tt ); + tt++; + } + + setObjectType( id, types ); +} + +void SalomeApp_Dialog::addObjectType( const int id, const TypesList& list ) +{ + TypesList types = list; objectTypes( id, types ); + setObjectType( id, types ); +} + +void SalomeApp_Dialog::addObjectType( const int id, const int type ) +{ + TypesList types; objectTypes( id, types ); + types.append( type ); + setObjectType( id, types ); +} + +void SalomeApp_Dialog::removeObjectType( const int id ) +{ + TypesList types; + setObjectType( id, types ); +} + +void SalomeApp_Dialog::removeObjectType( const int id, const TypesList& list ) +{ + if( !myObjects.contains( id ) ) + return; + + TypesList& internal = myObjects[ id ].types; + + QMap types; + TypesList::const_iterator anIt = internal.begin(), + aLast = internal.end(); + for( ; anIt!=aLast; anIt++ ) + types.insert( *anIt, 0 ); + anIt = list.begin(); aLast = list.end(); + for( ; anIt!=aLast; anIt++ ) + types.remove( *anIt ); + + + internal.clear(); + QMap::const_iterator aMIt = types.begin(), + aMLast = types.end(); + for( ; aMIt!=aMLast; aMIt++ ) + internal.append( aMIt.key() ); + + updateObject( id ); +} + +void SalomeApp_Dialog::removeObjectType( const int id, const int type ) +{ + TypesList list; list.append( type ); + removeObjectType( id, list ); +} + +bool SalomeApp_Dialog::hasObjectType( const int id, const int type ) const +{ + if( myObjects.contains( id ) ) + return myObjects[ id ].types.contains( type ); + else + return false; +} + +void SalomeApp_Dialog::objectTypes( const int id, TypesList& list ) const +{ + if( myObjects.contains( id ) ) + { + TypesList::const_iterator anIt = myObjects[ id ].types.begin(), + aLast = myObjects[ id ].types.end(); + for( ; anIt!=aLast; anIt++ ) + list.append( *anIt ); + } +} + +void SalomeApp_Dialog::onToggled( bool on ) +{ + QPushButton* but = ( QPushButton* )sender(); + int id = -1; + + if( !but ) + return; + + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast && id==-1; anIt++ ) + if( anIt.data().btn==but ) + id = anIt.key(); + + if( id!=-1 ) + if( on ) + { + emit objectActivated( id ); + updateButtons( id ); + } + else + emit objectDeactivated( id ); +} + +void SalomeApp_Dialog::updateObject( const int id ) +{ + if( hasSelection( id ) && !isCorrectType( id, myObjects[ id ].type ) ) + clearSelection( id ); +} + +bool SalomeApp_Dialog::isCorrectType( const int id, const int type ) const +{ + if( myObjects.contains( id ) ) + return hasObjectType( id, type ) || myObjects[ id ].types.isEmpty(); + else + return false; +} + +SUIT_ResourceMgr* SalomeApp_Dialog::resMgr() const +{ + return SUIT_Session::session()->resourceMgr(); +} + +void SalomeApp_Dialog::setObjectPixmap( const QPixmap& p ) +{ + myPixmap = p; + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + anIt.data().btn->setIconSet( p ); +} + +void SalomeApp_Dialog::setObjectPixmap( const QString& section, const QString& file ) +{ + SUIT_ResourceMgr* mgr = resMgr(); + if( mgr ) + setObjectPixmap( mgr->loadPixmap( section, file ) ); +} diff --git a/src/SalomeApp/SalomeApp_Dialog.h b/src/SalomeApp/SalomeApp_Dialog.h new file mode 100644 index 000000000..ac7a07ba2 --- /dev/null +++ b/src/SalomeApp/SalomeApp_Dialog.h @@ -0,0 +1,99 @@ +// File: SalomeApp_Dialog.h +// Author: Alexander SOLOVYOV + +#ifndef SALOMEAPP_DIALOG_H +#define SALOMEAPP_DIALOG_H + +#include + +#include +#include +#include + + +class QLineEdit; +class QPushButton; +class QLabel; +class SUIT_ResourceMgr; + + +class SalomeApp_Dialog : public QtxDialog +{ + Q_OBJECT + +public: + typedef QValueList TypesList; + typedef QMap SelectedObjects; + +public: + SalomeApp_Dialog( QWidget* = 0, const char* = 0, bool = false, + bool = false, const int = Standard, WFlags = 0 ); + virtual ~SalomeApp_Dialog(); + + virtual void show(); + bool isExclusive() const; + void setExclusive( const bool ); + + void showObject( const int ); + void hideObject( const int ); + void setObjectShown( const int, const bool ); + bool isObjectShown( const int ) const; + + void selectObject( const QString&, const int, const QString& ); + bool hasSelection( const int ) const; + void clearSelection( const int = -1 ); + QString selectedObject( const int ) const; + void objectSelection( SelectedObjects& ) const; + +signals: + void selectionChanged ( int ); + void objectActivated ( int ); + void objectDeactivated( int ); + +protected: + SUIT_ResourceMgr* resMgr() const; + + int createObject ( const QString&, QWidget*, const int = -1 ); + void setObjectPixmap ( const QPixmap& ); + void setObjectPixmap ( const QString&, const QString& ); + void renameObject ( const int, const QString& ); + void setObjectType ( const int, const int, ... ); + void setObjectType ( const int, const TypesList& ); + void addObjectType ( const int, const int, const int, ... ); + void addObjectType ( const int, const TypesList& ); + void addObjectType ( const int, const int ); + void removeObjectType( const int ); + void removeObjectType( const int, const TypesList& ); + void removeObjectType( const int, const int ); + bool hasObjectType ( const int, const int ) const; + void objectTypes ( const int, TypesList& ) const; + +private slots: + void onToggled( bool ); + +private: + void updateButtons( const int = -1 ); + void updateObject( const int ); + bool isCorrectType( const int id, const int type ) const; + +private: + typedef struct + { + QLineEdit* edit; + QPushButton* btn; + QLabel* label; + QString entry; + int type; + TypesList types; + + } Object; + + typedef QMap ObjectMap; + +private: + ObjectMap myObjects; + bool myIsExclusive; + QPixmap myPixmap; +}; + +#endif diff --git a/src/SalomeApp/SalomeApp_Operation.cxx b/src/SalomeApp/SalomeApp_Operation.cxx new file mode 100755 index 000000000..b9d32c464 --- /dev/null +++ b/src/SalomeApp/SalomeApp_Operation.cxx @@ -0,0 +1,229 @@ +// SALOME SalomeApp +// +// Copyright (C) 2005 CEA/DEN, EDF R&D +// +// +// +// File : SalomeApp_Operation.h +// Author : Sergey LITONIN +// Module : SALOME + +#include "SalomeApp_Operation.h" + +#include "SalomeApp_Module.h" +#include "SalomeApp_Application.h" +#include "SalomeApp_Operation.h" + +#include +#include +#include + + +/* + Class : SalomeApp_Operation + Description : Base class for all operations +*/ + +//======================================================================= +// name : SalomeApp_Operation +// Purpose : Constructor +//======================================================================= +SalomeApp_Operation::SalomeApp_Operation( SalomeApp_Application* theApp ) +: SUIT_Operation( theApp ), + myModule( 0 ) +{ + +} + +SalomeApp_Operation::~SalomeApp_Operation() +{ + +} + +//======================================================================= +// name : module +// Purpose : Get module +//======================================================================= +SalomeApp_Module* SalomeApp_Operation::module() const +{ + return myModule; +} + +void SalomeApp_Operation::setModule( SalomeApp_Module* theModule ) +{ + myModule = theModule; +} + +//======================================================================= +// name : desktop +// Purpose : Get desktop +//======================================================================= +SUIT_Desktop* SalomeApp_Operation::desktop() const +{ + return application() != 0 ? application()->desktop() : 0; +} + +//======================================================================= +// name : resumeOperation +// Purpose : Enable dialog if it was desabled (in suspend method) +// and activate selection +//======================================================================= +void SalomeApp_Operation::resumeOperation() +{ + if ( dlg() ) + dlg()->removeEventFilter( this ); + activateSelection(); +} + +//======================================================================= +// name : startOperation +// Purpose : Connect signal of selection manager to onSelectionDone() slot +//======================================================================= +void SalomeApp_Operation::startOperation() +{ + if( selectionMgr() ) + connect( selectionMgr(), SIGNAL( selectionChanged() ), SLOT( onSelectionDone() ) ); +} + +//======================================================================= +// name : suspendOperation +// Purpose : Disable dialog for mouse and key events +//======================================================================= +void SalomeApp_Operation::suspendOperation() +{ + if ( dlg() ) + dlg()->installEventFilter( this ); +} + +//======================================================================= +// name : abortOperation +// Purpose : Hide dialog box (if it is exists) +//======================================================================= +void SalomeApp_Operation::abortOperation() +{ + if ( dlg() ) + { + dlg()->removeEventFilter( this ); + dlg()->hide(); + } + + if( selectionMgr() ) + disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) ); +} + +//======================================================================= +// name : commitOperation +// Purpose : Hide dialog box (if it is exists) +//======================================================================= +void SalomeApp_Operation::commitOperation() +{ + if ( dlg() ) + { + dlg()->removeEventFilter( this ); + dlg()->hide(); + } + + if( selectionMgr() ) + disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionDone() ) ); +} + +//======================================================================= +// name : dlg +// Purpose : Get dialog. This method should be redefined in derived classes +// if they use dialogs. If this function returns pointer to dialog +// then dialog will be correctly +// 1. deactivated in suspendOperation method +// 2. activated in resumeOperation method +// 3. hidden in abortOperation and commitOperation methods +//======================================================================= +SalomeApp_Dialog* SalomeApp_Operation::dlg() const +{ + return 0; +} + +//======================================================================= +// name : activateSelection +// Purpose : Activate selection. This method should be redefined in derived +// classes if they use own selection modes (different from default) +//======================================================================= +void SalomeApp_Operation::activateSelection() +{ +} + +//======================================================================= +// name : selectionDone +// Purpose : This method called when selection is changed +//======================================================================= +void SalomeApp_Operation::selectionDone() +{ +} + +//======================================================================= +// name : isActive +// Purpose : Verify whether operator is active one +//======================================================================= +bool SalomeApp_Operation::isActive() const +{ + return activeOperation() == this; +} + +//======================================================================= +// name : activeOperation +// Purpose : Get active operation +//======================================================================= +SUIT_Operation* SalomeApp_Operation::activeOperation() const +{ + return study() != 0 ? study()->activeOperation() : 0; +} +//======================================================================= +// name : selectionMgr +// Purpose : Get selection manager +//======================================================================= +SalomeApp_SelectionMgr* SalomeApp_Operation::selectionMgr() const +{ + SUIT_Application* app = application(); + if ( app != 0 && app->inherits( "SalomeApp_Application" ) ) + return ( (SalomeApp_Application*)app )->selectionMgr(); + else + return 0; +} + +//======================================================================= +// name : onSelectionDone +// Purpose : Call selectionDone() method if operator is an active one +//======================================================================= +void SalomeApp_Operation::onSelectionDone() +{ + if ( isActive() ) + selectionDone(); +} + +//======================================================================= +// name : eventFilter +// Purpose : Block mouse and key events if operator is not active one +//======================================================================= +bool SalomeApp_Operation::eventFilter( QObject* obj, QEvent* e ) +{ + // to do + return SUIT_Operation::eventFilter( obj, e ); +} + + + + + + + + + + + + + + + + + + + + diff --git a/src/SalomeApp/SalomeApp_Operation.h b/src/SalomeApp/SalomeApp_Operation.h new file mode 100755 index 000000000..0f767ad81 --- /dev/null +++ b/src/SalomeApp/SalomeApp_Operation.h @@ -0,0 +1,113 @@ +// SALOME SalomeApp +// +// Copyright (C) 2005 CEA/DEN, EDF R&D +// +// +// +// File : SalomeApp_Operation.h +// Author : Sergey LITONIN +// Module : SALOME + + +#ifndef SalomeApp_Operation_H +#define SalomeApp_Operation_H + +#include "SUIT_Operation.h" + +class SalomeApp_Module; +class SalomeApp_Application; +class SalomeApp_Operation; +class SalomeApp_SelectionMgr; +class SalomeApp_Dialog; +class SUIT_Desktop; + +/* + Class : SalomeApp_Operation + Description : Base class for all operations +*/ + +class SalomeApp_Operation : public SUIT_Operation +{ + Q_OBJECT + +public: + + SalomeApp_Operation( SalomeApp_Application* theApp ); + virtual ~SalomeApp_Operation(); + + void setModule( SalomeApp_Module* ); + // Set module + +protected: + + // 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 + // if they use dialogs. If this function returns pointer to dialog + // then dialog will be correctly + // 1. deactivated in suspendOperation method + // 2. activated in resumeOperation method + // 3. hidden in abortOperation and commitOperation methods + + virtual void activateSelection(); + // Activate selection. This method should be redefined in derived + // classes if they use own selection modes (different from default) + + virtual void selectionDone(); + // This method called when selection is changed + + // Methods redefined from base class + + virtual void startOperation(); + // Connect signal of selection manager to onSelectionDone() slot + + virtual void suspendOperation(); + // Disable dialog for mouse and key events + + virtual void resumeOperation(); + // Enable dialog if it was deactivated (in suspend method) and activate selection + + virtual void abortOperation(); + // Hide dialog box (if it is exists) + + virtual void commitOperation(); + // Hide dialog box (if it is exists) + + bool isActive() const; + // Verify whether operator is active one + + SalomeApp_Module* module() const; + // Get module + + SUIT_Desktop* desktop() const; + // Get desktop + + SUIT_Operation* activeOperation() const; + // Get active operation + + SalomeApp_SelectionMgr* selectionMgr() const; + // Get selection manager + +private slots: + + virtual void onSelectionDone(); + // Call selectionDone() method if operator is an active one + +private: + + bool eventFilter( QObject*, QEvent* ); + // Block mouse and key events if operator is not active one + +private: + + SalomeApp_Module* myModule; +}; + +#endif + + + + + + -- 2.39.2