]> SALOME platform Git repositories - modules/gui.git/blob - src/SalomeApp/SalomeApp_Application.cxx
Salome HOME
d79353718785be02a6a0cf7921ea4be8092130b5
[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 <SUIT_Tools.h>
48 #include <SUIT_Session.h>
49
50 #include <QtxToolBar.h>
51 #include <QtxMRUAction.h>
52 #include <QtxDockAction.h>
53 #include <QtxResourceEdit.h>
54
55 #include <OB_Browser.h>
56
57 #include <PythonConsole_PyConsole.h>
58
59 #include <SUIT_FileDlg.h>
60 #include <SUIT_MessageBox.h>
61 #include <SUIT_ResourceMgr.h>
62 #include <SUIT_ActionOperation.h>
63
64 #include <Utils_ORB_INIT.hxx>
65 #include <Utils_SINGLETON.hxx>
66 #include <SALOME_ModuleCatalog_impl.hxx>
67 #include <SALOME_LifeCycleCORBA.hxx>
68
69 #include <qmap.h>
70 #include <qdir.h>
71 #include <qlabel.h>
72 #include <qimage.h>
73 #include <qaction.h>
74 #include <qmenubar.h>
75 #include <qcombobox.h>
76 #include <qmessagebox.h>
77 #include <qapplication.h>
78
79 #include "SALOMEDS_StudyManager.hxx"
80
81 #include "SALOME_ListIteratorOfListIO.hxx"
82 #include "SALOME_ListIO.hxx"
83
84 #define OBJECT_BROWSER_WIDTH 300
85
86 static const char* imageEmptyIcon[] = {
87 "20 20 1 1",
88 ".      c None",
89 "....................",
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "...................."};
109
110 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
111 {
112   return new SalomeApp_Application();
113 }
114
115 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
116
117 /*
118   Class       : SalomeApp_Application
119   Description : Application containing SalomeApp module
120 */
121
122 SalomeApp_Application::SalomeApp_Application()
123 : CAM_Application( false ),
124 myPrefs( 0 )
125 {
126   STD_TabDesktop* desk = new STD_TabDesktop();
127
128   setDesktop( desk );
129
130   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
131   QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
132
133   desktop()->setIcon( aLogo );
134   desktop()->setDockableMenuBar( true );
135   desktop()->setDockableStatusBar( false );
136
137   clearViewManagers();
138
139   mySelMgr = new SalomeApp_SelectionMgr( this );
140
141   connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
142            this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
143
144   connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
145 }
146
147 SalomeApp_Application::~SalomeApp_Application()
148 {
149   saveWindowsGeometry();
150
151   if ( resourceMgr() )
152   {
153     if ( desktop() )
154       desktop()->saveGeometry( resourceMgr(), "desktop" );
155     resourceMgr()->save();
156   }
157
158   delete mySelMgr;
159
160   SalomeApp_EventFilter::Destroy();
161 }
162
163 void SalomeApp_Application::start()
164 {
165   if ( desktop() )
166     desktop()->loadGeometry( resourceMgr(), "desktop" );
167
168   CAM_Application::start();
169
170   QAction* a = action( ViewWindowsId );
171   if ( a && a->inherits( "QtxDockAction" ) )
172     ((QtxDockAction*)a)->setAutoPlace( true );
173
174   SalomeApp_EventFilter::Init();
175
176   updateWindows();
177   updateViewManagers();
178
179   putInfo( "" );
180 }
181
182 QString SalomeApp_Application::applicationName() const
183 {
184   return tr( "APP_NAME" );
185 }
186
187 QString SalomeApp_Application::applicationVersion() const
188 {
189   static QString _app_version;
190
191   if ( _app_version.isEmpty() )
192   {
193     QString path( ::getenv( "GUI_ROOT_DIR" ) );
194     if ( !path.isEmpty() )
195       path += QDir::separator();
196     path += QString( "bin/salome/VERSION" );
197
198     QFile vf( path );
199     if ( vf.open( IO_ReadOnly ) )
200     {
201       QString line;
202       vf.readLine( line, 1024 );
203       vf.close();
204
205       if ( !line.isEmpty() )
206       {
207         while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
208           line.remove( line.length() - 1, 1 );
209
210         int idx = line.findRev( ":" );
211         if ( idx != -1 )
212           _app_version = line.mid( idx + 1 ).stripWhiteSpace();
213       }
214     }
215   }
216
217   return _app_version;
218 }
219
220 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
221 {
222   CAM_Module* mod = CAM_Application::loadModule( name );
223   if ( mod )
224   {
225     connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
226     connect( this, SIGNAL( studySaved() ),  mod, SLOT( onModelSaved() ) );
227     connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
228   }
229   return mod;
230 }
231
232 bool SalomeApp_Application::activateModule( const QString& modName )
233 {
234   QString actName;
235   CAM_Module* prevMod = activeModule();
236
237   if ( prevMod )
238     actName = prevMod->moduleName();
239
240   if ( actName == modName )
241     return true;
242
243   saveWindowsGeometry();
244
245   bool status = CAM_Application::activateModule( modName );
246
247   updateModuleActions();
248
249   if ( !status )
250     return false;
251
252   updateWindows();
253   updateViewManagers();
254
255   return true;
256 }
257
258 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
259 {
260   return mySelMgr;
261 }
262
263 void SalomeApp_Application::createActions()
264 {
265   STD_Application::createActions();
266
267   SUIT_Desktop* desk = desktop();
268   SUIT_ResourceMgr* resMgr = resourceMgr();
269   
270   // Dump study
271   createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
272                 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
273                 0, desk, false, this, SLOT( onDumpStudy() ) );
274     
275   // Load script
276   createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
277                 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
278                 0, desk, false, this, SLOT( onLoadScript() ) );
279
280   // Properties
281   createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
282                 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
283                 0, desk, false, this, SLOT( onProperties() ) );
284
285   // Preferences
286   createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
287                 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
288                 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
289
290   // MRU
291   QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
292   connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
293   registerAction( MRUId, mru );
294
295   // default icon for neutral point ('SALOME' module)
296   QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
297   if ( defIcon.isNull() )
298     defIcon = QPixmap( imageEmptyIcon );
299
300   // default icon for any module
301   QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
302   if ( modIcon.isNull() )
303     modIcon = QPixmap( imageEmptyIcon );
304
305   QToolBar* modTBar = new QtxToolBar( true, desk );
306   modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
307
308   QActionGroup* modGroup = new QActionGroup( this );
309   modGroup->setExclusive( true );
310   modGroup->setUsesDropDown( true );
311
312   QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
313                              tr( "PRP_APP_MODULE" ), 0, desk, true );
314   modGroup->add( a );
315   myActions.insert( QString(), a );
316
317   QMap<QString, QString> iconMap;
318   moduleIconNames( iconMap );
319
320   const int iconSize = 20;
321
322   modGroup->addTo( modTBar );
323   modTBar->addSeparator();
324
325   QStringList modList;
326   modules( modList, false );
327
328   for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
329   {
330     if ( (*it).isEmpty() )
331       continue;
332
333     QString iconName;
334     if ( iconMap.contains( *it ) )
335       iconName = iconMap[*it];
336
337     QString modName = moduleName( *it );
338
339     QPixmap icon = resMgr->loadPixmap( modName, iconName );
340     if ( icon.isNull() )
341       icon = modIcon;
342
343     icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
344
345     QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
346     a->addTo( modTBar );
347     modGroup->add( a );
348
349     myActions.insert( *it, a );
350   }
351
352   SUIT_Tools::simplifySeparators( modTBar );
353
354   // New window
355
356   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
357   int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
358   createMenu( separator(), windowMenu, -1, 1 );
359
360   QMap<int, int> accelMap;
361   accelMap[NewGLViewId]  = ALT+Key_G;
362   accelMap[NewPlot2dId]  = ALT+Key_P;
363   accelMap[NewOCCViewId] = ALT+Key_O;
364   accelMap[NewVTKViewId] = ALT+Key_K;
365
366   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
367   {
368     QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
369                                tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
370                                tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
371                                accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
372     createMenu( a, newWinMenu, -1 );
373   }
374   connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
375
376   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
377
378   createMenu( DumpStudyId, fileMenu, 10, -1 );
379   createMenu( separator(), fileMenu, -1, 15, -1 );
380   createMenu( LoadScriptId, fileMenu, 10, -1 );
381   createMenu( separator(), fileMenu, -1, 15, -1 );
382   createMenu( PropertiesId, fileMenu, 10, -1 );
383   createMenu( separator(), fileMenu, -1, 15, -1 );
384   createMenu( PreferencesId, fileMenu, 15, -1 );
385   createMenu( separator(), fileMenu, -1, 15, -1 );
386
387   /*
388   createMenu( separator(), fileMenu, -1, 100, -1 );
389   createMenu( MRUId, fileMenu, 100, -1 );
390   createMenu( separator(), fileMenu, -1, 100, -1 );
391   */
392 }
393
394 void SalomeApp_Application::onModuleActivation( QAction* a )
395 {
396   if ( !a )
397     return;
398
399   QString modName = a->menuText();
400   if ( modName == tr( "APP_NAME" ) )
401     modName = QString::null;
402
403   // Force user to create/open a study before module activation
404   QMap<QString, QString> iconMap;
405   moduleIconNames( iconMap );
406   QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
407
408   bool cancelled = false;
409   while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
410     SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
411     int res = aDlg.exec();
412
413     switch ( res ){
414     case 1:
415       onNewDoc();
416       break;
417     case 2:
418       onOpenDoc();
419       break;
420     case 3:
421       //onLoadStudy();
422       //break;
423     case 0:
424     default:
425       putInfo( tr("INF_CANCELLED") );
426       myActions[QString()]->setOn( true );
427       cancelled = true;
428     }
429   }
430
431   if ( !cancelled )
432     activateModule( modName );
433 }
434
435 QString SalomeApp_Application::defaultModule() const
436 {
437   QStringList aModuleNames;
438   modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
439   // If there's the one and only module --> activate it automatically
440   // TODO: Possible improvement - default module can be taken from preferences
441   return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
442 }
443
444 void SalomeApp_Application::onNewWindow()
445 {
446   const QObject* obj = sender();
447   if ( !obj || !obj->inherits( "QAction" ) )
448     return;
449
450   QString type;
451   int id = actionId( (QAction*)obj );
452   switch ( id )
453   {
454   case NewGLViewId:
455     type = GLViewer_Viewer::Type();
456     break;
457   case NewPlot2dId:
458     type = Plot2d_Viewer::Type();
459     break;
460   case NewOCCViewId:
461     type = OCCViewer_Viewer::Type();
462     break;
463   case NewVTKViewId:
464     type = VTKViewer_Viewer::Type();
465     break;
466   }
467
468   if ( !type.isEmpty() )
469     createViewManager( type );
470 }
471
472 //=======================================================================
473 // name    : onNewDoc
474 // Purpose : SLOT. Create new document
475 //=======================================================================
476 void SalomeApp_Application::onNewDoc()
477 {
478   SUIT_Study* study = activeStudy();
479
480   saveWindowsGeometry();
481
482   CAM_Application::onNewDoc();
483
484   if ( !study ) // new study will be create in THIS application
485   {
486     updateWindows();
487     updateViewManagers();
488   }
489 }
490
491 //=======================================================================
492 // name    : onOpenDoc
493 // Purpose : SLOT. Open new document
494 //=======================================================================
495 void SalomeApp_Application::onOpenDoc()
496 {
497   SUIT_Study* study = activeStudy();
498   saveWindowsGeometry();
499
500   CAM_Application::onOpenDoc();
501
502   if ( !study ) // new study will be create in THIS application
503   {
504     updateWindows();
505     updateViewManagers();
506   }
507 }
508
509 bool SalomeApp_Application::onOpenDoc( const QString& aName )
510 {
511   bool res = CAM_Application::onOpenDoc( aName );
512
513   QAction* a = action( MRUId );
514   if ( a && a->inherits( "QtxMRUAction" ) )
515   {
516     QtxMRUAction* mru = (QtxMRUAction*)a;
517     if ( res )
518       mru->insert( aName );
519     else
520       mru->remove( aName );
521   }
522   return res;
523 }
524
525 void SalomeApp_Application::onSelection()
526 {
527   onSelectionChanged();
528
529   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
530     ((SalomeApp_Module*)activeModule())->selectionChanged();
531 }
532
533 void SalomeApp_Application::onSelectionChanged()
534 {
535  /*
536    SalomeApp_Module* module = dynamic_cast<SalomeApp_Module*>(activeModule());
537    if(module == NULL) return;
538    
539    QString ior = module->engineIOR();
540    if(ior.length() < 5) return; //Not a real CORBA IOR
541    CORBA::Object_var obj = orb()->string_to_object(ior.latin1());
542    if(CORBA::is_nil(obj)) return;
543    
544    SALOMEDS::Driver_var engine = SALOMEDS::Driver::_narrow(obj);
545    if(CORBA::is_nil(engine)) return;
546 */
547
548    SALOME_ListIO list;
549    SalomeApp_SelectionMgr* mgr = selectionMgr();
550    mgr->selectedObjects(list);
551    
552    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
553    if(study == NULL) return;
554    
555    _PTR(Study) stdDS = study->studyDS();
556    if(!stdDS) return;
557    
558    QAction* qaction;  
559    
560    for ( SALOME_ListIteratorOfListIO it( list ); it.More(); it.Next() )
561    {
562       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
563       qaction = action(EditCutId);
564       if( studyMgr()->CanCopy(so) ) {
565         qaction->setEnabled(true);
566         qaction = action(EditCopyId); 
567         qaction->setEnabled(true);  
568       }
569       else {
570         qaction->setEnabled(false);
571         qaction = action(EditCopyId);
572         qaction->setEnabled(false);         
573       }
574       qaction = action(EditPasteId);
575       if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
576       else qaction->setEnabled(false);
577    } 
578 }               
579  
580 void SalomeApp_Application::onRefresh()
581 {
582   updateObjectBrowser( true );
583 }
584
585  
586 void SalomeApp_Application::onOpenWith()
587 {
588   QApplication::setOverrideCursor( Qt::waitCursor );
589   SALOME_ListIO aList;
590   SalomeApp_SelectionMgr* mgr = selectionMgr();
591   mgr->selectedObjects(aList);
592   if (aList.Extent() > 1) return;
593   Handle(SALOME_InteractiveObject) aIObj = aList.First();
594   QString aModuleName(aIObj->getComponentDataType());
595   QString aModuleTitle = moduleTitle(aModuleName);
596   activateModule(aModuleTitle);
597   QApplication::restoreOverrideCursor();
598 }
599
600 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
601 {
602   CAM_Application::setActiveStudy( study );
603
604   activateWindows();
605 }
606
607 //=======================================================================
608 // name    : createNewStudy
609 // Purpose : Create new study
610 //=======================================================================
611 SUIT_Study* SalomeApp_Application::createNewStudy()
612 {
613   SalomeApp_Study* aStudy = new SalomeApp_Study( this );
614
615   // Set up processing of major study-related events
616   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
617   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
618   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
619   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
620
621   return aStudy;
622 }
623
624 //=======================================================================
625 // name    : createNewStudy
626 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
627 //=======================================================================
628 void SalomeApp_Application::updateCommandsStatus()
629 {
630   CAM_Application::updateCommandsStatus();
631
632   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
633   {
634     QAction* a = action( id );
635     if ( a )
636       a->setEnabled( activeStudy() );
637   }
638
639   // Dump study menu
640   QAction* a = action( DumpStudyId );
641   if ( a )
642     a->setEnabled( activeStudy() );
643
644   // Load script menu
645   a = action( LoadScriptId );
646   if ( a )
647     a->setEnabled( activeStudy() );
648   
649   a = action( PropertiesId );
650   if( a )
651     a->setEnabled( activeStudy() );
652     
653   a = action(EditCutId);
654   a->setEnabled(false); 
655   a = action(EditCopyId);
656   a->setEnabled(false);       
657   a = action(EditPasteId);
658   a->setEnabled(false);      
659 }
660
661 //=======================================================================
662 // name    : onHelpAbout
663 // Purpose : SLOT. Display "About" message box
664 //=======================================================================
665 void SalomeApp_Application::onHelpAbout()
666 {
667   SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
668   dlg->exec();
669   delete dlg;
670 }
671
672 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
673 {
674   QWidget* wid = 0;
675
676   int sId = studyId;
677   if ( sId < 0 )
678   {
679     if ( !activeStudy() )
680       return 0;
681     else
682       sId = activeStudy()->id();
683   }
684
685   if ( myWindows.contains( flag ) )
686     wid = myWindows[flag]->widget( sId );
687
688   return wid;
689 }
690
691 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
692 {
693   if ( !wid )
694     return;
695
696   int sId = studyId;
697   if ( sId < 0 )
698   {
699     if ( !activeStudy() )
700       return;
701     else
702       sId = activeStudy()->id();
703   }
704
705   if ( !myWindows.contains( flag ) )
706   {
707     QMap<int, int> winMap;
708     currentWindows( winMap );
709
710     myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
711     if ( winMap.contains( flag ) )
712       desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
713
714     myWindows[flag]->setResizeEnabled( true );
715     myWindows[flag]->setCloseMode( QDockWindow::Always );
716     myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
717   }
718
719   myWindows[flag]->insert( sId, wid );
720
721   setWindowShown( flag, !myWindows[flag]->isEmpty() );
722 }
723
724 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
725 {
726   if ( !myWindows.contains( flag ) )
727     return;
728
729   int sId = studyId;
730   if ( sId < 0 )
731   {
732     if ( !activeStudy() )
733       return;
734     else
735       sId = activeStudy()->id();
736   }
737
738   QWidget* wid = myWindows[flag]->widget( sId );
739   myWindows[flag]->remove( sId );
740   delete wid;
741
742   setWindowShown( flag, !myWindows[flag]->isEmpty() );
743 }
744
745 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
746 {
747   QWidget* wid = window( flag, studyId );
748   if ( !wid )
749     addWindow( wid = createWindow( flag ), flag, studyId );
750
751   return wid;
752 }
753
754 bool SalomeApp_Application::isWindowVisible( const int type ) const
755 {
756   bool res = false;
757   if ( myWindows.contains( type ) )
758   {
759     SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
760     res = desk && desk->appropriate( myWindows[type] );
761   }
762   return res;
763 }
764
765 void SalomeApp_Application::setWindowShown( const int type, const bool on )
766 {
767   if ( !desktop() || !myWindows.contains( type ) )
768     return;
769
770   QDockWindow* dw = myWindows[type];
771   desktop()->setAppropriate( dw, on );
772   on ? dw->show() : dw->hide();
773 }
774
775 OB_Browser* SalomeApp_Application::objectBrowser()
776 {
777   OB_Browser* ob = 0;
778   QWidget* wid = getWindow( WT_ObjectBrowser );
779   if ( wid->inherits( "OB_Browser" ) )
780     ob = (OB_Browser*)wid;
781   return ob;
782 }
783
784 LogWindow* SalomeApp_Application::logWindow()
785 {
786   LogWindow* lw = 0;
787   QWidget* wid = getWindow( WT_LogWindow );
788   if ( wid->inherits( "LogWindow" ) )
789     lw = (LogWindow*)wid;
790   return lw;
791 }
792
793 PythonConsole* SalomeApp_Application::pythonConsole()
794 {
795   PythonConsole* console = 0;
796   QWidget* wid = getWindow( WT_PyConsole );
797   if ( wid->inherits( "PythonConsole" ) )
798     console = (PythonConsole*)wid;
799   return console;
800 }
801
802 SalomeApp_Preferences* SalomeApp_Application::preferences() const
803 {
804   return preferences( false );
805 }
806
807 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
808 {
809   SUIT_ViewManager* aVM = viewManager( vmType );
810   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
811
812   if ( anActiveVM && anActiveVM->getType() == vmType )
813     aVM = anActiveVM;
814
815   if ( aVM && create )
816   {
817     if ( !aVM->getActiveView() )
818       aVM->createView();
819     else
820       aVM->getActiveView()->setFocus();
821   }
822   else if ( create )
823     aVM = createViewManager( vmType );
824
825   return aVM;
826 }
827
828 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
829 {
830   SUIT_ResourceMgr* resMgr = resourceMgr();
831
832   SUIT_ViewManager* viewMgr = 0;
833   if ( vmType == GLViewer_Viewer::Type() )
834   {
835     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
836     new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
837   }
838   else if ( vmType == Plot2d_Viewer::Type() )
839   {
840     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
841     viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
842   }
843   else if ( vmType == OCCViewer_Viewer::Type() )
844   {
845     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
846     SOCC_Viewer* vm = new SOCC_Viewer();
847     vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
848     vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
849     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
850     new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
851   }
852   else if ( vmType == SVTK_Viewer::Type() )
853   {
854     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
855     SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
856     vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
857     new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
858   }
859
860   if ( !viewMgr )
861     return 0;
862
863   addViewManager( viewMgr );
864   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
865
866   if ( viewWin && desktop() )
867     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
868
869   connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
870            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
871
872   return viewMgr;
873 }
874
875 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
876 {
877   removeViewManager( theVM );
878 }
879
880 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
881 {
882   SUIT_DataObject* aRoot = 0;
883   if ( theStudy && theStudy->root() )
884   {
885     aRoot = theStudy->root();
886     //aRoot->setName( tr( "DATA_MODELS" ) );
887   }
888   if ( objectBrowser() != 0 )
889     objectBrowser()->setRootObject( aRoot );
890
891   activateModule( defaultModule() );
892
893   activateWindows();
894 }
895
896 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
897 {
898   SUIT_DataObject* aRoot = 0;
899   if ( theStudy && theStudy->root() )
900   {
901     aRoot = theStudy->root();
902     //aRoot->dump();
903   }
904   if ( objectBrowser() != 0 ) {
905     objectBrowser()->setRootObject( aRoot );
906   }
907
908   activateModule( defaultModule() );
909
910   activateWindows();
911
912   emit studyOpened();
913 }
914
915 void SalomeApp_Application::onStudySaved( SUIT_Study* )
916 {
917   emit studySaved();
918 }
919
920 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
921 {
922   emit studyClosed();
923
924   activateModule( "" );
925
926   saveWindowsGeometry();
927 }
928
929 void SalomeApp_Application::onDumpStudy( )
930 {
931   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
932   if ( !appStudy ) return;
933   _PTR(Study) aStudy = appStudy->studyDS();
934
935   QStringList aFilters;
936   aFilters.append(tr("PYTHON_FILES_FILTER"));
937
938   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
939   fd->setCaption(tr("TOT_DESK_FILE_DUMP_STUDY"));
940   fd->setFilters( aFilters );  
941   fd->SetChecked(true);
942   fd->exec();
943   QString aFileName = fd->selectedFile();
944   bool toPublish = fd->IsChecked();
945   delete fd;
946
947   if(!aFileName.isEmpty()) {
948     QFileInfo aFileInfo(aFileName);
949     aStudy->DumpStudy(aFileInfo.dirPath(true), aFileInfo.baseName(), toPublish);
950   }
951 }
952
953 void SalomeApp_Application::onLoadScript( )
954 {
955   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
956   if ( !appStudy ) return;
957   _PTR(Study) aStudy = appStudy->studyDS();
958
959   if ( aStudy->GetProperties()->IsLocked() ) {
960     SUIT_MessageBox::warn1 ( desktop(),
961                              QObject::tr("WRN_WARNING"),
962                              QObject::tr("WRN_STUDY_LOCKED"),
963                              QObject::tr("BUT_OK") );
964     return;
965   }
966
967   QStringList filtersList;
968   filtersList.append(tr("PYTHON_FILES_FILTER"));
969   filtersList.append(tr("ALL_FILES_FILTER"));
970
971   QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
972
973   if ( !aFile.isEmpty() )
974   {
975     QString command = QString("execfile(\"%1\")").arg(aFile);
976
977     PythonConsole* pyConsole = pythonConsole();
978
979     if ( pyConsole )
980       pyConsole->exec( command );
981   }
982 }
983
984 void SalomeApp_Application::onPreferences()
985 {
986   QApplication::setOverrideCursor( Qt::waitCursor );
987
988   SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
989
990   QApplication::restoreOverrideCursor();
991
992   if ( !prefDlg )
993     return;
994
995   prefDlg->exec();
996
997   delete prefDlg;
998 }
999
1000 void SalomeApp_Application::onMRUActivated( QString aName )
1001 {
1002   onOpenDoc( aName );
1003 }
1004
1005 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1006 {
1007   SalomeApp_Module* sMod = 0;
1008   CAM_Module* mod = module( modName );
1009   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1010     sMod = (SalomeApp_Module*)mod;
1011
1012   if ( sMod )
1013     sMod->preferencesChanged( section, param );
1014   else
1015     preferencesChanged( section, param );
1016 }
1017
1018 QString SalomeApp_Application::getFileFilter() const
1019 {
1020   return "(*.hdf)";
1021 }
1022
1023 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1024 {
1025   CAM_Application::beforeCloseDoc( s );
1026
1027   for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1028     removeWindow( itr.key(), s->id() );
1029 }
1030
1031 void SalomeApp_Application::updateActions()
1032 {
1033   updateCommandsStatus();
1034 }
1035
1036 QWidget* SalomeApp_Application::createWindow( const int flag )
1037 {
1038   QWidget* wid = 0;
1039
1040   SUIT_ResourceMgr* resMgr = resourceMgr();
1041
1042   if ( flag == WT_ObjectBrowser )
1043   {
1044     OB_Browser* ob = new OB_Browser( desktop() );
1045     ob->setAutoUpdate( true );
1046     ob->setAutoOpenLevel( 1 );
1047     ob->setCaption( tr( "OBJECT_BROWSER" ) );
1048     ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1049     ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1050
1051     ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1052
1053     for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1054     {
1055       ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1056       ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1057                                                    QString().sprintf( "visibility_column_%d", i ), true ) );
1058     }
1059
1060     // Create OBSelector
1061     new SalomeApp_OBSelector( ob, mySelMgr );
1062
1063     wid = ob;
1064
1065     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1066   }
1067   else if ( flag == WT_PyConsole )
1068   {
1069     PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1070     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1071     wid = pyCons;
1072
1073     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1074   }
1075   else if ( flag == WT_LogWindow )
1076   {
1077     LogWindow* logWin = new LogWindow( desktop() );
1078     logWin->setCaption( tr( "LOG_WINDOW" ) );
1079     wid = logWin;
1080
1081     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1082   }
1083
1084   return wid;
1085 }
1086
1087 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1088 {
1089   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1090   aMap.insert( WT_PyConsole, Qt::DockBottom );
1091   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1092 }
1093
1094 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1095 {
1096 }
1097
1098 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1099 {
1100   if ( myPrefs )
1101     return myPrefs;
1102
1103   SalomeApp_Application* that = (SalomeApp_Application*)this;
1104
1105   if ( !_prefs_ && crt )
1106   {
1107     _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1108     that->createPreferences( _prefs_ );
1109   }
1110
1111   that->myPrefs = _prefs_;
1112
1113   QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1114   for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1115   {
1116     if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1117       continue;
1118
1119     SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1120
1121     QStringList modNameList;
1122     app->modules( modNameList, false );
1123     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1124     {
1125       int id = _prefs_->addPreference( *it );
1126       _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1127     }
1128
1129     ModuleList modList;
1130     app->modules( modList );
1131     for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1132     {
1133       SalomeApp_Module* mod = 0;
1134       if ( itr.current()->inherits( "SalomeApp_Module" ) )
1135         mod = (SalomeApp_Module*)itr.current();
1136
1137       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1138         mod->createPreferences();
1139     }
1140   }
1141
1142   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1143            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1144
1145   return myPrefs;
1146 }
1147
1148 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1149 {
1150   CAM_Application::moduleAdded( mod );
1151
1152   SalomeApp_Module* salomeMod = 0;
1153   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1154     salomeMod = (SalomeApp_Module*)mod;
1155
1156   if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1157     salomeMod->createPreferences();
1158 }
1159
1160 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1161 {
1162   if ( !pref )
1163     return;
1164
1165   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1166
1167   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1168
1169   int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1170   for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1171   {
1172     pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1173                          SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1174   }
1175   pref->setProperty( obGroup, "columns", 1 );
1176
1177   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1178
1179   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1180
1181   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1182   pref->setProperty( occGroup, "columns", 1 );
1183   pref->setProperty( vtkGroup, "columns", 1 );
1184
1185   pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1186                        SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1187   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1188                        SalomeApp_Preferences::Color, "OCCViewer", "background" );
1189
1190   pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1191                        SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1192   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1193                        SalomeApp_Preferences::Color, "VTKViewer", "background" );
1194 }
1195
1196 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1197 {
1198   SUIT_ResourceMgr* resMgr = resourceMgr();
1199   if ( !resMgr )
1200     return;
1201
1202   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1203   {
1204     int sz = resMgr->integerValue( sec, param, -1 );
1205     QPtrList<SUIT_ViewManager> lst;
1206     viewManagers( OCCViewer_Viewer::Type(), lst );
1207     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1208     {
1209       SUIT_ViewModel* vm = it.current()->getViewModel();
1210       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1211         continue;
1212
1213       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1214       occVM->setTrihedronSize( sz );
1215       occVM->getAISContext()->UpdateCurrentViewer();
1216     }
1217   }
1218 }
1219
1220 void SalomeApp_Application::afterCloseDoc()
1221 {
1222   updateWindows();
1223
1224   CAM_Application::afterCloseDoc();
1225 }
1226
1227 CORBA::ORB_var SalomeApp_Application::orb()
1228 {
1229   ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1230   static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1231   return _orb;
1232 }
1233
1234 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1235 {
1236   static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1237   return _sm;
1238 }
1239
1240 SALOME_NamingService* SalomeApp_Application::namingService()
1241 {
1242   static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1243   return _ns;
1244 }
1245
1246 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1247 {
1248   static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1249   return _lcc;
1250 }
1251
1252 QString SalomeApp_Application::defaultEngineIOR()
1253 {
1254   // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1255   QString anIOR( "" );
1256   CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1257   if ( !CORBA::is_nil( anEngine ) )
1258     anIOR = orb()->object_to_string( anEngine );
1259   return anIOR;
1260 }
1261
1262 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1263 {
1264   iconMap.clear();
1265
1266   SUIT_ResourceMgr* resMgr = resourceMgr();
1267   if ( !resMgr )
1268     return;
1269
1270   QStringList modList;
1271   modules( modList, false );
1272
1273   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1274   {
1275     QString modName = *it;
1276     QString modIntr = moduleName( modName );
1277     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1278
1279     if ( modIcon.isEmpty() )
1280       continue;
1281
1282     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1283       modIcon += QString( ".png" );
1284
1285     iconMap.insert( modName, modIcon );
1286   }
1287 }
1288
1289 void SalomeApp_Application::updateModuleActions()
1290 {
1291   QString modName;
1292   if ( activeModule() )
1293     modName = activeModule()->moduleName();
1294
1295   if ( myActions.contains( modName ) )
1296     myActions[modName]->setOn( true );
1297 }
1298
1299 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1300 {
1301   winMap.clear();
1302   if ( !activeStudy() )
1303     return;
1304
1305   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1306     ((SalomeApp_Module*)activeModule())->windows( winMap );
1307   else
1308     defaultWindows( winMap );
1309 }
1310
1311 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1312 {
1313   lst.clear();
1314   if ( !activeStudy() )
1315     return;
1316
1317   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1318     ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1319   else
1320     defaultViewManagers( lst );
1321 }
1322
1323 void SalomeApp_Application::updateWindows()
1324 {
1325   QMap<int, int> winMap;
1326   currentWindows( winMap );
1327
1328   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1329     getWindow( it.key() );
1330
1331   loadWindowsGeometry();
1332
1333   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1334     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1335 }
1336
1337 void SalomeApp_Application::updateViewManagers()
1338 {
1339   QStringList lst;
1340   currentViewManagers( lst );
1341
1342   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1343     getViewManager( *it, true );
1344 }
1345
1346 void SalomeApp_Application::loadWindowsGeometry()
1347 {
1348   QtxDockAction* dockMgr = 0;
1349
1350   QAction* a = action( ViewWindowsId );
1351   if ( a && a->inherits( "QtxDockAction" ) )
1352     dockMgr = (QtxDockAction*)a;
1353
1354   if ( !dockMgr )
1355     return;
1356
1357   QString modName;
1358   if ( activeModule() )
1359     modName = moduleLibrary( activeModule()->moduleName(), false );
1360
1361   QString section = QString( "windows_geometry" );
1362   if ( !modName.isEmpty() )
1363     section += QString( "." ) + modName;
1364
1365   dockMgr->loadGeometry( resourceMgr(), section, false );
1366   dockMgr->restoreGeometry();
1367 }
1368
1369 void SalomeApp_Application::saveWindowsGeometry()
1370 {
1371   QtxDockAction* dockMgr = 0;
1372
1373   QAction* a = action( ViewWindowsId );
1374   if ( a && a->inherits( "QtxDockAction" ) )
1375     dockMgr = (QtxDockAction*)a;
1376
1377   if ( !dockMgr )
1378     return;
1379
1380   QString modName;
1381   if ( activeModule() )
1382     modName = moduleLibrary( activeModule()->moduleName(), false );
1383
1384   QString section = QString( "windows_geometry" );
1385   if ( !modName.isEmpty() )
1386     section += QString( "." ) + modName;
1387
1388   dockMgr->storeGeometry();
1389   dockMgr->saveGeometry( resourceMgr(), section, false );
1390 }
1391
1392 void SalomeApp_Application::activateWindows()
1393 {
1394   if ( activeStudy() )
1395   {
1396     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1397       itr.data()->activate( activeStudy()->id() );
1398   }
1399 }
1400
1401 void SalomeApp_Application::onProperties()
1402 {
1403   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1404   if( !study )
1405     return;
1406
1407   _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1408   SB->NewCommand();
1409
1410   SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1411   int res = aDlg.exec();
1412   if( res==QDialog::Accepted && aDlg.isChanged() )
1413     SB->CommitCommand();
1414   else
1415     SB->AbortCommand();
1416
1417   //study->updateCaptions();
1418 }
1419
1420 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters, 
1421                                             const QString& caption, QWidget* parent )
1422 {
1423   if ( !parent )
1424     parent = desktop();
1425   QStringList fls = QStringList::split( ";;", filters, false );
1426   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1427 }
1428
1429 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1430 {
1431   if ( !parent )
1432     parent = desktop();
1433   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1434 }
1435
1436 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters, 
1437                                                      const QString& caption, QWidget* parent )
1438 {
1439   if ( !parent )
1440     parent = desktop();
1441   QStringList fls = QStringList::split( ";;", filters, false );
1442   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1443 }
1444
1445 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1446 {
1447   CAM_Application::contextMenuPopup( type, thePopup, title );
1448   thePopup->insertSeparator();
1449   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1450   thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1451 }
1452
1453 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1454 {
1455   if ( updateModels ) 
1456   {
1457     for ( ModuleListIterator it = modules(); it.current(); ++it )
1458     {    
1459       CAM_DataModel* camDM = it.current()->dataModel();
1460       if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1461         ((SalomeApp_DataModel*)camDM)->update();
1462     }
1463   }
1464   if ( objectBrowser() )
1465     objectBrowser()->updateTree();
1466 }