Salome HOME
Initial version
[modules/gui.git] / src / SalomeApp / SalomeApp_Application.cxx
1 // File:      SalomeApp_Application.cxx
2 // Created:   10/22/2004 3:23:45 PM
3 // Author:    Sergey LITONIN
4 // Copyright (C) CEA 2004
5
6 #include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
7
8 #include "SalomeApp_Application.h"
9
10 #include "SalomeApp_Study.h"
11 #include "SalomeApp_Module.h"
12 #include "SalomeApp_GLSelector.h"
13 #include "SalomeApp_OBSelector.h"
14 #include "SalomeApp_OCCSelector.h"
15 #include "SalomeApp_VTKSelector.h"
16 #include "SalomeApp_EventFilter.h"
17 #include "SalomeApp_SelectionMgr.h"
18 #include "SalomeApp_EventFilter.h"
19 #include "SalomeApp_WidgetContainer.h"
20 #include "SalomeApp_ModuleDlg.h"
21
22 #include <LogWindow.h>
23
24 #include <GLViewer_Viewer.h>
25 #include <GLViewer_ViewManager.h>
26
27 #include <Plot2d_ViewManager.h>
28
29 #include <OCCViewer_ViewManager.h>
30 #include <SOCC_ViewModel.h>
31
32 #include "SVTK_ViewManager.h"
33 #include "SVTK_ViewModel.h"
34
35 #include <STD_TabDesktop.h>
36
37 #include <SUIT_Tools.h>
38 #include <SUIT_Session.h>
39
40 #include <QtxDockAction.h>
41
42 #include <OB_Browser.h>
43
44 #include <PythonConsole_PyConsole.h>
45
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_ActionOperation.h>
49
50 #include <Utils_ORB_INIT.hxx>
51 #include <Utils_SINGLETON.hxx>
52 #include <SALOME_ModuleCatalog_impl.hxx>
53
54 #include <qmap.h>
55 #include <qlabel.h>
56 #include <qimage.h>
57 #include <qaction.h>
58 #include <qmenubar.h>
59 #include <qcombobox.h>
60 #include <qmessagebox.h>
61 #include <qapplication.h>
62
63 #include "SALOMEDS_StudyManager.hxx"
64
65 #define OBJECT_BROWSER_WIDTH 300
66
67 static const char* imageEmptyIcon[] = {
68 "20 20 1 1",
69 ".      c None",
70 "....................",
71 "....................",
72 "....................",
73 "....................",
74 "....................",
75 "....................",
76 "....................",
77 "....................",
78 "....................",
79 "....................",
80 "....................",
81 "....................",
82 "....................",
83 "....................",
84 "....................",
85 "....................",
86 "....................",
87 "....................",
88 "....................",
89 "...................."};
90
91 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
92 {
93   return new SalomeApp_Application();
94 }
95
96 /*
97   Class       : SalomeApp_Application
98   Description : Application containing SalomeApp module
99 */
100
101 SalomeApp_Application::SalomeApp_Application()
102 : CAM_Application( false )
103 {
104   STD_TabDesktop* desk = new STD_TabDesktop();
105
106   setDesktop( desk );
107
108   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
109   QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
110
111   desktop()->setIcon( aLogo );
112   desktop()->setDockableMenuBar( true );
113   desktop()->setDockableStatusBar( false );
114
115   clearViewManagers();
116
117   mySelMgr = new SalomeApp_SelectionMgr( this );
118
119   connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
120            this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
121
122   connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
123 }
124
125 SalomeApp_Application::~SalomeApp_Application()
126 {
127   saveWindowsGeometry();
128
129   if ( resourceMgr() )
130   {
131     if ( desktop() )
132       desktop()->saveGeometry( resourceMgr(), "desktop" );
133     resourceMgr()->save();
134   }
135
136   delete mySelMgr;
137
138   SalomeApp_EventFilter::Destroy();
139 }
140
141 void SalomeApp_Application::start()
142 {
143   if ( desktop() )
144     desktop()->loadGeometry( resourceMgr(), "desktop" );
145
146   CAM_Application::start();
147
148   QAction* a = action( ViewWindowsId );
149   if ( a && a->inherits( "QtxDockAction" ) )
150     ((QtxDockAction*)a)->setAutoPlace( true );
151
152   SalomeApp_EventFilter::Init();
153
154   updateWindows();
155   updateViewManagers();
156
157   putInfo( "" );
158 }
159
160 QString SalomeApp_Application::applicationName() const 
161
162   return "SalomeApp";
163 }
164
165 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
166 {
167   CAM_Module* mod = CAM_Application::loadModule( name );
168   if ( mod )
169   {
170     connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
171     connect( this, SIGNAL( studySaved() ),  mod, SLOT( onModelSaved() ) );
172     connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
173   }
174   return mod;
175 }
176
177 bool SalomeApp_Application::activateModule( const QString& modName )
178 {
179   QString actName;
180   CAM_Module* prevMod = activeModule();
181
182   if ( prevMod )
183     actName = prevMod->moduleName();
184
185   if ( actName == modName )
186     return true;
187
188   saveWindowsGeometry();
189
190   bool status = CAM_Application::activateModule( modName );
191
192   updateModuleActions();
193
194   if ( !status )
195     return false;
196
197   updateWindows();
198   updateViewManagers();
199
200   return true;
201 }
202
203 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
204 {
205   return mySelMgr;
206 }
207
208 void SalomeApp_Application::createActions()
209 {
210   STD_Application::createActions();
211
212   SUIT_Desktop* desk = desktop();
213   SUIT_ResourceMgr* resMgr = resourceMgr();
214
215   // default icon for neutral point ('SALOME' module)
216   QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
217   if ( defIcon.isNull() )
218     defIcon = QPixmap( imageEmptyIcon );
219   // default icon for any module
220   QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
221   if ( modIcon.isNull() )
222     modIcon = QPixmap( imageEmptyIcon );
223
224   int modTBar = createTool( tr( "INF_TOOLBAR_MODULES" ) );
225
226   QActionGroup* modGroup = new QActionGroup( this );
227   modGroup->setExclusive( true );
228   modGroup->setUsesDropDown( true );
229
230   QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
231                              tr( "PRP_APP_MODULE" ), 0, desk, true );
232   modGroup->add( a );
233   myActions.insert( QString(), a );
234
235   QMap<QString, QString> iconMap;
236   moduleIconNames( iconMap );
237
238   const int iconSize = 20;
239
240   createTool( modGroup, modTBar );
241   createTool( separator(), modTBar );
242
243   QStringList modList;
244   modules( modList, false );
245
246   for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
247   {
248     if ( (*it).isEmpty() )
249       continue;
250
251     QString iconName;
252     if ( iconMap.contains( *it ) )
253       iconName = iconMap[*it];
254
255     QString modName = moduleName( *it );
256
257     QPixmap icon = resMgr->loadPixmap( modName, iconName );
258     if ( icon.isNull() )
259       icon = modIcon;
260
261     icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
262
263     QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
264     createTool( a, modTBar );
265     modGroup->add( a );
266
267     myActions.insert( *it, a );
268   }
269
270   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
271   int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
272   createMenu( separator(), windowMenu, -1, 1 );
273
274   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
275   {
276     QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(), 
277                                                        tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
278                                                        tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
279                                                        0, desk, false, this, SLOT( onNewWindow() ) );
280     createMenu( a, newWinMenu, -1 );
281   }
282
283   connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
284 }
285
286 void SalomeApp_Application::onModuleActivation( QAction* a )
287 {
288   if ( !a )
289     return;
290
291   QString modName = a->menuText();
292   if ( modName == tr( "APP_NAME" ) )
293     modName = QString::null;
294
295   // Force user to create/open a study before module activation
296   QMap<QString, QString> iconMap;
297   moduleIconNames( iconMap );
298   QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
299
300   bool cancelled = false;
301   while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
302     SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
303     int res = aDlg.exec();
304
305     switch ( res ){
306     case 1:
307       onNewDoc();
308       break;
309     case 2:
310       onOpenDoc();
311       break;
312     case 3:
313       //onLoadStudy();
314       //break;
315     case 0:
316     default:
317       putInfo( tr("INF_CANCELLED") );
318       myActions[QString()]->setOn( true );
319       cancelled = true;
320     }
321   }
322
323   if ( !cancelled )
324     activateModule( modName );
325 }
326
327 QString SalomeApp_Application::defaultModule() const
328 {
329   QStringList aModuleNames;
330   modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
331   // If there's the one and only module --> activate it automatically
332   // TODO: Possible improvement - default module can be taken from preferences
333   return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
334 }
335
336 void SalomeApp_Application::onNewWindow()
337 {
338   const QObject* obj = sender();
339   if ( !obj || !obj->inherits( "QAction" ) )
340     return;
341
342   QString type;
343   int id = actionId( (QAction*)obj );
344   switch ( id )
345   {
346   case NewGLViewId:
347     type = GLViewer_Viewer::Type();
348     break;
349   case NewPlot2dId:
350     type = Plot2d_Viewer::Type();
351     break;
352   case NewOCCViewId:
353     type = OCCViewer_Viewer::Type();
354     break;
355   case NewVTKViewId:
356     type = VTKViewer_Viewer::Type();
357     break;
358   }
359
360   if ( !type.isEmpty() )
361     createViewManager( type );
362 }
363
364 //=======================================================================
365 // name    : onNewDoc
366 // Purpose : SLOT. Create new document
367 //=======================================================================
368 void SalomeApp_Application::onNewDoc()
369 {
370   SUIT_Study* study = activeStudy();
371
372   saveWindowsGeometry();
373
374   CAM_Application::onNewDoc();
375   
376   if ( !study ) // new study will be create in THIS application
377   {
378     updateWindows();
379     updateViewManagers();
380   }
381 }
382
383 //=======================================================================
384 // name    : onOpenDoc
385 // Purpose : SLOT. Open new document
386 //=======================================================================
387 void SalomeApp_Application::onOpenDoc()
388 {
389   SUIT_Study* study = activeStudy();
390   saveWindowsGeometry();
391
392   CAM_Application::onOpenDoc();
393   
394   if ( !study ) // new study will be create in THIS application
395   {
396     updateWindows();
397     updateViewManagers();
398   }
399 }
400
401 void SalomeApp_Application::onSelection()
402 {
403   onSelectionChanged();
404
405   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
406     ((SalomeApp_Module*)activeModule())->selectionChanged();
407 }
408
409 void SalomeApp_Application::onSelectionChanged()
410 {
411 }
412
413 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
414 {
415   CAM_Application::setActiveStudy( study );
416     
417   activateWindows();
418 }
419
420 //=======================================================================
421 // name    : createNewStudy
422 // Purpose : Create new study
423 //=======================================================================
424 SUIT_Study* SalomeApp_Application::createNewStudy() 
425
426   SalomeApp_Study* aStudy = new SalomeApp_Study( this ); 
427   
428   // Set up processing of major study-related events
429   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
430   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
431   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
432   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
433
434   return aStudy; 
435 }
436
437 //=======================================================================
438 // name    : createNewStudy
439 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
440 //=======================================================================
441 void SalomeApp_Application::updateCommandsStatus()
442 {
443   CAM_Application::updateCommandsStatus();
444
445   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
446   {
447     QAction* a = action( id );
448     if ( a )
449       a->setEnabled( activeStudy() );
450   }
451 }
452
453 //=======================================================================
454 // name    : onHelpAbout
455 // Purpose : SLOT. Display "About" message box
456 //=======================================================================
457 void SalomeApp_Application::onHelpAbout()
458 {
459   //QAD_MessageBox::info1( myDesktop, tr( "ABOUT" ), tr( "APP_NAME_LONG" ).arg( APP_VERSION ), tr( "BUT_OK" ) );
460
461   QMessageBox aDlg( desktop(), "AboutDlg" );
462
463   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
464   QPixmap aPixmap = aResMgr->loadPixmap( "SalomeApp", tr( "ABOUT_ICO" ) );
465
466   QFontMetrics m( aDlg.font() );
467   QImage anImage = aPixmap.convertToImage();
468   int w = m.height() * 3;
469   anImage = anImage.scale( w, w );
470   aPixmap.convertFromImage( anImage );
471
472   aDlg.setCaption( tr( "ABOUT" ) );
473   aDlg.setText( tr( "APP_NAME_LONG" ).arg( APP_VERSION ) );
474   aDlg.setIconPixmap( aPixmap );
475   aDlg.exec();
476 }
477
478 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
479 {
480   QWidget* wid = 0;
481
482   int sId = studyId;
483   if ( sId < 0 )
484   {
485     if ( !activeStudy() )
486       return 0;
487     else
488       sId = activeStudy()->id();
489   }
490
491   if ( myWindows.contains( flag ) )
492     wid = myWindows[flag]->widget( sId );
493
494   return wid;
495 }
496
497 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
498 {
499   if ( !wid )
500     return;
501
502   int sId = studyId;
503   if ( sId < 0 )
504   {
505     if ( !activeStudy() )
506       return;
507     else
508       sId = activeStudy()->id();
509   }
510
511   if ( !myWindows.contains( flag ) )
512   {
513     QMap<int, int> winMap;
514     currentWindows( winMap );
515
516     myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
517     if ( winMap.contains( flag ) )
518       desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
519
520     myWindows[flag]->setResizeEnabled( true );
521     myWindows[flag]->setCloseMode( QDockWindow::Always );
522     myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
523   }
524
525   myWindows[flag]->insert( sId, wid );
526
527   setWindowShown( flag, !myWindows[flag]->isEmpty() );
528 }
529
530 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
531 {
532   if ( !myWindows.contains( flag ) )
533     return;
534
535   int sId = studyId;
536   if ( sId < 0 )
537   {
538     if ( !activeStudy() )
539       return;
540     else
541       sId = activeStudy()->id();
542   }
543
544   myWindows[flag]->remove( sId );
545
546   setWindowShown( flag, !myWindows[flag]->isEmpty() );
547 }
548
549 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
550 {
551   QWidget* wid = window( flag, studyId );
552   if ( !wid )
553     addWindow( wid = createWindow( flag ), flag, studyId );
554
555   return wid;
556 }
557
558 bool SalomeApp_Application::isWindowVisible( const int type ) const
559 {
560   bool res = false;
561   if ( myWindows.contains( type ) )
562   {
563     SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
564     res = desk && desk->appropriate( myWindows[type] );
565   }
566   return res;
567 }
568
569 void SalomeApp_Application::setWindowShown( const int type, const bool on )
570 {
571   if ( !desktop() || !myWindows.contains( type ) )
572     return;
573
574   QDockWindow* dw = myWindows[type];
575   desktop()->setAppropriate( dw, on );
576   on ? dw->show() : dw->hide();
577 }
578
579 OB_Browser* SalomeApp_Application::objectBrowser()
580 {
581   OB_Browser* ob = 0;
582   QWidget* wid = getWindow( WT_ObjectBrowser );
583   if ( wid->inherits( "OB_Browser" ) )
584     ob = (OB_Browser*)wid;
585   return ob;
586 }
587
588 LogWindow* SalomeApp_Application::logWindow()
589 {
590   LogWindow* lw = 0;
591   QWidget* wid = getWindow( WT_LogWindow );
592   if ( wid->inherits( "LogWindow" ) )
593     lw = (LogWindow*)wid;
594   return lw;
595 }
596
597 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
598 {
599   SUIT_ViewManager* aVM = viewManager( vmType );
600   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
601   if ( anActiveVM && anActiveVM->getType() == vmType )
602     aVM = anActiveVM;
603   else if ( aVM )
604   {
605     if ( !aVM->getActiveView() )
606       aVM->createView();
607   }
608   else if ( create )
609     aVM = createViewManager( vmType );
610   return aVM;
611 }
612
613 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
614 {
615   SUIT_ViewManager* viewMgr = 0;
616   if ( vmType == GLViewer_Viewer::Type() )
617   {
618     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
619     new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
620   }
621   else if ( vmType == Plot2d_Viewer::Type() )
622     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
623   else if ( vmType == OCCViewer_Viewer::Type() )
624   {
625     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
626     viewMgr->setViewModel( new SOCC_Viewer() );// custom view model, which extends SALOME_View interface
627     new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
628   }
629   else if ( vmType == SVTK_Viewer::Type() )
630   {
631     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
632     new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
633   }
634
635   if ( !viewMgr )
636     return 0;
637
638   addViewManager( viewMgr );
639   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
640
641   if ( viewWin && desktop() )
642     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
643
644   connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
645            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
646
647   return viewMgr;
648 }
649
650 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
651 {
652   removeViewManager( theVM );
653 }
654
655 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
656 {
657   SUIT_DataObject* aRoot = 0;
658   if ( theStudy && theStudy->root() )
659   {
660     aRoot = theStudy->root();
661     //aRoot->setName( tr( "DATA_MODELS" ) );
662   }
663   if ( objectBrowser() != 0 )
664     objectBrowser()->setRootObject( aRoot );
665
666   activateModule( defaultModule() );
667 }
668
669 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
670 {
671   SUIT_DataObject* aRoot = 0;
672   if ( theStudy && theStudy->root() )
673   {
674     aRoot = theStudy->root();
675     //aRoot->dump();
676   }
677   if ( objectBrowser() != 0 ) {
678     objectBrowser()->setRootObject( aRoot );
679   }
680
681   activateWindows();
682
683   activateModule( defaultModule() );
684
685   emit studyOpened();
686 }
687
688 void SalomeApp_Application::onStudySaved( SUIT_Study* )
689 {
690   emit studySaved();
691 }
692
693 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
694 {
695   emit studyClosed();
696
697   activateModule( "" );
698   if ( objectBrowser() != 0 )
699   {
700     objectBrowser()->setRootObject( 0 );
701   }
702
703   saveWindowsGeometry();
704 }
705
706 QString SalomeApp_Application::getFileFilter() const
707 {
708   return "(*.hdf)";
709 }
710
711 void SalomeApp_Application::updateActions()
712 {
713   updateCommandsStatus();
714 }
715
716 QWidget* SalomeApp_Application::createWindow( const int flag )
717 {
718   QWidget* wid = 0;
719
720   if ( flag == WT_ObjectBrowser )
721   {
722     OB_Browser* ob = new OB_Browser( desktop() );
723
724     ob->setCaption( tr( "OBJECT_BROWSER" ) );
725     ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
726     ob->setAutoUpdate( true );
727
728     // Create OBSelector
729     new SalomeApp_OBSelector( ob, mySelMgr );
730
731     wid = ob;
732
733     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
734   }
735   else if ( flag == WT_PyConsole )
736   {
737     PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
738     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
739     wid = pyCons;
740
741     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
742   }
743   else if ( flag == WT_LogWindow )
744   {
745     LogWindow* logWin = new LogWindow( desktop() );
746     logWin->setCaption( tr( "LOG_WINDOW" ) );
747     wid = logWin;
748
749     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
750   }
751   
752   return wid;
753 }
754
755 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
756 {
757   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
758   aMap.insert( WT_PyConsole, Qt::DockBottom );
759 }
760
761 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
762 {
763 }
764
765 CORBA::ORB_var SalomeApp_Application::orb()
766 {
767   ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
768   CORBA::ORB_var& orb = init( qApp->argc(), qApp->argv() );
769
770   return orb;
771 }
772
773 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
774 {
775   static SALOMEDSClient_StudyManager* aStudyManager = NULL;
776   
777   if(!aStudyManager) {
778     aStudyManager = new SALOMEDS_StudyManager();
779   }
780   return aStudyManager;
781 }
782
783 SALOME_NamingService* SalomeApp_Application::namingService()
784 {
785   return new SALOME_NamingService( orb() );
786 }
787
788 QString SalomeApp_Application::defaultEngineIOR()
789 {
790   // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
791   QString anIOR( "" );
792   CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
793   if ( !CORBA::is_nil( anEngine ) )
794     anIOR = orb()->object_to_string( anEngine );
795   return anIOR;
796 }
797
798 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
799 {
800   iconMap.clear();
801
802   SUIT_ResourceMgr* resMgr = resourceMgr();
803   if ( !resMgr )
804     return;
805
806   QStringList modList;
807   modules( modList, false );
808
809   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
810   {
811     QString modName = *it;
812     QString modIntr = moduleName( modName );
813     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
814
815     if ( modIcon.isEmpty() )
816       continue;
817
818     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
819       modIcon += QString( ".png" );
820
821     iconMap.insert( modName, modIcon );
822   }
823 }
824
825 void SalomeApp_Application::updateModuleActions()
826 {
827   QString modName;
828   if ( activeModule() )
829     modName = activeModule()->moduleName();
830
831   if ( myActions.contains( modName ) )
832     myActions[modName]->setOn( true );
833 }
834
835 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
836 {
837   winMap.clear();
838   if ( !activeStudy() )
839     return;
840
841   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
842     ((SalomeApp_Module*)activeModule())->windows( winMap );
843   else
844     defaultWindows( winMap );
845 }
846
847 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
848 {
849   lst.clear();
850   if ( !activeStudy() )
851     return;
852
853   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
854     ((SalomeApp_Module*)activeModule())->viewManagers( lst );
855   else
856     defaultViewManagers( lst );
857 }
858
859 void SalomeApp_Application::updateWindows()
860 {
861   QMap<int, int> winMap;
862   currentWindows( winMap );
863
864   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
865     getWindow( it.key() );
866
867   loadWindowsGeometry();
868
869   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
870     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
871 }
872
873 void SalomeApp_Application::updateViewManagers()
874 {
875   QStringList lst;
876   currentViewManagers( lst );
877
878   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
879     getViewManager( *it, true );
880 }
881
882 void SalomeApp_Application::loadWindowsGeometry()
883 {
884   QtxDockAction* dockMgr = 0;
885
886   QAction* a = action( ViewWindowsId );
887   if ( a && a->inherits( "QtxDockAction" ) )
888     dockMgr = (QtxDockAction*)a;
889
890   if ( !dockMgr )
891     return;
892
893   QString modName;
894   if ( activeModule() )
895     modName = moduleLibrary( activeModule()->moduleName(), false );
896   
897   QString section = QString( "windows_geometry" );
898   if ( !modName.isEmpty() )
899     section += QString( "." ) + modName;
900
901
902   dockMgr->loadGeometry( resourceMgr(), section, false );
903   dockMgr->restoreGeometry();
904 }
905
906 void SalomeApp_Application::saveWindowsGeometry()
907 {
908   QtxDockAction* dockMgr = 0;
909
910   QAction* a = action( ViewWindowsId );
911   if ( a && a->inherits( "QtxDockAction" ) )
912     dockMgr = (QtxDockAction*)a;
913
914   if ( !dockMgr )
915     return;
916
917   QString modName;
918   if ( activeModule() )
919     modName = moduleLibrary( activeModule()->moduleName(), false );
920   
921   QString section = QString( "windows_geometry" );
922   if ( !modName.isEmpty() )
923     section += QString( "." ) + modName;
924
925   dockMgr->storeGeometry();
926   dockMgr->saveGeometry( resourceMgr(), section, false );
927 }
928
929 void SalomeApp_Application::activateWindows()
930 {
931   if ( activeStudy() )
932   {
933     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
934       itr.data()->activate( activeStudy()->id() );
935   }
936 }