]> SALOME platform Git repositories - modules/gui.git/blob - src/SalomeApp/SalomeApp_Application.cxx
Salome HOME
Prevent double calling of onDesktopClosing() slot of application
[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 #include "SalomeApp_CheckFileDlg.h"
24
25 #include "SalomeApp_GLSelector.h"
26 #include "SalomeApp_OBSelector.h"
27 #include "SalomeApp_OCCSelector.h"
28 #include "SalomeApp_VTKSelector.h"
29 #include "SalomeApp_SelectionMgr.h"
30
31 #include <LogWindow.h>
32
33 #include <GLViewer_Viewer.h>
34 #include <GLViewer_ViewManager.h>
35
36 #include <Plot2d_ViewManager.h>
37 #include <SPlot2d_ViewModel.h>
38
39 #include <OCCViewer_ViewManager.h>
40 #include <SOCC_ViewModel.h>
41
42 #include <SVTK_ViewModel.h>
43 #include <SVTK_ViewManager.h>
44
45 #include <STD_TabDesktop.h>
46
47 #include "STD_LoadStudiesDlg.h"
48
49 #include <SUIT_Tools.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_Accel.h>
52
53 #include <QtxToolBar.h>
54 #include <QtxMRUAction.h>
55 #include <QtxDockAction.h>
56 #include <QtxResourceEdit.h>
57
58 #include <OB_Browser.h>
59
60 #include <PythonConsole_PyConsole.h>
61
62 #include <SUIT_FileDlg.h>
63 #include <SUIT_MessageBox.h>
64 #include <SUIT_ResourceMgr.h>
65 #include <SUIT_ActionOperation.h>
66
67 #include <Utils_ORB_INIT.hxx>
68 #include <Utils_SINGLETON.hxx>
69 #include <SALOME_ModuleCatalog_impl.hxx>
70 #include <SALOME_LifeCycleCORBA.hxx>
71
72 #include <qmap.h>
73 #include <qdir.h>
74 #include <qlabel.h>
75 #include <qimage.h>
76 #include <qaction.h>
77 #include <qmenubar.h>
78 #include <qcombobox.h>
79 #include <qmessagebox.h>
80 #include <qapplication.h>
81 #include <qlistbox.h>
82 #include <qregexp.h>
83
84 #include "SALOMEDS_StudyManager.hxx"
85
86 #include "SALOME_ListIteratorOfListIO.hxx"
87 #include "SALOME_ListIO.hxx"
88
89 #include "ToolsGUI_CatalogGeneratorDlg.h"
90 #include "ToolsGUI_RegWidget.h"
91
92 #define OBJECT_BROWSER_WIDTH 300
93
94 /*!Image for empty icon.*/
95 static const char* imageEmptyIcon[] = {
96 "20 20 1 1",
97 ".      c None",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "....................",
111 "....................",
112 "....................",
113 "....................",
114 "....................",
115 "....................",
116 "....................",
117 "...................."};
118
119 /*!Create new instance of SalomeApp_Application.*/
120 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
121 {
122   return new SalomeApp_Application();
123 }
124
125 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
126
127 /*
128   Class       : SalomeApp_Application
129   Description : Application containing SalomeApp module
130 */
131
132 /*!Constructor.*/
133 SalomeApp_Application::SalomeApp_Application()
134 : CAM_Application( false ),
135 myPrefs( 0 )
136 {
137   STD_TabDesktop* desk = new STD_TabDesktop();
138
139   setDesktop( desk );
140
141   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
142   QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
143
144   desktop()->setIcon( aLogo );
145   desktop()->setDockableMenuBar( true );
146   desktop()->setDockableStatusBar( false );
147
148   // base logo (salome itself)
149   desktop()->addLogo( "_app_base",  aResMgr->loadPixmap( "SalomeApp", tr( "APP_BASE_LOGO" ), false ) );
150   // extra logo (salome-based application)
151   desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "SalomeApp", tr( "APP_EXTRA_LOGO" ), false ) );
152
153   clearViewManagers();
154
155   mySelMgr = new SalomeApp_SelectionMgr( this );
156
157   myAccel = new SUIT_Accel( desktop() );
158   myAccel->setActionKey( SUIT_Accel::PanLeft,     CTRL+Key_Left,     OCCViewer_Viewer::Type() );
159   myAccel->setActionKey( SUIT_Accel::PanRight,    CTRL+Key_Right,    OCCViewer_Viewer::Type() );
160   myAccel->setActionKey( SUIT_Accel::PanUp,       CTRL+Key_Up,       OCCViewer_Viewer::Type() );
161   myAccel->setActionKey( SUIT_Accel::PanDown,     CTRL+Key_Down,     OCCViewer_Viewer::Type() );
162   myAccel->setActionKey( SUIT_Accel::ZoomIn,      CTRL+Key_Plus,     OCCViewer_Viewer::Type() );
163   myAccel->setActionKey( SUIT_Accel::ZoomOut,     CTRL+Key_Minus,    OCCViewer_Viewer::Type() );
164   myAccel->setActionKey( SUIT_Accel::ZoomFit,     CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
165   myAccel->setActionKey( SUIT_Accel::RotateLeft,  ALT+Key_Left,      OCCViewer_Viewer::Type() );
166   myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right,     OCCViewer_Viewer::Type() );
167   myAccel->setActionKey( SUIT_Accel::RotateUp,    ALT+Key_Up,        OCCViewer_Viewer::Type() );
168   myAccel->setActionKey( SUIT_Accel::RotateDown,  ALT+Key_Down,      OCCViewer_Viewer::Type() );
169   myAccel->setActionKey( SUIT_Accel::PanLeft,     CTRL+Key_Left,     SVTK_Viewer::Type() );
170   myAccel->setActionKey( SUIT_Accel::PanRight,    CTRL+Key_Right,    SVTK_Viewer::Type() );
171   myAccel->setActionKey( SUIT_Accel::PanUp,       CTRL+Key_Up,       SVTK_Viewer::Type() );
172   myAccel->setActionKey( SUIT_Accel::PanDown,     CTRL+Key_Down,     SVTK_Viewer::Type() );
173   myAccel->setActionKey( SUIT_Accel::ZoomIn,      CTRL+Key_Plus,     SVTK_Viewer::Type() );
174   myAccel->setActionKey( SUIT_Accel::ZoomOut,     CTRL+Key_Minus,    SVTK_Viewer::Type() );
175   myAccel->setActionKey( SUIT_Accel::ZoomFit,     CTRL+Key_Asterisk, SVTK_Viewer::Type() );
176   myAccel->setActionKey( SUIT_Accel::RotateLeft,  ALT+Key_Left,      SVTK_Viewer::Type() );
177   myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right,     SVTK_Viewer::Type() );
178   myAccel->setActionKey( SUIT_Accel::RotateUp,    ALT+Key_Up,        SVTK_Viewer::Type() );
179   myAccel->setActionKey( SUIT_Accel::RotateDown,  ALT+Key_Down,      SVTK_Viewer::Type() );
180
181   connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
182 }
183
184 /*!Destructor.
185  *\li Save window geometry.
186  *\li Save desktop geometry.
187  *\li Save resource maneger.
188  *\li Delete selection manager.
189  *\li Destroy event filter.
190  */
191 SalomeApp_Application::~SalomeApp_Application()
192 {
193   saveWindowsGeometry();
194
195   if ( resourceMgr() )
196   {
197     if ( desktop() )
198       desktop()->saveGeometry( resourceMgr(), "desktop" );
199     resourceMgr()->save();
200   }
201
202   delete mySelMgr;
203
204   SalomeApp_EventFilter::Destroy();
205 }
206
207 /*!Start application.*/
208 void SalomeApp_Application::start()
209 {
210   if ( desktop() )
211     desktop()->loadGeometry( resourceMgr(), "desktop" );
212
213   CAM_Application::start();
214
215   QAction* a = action( ViewWindowsId );
216   if ( a && a->inherits( "QtxDockAction" ) )
217     ((QtxDockAction*)a)->setAutoPlace( true );
218
219   SalomeApp_EventFilter::Init();
220
221   updateWindows();
222   updateViewManagers();
223
224   putInfo( "" );
225 }
226
227 /*!Gets application name.*/
228 QString SalomeApp_Application::applicationName() const
229 {
230   return tr( "APP_NAME" );
231 }
232
233 /*!Gets application version.*/
234 QString SalomeApp_Application::applicationVersion() const
235 {
236   static QString _app_version;
237
238   if ( _app_version.isEmpty() )
239   {
240     QString resVersion = tr( "APP_VERSION" );
241     if ( resVersion != "APP_VERSION" )
242     {
243       _app_version = resVersion;
244     }
245     else
246     {
247       QString path( ::getenv( "GUI_ROOT_DIR" ) );
248       if ( !path.isEmpty() )
249         path += QDir::separator();
250       path += QString( "bin/salome/VERSION" );
251
252       QFile vf( path );
253       if ( vf.open( IO_ReadOnly ) )
254       {
255         QString line;
256         vf.readLine( line, 1024 );
257         vf.close();
258
259         if ( !line.isEmpty() )
260         {
261           while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
262             line.remove( line.length() - 1, 1 );
263
264           int idx = line.findRev( ":" );
265           if ( idx != -1 )
266             _app_version = line.mid( idx + 1 ).stripWhiteSpace();
267         }
268       }
269     }
270   }
271   return _app_version;
272 }
273
274 /*!Load module by \a name.*/
275 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
276 {
277   CAM_Module* mod = CAM_Application::loadModule( name );
278   if ( mod )
279   {
280     connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
281     connect( this, SIGNAL( studySaved() ),  mod, SLOT( onModelSaved() ) );
282     connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
283   }
284   return mod;
285 }
286
287 /*!Activate module by \a modName*/
288 bool SalomeApp_Application::activateModule( const QString& modName )
289 {
290   QString actName;
291   CAM_Module* prevMod = activeModule();
292
293   if ( prevMod )
294     actName = prevMod->moduleName();
295
296   if ( actName == modName )
297     return true;
298
299   putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
300
301   saveWindowsGeometry();
302
303   bool status = CAM_Application::activateModule( modName );
304
305   updateModuleActions();
306
307   putInfo( "" );
308
309   if ( !status )
310     return false;
311
312   updateWindows();
313   updateViewManagers();
314
315   return true;
316 }
317
318 /*!Gets selection manager.*/
319 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
320 {
321   return mySelMgr;
322 }
323
324 /*!Create actions:*/
325 void SalomeApp_Application::createActions()
326 {
327   STD_Application::createActions();
328
329   SUIT_Desktop* desk = desktop();
330   SUIT_ResourceMgr* resMgr = resourceMgr();
331
332   //! Dump study
333   createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
334                 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
335                 0, desk, false, this, SLOT( onDumpStudy() ) );
336
337   //! Load script
338   createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
339                 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
340                 0, desk, false, this, SLOT( onLoadScript() ) );
341
342   //! Properties
343   createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
344                 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
345                 0, desk, false, this, SLOT( onProperties() ) );
346
347   //! Preferences
348   createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
349                 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
350                 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
351
352   //! Catalog Generator
353   createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ),  QIconSet(),
354                 tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ),
355                 0, desk, false, this, SLOT( onCatalogGen() ) );
356
357   //! Registry Display
358   createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ),  QIconSet(),
359                 tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ),
360                 0, desk, false, this, SLOT( onRegDisplay() ) );
361
362   //! MRU
363   QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
364   connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
365   registerAction( MRUId, mru );
366
367   //! default icon for neutral point ('SALOME' module)
368   QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
369   if ( defIcon.isNull() )
370     defIcon = QPixmap( imageEmptyIcon );
371
372   //! default icon for any module
373   QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
374   if ( modIcon.isNull() )
375     modIcon = QPixmap( imageEmptyIcon );
376
377   QToolBar* modTBar = new QtxToolBar( true, desk );
378   modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
379
380   QActionGroup* modGroup = new QActionGroup( this );
381   modGroup->setExclusive( true );
382   modGroup->setUsesDropDown( true );
383
384   QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
385                              tr( "PRP_APP_MODULE" ), 0, desk, true );
386   modGroup->add( a );
387   myActions.insert( QString(), a );
388
389   QMap<QString, QString> iconMap;
390   moduleIconNames( iconMap );
391
392   const int iconSize = 20;
393
394   modGroup->addTo( modTBar );
395   modTBar->addSeparator();
396
397   QStringList modList;
398   modules( modList, false );
399
400   for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
401   {
402     if ( (*it).isEmpty() )
403       continue;
404
405     QString iconName;
406     if ( iconMap.contains( *it ) )
407       iconName = iconMap[*it];
408
409     QString modName = moduleName( *it );
410
411     QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
412     if ( icon.isNull() )
413       icon = modIcon;
414
415     icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
416
417     QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
418     a->addTo( modTBar );
419     modGroup->add( a );
420
421     myActions.insert( *it, a );
422   }
423
424   SUIT_Tools::simplifySeparators( modTBar );
425
426   //! New window
427
428   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
429   int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
430   createMenu( separator(), windowMenu, -1, 1 );
431
432   QMap<int, int> accelMap;
433   accelMap[NewGLViewId]  = ALT+Key_G;
434   accelMap[NewPlot2dId]  = ALT+Key_P;
435   accelMap[NewOCCViewId] = ALT+Key_O;
436   accelMap[NewVTKViewId] = ALT+Key_K;
437
438   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
439   {
440     QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
441                                tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
442                                tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
443                                accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
444     createMenu( a, newWinMenu, -1 );
445   }
446   connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
447
448   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
449
450   createMenu( DumpStudyId, fileMenu, 10, -1 );
451   createMenu( separator(), fileMenu, -1, 15, -1 );
452   createMenu( LoadScriptId, fileMenu, 10, -1 );
453   createMenu( separator(), fileMenu, -1, 15, -1 );
454   createMenu( PropertiesId, fileMenu, 10, -1 );
455   createMenu( separator(), fileMenu, -1, 15, -1 );
456   createMenu( PreferencesId, fileMenu, 15, -1 );
457   createMenu( separator(), fileMenu, -1, 15, -1 );
458
459   int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, -1, 50 );
460   createMenu( CatalogGenId, toolsMenu, 10, -1 );
461   createMenu( RegDisplayId, toolsMenu, 10, -1 );
462   createMenu( separator(), toolsMenu, -1, 15, -1 );
463
464   /*
465   createMenu( separator(), fileMenu, -1, 100, -1 );
466   createMenu( MRUId, fileMenu, 100, -1 );
467   createMenu( separator(), fileMenu, -1, 100, -1 );
468   */
469 }
470
471 /*!On module activation action.*/
472 void SalomeApp_Application::onModuleActivation( QAction* a )
473 {
474   if ( !a )
475     return;
476
477   QString modName = a->menuText();
478   if ( modName == tr( "APP_NAME" ) )
479     modName = QString::null;
480
481   // Force user to create/open a study before module activation
482   QMap<QString, QString> iconMap;
483   moduleIconNames( iconMap );
484   QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
485   if ( icon.isNull() )
486     icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
487
488   bool cancelled = false;
489   while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
490     SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
491     int res = aDlg.exec();
492
493     switch ( res ){
494     case 1:
495       onNewDoc();
496       break;
497     case 2:
498       onOpenDoc();
499       break;
500     case 3:
501       //onLoadStudy();
502       //break;
503     case 0:
504     default:
505       putInfo( tr("INF_CANCELLED") );
506       myActions[QString()]->setOn( true );
507       cancelled = true;
508     }
509   }
510
511   if ( !cancelled )
512     activateModule( modName );
513 }
514
515 /*!Default module activation.*/
516 QString SalomeApp_Application::defaultModule() const
517 {
518   QStringList aModuleNames;
519   modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
520   //! If there's the one and only module --> activate it automatically
521   //! TODO: Possible improvement - default module can be taken from preferences
522   return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
523 }
524
525 /*!On new window slot.*/
526 void SalomeApp_Application::onNewWindow()
527 {
528   const QObject* obj = sender();
529   if ( !obj || !obj->inherits( "QAction" ) )
530     return;
531
532   QString type;
533   int id = actionId( (QAction*)obj );
534   switch ( id )
535   {
536   case NewGLViewId:
537     type = GLViewer_Viewer::Type();
538     break;
539   case NewPlot2dId:
540     type = Plot2d_Viewer::Type();
541     break;
542   case NewOCCViewId:
543     type = OCCViewer_Viewer::Type();
544     break;
545   case NewVTKViewId:
546     type = SVTK_Viewer::Type();
547     break;
548   }
549
550   if ( !type.isEmpty() )
551     createViewManager( type );
552 }
553
554 //=======================================================================
555 //  name    : onNewDoc
556 /*! Purpose : SLOT. Create new document*/
557 //=======================================================================
558 void SalomeApp_Application::onNewDoc()
559 {
560   SUIT_Study* study = activeStudy();
561
562   saveWindowsGeometry();
563
564   CAM_Application::onNewDoc();
565
566   if ( !study ) // new study will be create in THIS application
567   {
568     updateWindows();
569     updateViewManagers();
570   }
571 }
572
573 //=======================================================================
574 // name    : onOpenDoc
575 /*! Purpose : SLOT. Open new document*/
576 //=======================================================================
577 void SalomeApp_Application::onOpenDoc()
578 {
579   SUIT_Study* study = activeStudy();
580   saveWindowsGeometry();
581
582   CAM_Application::onOpenDoc();
583
584   if ( !study ) // new study will be create in THIS application
585   {
586     updateWindows();
587     updateViewManagers();
588   }
589 }
590
591 /*! Purpose : SLOT. Open new document with \a aName.*/
592 bool SalomeApp_Application::onOpenDoc( const QString& aName )
593 {
594   bool res = CAM_Application::onOpenDoc( aName );
595
596   QAction* a = action( MRUId );
597   if ( a && a->inherits( "QtxMRUAction" ) )
598   {
599     QtxMRUAction* mru = (QtxMRUAction*)a;
600     if ( res )
601       mru->insert( aName );
602     else
603       mru->remove( aName );
604   }
605   return res;
606 }
607
608 /*!SLOT. Load document.*/
609 void SalomeApp_Application::onLoadDoc()
610 {
611   QString name, studyname, ext;
612
613   STD_LoadStudiesDlg aDlg( desktop(), TRUE);
614
615   std::vector<std::string> List = studyMgr()->GetOpenStudies();
616
617   SUIT_Session* aSession = SUIT_Session::session();
618   QPtrList<SUIT_Application> aAppList = aSession->applications();
619   SUIT_Application* aApp = 0;
620
621   for (unsigned int ind = 0; ind < List.size(); ind++) {
622      studyname = List[ind].c_str();
623      //Add to list only unloaded studies
624      bool isAlreadyOpen = false;
625      for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
626        {
627          aApp = it.current();
628          if(!aApp || !aApp->activeStudy()) continue;
629          if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
630        }
631
632      if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
633   }
634
635   int retVal = aDlg.exec();
636   studyname = aDlg.ListComponent->currentText();
637
638   if (retVal == QDialog::Rejected)
639     return;
640
641   if ( studyname.isNull() || studyname.isEmpty() )
642     return;
643
644   name = studyname;
645   name.replace( QRegExp(":"), "/" );
646
647   if(onLoadDoc(name)) {
648      updateWindows();
649      updateViewManagers();
650      updateObjectBrowser(true);
651   }
652 }
653
654
655 /*!SLOT. Load document with \a aName.*/
656 bool SalomeApp_Application::onLoadDoc( const QString& aName )
657 {
658   bool res = CAM_Application::onLoadDoc( aName );
659
660   /*jfa tmp:QAction* a = action( MRUId );
661   if ( a && a->inherits( "QtxMRUAction" ) )
662   {
663     QtxMRUAction* mru = (QtxMRUAction*)a;
664     if ( res )
665       mru->insert( aName );
666     else
667       mru->remove( aName );
668   }*/
669   return res;
670 }
671
672 /*!Private SLOT. Selection.*/
673 void SalomeApp_Application::onSelection()
674 {
675   onSelectionChanged();
676
677   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
678     ((SalomeApp_Module*)activeModule())->selectionChanged();
679 }
680
681 /*!SLOT. Copy objects to study maneger from selection maneger..*/
682 void SalomeApp_Application::onCopy()
683 {
684   SALOME_ListIO list;
685   SalomeApp_SelectionMgr* mgr = selectionMgr();
686   mgr->selectedObjects(list);
687
688   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
689   if(study == NULL) return;
690
691   _PTR(Study) stdDS = study->studyDS();
692   if(!stdDS) return;
693
694   SALOME_ListIteratorOfListIO it( list );
695   if(it.More())
696     {
697       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
698       try {
699         studyMgr()->Copy(so);
700         onSelectionChanged();
701       }
702       catch(...) {
703       }
704     }
705 }
706
707 /*!SLOT. Paste objects to study maneger from selection manager.*/
708 void SalomeApp_Application::onPaste()
709 {
710   SALOME_ListIO list;
711   SalomeApp_SelectionMgr* mgr = selectionMgr();
712   mgr->selectedObjects(list);
713
714   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
715   if(study == NULL) return;
716
717   _PTR(Study) stdDS = study->studyDS();
718   if(!stdDS) return;
719
720   SALOME_ListIteratorOfListIO it( list );
721   if(it.More())
722     {
723       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
724       try {
725         studyMgr()->Paste(so);
726         updateObjectBrowser( true );
727         updateActions(); //SRN: BugID IPAL9377, case 3
728       }
729       catch(...) {
730       }
731     }
732 }
733
734 /*!Sets enable or disable some actions on selection changed.*/
735 void SalomeApp_Application::onSelectionChanged()
736 {
737    SALOME_ListIO list;
738    SalomeApp_SelectionMgr* mgr = selectionMgr();
739    mgr->selectedObjects(list);
740
741    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
742    if(study == NULL) return;
743
744    _PTR(Study) stdDS = study->studyDS();
745    if(!stdDS) return;
746
747    QAction* qaction;
748
749    SALOME_ListIteratorOfListIO it( list );
750    if(it.More() && list.Extent() == 1)
751    {
752       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
753
754       qaction = action(EditCopyId);
755       if( so && studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
756       else qaction->setEnabled(false);
757
758       qaction = action(EditPasteId);
759       if( so && studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
760       else qaction->setEnabled(false);
761    }
762    else {
763      qaction = action(EditCopyId);
764      qaction->setEnabled(false);
765      qaction = action(EditPasteId);
766      qaction->setEnabled(false);
767    }
768 }
769
770 /*!Update object browser.*/
771 void SalomeApp_Application::onRefresh()
772 {
773   updateObjectBrowser( true );
774 }
775
776 /*!Delete references.*/
777 void SalomeApp_Application::onDeleteReferences()
778 {
779   SALOME_ListIO aList;
780   SalomeApp_SelectionMgr* mgr = selectionMgr();
781   mgr->selectedObjects(aList);
782
783   if (aList.Extent() < 1) return;
784
785   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
786   _PTR(Study) aStudyDS = aStudy->studyDS();
787   _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder();
788   _PTR(SObject) anObj;
789
790   for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
791     {
792       if ( it.Value()->hasEntry() )
793         {
794           _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
795           if ( aSObject->ReferencedObject(anObj) )
796             aStudyBuilder->RemoveReference(aSObject);
797         }
798     }
799
800   updateObjectBrowser();
801 }
802
803 /*!Private SLOT. */
804 void SalomeApp_Application::onOpenWith()
805 {
806   QApplication::setOverrideCursor( Qt::waitCursor );
807   SALOME_ListIO aList;
808   SalomeApp_SelectionMgr* mgr = selectionMgr();
809   mgr->selectedObjects(aList);
810   if (aList.Extent() != 1)
811     {
812       QApplication::restoreOverrideCursor();
813       return;
814     }
815   Handle(SALOME_InteractiveObject) aIObj = aList.First();
816   QString aModuleName(aIObj->getComponentDataType());
817   QString aModuleTitle = moduleTitle(aModuleName);
818   activateModule(aModuleTitle);
819   QApplication::restoreOverrideCursor();
820 }
821
822 bool SalomeApp_Application::useStudy(const QString& theName)
823 {
824   createEmptyStudy();
825   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
826   bool res = false;
827   if (aStudy)
828     res = aStudy->loadDocument( theName );
829   updateDesktopTitle();
830   updateCommandsStatus();
831   return res;
832 }
833
834 /*!Set active study.
835  *\param study - SUIT_Study.
836  */
837 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
838 {
839   CAM_Application::setActiveStudy( study );
840
841   activateWindows();
842 }
843
844 //=======================================================================
845 // name    : createNewStudy
846 /*! Purpose : Create new study*/
847 //=======================================================================
848 SUIT_Study* SalomeApp_Application::createNewStudy()
849 {
850   SalomeApp_Study* aStudy = new SalomeApp_Study( this );
851
852   // Set up processing of major study-related events
853   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
854   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
855   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
856   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
857
858   return aStudy;
859 }
860
861 //=======================================================================
862 // name    : createNewStudy
863 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
864 //=======================================================================
865 void SalomeApp_Application::updateCommandsStatus()
866 {
867   CAM_Application::updateCommandsStatus();
868
869   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
870   {
871     QAction* a = action( id );
872     if ( a )
873       a->setEnabled( activeStudy() );
874   }
875
876   // Dump study menu
877   QAction* a = action( DumpStudyId );
878   if ( a )
879     a->setEnabled( activeStudy() );
880
881   // Load script menu
882   a = action( LoadScriptId );
883   if ( a )
884     a->setEnabled( activeStudy() );
885
886   a = action( PropertiesId );
887   if( a )
888     a->setEnabled( activeStudy() );
889
890   a = action(EditCopyId);
891   a->setEnabled(false);
892   a = action(EditPasteId);
893   a->setEnabled(false);
894 }
895
896 //=======================================================================
897 // name    : onHelpAbout
898 /*! Purpose : SLOT. Display "About" message box*/
899 //=======================================================================
900 void SalomeApp_Application::onHelpAbout()
901 {
902   SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
903   dlg->exec();
904   delete dlg;
905 }
906
907 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
908 {
909   QWidget* wid = 0;
910
911   int sId = studyId;
912   if ( sId < 0 )
913   {
914     if ( !activeStudy() )
915       return 0;
916     else
917       sId = activeStudy()->id();
918   }
919
920   if ( myWindows.contains( flag ) )
921     wid = myWindows[flag]->widget( sId );
922
923   return wid;
924 }
925
926 /*!Adds window to application.
927  *\param wid - QWidget
928  *\param flag - key wor window
929  *\param studyId - study id
930  * Flag used how identificator of window in windows list.
931  */
932 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
933 {
934   if ( !wid )
935     return;
936
937   int sId = studyId;
938   if ( sId < 0 )
939   {
940     if ( !activeStudy() )
941       return;
942     else
943       sId = activeStudy()->id();
944   }
945
946   if ( !myWindows.contains( flag ) )
947   {
948     QMap<int, int> winMap;
949     currentWindows( winMap );
950
951     myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
952     if ( winMap.contains( flag ) )
953       desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
954
955     myWindows[flag]->setResizeEnabled( true );
956     myWindows[flag]->setCloseMode( QDockWindow::Always );
957     myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
958   }
959
960   QFont f;
961   if( wid->inherits( "PythonConsole" ) )
962     f = ( ( PythonConsole* )wid )->font();
963   else
964     f = wid->font();
965
966   myWindows[flag]->insert( sId, wid );
967   wid->setFont( f );
968
969   setWindowShown( flag, !myWindows[flag]->isEmpty() );
970 }
971
972 /*!Remove window from application.
973  *\param flag - key wor window
974  *\param studyId - study id
975  * Flag used how identificator of window in windows list.
976  */
977 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
978 {
979   if ( !myWindows.contains( flag ) )
980     return;
981
982   int sId = studyId;
983   if ( sId < 0 )
984   {
985     if ( !activeStudy() )
986       return;
987     else
988       sId = activeStudy()->id();
989   }
990
991   QWidget* wid = myWindows[flag]->widget( sId );
992   myWindows[flag]->remove( sId );
993   delete wid;
994
995   setWindowShown( flag, !myWindows[flag]->isEmpty() );
996 }
997
998 /*!Gets window.
999  *\param flag - key wor window
1000  *\param studyId - study id
1001  * Flag used how identificator of window in windows list.
1002  */
1003 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
1004 {
1005   QWidget* wid = window( flag, studyId );
1006   if ( !wid )
1007     addWindow( wid = createWindow( flag ), flag, studyId );
1008
1009   return wid;
1010 }
1011
1012 /*!Check is window visible?(with identificator \a type)*/
1013 bool SalomeApp_Application::isWindowVisible( const int type ) const
1014 {
1015   bool res = false;
1016   if ( myWindows.contains( type ) )
1017   {
1018     SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
1019     res = desk && desk->appropriate( myWindows[type] );
1020   }
1021   return res;
1022 }
1023
1024 /*!Sets window show or hide.
1025  *\param type - window identificator.
1026  *\param on   - true/false (window show/hide)
1027  */
1028 void SalomeApp_Application::setWindowShown( const int type, const bool on )
1029 {
1030   if ( !desktop() || !myWindows.contains( type ) )
1031     return;
1032
1033   QDockWindow* dw = myWindows[type];
1034   desktop()->setAppropriate( dw, on );
1035   on ? dw->show() : dw->hide();
1036 }
1037
1038 OB_Browser* SalomeApp_Application::objectBrowser()
1039 {
1040   OB_Browser* ob = 0;
1041   QWidget* wid = getWindow( WT_ObjectBrowser );
1042   if ( wid->inherits( "OB_Browser" ) )
1043     ob = (OB_Browser*)wid;
1044   return ob;
1045 }
1046
1047 /*!Gets "LogWindow".*/
1048 LogWindow* SalomeApp_Application::logWindow()
1049 {
1050   LogWindow* lw = 0;
1051   QWidget* wid = getWindow( WT_LogWindow );
1052   if ( wid->inherits( "LogWindow" ) )
1053     lw = (LogWindow*)wid;
1054   return lw;
1055 }
1056
1057 /*!Get "PythonConsole"*/
1058 PythonConsole* SalomeApp_Application::pythonConsole()
1059 {
1060   PythonConsole* console = 0;
1061   QWidget* wid = getWindow( WT_PyConsole );
1062   if ( wid->inherits( "PythonConsole" ) )
1063     console = (PythonConsole*)wid;
1064   return console;
1065 }
1066
1067 /*!Gets preferences.*/
1068 SalomeApp_Preferences* SalomeApp_Application::preferences() const
1069 {
1070   return preferences( false );
1071 }
1072
1073 /*!Gets view manager*/
1074 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
1075 {
1076   SUIT_ViewManager* aVM = viewManager( vmType );
1077   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1078
1079   if ( anActiveVM && anActiveVM->getType() == vmType )
1080     aVM = anActiveVM;
1081
1082   if ( aVM && create )
1083   {
1084     if ( !aVM->getActiveView() )
1085       aVM->createView();
1086     else
1087       aVM->getActiveView()->setFocus();
1088   }
1089   else if ( create )
1090     aVM = createViewManager( vmType );
1091
1092   return aVM;
1093 }
1094
1095 /*!Create view manager.*/
1096 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
1097 {
1098   SUIT_ResourceMgr* resMgr = resourceMgr();
1099
1100   SUIT_ViewManager* viewMgr = 0;
1101   if ( vmType == GLViewer_Viewer::Type() )
1102   {
1103     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1104     new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1105   }
1106   else if ( vmType == Plot2d_Viewer::Type() )
1107   {
1108     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1109     viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
1110   }
1111   else if ( vmType == OCCViewer_Viewer::Type() )
1112   {
1113     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1114     SOCC_Viewer* vm = new SOCC_Viewer();
1115     vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1116     vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1117     int u( 1 ), v( 1 );
1118     vm->isos( u, v );
1119     u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1120     v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1121     vm->setIsos( u, v );
1122     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1123     new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1124   }
1125   else if ( vmType == SVTK_Viewer::Type() )
1126   {
1127     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1128     SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1129     if( vm )
1130     {
1131       vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1132       vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1133       new SalomeApp_VTKSelector( vm, mySelMgr );
1134     }
1135   }
1136
1137   if ( !viewMgr )
1138     return 0;
1139
1140   addViewManager( viewMgr );
1141   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1142
1143   if ( viewWin && desktop() )
1144     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1145
1146   connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1147            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1148
1149   return viewMgr;
1150 }
1151
1152 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1153 {
1154   removeViewManager( theVM );
1155 }
1156
1157 /*!Private SLOT. On study created.*/
1158 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1159 {
1160   SUIT_DataObject* aRoot = 0;
1161   if ( theStudy && theStudy->root() )
1162   {
1163     aRoot = theStudy->root();
1164     //aRoot->setName( tr( "DATA_MODELS" ) );
1165   }
1166   if ( objectBrowser() != 0 )
1167     objectBrowser()->setRootObject( aRoot );
1168
1169   activateModule( defaultModule() );
1170
1171   activateWindows();
1172 }
1173
1174 /*!Private SLOT. On study opened.*/
1175 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1176 {
1177   SUIT_DataObject* aRoot = 0;
1178   if ( theStudy && theStudy->root() )
1179   {
1180     aRoot = theStudy->root();
1181     //aRoot->dump();
1182   }
1183   if ( objectBrowser() != 0 ) {
1184     objectBrowser()->setRootObject( aRoot );
1185   }
1186
1187   activateModule( defaultModule() );
1188
1189   activateWindows();
1190
1191   emit studyOpened();
1192 }
1193
1194 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1195 {
1196   emit studySaved();
1197 }
1198
1199 /*!Private SLOT. On study closed.*/
1200 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1201 {
1202   emit studyClosed();
1203
1204   activateModule( "" );
1205
1206   saveWindowsGeometry();
1207 }
1208
1209 /*!Private SLOT. On dump study.*/
1210 void SalomeApp_Application::onDumpStudy( )
1211 {
1212   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1213   if ( !appStudy ) return;
1214   _PTR(Study) aStudy = appStudy->studyDS();
1215
1216   QStringList aFilters;
1217   aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1218
1219   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1220   fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1221   fd->setFilters( aFilters );
1222   fd->SetChecked(true);
1223   fd->exec();
1224   QString aFileName = fd->selectedFile();
1225   bool toPublish = fd->IsChecked();
1226   delete fd;
1227
1228   if(!aFileName.isEmpty()) {
1229     QFileInfo aFileInfo(aFileName);
1230     aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1231   }
1232 }
1233
1234 /*!Private SLOT. On load script.*/
1235 void SalomeApp_Application::onLoadScript( )
1236 {
1237   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1238   if ( !appStudy ) return;
1239   _PTR(Study) aStudy = appStudy->studyDS();
1240
1241   if ( aStudy->GetProperties()->IsLocked() ) {
1242     SUIT_MessageBox::warn1 ( desktop(),
1243                              QObject::tr("WRN_WARNING"),
1244                              QObject::tr("WRN_STUDY_LOCKED"),
1245                              QObject::tr("BUT_OK") );
1246     return;
1247   }
1248
1249   QStringList filtersList;
1250   filtersList.append(tr("PYTHON_FILES_FILTER"));
1251   filtersList.append(tr("ALL_FILES_FILTER"));
1252
1253   QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1254
1255   if ( !aFile.isEmpty() )
1256   {
1257     QString command = QString("execfile(\"%1\")").arg(aFile);
1258
1259     PythonConsole* pyConsole = pythonConsole();
1260
1261     if ( pyConsole )
1262       pyConsole->exec( command );
1263   }
1264 }
1265
1266 /*!Private SLOT. On preferences.*/
1267 void SalomeApp_Application::onPreferences()
1268 {
1269   QApplication::setOverrideCursor( Qt::waitCursor );
1270
1271   SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1272
1273   QApplication::restoreOverrideCursor();
1274
1275   if ( !prefDlg )
1276     return;
1277
1278   prefDlg->exec();
1279
1280   delete prefDlg;
1281 }
1282
1283 /*!Private SLOT. On open document with name \a aName.*/
1284 void SalomeApp_Application::onMRUActivated( QString aName )
1285 {
1286   onOpenDoc( aName );
1287 }
1288
1289 /*!Private SLOT. On preferences changed.*/
1290 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1291 {
1292   SalomeApp_Module* sMod = 0;
1293   CAM_Module* mod = module( modName );
1294   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1295     sMod = (SalomeApp_Module*)mod;
1296
1297   if ( sMod )
1298     sMod->preferencesChanged( section, param );
1299   else
1300     preferencesChanged( section, param );
1301 }
1302
1303 /*!Gets file filter.
1304  *\retval QString "(*.hdf)"
1305  */
1306 QString SalomeApp_Application::getFileFilter() const
1307 {
1308   return "(*.hdf)";
1309 }
1310
1311 /*!Remove all windows from study.*/
1312 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1313 {
1314   CAM_Application::beforeCloseDoc( s );
1315
1316   for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1317     removeWindow( itr.key(), s->id() );
1318 }
1319
1320 /*!Update actions.*/
1321 void SalomeApp_Application::updateActions()
1322 {
1323   updateCommandsStatus();
1324 }
1325
1326 /*!Create window.*/
1327 QWidget* SalomeApp_Application::createWindow( const int flag )
1328 {
1329   QWidget* wid = 0;
1330
1331   SUIT_ResourceMgr* resMgr = resourceMgr();
1332
1333   if ( flag == WT_ObjectBrowser )
1334   {
1335     OB_Browser* ob = new OB_Browser( desktop() );
1336     ob->setAutoUpdate( true );
1337     ob->setAutoOpenLevel( 1 );
1338     ob->setCaption( tr( "OBJECT_BROWSER" ) );
1339     ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1340     ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1341
1342     ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1343
1344     bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1345     for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1346     {
1347       ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1348       ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1349                                                    QString().sprintf( "visibility_column_%d", i ), true ) );
1350     }
1351     ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1352
1353     // Create OBSelector
1354     new SalomeApp_OBSelector( ob, mySelMgr );
1355
1356     wid = ob;
1357
1358     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1359   }
1360   else if ( flag == WT_PyConsole )
1361   {
1362     PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1363     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1364     pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1365     wid = pyCons;
1366
1367     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1368   }
1369   else if ( flag == WT_LogWindow )
1370   {
1371     LogWindow* logWin = new LogWindow( desktop() );
1372     logWin->setCaption( tr( "LOG_WINDOW" ) );
1373     wid = logWin;
1374
1375     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1376   }
1377
1378   return wid;
1379 }
1380
1381 /*!Default windows(Object Browser, Python Console).
1382  * Adds to map \a aMap.
1383  */
1384 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1385 {
1386   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1387   aMap.insert( WT_PyConsole, Qt::DockBottom );
1388   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1389 }
1390
1391 /*!Default view manager.*/
1392 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1393 {
1394   /*!Do nothing.*/
1395 }
1396
1397 /*!Gets preferences.
1398  * Create preferences, if \a crt = true.
1399  */
1400 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1401 {
1402   if ( myPrefs )
1403     return myPrefs;
1404
1405   SalomeApp_Application* that = (SalomeApp_Application*)this;
1406
1407   if ( !_prefs_ && crt )
1408   {
1409     _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1410     that->createPreferences( _prefs_ );
1411   }
1412
1413   that->myPrefs = _prefs_;
1414
1415   QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1416   for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1417   {
1418     if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1419       continue;
1420
1421     SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1422
1423     QStringList modNameList;
1424     app->modules( modNameList, false );
1425     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1426     {
1427       int id = _prefs_->addPreference( *it );
1428       _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1429     }
1430
1431     ModuleList modList;
1432     app->modules( modList );
1433     for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1434     {
1435       SalomeApp_Module* mod = 0;
1436       if ( itr.current()->inherits( "SalomeApp_Module" ) )
1437         mod = (SalomeApp_Module*)itr.current();
1438
1439       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1440       {
1441         int modCat = _prefs_->addPreference( mod->moduleName() );
1442         _prefs_->setItemProperty( modCat, "info", QString::null );
1443         mod->createPreferences();
1444       }
1445     }
1446   }
1447
1448   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1449            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1450
1451   return myPrefs;
1452 }
1453
1454 /*!Add new module to application.*/
1455 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1456 {
1457   CAM_Application::moduleAdded( mod );
1458
1459   SalomeApp_Module* salomeMod = 0;
1460   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1461     salomeMod = (SalomeApp_Module*)mod;
1462
1463   if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1464   {
1465     int modCat = myPrefs->addPreference( mod->moduleName() );
1466     myPrefs->setItemProperty( modCat, "info", QString::null );
1467     salomeMod->createPreferences();
1468   }
1469 }
1470
1471 /*!Create preferences.*/
1472 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1473 {
1474   if ( !pref )
1475     return;
1476
1477   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1478
1479   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1480   int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1481   pref->setItemProperty( studyGroup, "columns", 1 );
1482
1483   pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1484   pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1485   int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1486   pref->setItemProperty( undoPref, "min", 1 );
1487   pref->setItemProperty( undoPref, "max", 100 );
1488
1489   int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1490   pref->setItemProperty( extgroup, "columns", 1 );
1491   int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1492   pref->setItemProperty( apppref, "existing", true );
1493   pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1494
1495   pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1496
1497   int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1498   pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1499   pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1500
1501
1502
1503   int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1504   int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1505   for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1506   {
1507     pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1508                          SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1509   }
1510   pref->setItemProperty( defCols, "columns", 1 );
1511
1512   int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1513   pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1514
1515   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1516
1517   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1518
1519   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1520
1521   int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1522
1523   pref->setItemProperty( occGroup, "columns", 1 );
1524   pref->setItemProperty( vtkGroup, "columns", 1 );
1525   pref->setItemProperty( plot2dGroup, "columns", 1 );
1526
1527   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1528                                    SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1529   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1530                        SalomeApp_Preferences::Color, "OCCViewer", "background" );
1531
1532   pref->setItemProperty( occTS, "min", 1 );
1533   pref->setItemProperty( occTS, "max", 150 );
1534
1535   int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1536                                   SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1537   int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1538                                   SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1539
1540   pref->setItemProperty( isoU, "min", 0 );
1541   pref->setItemProperty( isoU, "max", 100000 );
1542
1543   pref->setItemProperty( isoV, "min", 0 );
1544   pref->setItemProperty( isoV, "max", 100000 );
1545
1546   int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1547                                    SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1548   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1549                        SalomeApp_Preferences::Color, "VTKViewer", "background" );
1550
1551   pref->setItemProperty( vtkTS, "min", 1 );
1552   pref->setItemProperty( vtkTS, "max", 150 );
1553
1554   pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1555                        SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1556
1557   int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1558                                             SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" );
1559   QStringList aLegendPosList;
1560   aLegendPosList.append( tr("PREF_LEFT") );
1561   aLegendPosList.append( tr("PREF_RIGHT") );
1562   aLegendPosList.append( tr("PREF_TOP") );
1563   aLegendPosList.append( tr("PREF_BOTTOM") );
1564
1565   QValueList<QVariant> anIndexesList;
1566   anIndexesList.append(0);
1567   anIndexesList.append(1);
1568   anIndexesList.append(2);
1569   anIndexesList.append(3);
1570
1571   pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1572   pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1573
1574   int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1575                                        SalomeApp_Preferences::Selector, "Plot2d", "CurveType" );
1576   QStringList aCurveTypesList;
1577   aCurveTypesList.append( tr("PREF_POINTS") );
1578   aCurveTypesList.append( tr("PREF_LINES") );
1579   aCurveTypesList.append( tr("PREF_SPLINE") );
1580
1581   anIndexesList.clear();
1582   anIndexesList.append(0);
1583   anIndexesList.append(1);
1584   anIndexesList.append(2);
1585
1586   pref->setItemProperty( curveType, "strings", aCurveTypesList );
1587   pref->setItemProperty( curveType, "indexes", anIndexesList );
1588
1589   int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1590                                         SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1591
1592   pref->setItemProperty( markerSize, "min", 0 );
1593   pref->setItemProperty( markerSize, "max", 100 );
1594
1595   QStringList aScaleModesList;
1596   aScaleModesList.append( tr("PREF_LINEAR") );
1597   aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1598
1599   anIndexesList.clear();
1600   anIndexesList.append(0);
1601   anIndexesList.append(1);
1602
1603   int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1604                                       SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1605
1606   pref->setItemProperty( horScale, "strings", aScaleModesList );
1607   pref->setItemProperty( horScale, "indexes", anIndexesList );
1608
1609   int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1610                                       SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1611
1612   pref->setItemProperty( verScale, "strings", aScaleModesList );
1613   pref->setItemProperty( verScale, "indexes", anIndexesList );
1614
1615   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1616                        SalomeApp_Preferences::Color, "Plot2d", "Background" );
1617
1618   int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1619   int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1620   pref->setItemProperty( dirGroup, "columns", 1 );
1621   pref->addPreference( tr( "" ), dirGroup,
1622                        SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1623 }
1624
1625 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1626 {
1627   SUIT_ResourceMgr* resMgr = resourceMgr();
1628   if ( !resMgr )
1629     return;
1630
1631   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1632   {
1633     int sz = resMgr->integerValue( sec, param, -1 );
1634     QPtrList<SUIT_ViewManager> lst;
1635     viewManagers( OCCViewer_Viewer::Type(), lst );
1636     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1637     {
1638       SUIT_ViewModel* vm = it.current()->getViewModel();
1639       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1640         continue;
1641
1642       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1643       occVM->setTrihedronSize( sz );
1644       occVM->getAISContext()->UpdateCurrentViewer();
1645     }
1646   }
1647
1648   if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1649   {
1650     int sz = resMgr->integerValue( sec, param, -1 );
1651     QPtrList<SUIT_ViewManager> lst;
1652     viewManagers( SVTK_Viewer::Type(), lst );
1653     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1654     {
1655       SUIT_ViewModel* vm = it.current()->getViewModel();
1656       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1657         continue;
1658
1659       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1660       if( vtkVM )
1661       {
1662         vtkVM->setTrihedronSize( sz );
1663         vtkVM->Repaint();
1664       }
1665     }
1666   }
1667
1668   if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1669   {
1670     QPtrList<SUIT_ViewManager> lst;
1671     viewManagers( OCCViewer_Viewer::Type(), lst );
1672     int u = resMgr->integerValue( sec, "iso_number_u" );
1673     int v = resMgr->integerValue( sec, "iso_number_v" );
1674     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1675       ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1676   }
1677
1678   if( sec=="ObjectBrowser" )
1679   {
1680     if( param=="auto_size" )
1681     {
1682       OB_Browser* ob = objectBrowser();
1683       if( !ob )
1684         return;
1685
1686       bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1687       ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1688
1689       updateObjectBrowser( false );
1690     }
1691   }
1692
1693   if( sec=="PyConsole" )
1694   {
1695     if( param=="font" )
1696       if( pythonConsole() )
1697         pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1698   }
1699 }
1700
1701 /*!Update desktop title.*/
1702 void SalomeApp_Application::updateDesktopTitle() {
1703   QString aTitle = applicationName();
1704   QString aVer = applicationVersion();
1705   if ( !aVer.isEmpty() )
1706     aTitle += QString( " " ) + aVer;
1707
1708   if ( activeStudy() )
1709   {
1710     QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1711     if ( !sName.isEmpty() ) {
1712       SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1713       _PTR(Study) stdDS = study->studyDS();
1714       if(stdDS) {
1715         if ( stdDS->GetProperties()->IsLocked() ) {
1716           aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1717         } else {
1718           aTitle += QString( " - [%1]" ).arg( sName );
1719         }
1720       }
1721     }
1722   }
1723
1724   desktop()->setCaption( aTitle );
1725 }
1726
1727 /*!Update windows after close document.*/
1728 void SalomeApp_Application::afterCloseDoc()
1729 {
1730   updateWindows();
1731
1732   CAM_Application::afterCloseDoc();
1733 }
1734
1735 /*!Gets CORBA::ORB_var*/
1736 CORBA::ORB_var SalomeApp_Application::orb()
1737 {
1738   ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1739   static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1740   return _orb;
1741 }
1742
1743 /*!Create and return SALOMEDS_StudyManager.*/
1744 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1745 {
1746   static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1747   return _sm;
1748 }
1749
1750 /*!Create and return SALOME_NamingService.*/
1751 SALOME_NamingService* SalomeApp_Application::namingService()
1752 {
1753   static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1754   return _ns;
1755 }
1756
1757 /*!Create and return SALOME_LifeCycleCORBA.*/
1758 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1759 {
1760   static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1761   return _lcc;
1762 }
1763
1764 QString SalomeApp_Application::defaultEngineIOR()
1765 {
1766   /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1767   QString anIOR( "" );
1768   CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1769   if ( !CORBA::is_nil( anEngine ) )
1770     anIOR = orb()->object_to_string( anEngine );
1771   return anIOR;
1772 }
1773
1774 /*!Adds icon names for modules.*/
1775 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1776 {
1777   iconMap.clear();
1778
1779   SUIT_ResourceMgr* resMgr = resourceMgr();
1780   if ( !resMgr )
1781     return;
1782
1783   QStringList modList;
1784   modules( modList, false );
1785
1786   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1787   {
1788     QString modName = *it;
1789     QString modIntr = moduleName( modName );
1790     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1791
1792     if ( modIcon.isEmpty() )
1793       continue;
1794
1795     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1796       modIcon += QString( ".png" );
1797
1798     iconMap.insert( modName, modIcon );
1799   }
1800 }
1801
1802 /*!Update module action.*/
1803 void SalomeApp_Application::updateModuleActions()
1804 {
1805   QString modName;
1806   if ( activeModule() )
1807     modName = activeModule()->moduleName();
1808
1809   if ( myActions.contains( modName ) )
1810     myActions[modName]->setOn( true );
1811 }
1812
1813 /*!Gets current windows.
1814  *\param winMap - output current windows map.
1815  */
1816 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1817 {
1818   winMap.clear();
1819   if ( !activeStudy() )
1820     return;
1821
1822   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1823     ((SalomeApp_Module*)activeModule())->windows( winMap );
1824   else
1825     defaultWindows( winMap );
1826 }
1827
1828 /*!Gets current view managers.
1829  *\param lst - output current view managers list.
1830  */
1831 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1832 {
1833   lst.clear();
1834   if ( !activeStudy() )
1835     return;
1836
1837   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1838     ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1839   else
1840     defaultViewManagers( lst );
1841 }
1842
1843 /*!Update windows.*/
1844 void SalomeApp_Application::updateWindows()
1845 {
1846   QMap<int, int> winMap;
1847   currentWindows( winMap );
1848
1849   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1850     getWindow( it.key() );
1851
1852   loadWindowsGeometry();
1853
1854   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1855     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1856 }
1857
1858 /*!Update view managers.*/
1859 void SalomeApp_Application::updateViewManagers()
1860 {
1861   QStringList lst;
1862   currentViewManagers( lst );
1863
1864   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1865     getViewManager( *it, true );
1866 }
1867
1868 /*!Load windows geometry.*/
1869 void SalomeApp_Application::loadWindowsGeometry()
1870 {
1871   QtxDockAction* dockMgr = 0;
1872
1873   QAction* a = action( ViewWindowsId );
1874   if ( a && a->inherits( "QtxDockAction" ) )
1875     dockMgr = (QtxDockAction*)a;
1876
1877   if ( !dockMgr )
1878     return;
1879
1880   QString modName;
1881   if ( activeModule() )
1882     modName = activeModule()->name("");
1883
1884   QString section = QString( "windows_geometry" );
1885   if ( !modName.isEmpty() )
1886     section += QString( "." ) + modName;
1887
1888   dockMgr->loadGeometry( resourceMgr(), section, false );
1889   dockMgr->restoreGeometry();
1890 }
1891
1892 /*!Save windows geometry.*/
1893 void SalomeApp_Application::saveWindowsGeometry()
1894 {
1895   QtxDockAction* dockMgr = 0;
1896
1897   QAction* a = action( ViewWindowsId );
1898   if ( a && a->inherits( "QtxDockAction" ) )
1899     dockMgr = (QtxDockAction*)a;
1900
1901   if ( !dockMgr )
1902     return;
1903
1904   QString modName;
1905   if ( activeModule() )
1906     modName = activeModule()->name("");
1907
1908   QString section = QString( "windows_geometry" );
1909   if ( !modName.isEmpty() )
1910     section += QString( "." ) + modName;
1911
1912   dockMgr->storeGeometry();
1913   dockMgr->saveGeometry( resourceMgr(), section, false );
1914 }
1915
1916 /*!Activate windows.*/
1917 void SalomeApp_Application::activateWindows()
1918 {
1919   if ( activeStudy() )
1920   {
1921     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1922       itr.data()->activate( activeStudy()->id() );
1923   }
1924 }
1925
1926 /*!Private SLOT. On preferences.*/
1927 void SalomeApp_Application::onProperties()
1928 {
1929   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1930   if( !study )
1931     return;
1932
1933   _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1934   SB->NewCommand();
1935
1936   SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1937   int res = aDlg.exec();
1938   if( res==QDialog::Accepted && aDlg.isChanged() )
1939     SB->CommitCommand();
1940   else
1941     SB->AbortCommand();
1942
1943   //study->updateCaptions();
1944   updateDesktopTitle();
1945   updateActions();
1946 }
1947
1948 /*!*/
1949 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1950                                             const QString& caption, QWidget* parent )
1951 {
1952   if ( !parent )
1953     parent = desktop();
1954   QStringList fls = QStringList::split( ";;", filters, false );
1955   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1956 }
1957
1958 /*!*/
1959 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1960 {
1961   if ( !parent )
1962     parent = desktop();
1963   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1964 }
1965
1966 /*!*/
1967 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1968                                                      const QString& caption, QWidget* parent )
1969 {
1970   if ( !parent )
1971     parent = desktop();
1972   QStringList fls = QStringList::split( ";;", filters, false );
1973   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1974 }
1975
1976 /*!*/
1977 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1978 {
1979   CAM_Application::contextMenuPopup( type, thePopup, title );
1980
1981   OB_Browser* ob = objectBrowser();
1982   if ( !ob || type != ob->popupClientType() )
1983     return;
1984
1985   thePopup->insertSeparator();
1986   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1987
1988   // Get selected objects
1989   SALOME_ListIO aList;
1990   SalomeApp_SelectionMgr* mgr = selectionMgr();
1991   mgr->selectedObjects(aList);
1992
1993   // "Delete reference" item should appear only for invalid references
1994
1995   // Check if selected objects is invalid references
1996   bool isInvalidRefs = true;
1997
1998   if ( aList.Extent() < 1 )
1999     isInvalidRefs = false;
2000
2001   if ( isInvalidRefs )
2002     {
2003       SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
2004       _PTR(Study) aStudyDS = aStudy->studyDS();
2005       _PTR(SObject) anObj;
2006
2007       for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() )
2008         {
2009           if ( it.Value()->hasEntry() )
2010             {
2011               _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
2012               if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() )
2013                 isInvalidRefs = false;
2014             }
2015         }
2016     }
2017
2018   // Add "Delete refrence" item to popup
2019   if ( isInvalidRefs )
2020     {
2021       thePopup->insertSeparator();
2022       thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) );
2023       return;
2024     }
2025
2026   // "Activate module" item should appear only if it's necessary
2027   if (aList.Extent() != 1)
2028     return;
2029   Handle(SALOME_InteractiveObject) aIObj = aList.First();
2030   QString aModuleName(aIObj->getComponentDataType());
2031   QString aModuleTitle = moduleTitle(aModuleName);
2032   CAM_Module* currentModule = activeModule();
2033   if (currentModule && currentModule->moduleName() == aModuleTitle)
2034     return;
2035   thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
2036
2037 }
2038
2039 /*!Update obect browser*/
2040 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
2041 {
2042   // update existing data models (already loaded SComponents)
2043   if ( updateModels )
2044   {
2045     for ( ModuleListIterator it = modules(); it.current(); ++it )
2046     {
2047       CAM_DataModel* camDM = it.current()->dataModel();
2048       if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
2049         ((SalomeApp_DataModel*)camDM)->update();
2050     }
2051   }
2052   // update "non-existing" (not loaded yet) data models
2053   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
2054   if ( study )
2055   {
2056     _PTR(Study) stdDS = study->studyDS();
2057     if( stdDS )
2058     {
2059       for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
2060       {
2061         _PTR(SComponent) aComponent ( it->Value() );
2062
2063         if ( aComponent->ComponentDataType() == "Interface Applicative" )
2064           continue; // skip the magic "Interface Applicative" component
2065
2066         SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
2067       }
2068     }
2069   }
2070
2071   if ( objectBrowser() )
2072   {
2073     objectBrowser()->updateGeometry();
2074     objectBrowser()->updateTree();
2075   }
2076 }
2077
2078 /*!Protected SLOT.On desktop activated.*/
2079 void SalomeApp_Application::onDesktopActivated()
2080 {
2081   CAM_Application::onDesktopActivated();
2082   SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
2083   if(aModule)
2084     aModule->studyActivated();
2085 }
2086
2087 /*!Create empty study.*/
2088 void SalomeApp_Application::createEmptyStudy()
2089 {
2090   CAM_Application::createEmptyStudy();
2091   if ( objectBrowser() )
2092     objectBrowser()->updateTree();
2093 }
2094
2095 /*!Activate module \a mod.*/
2096 bool SalomeApp_Application::activateModule( CAM_Module* mod )
2097 {
2098   bool res = CAM_Application::activateModule( mod );
2099   if ( objectBrowser() )
2100     objectBrowser()->updateTree();
2101   return res;
2102 }
2103
2104 /*!Display Catalog Genenerator dialog */
2105 void SalomeApp_Application::onCatalogGen()
2106 {
2107   ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
2108   aDlg.exec();
2109 }
2110
2111 /*!Display Registry Display dialog */
2112 void SalomeApp_Application::onRegDisplay()
2113 {
2114   CORBA::ORB_var anOrb = orb();
2115   ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
2116   regWnd->show();
2117   regWnd->raise();
2118   regWnd->setActiveWindow();
2119 }
2120
2121 /*!return keyborad accelerators manager object */
2122 SUIT_Accel* SalomeApp_Application::accel() const
2123 {
2124   return myAccel;
2125 }