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