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