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