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