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