Salome HOME
4a5c188543143b90af71c5346145aed361d83406
[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_OBFilter.h"
13 #include "SalomeApp_DataModel.h"
14 #include "SalomeApp_DataObject.h"
15 #include "SalomeApp_EventFilter.h"
16 #include "SalomeApp_WidgetContainer.h"
17
18 #include "SalomeApp_AboutDlg.h"
19 #include "SalomeApp_ModuleDlg.h"
20 #include "SalomeApp_Preferences.h"
21 #include "SalomeApp_PreferencesDlg.h"
22 #include "SalomeApp_StudyPropertiesDlg.h"
23
24 #include "SalomeApp_GLSelector.h"
25 #include "SalomeApp_OBSelector.h"
26 #include "SalomeApp_OCCSelector.h"
27 #include "SalomeApp_VTKSelector.h"
28 #include "SalomeApp_SelectionMgr.h"
29
30 #include <LogWindow.h>
31
32 #include <GLViewer_Viewer.h>
33 #include <GLViewer_ViewManager.h>
34
35 #include <Plot2d_ViewManager.h>
36 #include <SPlot2d_ViewModel.h>
37
38 #include <OCCViewer_ViewManager.h>
39 #include <SOCC_ViewModel.h>
40
41 #include <SVTK_ViewModel.h>
42 #include <SVTK_ViewManager.h>
43
44 #include <STD_TabDesktop.h>
45
46 #include <SUIT_Tools.h>
47 #include <SUIT_Session.h>
48
49 #include <QtxToolBar.h>
50 #include <QtxMRUAction.h>
51 #include <QtxDockAction.h>
52 #include <QtxResourceEdit.h>
53
54 #include <OB_Browser.h>
55
56 #include <PythonConsole_PyConsole.h>
57
58 #include <SUIT_FileDlg.h>
59 #include <SUIT_MessageBox.h>
60 #include <SUIT_ResourceMgr.h>
61 #include <SUIT_ActionOperation.h>
62
63 #include <Utils_ORB_INIT.hxx>
64 #include <Utils_SINGLETON.hxx>
65 #include <SALOME_ModuleCatalog_impl.hxx>
66 #include <SALOME_LifeCycleCORBA.hxx>
67
68 #include <qmap.h>
69 #include <qdir.h>
70 #include <qlabel.h>
71 #include <qimage.h>
72 #include <qaction.h>
73 #include <qmenubar.h>
74 #include <qcombobox.h>
75 #include <qmessagebox.h>
76 #include <qapplication.h>
77
78 #include "SALOMEDS_StudyManager.hxx"
79
80 #include "SALOME_ListIteratorOfListIO.hxx"
81 #include "SALOME_ListIO.hxx"
82
83 #define OBJECT_BROWSER_WIDTH 300
84
85 static const char* imageEmptyIcon[] = {
86 "20 20 1 1",
87 ".      c None",
88 "....................",
89 "....................",
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "...................."};
108
109 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
110 {
111   return new SalomeApp_Application();
112 }
113
114 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
115
116 /*
117   Class       : SalomeApp_Application
118   Description : Application containing SalomeApp module
119 */
120
121 SalomeApp_Application::SalomeApp_Application()
122 : CAM_Application( false ),
123 myPrefs( 0 )
124 {
125   STD_TabDesktop* desk = new STD_TabDesktop();
126
127   setDesktop( desk );
128
129   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
130   QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
131
132   desktop()->setIcon( aLogo );
133   desktop()->setDockableMenuBar( true );
134   desktop()->setDockableStatusBar( false );
135
136   clearViewManagers();
137
138   mySelMgr = new SalomeApp_SelectionMgr( this );
139
140   connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
141            this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
142
143   connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
144 }
145
146 SalomeApp_Application::~SalomeApp_Application()
147 {
148   saveWindowsGeometry();
149
150   if ( resourceMgr() )
151   {
152     if ( desktop() )
153       desktop()->saveGeometry( resourceMgr(), "desktop" );
154     resourceMgr()->save();
155   }
156
157   delete mySelMgr;
158
159   SalomeApp_EventFilter::Destroy();
160 }
161
162 void SalomeApp_Application::start()
163 {
164   if ( desktop() )
165     desktop()->loadGeometry( resourceMgr(), "desktop" );
166
167   CAM_Application::start();
168
169   QAction* a = action( ViewWindowsId );
170   if ( a && a->inherits( "QtxDockAction" ) )
171     ((QtxDockAction*)a)->setAutoPlace( true );
172
173   SalomeApp_EventFilter::Init();
174
175   updateWindows();
176   updateViewManagers();
177
178   putInfo( "" );
179 }
180
181 QString SalomeApp_Application::applicationName() const
182 {
183   return tr( "APP_NAME" );
184 }
185
186 QString SalomeApp_Application::applicationVersion() const
187 {
188   static QString _app_version;
189
190   if ( _app_version.isEmpty() )
191   {
192     QString path( ::getenv( "GUI_ROOT_DIR" ) );
193     if ( !path.isEmpty() )
194       path += QDir::separator();
195     path += QString( "bin/salome/VERSION" );
196
197     QFile vf( path );
198     if ( vf.open( IO_ReadOnly ) )
199     {
200       QString line;
201       vf.readLine( line, 1024 );
202       vf.close();
203
204       if ( !line.isEmpty() )
205       {
206         while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
207           line.remove( line.length() - 1, 1 );
208
209         int idx = line.findRev( ":" );
210         if ( idx != -1 )
211           _app_version = line.mid( idx + 1 ).stripWhiteSpace();
212       }
213     }
214   }
215
216   return _app_version;
217 }
218
219 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
220 {
221   CAM_Module* mod = CAM_Application::loadModule( name );
222   if ( mod )
223   {
224     connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
225     connect( this, SIGNAL( studySaved() ),  mod, SLOT( onModelSaved() ) );
226     connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
227   }
228   return mod;
229 }
230
231 bool SalomeApp_Application::activateModule( const QString& modName )
232 {
233   QString actName;
234   CAM_Module* prevMod = activeModule();
235
236   if ( prevMod )
237     actName = prevMod->moduleName();
238
239   if ( actName == modName )
240     return true;
241
242   saveWindowsGeometry();
243
244   bool status = CAM_Application::activateModule( modName );
245
246   updateModuleActions();
247
248   if ( !status )
249     return false;
250
251   updateWindows();
252   updateViewManagers();
253
254   return true;
255 }
256
257 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
258 {
259   return mySelMgr;
260 }
261
262 void SalomeApp_Application::createActions()
263 {
264   STD_Application::createActions();
265
266   SUIT_Desktop* desk = desktop();
267   SUIT_ResourceMgr* resMgr = resourceMgr();
268
269   // Load script
270   createAction( LoadScriptId, tr( "TOT_DESK_LOADSCRIPT" ), QIconSet(),
271                 tr( "MEN_DESK_LOADSCRIPT" ), tr( "PRP_DESK_LOADSCRIPT" ),
272                 0, desk, false, this, SLOT( onLoadScript() ) );
273
274   // Properties
275   createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
276                 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
277                 0, desk, false, this, SLOT( onProperties() ) );
278
279   // Preferences
280   createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
281                 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
282                 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
283
284   // MRU
285   QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
286   connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
287   registerAction( MRUId, mru );
288
289   // default icon for neutral point ('SALOME' module)
290   QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
291   if ( defIcon.isNull() )
292     defIcon = QPixmap( imageEmptyIcon );
293
294   // default icon for any module
295   QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
296   if ( modIcon.isNull() )
297     modIcon = QPixmap( imageEmptyIcon );
298
299   QToolBar* modTBar = new QtxToolBar( true, desk );
300   modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
301
302   QActionGroup* modGroup = new QActionGroup( this );
303   modGroup->setExclusive( true );
304   modGroup->setUsesDropDown( true );
305
306   QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
307                              tr( "PRP_APP_MODULE" ), 0, desk, true );
308   modGroup->add( a );
309   myActions.insert( QString(), a );
310
311   QMap<QString, QString> iconMap;
312   moduleIconNames( iconMap );
313
314   const int iconSize = 20;
315
316   modGroup->addTo( modTBar );
317   modTBar->addSeparator();
318
319   QStringList modList;
320   modules( modList, false );
321
322   for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
323   {
324     if ( (*it).isEmpty() )
325       continue;
326
327     QString iconName;
328     if ( iconMap.contains( *it ) )
329       iconName = iconMap[*it];
330
331     QString modName = moduleName( *it );
332
333     QPixmap icon = resMgr->loadPixmap( modName, iconName );
334     if ( icon.isNull() )
335       icon = modIcon;
336
337     icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
338
339     QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
340     a->addTo( modTBar );
341     modGroup->add( a );
342
343     myActions.insert( *it, a );
344   }
345
346   SUIT_Tools::simplifySeparators( modTBar );
347
348   // New window
349
350   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
351   int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
352   createMenu( separator(), windowMenu, -1, 1 );
353
354   QMap<int, int> accelMap;
355   accelMap[NewGLViewId]  = ALT+Key_G;
356   accelMap[NewPlot2dId]  = ALT+Key_P;
357   accelMap[NewOCCViewId] = ALT+Key_O;
358   accelMap[NewVTKViewId] = ALT+Key_K;
359
360   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
361   {
362     QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
363                                tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
364                                tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
365                                accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
366     createMenu( a, newWinMenu, -1 );
367   }
368   connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
369
370
371
372   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
373
374   createMenu( separator(), fileMenu, -1, 15, -1 );
375   createMenu( LoadScriptId, fileMenu, 15, -1 );
376   createMenu( separator(), fileMenu, -1, 15, -1 );
377   createMenu( PropertiesId, fileMenu, 10, -1 );
378   createMenu( separator(), fileMenu, -1, 15, -1 );
379   createMenu( PreferencesId, fileMenu, 15, -1 );
380   createMenu( separator(), fileMenu, -1, 15, -1 );
381
382   /*
383   createMenu( separator(), fileMenu, -1, 100, -1 );
384   createMenu( MRUId, fileMenu, 100, -1 );
385   createMenu( separator(), fileMenu, -1, 100, -1 );
386   */
387 }
388
389 void SalomeApp_Application::onModuleActivation( QAction* a )
390 {
391   if ( !a )
392     return;
393
394   QString modName = a->menuText();
395   if ( modName == tr( "APP_NAME" ) )
396     modName = QString::null;
397
398   // Force user to create/open a study before module activation
399   QMap<QString, QString> iconMap;
400   moduleIconNames( iconMap );
401   QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
402
403   bool cancelled = false;
404   while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
405     SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
406     int res = aDlg.exec();
407
408     switch ( res ){
409     case 1:
410       onNewDoc();
411       break;
412     case 2:
413       onOpenDoc();
414       break;
415     case 3:
416       //onLoadStudy();
417       //break;
418     case 0:
419     default:
420       putInfo( tr("INF_CANCELLED") );
421       myActions[QString()]->setOn( true );
422       cancelled = true;
423     }
424   }
425
426   if ( !cancelled )
427     activateModule( modName );
428 }
429
430 QString SalomeApp_Application::defaultModule() const
431 {
432   QStringList aModuleNames;
433   modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
434   // If there's the one and only module --> activate it automatically
435   // TODO: Possible improvement - default module can be taken from preferences
436   return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
437 }
438
439 void SalomeApp_Application::onNewWindow()
440 {
441   const QObject* obj = sender();
442   if ( !obj || !obj->inherits( "QAction" ) )
443     return;
444
445   QString type;
446   int id = actionId( (QAction*)obj );
447   switch ( id )
448   {
449   case NewGLViewId:
450     type = GLViewer_Viewer::Type();
451     break;
452   case NewPlot2dId:
453     type = Plot2d_Viewer::Type();
454     break;
455   case NewOCCViewId:
456     type = OCCViewer_Viewer::Type();
457     break;
458   case NewVTKViewId:
459     type = VTKViewer_Viewer::Type();
460     break;
461   }
462
463   if ( !type.isEmpty() )
464     createViewManager( type );
465 }
466
467 //=======================================================================
468 // name    : onNewDoc
469 // Purpose : SLOT. Create new document
470 //=======================================================================
471 void SalomeApp_Application::onNewDoc()
472 {
473   SUIT_Study* study = activeStudy();
474
475   saveWindowsGeometry();
476
477   CAM_Application::onNewDoc();
478
479   if ( !study ) // new study will be create in THIS application
480   {
481     updateWindows();
482     updateViewManagers();
483   }
484 }
485
486 //=======================================================================
487 // name    : onOpenDoc
488 // Purpose : SLOT. Open new document
489 //=======================================================================
490 void SalomeApp_Application::onOpenDoc()
491 {
492   SUIT_Study* study = activeStudy();
493   saveWindowsGeometry();
494
495   CAM_Application::onOpenDoc();
496
497   if ( !study ) // new study will be create in THIS application
498   {
499     updateWindows();
500     updateViewManagers();
501   }
502 }
503
504 bool SalomeApp_Application::onOpenDoc( const QString& aName )
505 {
506   bool res = CAM_Application::onOpenDoc( aName );
507
508   QAction* a = action( MRUId );
509   if ( a && a->inherits( "QtxMRUAction" ) )
510   {
511     QtxMRUAction* mru = (QtxMRUAction*)a;
512     if ( res )
513       mru->insert( aName );
514     else
515       mru->remove( aName );
516   }
517   return res;
518 }
519
520 void SalomeApp_Application::onSelection()
521 {
522   onSelectionChanged();
523
524   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
525     ((SalomeApp_Module*)activeModule())->selectionChanged();
526 }
527
528 void SalomeApp_Application::onSelectionChanged()
529 {
530  /*
531    SalomeApp_Module* module = dynamic_cast<SalomeApp_Module*>(activeModule());
532    if(module == NULL) return;
533    
534    QString ior = module->engineIOR();
535    if(ior.length() < 5) return; //Not a real CORBA IOR
536    CORBA::Object_var obj = orb()->string_to_object(ior.latin1());
537    if(CORBA::is_nil(obj)) return;
538    
539    SALOMEDS::Driver_var engine = SALOMEDS::Driver::_narrow(obj);
540    if(CORBA::is_nil(engine)) return;
541 */
542
543    SALOME_ListIO list;
544    SalomeApp_SelectionMgr* mgr = selectionMgr();
545    mgr->selectedObjects(list);
546    
547    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
548    if(study == NULL) return;
549    
550    _PTR(Study) stdDS = study->studyDS();
551    if(!stdDS) return;
552    
553    QAction* qaction;  
554    
555    for ( SALOME_ListIteratorOfListIO it( list ); it.More(); it.Next() )
556    {
557       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
558       qaction = action(EditCutId);
559       if( studyMgr()->CanCopy(so) ) {
560         qaction->setEnabled(true);
561         qaction = action(EditCopyId); 
562         qaction->setEnabled(true);  
563       }
564       else {
565         qaction->setEnabled(false);
566         qaction = action(EditCopyId);
567         qaction->setEnabled(false);         
568       }
569       qaction = action(EditPasteId);
570       if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
571       else qaction->setEnabled(false);
572    } 
573 }               
574  
575 void SalomeApp_Application::onRefresh()
576 {
577   updateObjectBrowser( true );
578 }
579
580 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
581 {
582   CAM_Application::setActiveStudy( study );
583
584   activateWindows();
585 }
586
587 //=======================================================================
588 // name    : createNewStudy
589 // Purpose : Create new study
590 //=======================================================================
591 SUIT_Study* SalomeApp_Application::createNewStudy()
592 {
593   SalomeApp_Study* aStudy = new SalomeApp_Study( this );
594
595   // Set up processing of major study-related events
596   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
597   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
598   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
599   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
600
601   return aStudy;
602 }
603
604 //=======================================================================
605 // name    : createNewStudy
606 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
607 //=======================================================================
608 void SalomeApp_Application::updateCommandsStatus()
609 {
610   CAM_Application::updateCommandsStatus();
611
612   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
613   {
614     QAction* a = action( id );
615     if ( a )
616       a->setEnabled( activeStudy() );
617   }
618
619   // Load script menu
620   QAction* a = action( LoadScriptId );
621   if ( a )
622     a->setEnabled( activeStudy() );
623   
624   a = action( PropertiesId );
625   if( a )
626     a->setEnabled( activeStudy() );
627     
628   a = action(EditCutId);
629   a->setEnabled(false); 
630   a = action(EditCopyId);
631   a->setEnabled(false);       
632   a = action(EditPasteId);
633   a->setEnabled(false);      
634 }
635
636 //=======================================================================
637 // name    : onHelpAbout
638 // Purpose : SLOT. Display "About" message box
639 //=======================================================================
640 void SalomeApp_Application::onHelpAbout()
641 {
642   SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
643   dlg->exec();
644   delete dlg;
645 }
646
647 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
648 {
649   QWidget* wid = 0;
650
651   int sId = studyId;
652   if ( sId < 0 )
653   {
654     if ( !activeStudy() )
655       return 0;
656     else
657       sId = activeStudy()->id();
658   }
659
660   if ( myWindows.contains( flag ) )
661     wid = myWindows[flag]->widget( sId );
662
663   return wid;
664 }
665
666 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
667 {
668   if ( !wid )
669     return;
670
671   int sId = studyId;
672   if ( sId < 0 )
673   {
674     if ( !activeStudy() )
675       return;
676     else
677       sId = activeStudy()->id();
678   }
679
680   if ( !myWindows.contains( flag ) )
681   {
682     QMap<int, int> winMap;
683     currentWindows( winMap );
684
685     myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
686     if ( winMap.contains( flag ) )
687       desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
688
689     myWindows[flag]->setResizeEnabled( true );
690     myWindows[flag]->setCloseMode( QDockWindow::Always );
691     myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
692   }
693
694   myWindows[flag]->insert( sId, wid );
695
696   setWindowShown( flag, !myWindows[flag]->isEmpty() );
697 }
698
699 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
700 {
701   if ( !myWindows.contains( flag ) )
702     return;
703
704   int sId = studyId;
705   if ( sId < 0 )
706   {
707     if ( !activeStudy() )
708       return;
709     else
710       sId = activeStudy()->id();
711   }
712
713   QWidget* wid = myWindows[flag]->widget( sId );
714   myWindows[flag]->remove( sId );
715   delete wid;
716
717   setWindowShown( flag, !myWindows[flag]->isEmpty() );
718 }
719
720 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
721 {
722   QWidget* wid = window( flag, studyId );
723   if ( !wid )
724     addWindow( wid = createWindow( flag ), flag, studyId );
725
726   return wid;
727 }
728
729 bool SalomeApp_Application::isWindowVisible( const int type ) const
730 {
731   bool res = false;
732   if ( myWindows.contains( type ) )
733   {
734     SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
735     res = desk && desk->appropriate( myWindows[type] );
736   }
737   return res;
738 }
739
740 void SalomeApp_Application::setWindowShown( const int type, const bool on )
741 {
742   if ( !desktop() || !myWindows.contains( type ) )
743     return;
744
745   QDockWindow* dw = myWindows[type];
746   desktop()->setAppropriate( dw, on );
747   on ? dw->show() : dw->hide();
748 }
749
750 OB_Browser* SalomeApp_Application::objectBrowser()
751 {
752   OB_Browser* ob = 0;
753   QWidget* wid = getWindow( WT_ObjectBrowser );
754   if ( wid->inherits( "OB_Browser" ) )
755     ob = (OB_Browser*)wid;
756   return ob;
757 }
758
759 LogWindow* SalomeApp_Application::logWindow()
760 {
761   LogWindow* lw = 0;
762   QWidget* wid = getWindow( WT_LogWindow );
763   if ( wid->inherits( "LogWindow" ) )
764     lw = (LogWindow*)wid;
765   return lw;
766 }
767
768 PythonConsole* SalomeApp_Application::pythonConsole()
769 {
770   PythonConsole* console = 0;
771   QWidget* wid = getWindow( WT_PyConsole );
772   if ( wid->inherits( "PythonConsole" ) )
773     console = (PythonConsole*)wid;
774   return console;
775 }
776
777 SalomeApp_Preferences* SalomeApp_Application::preferences() const
778 {
779   return preferences( false );
780 }
781
782 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
783 {
784   SUIT_ViewManager* aVM = viewManager( vmType );
785   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
786
787   if ( anActiveVM && anActiveVM->getType() == vmType )
788     aVM = anActiveVM;
789
790   if ( aVM && create )
791   {
792     if ( !aVM->getActiveView() )
793       aVM->createView();
794     else
795       aVM->getActiveView()->setFocus();
796   }
797   else if ( create )
798     aVM = createViewManager( vmType );
799
800   return aVM;
801 }
802
803 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
804 {
805   SUIT_ResourceMgr* resMgr = resourceMgr();
806
807   SUIT_ViewManager* viewMgr = 0;
808   if ( vmType == GLViewer_Viewer::Type() )
809   {
810     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
811     new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
812   }
813   else if ( vmType == Plot2d_Viewer::Type() )
814   {
815     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
816     viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
817   }
818   else if ( vmType == OCCViewer_Viewer::Type() )
819   {
820     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
821     SOCC_Viewer* vm = new SOCC_Viewer();
822     vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
823     vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
824     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
825     new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
826   }
827   else if ( vmType == SVTK_Viewer::Type() )
828   {
829     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
830     SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
831     vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
832     new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
833   }
834
835   if ( !viewMgr )
836     return 0;
837
838   addViewManager( viewMgr );
839   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
840
841   if ( viewWin && desktop() )
842     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
843
844   connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
845            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
846
847   return viewMgr;
848 }
849
850 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
851 {
852   removeViewManager( theVM );
853 }
854
855 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
856 {
857   SUIT_DataObject* aRoot = 0;
858   if ( theStudy && theStudy->root() )
859   {
860     aRoot = theStudy->root();
861     //aRoot->setName( tr( "DATA_MODELS" ) );
862   }
863   if ( objectBrowser() != 0 )
864     objectBrowser()->setRootObject( aRoot );
865
866   activateModule( defaultModule() );
867
868   activateWindows();
869 }
870
871 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
872 {
873   SUIT_DataObject* aRoot = 0;
874   if ( theStudy && theStudy->root() )
875   {
876     aRoot = theStudy->root();
877     //aRoot->dump();
878   }
879   if ( objectBrowser() != 0 ) {
880     objectBrowser()->setRootObject( aRoot );
881   }
882
883   activateModule( defaultModule() );
884
885   activateWindows();
886
887   emit studyOpened();
888 }
889
890 void SalomeApp_Application::onStudySaved( SUIT_Study* )
891 {
892   emit studySaved();
893 }
894
895 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
896 {
897   emit studyClosed();
898
899   activateModule( "" );
900
901   saveWindowsGeometry();
902 }
903
904 void SalomeApp_Application::onLoadScript( )
905 {
906   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
907   if ( !appStudy ) return;
908   _PTR(Study) aStudy = appStudy->studyDS();
909
910   if ( aStudy->GetProperties()->IsLocked() ) {
911     SUIT_MessageBox::warn1 ( desktop(),
912                              QObject::tr("WRN_WARNING"),
913                              QObject::tr("WRN_STUDY_LOCKED"),
914                              QObject::tr("BUT_OK") );
915     return;
916   }
917
918   QStringList filtersList;
919   filtersList.append(tr("PYTHON_FILES_FILTER"));
920   filtersList.append(tr("ALL_FILES_FILTER"));
921
922   QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_LOADSCRIPT" ), true, true );
923
924   if ( !aFile.isEmpty() )
925   {
926     QString command = QString("execfile(\"%1\")").arg(aFile);
927
928     PythonConsole* pyConsole = pythonConsole();
929
930     if ( pyConsole )
931       pyConsole->exec( command );
932   }
933 }
934
935 void SalomeApp_Application::onPreferences()
936 {
937   QApplication::setOverrideCursor( Qt::waitCursor );
938
939   SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
940
941   QApplication::restoreOverrideCursor();
942
943   if ( !prefDlg )
944     return;
945
946   prefDlg->exec();
947
948   delete prefDlg;
949 }
950
951 void SalomeApp_Application::onMRUActivated( QString aName )
952 {
953   onOpenDoc( aName );
954 }
955
956 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
957 {
958   SalomeApp_Module* sMod = 0;
959   CAM_Module* mod = module( modName );
960   if ( mod && mod->inherits( "SalomeApp_Module" ) )
961     sMod = (SalomeApp_Module*)mod;
962
963   if ( sMod )
964     sMod->preferencesChanged( section, param );
965   else
966     preferencesChanged( section, param );
967 }
968
969 QString SalomeApp_Application::getFileFilter() const
970 {
971   return "(*.hdf)";
972 }
973
974 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
975 {
976   CAM_Application::beforeCloseDoc( s );
977
978   for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
979     removeWindow( itr.key(), s->id() );
980 }
981
982 void SalomeApp_Application::updateActions()
983 {
984   updateCommandsStatus();
985 }
986
987 QWidget* SalomeApp_Application::createWindow( const int flag )
988 {
989   QWidget* wid = 0;
990
991   SUIT_ResourceMgr* resMgr = resourceMgr();
992
993   if ( flag == WT_ObjectBrowser )
994   {
995     OB_Browser* ob = new OB_Browser( desktop() );
996     ob->setAutoUpdate( true );
997     ob->setAutoOpenLevel( 1 );
998     ob->setCaption( tr( "OBJECT_BROWSER" ) );
999     ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1000     ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1001
1002     ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1003
1004     for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1005     {
1006       ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1007       ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1008                                                    QString().sprintf( "visibility_column_%d", i ), true ) );
1009     }
1010
1011     // Create OBSelector
1012     new SalomeApp_OBSelector( ob, mySelMgr );
1013
1014     wid = ob;
1015
1016     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1017   }
1018   else if ( flag == WT_PyConsole )
1019   {
1020     PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1021     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1022     wid = pyCons;
1023
1024     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1025   }
1026   else if ( flag == WT_LogWindow )
1027   {
1028     LogWindow* logWin = new LogWindow( desktop() );
1029     logWin->setCaption( tr( "LOG_WINDOW" ) );
1030     wid = logWin;
1031
1032     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1033   }
1034
1035   return wid;
1036 }
1037
1038 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1039 {
1040   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1041   aMap.insert( WT_PyConsole, Qt::DockBottom );
1042   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1043 }
1044
1045 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1046 {
1047 }
1048
1049 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1050 {
1051   if ( myPrefs )
1052     return myPrefs;
1053
1054   SalomeApp_Application* that = (SalomeApp_Application*)this;
1055
1056   if ( !_prefs_ && crt )
1057   {
1058     _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1059     that->createPreferences( _prefs_ );
1060   }
1061
1062   that->myPrefs = _prefs_;
1063
1064   QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1065   for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1066   {
1067     if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1068       continue;
1069
1070     SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1071
1072     QStringList modNameList;
1073     app->modules( modNameList, false );
1074     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1075     {
1076       int id = _prefs_->addPreference( *it );
1077       _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1078     }
1079
1080     ModuleList modList;
1081     app->modules( modList );
1082     for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1083     {
1084       SalomeApp_Module* mod = 0;
1085       if ( itr.current()->inherits( "SalomeApp_Module" ) )
1086         mod = (SalomeApp_Module*)itr.current();
1087
1088       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1089         mod->createPreferences();
1090     }
1091   }
1092
1093   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1094            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1095
1096   return myPrefs;
1097 }
1098
1099 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1100 {
1101   CAM_Application::moduleAdded( mod );
1102
1103   SalomeApp_Module* salomeMod = 0;
1104   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1105     salomeMod = (SalomeApp_Module*)mod;
1106
1107   if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1108     salomeMod->createPreferences();
1109 }
1110
1111 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1112 {
1113   if ( !pref )
1114     return;
1115
1116   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1117
1118   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1119
1120   int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1121   for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1122   {
1123     pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1124                          SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1125   }
1126   pref->setProperty( obGroup, "columns", 1 );
1127
1128   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1129
1130   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1131
1132   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1133   pref->setProperty( occGroup, "columns", 1 );
1134   pref->setProperty( vtkGroup, "columns", 1 );
1135
1136   pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1137                        SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1138   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1139                        SalomeApp_Preferences::Color, "OCCViewer", "background" );
1140
1141   pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1142                        SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1143   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1144                        SalomeApp_Preferences::Color, "VTKViewer", "background" );
1145 }
1146
1147 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1148 {
1149   SUIT_ResourceMgr* resMgr = resourceMgr();
1150   if ( !resMgr )
1151     return;
1152
1153   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1154   {
1155     int sz = resMgr->integerValue( sec, param, -1 );
1156     QPtrList<SUIT_ViewManager> lst;
1157     viewManagers( OCCViewer_Viewer::Type(), lst );
1158     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1159     {
1160       SUIT_ViewModel* vm = it.current()->getViewModel();
1161       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1162         continue;
1163
1164       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1165       occVM->setTrihedronSize( sz );
1166       occVM->getAISContext()->UpdateCurrentViewer();
1167     }
1168   }
1169 }
1170
1171 void SalomeApp_Application::afterCloseDoc()
1172 {
1173   updateWindows();
1174
1175   CAM_Application::afterCloseDoc();
1176 }
1177
1178 CORBA::ORB_var SalomeApp_Application::orb()
1179 {
1180   ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1181   static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1182   return _orb;
1183 }
1184
1185 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1186 {
1187   static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1188   return _sm;
1189 }
1190
1191 SALOME_NamingService* SalomeApp_Application::namingService()
1192 {
1193   static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1194   return _ns;
1195 }
1196
1197 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1198 {
1199   static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1200   return _lcc;
1201 }
1202
1203 QString SalomeApp_Application::defaultEngineIOR()
1204 {
1205   // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1206   QString anIOR( "" );
1207   CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1208   if ( !CORBA::is_nil( anEngine ) )
1209     anIOR = orb()->object_to_string( anEngine );
1210   return anIOR;
1211 }
1212
1213 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1214 {
1215   iconMap.clear();
1216
1217   SUIT_ResourceMgr* resMgr = resourceMgr();
1218   if ( !resMgr )
1219     return;
1220
1221   QStringList modList;
1222   modules( modList, false );
1223
1224   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1225   {
1226     QString modName = *it;
1227     QString modIntr = moduleName( modName );
1228     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1229
1230     if ( modIcon.isEmpty() )
1231       continue;
1232
1233     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1234       modIcon += QString( ".png" );
1235
1236     iconMap.insert( modName, modIcon );
1237   }
1238 }
1239
1240 void SalomeApp_Application::updateModuleActions()
1241 {
1242   QString modName;
1243   if ( activeModule() )
1244     modName = activeModule()->moduleName();
1245
1246   if ( myActions.contains( modName ) )
1247     myActions[modName]->setOn( true );
1248 }
1249
1250 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1251 {
1252   winMap.clear();
1253   if ( !activeStudy() )
1254     return;
1255
1256   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1257     ((SalomeApp_Module*)activeModule())->windows( winMap );
1258   else
1259     defaultWindows( winMap );
1260 }
1261
1262 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1263 {
1264   lst.clear();
1265   if ( !activeStudy() )
1266     return;
1267
1268   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1269     ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1270   else
1271     defaultViewManagers( lst );
1272 }
1273
1274 void SalomeApp_Application::updateWindows()
1275 {
1276   QMap<int, int> winMap;
1277   currentWindows( winMap );
1278
1279   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1280     getWindow( it.key() );
1281
1282   loadWindowsGeometry();
1283
1284   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1285     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1286 }
1287
1288 void SalomeApp_Application::updateViewManagers()
1289 {
1290   QStringList lst;
1291   currentViewManagers( lst );
1292
1293   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1294     getViewManager( *it, true );
1295 }
1296
1297 void SalomeApp_Application::loadWindowsGeometry()
1298 {
1299   QtxDockAction* dockMgr = 0;
1300
1301   QAction* a = action( ViewWindowsId );
1302   if ( a && a->inherits( "QtxDockAction" ) )
1303     dockMgr = (QtxDockAction*)a;
1304
1305   if ( !dockMgr )
1306     return;
1307
1308   QString modName;
1309   if ( activeModule() )
1310     modName = moduleLibrary( activeModule()->moduleName(), false );
1311
1312   QString section = QString( "windows_geometry" );
1313   if ( !modName.isEmpty() )
1314     section += QString( "." ) + modName;
1315
1316   dockMgr->loadGeometry( resourceMgr(), section, false );
1317   dockMgr->restoreGeometry();
1318 }
1319
1320 void SalomeApp_Application::saveWindowsGeometry()
1321 {
1322   QtxDockAction* dockMgr = 0;
1323
1324   QAction* a = action( ViewWindowsId );
1325   if ( a && a->inherits( "QtxDockAction" ) )
1326     dockMgr = (QtxDockAction*)a;
1327
1328   if ( !dockMgr )
1329     return;
1330
1331   QString modName;
1332   if ( activeModule() )
1333     modName = moduleLibrary( activeModule()->moduleName(), false );
1334
1335   QString section = QString( "windows_geometry" );
1336   if ( !modName.isEmpty() )
1337     section += QString( "." ) + modName;
1338
1339   dockMgr->storeGeometry();
1340   dockMgr->saveGeometry( resourceMgr(), section, false );
1341 }
1342
1343 void SalomeApp_Application::activateWindows()
1344 {
1345   if ( activeStudy() )
1346   {
1347     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1348       itr.data()->activate( activeStudy()->id() );
1349   }
1350 }
1351
1352 void SalomeApp_Application::onProperties()
1353 {
1354   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1355   if( !study )
1356     return;
1357
1358   _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1359   SB->NewCommand();
1360
1361   SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1362   int res = aDlg.exec();
1363   if( res==QDialog::Accepted && aDlg.isChanged() )
1364     SB->CommitCommand();
1365   else
1366     SB->AbortCommand();
1367
1368   //study->updateCaptions();
1369 }
1370
1371 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters, 
1372                                             const QString& caption, QWidget* parent )
1373 {
1374   if ( !parent )
1375     parent = desktop();
1376   QStringList fls = QStringList::split( ";;", filters, false );
1377   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1378 }
1379
1380 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1381 {
1382   if ( !parent )
1383     parent = desktop();
1384   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1385 }
1386
1387 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1388 {
1389   CAM_Application::contextMenuPopup( type, thePopup, title );
1390   thePopup->insertSeparator();
1391   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1392 }
1393
1394 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1395 {
1396   if ( updateModels ) 
1397   {
1398     for ( ModuleListIterator it = modules(); it.current(); ++it )
1399     {    
1400       CAM_DataModel* camDM = it.current()->dataModel();
1401       if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1402         ((SalomeApp_DataModel*)camDM)->update();
1403     }
1404   }
1405   if ( objectBrowser() )
1406     objectBrowser()->updateTree();
1407 }