From 410b110422cbd5b97269a3aecec7c805bc83bf0d Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 4 Oct 2007 08:08:20 +0000 Subject: [PATCH] Improve SALOME Swig interface (use GUI module API instead of ModuleCatalog to get the component name/username) --- src/SALOME_SWIG/SALOMEGUI_Swig.cxx | 55 ++++++++++-------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx index d56fafe08..6574096a4 100644 --- a/src/SALOME_SWIG/SALOMEGUI_Swig.cxx +++ b/src/SALOME_SWIG/SALOMEGUI_Swig.cxx @@ -201,60 +201,41 @@ const char* SALOMEGUI_Swig::getActiveStudyName() return result.empty() ? NULL : result.c_str(); } -/*! - SALOMEGUI_Swig::getComponentName - Returns the name of the component by its user name. -*/ -class TGetModulCatalogEvent: public SALOME_Event { +class TGetComponentNameEvent: public SALOME_Event +{ public: - typedef CORBA::Object_var TResult; + typedef QString TResult; TResult myResult; - TGetModulCatalogEvent() : myResult(CORBA::Object::_nil()) {} - virtual void Execute() { - if (SalomeApp_Application* anApp = getApplication()) - myResult = anApp->namingService()->Resolve("/Kernel/ModulCatalog"); + QString myName; + bool myIsUserName; + TGetComponentNameEvent( const QString& name, bool isUserName ) + : myName( name ), myIsUserName( isUserName ) {} + virtual void Execute() + { + if ( SalomeApp_Application* app = getApplication() ) { + myResult = myIsUserName ? app->moduleTitle( myName ) : app->moduleName( myName ); + } } }; /*! + SALOMEGUI_Swig::getComponentName \return the name of the component by its user name. */ const char* SALOMEGUI_Swig::getComponentName( const char* componentUserName ) { - CORBA::Object_var anObject = ProcessEvent(new TGetModulCatalogEvent()); - if (!CORBA::is_nil(anObject)) { - SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue = - SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject ); - SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList(); - for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) { - CORBA::String_var aModuleName = aModules[ ind ].modulename; - CORBA::String_var aModuleUserName = aModules[ ind ].moduleusername; - if ( strcmp(componentUserName, aModuleUserName.in()) == 0 ) - return aModuleName._retn(); - } - } - return 0; + QString result = ProcessEvent( new TGetComponentNameEvent( componentUserName, false ) ); + return result.isEmpty() ? 0 : strdup( result.latin1() ); } /*! SALOMEGUI_Swig::getComponentUserName - Returns the user name of the component by its name. + \return the user name of the component by its name. */ const char* SALOMEGUI_Swig::getComponentUserName( const char* componentName ) { - CORBA::Object_var anObject = ProcessEvent(new TGetModulCatalogEvent()); - if (!CORBA::is_nil(anObject)) { - SALOME_ModuleCatalog::ModuleCatalog_var aCatalogue = - SALOME_ModuleCatalog::ModuleCatalog::_narrow( anObject ); - SALOME_ModuleCatalog::ListOfIAPP_Affich_var aModules = aCatalogue->GetComponentIconeList(); - for ( unsigned int ind = 0; ind < aModules->length(); ind++ ) { - CORBA::String_var aModuleName = aModules[ ind ].modulename; - CORBA::String_var aModuleUserName = aModules[ ind ].moduleusername; - if ( strcmp(componentName, aModuleName.in()) == 0 ) - return aModuleUserName._retn(); - } - } - return 0; + QString result = ProcessEvent( new TGetComponentNameEvent( componentName, true ) ); + return result.isEmpty() ? 0 : strdup( result.latin1() ); } /*! -- 2.39.2