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