Salome HOME
f787fc2072a2aefc4254510b91a9bceba54ae8a4
[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,     VTKViewer_Viewer::Type() );
170   myAccel->setActionKey( SUIT_Accel::PanRight,    CTRL+Key_Right,    VTKViewer_Viewer::Type() );
171   myAccel->setActionKey( SUIT_Accel::PanUp,       CTRL+Key_Up,       VTKViewer_Viewer::Type() );
172   myAccel->setActionKey( SUIT_Accel::PanDown,     CTRL+Key_Down,     VTKViewer_Viewer::Type() );
173   myAccel->setActionKey( SUIT_Accel::ZoomIn,      CTRL+Key_Plus,     VTKViewer_Viewer::Type() );
174   myAccel->setActionKey( SUIT_Accel::ZoomOut,     CTRL+Key_Minus,    VTKViewer_Viewer::Type() );
175   myAccel->setActionKey( SUIT_Accel::ZoomFit,     CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
176   myAccel->setActionKey( SUIT_Accel::RotateLeft,  ALT+Key_Left,      VTKViewer_Viewer::Type() );
177   myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right,     VTKViewer_Viewer::Type() );
178   myAccel->setActionKey( SUIT_Accel::RotateUp,    ALT+Key_Up,        VTKViewer_Viewer::Type() );
179   myAccel->setActionKey( SUIT_Accel::RotateDown,  ALT+Key_Down,      VTKViewer_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 = VTKViewer_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(studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
759       else qaction->setEnabled(false);
760
761       qaction = action(EditPasteId);
762       if( 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 = (SVTK_Viewer*)viewMgr->getViewModel();
1132     vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1133     vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1134     new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
1135   }
1136
1137   if ( !viewMgr )
1138     return 0;
1139
1140   addViewManager( viewMgr );
1141   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1142
1143   if ( viewWin && desktop() )
1144     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1145
1146   connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1147            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1148
1149   return viewMgr;
1150 }
1151
1152 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1153 {
1154   removeViewManager( theVM );
1155 }
1156
1157 /*!Private SLOT. On study created.*/
1158 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1159 {
1160   SUIT_DataObject* aRoot = 0;
1161   if ( theStudy && theStudy->root() )
1162   {
1163     aRoot = theStudy->root();
1164     //aRoot->setName( tr( "DATA_MODELS" ) );
1165   }
1166   if ( objectBrowser() != 0 )
1167     objectBrowser()->setRootObject( aRoot );
1168
1169   activateModule( defaultModule() );
1170
1171   activateWindows();
1172 }
1173
1174 /*!Private SLOT. On study opened.*/
1175 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1176 {
1177   SUIT_DataObject* aRoot = 0;
1178   if ( theStudy && theStudy->root() )
1179   {
1180     aRoot = theStudy->root();
1181     //aRoot->dump();
1182   }
1183   if ( objectBrowser() != 0 ) {
1184     objectBrowser()->setRootObject( aRoot );
1185   }
1186
1187   activateModule( defaultModule() );
1188
1189   activateWindows();
1190
1191   emit studyOpened();
1192 }
1193
1194 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1195 {
1196   emit studySaved();
1197 }
1198
1199 /*!Private SLOT. On study closed.*/
1200 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1201 {
1202   emit studyClosed();
1203
1204   activateModule( "" );
1205
1206   saveWindowsGeometry();
1207 }
1208
1209 /*!Private SLOT. On dump study.*/
1210 void SalomeApp_Application::onDumpStudy( )
1211 {
1212   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1213   if ( !appStudy ) return;
1214   _PTR(Study) aStudy = appStudy->studyDS();
1215
1216   QStringList aFilters;
1217   aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1218
1219   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1220   fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1221   fd->setFilters( aFilters );
1222   fd->SetChecked(true);
1223   fd->exec();
1224   QString aFileName = fd->selectedFile();
1225   bool toPublish = fd->IsChecked();
1226   delete fd;
1227
1228   if(!aFileName.isEmpty()) {
1229     QFileInfo aFileInfo(aFileName);
1230     aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1231   }
1232 }
1233
1234 /*!Private SLOT. On load script.*/
1235 void SalomeApp_Application::onLoadScript( )
1236 {
1237   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1238   if ( !appStudy ) return;
1239   _PTR(Study) aStudy = appStudy->studyDS();
1240
1241   if ( aStudy->GetProperties()->IsLocked() ) {
1242     SUIT_MessageBox::warn1 ( desktop(),
1243                              QObject::tr("WRN_WARNING"),
1244                              QObject::tr("WRN_STUDY_LOCKED"),
1245                              QObject::tr("BUT_OK") );
1246     return;
1247   }
1248
1249   QStringList filtersList;
1250   filtersList.append(tr("PYTHON_FILES_FILTER"));
1251   filtersList.append(tr("ALL_FILES_FILTER"));
1252
1253   QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1254
1255   if ( !aFile.isEmpty() )
1256   {
1257     QString command = QString("execfile(\"%1\")").arg(aFile);
1258
1259     PythonConsole* pyConsole = pythonConsole();
1260
1261     if ( pyConsole )
1262       pyConsole->exec( command );
1263   }
1264 }
1265
1266 /*!Private SLOT. On preferences.*/
1267 void SalomeApp_Application::onPreferences()
1268 {
1269   QApplication::setOverrideCursor( Qt::waitCursor );
1270
1271   SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1272
1273   QApplication::restoreOverrideCursor();
1274
1275   if ( !prefDlg )
1276     return;
1277
1278   prefDlg->exec();
1279
1280   delete prefDlg;
1281 }
1282
1283 /*!Private SLOT. On open document with name \a aName.*/
1284 void SalomeApp_Application::onMRUActivated( QString aName )
1285 {
1286   onOpenDoc( aName );
1287 }
1288
1289 /*!Private SLOT. On preferences changed.*/
1290 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1291 {
1292   SalomeApp_Module* sMod = 0;
1293   CAM_Module* mod = module( modName );
1294   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1295     sMod = (SalomeApp_Module*)mod;
1296
1297   if ( sMod )
1298     sMod->preferencesChanged( section, param );
1299   else
1300     preferencesChanged( section, param );
1301 }
1302
1303 /*!Gets file filter.
1304  *\retval QString "(*.hdf)"
1305  */
1306 QString SalomeApp_Application::getFileFilter() const
1307 {
1308   return "(*.hdf)";
1309 }
1310
1311 /*!Remove all windows from study.*/
1312 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1313 {
1314   CAM_Application::beforeCloseDoc( s );
1315
1316   for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1317     removeWindow( itr.key(), s->id() );
1318 }
1319
1320 /*!Update actions.*/
1321 void SalomeApp_Application::updateActions()
1322 {
1323   updateCommandsStatus();
1324 }
1325
1326 /*!Create window.*/
1327 QWidget* SalomeApp_Application::createWindow( const int flag )
1328 {
1329   QWidget* wid = 0;
1330
1331   SUIT_ResourceMgr* resMgr = resourceMgr();
1332
1333   if ( flag == WT_ObjectBrowser )
1334   {
1335     OB_Browser* ob = new OB_Browser( desktop() );
1336     ob->setAutoUpdate( true );
1337     ob->setAutoOpenLevel( 1 );
1338     ob->setCaption( tr( "OBJECT_BROWSER" ) );
1339     ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1340     ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1341
1342     ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1343
1344     bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1345     for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1346     {
1347       ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1348       ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1349                                                    QString().sprintf( "visibility_column_%d", i ), true ) );
1350     }
1351     ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1352
1353     // Create OBSelector
1354     new SalomeApp_OBSelector( ob, mySelMgr );
1355
1356     wid = ob;
1357
1358     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1359   }
1360   else if ( flag == WT_PyConsole )
1361   {
1362     PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1363     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1364     pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1365     wid = pyCons;
1366
1367     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1368   }
1369   else if ( flag == WT_LogWindow )
1370   {
1371     LogWindow* logWin = new LogWindow( desktop() );
1372     logWin->setCaption( tr( "LOG_WINDOW" ) );
1373     wid = logWin;
1374
1375     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1376   }
1377
1378   return wid;
1379 }
1380
1381 /*!Default windows(Object Browser, Python Console).
1382  * Adds to map \a aMap.
1383  */
1384 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1385 {
1386   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1387   aMap.insert( WT_PyConsole, Qt::DockBottom );
1388   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1389 }
1390
1391 /*!Default view manager.*/
1392 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1393 {
1394   /*!Do nothing.*/
1395 }
1396
1397 /*!Gets preferences.
1398  * Create preferences, if \a crt = true.
1399  */
1400 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1401 {
1402   if ( myPrefs )
1403     return myPrefs;
1404
1405   SalomeApp_Application* that = (SalomeApp_Application*)this;
1406
1407   if ( !_prefs_ && crt )
1408   {
1409     _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1410     that->createPreferences( _prefs_ );
1411   }
1412
1413   that->myPrefs = _prefs_;
1414
1415   QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1416   for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1417   {
1418     if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1419       continue;
1420
1421     SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1422
1423     QStringList modNameList;
1424     app->modules( modNameList, false );
1425     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1426     {
1427       int id = _prefs_->addPreference( *it );
1428       _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1429     }
1430
1431     ModuleList modList;
1432     app->modules( modList );
1433     for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1434     {
1435       SalomeApp_Module* mod = 0;
1436       if ( itr.current()->inherits( "SalomeApp_Module" ) )
1437         mod = (SalomeApp_Module*)itr.current();
1438
1439       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1440       {
1441         int modCat = _prefs_->addPreference( mod->moduleName() );
1442         _prefs_->setItemProperty( modCat, "info", QString::null );
1443         mod->createPreferences();
1444       }
1445     }
1446   }
1447
1448   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1449            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1450
1451   return myPrefs;
1452 }
1453
1454 /*!Add new module to application.*/
1455 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1456 {
1457   CAM_Application::moduleAdded( mod );
1458
1459   SalomeApp_Module* salomeMod = 0;
1460   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1461     salomeMod = (SalomeApp_Module*)mod;
1462
1463   if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1464   {
1465     int modCat = myPrefs->addPreference( mod->moduleName() );
1466     myPrefs->setItemProperty( modCat, "info", QString::null );
1467     salomeMod->createPreferences();
1468   }
1469 }
1470
1471 /*!Create preferences.*/
1472 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1473 {
1474   if ( !pref )
1475     return;
1476
1477   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1478
1479   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1480   int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1481   pref->setItemProperty( studyGroup, "columns", 1 );
1482
1483   pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1484   pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1485   int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1486   pref->setItemProperty( undoPref, "min", 1 );
1487   pref->setItemProperty( undoPref, "max", 100 );
1488
1489   int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1490   pref->setItemProperty( extgroup, "columns", 1 );
1491   int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1492   pref->setItemProperty( apppref, "existing", true );
1493   pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1494
1495   pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1496
1497   int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1498   pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1499   pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1500
1501
1502
1503   int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1504   int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1505   for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1506   {
1507     pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1508                          SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1509   }
1510   pref->setItemProperty( defCols, "columns", 1 );
1511
1512   int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1513   pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1514
1515   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1516
1517   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1518
1519   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1520
1521   int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1522
1523   pref->setItemProperty( occGroup, "columns", 1 );
1524   pref->setItemProperty( vtkGroup, "columns", 1 );
1525   pref->setItemProperty( plot2dGroup, "columns", 1 );
1526
1527   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1528                                    SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1529   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1530                        SalomeApp_Preferences::Color, "OCCViewer", "background" );
1531
1532   pref->setItemProperty( occTS, "min", 1 );
1533   pref->setItemProperty( occTS, "max", 150 );
1534
1535   int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1536                                   SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1537   int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1538                                   SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1539
1540   pref->setItemProperty( isoU, "min", 0 );
1541   pref->setItemProperty( isoU, "max", 100000 );
1542
1543   pref->setItemProperty( isoV, "min", 0 );
1544   pref->setItemProperty( isoV, "max", 100000 );
1545
1546   int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1547                                    SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1548   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1549                        SalomeApp_Preferences::Color, "VTKViewer", "background" );
1550
1551   pref->setItemProperty( vtkTS, "min", 1 );
1552   pref->setItemProperty( vtkTS, "max", 150 );
1553
1554   pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1555                        SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1556
1557   int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1558                                             SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" );
1559   QStringList aLegendPosList;
1560   aLegendPosList.append( tr("PREF_LEFT") );
1561   aLegendPosList.append( tr("PREF_RIGHT") );
1562   aLegendPosList.append( tr("PREF_TOP") );
1563   aLegendPosList.append( tr("PREF_BOTTOM") );
1564
1565   QValueList<QVariant> anIndexesList;
1566   anIndexesList.append(0);
1567   anIndexesList.append(1);
1568   anIndexesList.append(2);
1569   anIndexesList.append(3);
1570
1571   pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1572   pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1573
1574   int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1575                                        SalomeApp_Preferences::Selector, "Plot2d", "CurveType" );
1576   QStringList aCurveTypesList;
1577   aCurveTypesList.append( tr("PREF_POINTS") );
1578   aCurveTypesList.append( tr("PREF_LINES") );
1579   aCurveTypesList.append( tr("PREF_SPLINE") );
1580
1581   anIndexesList.clear();
1582   anIndexesList.append(0);
1583   anIndexesList.append(1);
1584   anIndexesList.append(2);
1585
1586   pref->setItemProperty( curveType, "strings", aCurveTypesList );
1587   pref->setItemProperty( curveType, "indexes", anIndexesList );
1588
1589   int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1590                                         SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1591
1592   pref->setItemProperty( markerSize, "min", 0 );
1593   pref->setItemProperty( markerSize, "max", 100 );
1594
1595   QStringList aScaleModesList;
1596   aScaleModesList.append( tr("PREF_LINEAR") );
1597   aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1598
1599   anIndexesList.clear();
1600   anIndexesList.append(0);
1601   anIndexesList.append(1);
1602
1603   int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1604                                       SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1605
1606   pref->setItemProperty( horScale, "strings", aScaleModesList );
1607   pref->setItemProperty( horScale, "indexes", anIndexesList );
1608
1609   int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1610                                       SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1611
1612   pref->setItemProperty( verScale, "strings", aScaleModesList );
1613   pref->setItemProperty( verScale, "indexes", anIndexesList );
1614
1615   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1616                        SalomeApp_Preferences::Color, "Plot2d", "Background" );
1617
1618   int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1619   int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1620   pref->setItemProperty( dirGroup, "columns", 1 );
1621   pref->addPreference( tr( "" ), dirGroup,
1622                        SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1623 }
1624
1625 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1626 {
1627   SUIT_ResourceMgr* resMgr = resourceMgr();
1628   if ( !resMgr )
1629     return;
1630
1631   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1632   {
1633     int sz = resMgr->integerValue( sec, param, -1 );
1634     QPtrList<SUIT_ViewManager> lst;
1635     viewManagers( OCCViewer_Viewer::Type(), lst );
1636     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1637     {
1638       SUIT_ViewModel* vm = it.current()->getViewModel();
1639       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1640         continue;
1641
1642       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1643       occVM->setTrihedronSize( sz );
1644       occVM->getAISContext()->UpdateCurrentViewer();
1645     }
1646   }
1647
1648   if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1649   {
1650     int sz = resMgr->integerValue( sec, param, -1 );
1651     QPtrList<SUIT_ViewManager> lst;
1652     viewManagers( SVTK_Viewer::Type(), lst );
1653     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1654     {
1655       SUIT_ViewModel* vm = it.current()->getViewModel();
1656       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1657         continue;
1658
1659       SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1660       vtkVM->setTrihedronSize( sz );
1661       vtkVM->Repaint();
1662     }
1663   }
1664
1665   if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1666   {
1667     QPtrList<SUIT_ViewManager> lst;
1668     viewManagers( OCCViewer_Viewer::Type(), lst );
1669     int u = resMgr->integerValue( sec, "iso_number_u" );
1670     int v = resMgr->integerValue( sec, "iso_number_v" );
1671     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1672       ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1673   }
1674
1675   if( sec=="ObjectBrowser" )
1676   {
1677     if( param=="auto_size" )
1678     {
1679       OB_Browser* ob = objectBrowser();
1680       if( !ob )
1681         return;
1682
1683       bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1684       ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1685
1686       updateObjectBrowser( false );
1687     }
1688   }
1689
1690   if( sec=="PyConsole" )
1691   {
1692     if( param=="font" )
1693       if( pythonConsole() )
1694         pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1695   }
1696 }
1697
1698 /*!Update desktop title.*/
1699 void SalomeApp_Application::updateDesktopTitle() {
1700   QString aTitle = applicationName();
1701   QString aVer = applicationVersion();
1702   if ( !aVer.isEmpty() )
1703     aTitle += QString( " " ) + aVer;
1704
1705   if ( activeStudy() )
1706   {
1707     QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1708     if ( !sName.isEmpty() ) {
1709       SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1710       _PTR(Study) stdDS = study->studyDS();
1711       if(stdDS) {
1712         if ( stdDS->GetProperties()->IsLocked() ) {
1713           aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1714         } else {
1715           aTitle += QString( " - [%1]" ).arg( sName );
1716         }
1717       }
1718     }
1719   }
1720
1721   desktop()->setCaption( aTitle );
1722 }
1723
1724 /*!Update windows after close document.*/
1725 void SalomeApp_Application::afterCloseDoc()
1726 {
1727   updateWindows();
1728
1729   CAM_Application::afterCloseDoc();
1730 }
1731
1732 /*!Gets CORBA::ORB_var*/
1733 CORBA::ORB_var SalomeApp_Application::orb()
1734 {
1735   ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1736   static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1737   return _orb;
1738 }
1739
1740 /*!Create and return SALOMEDS_StudyManager.*/
1741 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1742 {
1743   static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1744   return _sm;
1745 }
1746
1747 /*!Create and return SALOME_NamingService.*/
1748 SALOME_NamingService* SalomeApp_Application::namingService()
1749 {
1750   static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1751   return _ns;
1752 }
1753
1754 /*!Create and return SALOME_LifeCycleCORBA.*/
1755 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1756 {
1757   static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1758   return _lcc;
1759 }
1760
1761 QString SalomeApp_Application::defaultEngineIOR()
1762 {
1763   /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1764   QString anIOR( "" );
1765   CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1766   if ( !CORBA::is_nil( anEngine ) )
1767     anIOR = orb()->object_to_string( anEngine );
1768   return anIOR;
1769 }
1770
1771 /*!Adds icon names for modules.*/
1772 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1773 {
1774   iconMap.clear();
1775
1776   SUIT_ResourceMgr* resMgr = resourceMgr();
1777   if ( !resMgr )
1778     return;
1779
1780   QStringList modList;
1781   modules( modList, false );
1782
1783   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1784   {
1785     QString modName = *it;
1786     QString modIntr = moduleName( modName );
1787     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1788
1789     if ( modIcon.isEmpty() )
1790       continue;
1791
1792     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1793       modIcon += QString( ".png" );
1794
1795     iconMap.insert( modName, modIcon );
1796   }
1797 }
1798
1799 /*!Update module action.*/
1800 void SalomeApp_Application::updateModuleActions()
1801 {
1802   QString modName;
1803   if ( activeModule() )
1804     modName = activeModule()->moduleName();
1805
1806   if ( myActions.contains( modName ) )
1807     myActions[modName]->setOn( true );
1808 }
1809
1810 /*!Gets current windows.
1811  *\param winMap - output current windows map.
1812  */
1813 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1814 {
1815   winMap.clear();
1816   if ( !activeStudy() )
1817     return;
1818
1819   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1820     ((SalomeApp_Module*)activeModule())->windows( winMap );
1821   else
1822     defaultWindows( winMap );
1823 }
1824
1825 /*!Gets current view managers.
1826  *\param lst - output current view managers list.
1827  */
1828 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1829 {
1830   lst.clear();
1831   if ( !activeStudy() )
1832     return;
1833
1834   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1835     ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1836   else
1837     defaultViewManagers( lst );
1838 }
1839
1840 /*!Update windows.*/
1841 void SalomeApp_Application::updateWindows()
1842 {
1843   QMap<int, int> winMap;
1844   currentWindows( winMap );
1845
1846   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1847     getWindow( it.key() );
1848
1849   loadWindowsGeometry();
1850
1851   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1852     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1853 }
1854
1855 /*!Update view managers.*/
1856 void SalomeApp_Application::updateViewManagers()
1857 {
1858   QStringList lst;
1859   currentViewManagers( lst );
1860
1861   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1862     getViewManager( *it, true );
1863 }
1864
1865 /*!Load windows geometry.*/
1866 void SalomeApp_Application::loadWindowsGeometry()
1867 {
1868   QtxDockAction* dockMgr = 0;
1869
1870   QAction* a = action( ViewWindowsId );
1871   if ( a && a->inherits( "QtxDockAction" ) )
1872     dockMgr = (QtxDockAction*)a;
1873
1874   if ( !dockMgr )
1875     return;
1876
1877   QString modName;
1878   if ( activeModule() )
1879     modName = moduleLibrary( activeModule()->moduleName(), false );
1880
1881   QString section = QString( "windows_geometry" );
1882   if ( !modName.isEmpty() )
1883     section += QString( "." ) + modName;
1884
1885   dockMgr->loadGeometry( resourceMgr(), section, false );
1886   dockMgr->restoreGeometry();
1887 }
1888
1889 /*!Save windows geometry.*/
1890 void SalomeApp_Application::saveWindowsGeometry()
1891 {
1892   QtxDockAction* dockMgr = 0;
1893
1894   QAction* a = action( ViewWindowsId );
1895   if ( a && a->inherits( "QtxDockAction" ) )
1896     dockMgr = (QtxDockAction*)a;
1897
1898   if ( !dockMgr )
1899     return;
1900
1901   QString modName;
1902   if ( activeModule() )
1903     modName = moduleLibrary( activeModule()->moduleName(), false );
1904
1905   QString section = QString( "windows_geometry" );
1906   if ( !modName.isEmpty() )
1907     section += QString( "." ) + modName;
1908
1909   dockMgr->storeGeometry();
1910   dockMgr->saveGeometry( resourceMgr(), section, false );
1911 }
1912
1913 /*!Activate windows.*/
1914 void SalomeApp_Application::activateWindows()
1915 {
1916   if ( activeStudy() )
1917   {
1918     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1919       itr.data()->activate( activeStudy()->id() );
1920   }
1921 }
1922
1923 /*!Private SLOT. On preferences.*/
1924 void SalomeApp_Application::onProperties()
1925 {
1926   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1927   if( !study )
1928     return;
1929
1930   _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1931   SB->NewCommand();
1932
1933   SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1934   int res = aDlg.exec();
1935   if( res==QDialog::Accepted && aDlg.isChanged() )
1936     SB->CommitCommand();
1937   else
1938     SB->AbortCommand();
1939
1940   //study->updateCaptions();
1941   updateDesktopTitle();
1942   updateActions();
1943 }
1944
1945 /*!*/
1946 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1947                                             const QString& caption, QWidget* parent )
1948 {
1949   if ( !parent )
1950     parent = desktop();
1951   QStringList fls = QStringList::split( ";;", filters, false );
1952   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1953 }
1954
1955 /*!*/
1956 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1957 {
1958   if ( !parent )
1959     parent = desktop();
1960   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1961 }
1962
1963 /*!*/
1964 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1965                                                      const QString& caption, QWidget* parent )
1966 {
1967   if ( !parent )
1968     parent = desktop();
1969   QStringList fls = QStringList::split( ";;", filters, false );
1970   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1971 }
1972
1973 /*!*/
1974 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1975 {
1976   CAM_Application::contextMenuPopup( type, thePopup, title );
1977
1978   OB_Browser* ob = objectBrowser();
1979   if ( !ob || type != ob->popupClientType() )
1980     return;
1981
1982   thePopup->insertSeparator();
1983   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1984
1985   // Get selected objects
1986   SALOME_ListIO aList;
1987   SalomeApp_SelectionMgr* mgr = selectionMgr();
1988   mgr->selectedObjects(aList);
1989
1990   // "Delete reference" item should appear only for invalid references
1991
1992   // Check if selected objects is invalid references
1993   bool isInvalidRefs = true;
1994
1995   if ( aList.Extent() < 1 )
1996     isInvalidRefs = false;
1997
1998   if ( isInvalidRefs )
1999     {
2000       SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
2001       _PTR(Study) aStudyDS = aStudy->studyDS();
2002       _PTR(SObject) anObj;
2003
2004       for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() )
2005         {
2006           if ( it.Value()->hasEntry() )
2007             {
2008               _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
2009               if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() )
2010                 isInvalidRefs = false;
2011             }
2012         }
2013     }
2014
2015   // Add "Delete refrence" item to popup
2016   if ( isInvalidRefs )
2017     {
2018       thePopup->insertSeparator();
2019       thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) );
2020       return;
2021     }
2022
2023   // "Activate module" item should appear only if it's necessary
2024   if (aList.Extent() != 1)
2025     return;
2026   Handle(SALOME_InteractiveObject) aIObj = aList.First();
2027   QString aModuleName(aIObj->getComponentDataType());
2028   QString aModuleTitle = moduleTitle(aModuleName);
2029   CAM_Module* currentModule = activeModule();
2030   if (currentModule && currentModule->moduleName() == aModuleTitle)
2031     return;
2032   thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
2033
2034 }
2035
2036 /*!Update obect browser*/
2037 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
2038 {
2039   // update existing data models (already loaded SComponents)
2040   if ( updateModels )
2041   {
2042     for ( ModuleListIterator it = modules(); it.current(); ++it )
2043     {
2044       CAM_DataModel* camDM = it.current()->dataModel();
2045       if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
2046         ((SalomeApp_DataModel*)camDM)->update();
2047     }
2048   }
2049   // update "non-existing" (not loaded yet) data models
2050   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
2051   if ( study )
2052   {
2053     _PTR(Study) stdDS = study->studyDS();
2054     if( stdDS )
2055     {
2056       for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
2057       {
2058         _PTR(SComponent) aComponent ( it->Value() );
2059
2060         if ( aComponent->ComponentDataType() == "Interface Applicative" )
2061           continue; // skip the magic "Interface Applicative" component
2062
2063         SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
2064       }
2065     }
2066   }
2067
2068   if ( objectBrowser() )
2069   {
2070     objectBrowser()->updateGeometry();
2071     objectBrowser()->updateTree();
2072   }
2073 }
2074
2075 /*!Protected SLOT.On desktop activated.*/
2076 void SalomeApp_Application::onDesktopActivated()
2077 {
2078   CAM_Application::onDesktopActivated();
2079   SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
2080   if(aModule)
2081     aModule->studyActivated();
2082 }
2083
2084 /*!Create empty study.*/
2085 void SalomeApp_Application::createEmptyStudy()
2086 {
2087   CAM_Application::createEmptyStudy();
2088   if ( objectBrowser() )
2089     objectBrowser()->updateTree();
2090 }
2091
2092 /*!Activate module \a mod.*/
2093 bool SalomeApp_Application::activateModule( CAM_Module* mod )
2094 {
2095   bool res = CAM_Application::activateModule( mod );
2096   if ( objectBrowser() )
2097     objectBrowser()->updateTree();
2098   return res;
2099 }
2100
2101 /*!Display Catalog Genenerator dialog */
2102 void SalomeApp_Application::onCatalogGen()
2103 {
2104   ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
2105   aDlg.exec();
2106 }
2107
2108 /*!Display Registry Display dialog */
2109 void SalomeApp_Application::onRegDisplay()
2110 {
2111   CORBA::ORB_var anOrb = orb();
2112   ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
2113   regWnd->show();
2114   regWnd->raise();
2115   regWnd->setActiveWindow();
2116 }
2117
2118 /*!return keyborad accelerators manager object */
2119 SUIT_Accel* SalomeApp_Application::accel() const
2120 {
2121   return myAccel;
2122 }