]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_Application.cxx
Salome HOME
1c231df2a68624cefcafbbcd9e034b63b5934193
[modules/gui.git] / src / LightApp / LightApp_Application.cxx
1 // File:      LightApp_Application.cxx
2 // Created:   6/20/2005 18:39:45 PM
3 // Author:    Natalia Donis
4 // Copyright (C) CEA 2005
5
6 #ifndef DISABLE_PYCONSOLE
7   #include "PythonConsole_PyInterp.h" // WARNING! This include must be the first!
8   #include <PythonConsole_PyConsole.h>
9 #endif
10
11 #include "LightApp_Application.h"
12 #include "LightApp_WidgetContainer.h"
13 #include "LightApp_Module.h"
14 #include "LightApp_DataModel.h"
15 #include "LightApp_Study.h"
16 #include "LightApp_Preferences.h"
17 #include "LightApp_PreferencesDlg.h"
18 #include "LightApp_ModuleDlg.h"
19 #include "LightApp_AboutDlg.h"
20
21 #include "LightApp_OBFilter.h"
22
23 #include "LightApp_OBSelector.h"
24 #include "LightApp_SelectionMgr.h"
25
26 #include <CAM_Module.h>
27 #include <CAM_DataModel.h>
28 #include <CAM_Study.h>
29 #include <STD_TabDesktop.h>
30
31 #include <SUIT_Session.h>
32 #include <SUIT_Study.h>
33 #include <SUIT_FileDlg.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Tools.h>
36 #include <SUIT_Accel.h>
37
38 #include <QtxMRUAction.h>
39 #include <QtxDockAction.h>
40 #include <QtxToolBar.h>
41
42 #include <LogWindow.h>
43 #include <OB_Browser.h>
44 #include <OB_ListView.h>
45
46 #ifndef DISABLE_GLVIEWER
47   #include <GLViewer_Viewer.h>
48   #include <GLViewer_ViewManager.h>
49   #include "LightApp_GLSelector.h"
50 #endif
51
52 #ifndef DISABLE_PLOT2DVIEWER
53   #include <Plot2d_ViewManager.h>
54   #include <Plot2d_ViewModel.h>
55 #ifndef DISABLE_SALOMEOBJECT
56   #include <SPlot2d_ViewModel.h>
57 #else
58   #include <Plot2d_ViewModel.h>
59 #endif
60 #endif
61
62 #ifndef DISABLE_OCCVIEWER
63   #include <OCCViewer_ViewManager.h>
64 #ifndef DISABLE_SALOMEOBJECT
65   #include <SOCC_ViewModel.h>
66 #else
67   #include <OCCViewer_ViewModel.h>
68 #endif
69   #include "LightApp_OCCSelector.h"
70 #endif
71
72 #ifndef DISABLE_VTKVIEWER
73 #ifndef DISABLE_SALOMEOBJECT
74   #include <SVTK_ViewModel.h>
75   #include <SVTK_ViewManager.h>
76   #include "LightApp_VTKSelector.h"
77 #else
78   #include <VTKViewer_ViewModel.h>
79   #include <VTKViewer_ViewManager.h>
80 #endif
81   #include <VTKViewer_ViewModel.h>
82 #endif
83
84 //#ifndef DISABLE_SUPERVGRAPHVIEWER
85 //  #include <SUPERVGraph_ViewModel.h>
86 //  #include <SUPERVGraph_ViewFrame.h>
87 //  #include <SUPERVGraph_ViewManager.h>
88 //#endif
89
90 #include <QtxWorkstack.h>
91
92 #include <qdir.h>
93 #include <qimage.h>
94 #include <qstring.h>
95 #include <qwidget.h>
96 #include <qstringlist.h>
97 #include <qfile.h>
98 #include <qapplication.h>
99 #include <qmap.h>
100 #include <qstatusbar.h>
101 #include <qthread.h>
102 #include <qobjectlist.h>
103 #include <qcombobox.h>
104 #include <qinputdialog.h>
105 #include <qmessagebox.h>
106 #include <qfontdatabase.h>
107
108 #define FIRST_HELP_ID 1000000
109
110 #ifndef DISABLE_SALOMEOBJECT
111   #include "SALOME_InteractiveObject.hxx"
112   #include "SALOME_ListIO.hxx"
113 #endif
114
115 static const char* imageEmptyIcon[] = {
116 "20 20 1 1",
117 ".      c None",
118 "....................",
119 "....................",
120 "....................",
121 "....................",
122 "....................",
123 "....................",
124 "....................",
125 "....................",
126 "....................",
127 "....................",
128 "....................",
129 "....................",
130 "....................",
131 "....................",
132 "....................",
133 "....................",
134 "....................",
135 "....................",
136 "....................",
137 "...................."};
138
139 int LightApp_Application::lastStudyId = 0;
140
141 /*!
142   \return last global id of study
143 */
144 int LightApp_Application::studyId()
145 {
146   return LightApp_Application::lastStudyId;
147 }
148
149 /*!Create new instance of LightApp_Application.*/
150 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
151 {
152   return new LightApp_Application();
153 }
154
155 /*! \var global preferences of LightApp */
156 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
157
158 /*!
159   \class LightApp_Application
160   Application containing LightApp module
161 */
162
163 /*!Constructor.*/
164 LightApp_Application::LightApp_Application()
165 : CAM_Application( false ),
166 myPrefs( 0 )
167 {
168   STD_TabDesktop* desk = new STD_TabDesktop();
169
170   setDesktop( desk );
171
172   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
173   QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
174
175   desktop()->setIcon( aLogo );
176   desktop()->setDockableMenuBar( true );
177   desktop()->setDockableStatusBar( false );
178
179   // base logo (salome itself)
180   desktop()->addLogo( "_app_base",  aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
181   // extra logo (salome-based application)
182   desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
183
184   clearViewManagers();
185
186   mySelMgr = new LightApp_SelectionMgr( this );
187
188   myAccel = SUIT_Accel::getAccel();
189
190 #ifndef DISABLE_OCCVIEWER
191   myAccel->setActionKey( SUIT_Accel::PanLeft,     CTRL+Key_Left,     OCCViewer_Viewer::Type() );
192   myAccel->setActionKey( SUIT_Accel::PanRight,    CTRL+Key_Right,    OCCViewer_Viewer::Type() );
193   myAccel->setActionKey( SUIT_Accel::PanUp,       CTRL+Key_Up,       OCCViewer_Viewer::Type() );
194   myAccel->setActionKey( SUIT_Accel::PanDown,     CTRL+Key_Down,     OCCViewer_Viewer::Type() );
195   myAccel->setActionKey( SUIT_Accel::ZoomIn,      CTRL+Key_Plus,     OCCViewer_Viewer::Type() );
196   myAccel->setActionKey( SUIT_Accel::ZoomOut,     CTRL+Key_Minus,    OCCViewer_Viewer::Type() );
197   myAccel->setActionKey( SUIT_Accel::ZoomFit,     CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
198   myAccel->setActionKey( SUIT_Accel::RotateLeft,  ALT+Key_Left,      OCCViewer_Viewer::Type() );
199   myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right,     OCCViewer_Viewer::Type() );
200   myAccel->setActionKey( SUIT_Accel::RotateUp,    ALT+Key_Up,        OCCViewer_Viewer::Type() );
201   myAccel->setActionKey( SUIT_Accel::RotateDown,  ALT+Key_Down,      OCCViewer_Viewer::Type() );
202 #endif
203 #ifndef DISABLE_VTKVIEWER
204   myAccel->setActionKey( SUIT_Accel::PanLeft,     CTRL+Key_Left,     VTKViewer_Viewer::Type() );
205   myAccel->setActionKey( SUIT_Accel::PanRight,    CTRL+Key_Right,    VTKViewer_Viewer::Type() );
206   myAccel->setActionKey( SUIT_Accel::PanUp,       CTRL+Key_Up,       VTKViewer_Viewer::Type() );
207   myAccel->setActionKey( SUIT_Accel::PanDown,     CTRL+Key_Down,     VTKViewer_Viewer::Type() );
208   myAccel->setActionKey( SUIT_Accel::ZoomIn,      CTRL+Key_Plus,     VTKViewer_Viewer::Type() );
209   myAccel->setActionKey( SUIT_Accel::ZoomOut,     CTRL+Key_Minus,    VTKViewer_Viewer::Type() );
210   myAccel->setActionKey( SUIT_Accel::ZoomFit,     CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
211   myAccel->setActionKey( SUIT_Accel::RotateLeft,  ALT+Key_Left,      VTKViewer_Viewer::Type() );
212   myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right,     VTKViewer_Viewer::Type() );
213   myAccel->setActionKey( SUIT_Accel::RotateUp,    ALT+Key_Up,        VTKViewer_Viewer::Type() );
214   myAccel->setActionKey( SUIT_Accel::RotateDown,  ALT+Key_Down,      VTKViewer_Viewer::Type() );
215 #endif
216
217   connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
218
219   // Set existing font for the python console in resources
220   if( !aResMgr->hasValue( "PyConsole", "font" ) )
221     return;
222   
223   QFont f = aResMgr->fontValue( "PyConsole", "font" );
224   QFontDatabase fdb;
225   QStringList famdb = fdb.families();
226   
227   if ( famdb.contains(f.family()) || !aResMgr->hasValue( "PyConsole", "additional_families" ) )
228     return;
229   
230   QStringList anAddFamilies = QStringList::split( ";", aResMgr->stringValue( "PyConsole", "additional_families" ) );
231   QString aFamily;
232   for ( QStringList::Iterator it = anAddFamilies.begin(); it != anAddFamilies.end(); ++it )
233     {
234       aFamily = *it;
235       if ( famdb.contains(aFamily) )
236         {
237           f.setFamily( aFamily );
238           aResMgr->setValue( "PyConsole", "font", f );
239           break;
240         }
241     }
242 }
243
244 /*!Destructor.
245  *\li Save window geometry.
246  *\li Save desktop geometry.
247  *\li Save resource maneger.
248  *\li Delete selection manager.
249  */
250 LightApp_Application::~LightApp_Application()
251 {
252   delete mySelMgr;
253 }
254
255 /*!Start application.*/
256 void LightApp_Application::start()
257 {
258   if ( desktop() )
259     desktop()->loadGeometry( resourceMgr(), "desktop" );
260
261   CAM_Application::start();
262
263   QAction* a = action( ViewWindowsId );
264   if ( a && a->inherits( "QtxDockAction" ) )
265     ((QtxDockAction*)a)->setAutoPlace( true );
266
267   updateWindows();
268   updateViewManagers();
269
270   putInfo( "" );
271   desktop()->statusBar()->message( "" );
272 }
273
274 /*!Gets application name.*/
275 QString LightApp_Application::applicationName() const
276 {
277   return tr( "APP_NAME" );
278 }
279
280 /*!Gets application version.*/
281 QString LightApp_Application::applicationVersion() const
282 {
283   static QString _app_version;
284
285   if ( _app_version.isEmpty() )
286   {
287     QString resVersion = tr( "APP_VERSION" );
288     if ( resVersion != "APP_VERSION" )
289     {
290       _app_version = resVersion;
291     }
292     else
293     {
294       QString path( ::getenv( "GUI_ROOT_DIR" ) );
295       if ( !path.isEmpty() )
296         path += QDir::separator();
297       path += QString( "bin/salome/VERSION" );
298
299       QFile vf( path );
300       if ( vf.open( IO_ReadOnly ) )
301       {
302         QString line;
303         vf.readLine( line, 1024 );
304         vf.close();
305
306         if ( !line.isEmpty() )
307         {
308           while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
309             line.remove( line.length() - 1, 1 );
310
311           int idx = line.findRev( ":" );
312           if ( idx != -1 )
313             _app_version = line.mid( idx + 1 ).stripWhiteSpace();
314         }
315       }
316     }
317   }
318   return _app_version;  
319 }
320
321 /*!Load module by \a name.*/
322 CAM_Module* LightApp_Application::loadModule( const QString& name )
323 {
324   CAM_Module* mod = CAM_Application::loadModule( name );
325   if ( mod )
326   {
327     connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
328     connect( this, SIGNAL( studySaved() ),  mod, SLOT( onModelSaved() ) );
329     connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
330   }
331   return mod;
332 }
333
334 /*!Activate module by \a modName*/
335 bool LightApp_Application::activateModule( const QString& modName )
336 {
337   QString actName;
338   CAM_Module* prevMod = activeModule();
339
340   if ( prevMod )
341     actName = prevMod->moduleName();
342
343   if ( actName == modName )
344     return true;
345
346   putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );  
347
348   saveWindowsGeometry();
349
350   bool status = CAM_Application::activateModule( modName );
351
352   updateModuleActions();
353
354   putInfo( "" );  
355
356   if ( !status )
357     return false;
358
359   updateWindows();
360   updateViewManagers();
361
362   return true;
363 }
364
365 /*!
366   Opens other study into active Study. If Study is empty - creates it.
367   \param theName - name of study
368 */
369 bool LightApp_Application::useStudy(const QString& theName)
370 {
371   createEmptyStudy();
372   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
373   bool res = false;
374   if (aStudy)
375     res = aStudy->loadDocument( theName );
376   updateDesktopTitle();
377   updateCommandsStatus();
378   return res;
379 }
380
381 /*!Gets selection manager.*/
382 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
383 {
384   return mySelMgr;
385 }
386
387 /*!Creat action "New window" for certain type of viewer:*/
388 void LightApp_Application::createActionForViewer( const int id,
389                                                   const int parentId,
390                                                   const QString& suffix,
391                                                   const int accel )
392 {
393   QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ), QIconSet(),
394                                tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
395                                tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
396                                accel, desktop(), false, this, SLOT( onNewWindow() ) );
397   createMenu( a, parentId, -1 );
398 }
399
400 /*!Create actions:*/
401 void LightApp_Application::createActions()
402 {
403   STD_Application::createActions();
404
405   SUIT_Desktop* desk = desktop();
406   SUIT_ResourceMgr* resMgr = resourceMgr();
407
408   //! Preferences
409   createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
410                 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
411                 CTRL+Key_F, desk, false, this, SLOT( onPreferences() ) );
412
413   //! Help for modules
414   int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
415   int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
416   createMenu( separator(), helpMenu, -1, 1 );
417
418   QStringList aModuleList;
419   modules( aModuleList, false );
420
421   int id = LightApp_Application::UserID + FIRST_HELP_ID;
422   // help for KERNEL and GUI
423   QCString dir;
424   QString aFileName;
425   QString root;
426   QAction* a;
427   if (dir = getenv("GUI_ROOT_DIR")) {
428     aFileName = "GUI_index_v3.1.0.html";
429     root = Qtx::addSlash( Qtx::addSlash(dir) +  Qtx::addSlash("doc") +  Qtx::addSlash("salome") );
430     if ( QFileInfo( root + aFileName ).exists() ) {
431       a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
432                         tr( QString("Kernel && GUI Help") ),
433                         tr( QString("Kernel & GUI Help") ),
434                         0, desk, false, this, SLOT( onHelpContentsModule() ) );
435       a->setName( QString("GUI") );
436       createMenu( a, helpModuleMenu, -1 );
437       id++;
438     }
439   }
440   // help for other existing modules
441   QStringList::Iterator it;
442   for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
443   {
444     if ( (*it).isEmpty() )
445       continue;
446
447     QString modName = moduleName( *it );
448     aFileName = modName + "_index_v3.1.0.html";
449     
450     if (dir = getenv( modName + "_ROOT_DIR")) {
451       root = Qtx::addSlash( Qtx::addSlash(dir) +  Qtx::addSlash("doc") +  Qtx::addSlash("salome") );
452       if ( QFileInfo( root + aFileName ).exists() ) {
453
454         QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
455                                    tr( moduleTitle(modName) + QString(" Help") ),
456                                    tr( moduleTitle(modName) + QString(" Help") ),
457                                    0, desk, false, this, SLOT( onHelpContentsModule() ) );
458         a->setName( modName );
459         createMenu( a, helpModuleMenu, -1 );
460         id++;
461       }
462     }
463   }
464
465   //! MRU
466   QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
467   connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
468   registerAction( MRUId, mru );
469
470   // default icon for neutral point ('SALOME' module)
471   QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
472   if ( defIcon.isNull() )
473     defIcon = QPixmap( imageEmptyIcon );
474
475   //! default icon for any module
476   QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
477   if ( modIcon.isNull() )
478     modIcon = QPixmap( imageEmptyIcon );
479
480   QToolBar* modTBar = new QtxToolBar( true, desk );
481   modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
482
483   QActionGroup* modGroup = new QActionGroup( this );
484   modGroup->setExclusive( true );
485   modGroup->setUsesDropDown( true );
486
487   a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
488                     tr( "PRP_APP_MODULE" ), 0, desk, true );
489   modGroup->add( a );
490   myActions.insert( QString(), a );
491
492   QMap<QString, QString> iconMap;
493   moduleIconNames( iconMap );
494
495   const int iconSize = 20;
496
497   modGroup->addTo( modTBar );
498   QObjectList *l = modTBar->queryList( "QComboBox" );
499   QObjectListIt oit( *l );
500   while ( QObject* obj = oit.current() ) {
501     QComboBox* cb = (QComboBox*)obj;
502     if ( cb ) cb->setFocusPolicy( QWidget::NoFocus );
503     ++oit;
504   }
505   delete l;
506   
507    modTBar->addSeparator();
508
509   QStringList modList;
510   modules( modList, false );
511
512   for ( it = modList.begin(); it != modList.end(); ++it )
513   {
514     if ( !isLibExists( *it ) )
515     {
516       qDebug( QString( "Library '%1' cannot be found" ).arg( *it ) );
517       continue;
518     }
519
520     QString iconName;
521     if ( iconMap.contains( *it ) )
522       iconName = iconMap[*it];
523
524     QString modName = moduleName( *it );
525
526     QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
527     if ( icon.isNull() )
528       icon = modIcon;
529
530     icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
531
532     QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
533     a->addTo( modTBar );
534     modGroup->add( a );
535
536     myActions.insert( *it, a );
537   }
538
539   SUIT_Tools::simplifySeparators( modTBar );
540
541   // New window
542   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 );
543   int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
544   createMenu( separator(), windowMenu, -1, 1 );
545
546
547 #ifndef DISABLE_GLVIEWER
548   createActionForViewer( NewGLViewId, newWinMenu, QString::number( 0 ), ALT+Key_G );
549 #endif
550 #ifndef DISABLE_PLOT2DVIEWER
551   createActionForViewer( NewPlot2dId, newWinMenu, QString::number( 1 ), ALT+Key_P );
552 #endif
553 #ifndef DISABLE_OCCVIEWER
554   createActionForViewer( NewOCCViewId, newWinMenu, QString::number( 2 ), ALT+Key_O );
555 #endif
556 #ifndef DISABLE_VTKVIEWER
557   createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), ALT+Key_K );
558 #endif
559
560
561   createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
562                 SHIFT+Key_R, desk, false, this, SLOT( onRenameWindow() ) );
563   createMenu( RenameId, windowMenu, -1 );
564
565   connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
566
567   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
568   createMenu( PreferencesId, fileMenu, 15, -1 );
569   createMenu( separator(), fileMenu, -1, 15, -1 );
570
571   /*
572   createMenu( separator(), fileMenu, -1, 100, -1 );
573   createMenu( MRUId, fileMenu, 100, -1 );
574   createMenu( separator(), fileMenu, -1, 100, -1 );
575   */
576 }
577
578 /*!On module activation action.*/
579 void LightApp_Application::onModuleActivation( QAction* a )
580 {
581   if ( !a )
582     return;
583
584   QString modName = a->menuText();
585   if ( modName == tr( "APP_NAME" ) )
586     modName = QString::null;
587
588   // Force user to create/open a study before module activation
589   QMap<QString, QString> iconMap;
590   moduleIconNames( iconMap );
591   QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
592   if ( icon.isNull() )
593     icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
594
595   bool cancelled = false;
596   while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
597     LightApp_ModuleDlg aDlg( desktop(), modName, icon );
598     int res = aDlg.exec();
599
600     switch ( res ){
601     case 1:
602       onNewDoc();
603       break;
604     case 2:
605       onOpenDoc();
606       break;
607     case 3:
608       //onLoadStudy();
609       //break;
610     case 0:
611     default:
612       putInfo( tr("INF_CANCELLED") );
613       myActions[QString()]->setOn( true );
614       cancelled = true;
615     }
616   }
617
618   if ( !cancelled )
619     activateModule( modName );
620 }
621
622 /*!Default module activation.*/
623 QString LightApp_Application::defaultModule() const
624 {
625   QStringList aModuleNames;
626   modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
627   //! If there's the one and only module --> activate it automatically
628   //! TODO: Possible improvement - default module can be taken from preferences
629   return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
630 }
631
632 /*!On new window slot.*/
633 void LightApp_Application::onNewWindow()
634 {
635   const QObject* obj = sender();
636   if ( !obj || !obj->inherits( "QAction" ) )
637     return;
638
639   QString type;
640   int id = actionId( (QAction*)obj );
641   switch ( id )
642   {
643 #ifndef DISABLE_GLVIEWER
644   case NewGLViewId:
645     type = GLViewer_Viewer::Type();
646     break;
647 #endif
648 #ifndef DISABLE_PLOT2DVIEWER
649   case NewPlot2dId:
650     type = Plot2d_Viewer::Type();
651     break;
652 #endif
653 #ifndef DISABLE_OCCVIEWER
654   case NewOCCViewId:
655     type = OCCViewer_Viewer::Type();
656     break;
657 #endif
658 #ifndef DISABLE_VTKVIEWER
659   case NewVTKViewId:
660     type = VTKViewer_Viewer::Type();
661     break;
662 #endif
663   }
664
665   if ( !type.isEmpty() )
666     createViewManager( type );
667 }
668
669 /*!
670   SLOT: Creates new document
671 */
672 void LightApp_Application::onNewDoc()
673 {
674   SUIT_Study* study = activeStudy();
675
676   saveWindowsGeometry();
677
678   CAM_Application::onNewDoc();
679
680   if ( !study ) // new study will be create in THIS application
681   {
682     updateWindows();
683     updateViewManagers();
684   }
685 }
686
687 /*!
688   SLOT: Opens new document
689 */
690 void LightApp_Application::onOpenDoc()
691 {
692   SUIT_Study* study = activeStudy();
693   saveWindowsGeometry();
694
695   CAM_Application::onOpenDoc();
696
697   if ( !study ) // new study will be create in THIS application
698   {
699     updateWindows();
700     updateViewManagers();
701   }
702 }
703
704 #include "SUIT_MessageBox.h"
705
706 /*!
707   SLOT: Opens new document.
708   \param aName - name of file
709 */
710 bool LightApp_Application::onOpenDoc( const QString& aName )
711 {
712   bool isAlreadyOpen = false;
713
714   // Look among opened studies
715   if (activeStudy()) { // at least one study is opened
716     SUIT_Session* aSession = SUIT_Session::session();
717     QPtrList<SUIT_Application> aAppList = aSession->applications();
718     QPtrListIterator<SUIT_Application> it (aAppList);
719     SUIT_Application* aApp = 0;
720     // iterate on all applications
721     for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
722       if (aApp->activeStudy()->studyName() == aName) {
723         isAlreadyOpen = true; // Already opened, ask user what to do
724
725         // The document ... is already open.
726         // Do you want to reload it?
727         int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
728                                              tr("QUE_DOC_ALREADYOPEN").arg(aName),
729                                              tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
730         if (aAnswer == 1) { // reload
731           if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
732             // Opened in THIS (active) application.
733             STD_Application* app1 = (STD_Application*)aAppList.at(0);
734             STD_Application* app2 = (STD_Application*)aAppList.at(1);
735             if (!app1 || !app2) {
736               // Error
737               return false;
738             }
739             if (app1->activeStudy()->studyName() == aName) {
740               // app1 is this application, we need another one
741               app1 = app2;
742             }
743             // Close document of this application. This application will be destroyed.
744             onCloseDoc(/*ask = */false);
745             // Open the file with another application, as this one will be destroyed.
746             return app1->onOpenDoc(aName);
747           } else {
748             // Opened in another application.
749             STD_Application* app = (STD_Application*)aApp;
750             if (app)
751               app->onCloseDoc(/*ask = */false);
752           }
753         } else { // do not reload
754           // OK, the study will not be reloaded, but we call
755           // CAM_Application::onOpenDoc( aName ) all the same.
756           // It will activate a desktop of the study <aName>.
757         }
758       }
759     }
760   }
761
762   bool res = CAM_Application::onOpenDoc( aName );
763
764   QAction* a = action( MRUId );
765   if ( a && a->inherits( "QtxMRUAction" ) )
766   {
767     QtxMRUAction* mru = (QtxMRUAction*)a;
768     if ( res )
769       mru->insert( aName );
770     else
771       mru->remove( aName );
772   }
773   return res;
774 }
775
776 /*!
777   SLOT: Displays "About" message box
778 */
779 void LightApp_Application::onHelpAbout()
780 {
781   LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
782   dlg->exec();
783   delete dlg;
784 }
785
786 /*!
787   SLOT: Loads document
788   \param aName - name of document
789 */
790 bool LightApp_Application::onLoadDoc( const QString& aName )
791 {
792   bool res = CAM_Application::onLoadDoc( aName );
793
794   /*jfa tmp:QAction* a = action( MRUId );
795   if ( a && a->inherits( "QtxMRUAction" ) )
796   {
797     QtxMRUAction* mru = (QtxMRUAction*)a;
798     if ( res )
799       mru->insert( aName );
800     else
801       mru->remove( aName );
802   }*/
803   return res;
804 }
805
806 /*!
807   Private SLOT: Called on selection is changed
808   Dispatchs active module that selection is changed
809 */
810 void LightApp_Application::onSelection()
811 {
812   onSelectionChanged();
813
814   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
815     ((LightApp_Module*)activeModule())->selectionChanged();
816 }
817
818 /*!
819   Sets active study.
820  \param study - SUIT_Study.
821 */
822 void LightApp_Application::setActiveStudy( SUIT_Study* study )
823 {
824   CAM_Application::setActiveStudy( study );
825
826   activateWindows();
827 }
828
829 /*!
830   Enables/Disables menu items and toolbar buttons. Rebuild menu
831 */
832 void LightApp_Application::updateCommandsStatus()
833 {
834   CAM_Application::updateCommandsStatus();
835   QAction* a = 0;
836
837 #ifndef DISABLE_GLVIEWER
838   a = action( NewGLViewId );
839   if( a )
840     a->setEnabled( activeStudy() );
841 #endif
842
843 #ifndef DISABLE_PLOT2DVIEWER
844   a = action( NewPlot2dId );
845   if( a )
846     a->setEnabled( activeStudy() );
847 #endif
848
849 #ifndef DISABLE_OCCVIEWER
850   a = action( NewOCCViewId );
851   if( a )
852     a->setEnabled( activeStudy() );
853 #endif
854
855 #ifndef DISABLE_VTKVIEWER
856   a = action( NewVTKViewId );
857   if( a )
858     a->setEnabled( activeStudy() );
859 #endif
860 }
861
862 /*!
863   \class RunBrowser
864   Runs system command in separate thread
865 */
866 class RunBrowser: public QThread {
867 public:
868
869   RunBrowser( LightApp_Application* app, QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
870     myApp(theApp), myParams(theParams), 
871 #ifdef WIN32
872       myHelpFile("file://" + theHelpFile + theContext), 
873 #else
874       myHelpFile("file:" + theHelpFile + theContext),
875 #endif
876       myStatus(0),
877       myLApp( app )
878 {
879 };
880
881   virtual void run()
882   {
883     QString aCommand;
884
885     if ( !myApp.isEmpty())
886       {
887         aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
888         myStatus = system(aCommand);
889         if(myStatus != 0)
890           {
891             QCustomEvent* ce2000 = new QCustomEvent( 2000 );
892             QString* msg = new QString( QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").arg(myApp).arg(myHelpFile) );
893             ce2000->setData( msg );
894             postEvent( myLApp, ce2000 );
895           }
896       }
897   }
898
899 private:
900   QString myApp;
901   QString myParams;
902   QString myHelpFile;
903   int myStatus;
904   LightApp_Application* myLApp;
905 };
906
907 /*!
908   SLOT: Displays help contents for choosen module
909 */
910 void LightApp_Application::onHelpContentsModule()
911 {
912   const QAction* obj = (QAction*) sender();
913
914   QString aComponentName = obj->name();
915   QString aFileName = aComponentName + "_index_v3.1.0.html";
916
917   QCString dir = getenv( aComponentName + "_ROOT_DIR");
918   QString homeDir = Qtx::addSlash( Qtx::addSlash(dir) +  Qtx::addSlash("doc") +  Qtx::addSlash("salome") );
919
920   QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
921   SUIT_ResourceMgr* resMgr = resourceMgr();
922   QString anApp = resMgr->stringValue("ExternalBrowser", "application");
923   QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
924
925   if (!anApp.isEmpty()) {
926     RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
927     rs->start();
928   }
929   else {
930     if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
931                            tr("DEFINE_EXTERNAL_BROWSER"),
932                            tr("BUT_OK"),tr("BUT_CANCEL"),0,1,0 )==0 )
933       onPreferences();
934   }
935 }
936
937 /*!
938   SLOT: Displays help contents for choosen dialog
939 */
940 void LightApp_Application::onHelpContextModule(const QString& theComponentName, const QString& theFileName)
941 {
942   QCString dir = getenv( theComponentName + "_ROOT_DIR");
943   QString homeDir = Qtx::addSlash(Qtx::addSlash(dir)+Qtx::addSlash("doc")+Qtx::addSlash("salome")+Qtx::addSlash("gui")+Qtx::addSlash(theComponentName));
944
945   QString helpFile = QFileInfo( homeDir + theFileName ).absFilePath();
946   SUIT_ResourceMgr* resMgr = resourceMgr();
947   QString anApp = resMgr->stringValue("ExternalBrowser", "application");
948   QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
949
950   if (!anApp.isEmpty()) {
951     RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
952     rs->start();
953   }
954   else {
955     if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
956                            tr("DEFINE_EXTERNAL_BROWSER"),
957                            tr("BUT_OK"), tr("BUT_CANCEL"),0,1,0)==0 )
958       onPreferences();
959   }
960 }
961
962 /*!
963   Sets enable or disable some actions on selection changed.
964 */
965 void LightApp_Application::onSelectionChanged()
966 {
967 }
968
969 /*!
970   \return window by key
971   \param flag - key for window
972   \param studyId - study id
973   Flag used how identificator of window in windows list.
974 */
975 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
976 {
977   QWidget* wid = 0;
978
979  int sId = studyId;
980   if ( sId < 0 )
981   {
982     if ( !activeStudy() )
983       return 0;
984     else
985       sId = activeStudy()->id();
986   }
987
988   if ( myWindows.contains( flag ) )
989     wid = myWindows[flag]->widget( sId );
990
991   return wid;
992 }
993
994 /*!
995   Adds window to application.
996   \param wid - QWidget
997   \param flag - key for window
998   \param studyId - study id
999   Flag used how identificator of window in windows list.
1000 */
1001 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
1002 {
1003   if ( !wid )
1004     return;
1005
1006   int sId = studyId;
1007   if ( sId < 0 )
1008   {
1009     if ( !activeStudy() )
1010       return;
1011     else
1012       sId = activeStudy()->id();
1013   }
1014
1015   if ( !myWindows.contains( flag ) )
1016   {
1017     QMap<int, int> winMap;
1018     currentWindows( winMap );
1019
1020     LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
1021     connect( newWC, SIGNAL(  destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1022     // asv: connecting a slot for storing visibility flag of a window 
1023     connect( newWC, SIGNAL( visibilityChanged ( bool ) ), SLOT( onVisibilityChanged( bool ) ) );
1024     myWindows.insert( flag, newWC );
1025     if ( winMap.contains( flag ) )
1026       desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
1027
1028     myWindows[flag]->setResizeEnabled( true );
1029     myWindows[flag]->setCloseMode( QDockWindow::Always );
1030     myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
1031     myWindows[flag]->setFixedExtentWidth( wid->width() );
1032     myWindows[flag]->setFixedExtentHeight( wid->height() );
1033   }
1034
1035   QFont f;
1036 #ifndef DISABLE_PYCONSOLE
1037   if( wid->inherits( "PythonConsole" ) )
1038   {
1039     if( resourceMgr()->hasValue( "PyConsole", "font" ) )
1040       f = resourceMgr()->fontValue( "PyConsole", "font" );
1041     else
1042       {
1043         f = ( ( PythonConsole* )wid )->font();
1044         resourceMgr()->setValue( "PyConsole", "font", f );
1045       }
1046   }
1047   else
1048 #endif
1049     f = wid->font();
1050
1051   myWindows[flag]->insert( sId, wid );
1052   wid->setFont(f);
1053
1054   setWindowShown( flag, !myWindows[flag]->isEmpty() );
1055 }
1056
1057 /*!
1058   Removes window from application.
1059   \param flag - key for window
1060   \param studyId - study id
1061   Flag used how identificator of window in windows list.
1062 */
1063 void LightApp_Application::removeWindow( const int flag, const int studyId )
1064 {
1065   if ( !myWindows.contains( flag ) )
1066     return;
1067
1068   int sId = studyId;
1069   if ( sId < 0 )
1070   {
1071     if ( !activeStudy() )
1072       return;
1073     else
1074       sId = activeStudy()->id();
1075   }
1076
1077   QWidget* wid = myWindows[flag]->widget( sId );
1078   myWindows[flag]->remove( sId );
1079   delete wid;
1080
1081   setWindowShown( flag, !myWindows[flag]->isEmpty() );
1082 }
1083
1084 /*!
1085   Gets window.
1086   \param flag - key for window
1087   \param studyId - study id
1088   Flag used how identificator of window in windows list.
1089 */
1090 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
1091 {
1092   QWidget* wid = window( flag, studyId );
1093   if ( !wid )
1094     addWindow( wid = createWindow( flag ), flag, studyId );
1095
1096   return wid;
1097 }
1098
1099 /*!
1100   \return is window visible
1101   \param type - flag of window
1102 */
1103 bool LightApp_Application::isWindowVisible( const int type ) const
1104 {
1105   bool res = false;
1106   if ( myWindows.contains( type ) )
1107   {
1108     SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
1109     res = desk && desk->appropriate( myWindows[type] );
1110   }
1111   return res;
1112 }
1113
1114 /*!
1115   Sets window show or hide.
1116   \param type - window identificator.
1117   \param on   - true/false (window show/hide)
1118 */
1119 void LightApp_Application::setWindowShown( const int type, const bool on )
1120 {
1121   if ( !desktop() || !myWindows.contains( type ) )
1122     return;
1123
1124   QDockWindow* dw = myWindows[type];
1125   desktop()->setAppropriate( dw, on );
1126   if( on )
1127     dw->show();
1128   else if( dw->isShown() )
1129   {
1130     dw->hide();
1131     myWindowsVisible[ type ] = true;
1132   }
1133 }
1134
1135 /*!
1136   \return Object Browser
1137 */
1138 OB_Browser* LightApp_Application::objectBrowser()
1139 {
1140   OB_Browser* ob = 0;
1141   QWidget* wid = window( WT_ObjectBrowser );
1142   if ( wid && wid->inherits( "OB_Browser" ) )
1143     ob = (OB_Browser*)wid;
1144   return ob;
1145 }
1146
1147 /*!
1148   \return Log Window
1149 */
1150 LogWindow* LightApp_Application::logWindow()
1151 {
1152   LogWindow* lw = 0;
1153   QWidget* wid = getWindow( WT_LogWindow );
1154   if ( wid->inherits( "LogWindow" ) )
1155     lw = (LogWindow*)wid;
1156   return lw;
1157 }
1158
1159 #ifndef DISABLE_PYCONSOLE
1160 /*!
1161   \return Python Console
1162 */
1163 PythonConsole* LightApp_Application::pythonConsole()
1164 {
1165   PythonConsole* console = 0;
1166   QWidget* wid = getWindow( WT_PyConsole );
1167   if ( wid->inherits( "PythonConsole" ) )
1168     console = (PythonConsole*)wid;
1169   return console;
1170 }
1171 #endif
1172
1173 /*!
1174   Updates object browser and maybe data models
1175   \param updateModels - if it is true, then data models are updated
1176 */
1177 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1178 {
1179   // update existing data models
1180   if ( updateModels ) 
1181   {
1182     const bool isAutoUpdate = objectBrowser() ? objectBrowser()->isAutoUpdate() : true;
1183     if( objectBrowser() )
1184       objectBrowser()->setAutoUpdate( false );
1185
1186     LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1187     if ( study ) {
1188       CAM_Study::ModelList dm_list;
1189       study->dataModels( dm_list );
1190       for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
1191         CAM_DataModel* camDM = it.current();
1192         if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1193           ((LightApp_DataModel*)camDM)->update();
1194       }
1195     }
1196
1197     if( objectBrowser() )
1198       objectBrowser()->setAutoUpdate( isAutoUpdate );
1199   }
1200   if ( objectBrowser() )
1201   {
1202     objectBrowser()->updateGeometry();
1203     objectBrowser()->updateTree( 0, false );
1204   }
1205 }
1206
1207 /*!
1208   \return preferences
1209 */
1210 LightApp_Preferences* LightApp_Application::preferences() const
1211 {
1212   return preferences( false );
1213 }
1214
1215 /*!
1216   \return first view manager of some type
1217   \param vmType - type of view manager
1218   \param create - is it necessary to create view manager in case, when there is no manager of such type
1219 */
1220 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1221 {
1222   SUIT_ViewManager* aVM = viewManager( vmType );
1223   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1224
1225   if ( anActiveVM && anActiveVM->getType() == vmType )
1226     aVM = anActiveVM;
1227
1228   if ( aVM && create )
1229   {
1230     if ( !aVM->getActiveView() )
1231       aVM->createView();
1232     else
1233       aVM->getActiveView()->setFocus();
1234   }
1235   else if ( create )
1236     aVM = createViewManager( vmType );
1237
1238   return aVM;
1239 }
1240
1241 /*!
1242   Creates view manager of some type
1243   \param vmType - type of view manager
1244 */
1245 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1246 {
1247   SUIT_ResourceMgr* resMgr = resourceMgr();
1248
1249   SUIT_ViewManager* viewMgr = 0;
1250 #ifndef DISABLE_GLVIEWER
1251   if( vmType == GLViewer_Viewer::Type() )
1252   {
1253     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1254     new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1255   }
1256 #endif
1257 #ifndef DISABLE_PLOT2DVIEWER
1258   if( vmType == Plot2d_Viewer::Type() )
1259   {
1260     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1261     Plot2d_Viewer* vm;
1262 #ifndef DISABLE_SALOMEOBJECT
1263     vm = new SPlot2d_Viewer();
1264 #else
1265     vm = new Plot2d_Viewer();
1266 #endif
1267     viewMgr->setViewModel( vm  );// custom view model, which extends SALOME_View interface 
1268     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1269     if( wnd )
1270     {
1271       Plot2d_ViewFrame* frame = wnd->getViewFrame();
1272       frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1273     }
1274   }
1275 #endif
1276   //#ifndef DISABLE_SUPERVGRAPHVIEWER
1277   //  if( vmType == SUPERVGraph_Viewer::Type() )
1278   //  {
1279   //    viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop(), new SUPERVGraph_Viewer() );
1280   //  }
1281   //#endif
1282 #ifndef DISABLE_OCCVIEWER
1283   if( vmType == OCCViewer_Viewer::Type() )
1284   {
1285     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1286     OCCViewer_Viewer* vm;
1287 #ifndef DISABLE_SALOMEOBJECT
1288     vm = new SOCC_Viewer();
1289 #else
1290     vm = new OCCViewer_Viewer();
1291 #endif
1292     vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1293     vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1294     int u( 1 ), v( 1 );
1295     vm->isos( u, v );
1296     u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1297     v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1298     vm->setIsos( u, v );
1299     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1300     new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1301   }
1302 #endif
1303 #ifndef DISABLE_VTKVIEWER
1304 #ifndef DISABLE_SALOMEOBJECT
1305   if ( vmType == SVTK_Viewer::Type() )
1306 #else
1307   if ( vmType == VTKViewer_Viewer::Type() )
1308 #endif
1309   {
1310 #ifndef DISABLE_SALOMEOBJECT
1311     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1312     SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1313     if( vm )
1314     {
1315       vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1316       vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ),
1317                             resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) );
1318       new LightApp_VTKSelector( vm, mySelMgr );
1319     }
1320 #else
1321     viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
1322     VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
1323     if ( vm )
1324       vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1325 #endif
1326   }
1327 #endif
1328
1329   if ( !viewMgr )
1330     return 0;
1331
1332   addViewManager( viewMgr );
1333   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1334
1335   if ( viewWin && desktop() )
1336     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1337
1338   return viewMgr;
1339 }
1340
1341 /*!
1342   SLOT: Removes view manager from application
1343 */
1344 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1345 {
1346   removeViewManager( theVM );
1347 }
1348
1349 /*!
1350   Protected SLOT: On study created.
1351   \param theStudy - just created study
1352 */
1353 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1354 {
1355   SUIT_DataObject* aRoot = 0;
1356   if ( theStudy && theStudy->root() )
1357   {
1358     aRoot = theStudy->root();
1359     //aRoot->setName( tr( "DATA_MODELS" ) );
1360   }
1361   getWindow( WT_ObjectBrowser );
1362   if ( objectBrowser() != 0 )
1363     objectBrowser()->setRootObject( aRoot );
1364
1365   activateModule( defaultModule() );
1366
1367   activateWindows();
1368 }
1369
1370 /*!
1371   Protected SLOT: On study opened.
1372   \param theStudy - just opened  study
1373 */
1374 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1375 {
1376   SUIT_DataObject* aRoot = 0;
1377   if ( theStudy && theStudy->root() )
1378   {
1379     aRoot = theStudy->root();
1380     //aRoot->dump();
1381   }
1382   getWindow( WT_ObjectBrowser );
1383   if ( objectBrowser() != 0 ) {
1384     objectBrowser()->setRootObject( aRoot );
1385   }
1386
1387   activateModule( defaultModule() );
1388
1389   activateWindows();
1390
1391   emit studyOpened();
1392 }
1393
1394 /*!Protected SLOT. On study saved.*/
1395 void LightApp_Application::onStudySaved( SUIT_Study* )
1396 {
1397   emit studySaved();
1398 }
1399
1400 /*!Protected SLOT. On study closed.*/
1401 void LightApp_Application::onStudyClosed( SUIT_Study* )
1402 {
1403   emit studyClosed();
1404
1405   // Bug 10396: clear selection
1406   mySelMgr->clearSelected();
1407
1408   activateModule( "" );
1409
1410   saveWindowsGeometry();
1411 }
1412
1413 /*!Protected SLOT.On desktop activated.*/
1414 void LightApp_Application::onDesktopActivated()
1415 {
1416   CAM_Application::onDesktopActivated();
1417   LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1418   if(aModule)
1419     aModule->studyActivated();
1420 }
1421
1422 /*!Gets file filter.
1423  *\retval QString "(*.bin)"
1424  */
1425 QString LightApp_Application::getFileFilter() const
1426 {
1427   //return "(*.bin)";
1428   // HDF persistence
1429   return "(*.hdf)";
1430 }
1431
1432 /*!
1433   Shows file dialog and return user selected file name
1434 */
1435 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters, 
1436                                            const QString& caption, QWidget* parent )
1437 {
1438   if ( !parent )
1439     parent = desktop();
1440   QStringList fls = QStringList::split( ";;", filters, false );
1441   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1442 }
1443
1444 /*! Gets directory*/
1445 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1446 {
1447   if ( !parent )
1448     parent = desktop();
1449   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1450 }
1451
1452 /*! Get open file names*/
1453 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters, 
1454                                                     const QString& caption, QWidget* parent )
1455 {
1456   if ( !parent )
1457     parent = desktop();
1458   QStringList fls = QStringList::split( ";;", filters, false );
1459   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1460 }
1461
1462 /*!Private SLOT. Update object browser.*/
1463 void LightApp_Application::onRefresh()
1464 {
1465   updateObjectBrowser( true );
1466 }
1467
1468 /*!Private SLOT. On preferences.*/
1469 void LightApp_Application::onPreferences()
1470 {
1471   QApplication::setOverrideCursor( Qt::waitCursor );
1472
1473   LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1474
1475   QApplication::restoreOverrideCursor();
1476
1477   if ( !prefDlg )
1478     return;
1479
1480   if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) &&  resourceMgr() ) {
1481     if ( desktop() )
1482       desktop()->saveGeometry( resourceMgr(), "desktop" );
1483     resourceMgr()->save();
1484   }
1485
1486   delete prefDlg;
1487 }
1488
1489 /*!Protected SLOT. On preferences changed.*/
1490 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1491 {
1492   LightApp_Module* sMod = 0;
1493   CAM_Module* mod = module( modName );
1494   if ( mod && mod->inherits( "LightApp_Module" ) )
1495     sMod = (LightApp_Module*)mod;
1496
1497   if ( sMod )
1498     sMod->preferencesChanged( section, param );
1499   else
1500     preferencesChanged( section, param );
1501 }
1502
1503 /*!Private SLOT. On open document with name \a aName.*/
1504 void LightApp_Application::onMRUActivated( QString aName )
1505 {
1506   onOpenDoc( aName );
1507 }
1508
1509 /*!Remove all windows from study.*/
1510 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1511 {
1512   CAM_Application::beforeCloseDoc( s );
1513
1514   for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1515     removeWindow( itr.key(), s->id() );
1516 }
1517
1518 /*!Update actions.*/
1519 void LightApp_Application::updateActions()
1520 {
1521   updateCommandsStatus();
1522 }
1523
1524 /*!
1525   Creates new study
1526 */
1527 SUIT_Study* LightApp_Application::createNewStudy()
1528 {
1529   LightApp_Application::lastStudyId++;
1530
1531   LightApp_Study* aStudy = new LightApp_Study( this );
1532
1533   // Set up processing of major study-related events
1534   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1535   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1536   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
1537   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1538
1539   return aStudy;
1540 }
1541
1542 /*!
1543   Creates window by flag.
1544   \param flag - identificator of window type
1545 */
1546 QWidget* LightApp_Application::createWindow( const int flag )
1547 {
1548   QWidget* wid = 0;
1549   if ( flag == WT_ObjectBrowser )
1550   {
1551     OB_Browser* ob = new OB_Browser( desktop() );
1552     ob->setAutoUpdate( true );
1553     //ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107
1554     ob->setCaption( tr( "OBJECT_BROWSER" ) );
1555
1556     OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1557     if( ob_list )
1558       ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1559
1560     ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1561     ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1562
1563     // Create OBSelector
1564     new LightApp_OBSelector( ob, mySelMgr );
1565
1566     wid = ob;
1567
1568     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1569   }
1570 #ifndef DISABLE_PYCONSOLE
1571   else  if ( flag == WT_PyConsole )
1572   {
1573     PythonConsole* pyCons = new PythonConsole( desktop() );
1574     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1575     wid = pyCons;
1576     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1577   }
1578 #endif
1579   else if ( flag == WT_LogWindow )
1580   {
1581     LogWindow* logWin = new LogWindow( desktop() );
1582     logWin->setCaption( tr( "LOG_WINDOW" ) );
1583     wid = logWin;
1584     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1585   }
1586   return wid;
1587 }
1588
1589 /*!
1590   \return default windows( Object Browser, Python Console )
1591   Adds to map \a aMap.
1592  */
1593 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1594 {  
1595   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1596 #ifndef DISABLE_PYCONSOLE
1597   aMap.insert( WT_PyConsole, Qt::DockBottom );
1598 #endif
1599   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1600 }
1601
1602 /*!Default view managers*/
1603 void LightApp_Application::defaultViewManagers( QStringList& ) const
1604 {
1605   /*!Do nothing.*/
1606 }
1607
1608 /*!
1609   \return preferences.
1610   Create preferences, if \a crt = true.
1611 */
1612 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1613 {
1614   if ( myPrefs )
1615     return myPrefs;
1616
1617   LightApp_Application* that = (LightApp_Application*)this;
1618
1619   bool toCreate = !_prefs_ && crt;
1620   if( toCreate )
1621   {
1622     _prefs_ = new LightApp_Preferences( resourceMgr() );
1623     that->createPreferences( _prefs_ );
1624   }
1625
1626   that->myPrefs = _prefs_;
1627
1628   QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1629   for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1630   {
1631     if ( !appIt.current()->inherits( "LightApp_Application" ) )
1632       continue;
1633
1634     LightApp_Application* app = (LightApp_Application*)appIt.current();
1635
1636     QStringList modNameList;
1637     app->modules( modNameList, false );
1638     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1639     {
1640       int id = _prefs_->addPreference( *it );
1641       _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1642     }
1643
1644     ModuleList modList;
1645     app->modules( modList );
1646     for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1647     {
1648       LightApp_Module* mod = 0;
1649       if ( itr.current()->inherits( "LightApp_Module" ) )
1650         mod = (LightApp_Module*)itr.current();
1651
1652       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1653       {
1654         int modCat = _prefs_->addPreference( mod->moduleName() );
1655         _prefs_->setItemProperty( modCat, "info", QString::null );
1656         if( toCreate )
1657           mod->createPreferences();
1658       }
1659     }
1660   }
1661
1662   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1663            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1664
1665   return myPrefs;
1666 }
1667
1668 /*!
1669   Adds new module to application
1670 */
1671 void LightApp_Application::moduleAdded( CAM_Module* mod )
1672 {
1673   CAM_Application::moduleAdded( mod );
1674
1675   LightApp_Module* lightMod = 0;
1676   if ( mod && mod->inherits( "LightApp_Module" ) )
1677     lightMod = (LightApp_Module*)mod;
1678
1679   if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1680   {
1681     int modCat = myPrefs->addPreference( mod->moduleName() );
1682     myPrefs->setItemProperty( modCat, "info", QString::null );
1683     lightMod->createPreferences();
1684   }
1685 }
1686
1687 /*!
1688   Create preferences
1689 */
1690 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1691 {
1692   if ( !pref )
1693     return;
1694
1695   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1696
1697   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1698   int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1699   pref->setItemProperty( studyGroup, "columns", 1 );
1700
1701   pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1702   pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1703   pref->addPreference( tr( "PREF_STORE_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
1704
1705   int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1706   pref->setItemProperty( extgroup, "columns", 1 );
1707   int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1708   pref->setItemProperty( apppref, "existing", true );
1709   pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1710   pref->setItemProperty( apppref, "readOnly", false );
1711
1712   pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1713
1714   int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1715   pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1716   pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1717
1718   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1719
1720   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1721
1722   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1723
1724   int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1725
1726   int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1727
1728   pref->setItemProperty( occGroup, "columns", 1 );
1729   pref->setItemProperty( vtkGroup, "columns", 1 );
1730   pref->setItemProperty( plot2dGroup, "columns", 1 );
1731
1732   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1733                                    LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1734   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1735                        LightApp_Preferences::Color, "OCCViewer", "background" );
1736
1737   pref->setItemProperty( occTS, "min", 1 );
1738   pref->setItemProperty( occTS, "max", 1000 );
1739
1740   int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1741                                   LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1742   int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1743                                   LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1744
1745   pref->setItemProperty( isoU, "min", 0 );
1746   pref->setItemProperty( isoU, "max", 100000 );
1747
1748   pref->setItemProperty( isoV, "min", 0 );
1749   pref->setItemProperty( isoV, "max", 100000 );
1750
1751   int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1752                                    LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1753   pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
1754   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1755                        LightApp_Preferences::Color, "VTKViewer", "background" );
1756
1757   pref->setItemProperty( vtkTS, "min", 1 );
1758   pref->setItemProperty( vtkTS, "max", 150 );
1759
1760   pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1761                        LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1762
1763   int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1764                                             LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1765   QStringList aLegendPosList;
1766   aLegendPosList.append( tr("PREF_LEFT") );
1767   aLegendPosList.append( tr("PREF_RIGHT") );
1768   aLegendPosList.append( tr("PREF_TOP") );
1769   aLegendPosList.append( tr("PREF_BOTTOM") );
1770
1771   QValueList<QVariant> anIndexesList;
1772   anIndexesList.append(0);
1773   anIndexesList.append(1);
1774   anIndexesList.append(2);
1775   anIndexesList.append(3);
1776
1777   pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1778   pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1779
1780   int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1781                                        LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1782   QStringList aCurveTypesList;
1783   aCurveTypesList.append( tr("PREF_POINTS") );
1784   aCurveTypesList.append( tr("PREF_LINES") );
1785   aCurveTypesList.append( tr("PREF_SPLINE") );
1786
1787   anIndexesList.clear();
1788   anIndexesList.append(0);
1789   anIndexesList.append(1);
1790   anIndexesList.append(2);
1791   
1792   pref->setItemProperty( curveType, "strings", aCurveTypesList );
1793   pref->setItemProperty( curveType, "indexes", anIndexesList );
1794
1795   int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1796                                         LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1797
1798   pref->setItemProperty( markerSize, "min", 0 );
1799   pref->setItemProperty( markerSize, "max", 100 );
1800   
1801   QStringList aScaleModesList;
1802   aScaleModesList.append( tr("PREF_LINEAR") );
1803   aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1804   
1805   anIndexesList.clear();
1806   anIndexesList.append(0);
1807   anIndexesList.append(1);
1808
1809   int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1810                                       LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1811
1812   pref->setItemProperty( horScale, "strings", aScaleModesList );
1813   pref->setItemProperty( horScale, "indexes", anIndexesList );
1814
1815   int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1816                                       LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1817
1818   pref->setItemProperty( verScale, "strings", aScaleModesList );
1819   pref->setItemProperty( verScale, "indexes", anIndexesList );
1820
1821   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1822                        LightApp_Preferences::Color, "Plot2d", "Background" );
1823
1824   int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1825   int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1826   pref->setItemProperty( dirGroup, "columns", 1 );
1827   pref->addPreference( tr( "" ), dirGroup,
1828                        LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1829
1830   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1831                        LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1832   pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1833                        LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1834 //  pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1835 //                     LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1836
1837   int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1838   int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1839   pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
1840                        "ObjectBrowser", "auto_size_first" );
1841   pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
1842                        "ObjectBrowser", "auto_size" );
1843 }
1844
1845 /*!
1846   Changes appearance of application according to changed preferences
1847   \param sec - section
1848   \param param - name of changed parameter
1849 */
1850 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1851 {
1852   SUIT_ResourceMgr* resMgr = resourceMgr();
1853   if ( !resMgr )
1854     return;
1855
1856 #ifndef DISABLE_OCCVIEWER
1857   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1858   {
1859     int sz = resMgr->integerValue( sec, param, -1 );
1860     QPtrList<SUIT_ViewManager> lst;
1861     viewManagers( OCCViewer_Viewer::Type(), lst );
1862     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1863     {
1864       SUIT_ViewModel* vm = it.current()->getViewModel();
1865       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1866         continue;
1867
1868       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1869       occVM->setTrihedronSize( sz );
1870       occVM->getAISContext()->UpdateCurrentViewer();
1871     }
1872   }
1873 #endif
1874
1875 #ifndef DISABLE_VTKVIEWER
1876   if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
1877   {
1878     int sz = resMgr->integerValue( "VTKViewer", "trihedron_size", -1 );
1879     bool isRelative = resMgr->booleanValue( "VTKViewer", "relative_size", true );
1880     QPtrList<SUIT_ViewManager> lst;
1881 #ifndef DISABLE_SALOMEOBJECT
1882     viewManagers( SVTK_Viewer::Type(), lst );
1883     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1884     {
1885       SUIT_ViewModel* vm = it.current()->getViewModel();
1886       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1887         continue;
1888
1889       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1890       if( vtkVM )
1891       {
1892         vtkVM->setTrihedronSize( sz, isRelative );
1893         vtkVM->Repaint();
1894       }
1895     }
1896 #endif
1897   }
1898 #endif
1899
1900 #ifndef DISABLE_OCCVIEWER
1901   if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1902   {
1903     QPtrList<SUIT_ViewManager> lst;
1904     viewManagers( OCCViewer_Viewer::Type(), lst );
1905     int u = resMgr->integerValue( sec, "iso_number_u" );
1906     int v = resMgr->integerValue( sec, "iso_number_v" );
1907     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1908     {
1909       OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1910       if( mgr && mgr->getOCCViewer() )
1911         mgr->getOCCViewer()->setIsos( u, v );
1912     }
1913   }
1914 #endif
1915
1916   if( sec=="ObjectBrowser" )
1917   {
1918     if( param=="auto_size" || param=="auto_size_first" )
1919     {
1920       OB_Browser* ob = objectBrowser();
1921       if( !ob )
1922         return;
1923
1924       bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ),
1925            autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
1926       ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1927       ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual );
1928       if( autoSize )
1929         for( int i=1; i<ob->listView()->columns(); i++ )
1930           if( ob->listView()->columnWidth( i )>0 )
1931             ob->listView()->adjustColumn( i );
1932       updateObjectBrowser( false );
1933     }
1934   }
1935
1936   if( sec=="Study" )
1937   { 
1938     if( param=="store_positions" )
1939       updateWindows();
1940   }
1941
1942 #ifndef DISABLE_PYCONSOLE
1943   if( sec=="PyConsole" )
1944   {
1945     if( param=="font" )
1946       if( pythonConsole() )
1947         pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1948   }
1949 #endif
1950 }
1951
1952 /*!
1953   Saves preferences
1954 */
1955 void LightApp_Application::savePreferences()
1956 {
1957   saveWindowsGeometry();
1958   
1959   if ( resourceMgr() )
1960     {
1961       if ( desktop() )
1962         desktop()->saveGeometry( resourceMgr(), "desktop" );
1963       resourceMgr()->save();
1964     }
1965 }
1966
1967 /*!
1968   Updates desktop title
1969 */
1970 void LightApp_Application::updateDesktopTitle() {
1971   QString aTitle = applicationName();
1972   QString aVer = applicationVersion();
1973   if ( !aVer.isEmpty() )
1974     aTitle += QString( " " ) + aVer;
1975
1976   if ( activeStudy() ) {
1977     QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1978     aTitle += QString( " - [%1]" ).arg( sName );
1979   }
1980
1981   desktop()->setCaption( aTitle );
1982 }
1983
1984 /*!
1985   Updates windows after close document
1986 */
1987 void LightApp_Application::afterCloseDoc()
1988 {
1989   updateWindows();
1990
1991   CAM_Application::afterCloseDoc();
1992 }
1993
1994 /*!
1995   Updates actions of active module
1996 */
1997 void LightApp_Application::updateModuleActions()
1998 {
1999   QString modName;
2000   if ( activeModule() )
2001     modName = activeModule()->moduleName();
2002
2003   if ( myActions.contains( modName ) )
2004     myActions[modName]->setOn( true );
2005 }
2006
2007 /*!
2008   Gets current windows.
2009   \param winMap - output current windows map.
2010 */
2011 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
2012 {
2013   winMap.clear();
2014   if ( !activeStudy() )
2015     return;
2016
2017   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2018     ((LightApp_Module*)activeModule())->windows( winMap );
2019   else
2020     defaultWindows( winMap );
2021 }
2022
2023 /*!
2024   Gets current view managers.
2025   \param lst - output current view managers list.
2026 */
2027 void LightApp_Application::currentViewManagers( QStringList& lst ) const
2028 {
2029   lst.clear();
2030   if ( !activeStudy() )
2031     return;
2032
2033   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2034     ((LightApp_Module*)activeModule())->viewManagers( lst );
2035   else
2036     defaultViewManagers( lst );
2037 }
2038
2039 /*!
2040   Updates windows
2041 */
2042 void LightApp_Application::updateWindows()
2043 {
2044   QMap<int, int> winMap;
2045   currentWindows( winMap );
2046
2047   if ( activeStudy() ) {
2048     for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
2049       getWindow( it.key() );
2050
2051     loadWindowsGeometry();
2052   }
2053
2054   // setWindowShown should be done even if no study is active (open). in this case all open windows
2055   // will be hidden, which is neccessary in this case.
2056   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) {
2057     
2058     if ( myWindowsVisible.contains( itr.key() ) && 
2059          !myWindowsVisible[ itr.key() ] )
2060       continue;
2061
2062     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
2063   }
2064 }
2065
2066 /*!
2067   Updates view managers
2068 */
2069 void LightApp_Application::updateViewManagers()
2070 {
2071   QStringList lst;
2072   currentViewManagers( lst );
2073
2074   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
2075     getViewManager( *it, true );
2076 }
2077
2078 /*!
2079   Loads windows geometry
2080 */
2081 void LightApp_Application::loadWindowsGeometry()
2082 {
2083   bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2084   if( !store )
2085     return;
2086
2087   QtxDockAction* dockMgr = 0;
2088
2089   QAction* a = action( ViewWindowsId );
2090   if ( a && a->inherits( "QtxDockAction" ) )
2091     dockMgr = (QtxDockAction*)a;
2092
2093   if ( !dockMgr )
2094     return;
2095
2096   QString modName;
2097   if ( activeModule() )
2098     modName = activeModule()->name("");
2099
2100   QString section = QString( "windows_geometry" );
2101   if ( !modName.isEmpty() )
2102     section += QString( "." ) + modName;
2103
2104   dockMgr->loadGeometry( resourceMgr(), section, false );
2105   dockMgr->restoreGeometry();
2106 }
2107
2108 /*!
2109   Saves windows geometry
2110 */
2111 void LightApp_Application::saveWindowsGeometry()
2112 {
2113   bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2114   if( !store )
2115     return;
2116
2117   QtxDockAction* dockMgr = 0;
2118
2119   QAction* a = action( ViewWindowsId );
2120   if ( a && a->inherits( "QtxDockAction" ) )
2121     dockMgr = (QtxDockAction*)a;
2122
2123   if ( !dockMgr )
2124     return;
2125
2126   QString modName;
2127   if ( activeModule() )
2128     modName = activeModule()->name("");
2129
2130   QString section = QString( "windows_geometry" );
2131   if ( !modName.isEmpty() )
2132     section += QString( "." ) + modName;
2133
2134   dockMgr->storeGeometry();
2135   dockMgr->saveGeometry( resourceMgr(), section, false );
2136 }
2137
2138 /*!
2139   Activates windows
2140 */
2141 void LightApp_Application::activateWindows()
2142 {
2143   if ( activeStudy() )
2144   {
2145     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2146       itr.data()->activate( activeStudy()->id() );
2147   }
2148 }
2149
2150 /*!
2151   Adds icon names for modules
2152 */
2153 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
2154 {
2155   iconMap.clear();
2156
2157   SUIT_ResourceMgr* resMgr = resourceMgr();
2158   if ( !resMgr )
2159     return;
2160
2161   QStringList modList;
2162   modules( modList, false );
2163
2164   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
2165   {
2166     QString modName = *it;
2167     QString modIntr = moduleName( modName );
2168     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
2169
2170     if ( modIcon.isEmpty() )
2171       continue;
2172
2173     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
2174       modIcon += QString( ".png" );
2175
2176     iconMap.insert( modName, modIcon );
2177   }
2178 }
2179
2180 /*!
2181   Inserts items in popup, which necessary for current application
2182 */
2183 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
2184 {
2185   CAM_Application::contextMenuPopup( type, thePopup, title );
2186
2187   OB_Browser* ob = objectBrowser();
2188   if ( !ob || type != ob->popupClientType() )
2189     return;
2190
2191   thePopup->insertSeparator();
2192   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
2193 }
2194
2195 /*!
2196   Create empty study
2197 */
2198 void LightApp_Application::createEmptyStudy()
2199 {
2200   CAM_Application::createEmptyStudy();
2201   if ( objectBrowser() )
2202     objectBrowser()->updateTree();
2203 }
2204
2205 /*!
2206   Activates module
2207   \param mod - module to be activated
2208 */
2209 bool LightApp_Application::activateModule( CAM_Module* mod )
2210 {
2211   bool res = CAM_Application::activateModule( mod );
2212   if ( objectBrowser() )
2213     objectBrowser()->updateTree();
2214   return res;
2215 }
2216
2217 /*!
2218   \return keyborad accelerators manager object
2219 */
2220 SUIT_Accel* LightApp_Application::accel() const
2221 {
2222   return myAccel;
2223 }
2224
2225 /*!
2226   Removes dead widget container from map
2227 */
2228 void LightApp_Application::onWCDestroyed( QObject* ob )
2229 {
2230   // remove destroyed widget container from windows map
2231   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2232   {
2233     if ( itr.data() != ob )
2234       continue;
2235
2236     int key = itr.key();
2237     myWindows.remove( key );
2238     break;
2239   }
2240 }
2241
2242 /*!
2243   Connects just added view manager
2244 */
2245 void LightApp_Application::addViewManager( SUIT_ViewManager* vm )
2246 {
2247   connect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2248            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2249   STD_Application::addViewManager( vm );
2250 }
2251
2252 /*!
2253   Remove view manager from memory
2254 */
2255 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
2256 {
2257   disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2258            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2259   STD_Application::removeViewManager( vm );
2260   delete vm;
2261 }
2262
2263 /*!
2264   Renames active window of desktop
2265 */
2266 void LightApp_Application::onRenameWindow()
2267 {
2268   if( !desktop() )
2269     return;
2270
2271   QWidget* w = desktop()->activeWindow();
2272   if( !w )
2273     return;
2274
2275   bool ok;
2276   QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
2277   if( ok && !name.isEmpty() )
2278     w->setCaption( name );
2279 }
2280
2281 /*!
2282   \return if the library of module exists
2283   \param moduleTitle - title of module
2284 */
2285 bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
2286 {
2287   if( moduleTitle.isEmpty() )
2288     return false;
2289
2290   QString lib = moduleLibrary( moduleTitle );
2291   QStringList paths;
2292 #ifdef WIN32
2293   paths = QStringList::split( ";", ::getenv( "PATH" ) );
2294 #else
2295   paths = QStringList::split( ":", ::getenv( "LD_LIBRARY_PATH" ) );
2296 #endif
2297
2298   QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2299   for( ; anIt!=aLast; anIt++ )
2300   {
2301     QFileInfo inf( Qtx::addSlash( *anIt ) + lib );
2302     if( inf.exists() )
2303       return true;
2304   }
2305   return false;
2306 }
2307
2308 /*!
2309   \return default name for an active study
2310 */
2311 void LightApp_Application::setDefaultStudyName( const QString& theName )
2312 {
2313   QStringList anInfoList;
2314   modules( anInfoList, false );
2315
2316   LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
2317   if( anInfoList.count() == 1 && // to avoid a conflict between different modules
2318       !aStudy->isSaved() )
2319   {
2320     aStudy->setStudyName( theName );
2321     updateDesktopTitle();
2322   }
2323 }
2324
2325 /*! slot, called on show/hide of a dock window */
2326 void LightApp_Application::onVisibilityChanged( bool visible )
2327 {
2328   const QObject* win = sender();
2329  
2330   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2331     if ( itr.data() == win ) 
2332     {
2333       myWindowsVisible[ itr.key() ] = visible;
2334       return;
2335     }
2336 }
2337
2338 /*!
2339   Custom event handler
2340 */
2341 bool LightApp_Application::event( QEvent* e )
2342 {
2343   if( e && e->type()==2000 )
2344   {
2345     QCustomEvent* ce = ( QCustomEvent* )e;
2346     QString* d = ( QString* )ce->data();
2347     if( SUIT_MessageBox::warn2(0, tr("WRN_WARNING"),
2348                            d ? *d : "",
2349                            tr("BUT_OK"), tr("BUT_CANCEL"), 0, 1, 0 )==0 )
2350        onPreferences();
2351     if( d )
2352       delete d;
2353     return true;
2354   }
2355   return CAM_Application::event( e );
2356 }