Salome HOME
ENV: Windows porting
[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 /*!Delete references.*/
768 void SalomeApp_Application::onDeleteReferences()
769 {
770   SALOME_ListIO aList;
771   SalomeApp_SelectionMgr* mgr = selectionMgr();
772   mgr->selectedObjects(aList);
773
774   if (aList.Extent() < 1) return;
775
776   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
777   _PTR(Study) aStudyDS = aStudy->studyDS();
778   _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder();
779   _PTR(SObject) anObj;
780   
781   for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
782     {
783       if ( it.Value()->hasEntry() )
784         {
785           _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
786           if ( aSObject->ReferencedObject(anObj) )
787             aStudyBuilder->RemoveReference(aSObject);
788         }
789     }
790
791   updateObjectBrowser();
792 }
793
794 /*!Private SLOT. */
795 void SalomeApp_Application::onOpenWith()
796 {
797   QApplication::setOverrideCursor( Qt::waitCursor );
798   SALOME_ListIO aList;
799   SalomeApp_SelectionMgr* mgr = selectionMgr();
800   mgr->selectedObjects(aList);
801   if (aList.Extent() != 1)
802     {
803       QApplication::restoreOverrideCursor();
804       return;
805     }
806   Handle(SALOME_InteractiveObject) aIObj = aList.First();
807   QString aModuleName(aIObj->getComponentDataType());
808   QString aModuleTitle = moduleTitle(aModuleName);
809   activateModule(aModuleTitle);
810   QApplication::restoreOverrideCursor();
811 }
812
813 bool SalomeApp_Application::useStudy(const QString& theName)
814 {
815   createEmptyStudy();
816   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
817   bool res = false;
818   if (aStudy)
819     res = aStudy->loadDocument( theName );
820   updateDesktopTitle();
821   updateCommandsStatus();
822   return res;
823 }
824
825 /*!Set active study.
826  *\param study - SUIT_Study.
827  */
828 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
829 {
830   CAM_Application::setActiveStudy( study );
831
832   activateWindows();
833 }
834
835 //=======================================================================
836 // name    : createNewStudy
837 /*! Purpose : Create new study*/
838 //=======================================================================
839 SUIT_Study* SalomeApp_Application::createNewStudy()
840 {
841   SalomeApp_Study* aStudy = new SalomeApp_Study( this );
842
843   // Set up processing of major study-related events
844   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
845   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
846   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
847   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
848
849   return aStudy;
850 }
851
852 //=======================================================================
853 // name    : createNewStudy
854 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
855 //=======================================================================
856 void SalomeApp_Application::updateCommandsStatus()
857 {
858   CAM_Application::updateCommandsStatus();
859
860   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
861   {
862     QAction* a = action( id );
863     if ( a )
864       a->setEnabled( activeStudy() );
865   }
866
867   // Dump study menu
868   QAction* a = action( DumpStudyId );
869   if ( a )
870     a->setEnabled( activeStudy() );
871
872   // Load script menu
873   a = action( LoadScriptId );
874   if ( a )
875     a->setEnabled( activeStudy() );
876
877   a = action( PropertiesId );
878   if( a )
879     a->setEnabled( activeStudy() );
880
881   a = action(EditCopyId);
882   a->setEnabled(false);
883   a = action(EditPasteId);
884   a->setEnabled(false);
885 }
886
887 //=======================================================================
888 // name    : onHelpAbout
889 /*! Purpose : SLOT. Display "About" message box*/
890 //=======================================================================
891 void SalomeApp_Application::onHelpAbout()
892 {
893   SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
894   dlg->exec();
895   delete dlg;
896 }
897
898 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
899 {
900   QWidget* wid = 0;
901
902   int sId = studyId;
903   if ( sId < 0 )
904   {
905     if ( !activeStudy() )
906       return 0;
907     else
908       sId = activeStudy()->id();
909   }
910
911   if ( myWindows.contains( flag ) )
912     wid = myWindows[flag]->widget( sId );
913
914   return wid;
915 }
916
917 /*!Adds window to application.
918  *\param wid - QWidget
919  *\param flag - key wor window
920  *\param studyId - study id
921  * Flag used how identificator of window in windows list.
922  */
923 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
924 {
925   if ( !wid )
926     return;
927
928   int sId = studyId;
929   if ( sId < 0 )
930   {
931     if ( !activeStudy() )
932       return;
933     else
934       sId = activeStudy()->id();
935   }
936
937   if ( !myWindows.contains( flag ) )
938   {
939     QMap<int, int> winMap;
940     currentWindows( winMap );
941
942     myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
943     if ( winMap.contains( flag ) )
944       desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
945
946     myWindows[flag]->setResizeEnabled( true );
947     myWindows[flag]->setCloseMode( QDockWindow::Always );
948     myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
949   }
950
951   QFont f;
952   if( wid->inherits( "PythonConsole" ) )
953     f = ( ( PythonConsole* )wid )->font();
954   else
955     f = wid->font();
956
957   myWindows[flag]->insert( sId, wid );
958   wid->setFont( f );
959
960   setWindowShown( flag, !myWindows[flag]->isEmpty() );
961 }
962
963 /*!Remove window from application.
964  *\param flag - key wor window
965  *\param studyId - study id
966  * Flag used how identificator of window in windows list.
967  */
968 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
969 {
970   if ( !myWindows.contains( flag ) )
971     return;
972
973   int sId = studyId;
974   if ( sId < 0 )
975   {
976     if ( !activeStudy() )
977       return;
978     else
979       sId = activeStudy()->id();
980   }
981
982   QWidget* wid = myWindows[flag]->widget( sId );
983   myWindows[flag]->remove( sId );
984   delete wid;
985
986   setWindowShown( flag, !myWindows[flag]->isEmpty() );
987 }
988
989 /*!Gets window.
990  *\param flag - key wor window
991  *\param studyId - study id
992  * Flag used how identificator of window in windows list.
993  */
994 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
995 {
996   QWidget* wid = window( flag, studyId );
997   if ( !wid )
998     addWindow( wid = createWindow( flag ), flag, studyId );
999
1000   return wid;
1001 }
1002
1003 /*!Check is window visible?(with identificator \a type)*/
1004 bool SalomeApp_Application::isWindowVisible( const int type ) const
1005 {
1006   bool res = false;
1007   if ( myWindows.contains( type ) )
1008   {
1009     SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
1010     res = desk && desk->appropriate( myWindows[type] );
1011   }
1012   return res;
1013 }
1014
1015 /*!Sets window show or hide.
1016  *\param type - window identificator.
1017  *\param on   - true/false (window show/hide)
1018  */
1019 void SalomeApp_Application::setWindowShown( const int type, const bool on )
1020 {
1021   if ( !desktop() || !myWindows.contains( type ) )
1022     return;
1023
1024   QDockWindow* dw = myWindows[type];
1025   desktop()->setAppropriate( dw, on );
1026   on ? dw->show() : dw->hide();
1027 }
1028
1029 OB_Browser* SalomeApp_Application::objectBrowser()
1030 {
1031   OB_Browser* ob = 0;
1032   QWidget* wid = getWindow( WT_ObjectBrowser );
1033   if ( wid->inherits( "OB_Browser" ) )
1034     ob = (OB_Browser*)wid;
1035   return ob;
1036 }
1037
1038 /*!Gets "LogWindow".*/
1039 LogWindow* SalomeApp_Application::logWindow()
1040 {
1041   LogWindow* lw = 0;
1042   QWidget* wid = getWindow( WT_LogWindow );
1043   if ( wid->inherits( "LogWindow" ) )
1044     lw = (LogWindow*)wid;
1045   return lw;
1046 }
1047
1048 /*!Get "PythonConsole"*/
1049 PythonConsole* SalomeApp_Application::pythonConsole()
1050 {
1051   PythonConsole* console = 0;
1052   QWidget* wid = getWindow( WT_PyConsole );
1053   if ( wid->inherits( "PythonConsole" ) )
1054     console = (PythonConsole*)wid;
1055   return console;
1056 }
1057
1058 /*!Gets preferences.*/
1059 SalomeApp_Preferences* SalomeApp_Application::preferences() const
1060 {
1061   return preferences( false );
1062 }
1063
1064 /*!Gets view manager*/
1065 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
1066 {
1067   SUIT_ViewManager* aVM = viewManager( vmType );
1068   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1069
1070   if ( anActiveVM && anActiveVM->getType() == vmType )
1071     aVM = anActiveVM;
1072
1073   if ( aVM && create )
1074   {
1075     if ( !aVM->getActiveView() )
1076       aVM->createView();
1077     else
1078       aVM->getActiveView()->setFocus();
1079   }
1080   else if ( create )
1081     aVM = createViewManager( vmType );
1082
1083   return aVM;
1084 }
1085
1086 /*!Create view manager.*/
1087 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
1088 {
1089   SUIT_ResourceMgr* resMgr = resourceMgr();
1090
1091   SUIT_ViewManager* viewMgr = 0;
1092   if ( vmType == GLViewer_Viewer::Type() )
1093   {
1094     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1095     new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1096   }
1097   else if ( vmType == Plot2d_Viewer::Type() )
1098   {
1099     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1100     viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
1101   }
1102   else if ( vmType == OCCViewer_Viewer::Type() )
1103   {
1104     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1105     SOCC_Viewer* vm = new SOCC_Viewer();
1106     vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1107     vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1108     int u( 1 ), v( 1 );
1109     vm->isos( u, v );
1110     u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1111     v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1112     vm->setIsos( u, v );
1113     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1114     new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1115   }
1116   else if ( vmType == SVTK_Viewer::Type() )
1117   {
1118     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1119     SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
1120     vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1121     vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1122     new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
1123   }
1124
1125   if ( !viewMgr )
1126     return 0;
1127
1128   addViewManager( viewMgr );
1129   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1130
1131   if ( viewWin && desktop() )
1132     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1133
1134   connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1135            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1136
1137   return viewMgr;
1138 }
1139
1140 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1141 {
1142   removeViewManager( theVM );
1143 }
1144
1145 /*!Private SLOT. On study created.*/
1146 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1147 {
1148   SUIT_DataObject* aRoot = 0;
1149   if ( theStudy && theStudy->root() )
1150   {
1151     aRoot = theStudy->root();
1152     //aRoot->setName( tr( "DATA_MODELS" ) );
1153   }
1154   if ( objectBrowser() != 0 )
1155     objectBrowser()->setRootObject( aRoot );
1156
1157   activateModule( defaultModule() );
1158
1159   activateWindows();
1160 }
1161
1162 /*!Private SLOT. On study opened.*/
1163 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1164 {
1165   SUIT_DataObject* aRoot = 0;
1166   if ( theStudy && theStudy->root() )
1167   {
1168     aRoot = theStudy->root();
1169     //aRoot->dump();
1170   }
1171   if ( objectBrowser() != 0 ) {
1172     objectBrowser()->setRootObject( aRoot );
1173   }
1174
1175   activateModule( defaultModule() );
1176
1177   activateWindows();
1178
1179   emit studyOpened();
1180 }
1181
1182 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1183 {
1184   emit studySaved();
1185 }
1186
1187 /*!Private SLOT. On study closed.*/
1188 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1189 {
1190   emit studyClosed();
1191
1192   activateModule( "" );
1193
1194   saveWindowsGeometry();
1195 }
1196
1197 /*!Private SLOT. On dump study.*/
1198 void SalomeApp_Application::onDumpStudy( )
1199 {
1200   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1201   if ( !appStudy ) return;
1202   _PTR(Study) aStudy = appStudy->studyDS();
1203
1204   QStringList aFilters;
1205   aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1206
1207   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1208   fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1209   fd->setFilters( aFilters );
1210   fd->SetChecked(true);
1211   fd->exec();
1212   QString aFileName = fd->selectedFile();
1213   bool toPublish = fd->IsChecked();
1214   delete fd;
1215
1216   if(!aFileName.isEmpty()) {
1217     QFileInfo aFileInfo(aFileName);
1218     aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1219   }
1220 }
1221
1222 /*!Private SLOT. On load script.*/
1223 void SalomeApp_Application::onLoadScript( )
1224 {
1225   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1226   if ( !appStudy ) return;
1227   _PTR(Study) aStudy = appStudy->studyDS();
1228
1229   if ( aStudy->GetProperties()->IsLocked() ) {
1230     SUIT_MessageBox::warn1 ( desktop(),
1231                              QObject::tr("WRN_WARNING"),
1232                              QObject::tr("WRN_STUDY_LOCKED"),
1233                              QObject::tr("BUT_OK") );
1234     return;
1235   }
1236
1237   QStringList filtersList;
1238   filtersList.append(tr("PYTHON_FILES_FILTER"));
1239   filtersList.append(tr("ALL_FILES_FILTER"));
1240
1241   QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1242
1243   if ( !aFile.isEmpty() )
1244   {
1245     QString command = QString("execfile(\"%1\")").arg(aFile);
1246
1247     PythonConsole* pyConsole = pythonConsole();
1248
1249     if ( pyConsole )
1250       pyConsole->exec( command );
1251   }
1252 }
1253
1254 /*!Private SLOT. On preferences.*/
1255 void SalomeApp_Application::onPreferences()
1256 {
1257   QApplication::setOverrideCursor( Qt::waitCursor );
1258
1259   SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1260
1261   QApplication::restoreOverrideCursor();
1262
1263   if ( !prefDlg )
1264     return;
1265
1266   prefDlg->exec();
1267
1268   delete prefDlg;
1269 }
1270
1271 /*!Private SLOT. On open document with name \a aName.*/
1272 void SalomeApp_Application::onMRUActivated( QString aName )
1273 {
1274   onOpenDoc( aName );
1275 }
1276
1277 /*!Private SLOT. On preferences changed.*/
1278 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1279 {
1280   SalomeApp_Module* sMod = 0;
1281   CAM_Module* mod = module( modName );
1282   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1283     sMod = (SalomeApp_Module*)mod;
1284
1285   if ( sMod )
1286     sMod->preferencesChanged( section, param );
1287   else
1288     preferencesChanged( section, param );
1289 }
1290
1291 /*!Gets file filter.
1292  *\retval QString "(*.hdf)"
1293  */
1294 QString SalomeApp_Application::getFileFilter() const
1295 {
1296   return "(*.hdf)";
1297 }
1298
1299 /*!Remove all windows from study.*/
1300 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1301 {
1302   CAM_Application::beforeCloseDoc( s );
1303
1304   for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1305     removeWindow( itr.key(), s->id() );
1306 }
1307
1308 /*!Update actions.*/
1309 void SalomeApp_Application::updateActions()
1310 {
1311   updateCommandsStatus();
1312 }
1313
1314 /*!Create window.*/
1315 QWidget* SalomeApp_Application::createWindow( const int flag )
1316 {
1317   QWidget* wid = 0;
1318
1319   SUIT_ResourceMgr* resMgr = resourceMgr();
1320
1321   if ( flag == WT_ObjectBrowser )
1322   {
1323     OB_Browser* ob = new OB_Browser( desktop() );
1324     ob->setAutoUpdate( true );
1325     ob->setAutoOpenLevel( 1 );
1326     ob->setCaption( tr( "OBJECT_BROWSER" ) );
1327     ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1328     ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1329
1330     ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1331
1332     bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1333     for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1334     {
1335       ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1336       ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1337                                                    QString().sprintf( "visibility_column_%d", i ), true ) );
1338     }
1339     ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1340
1341     // Create OBSelector
1342     new SalomeApp_OBSelector( ob, mySelMgr );
1343
1344     wid = ob;
1345
1346     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1347   }
1348   else if ( flag == WT_PyConsole )
1349   {
1350     PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1351     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1352     pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1353     wid = pyCons;
1354
1355     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1356   }
1357   else if ( flag == WT_LogWindow )
1358   {
1359     LogWindow* logWin = new LogWindow( desktop() );
1360     logWin->setCaption( tr( "LOG_WINDOW" ) );
1361     wid = logWin;
1362
1363     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1364   }
1365
1366   return wid;
1367 }
1368
1369 /*!Default windows(Object Browser, Python Console).
1370  * Adds to map \a aMap.
1371  */
1372 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1373 {
1374   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1375   aMap.insert( WT_PyConsole, Qt::DockBottom );
1376   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1377 }
1378
1379 /*!Default view manager.*/
1380 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1381 {
1382   /*!Do nothing.*/
1383 }
1384
1385 /*!Gets preferences.
1386  * Create preferences, if \a crt = true.
1387  */
1388 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1389 {
1390   if ( myPrefs )
1391     return myPrefs;
1392
1393   SalomeApp_Application* that = (SalomeApp_Application*)this;
1394
1395   if ( !_prefs_ && crt )
1396   {
1397     _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1398     that->createPreferences( _prefs_ );
1399   }
1400
1401   that->myPrefs = _prefs_;
1402
1403   QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1404   for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1405   {
1406     if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1407       continue;
1408
1409     SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1410
1411     QStringList modNameList;
1412     app->modules( modNameList, false );
1413     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1414     {
1415       int id = _prefs_->addPreference( *it );
1416       _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1417     }
1418
1419     ModuleList modList;
1420     app->modules( modList );
1421     for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1422     {
1423       SalomeApp_Module* mod = 0;
1424       if ( itr.current()->inherits( "SalomeApp_Module" ) )
1425         mod = (SalomeApp_Module*)itr.current();
1426
1427       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1428       {
1429         int modCat = _prefs_->addPreference( mod->moduleName() );
1430         _prefs_->setItemProperty( modCat, "info", QString::null );
1431         mod->createPreferences();
1432       }
1433     }
1434   }
1435
1436   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1437            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1438
1439   return myPrefs;
1440 }
1441
1442 /*!Add new module to application.*/
1443 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1444 {
1445   CAM_Application::moduleAdded( mod );
1446
1447   SalomeApp_Module* salomeMod = 0;
1448   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1449     salomeMod = (SalomeApp_Module*)mod;
1450
1451   if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1452   {
1453     int modCat = myPrefs->addPreference( mod->moduleName() );
1454     myPrefs->setItemProperty( modCat, "info", QString::null );
1455     salomeMod->createPreferences();
1456   }
1457 }
1458
1459 /*!Create preferences.*/
1460 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1461 {
1462   if ( !pref )
1463     return;
1464
1465   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1466
1467   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1468   int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1469   pref->setItemProperty( studyGroup, "columns", 1 );
1470
1471   pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1472   pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1473   int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1474   pref->setItemProperty( undoPref, "min", 1 );
1475   pref->setItemProperty( undoPref, "max", 100 );
1476
1477   int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1478   pref->setItemProperty( extgroup, "columns", 1 );
1479   int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1480   pref->setItemProperty( apppref, "existing", true );
1481   pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1482
1483   pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1484
1485   int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1486   pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1487   pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1488
1489
1490
1491   int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1492   int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1493   for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1494   {
1495     pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1496                          SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1497   }
1498   pref->setItemProperty( defCols, "columns", 1 );
1499
1500   int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1501   pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1502
1503   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1504
1505   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1506
1507   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1508
1509   int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1510
1511   pref->setItemProperty( occGroup, "columns", 1 );
1512   pref->setItemProperty( vtkGroup, "columns", 1 );
1513   pref->setItemProperty( plot2dGroup, "columns", 1 );
1514
1515   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1516                                    SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1517   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1518                        SalomeApp_Preferences::Color, "OCCViewer", "background" );
1519
1520   pref->setItemProperty( occTS, "min", 1 );
1521   pref->setItemProperty( occTS, "max", 150 );
1522
1523   int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1524                                   SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1525   int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1526                                   SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1527
1528   pref->setItemProperty( isoU, "min", 0 );
1529   pref->setItemProperty( isoU, "max", 100000 );
1530
1531   pref->setItemProperty( isoV, "min", 0 );
1532   pref->setItemProperty( isoV, "max", 100000 );
1533
1534   int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1535                                    SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1536   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1537                        SalomeApp_Preferences::Color, "VTKViewer", "background" );
1538
1539   pref->setItemProperty( vtkTS, "min", 1 );
1540   pref->setItemProperty( vtkTS, "max", 150 );
1541   
1542   pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1543                        SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1544
1545   int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1546                                             SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" );
1547   QStringList aLegendPosList;
1548   aLegendPosList.append( tr("PREF_LEFT") );
1549   aLegendPosList.append( tr("PREF_RIGHT") );
1550   aLegendPosList.append( tr("PREF_TOP") );
1551   aLegendPosList.append( tr("PREF_BOTTOM") );
1552   
1553   QValueList<QVariant> anIndexesList;
1554   anIndexesList.append(0);
1555   anIndexesList.append(1);
1556   anIndexesList.append(2);
1557   anIndexesList.append(3);
1558   
1559   pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1560   pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1561   
1562   int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1563                                        SalomeApp_Preferences::Selector, "Plot2d", "CurveType" );
1564   QStringList aCurveTypesList;
1565   aCurveTypesList.append( tr("PREF_POINTS") );
1566   aCurveTypesList.append( tr("PREF_LINES") );
1567   aCurveTypesList.append( tr("PREF_SPLINE") );
1568   
1569   anIndexesList.clear();
1570   anIndexesList.append(0);
1571   anIndexesList.append(1);
1572   anIndexesList.append(2);
1573   
1574   pref->setItemProperty( curveType, "strings", aCurveTypesList );
1575   pref->setItemProperty( curveType, "indexes", anIndexesList );
1576
1577   int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1578                                         SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1579
1580   pref->setItemProperty( markerSize, "min", 0 );
1581   pref->setItemProperty( markerSize, "max", 100 );
1582   
1583   QStringList aScaleModesList;
1584   aScaleModesList.append( tr("PREF_LINEAR") );
1585   aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1586   
1587   anIndexesList.clear();
1588   anIndexesList.append(0);
1589   anIndexesList.append(1);
1590   
1591   int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1592                                       SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1593
1594   pref->setItemProperty( horScale, "strings", aScaleModesList );
1595   pref->setItemProperty( horScale, "indexes", anIndexesList );
1596
1597   int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1598                                       SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1599   
1600   pref->setItemProperty( verScale, "strings", aScaleModesList );
1601   pref->setItemProperty( verScale, "indexes", anIndexesList );
1602
1603   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1604                        SalomeApp_Preferences::Color, "Plot2d", "Background" );
1605   
1606   int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1607   int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1608   pref->setItemProperty( dirGroup, "columns", 1 );
1609   pref->addPreference( tr( "" ), dirGroup,
1610                        SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1611 }
1612
1613 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1614 {
1615   SUIT_ResourceMgr* resMgr = resourceMgr();
1616   if ( !resMgr )
1617     return;
1618
1619   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1620   {
1621     int sz = resMgr->integerValue( sec, param, -1 );
1622     QPtrList<SUIT_ViewManager> lst;
1623     viewManagers( OCCViewer_Viewer::Type(), lst );
1624     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1625     {
1626       SUIT_ViewModel* vm = it.current()->getViewModel();
1627       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1628         continue;
1629
1630       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1631       occVM->setTrihedronSize( sz );
1632       occVM->getAISContext()->UpdateCurrentViewer();
1633     }
1634   }
1635
1636   if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1637   {
1638     int sz = resMgr->integerValue( sec, param, -1 );
1639     QPtrList<SUIT_ViewManager> lst;
1640     viewManagers( SVTK_Viewer::Type(), lst );
1641     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1642     {
1643       SUIT_ViewModel* vm = it.current()->getViewModel();
1644       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1645         continue;
1646
1647       SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1648       vtkVM->setTrihedronSize( sz );
1649       vtkVM->Repaint();
1650     }
1651   }
1652
1653   if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1654   {
1655     QPtrList<SUIT_ViewManager> lst;
1656     viewManagers( OCCViewer_Viewer::Type(), lst );
1657     int u = resMgr->integerValue( sec, "iso_number_u" );
1658     int v = resMgr->integerValue( sec, "iso_number_v" );
1659     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1660       ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1661   }
1662
1663   if( sec=="ObjectBrowser" )
1664   {
1665     if( param=="auto_size" )
1666     {
1667       OB_Browser* ob = objectBrowser();
1668       if( !ob )
1669         return;
1670
1671       bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1672       ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1673
1674       updateObjectBrowser( false );
1675     }
1676   }
1677
1678   if( sec=="PyConsole" )
1679   {
1680     if( param=="font" )
1681       if( pythonConsole() )
1682         pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1683   }
1684 }
1685
1686 /*!Update desktop title.*/
1687 void SalomeApp_Application::updateDesktopTitle() {
1688   QString aTitle = applicationName();
1689   QString aVer = applicationVersion();
1690   if ( !aVer.isEmpty() )
1691     aTitle += QString( " " ) + aVer;
1692
1693   if ( activeStudy() )
1694   {
1695     QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1696     if ( !sName.isEmpty() ) {
1697       SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1698       _PTR(Study) stdDS = study->studyDS();
1699       if(stdDS) {
1700         if ( stdDS->GetProperties()->IsLocked() ) {
1701           aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1702         } else {
1703           aTitle += QString( " - [%1]" ).arg( sName );
1704         }
1705       }
1706     }
1707   }
1708
1709   desktop()->setCaption( aTitle );
1710 }
1711
1712 /*!Update windows after close document.*/
1713 void SalomeApp_Application::afterCloseDoc()
1714 {
1715   updateWindows();
1716
1717   CAM_Application::afterCloseDoc();
1718 }
1719
1720 /*!Gets CORBA::ORB_var*/
1721 CORBA::ORB_var SalomeApp_Application::orb()
1722 {
1723   ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1724   static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1725   return _orb;
1726 }
1727
1728 /*!Create and return SALOMEDS_StudyManager.*/
1729 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1730 {
1731   static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1732   return _sm;
1733 }
1734
1735 /*!Create and return SALOME_NamingService.*/
1736 SALOME_NamingService* SalomeApp_Application::namingService()
1737 {
1738   static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1739   return _ns;
1740 }
1741
1742 /*!Create and return SALOME_LifeCycleCORBA.*/
1743 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1744 {
1745   static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1746   return _lcc;
1747 }
1748
1749 QString SalomeApp_Application::defaultEngineIOR()
1750 {
1751   /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1752   QString anIOR( "" );
1753   CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1754   if ( !CORBA::is_nil( anEngine ) )
1755     anIOR = orb()->object_to_string( anEngine );
1756   return anIOR;
1757 }
1758
1759 /*!Adds icon names for modules.*/
1760 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1761 {
1762   iconMap.clear();
1763
1764   SUIT_ResourceMgr* resMgr = resourceMgr();
1765   if ( !resMgr )
1766     return;
1767
1768   QStringList modList;
1769   modules( modList, false );
1770
1771   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1772   {
1773     QString modName = *it;
1774     QString modIntr = moduleName( modName );
1775     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1776
1777     if ( modIcon.isEmpty() )
1778       continue;
1779
1780     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1781       modIcon += QString( ".png" );
1782
1783     iconMap.insert( modName, modIcon );
1784   }
1785 }
1786
1787 /*!Update module action.*/
1788 void SalomeApp_Application::updateModuleActions()
1789 {
1790   QString modName;
1791   if ( activeModule() )
1792     modName = activeModule()->moduleName();
1793
1794   if ( myActions.contains( modName ) )
1795     myActions[modName]->setOn( true );
1796 }
1797
1798 /*!Gets current windows.
1799  *\param winMap - output current windows map.
1800  */
1801 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1802 {
1803   winMap.clear();
1804   if ( !activeStudy() )
1805     return;
1806
1807   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1808     ((SalomeApp_Module*)activeModule())->windows( winMap );
1809   else
1810     defaultWindows( winMap );
1811 }
1812
1813 /*!Gets current view managers.
1814  *\param lst - output current view managers list.
1815  */
1816 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1817 {
1818   lst.clear();
1819   if ( !activeStudy() )
1820     return;
1821
1822   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1823     ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1824   else
1825     defaultViewManagers( lst );
1826 }
1827
1828 /*!Update windows.*/
1829 void SalomeApp_Application::updateWindows()
1830 {
1831   QMap<int, int> winMap;
1832   currentWindows( winMap );
1833
1834   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1835     getWindow( it.key() );
1836
1837   loadWindowsGeometry();
1838
1839   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1840     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1841 }
1842
1843 /*!Update view managers.*/
1844 void SalomeApp_Application::updateViewManagers()
1845 {
1846   QStringList lst;
1847   currentViewManagers( lst );
1848
1849   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1850     getViewManager( *it, true );
1851 }
1852
1853 /*!Load windows geometry.*/
1854 void SalomeApp_Application::loadWindowsGeometry()
1855 {
1856   QtxDockAction* dockMgr = 0;
1857
1858   QAction* a = action( ViewWindowsId );
1859   if ( a && a->inherits( "QtxDockAction" ) )
1860     dockMgr = (QtxDockAction*)a;
1861
1862   if ( !dockMgr )
1863     return;
1864
1865   QString modName;
1866   if ( activeModule() )
1867     modName = moduleLibrary( activeModule()->moduleName(), false );
1868
1869   QString section = QString( "windows_geometry" );
1870   if ( !modName.isEmpty() )
1871     section += QString( "." ) + modName;
1872
1873   dockMgr->loadGeometry( resourceMgr(), section, false );
1874   dockMgr->restoreGeometry();
1875 }
1876
1877 /*!Save windows geometry.*/
1878 void SalomeApp_Application::saveWindowsGeometry()
1879 {
1880   QtxDockAction* dockMgr = 0;
1881
1882   QAction* a = action( ViewWindowsId );
1883   if ( a && a->inherits( "QtxDockAction" ) )
1884     dockMgr = (QtxDockAction*)a;
1885
1886   if ( !dockMgr )
1887     return;
1888
1889   QString modName;
1890   if ( activeModule() )
1891     modName = moduleLibrary( activeModule()->moduleName(), false );
1892
1893   QString section = QString( "windows_geometry" );
1894   if ( !modName.isEmpty() )
1895     section += QString( "." ) + modName;
1896
1897   dockMgr->storeGeometry();
1898   dockMgr->saveGeometry( resourceMgr(), section, false );
1899 }
1900
1901 /*!Activate windows.*/
1902 void SalomeApp_Application::activateWindows()
1903 {
1904   if ( activeStudy() )
1905   {
1906     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1907       itr.data()->activate( activeStudy()->id() );
1908   }
1909 }
1910
1911 /*!Private SLOT. On preferences.*/
1912 void SalomeApp_Application::onProperties()
1913 {
1914   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1915   if( !study )
1916     return;
1917
1918   _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1919   SB->NewCommand();
1920
1921   SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1922   int res = aDlg.exec();
1923   if( res==QDialog::Accepted && aDlg.isChanged() )
1924     SB->CommitCommand();
1925   else
1926     SB->AbortCommand();
1927
1928   //study->updateCaptions();
1929   updateDesktopTitle();
1930 }
1931
1932 /*!*/
1933 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1934                                             const QString& caption, QWidget* parent )
1935 {
1936   if ( !parent )
1937     parent = desktop();
1938   QStringList fls = QStringList::split( ";;", filters, false );
1939   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1940 }
1941
1942 /*!*/
1943 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1944 {
1945   if ( !parent )
1946     parent = desktop();
1947   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1948 }
1949
1950 /*!*/
1951 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1952                                                      const QString& caption, QWidget* parent )
1953 {
1954   if ( !parent )
1955     parent = desktop();
1956   QStringList fls = QStringList::split( ";;", filters, false );
1957   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1958 }
1959
1960 /*!*/
1961 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1962 {
1963   CAM_Application::contextMenuPopup( type, thePopup, title );
1964
1965   OB_Browser* ob = objectBrowser();
1966   if ( !ob || type != ob->popupClientType() )
1967     return;
1968
1969   thePopup->insertSeparator();
1970   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1971
1972   // Get selected objects
1973   SALOME_ListIO aList;
1974   SalomeApp_SelectionMgr* mgr = selectionMgr();
1975   mgr->selectedObjects(aList);
1976
1977   // "Delete reference" item should appear only for invalid references
1978   
1979   // Check if selected objects is invalid references
1980   bool isInvalidRefs = true;
1981   
1982   if ( aList.Extent() < 1 )
1983     isInvalidRefs = false;
1984   
1985   if ( isInvalidRefs )
1986     {
1987       SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
1988       _PTR(Study) aStudyDS = aStudy->studyDS();
1989       _PTR(SObject) anObj;
1990       
1991       for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() )
1992         {
1993           if ( it.Value()->hasEntry() )
1994             {
1995               _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
1996               if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() )
1997                 isInvalidRefs = false;
1998             }
1999         }
2000     }
2001   
2002   // Add "Delete refrence" item to popup
2003   if ( isInvalidRefs )
2004     {
2005       thePopup->insertSeparator();
2006       thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) );
2007       return;
2008     }
2009
2010   // "Activate module" item should appear only if it's necessary
2011   if (aList.Extent() != 1)
2012     return;
2013   Handle(SALOME_InteractiveObject) aIObj = aList.First();
2014   QString aModuleName(aIObj->getComponentDataType());
2015   QString aModuleTitle = moduleTitle(aModuleName);
2016   CAM_Module* currentModule = activeModule();
2017   if (currentModule && currentModule->moduleName() == aModuleTitle)
2018     return;
2019   thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
2020   
2021 }
2022
2023 /*!Update obect browser*/
2024 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
2025 {
2026   // update existing data models (already loaded SComponents)
2027   if ( updateModels )
2028   {
2029     for ( ModuleListIterator it = modules(); it.current(); ++it )
2030     {
2031       CAM_DataModel* camDM = it.current()->dataModel();
2032       if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
2033         ((SalomeApp_DataModel*)camDM)->update();
2034     }
2035   }
2036   // update "non-existing" (not loaded yet) data models
2037   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
2038   if ( study )
2039   {
2040     _PTR(Study) stdDS = study->studyDS();
2041     if( stdDS )
2042     {
2043       for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
2044       {
2045         _PTR(SComponent) aComponent ( it->Value() );
2046
2047         if ( aComponent->ComponentDataType() == "Interface Applicative" )
2048           continue; // skip the magic "Interface Applicative" component
2049
2050         SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
2051       }
2052     }
2053   }
2054
2055   if ( objectBrowser() )
2056   {
2057     objectBrowser()->updateGeometry();
2058     objectBrowser()->updateTree();
2059   }
2060 }
2061
2062 /*!Protected SLOT.On desktop activated.*/
2063 void SalomeApp_Application::onDesktopActivated()
2064 {
2065   CAM_Application::onDesktopActivated();
2066   SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
2067   if(aModule)
2068     aModule->studyActivated();
2069 }
2070
2071 /*!Create empty study.*/
2072 void SalomeApp_Application::createEmptyStudy()
2073 {
2074   CAM_Application::createEmptyStudy();
2075   if ( objectBrowser() )
2076     objectBrowser()->updateTree();
2077 }
2078
2079 /*!Activate module \a mod.*/
2080 bool SalomeApp_Application::activateModule( CAM_Module* mod )
2081 {
2082   bool res = CAM_Application::activateModule( mod );
2083   if ( objectBrowser() )
2084     objectBrowser()->updateTree();
2085   return res;
2086 }
2087
2088 /*!Display Catalog Genenerator dialog */
2089 void SalomeApp_Application::onCatalogGen()
2090 {
2091   ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
2092   aDlg.exec();
2093 }
2094
2095 /*!Display Registry Display dialog */
2096 void SalomeApp_Application::onRegDisplay()
2097 {
2098   CORBA::ORB_var anOrb = orb();
2099   ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
2100   regWnd->show();
2101   regWnd->raise();
2102   regWnd->setActiveWindow();
2103 }
2104
2105 /*!return keyborad accelerators manager object */
2106 SUIT_Accel* SalomeApp_Application::accel() const
2107 {
2108   return myAccel;
2109 }