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