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