From 128fc93d2767192cb91ce0bf8b0cab4f91efcb8d Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 10 Dec 2020 13:30:48 +0300 Subject: [PATCH] Find displayer by module internal name, as user name is empty for modules without GUI. --- src/CAM/CAM_Application.cxx | 15 +++++++--- src/LightApp/LightApp_Application.cxx | 4 +-- src/LightApp/LightApp_Displayer.cxx | 4 ++- src/LightApp/LightApp_Module.cxx | 2 +- src/LightApp/LightApp_Selection.cxx | 18 ++++-------- src/LightApp/LightApp_ShowHideOp.cxx | 8 +++--- src/SALOME_SWIG/SALOMEGUI_Swig.cxx | 12 ++++---- src/SalomeApp/SalomeApp_Application.cxx | 9 +++++- src/SalomeApp/SalomeApp_Study.cxx | 37 ++++++++++++------------- 9 files changed, 58 insertions(+), 51 deletions(-) diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index dadb2edc9..8738202ec 100644 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -675,19 +675,26 @@ QString CAM_Application::moduleLibrary( const QString& title, const bool full ) } /*! - \brief Get displayer proxy for given module, by its title (user name). + \brief Get displayer proxy for given module, by its title (user name) or by its name. \param title module title (user name) \return name of module which provides displayer for requested module */ -QString CAM_Application::moduleDisplayer( const QString& title ) +QString CAM_Application::moduleDisplayer( const QString& title_or_name ) { QString res; + if (title_or_name.isEmpty()) + return res; + for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end() && res.isEmpty(); ++it ) { - if ( (*it).title == title ) + if ( (*it).title == title_or_name || + (*it).name == title_or_name ) { res = (*it).displayer; + if (res.isEmpty()) + res = (*it).title; + } } - return res.isEmpty() ? title : res; + return res; } /*! diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 692e3a084..9ced671ae 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -5196,8 +5196,8 @@ void LightApp_Application::updateVisibilityState( DataObjectList& theList, if ( !obj || aStudy->isComponent( obj->entry() ) ) continue; - QString mod_name = moduleTitle(aStudy->componentDataType(obj->entry())); - LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(mod_name, false); + QString mname = aStudy->componentDataType(obj->entry()); + LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(mname, false); if ( aDisplayer ) { Qtx::VisibilityState anObjState = Qtx::UnpresentableState; if ( aDisplayer->canBeDisplayed( obj->entry(), theViewModel->getType() ) ) { diff --git a/src/LightApp/LightApp_Displayer.cxx b/src/LightApp/LightApp_Displayer.cxx index 636f72a4c..fbc9200fd 100644 --- a/src/LightApp/LightApp_Displayer.cxx +++ b/src/LightApp/LightApp_Displayer.cxx @@ -298,7 +298,9 @@ bool LightApp_Displayer::canBeDisplayed( const QString& entry ) const /*! \return displayer, corresponding to module - \param mod_name - name of module + \param mod_name - name or title of module. + \note It is better to use name (component data type) + in any case when you are not sure the title is not empty. \param load - is module has to be forced loaded */ LightApp_Displayer* LightApp_Displayer::FindDisplayer( const QString& mod_name, const bool load ) diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 3a10b55fb..1e0e2c734 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -460,7 +460,7 @@ QtxPopupMgr* LightApp_Module::popupMgr() QString oneAndNotActive = "( count( $component ) = 1 ) and ( not( activeModule in $component ) ) and ( not($displayer={'%3'}) )"; QString uniform = "true in $canBeDisplayed and %1 and ( activeModule = '%2' )"; - uniform = uniform.arg( oneAndNotActive ).arg( name() ).arg( LightApp_Application::moduleDisplayer( moduleName() ) ); + uniform = uniform.arg( oneAndNotActive ).arg( name() ).arg( LightApp_Application::moduleDisplayer( name() ) ); myPopupMgr->setRule( disp, /*QString( "( not isVisible ) and " ) + */ uniform, QtxPopupMgr::VisibleRule ); myPopupMgr->setRule( erase, /*QString( "( isVisible ) and " ) + */ uniform, QtxPopupMgr::VisibleRule ); myPopupMgr->setRule( dispOnly, uniform, QtxPopupMgr::VisibleRule ); diff --git a/src/LightApp/LightApp_Selection.cxx b/src/LightApp/LightApp_Selection.cxx index 493e311df..ec2f910ba 100644 --- a/src/LightApp/LightApp_Selection.cxx +++ b/src/LightApp/LightApp_Selection.cxx @@ -215,8 +215,8 @@ QVariant LightApp_Selection::parameter( const int idx, const QString& p ) const QString e = entry( idx ); if ( !e.isEmpty() ) { if ( p == "isVisible" ) { - QString mod_name = app->moduleTitle( myStudy->componentDataType( e ) ); - LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false ); + QString mname = myStudy->componentDataType( e ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, false ); // false in last parameter means that now we doesn't load module, if it isn't loaded bool vis = false; @@ -226,23 +226,17 @@ QVariant LightApp_Selection::parameter( const int idx, const QString& p ) const vis = LightApp_Displayer().IsDisplayed( e ); v = vis; } - - //else if ( p == "component" || p == "displayer" ) - // v = myStudy->componentDataType( e ); else if ( p == "component" ) v = myStudy->componentDataType( e ); - else if ( p == "displayer" ) { - QString mod_name = app->moduleTitle( myStudy->componentDataType( e ) ); - v = LightApp_Application::moduleDisplayer( mod_name ); - } - + else if ( p == "displayer" ) + v = LightApp_Application::moduleDisplayer( myStudy->componentDataType( e ) ); else if ( p == "isComponent" ) v = myStudy->isComponent( e ); else if ( p == "isReference" ) v = isReference( idx ); else if ( p == "canBeDisplayed" ) { - QString mod_name = app->moduleTitle( myStudy->componentDataType( e ) ); - LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, false ); + QString mname = myStudy->componentDataType( e ) ; + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, false ); // false in last parameter means that now we doesn't load module, if it isn't loaded if ( d ) diff --git a/src/LightApp/LightApp_ShowHideOp.cxx b/src/LightApp/LightApp_ShowHideOp.cxx index 3c313941d..a940de8fc 100644 --- a/src/LightApp/LightApp_ShowHideOp.cxx +++ b/src/LightApp/LightApp_ShowHideOp.cxx @@ -88,7 +88,7 @@ void LightApp_ShowHideOp::startOperation() QStringList::const_iterator anIt = comps.begin(), aLast = comps.end(); for( ; anIt!=aLast; anIt++ ) { - LightApp_Displayer* disp = LightApp_Displayer::FindDisplayer( app->moduleTitle( *anIt ), false ); + LightApp_Displayer* disp = LightApp_Displayer::FindDisplayer( *anIt, false ); if( disp ) disp->EraseAll( false, false, 0 ); } @@ -105,11 +105,11 @@ void LightApp_ShowHideOp::startOperation() QString mod_name; if( sel->count()>0 ) { - QString aStr = sel->parameter( 0, "displayer" ).toString(); - mod_name = app->moduleTitle( aStr ); + QString aStr = sel->parameter( 0, "displayer" ).toString(); + mod_name = aStr; } else if( app->activeModule() ) - mod_name = app->moduleTitle( app->activeModule()->name() ); + mod_name = app->activeModule()->name(); LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mod_name, true ); if( !d ) diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx index 60f31e8f1..2109b4399 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx @@ -418,7 +418,7 @@ void SALOMEGUI_Swig::Display( const char* theEntry ) LightApp_Application* anApp = getApplication(); LightApp_Study* aStudy = getActiveStudy(); if ( anApp && aStudy ) { - QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) ); + QString mname = aStudy->componentDataType( myEntry ); LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true ); if ( d ) { QStringList entries; @@ -459,11 +459,11 @@ void SALOMEGUI_Swig::DisplayOnly( const char* theEntry ) QStringList comps; aStudy->components( comps ); foreach( QString comp, comps ) { - LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( comp, false ); if ( d ) d->EraseAll( false, false, 0 ); } - QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) ); + QString mname = aStudy->componentDataType( myEntry ); LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true ); if ( d ) { QStringList entries; @@ -500,7 +500,7 @@ void SALOMEGUI_Swig::Erase( const char* theEntry ) LightApp_Application* anApp = getApplication(); LightApp_Study* aStudy = getActiveStudy(); if ( anApp && aStudy ) { - QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) ); + QString mname = aStudy->componentDataType( myEntry ); LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true ); if ( d ) { QStringList entries; @@ -538,7 +538,7 @@ void SALOMEGUI_Swig::DisplayAll() QStringList comps; aStudy->components( comps ); foreach( QString comp, comps ) { - LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( comp, true ); if ( d ) { QStringList entries; aStudy->children( aStudy->centry( comp ), entries ); @@ -569,7 +569,7 @@ void SALOMEGUI_Swig::EraseAll() QStringList comps; aStudy->components( comps ); foreach( QString comp, comps ) { - LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), false ); + LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( comp, false ); if ( d ) d->EraseAll( false, false, 0 ); } } diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 7204f3f74..f7f5573f8 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -813,6 +813,8 @@ void SalomeApp_Application::onOpenWith() Handle(SALOME_InteractiveObject) aIObj = aList.First(); QString aModuleName(aIObj->getComponentDataType()); QString aModuleTitle = moduleTitle(aModuleName); + if (aModuleTitle.isEmpty()) // no gui + aModuleTitle = moduleDisplayer(aModuleName); activateModule(aModuleTitle); QApplication::restoreOverrideCursor(); } @@ -1488,9 +1490,14 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePop if ( !entry.startsWith( tr( "SAVE_POINT_DEF_NAME" ) ) ) { QString aModuleName( aIObj->getComponentDataType() ); QString aModuleTitle = moduleTitle( aModuleName ); + if (aModuleTitle.isEmpty()) { + // use displayer module, if given + aModuleTitle = moduleDisplayer( aModuleName ); + } CAM_Module* currentModule = activeModule(); - if ( ( !currentModule || currentModule->moduleName() != aModuleTitle ) && !aModuleTitle.isEmpty() ) + if ( ( !currentModule || currentModule->moduleName() != aModuleTitle ) && !aModuleTitle.isEmpty() ) { thePopup->addAction( tr( "MEN_OPENWITH" ).arg( aModuleTitle ), this, SLOT( onOpenWith() ) ); + } } } diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 39bf6bf03..156c4882e 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -190,17 +190,16 @@ public: /* Define visibility state */ bool isComponent = dynamic_cast( suit_obj ) != 0; if ( suit_obj && !isComponent && myStudy->visibilityState( theID.c_str() ) == Qtx::UnpresentableState ) { - QString moduleTitle = ((CAM_Application*)myStudy->application())->moduleTitle(suit_obj->componentDataType()); - if (!moduleTitle.isEmpty()) { - LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(moduleTitle,false); - if (aDisplayer) { - if(aDisplayer->canBeDisplayed(theID.c_str())) { - myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState ); //hide the just added object - //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!"); - } - //else - //MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!"); + LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer + (suit_obj->componentDataType(),false); + if (aDisplayer) { + if (aDisplayer->canBeDisplayed(theID.c_str())) { + //hide the just added object + myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState ); + //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!"); } + //else + // MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!"); } } } // END: work with tree nodes structure @@ -323,17 +322,15 @@ public: /* Define visibility state */ bool isComponent = dynamic_cast( suit_obj ) != 0; if ( suit_obj && !isComponent ) { - QString moduleTitle = ((CAM_Application*)myStudy->application())->moduleTitle(suit_obj->componentDataType()); - if (!moduleTitle.isEmpty()) { - LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(moduleTitle,false); - if (aDisplayer) { - if(aDisplayer->canBeDisplayed(theID.c_str())) { - myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState ); - //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!"); - } - //else - //MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!"); + LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer + (suit_obj->componentDataType(),false); + if (aDisplayer) { + if (aDisplayer->canBeDisplayed(theID.c_str())) { + myStudy->setVisibilityState( theID.c_str(), Qtx::HiddenState ); + //MESSAGE("Object with entry : "<< theID <<" CAN be displayed !!!"); } + //else + // MESSAGE("Object with entry : "<< theID <<" CAN'T be displayed !!!"); } } break; -- 2.39.2