From bf27a11cfccce683cdd39d7ea91f02fafc9a0dc2 Mon Sep 17 00:00:00 2001 From: inv Date: Fri, 24 Dec 2010 14:18:34 +0000 Subject: [PATCH] Issue 0021124: EDF 1731 GUI: Unexpected behaviour of sg.Display() command --- src/LightApp/LightApp_Study.cxx | 21 +++++ src/LightApp/LightApp_Study.h | 1 + src/SALOME_SWIG/SALOMEGUI_Swig.cxx | 127 +++++++++++++++++------------ src/SalomeApp/SalomeApp_Study.cxx | 17 ++++ src/SalomeApp/SalomeApp_Study.h | 1 + 5 files changed, 113 insertions(+), 54 deletions(-) diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx index 7f2ee5e95..ae8e174c4 100644 --- a/src/LightApp/LightApp_Study.cxx +++ b/src/LightApp/LightApp_Study.cxx @@ -462,3 +462,24 @@ void LightApp_Study::components( QStringList& comp ) const comp.append( obj->entry() ); } } + +/*! + Get the entry for the given module + \param comp - list to be filled + \return module root's entry +*/ +QString LightApp_Study::centry( const QString& comp ) const +{ + QString e; + ModelList dmlist; + dataModels( dmlist ); + QListIterator it( dmlist ); + while ( it.hasNext() && e.isEmpty() ) { + CAM_DataModel* dm = it.next(); + if ( dm->module() && dm->module()->name() == comp ) { + LightApp_DataObject* r = dynamic_cast( dm->root() ); + if ( r ) e = r->entry(); + } + } + return e; +} diff --git a/src/LightApp/LightApp_Study.h b/src/LightApp/LightApp_Study.h index 314b87746..c4ef9ce69 100644 --- a/src/LightApp/LightApp_Study.h +++ b/src/LightApp/LightApp_Study.h @@ -69,6 +69,7 @@ public: virtual bool isComponent( const QString& ) const; virtual void children( const QString&, QStringList& ) const; virtual void components( QStringList& ) const; + virtual QString centry( const QString& ) const; protected: virtual void saveModuleData ( QString theModuleName, QStringList theListOfFiles ); diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx index 2a33e342f..bf7f7d830 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -416,8 +417,6 @@ void SALOMEGUI_Swig::ClearIObjects() The presentable object should be previously created and displayed in this viewer. - For the current moment implemented for OCC and VTK viewers only. - \param theEntry object entry */ void SALOMEGUI_Swig::Display( const char* theEntry ) @@ -428,13 +427,20 @@ void SALOMEGUI_Swig::Display( const char* theEntry ) public: TEvent( const char* theEntry ) : myEntry( theEntry ) {} virtual void Execute() { - if ( LightApp_Application* anApp = getApplication() ) { - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); - if ( window ) { - SALOME_View* view = dynamic_cast( window->getViewManager()->getViewModel() ); - if ( view ) - view->Display( view->CreatePrs( myEntry.toLatin1() ) ); - } + LightApp_Application* anApp = getApplication(); + LightApp_Study* aStudy = getActiveStudy(); + if ( anApp && aStudy ) { + QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true ); + if ( d ) { + QStringList entries; + if( aStudy->isComponent( myEntry ) ) + aStudy->children( myEntry, entries ); + else + entries.append( myEntry ); + foreach( QString entry, entries ) + d->Display( aStudy->referencedToEntry( entry ), false, 0 ); + } } } }; @@ -448,8 +454,6 @@ void SALOMEGUI_Swig::Display( const char* theEntry ) The presentable object should be previously created and displayed in this viewer. - For the current moment implemented for OCC and VTK viewers only. - \param theEntry object entry */ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry ) @@ -461,15 +465,27 @@ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry ) TEvent( const char* theEntry ) : myEntry( theEntry ) {} virtual void Execute() { - if ( LightApp_Application* anApp = getApplication() ) { - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); - if ( window ) { - SALOME_View* view = dynamic_cast( window->getViewManager()->getViewModel() ); - if ( view ) { - view->EraseAll( false ); - view->Display( view->CreatePrs( myEntry.toLatin1() ) ); - } - } + LightApp_Application* anApp = getApplication(); + LightApp_Study* aStudy = getActiveStudy(); + if ( anApp && aStudy ) { + QStringList comps; + aStudy->components( comps ); + foreach( QString comp, comps ) { + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true ); + if ( d ) d->EraseAll( false, false, 0 ); + } + + QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true ); + if ( d ) { + QStringList entries; + if( aStudy->isComponent( myEntry ) ) + aStudy->children( myEntry, entries ); + else + entries.append( myEntry ); + foreach( QString entry, entries ) + d->Display( aStudy->referencedToEntry( entry ), false, 0 ); + } } } }; @@ -482,8 +498,6 @@ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry ) The presentable object should be previously created and displayed in this viewer. - For the current moment implemented for OCC and VTK viewers only. - \param theEntry object entry */ void SALOMEGUI_Swig::Erase( const char* theEntry ) @@ -495,13 +509,20 @@ void SALOMEGUI_Swig::Erase( const char* theEntry ) TEvent( const char* theEntry ) : myEntry( theEntry ) {} virtual void Execute() { - if ( LightApp_Application* anApp = getApplication() ) { - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); - if ( window ) { - SALOME_View* view = dynamic_cast( window->getViewManager()->getViewModel() ); - if ( view ) - view->Erase( view->CreatePrs( myEntry.toLatin1() ) ); - } + LightApp_Application* anApp = getApplication(); + LightApp_Study* aStudy = getActiveStudy(); + if ( anApp && aStudy ) { + QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true ); + if ( d ) { + QStringList entries; + if( aStudy->isComponent( myEntry ) ) + aStudy->children( myEntry, entries ); + else + entries.append( myEntry ); + foreach( QString entry, entries ) + d->Erase( aStudy->referencedToEntry( entry ), false, false, 0 ); + } } } }; @@ -514,8 +535,6 @@ void SALOMEGUI_Swig::Erase( const char* theEntry ) The presentable objects should be previously created and displayed in this viewer. - - For the current moment implemented for OCC and VTK viewers only. */ void SALOMEGUI_Swig::DisplayAll() { @@ -525,20 +544,20 @@ void SALOMEGUI_Swig::DisplayAll() TEvent() {} virtual void Execute() { - if ( LightApp_Application* anApp = getApplication() ) { - LightApp_Study* study = dynamic_cast( anApp->activeStudy() ); // for sure! - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); - LightApp_Module* activeModule = dynamic_cast( anApp->activeModule() ); - if ( study && window && activeModule ) { - SALOME_View* view = dynamic_cast( window->getViewManager()->getViewModel() ); - if ( view ) { - for ( SUIT_DataObjectIterator it( activeModule->dataModel()->root(), SUIT_DataObjectIterator::DepthLeft ); it.current(); ++it ) { - LightApp_DataObject* obj = dynamic_cast( it.current() ); - if ( obj && !obj->entry().isEmpty() ) - view->Display( view->CreatePrs( obj->entry().toLatin1() ) ); - } - } - } + LightApp_Application* anApp = getApplication(); + LightApp_Study* aStudy = getActiveStudy(); + if ( anApp && aStudy ) { + QStringList comps; + aStudy->components( comps ); + foreach( QString comp, comps ) { + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true ); + if ( d ) { + QStringList entries; + aStudy->children( aStudy->centry( comp ), entries ); + foreach( QString entry, entries ) + d->Display( aStudy->referencedToEntry( entry ), false, 0 ); + } + } } } }; @@ -547,8 +566,6 @@ void SALOMEGUI_Swig::DisplayAll() /*! \brief Erase all objects from the current view window. - - For the current moment implemented for OCC and VTK viewers only. */ void SALOMEGUI_Swig::EraseAll() { @@ -558,13 +575,15 @@ void SALOMEGUI_Swig::EraseAll() TEvent() {} virtual void Execute() { - if ( LightApp_Application* anApp = getApplication() ) { - SUIT_ViewWindow* window = anApp->desktop()->activeWindow(); - if ( window ) { - SALOME_View* view = dynamic_cast( window->getViewManager()->getViewModel() ); - if ( view ) - view->EraseAll( false ); - } + LightApp_Application* anApp = getApplication(); + LightApp_Study* aStudy = getActiveStudy(); + if ( anApp && aStudy ) { + QStringList comps; + aStudy->components( comps ); + foreach( QString comp, comps ) { + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true ); + if ( d ) d->EraseAll( false, false, 0 ); + } } } }; diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 019b882b4..7a0008783 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -706,6 +706,23 @@ void SalomeApp_Study::components( QStringList& comps ) const } } +/*! + Get the entry for the given module + \param comp - list to be filled + \return module root's entry +*/ +QString SalomeApp_Study::centry( const QString& comp ) const +{ + QString e; + for( _PTR(SComponentIterator) it ( studyDS()->NewComponentIterator() ); it->More() && e.isEmpty(); it->Next() ) + { + _PTR(SComponent) aComponent ( it->Value() ); + if ( aComponent && comp == aComponent->ComponentDataType().c_str() ) + e = aComponent->GetID().c_str(); + } + return e; +} + /*! \return a list of saved points' IDs */ diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index 597a3e069..e63decf93 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -71,6 +71,7 @@ public: virtual bool isComponent( const QString& ) const; virtual void children( const QString&, QStringList& ) const; virtual void components( QStringList& ) const; + virtual QString centry( const QString& ) const; std::vector getSavePoints(); void removeSavePoint(int savePoint); -- 2.39.2