]> SALOME platform Git repositories - modules/gui.git/blob - src/SalomeApp/SalomeApp_Application.cxx
Salome HOME
a3eb99fea6c343d77f90bfde9f0bddafeadc8f77
[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    //Varibales isEnabledCopy and isEnabledPaste are used for multi selection.
560    bool isEnabledCopy = true;  
561    bool isEnabledPaste = true;  
562
563    for ( SALOME_ListIteratorOfListIO it( list ); it.More() && (isEnabledCopy || isEnabledPaste); it.Next() )
564    {
565       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
566
567       qaction = action(EditCopyId); 
568       if( isEnabledCopy && studyMgr()->CanCopy(so) ) qaction->setEnabled(true);  
569       else { 
570         isEnabledCopy = false;
571         qaction->setEnabled(false);         
572       }
573
574       qaction = action(EditPasteId);
575       if( isEnabledPaste && studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
576       else {
577         isEnabledPaste = false;
578         qaction->setEnabled(false);
579       }
580    } 
581 }               
582  
583 void SalomeApp_Application::onRefresh()
584 {
585   updateObjectBrowser( true );
586 }
587
588  
589 void SalomeApp_Application::onOpenWith()
590 {
591   QApplication::setOverrideCursor( Qt::waitCursor );
592   SALOME_ListIO aList;
593   SalomeApp_SelectionMgr* mgr = selectionMgr();
594   mgr->selectedObjects(aList);
595   if (aList.Extent() > 1) return;
596   Handle(SALOME_InteractiveObject) aIObj = aList.First();
597   QString aModuleName(aIObj->getComponentDataType());
598   QString aModuleTitle = moduleTitle(aModuleName);
599   activateModule(aModuleTitle);
600   QApplication::restoreOverrideCursor();
601 }
602
603 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
604 {
605   CAM_Application::setActiveStudy( study );
606
607   activateWindows();
608 }
609
610 //=======================================================================
611 // name    : createNewStudy
612 // Purpose : Create new study
613 //=======================================================================
614 SUIT_Study* SalomeApp_Application::createNewStudy()
615 {
616   SalomeApp_Study* aStudy = new SalomeApp_Study( this );
617
618   // Set up processing of major study-related events
619   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
620   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
621   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
622   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
623
624   return aStudy;
625 }
626
627 //=======================================================================
628 // name    : createNewStudy
629 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
630 //=======================================================================
631 void SalomeApp_Application::updateCommandsStatus()
632 {
633   CAM_Application::updateCommandsStatus();
634
635   for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
636   {
637     QAction* a = action( id );
638     if ( a )
639       a->setEnabled( activeStudy() );
640   }
641
642   // Dump study menu
643   QAction* a = action( DumpStudyId );
644   if ( a )
645     a->setEnabled( activeStudy() );
646
647   // Load script menu
648   a = action( LoadScriptId );
649   if ( a )
650     a->setEnabled( activeStudy() );
651   
652   a = action( PropertiesId );
653   if( a )
654     a->setEnabled( activeStudy() );
655     
656   a = action(EditCopyId);
657   a->setEnabled(false);       
658   a = action(EditPasteId);
659   a->setEnabled(false);      
660 }
661
662 //=======================================================================
663 // name    : onHelpAbout
664 // Purpose : SLOT. Display "About" message box
665 //=======================================================================
666 void SalomeApp_Application::onHelpAbout()
667 {
668   SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
669   dlg->exec();
670   delete dlg;
671 }
672
673 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
674 {
675   QWidget* wid = 0;
676
677   int sId = studyId;
678   if ( sId < 0 )
679   {
680     if ( !activeStudy() )
681       return 0;
682     else
683       sId = activeStudy()->id();
684   }
685
686   if ( myWindows.contains( flag ) )
687     wid = myWindows[flag]->widget( sId );
688
689   return wid;
690 }
691
692 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
693 {
694   if ( !wid )
695     return;
696
697   int sId = studyId;
698   if ( sId < 0 )
699   {
700     if ( !activeStudy() )
701       return;
702     else
703       sId = activeStudy()->id();
704   }
705
706   if ( !myWindows.contains( flag ) )
707   {
708     QMap<int, int> winMap;
709     currentWindows( winMap );
710
711     myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
712     if ( winMap.contains( flag ) )
713       desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
714
715     myWindows[flag]->setResizeEnabled( true );
716     myWindows[flag]->setCloseMode( QDockWindow::Always );
717     myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
718   }
719
720   myWindows[flag]->insert( sId, wid );
721
722   setWindowShown( flag, !myWindows[flag]->isEmpty() );
723 }
724
725 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
726 {
727   if ( !myWindows.contains( flag ) )
728     return;
729
730   int sId = studyId;
731   if ( sId < 0 )
732   {
733     if ( !activeStudy() )
734       return;
735     else
736       sId = activeStudy()->id();
737   }
738
739   QWidget* wid = myWindows[flag]->widget( sId );
740   myWindows[flag]->remove( sId );
741   delete wid;
742
743   setWindowShown( flag, !myWindows[flag]->isEmpty() );
744 }
745
746 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
747 {
748   QWidget* wid = window( flag, studyId );
749   if ( !wid )
750     addWindow( wid = createWindow( flag ), flag, studyId );
751
752   return wid;
753 }
754
755 bool SalomeApp_Application::isWindowVisible( const int type ) const
756 {
757   bool res = false;
758   if ( myWindows.contains( type ) )
759   {
760     SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
761     res = desk && desk->appropriate( myWindows[type] );
762   }
763   return res;
764 }
765
766 void SalomeApp_Application::setWindowShown( const int type, const bool on )
767 {
768   if ( !desktop() || !myWindows.contains( type ) )
769     return;
770
771   QDockWindow* dw = myWindows[type];
772   desktop()->setAppropriate( dw, on );
773   on ? dw->show() : dw->hide();
774 }
775
776 OB_Browser* SalomeApp_Application::objectBrowser()
777 {
778   OB_Browser* ob = 0;
779   QWidget* wid = getWindow( WT_ObjectBrowser );
780   if ( wid->inherits( "OB_Browser" ) )
781     ob = (OB_Browser*)wid;
782   return ob;
783 }
784
785 LogWindow* SalomeApp_Application::logWindow()
786 {
787   LogWindow* lw = 0;
788   QWidget* wid = getWindow( WT_LogWindow );
789   if ( wid->inherits( "LogWindow" ) )
790     lw = (LogWindow*)wid;
791   return lw;
792 }
793
794 PythonConsole* SalomeApp_Application::pythonConsole()
795 {
796   PythonConsole* console = 0;
797   QWidget* wid = getWindow( WT_PyConsole );
798   if ( wid->inherits( "PythonConsole" ) )
799     console = (PythonConsole*)wid;
800   return console;
801 }
802
803 SalomeApp_Preferences* SalomeApp_Application::preferences() const
804 {
805   return preferences( false );
806 }
807
808 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
809 {
810   SUIT_ViewManager* aVM = viewManager( vmType );
811   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
812
813   if ( anActiveVM && anActiveVM->getType() == vmType )
814     aVM = anActiveVM;
815
816   if ( aVM && create )
817   {
818     if ( !aVM->getActiveView() )
819       aVM->createView();
820     else
821       aVM->getActiveView()->setFocus();
822   }
823   else if ( create )
824     aVM = createViewManager( vmType );
825
826   return aVM;
827 }
828
829 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
830 {
831   SUIT_ResourceMgr* resMgr = resourceMgr();
832
833   SUIT_ViewManager* viewMgr = 0;
834   if ( vmType == GLViewer_Viewer::Type() )
835   {
836     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
837     new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
838   }
839   else if ( vmType == Plot2d_Viewer::Type() )
840   {
841     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
842     viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
843   }
844   else if ( vmType == OCCViewer_Viewer::Type() )
845   {
846     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
847     SOCC_Viewer* vm = new SOCC_Viewer();
848     vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
849     vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
850     int u( 1 ), v( 1 );
851     vm->isos( u, v );
852     u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
853     v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
854     //    vm->setIsos( u, v );
855     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
856     new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
857   }
858   else if ( vmType == SVTK_Viewer::Type() )
859   {
860     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
861     SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
862     vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
863     vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
864     new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
865   }
866
867   if ( !viewMgr )
868     return 0;
869
870   addViewManager( viewMgr );
871   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
872
873   if ( viewWin && desktop() )
874     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
875
876   connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
877            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
878
879   return viewMgr;
880 }
881
882 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
883 {
884   removeViewManager( theVM );
885 }
886
887 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
888 {
889   SUIT_DataObject* aRoot = 0;
890   if ( theStudy && theStudy->root() )
891   {
892     aRoot = theStudy->root();
893     //aRoot->setName( tr( "DATA_MODELS" ) );
894   }
895   if ( objectBrowser() != 0 )
896     objectBrowser()->setRootObject( aRoot );
897
898   activateModule( defaultModule() );
899
900   activateWindows();
901 }
902
903 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
904 {
905   SUIT_DataObject* aRoot = 0;
906   if ( theStudy && theStudy->root() )
907   {
908     aRoot = theStudy->root();
909     //aRoot->dump();
910   }
911   if ( objectBrowser() != 0 ) {
912     objectBrowser()->setRootObject( aRoot );
913   }
914
915   activateModule( defaultModule() );
916
917   activateWindows();
918
919   emit studyOpened();
920 }
921
922 void SalomeApp_Application::onStudySaved( SUIT_Study* )
923 {
924   emit studySaved();
925 }
926
927 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
928 {
929   emit studyClosed();
930
931   activateModule( "" );
932
933   saveWindowsGeometry();
934 }
935
936 void SalomeApp_Application::onDumpStudy( )
937 {
938   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
939   if ( !appStudy ) return;
940   _PTR(Study) aStudy = appStudy->studyDS();
941
942   QStringList aFilters;
943   aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
944
945   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
946   fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
947   fd->setFilters( aFilters );  
948   fd->SetChecked(true);
949   fd->exec();
950   QString aFileName = fd->selectedFile();
951   bool toPublish = fd->IsChecked();
952   delete fd;
953
954   if(!aFileName.isEmpty()) {
955     QFileInfo aFileInfo(aFileName);
956     aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
957   }
958 }
959
960 void SalomeApp_Application::onLoadScript( )
961 {
962   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
963   if ( !appStudy ) return;
964   _PTR(Study) aStudy = appStudy->studyDS();
965
966   if ( aStudy->GetProperties()->IsLocked() ) {
967     SUIT_MessageBox::warn1 ( desktop(),
968                              QObject::tr("WRN_WARNING"),
969                              QObject::tr("WRN_STUDY_LOCKED"),
970                              QObject::tr("BUT_OK") );
971     return;
972   }
973
974   QStringList filtersList;
975   filtersList.append(tr("PYTHON_FILES_FILTER"));
976   filtersList.append(tr("ALL_FILES_FILTER"));
977
978   QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
979
980   if ( !aFile.isEmpty() )
981   {
982     QString command = QString("execfile(\"%1\")").arg(aFile);
983
984     PythonConsole* pyConsole = pythonConsole();
985
986     if ( pyConsole )
987       pyConsole->exec( command );
988   }
989 }
990
991 void SalomeApp_Application::onPreferences()
992 {
993   QApplication::setOverrideCursor( Qt::waitCursor );
994
995   SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
996
997   QApplication::restoreOverrideCursor();
998
999   if ( !prefDlg )
1000     return;
1001
1002   prefDlg->exec();
1003
1004   delete prefDlg;
1005 }
1006
1007 void SalomeApp_Application::onMRUActivated( QString aName )
1008 {
1009   onOpenDoc( aName );
1010 }
1011
1012 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1013 {
1014   SalomeApp_Module* sMod = 0;
1015   CAM_Module* mod = module( modName );
1016   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1017     sMod = (SalomeApp_Module*)mod;
1018
1019   if ( sMod )
1020     sMod->preferencesChanged( section, param );
1021   else
1022     preferencesChanged( section, param );
1023 }
1024
1025 QString SalomeApp_Application::getFileFilter() const
1026 {
1027   return "(*.hdf)";
1028 }
1029
1030 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1031 {
1032   CAM_Application::beforeCloseDoc( s );
1033
1034   for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1035     removeWindow( itr.key(), s->id() );
1036 }
1037
1038 void SalomeApp_Application::updateActions()
1039 {
1040   updateCommandsStatus();
1041 }
1042
1043 QWidget* SalomeApp_Application::createWindow( const int flag )
1044 {
1045   QWidget* wid = 0;
1046
1047   SUIT_ResourceMgr* resMgr = resourceMgr();
1048
1049   if ( flag == WT_ObjectBrowser )
1050   {
1051     OB_Browser* ob = new OB_Browser( desktop() );
1052     ob->setAutoUpdate( true );
1053     ob->setAutoOpenLevel( 1 );
1054     ob->setCaption( tr( "OBJECT_BROWSER" ) );
1055     ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1056     ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1057
1058     ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1059
1060     for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1061     {
1062       ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1063       ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1064                                                    QString().sprintf( "visibility_column_%d", i ), true ) );
1065     }
1066
1067     // Create OBSelector
1068     new SalomeApp_OBSelector( ob, mySelMgr );
1069
1070     wid = ob;
1071
1072     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1073   }
1074   else if ( flag == WT_PyConsole )
1075   {
1076     PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1077     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1078     wid = pyCons;
1079
1080     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1081   }
1082   else if ( flag == WT_LogWindow )
1083   {
1084     LogWindow* logWin = new LogWindow( desktop() );
1085     logWin->setCaption( tr( "LOG_WINDOW" ) );
1086     wid = logWin;
1087
1088     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1089   }
1090
1091   return wid;
1092 }
1093
1094 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1095 {
1096   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1097   aMap.insert( WT_PyConsole, Qt::DockBottom );
1098   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1099 }
1100
1101 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1102 {
1103 }
1104
1105 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1106 {
1107   if ( myPrefs )
1108     return myPrefs;
1109
1110   SalomeApp_Application* that = (SalomeApp_Application*)this;
1111
1112   if ( !_prefs_ && crt )
1113   {
1114     _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1115     that->createPreferences( _prefs_ );
1116   }
1117
1118   that->myPrefs = _prefs_;
1119
1120   QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1121   for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1122   {
1123     if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1124       continue;
1125
1126     SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1127
1128     QStringList modNameList;
1129     app->modules( modNameList, false );
1130     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1131     {
1132       int id = _prefs_->addPreference( *it );
1133       _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1134     }
1135
1136     ModuleList modList;
1137     app->modules( modList );
1138     for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1139     {
1140       SalomeApp_Module* mod = 0;
1141       if ( itr.current()->inherits( "SalomeApp_Module" ) )
1142         mod = (SalomeApp_Module*)itr.current();
1143
1144       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1145         mod->createPreferences();
1146     }
1147   }
1148
1149   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1150            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1151
1152   return myPrefs;
1153 }
1154
1155 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1156 {
1157   CAM_Application::moduleAdded( mod );
1158
1159   SalomeApp_Module* salomeMod = 0;
1160   if ( mod && mod->inherits( "SalomeApp_Module" ) )
1161     salomeMod = (SalomeApp_Module*)mod;
1162
1163   if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1164     salomeMod->createPreferences();
1165 }
1166
1167 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1168 {
1169   if ( !pref )
1170     return;
1171
1172   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1173
1174   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1175
1176   int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1177   for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1178   {
1179     pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1180                          SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1181   }
1182   pref->setProperty( obGroup, "columns", 1 );
1183
1184   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1185
1186   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1187
1188   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1189   pref->setProperty( occGroup, "columns", 1 );
1190   pref->setProperty( vtkGroup, "columns", 1 );
1191
1192   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1193                                    SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1194   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1195                        SalomeApp_Preferences::Color, "OCCViewer", "background" );
1196
1197   pref->setProperty( occTS, "min", 1 );
1198   pref->setProperty( occTS, "max", 150 );
1199
1200   int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1201                                   SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1202   int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1203                                   SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1204
1205   pref->setProperty( isoU, "min", 0 );
1206   pref->setProperty( isoU, "max", 100000 );
1207
1208   pref->setProperty( isoV, "min", 0 );
1209   pref->setProperty( isoV, "max", 100000 );
1210
1211   int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1212                                    SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1213   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1214                        SalomeApp_Preferences::Color, "VTKViewer", "background" );
1215
1216   pref->setProperty( vtkTS, "min", 1 );
1217   pref->setProperty( vtkTS, "max", 150 );
1218 }
1219
1220 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1221 {
1222   SUIT_ResourceMgr* resMgr = resourceMgr();
1223   if ( !resMgr )
1224     return;
1225
1226   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1227   {
1228     int sz = resMgr->integerValue( sec, param, -1 );
1229     QPtrList<SUIT_ViewManager> lst;
1230     viewManagers( OCCViewer_Viewer::Type(), lst );
1231     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1232     {
1233       SUIT_ViewModel* vm = it.current()->getViewModel();
1234       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1235         continue;
1236
1237       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1238       occVM->setTrihedronSize( sz );
1239       occVM->getAISContext()->UpdateCurrentViewer();
1240     }
1241   }
1242
1243   if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1244   {
1245     int sz = resMgr->integerValue( sec, param, -1 );
1246     QPtrList<SUIT_ViewManager> lst;
1247     viewManagers( SVTK_Viewer::Type(), lst );
1248     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1249     {
1250       SUIT_ViewModel* vm = it.current()->getViewModel();
1251       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1252         continue;
1253
1254       SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1255       vtkVM->setTrihedronSize( sz );
1256       vtkVM->Repaint();
1257     }
1258   }
1259   /*
1260   if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1261   {
1262     QPtrList<SUIT_ViewManager> lst;
1263     viewManagers( OCCViewer_Viewer::Type(), lst );
1264     int u = resMgr->integerValue( sec, "iso_number_u" );
1265     int v = resMgr->integerValue( sec, "iso_number_v" );
1266     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1267       ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1268   }
1269   */
1270 }
1271
1272 void SalomeApp_Application::afterCloseDoc()
1273 {
1274   updateWindows();
1275
1276   CAM_Application::afterCloseDoc();
1277 }
1278
1279 CORBA::ORB_var SalomeApp_Application::orb()
1280 {
1281   ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1282   static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1283   return _orb;
1284 }
1285
1286 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1287 {
1288   static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1289   return _sm;
1290 }
1291
1292 SALOME_NamingService* SalomeApp_Application::namingService()
1293 {
1294   static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1295   return _ns;
1296 }
1297
1298 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1299 {
1300   static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1301   return _lcc;
1302 }
1303
1304 QString SalomeApp_Application::defaultEngineIOR()
1305 {
1306   // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1307   QString anIOR( "" );
1308   CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1309   if ( !CORBA::is_nil( anEngine ) )
1310     anIOR = orb()->object_to_string( anEngine );
1311   return anIOR;
1312 }
1313
1314 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1315 {
1316   iconMap.clear();
1317
1318   SUIT_ResourceMgr* resMgr = resourceMgr();
1319   if ( !resMgr )
1320     return;
1321
1322   QStringList modList;
1323   modules( modList, false );
1324
1325   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1326   {
1327     QString modName = *it;
1328     QString modIntr = moduleName( modName );
1329     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1330
1331     if ( modIcon.isEmpty() )
1332       continue;
1333
1334     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1335       modIcon += QString( ".png" );
1336
1337     iconMap.insert( modName, modIcon );
1338   }
1339 }
1340
1341 void SalomeApp_Application::updateModuleActions()
1342 {
1343   QString modName;
1344   if ( activeModule() )
1345     modName = activeModule()->moduleName();
1346
1347   if ( myActions.contains( modName ) )
1348     myActions[modName]->setOn( true );
1349 }
1350
1351 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1352 {
1353   winMap.clear();
1354   if ( !activeStudy() )
1355     return;
1356
1357   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1358     ((SalomeApp_Module*)activeModule())->windows( winMap );
1359   else
1360     defaultWindows( winMap );
1361 }
1362
1363 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1364 {
1365   lst.clear();
1366   if ( !activeStudy() )
1367     return;
1368
1369   if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1370     ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1371   else
1372     defaultViewManagers( lst );
1373 }
1374
1375 void SalomeApp_Application::updateWindows()
1376 {
1377   QMap<int, int> winMap;
1378   currentWindows( winMap );
1379
1380   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1381     getWindow( it.key() );
1382
1383   loadWindowsGeometry();
1384
1385   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1386     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1387 }
1388
1389 void SalomeApp_Application::updateViewManagers()
1390 {
1391   QStringList lst;
1392   currentViewManagers( lst );
1393
1394   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1395     getViewManager( *it, true );
1396 }
1397
1398 void SalomeApp_Application::loadWindowsGeometry()
1399 {
1400   QtxDockAction* dockMgr = 0;
1401
1402   QAction* a = action( ViewWindowsId );
1403   if ( a && a->inherits( "QtxDockAction" ) )
1404     dockMgr = (QtxDockAction*)a;
1405
1406   if ( !dockMgr )
1407     return;
1408
1409   QString modName;
1410   if ( activeModule() )
1411     modName = moduleLibrary( activeModule()->moduleName(), false );
1412
1413   QString section = QString( "windows_geometry" );
1414   if ( !modName.isEmpty() )
1415     section += QString( "." ) + modName;
1416
1417   dockMgr->loadGeometry( resourceMgr(), section, false );
1418   dockMgr->restoreGeometry();
1419 }
1420
1421 void SalomeApp_Application::saveWindowsGeometry()
1422 {
1423   QtxDockAction* dockMgr = 0;
1424
1425   QAction* a = action( ViewWindowsId );
1426   if ( a && a->inherits( "QtxDockAction" ) )
1427     dockMgr = (QtxDockAction*)a;
1428
1429   if ( !dockMgr )
1430     return;
1431
1432   QString modName;
1433   if ( activeModule() )
1434     modName = moduleLibrary( activeModule()->moduleName(), false );
1435
1436   QString section = QString( "windows_geometry" );
1437   if ( !modName.isEmpty() )
1438     section += QString( "." ) + modName;
1439
1440   dockMgr->storeGeometry();
1441   dockMgr->saveGeometry( resourceMgr(), section, false );
1442 }
1443
1444 void SalomeApp_Application::activateWindows()
1445 {
1446   if ( activeStudy() )
1447   {
1448     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1449       itr.data()->activate( activeStudy()->id() );
1450   }
1451 }
1452
1453 void SalomeApp_Application::onProperties()
1454 {
1455   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1456   if( !study )
1457     return;
1458
1459   _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1460   SB->NewCommand();
1461
1462   SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1463   int res = aDlg.exec();
1464   if( res==QDialog::Accepted && aDlg.isChanged() )
1465     SB->CommitCommand();
1466   else
1467     SB->AbortCommand();
1468
1469   //study->updateCaptions();
1470 }
1471
1472 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters, 
1473                                             const QString& caption, QWidget* parent )
1474 {
1475   if ( !parent )
1476     parent = desktop();
1477   QStringList fls = QStringList::split( ";;", filters, false );
1478   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1479 }
1480
1481 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1482 {
1483   if ( !parent )
1484     parent = desktop();
1485   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1486 }
1487
1488 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters, 
1489                                                      const QString& caption, QWidget* parent )
1490 {
1491   if ( !parent )
1492     parent = desktop();
1493   QStringList fls = QStringList::split( ";;", filters, false );
1494   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1495 }
1496
1497 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1498 {
1499   CAM_Application::contextMenuPopup( type, thePopup, title );
1500   thePopup->insertSeparator();
1501   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1502   thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1503 }
1504
1505 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1506 {
1507   if ( updateModels ) 
1508   {
1509     for ( ModuleListIterator it = modules(); it.current(); ++it )
1510     {    
1511       CAM_DataModel* camDM = it.current()->dataModel();
1512       if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1513         ((SalomeApp_DataModel*)camDM)->update();
1514     }
1515   }
1516   if ( objectBrowser() )
1517     objectBrowser()->updateTree();
1518 }