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