1 // File: SalomeApp_Application.cxx
2 // Created: 10/22/2004 3:23:45 PM
3 // Author: Sergey LITONIN
4 // Copyright (C) CEA 2004
6 #include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
8 #include "SalomeApp_Application.h"
10 #include "SalomeApp_Study.h"
11 #include "SalomeApp_Module.h"
12 #include "SalomeApp_OBFilter.h"
13 #include "SalomeApp_DataModel.h"
14 #include "SalomeApp_DataObject.h"
15 #include "SalomeApp_EventFilter.h"
16 #include "SalomeApp_WidgetContainer.h"
18 #include "SalomeApp_AboutDlg.h"
19 #include "SalomeApp_ModuleDlg.h"
21 #include "SalomeApp_GLSelector.h"
22 #include "SalomeApp_OBSelector.h"
23 #include "SalomeApp_OCCSelector.h"
24 #include "SalomeApp_VTKSelector.h"
25 #include "SalomeApp_SelectionMgr.h"
27 #include <LogWindow.h>
29 #include <GLViewer_Viewer.h>
30 #include <GLViewer_ViewManager.h>
32 #include <Plot2d_ViewManager.h>
34 #include <OCCViewer_ViewManager.h>
35 #include <SOCC_ViewModel.h>
37 #include <SVTK_ViewModel.h>
38 #include <SVTK_ViewManager.h>
40 #include <STD_TabDesktop.h>
42 #include <SUIT_Tools.h>
43 #include <SUIT_Session.h>
45 #include <QtxToolBar.h>
46 #include <QtxDockAction.h>
48 #include <OB_Browser.h>
50 #include <PythonConsole_PyConsole.h>
52 #include <SUIT_FileDlg.h>
53 #include <SUIT_MessageBox.h>
54 #include <SUIT_ResourceMgr.h>
55 #include <SUIT_ActionOperation.h>
57 #include <Utils_ORB_INIT.hxx>
58 #include <Utils_SINGLETON.hxx>
59 #include <SALOME_ModuleCatalog_impl.hxx>
60 #include <SALOME_LifeCycleCORBA.hxx>
68 #include <qcombobox.h>
69 #include <qmessagebox.h>
70 #include <qapplication.h>
72 #include "SALOMEDS_StudyManager.hxx"
74 #define OBJECT_BROWSER_WIDTH 300
76 static const char* imageEmptyIcon[] = {
79 "....................",
80 "....................",
81 "....................",
82 "....................",
83 "....................",
84 "....................",
85 "....................",
86 "....................",
87 "....................",
88 "....................",
89 "....................",
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "...................."};
100 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
102 return new SalomeApp_Application();
106 Class : SalomeApp_Application
107 Description : Application containing SalomeApp module
110 SalomeApp_Application::SalomeApp_Application()
111 : CAM_Application( false )
113 STD_TabDesktop* desk = new STD_TabDesktop();
117 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
118 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
120 desktop()->setIcon( aLogo );
121 desktop()->setDockableMenuBar( true );
122 desktop()->setDockableStatusBar( false );
126 mySelMgr = new SalomeApp_SelectionMgr( this );
128 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
129 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
131 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
134 SalomeApp_Application::~SalomeApp_Application()
136 saveWindowsGeometry();
141 desktop()->saveGeometry( resourceMgr(), "desktop" );
142 resourceMgr()->save();
147 SalomeApp_EventFilter::Destroy();
150 void SalomeApp_Application::start()
153 desktop()->loadGeometry( resourceMgr(), "desktop" );
155 CAM_Application::start();
157 QAction* a = action( ViewWindowsId );
158 if ( a && a->inherits( "QtxDockAction" ) )
159 ((QtxDockAction*)a)->setAutoPlace( true );
161 SalomeApp_EventFilter::Init();
164 updateViewManagers();
169 QString SalomeApp_Application::applicationName() const
171 return tr( "APP_NAME" );
174 QString SalomeApp_Application::applicationVersion() const
176 static QString _app_version;
178 if ( _app_version.isEmpty() )
180 QString path( ::getenv( "GUI_ROOT_DIR" ) );
181 if ( !path.isEmpty() )
182 path += QDir::separator();
183 path += QString( "bin/salome/VERSION" );
186 if ( vf.open( IO_ReadOnly ) )
189 vf.readLine( line, 1024 );
192 if ( !line.isEmpty() )
194 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
195 line.remove( line.length() - 1, 1 );
197 int idx = line.findRev( ":" );
199 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
207 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
209 CAM_Module* mod = CAM_Application::loadModule( name );
212 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
213 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
214 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
219 bool SalomeApp_Application::activateModule( const QString& modName )
222 CAM_Module* prevMod = activeModule();
225 actName = prevMod->moduleName();
227 if ( actName == modName )
230 saveWindowsGeometry();
232 bool status = CAM_Application::activateModule( modName );
234 updateModuleActions();
240 updateViewManagers();
245 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
250 void SalomeApp_Application::createActions()
252 STD_Application::createActions();
254 SUIT_Desktop* desk = desktop();
255 SUIT_ResourceMgr* resMgr = resourceMgr();
258 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
259 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
260 0, desk, false, this, SLOT( onLoadScript() ) );
261 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
262 createMenu( LoadScriptId, fileMenu, 10, -1 );
264 // default icon for neutral point ('SALOME' module)
265 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
266 if ( defIcon.isNull() )
267 defIcon = QPixmap( imageEmptyIcon );
269 // default icon for any module
270 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
271 if ( modIcon.isNull() )
272 modIcon = QPixmap( imageEmptyIcon );
274 QToolBar* modTBar = new QtxToolBar( true, desk );
275 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
277 QActionGroup* modGroup = new QActionGroup( this );
278 modGroup->setExclusive( true );
279 modGroup->setUsesDropDown( true );
281 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
282 tr( "PRP_APP_MODULE" ), 0, desk, true );
284 myActions.insert( QString(), a );
286 QMap<QString, QString> iconMap;
287 moduleIconNames( iconMap );
289 const int iconSize = 20;
291 modGroup->addTo( modTBar );
292 modTBar->addSeparator();
295 modules( modList, false );
297 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
299 if ( (*it).isEmpty() )
303 if ( iconMap.contains( *it ) )
304 iconName = iconMap[*it];
306 QString modName = moduleName( *it );
308 QPixmap icon = resMgr->loadPixmap( modName, iconName );
312 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
314 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
318 myActions.insert( *it, a );
321 SUIT_Tools::simplifySeparators( modTBar );
325 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
326 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
327 createMenu( separator(), windowMenu, -1, 1 );
329 QMap<int, int> accelMap;
330 accelMap[NewGLViewId] = ALT+Key_G;
331 accelMap[NewPlot2dId] = ALT+Key_P;
332 accelMap[NewOCCViewId] = ALT+Key_O;
333 accelMap[NewVTKViewId] = ALT+Key_K;
335 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
337 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
338 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
339 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
340 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
341 createMenu( a, newWinMenu, -1 );
344 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
347 void SalomeApp_Application::onModuleActivation( QAction* a )
352 QString modName = a->menuText();
353 if ( modName == tr( "APP_NAME" ) )
354 modName = QString::null;
356 // Force user to create/open a study before module activation
357 QMap<QString, QString> iconMap;
358 moduleIconNames( iconMap );
359 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
361 bool cancelled = false;
362 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
363 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
364 int res = aDlg.exec();
378 putInfo( tr("INF_CANCELLED") );
379 myActions[QString()]->setOn( true );
385 activateModule( modName );
388 QString SalomeApp_Application::defaultModule() const
390 QStringList aModuleNames;
391 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
392 // If there's the one and only module --> activate it automatically
393 // TODO: Possible improvement - default module can be taken from preferences
394 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
397 void SalomeApp_Application::onNewWindow()
399 const QObject* obj = sender();
400 if ( !obj || !obj->inherits( "QAction" ) )
404 int id = actionId( (QAction*)obj );
408 type = GLViewer_Viewer::Type();
411 type = Plot2d_Viewer::Type();
414 type = OCCViewer_Viewer::Type();
417 type = VTKViewer_Viewer::Type();
421 if ( !type.isEmpty() )
422 createViewManager( type );
425 //=======================================================================
427 // Purpose : SLOT. Create new document
428 //=======================================================================
429 void SalomeApp_Application::onNewDoc()
431 SUIT_Study* study = activeStudy();
433 saveWindowsGeometry();
435 CAM_Application::onNewDoc();
437 if ( !study ) // new study will be create in THIS application
440 updateViewManagers();
444 //=======================================================================
446 // Purpose : SLOT. Open new document
447 //=======================================================================
448 void SalomeApp_Application::onOpenDoc()
450 SUIT_Study* study = activeStudy();
451 saveWindowsGeometry();
453 CAM_Application::onOpenDoc();
455 if ( !study ) // new study will be create in THIS application
458 updateViewManagers();
462 void SalomeApp_Application::onSelection()
464 onSelectionChanged();
466 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
467 ((SalomeApp_Module*)activeModule())->selectionChanged();
470 void SalomeApp_Application::onSelectionChanged()
474 void SalomeApp_Application::onAboutRefresh()
476 SalomeApp_DataModel* dm = 0;
477 if ( activeModule() )
479 CAM_DataModel* camDM = activeModule()->dataModel();
480 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
481 dm = (SalomeApp_DataModel*)camDM;
488 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
490 CAM_Application::setActiveStudy( study );
495 //=======================================================================
496 // name : createNewStudy
497 // Purpose : Create new study
498 //=======================================================================
499 SUIT_Study* SalomeApp_Application::createNewStudy()
501 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
503 // Set up processing of major study-related events
504 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
505 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
506 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
507 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
512 //=======================================================================
513 // name : createNewStudy
514 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
515 //=======================================================================
516 void SalomeApp_Application::updateCommandsStatus()
518 CAM_Application::updateCommandsStatus();
520 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
522 QAction* a = action( id );
524 a->setEnabled( activeStudy() );
528 QAction* a = action( LoadScriptId );
530 a->setEnabled( activeStudy() );
533 //=======================================================================
534 // name : onHelpAbout
535 // Purpose : SLOT. Display "About" message box
536 //=======================================================================
537 void SalomeApp_Application::onHelpAbout()
539 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
544 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
551 if ( !activeStudy() )
554 sId = activeStudy()->id();
557 if ( myWindows.contains( flag ) )
558 wid = myWindows[flag]->widget( sId );
563 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
571 if ( !activeStudy() )
574 sId = activeStudy()->id();
577 if ( !myWindows.contains( flag ) )
579 QMap<int, int> winMap;
580 currentWindows( winMap );
582 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
583 if ( winMap.contains( flag ) )
584 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
586 myWindows[flag]->setResizeEnabled( true );
587 myWindows[flag]->setCloseMode( QDockWindow::Always );
588 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
591 myWindows[flag]->insert( sId, wid );
593 setWindowShown( flag, !myWindows[flag]->isEmpty() );
596 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
598 if ( !myWindows.contains( flag ) )
604 if ( !activeStudy() )
607 sId = activeStudy()->id();
610 QWidget* wid = myWindows[flag]->widget( sId );
611 myWindows[flag]->remove( sId );
614 setWindowShown( flag, !myWindows[flag]->isEmpty() );
617 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
619 QWidget* wid = window( flag, studyId );
621 addWindow( wid = createWindow( flag ), flag, studyId );
626 bool SalomeApp_Application::isWindowVisible( const int type ) const
629 if ( myWindows.contains( type ) )
631 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
632 res = desk && desk->appropriate( myWindows[type] );
637 void SalomeApp_Application::setWindowShown( const int type, const bool on )
639 if ( !desktop() || !myWindows.contains( type ) )
642 QDockWindow* dw = myWindows[type];
643 desktop()->setAppropriate( dw, on );
644 on ? dw->show() : dw->hide();
647 OB_Browser* SalomeApp_Application::objectBrowser()
650 QWidget* wid = getWindow( WT_ObjectBrowser );
651 if ( wid->inherits( "OB_Browser" ) )
652 ob = (OB_Browser*)wid;
656 LogWindow* SalomeApp_Application::logWindow()
659 QWidget* wid = getWindow( WT_LogWindow );
660 if ( wid->inherits( "LogWindow" ) )
661 lw = (LogWindow*)wid;
665 PythonConsole* SalomeApp_Application::pythonConsole()
667 PythonConsole* console = 0;
668 QWidget* wid = getWindow( WT_PyConsole );
669 if ( wid->inherits( "PythonConsole" ) )
670 console = (PythonConsole*)wid;
674 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
676 SUIT_ViewManager* aVM = viewManager( vmType );
677 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
678 if ( anActiveVM && anActiveVM->getType() == vmType )
682 if ( !aVM->getActiveView() )
686 aVM = createViewManager( vmType );
690 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
692 SUIT_ViewManager* viewMgr = 0;
693 if ( vmType == GLViewer_Viewer::Type() )
695 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
696 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
698 else if ( vmType == Plot2d_Viewer::Type() )
699 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
700 else if ( vmType == OCCViewer_Viewer::Type() )
702 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
703 viewMgr->setViewModel( new SOCC_Viewer() );// custom view model, which extends SALOME_View interface
704 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
706 else if ( vmType == SVTK_Viewer::Type() )
708 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
709 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
715 addViewManager( viewMgr );
716 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
718 if ( viewWin && desktop() )
719 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
721 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
722 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
727 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
729 removeViewManager( theVM );
732 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
734 SUIT_DataObject* aRoot = 0;
735 if ( theStudy && theStudy->root() )
737 aRoot = theStudy->root();
738 //aRoot->setName( tr( "DATA_MODELS" ) );
740 if ( objectBrowser() != 0 )
741 objectBrowser()->setRootObject( aRoot );
743 activateModule( defaultModule() );
746 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
748 SUIT_DataObject* aRoot = 0;
749 if ( theStudy && theStudy->root() )
751 aRoot = theStudy->root();
754 if ( objectBrowser() != 0 ) {
755 objectBrowser()->setRootObject( aRoot );
760 activateModule( defaultModule() );
765 void SalomeApp_Application::onStudySaved( SUIT_Study* )
770 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
774 activateModule( "" );
776 saveWindowsGeometry();
779 void SalomeApp_Application::onLoadScript( )
781 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
782 if ( !appStudy ) return;
783 _PTR(Study) aStudy = appStudy->studyDS();
785 if ( aStudy->GetProperties()->IsLocked() ) {
786 SUIT_MessageBox::warn1 ( desktop(),
787 QObject::tr("WRN_WARNING"),
788 QObject::tr("WRN_STUDY_LOCKED"),
789 QObject::tr("BUT_OK") );
793 QStringList filtersList;
794 filtersList.append(tr("PYTHON_FILES_FILTER"));
795 filtersList.append(tr("ALL_FILES_FILTER"));
797 QString aFile = SUIT_FileDlg::getFileName(desktop(), "", filtersList, tr("TOT_DESK_FILE_LOAD_SCRIPT"), true, false);
798 if(!aFile.isEmpty()) {
799 QString command = QString("execfile(\"%1\")").arg(aFile);
801 PythonConsole* pyConsole = pythonConsole();
804 pyConsole->exec(command);
808 QString SalomeApp_Application::getFileFilter() const
813 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
815 CAM_Application::beforeCloseDoc( s );
817 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
818 removeWindow( itr.key(), s->id() );
821 void SalomeApp_Application::updateActions()
823 updateCommandsStatus();
826 QWidget* SalomeApp_Application::createWindow( const int flag )
830 if ( flag == WT_ObjectBrowser )
832 OB_Browser* ob = new OB_Browser( desktop() );
833 ob->setAutoUpdate( true );
834 ob->setAutoOpenLevel( 1 );
835 ob->setCaption( tr( "OBJECT_BROWSER" ) );
836 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
837 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
839 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
840 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
841 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
844 new SalomeApp_OBSelector( ob, mySelMgr );
848 connect( ob, SIGNAL( aboutRefresh() ), this, SLOT( onAboutRefresh() ) );
849 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
851 else if ( flag == WT_PyConsole )
853 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
854 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
857 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
859 else if ( flag == WT_LogWindow )
861 LogWindow* logWin = new LogWindow( desktop() );
862 logWin->setCaption( tr( "LOG_WINDOW" ) );
865 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
871 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
873 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
874 aMap.insert( WT_PyConsole, Qt::DockBottom );
875 aMap.insert( WT_LogWindow, Qt::DockBottom );
878 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
882 void SalomeApp_Application::afterCloseDoc()
886 CAM_Application::afterCloseDoc();
889 CORBA::ORB_var SalomeApp_Application::orb()
891 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
892 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
896 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
898 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
902 SALOME_NamingService* SalomeApp_Application::namingService()
904 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
908 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
910 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
914 QString SalomeApp_Application::defaultEngineIOR()
916 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
918 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
919 if ( !CORBA::is_nil( anEngine ) )
920 anIOR = orb()->object_to_string( anEngine );
924 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
928 SUIT_ResourceMgr* resMgr = resourceMgr();
933 modules( modList, false );
935 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
937 QString modName = *it;
938 QString modIntr = moduleName( modName );
939 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
941 if ( modIcon.isEmpty() )
944 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
945 modIcon += QString( ".png" );
947 iconMap.insert( modName, modIcon );
951 void SalomeApp_Application::updateModuleActions()
954 if ( activeModule() )
955 modName = activeModule()->moduleName();
957 if ( myActions.contains( modName ) )
958 myActions[modName]->setOn( true );
961 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
964 if ( !activeStudy() )
967 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
968 ((SalomeApp_Module*)activeModule())->windows( winMap );
970 defaultWindows( winMap );
973 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
976 if ( !activeStudy() )
979 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
980 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
982 defaultViewManagers( lst );
985 void SalomeApp_Application::updateWindows()
987 QMap<int, int> winMap;
988 currentWindows( winMap );
990 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
991 getWindow( it.key() );
993 loadWindowsGeometry();
995 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
996 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
999 void SalomeApp_Application::updateViewManagers()
1002 currentViewManagers( lst );
1004 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1005 getViewManager( *it, true );
1008 void SalomeApp_Application::loadWindowsGeometry()
1010 QtxDockAction* dockMgr = 0;
1012 QAction* a = action( ViewWindowsId );
1013 if ( a && a->inherits( "QtxDockAction" ) )
1014 dockMgr = (QtxDockAction*)a;
1020 if ( activeModule() )
1021 modName = moduleLibrary( activeModule()->moduleName(), false );
1023 QString section = QString( "windows_geometry" );
1024 if ( !modName.isEmpty() )
1025 section += QString( "." ) + modName;
1027 dockMgr->loadGeometry( resourceMgr(), section, false );
1028 dockMgr->restoreGeometry();
1031 void SalomeApp_Application::saveWindowsGeometry()
1033 QtxDockAction* dockMgr = 0;
1035 QAction* a = action( ViewWindowsId );
1036 if ( a && a->inherits( "QtxDockAction" ) )
1037 dockMgr = (QtxDockAction*)a;
1043 if ( activeModule() )
1044 modName = moduleLibrary( activeModule()->moduleName(), false );
1046 QString section = QString( "windows_geometry" );
1047 if ( !modName.isEmpty() )
1048 section += QString( "." ) + modName;
1050 dockMgr->storeGeometry();
1051 dockMgr->saveGeometry( resourceMgr(), section, false );
1054 void SalomeApp_Application::activateWindows()
1056 if ( activeStudy() )
1058 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1059 itr.data()->activate( activeStudy()->id() );