Salome HOME
*** empty log message ***
[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     objectBrowser()->setRootObject( 0 );
700
701   saveWindowsGeometry();
702 }
703
704 QString SalomeApp_Application::getFileFilter() const
705 {
706   return "(*.hdf)";
707 }
708
709 void SalomeApp_Application::afterCloseDoc()
710 {
711   updateWindows();
712
713   CAM_Application::afterCloseDoc();
714 }
715
716 void SalomeApp_Application::updateActions()
717 {
718   updateCommandsStatus();
719 }
720
721 QWidget* SalomeApp_Application::createWindow( const int flag )
722 {
723   QWidget* wid = 0;
724
725   if ( flag == WT_ObjectBrowser )
726   {
727     OB_Browser* ob = new OB_Browser( desktop() );
728
729     ob->setCaption( tr( "OBJECT_BROWSER" ) );
730     ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
731     ob->setAutoUpdate( true );
732
733     // Create OBSelector
734     new SalomeApp_OBSelector( ob, mySelMgr );
735
736     wid = ob;
737
738     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
739   }
740   else if ( flag == WT_PyConsole )
741   {
742     PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
743     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
744     wid = pyCons;
745
746     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
747   }
748   else if ( flag == WT_LogWindow )
749   {
750     LogWindow* logWin = new LogWindow( desktop() );
751     logWin->setCaption( tr( "LOG_WINDOW" ) );
752     wid = logWin;
753
754     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
755   }
756   
757   return wid;
758 }
759
760 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
761 {
762   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
763   aMap.insert( WT_PyConsole, Qt::DockBottom );
764 }
765
766 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
767 {
768 }
769
770 CORBA::ORB_var SalomeApp_Application::orb()
771 {
772   ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
773   CORBA::ORB_var& orb = init( qApp->argc(), qApp->argv() );
774
775   return orb;
776 }
777
778 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
779 {
780   static SALOMEDSClient_StudyManager* aStudyManager = NULL;
781   
782   if(!aStudyManager) {
783     aStudyManager = new SALOMEDS_StudyManager();
784   }
785   return aStudyManager;
786 }
787
788 SALOME_NamingService* SalomeApp_Application::namingService()
789 {
790   return new SALOME_NamingService( orb() );
791 }
792
793 QString SalomeApp_Application::defaultEngineIOR()
794 {
795   // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
796   QString anIOR( "" );
797   CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
798   if ( !CORBA::is_nil( anEngine ) )
799     anIOR = orb()->object_to_string( anEngine );
800   return anIOR;
801 }
802
803 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
804 {
805   iconMap.clear();
806
807   SUIT_ResourceMgr* resMgr = resourceMgr();
808   if ( !resMgr )
809     return;
810
811   QStringList modList;
812   modules( modList, false );
813
814   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
815   {
816     QString modName = *it;
817     QString modIntr = moduleName( modName );
818     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
819
820     if ( modIcon.isEmpty() )
821       continue;
822
823     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
824       modIcon += QString( ".png" );
825
826     iconMap.insert( modName, modIcon );
827   }
828 }
829
830 void SalomeApp_Application::updateModuleActions()
831 {
832   QString modName;
833   if ( activeModule() )
834     modName = activeModule()->moduleName();
835
836   if ( myActions.contains( modName ) )
837     myActions[modName]->setOn( true );
838 }
839
840 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
841 {
842   winMap.clear();
843   if ( !activeStudy() )
844     return;
845
846   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
847     ((SalomeApp_Module*)activeModule())->windows( winMap );
848   else
849     defaultWindows( winMap );
850 }
851
852 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
853 {
854   lst.clear();
855   if ( !activeStudy() )
856     return;
857
858   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
859     ((SalomeApp_Module*)activeModule())->viewManagers( lst );
860   else
861     defaultViewManagers( lst );
862 }
863
864 void SalomeApp_Application::updateWindows()
865 {
866   QMap<int, int> winMap;
867   currentWindows( winMap );
868
869   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
870     getWindow( it.key() );
871
872   loadWindowsGeometry();
873
874   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
875     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
876 }
877
878 void SalomeApp_Application::updateViewManagers()
879 {
880   QStringList lst;
881   currentViewManagers( lst );
882
883   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
884     getViewManager( *it, true );
885 }
886
887 void SalomeApp_Application::loadWindowsGeometry()
888 {
889   QtxDockAction* dockMgr = 0;
890
891   QAction* a = action( ViewWindowsId );
892   if ( a && a->inherits( "QtxDockAction" ) )
893     dockMgr = (QtxDockAction*)a;
894
895   if ( !dockMgr )
896     return;
897
898   QString modName;
899   if ( activeModule() )
900     modName = moduleLibrary( activeModule()->moduleName(), false );
901   
902   QString section = QString( "windows_geometry" );
903   if ( !modName.isEmpty() )
904     section += QString( "." ) + modName;
905
906
907   dockMgr->loadGeometry( resourceMgr(), section, false );
908   dockMgr->restoreGeometry();
909 }
910
911 void SalomeApp_Application::saveWindowsGeometry()
912 {
913   QtxDockAction* dockMgr = 0;
914
915   QAction* a = action( ViewWindowsId );
916   if ( a && a->inherits( "QtxDockAction" ) )
917     dockMgr = (QtxDockAction*)a;
918
919   if ( !dockMgr )
920     return;
921
922   QString modName;
923   if ( activeModule() )
924     modName = moduleLibrary( activeModule()->moduleName(), false );
925   
926   QString section = QString( "windows_geometry" );
927   if ( !modName.isEmpty() )
928     section += QString( "." ) + modName;
929
930   dockMgr->storeGeometry();
931   dockMgr->saveGeometry( resourceMgr(), section, false );
932 }
933
934 void SalomeApp_Application::activateWindows()
935 {
936   if ( activeStudy() )
937   {
938     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
939       itr.data()->activate( activeStudy()->id() );
940   }
941 }