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"
20 #include "SalomeApp_PreferencesDlg.h"
22 #include "SalomeApp_GLSelector.h"
23 #include "SalomeApp_OBSelector.h"
24 #include "SalomeApp_OCCSelector.h"
25 #include "SalomeApp_VTKSelector.h"
26 #include "SalomeApp_SelectionMgr.h"
28 #include <LogWindow.h>
30 #include <GLViewer_Viewer.h>
31 #include <GLViewer_ViewManager.h>
33 #include <Plot2d_ViewManager.h>
34 #include <SPlot2d_ViewModel.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <SOCC_ViewModel.h>
39 #include <SVTK_ViewModel.h>
40 #include <SVTK_ViewManager.h>
42 #include <STD_TabDesktop.h>
44 #include <SUIT_Tools.h>
45 #include <SUIT_Session.h>
47 #include <QtxToolBar.h>
48 #include <QtxDockAction.h>
50 #include <OB_Browser.h>
52 #include <PythonConsole_PyConsole.h>
54 #include <SUIT_FileDlg.h>
55 #include <SUIT_MessageBox.h>
56 #include <SUIT_ResourceMgr.h>
57 #include <SUIT_ActionOperation.h>
59 #include <Utils_ORB_INIT.hxx>
60 #include <Utils_SINGLETON.hxx>
61 #include <SALOME_ModuleCatalog_impl.hxx>
62 #include <SALOME_LifeCycleCORBA.hxx>
70 #include <qcombobox.h>
71 #include <qmessagebox.h>
72 #include <qapplication.h>
74 #include "SALOMEDS_StudyManager.hxx"
76 #define OBJECT_BROWSER_WIDTH 300
78 static const char* imageEmptyIcon[] = {
81 "....................",
82 "....................",
83 "....................",
84 "....................",
85 "....................",
86 "....................",
87 "....................",
88 "....................",
89 "....................",
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "...................."};
102 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
104 return new SalomeApp_Application();
108 Class : SalomeApp_Application
109 Description : Application containing SalomeApp module
112 SalomeApp_Application::SalomeApp_Application()
113 : CAM_Application( false ),
116 STD_TabDesktop* desk = new STD_TabDesktop();
120 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
121 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
123 desktop()->setIcon( aLogo );
124 desktop()->setDockableMenuBar( true );
125 desktop()->setDockableStatusBar( false );
129 mySelMgr = new SalomeApp_SelectionMgr( this );
131 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
132 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
134 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
137 SalomeApp_Application::~SalomeApp_Application()
139 saveWindowsGeometry();
144 desktop()->saveGeometry( resourceMgr(), "desktop" );
145 resourceMgr()->save();
150 SalomeApp_EventFilter::Destroy();
153 void SalomeApp_Application::start()
156 desktop()->loadGeometry( resourceMgr(), "desktop" );
158 CAM_Application::start();
160 QAction* a = action( ViewWindowsId );
161 if ( a && a->inherits( "QtxDockAction" ) )
162 ((QtxDockAction*)a)->setAutoPlace( true );
164 SalomeApp_EventFilter::Init();
167 updateViewManagers();
172 QString SalomeApp_Application::applicationName() const
174 return tr( "APP_NAME" );
177 QString SalomeApp_Application::applicationVersion() const
179 static QString _app_version;
181 if ( _app_version.isEmpty() )
183 QString path( ::getenv( "GUI_ROOT_DIR" ) );
184 if ( !path.isEmpty() )
185 path += QDir::separator();
186 path += QString( "bin/salome/VERSION" );
189 if ( vf.open( IO_ReadOnly ) )
192 vf.readLine( line, 1024 );
195 if ( !line.isEmpty() )
197 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
198 line.remove( line.length() - 1, 1 );
200 int idx = line.findRev( ":" );
202 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
210 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
212 CAM_Module* mod = CAM_Application::loadModule( name );
215 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
216 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
217 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
222 bool SalomeApp_Application::activateModule( const QString& modName )
225 CAM_Module* prevMod = activeModule();
228 actName = prevMod->moduleName();
230 if ( actName == modName )
233 saveWindowsGeometry();
235 bool status = CAM_Application::activateModule( modName );
237 updateModuleActions();
243 updateViewManagers();
248 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
253 void SalomeApp_Application::createActions()
255 STD_Application::createActions();
257 SUIT_Desktop* desk = desktop();
258 SUIT_ResourceMgr* resMgr = resourceMgr();
261 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
262 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
263 0, desk, false, this, SLOT( onLoadScript() ) );
264 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
265 createMenu( LoadScriptId, fileMenu, 10, -1 );
267 // default icon for neutral point ('SALOME' module)
268 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
269 if ( defIcon.isNull() )
270 defIcon = QPixmap( imageEmptyIcon );
272 // default icon for any module
273 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
274 if ( modIcon.isNull() )
275 modIcon = QPixmap( imageEmptyIcon );
277 QToolBar* modTBar = new QtxToolBar( true, desk );
278 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
280 QActionGroup* modGroup = new QActionGroup( this );
281 modGroup->setExclusive( true );
282 modGroup->setUsesDropDown( true );
284 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
285 tr( "PRP_APP_MODULE" ), 0, desk, true );
287 myActions.insert( QString(), a );
289 QMap<QString, QString> iconMap;
290 moduleIconNames( iconMap );
292 const int iconSize = 20;
294 modGroup->addTo( modTBar );
295 modTBar->addSeparator();
298 modules( modList, false );
300 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
302 if ( (*it).isEmpty() )
306 if ( iconMap.contains( *it ) )
307 iconName = iconMap[*it];
309 QString modName = moduleName( *it );
311 QPixmap icon = resMgr->loadPixmap( modName, iconName );
315 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
317 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
321 myActions.insert( *it, a );
324 SUIT_Tools::simplifySeparators( modTBar );
328 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
329 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
330 createMenu( separator(), windowMenu, -1, 1 );
332 QMap<int, int> accelMap;
333 accelMap[NewGLViewId] = ALT+Key_G;
334 accelMap[NewPlot2dId] = ALT+Key_P;
335 accelMap[NewOCCViewId] = ALT+Key_O;
336 accelMap[NewVTKViewId] = ALT+Key_K;
338 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
340 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
341 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
342 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
343 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
344 createMenu( a, newWinMenu, -1 );
347 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
350 void SalomeApp_Application::onModuleActivation( QAction* a )
355 QString modName = a->menuText();
356 if ( modName == tr( "APP_NAME" ) )
357 modName = QString::null;
359 // Force user to create/open a study before module activation
360 QMap<QString, QString> iconMap;
361 moduleIconNames( iconMap );
362 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
364 bool cancelled = false;
365 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
366 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
367 int res = aDlg.exec();
381 putInfo( tr("INF_CANCELLED") );
382 myActions[QString()]->setOn( true );
388 activateModule( modName );
391 QString SalomeApp_Application::defaultModule() const
393 QStringList aModuleNames;
394 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
395 // If there's the one and only module --> activate it automatically
396 // TODO: Possible improvement - default module can be taken from preferences
397 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
400 void SalomeApp_Application::onNewWindow()
402 const QObject* obj = sender();
403 if ( !obj || !obj->inherits( "QAction" ) )
407 int id = actionId( (QAction*)obj );
411 type = GLViewer_Viewer::Type();
414 type = Plot2d_Viewer::Type();
417 type = OCCViewer_Viewer::Type();
420 type = VTKViewer_Viewer::Type();
424 if ( !type.isEmpty() )
425 createViewManager( type );
428 //=======================================================================
430 // Purpose : SLOT. Create new document
431 //=======================================================================
432 void SalomeApp_Application::onNewDoc()
434 SUIT_Study* study = activeStudy();
436 saveWindowsGeometry();
438 CAM_Application::onNewDoc();
440 if ( !study ) // new study will be create in THIS application
443 updateViewManagers();
447 //=======================================================================
449 // Purpose : SLOT. Open new document
450 //=======================================================================
451 void SalomeApp_Application::onOpenDoc()
453 SUIT_Study* study = activeStudy();
454 saveWindowsGeometry();
456 CAM_Application::onOpenDoc();
458 if ( !study ) // new study will be create in THIS application
461 updateViewManagers();
465 void SalomeApp_Application::onSelection()
467 onSelectionChanged();
469 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
470 ((SalomeApp_Module*)activeModule())->selectionChanged();
473 void SalomeApp_Application::onSelectionChanged()
477 void SalomeApp_Application::onAboutRefresh()
479 SalomeApp_DataModel* dm = 0;
480 if ( activeModule() )
482 CAM_DataModel* camDM = activeModule()->dataModel();
483 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
484 dm = (SalomeApp_DataModel*)camDM;
491 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
493 CAM_Application::setActiveStudy( study );
498 //=======================================================================
499 // name : createNewStudy
500 // Purpose : Create new study
501 //=======================================================================
502 SUIT_Study* SalomeApp_Application::createNewStudy()
504 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
506 // Set up processing of major study-related events
507 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
508 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
509 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
510 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
515 //=======================================================================
516 // name : createNewStudy
517 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
518 //=======================================================================
519 void SalomeApp_Application::updateCommandsStatus()
521 CAM_Application::updateCommandsStatus();
523 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
525 QAction* a = action( id );
527 a->setEnabled( activeStudy() );
531 QAction* a = action( LoadScriptId );
533 a->setEnabled( activeStudy() );
536 //=======================================================================
537 // name : onHelpAbout
538 // Purpose : SLOT. Display "About" message box
539 //=======================================================================
540 void SalomeApp_Application::onHelpAbout()
542 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
547 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
554 if ( !activeStudy() )
557 sId = activeStudy()->id();
560 if ( myWindows.contains( flag ) )
561 wid = myWindows[flag]->widget( sId );
566 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
574 if ( !activeStudy() )
577 sId = activeStudy()->id();
580 if ( !myWindows.contains( flag ) )
582 QMap<int, int> winMap;
583 currentWindows( winMap );
585 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
586 if ( winMap.contains( flag ) )
587 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
589 myWindows[flag]->setResizeEnabled( true );
590 myWindows[flag]->setCloseMode( QDockWindow::Always );
591 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
594 myWindows[flag]->insert( sId, wid );
596 setWindowShown( flag, !myWindows[flag]->isEmpty() );
599 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
601 if ( !myWindows.contains( flag ) )
607 if ( !activeStudy() )
610 sId = activeStudy()->id();
613 QWidget* wid = myWindows[flag]->widget( sId );
614 myWindows[flag]->remove( sId );
617 setWindowShown( flag, !myWindows[flag]->isEmpty() );
620 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
622 QWidget* wid = window( flag, studyId );
624 addWindow( wid = createWindow( flag ), flag, studyId );
629 bool SalomeApp_Application::isWindowVisible( const int type ) const
632 if ( myWindows.contains( type ) )
634 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
635 res = desk && desk->appropriate( myWindows[type] );
640 void SalomeApp_Application::setWindowShown( const int type, const bool on )
642 if ( !desktop() || !myWindows.contains( type ) )
645 QDockWindow* dw = myWindows[type];
646 desktop()->setAppropriate( dw, on );
647 on ? dw->show() : dw->hide();
650 OB_Browser* SalomeApp_Application::objectBrowser()
653 QWidget* wid = getWindow( WT_ObjectBrowser );
654 if ( wid->inherits( "OB_Browser" ) )
655 ob = (OB_Browser*)wid;
659 LogWindow* SalomeApp_Application::logWindow()
662 QWidget* wid = getWindow( WT_LogWindow );
663 if ( wid->inherits( "LogWindow" ) )
664 lw = (LogWindow*)wid;
668 PythonConsole* SalomeApp_Application::pythonConsole()
670 PythonConsole* console = 0;
671 QWidget* wid = getWindow( WT_PyConsole );
672 if ( wid->inherits( "PythonConsole" ) )
673 console = (PythonConsole*)wid;
677 QtxResourceEdit* SalomeApp_Application::resourceEdit() const
681 QtxResourceEdit* edit = 0;
684 SalomeApp_Application* that = (SalomeApp_Application*)this;
685 that->myPrefDlg = new SalomeApp_PreferencesDlg( that->desktop() );
687 edit = myPrefDlg->resourceEdit();
690 modules( modList, false );
691 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
693 int id = edit->addItem( *it );
694 edit->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
698 edit = myPrefDlg->resourceEdit();
702 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
704 SUIT_ViewManager* aVM = viewManager( vmType );
705 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
706 if ( anActiveVM && anActiveVM->getType() == vmType )
710 if ( !aVM->getActiveView() )
714 aVM = createViewManager( vmType );
718 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
720 SUIT_ViewManager* viewMgr = 0;
721 if ( vmType == GLViewer_Viewer::Type() )
723 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
724 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
726 else if ( vmType == Plot2d_Viewer::Type() )
728 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
729 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
731 else if ( vmType == OCCViewer_Viewer::Type() )
733 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
734 viewMgr->setViewModel( new SOCC_Viewer() );// custom view model, which extends SALOME_View interface
735 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
737 else if ( vmType == SVTK_Viewer::Type() )
739 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
740 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
746 addViewManager( viewMgr );
747 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
749 if ( viewWin && desktop() )
750 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
752 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
753 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
758 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
760 removeViewManager( theVM );
763 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
765 SUIT_DataObject* aRoot = 0;
766 if ( theStudy && theStudy->root() )
768 aRoot = theStudy->root();
769 //aRoot->setName( tr( "DATA_MODELS" ) );
771 if ( objectBrowser() != 0 )
772 objectBrowser()->setRootObject( aRoot );
774 activateModule( defaultModule() );
779 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
781 SUIT_DataObject* aRoot = 0;
782 if ( theStudy && theStudy->root() )
784 aRoot = theStudy->root();
787 if ( objectBrowser() != 0 ) {
788 objectBrowser()->setRootObject( aRoot );
791 activateModule( defaultModule() );
798 void SalomeApp_Application::onStudySaved( SUIT_Study* )
803 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
807 activateModule( "" );
809 saveWindowsGeometry();
812 void SalomeApp_Application::onLoadScript( )
814 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
815 if ( !appStudy ) return;
816 _PTR(Study) aStudy = appStudy->studyDS();
818 if ( aStudy->GetProperties()->IsLocked() ) {
819 SUIT_MessageBox::warn1 ( desktop(),
820 QObject::tr("WRN_WARNING"),
821 QObject::tr("WRN_STUDY_LOCKED"),
822 QObject::tr("BUT_OK") );
826 QStringList filtersList;
827 filtersList.append(tr("PYTHON_FILES_FILTER"));
828 filtersList.append(tr("ALL_FILES_FILTER"));
830 QString aFile = SUIT_FileDlg::getFileName(desktop(), "", filtersList, tr("TOT_DESK_FILE_LOAD_SCRIPT"), true, false);
831 if(!aFile.isEmpty()) {
832 QString command = QString("execfile(\"%1\")").arg(aFile);
834 PythonConsole* pyConsole = pythonConsole();
837 pyConsole->exec(command);
841 QString SalomeApp_Application::getFileFilter() const
846 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
848 CAM_Application::beforeCloseDoc( s );
850 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
851 removeWindow( itr.key(), s->id() );
854 void SalomeApp_Application::updateActions()
856 updateCommandsStatus();
859 QWidget* SalomeApp_Application::createWindow( const int flag )
863 if ( flag == WT_ObjectBrowser )
865 OB_Browser* ob = new OB_Browser( desktop() );
866 ob->setAutoUpdate( true );
867 ob->setAutoOpenLevel( 1 );
868 ob->setCaption( tr( "OBJECT_BROWSER" ) );
869 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
870 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
872 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
873 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
874 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
877 new SalomeApp_OBSelector( ob, mySelMgr );
881 connect( ob, SIGNAL( aboutRefresh() ), this, SLOT( onAboutRefresh() ) );
882 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
884 else if ( flag == WT_PyConsole )
886 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
887 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
890 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
892 else if ( flag == WT_LogWindow )
894 LogWindow* logWin = new LogWindow( desktop() );
895 logWin->setCaption( tr( "LOG_WINDOW" ) );
898 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
904 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
906 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
907 aMap.insert( WT_PyConsole, Qt::DockBottom );
908 aMap.insert( WT_LogWindow, Qt::DockBottom );
911 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
915 void SalomeApp_Application::afterCloseDoc()
919 CAM_Application::afterCloseDoc();
922 CORBA::ORB_var SalomeApp_Application::orb()
924 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
925 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
929 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
931 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
935 SALOME_NamingService* SalomeApp_Application::namingService()
937 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
941 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
943 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
947 QString SalomeApp_Application::defaultEngineIOR()
949 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
951 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
952 if ( !CORBA::is_nil( anEngine ) )
953 anIOR = orb()->object_to_string( anEngine );
957 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
961 SUIT_ResourceMgr* resMgr = resourceMgr();
966 modules( modList, false );
968 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
970 QString modName = *it;
971 QString modIntr = moduleName( modName );
972 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
974 if ( modIcon.isEmpty() )
977 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
978 modIcon += QString( ".png" );
980 iconMap.insert( modName, modIcon );
984 void SalomeApp_Application::updateModuleActions()
987 if ( activeModule() )
988 modName = activeModule()->moduleName();
990 if ( myActions.contains( modName ) )
991 myActions[modName]->setOn( true );
994 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
997 if ( !activeStudy() )
1000 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1001 ((SalomeApp_Module*)activeModule())->windows( winMap );
1003 defaultWindows( winMap );
1006 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1009 if ( !activeStudy() )
1012 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1013 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1015 defaultViewManagers( lst );
1018 void SalomeApp_Application::updateWindows()
1020 QMap<int, int> winMap;
1021 currentWindows( winMap );
1023 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1024 getWindow( it.key() );
1026 loadWindowsGeometry();
1028 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1029 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1032 void SalomeApp_Application::updateViewManagers()
1035 currentViewManagers( lst );
1037 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1038 getViewManager( *it, true );
1041 void SalomeApp_Application::loadWindowsGeometry()
1043 QtxDockAction* dockMgr = 0;
1045 QAction* a = action( ViewWindowsId );
1046 if ( a && a->inherits( "QtxDockAction" ) )
1047 dockMgr = (QtxDockAction*)a;
1053 if ( activeModule() )
1054 modName = moduleLibrary( activeModule()->moduleName(), false );
1056 QString section = QString( "windows_geometry" );
1057 if ( !modName.isEmpty() )
1058 section += QString( "." ) + modName;
1060 dockMgr->loadGeometry( resourceMgr(), section, false );
1061 dockMgr->restoreGeometry();
1064 void SalomeApp_Application::saveWindowsGeometry()
1066 QtxDockAction* dockMgr = 0;
1068 QAction* a = action( ViewWindowsId );
1069 if ( a && a->inherits( "QtxDockAction" ) )
1070 dockMgr = (QtxDockAction*)a;
1076 if ( activeModule() )
1077 modName = moduleLibrary( activeModule()->moduleName(), false );
1079 QString section = QString( "windows_geometry" );
1080 if ( !modName.isEmpty() )
1081 section += QString( "." ) + modName;
1083 dockMgr->storeGeometry();
1084 dockMgr->saveGeometry( resourceMgr(), section, false );
1087 void SalomeApp_Application::activateWindows()
1089 if ( activeStudy() )
1091 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1092 itr.data()->activate( activeStudy()->id() );