]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_Application.cxx
Salome HOME
Join modifications from branch BR_3_1_0deb
[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 }
1214
1215 /*! Gets file name*/
1216 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters, 
1217                                            const QString& caption, QWidget* parent )
1218 {
1219   if ( !parent )
1220     parent = desktop();
1221   QStringList fls = QStringList::split( ";;", filters, false );
1222   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1223 }
1224
1225 /*! Gets directory*/
1226 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1227 {
1228   if ( !parent )
1229     parent = desktop();
1230   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1231 }
1232
1233 /*! Get open file names*/
1234 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters, 
1235                                                     const QString& caption, QWidget* parent )
1236 {
1237   if ( !parent )
1238     parent = desktop();
1239   QStringList fls = QStringList::split( ";;", filters, false );
1240   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1241 }
1242
1243 /*!Private SLOT. Update object browser.*/
1244 void LightApp_Application::onRefresh()
1245 {
1246   updateObjectBrowser( true );
1247 }
1248
1249 /*!Private SLOT. On preferences.*/
1250 void LightApp_Application::onPreferences()
1251 {
1252   QApplication::setOverrideCursor( Qt::waitCursor );
1253
1254   LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1255
1256   QApplication::restoreOverrideCursor();
1257
1258   if ( !prefDlg )
1259     return;
1260
1261   if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) &&  resourceMgr() ) {
1262     if ( desktop() )
1263       desktop()->saveGeometry( resourceMgr(), "desktop" );
1264     resourceMgr()->save();
1265   }
1266
1267   delete prefDlg;
1268 }
1269
1270 /*!Protected SLOT. On preferences changed.*/
1271 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1272 {
1273   LightApp_Module* sMod = 0;
1274   CAM_Module* mod = module( modName );
1275   if ( mod && mod->inherits( "LightApp_Module" ) )
1276     sMod = (LightApp_Module*)mod;
1277
1278   if ( sMod )
1279     sMod->preferencesChanged( section, param );
1280   else
1281     preferencesChanged( section, param );
1282 }
1283
1284 /*!Private SLOT. On open document with name \a aName.*/
1285 void LightApp_Application::onMRUActivated( QString aName )
1286 {
1287   onOpenDoc( aName );
1288 }
1289
1290 /*!Remove all windows from study.*/
1291 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1292 {
1293   CAM_Application::beforeCloseDoc( s );
1294
1295   for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1296     removeWindow( itr.key(), s->id() );
1297 }
1298
1299 /*!Update actions.*/
1300 void LightApp_Application::updateActions()
1301 {
1302   updateCommandsStatus();
1303 }
1304
1305 //=======================================================================
1306 // name    : createNewStudy
1307 /*! Purpose : Create new study*/
1308 //=======================================================================
1309 SUIT_Study* LightApp_Application::createNewStudy()
1310 {
1311   LightApp_Study* aStudy = new LightApp_Study( this );
1312
1313   // Set up processing of major study-related events
1314   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1315   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1316   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
1317   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1318
1319   return aStudy;
1320 }
1321
1322 /*!Create window.*/
1323 QWidget* LightApp_Application::createWindow( const int flag )
1324 {
1325   QWidget* wid = 0;
1326   if ( flag == WT_ObjectBrowser )
1327   {
1328     OB_Browser* ob = new OB_Browser( desktop() );
1329     ob->setAutoUpdate( true );
1330     ob->setAutoOpenLevel( 1 );
1331     ob->setCaption( tr( "OBJECT_BROWSER" ) );
1332
1333     OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1334     if( ob_list )
1335       ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1336
1337     ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1338     ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1339
1340     // Create OBSelector
1341     new LightApp_OBSelector( ob, mySelMgr );
1342
1343     wid = ob;
1344
1345     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1346   }
1347   else  if ( flag == WT_PyConsole )
1348   {
1349     PythonConsole* pyCons = new PythonConsole( desktop() );
1350     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1351     wid = pyCons;
1352     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1353   }
1354   else if ( flag == WT_LogWindow )
1355   {
1356     LogWindow* logWin = new LogWindow( desktop() );
1357     logWin->setCaption( tr( "LOG_WINDOW" ) );
1358     wid = logWin;
1359     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1360   }
1361   return wid;
1362 }
1363
1364 /*!Default windows(Object Browser, Python Console).
1365  * Adds to map \a aMap.
1366  */
1367 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1368 {  
1369   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1370   aMap.insert( WT_PyConsole, Qt::DockBottom );
1371   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1372 }
1373
1374 /*!Default view manager.*/
1375 void LightApp_Application::defaultViewManagers( QStringList& ) const
1376 {
1377   /*!Do nothing.*/
1378 }
1379
1380 /*!Gets preferences.
1381  * Create preferences, if \a crt = true.
1382  */
1383 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1384 {
1385   if ( myPrefs )
1386     return myPrefs;
1387
1388   LightApp_Application* that = (LightApp_Application*)this;
1389
1390   bool toCreate = !_prefs_ && crt;
1391   if( toCreate )
1392   {
1393     _prefs_ = new LightApp_Preferences( resourceMgr() );
1394     that->createPreferences( _prefs_ );
1395   }
1396
1397   that->myPrefs = _prefs_;
1398
1399   QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1400   for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1401   {
1402     if ( !appIt.current()->inherits( "LightApp_Application" ) )
1403       continue;
1404
1405     LightApp_Application* app = (LightApp_Application*)appIt.current();
1406
1407     QStringList modNameList;
1408     app->modules( modNameList, false );
1409     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1410     {
1411       int id = _prefs_->addPreference( *it );
1412       _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1413     }
1414
1415     ModuleList modList;
1416     app->modules( modList );
1417     for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1418     {
1419       LightApp_Module* mod = 0;
1420       if ( itr.current()->inherits( "LightApp_Module" ) )
1421         mod = (LightApp_Module*)itr.current();
1422
1423       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1424       {
1425         int modCat = _prefs_->addPreference( mod->moduleName() );
1426         _prefs_->setItemProperty( modCat, "info", QString::null );
1427         if( toCreate )
1428           mod->createPreferences();
1429       }
1430     }
1431   }
1432
1433   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1434            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1435
1436   return myPrefs;
1437 }
1438
1439 /*!Add new module to application.*/
1440 void LightApp_Application::moduleAdded( CAM_Module* mod )
1441 {
1442   CAM_Application::moduleAdded( mod );
1443
1444   LightApp_Module* lightMod = 0;
1445   if ( mod && mod->inherits( "LightApp_Module" ) )
1446     lightMod = (LightApp_Module*)mod;
1447
1448   if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1449   {
1450     int modCat = myPrefs->addPreference( mod->moduleName() );
1451     myPrefs->setItemProperty( modCat, "info", QString::null );
1452     lightMod->createPreferences();
1453   }
1454 }
1455
1456 /*!Create preferences.*/
1457 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1458 {
1459   if ( !pref )
1460     return;
1461
1462   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1463
1464   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1465   int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1466   pref->setItemProperty( studyGroup, "columns", 1 );
1467
1468   pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1469   pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1470   int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, LightApp_Preferences::IntSpin, "Study", "undo_level" );
1471   pref->setItemProperty( undoPref, "min", 1 );
1472   pref->setItemProperty( undoPref, "max", 100 );
1473   pref->addPreference( tr( "PREF_STORE_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
1474
1475   int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1476   pref->setItemProperty( extgroup, "columns", 1 );
1477   int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1478   pref->setItemProperty( apppref, "existing", true );
1479   pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1480   pref->setItemProperty( apppref, "readOnly", false );
1481
1482   pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1483
1484   int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1485   pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1486   pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1487
1488   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1489
1490   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1491
1492   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1493
1494   int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1495
1496   int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1497
1498   pref->setItemProperty( occGroup, "columns", 1 );
1499   pref->setItemProperty( vtkGroup, "columns", 1 );
1500   pref->setItemProperty( plot2dGroup, "columns", 1 );
1501
1502   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1503                                    LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1504   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1505                        LightApp_Preferences::Color, "OCCViewer", "background" );
1506
1507   pref->setItemProperty( occTS, "min", 1 );
1508   pref->setItemProperty( occTS, "max", 150 );
1509
1510   int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1511                                   LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1512   int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1513                                   LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1514
1515   pref->setItemProperty( isoU, "min", 0 );
1516   pref->setItemProperty( isoU, "max", 100000 );
1517
1518   pref->setItemProperty( isoV, "min", 0 );
1519   pref->setItemProperty( isoV, "max", 100000 );
1520
1521   int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1522                                    LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1523   pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
1524   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1525                        LightApp_Preferences::Color, "VTKViewer", "background" );
1526
1527   pref->setItemProperty( vtkTS, "min", 1 );
1528   pref->setItemProperty( vtkTS, "max", 150 );
1529
1530   pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1531                        LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1532
1533   int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1534                                             LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1535   QStringList aLegendPosList;
1536   aLegendPosList.append( tr("PREF_LEFT") );
1537   aLegendPosList.append( tr("PREF_RIGHT") );
1538   aLegendPosList.append( tr("PREF_TOP") );
1539   aLegendPosList.append( tr("PREF_BOTTOM") );
1540
1541   QValueList<QVariant> anIndexesList;
1542   anIndexesList.append(0);
1543   anIndexesList.append(1);
1544   anIndexesList.append(2);
1545   anIndexesList.append(3);
1546
1547   pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1548   pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1549
1550   int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1551                                        LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1552   QStringList aCurveTypesList;
1553   aCurveTypesList.append( tr("PREF_POINTS") );
1554   aCurveTypesList.append( tr("PREF_LINES") );
1555   aCurveTypesList.append( tr("PREF_SPLINE") );
1556
1557   anIndexesList.clear();
1558   anIndexesList.append(0);
1559   anIndexesList.append(1);
1560   anIndexesList.append(2);
1561   
1562   pref->setItemProperty( curveType, "strings", aCurveTypesList );
1563   pref->setItemProperty( curveType, "indexes", anIndexesList );
1564
1565   int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1566                                         LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1567
1568   pref->setItemProperty( markerSize, "min", 0 );
1569   pref->setItemProperty( markerSize, "max", 100 );
1570   
1571   QStringList aScaleModesList;
1572   aScaleModesList.append( tr("PREF_LINEAR") );
1573   aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1574   
1575   anIndexesList.clear();
1576   anIndexesList.append(0);
1577   anIndexesList.append(1);
1578
1579   int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1580                                       LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1581
1582   pref->setItemProperty( horScale, "strings", aScaleModesList );
1583   pref->setItemProperty( horScale, "indexes", anIndexesList );
1584
1585   int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1586                                       LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1587
1588   pref->setItemProperty( verScale, "strings", aScaleModesList );
1589   pref->setItemProperty( verScale, "indexes", anIndexesList );
1590
1591   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1592                        LightApp_Preferences::Color, "Plot2d", "Background" );
1593
1594   int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1595   int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1596   pref->setItemProperty( dirGroup, "columns", 1 );
1597   pref->addPreference( tr( "" ), dirGroup,
1598                        LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1599
1600   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1601                        LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1602   pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1603                        LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1604 //  pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1605 //                     LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1606
1607   int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1608   int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1609   pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
1610                        "ObjectBrowser", "auto_size_first" );
1611   pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
1612                        "ObjectBrowser", "auto_size" );
1613 }
1614
1615 /*!Changed preferences */
1616 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1617 {
1618   SUIT_ResourceMgr* resMgr = resourceMgr();
1619   if ( !resMgr )
1620     return;
1621
1622   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1623   {
1624     int sz = resMgr->integerValue( sec, param, -1 );
1625     QPtrList<SUIT_ViewManager> lst;
1626     viewManagers( OCCViewer_Viewer::Type(), lst );
1627     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1628     {
1629       SUIT_ViewModel* vm = it.current()->getViewModel();
1630       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1631         continue;
1632
1633       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1634       occVM->setTrihedronSize( sz );
1635       occVM->getAISContext()->UpdateCurrentViewer();
1636     }
1637   }
1638
1639   if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
1640   {
1641     int sz = resMgr->integerValue( "VTKViewer", "trihedron_size", -1 );
1642     QPtrList<SUIT_ViewManager> lst;
1643     viewManagers( SVTK_Viewer::Type(), lst );
1644     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1645     {
1646       SUIT_ViewModel* vm = it.current()->getViewModel();
1647       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1648         continue;
1649
1650       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1651       if( vtkVM )
1652       {
1653         vtkVM->setTrihedronSize( sz );
1654         vtkVM->Repaint();
1655       }
1656     }
1657   }
1658
1659   if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1660   {
1661     QPtrList<SUIT_ViewManager> lst;
1662     viewManagers( OCCViewer_Viewer::Type(), lst );
1663     int u = resMgr->integerValue( sec, "iso_number_u" );
1664     int v = resMgr->integerValue( sec, "iso_number_v" );
1665     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1666     {
1667       OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1668       if( mgr && mgr->getOCCViewer() )
1669         mgr->getOCCViewer()->setIsos( u, v );
1670     }
1671   }
1672
1673   if( sec=="ObjectBrowser" )
1674   {
1675     if( param=="auto_size" || param=="auto_size_first" )
1676     {
1677       OB_Browser* ob = objectBrowser();
1678       if( !ob )
1679         return;
1680
1681       bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ),
1682            autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
1683       ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1684       ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual );
1685       updateObjectBrowser( false );
1686     }
1687   }
1688
1689   if( sec=="Study" )
1690   { 
1691     if( param=="store_positions" )
1692       updateWindows();
1693   }
1694
1695   if( sec=="PyConsole" )
1696   {
1697     if( param=="font" )
1698       if( pythonConsole() )
1699         pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1700   }
1701 }
1702
1703 /*!Update desktop title.*/
1704 void LightApp_Application::updateDesktopTitle() {
1705   QString aTitle = applicationName();
1706   QString aVer = applicationVersion();
1707   if ( !aVer.isEmpty() )
1708     aTitle += QString( " " ) + aVer;
1709
1710   desktop()->setCaption( aTitle );
1711 }
1712
1713 /*!Update windows after close document.*/
1714 void LightApp_Application::afterCloseDoc()
1715 {
1716   updateWindows();
1717
1718   CAM_Application::afterCloseDoc();
1719 }
1720
1721 /*!Update module action.*/
1722 void LightApp_Application::updateModuleActions()
1723 {
1724   QString modName;
1725   if ( activeModule() )
1726     modName = activeModule()->moduleName();
1727
1728   if ( myActions.contains( modName ) )
1729     myActions[modName]->setOn( true );
1730 }
1731
1732 /*!Gets current windows.
1733  *\param winMap - output current windows map.
1734  */
1735 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
1736 {
1737   winMap.clear();
1738   if ( !activeStudy() )
1739     return;
1740
1741   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1742     ((LightApp_Module*)activeModule())->windows( winMap );
1743   else
1744     defaultWindows( winMap );
1745 }
1746
1747 /*!Gets current view managers.
1748  *\param lst - output current view managers list.
1749  */
1750 void LightApp_Application::currentViewManagers( QStringList& lst ) const
1751 {
1752   lst.clear();
1753   if ( !activeStudy() )
1754     return;
1755
1756   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1757     ((LightApp_Module*)activeModule())->viewManagers( lst );
1758   else
1759     defaultViewManagers( lst );
1760 }
1761
1762 /*!Update windows.*/
1763 void LightApp_Application::updateWindows()
1764 {
1765   QMap<int, int> winMap;
1766   currentWindows( winMap );
1767
1768   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1769     getWindow( it.key() );
1770
1771   loadWindowsGeometry();
1772
1773   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1774     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1775 }
1776
1777 /*!Update view managers.*/
1778 void LightApp_Application::updateViewManagers()
1779 {
1780   QStringList lst;
1781   currentViewManagers( lst );
1782
1783   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1784     getViewManager( *it, true );
1785 }
1786
1787 /*!Load windows geometry.*/
1788 void LightApp_Application::loadWindowsGeometry()
1789 {
1790   bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
1791   if( !store )
1792     return;
1793
1794   QtxDockAction* dockMgr = 0;
1795
1796   QAction* a = action( ViewWindowsId );
1797   if ( a && a->inherits( "QtxDockAction" ) )
1798     dockMgr = (QtxDockAction*)a;
1799
1800   if ( !dockMgr )
1801     return;
1802
1803   QString modName;
1804   if ( activeModule() )
1805     modName = activeModule()->name("");
1806
1807   QString section = QString( "windows_geometry" );
1808   if ( !modName.isEmpty() )
1809     section += QString( "." ) + modName;
1810
1811   dockMgr->loadGeometry( resourceMgr(), section, false );
1812   dockMgr->restoreGeometry();
1813 }
1814
1815 /*!Save windows geometry.*/
1816 void LightApp_Application::saveWindowsGeometry()
1817 {
1818   bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
1819   if( !store )
1820     return;
1821
1822   QtxDockAction* dockMgr = 0;
1823
1824   QAction* a = action( ViewWindowsId );
1825   if ( a && a->inherits( "QtxDockAction" ) )
1826     dockMgr = (QtxDockAction*)a;
1827
1828   if ( !dockMgr )
1829     return;
1830
1831   QString modName;
1832   if ( activeModule() )
1833     modName = activeModule()->name("");
1834
1835   QString section = QString( "windows_geometry" );
1836   if ( !modName.isEmpty() )
1837     section += QString( "." ) + modName;
1838
1839   dockMgr->storeGeometry();
1840   dockMgr->saveGeometry( resourceMgr(), section, false );
1841 }
1842
1843 /*!Activate windows.*/
1844 void LightApp_Application::activateWindows()
1845 {
1846   if ( activeStudy() )
1847   {
1848     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1849       itr.data()->activate( activeStudy()->id() );
1850   }
1851 }
1852
1853 /*!Adds icon names for modules.*/
1854 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1855 {
1856   iconMap.clear();
1857
1858   SUIT_ResourceMgr* resMgr = resourceMgr();
1859   if ( !resMgr )
1860     return;
1861
1862   QStringList modList;
1863   modules( modList, false );
1864
1865   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1866   {
1867     QString modName = *it;
1868     QString modIntr = moduleName( modName );
1869     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1870
1871     if ( modIcon.isEmpty() )
1872       continue;
1873
1874     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1875       modIcon += QString( ".png" );
1876
1877     iconMap.insert( modName, modIcon );
1878   }
1879 }
1880
1881 /*!Insert items in popup, which necessary for current application*/
1882 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1883 {
1884   CAM_Application::contextMenuPopup( type, thePopup, title );
1885
1886   OB_Browser* ob = objectBrowser();
1887   if ( !ob || type != ob->popupClientType() )
1888     return;
1889
1890   thePopup->insertSeparator();
1891   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1892 }
1893
1894 /*!Create empty study.*/
1895 void LightApp_Application::createEmptyStudy()
1896 {
1897   CAM_Application::createEmptyStudy();
1898   if ( objectBrowser() )
1899     objectBrowser()->updateTree();
1900 }
1901
1902 /*!Activate module \a mod.*/
1903 bool LightApp_Application::activateModule( CAM_Module* mod )
1904 {
1905   bool res = CAM_Application::activateModule( mod );
1906   if ( objectBrowser() )
1907     objectBrowser()->updateTree();
1908   return res;
1909 }
1910
1911 /*!return keyborad accelerators manager object */
1912 SUIT_Accel* LightApp_Application::accel() const
1913 {
1914   return myAccel;
1915 }
1916
1917 /*! remove dead widget container from map */
1918 void LightApp_Application::onWCDestroyed( QObject* ob )
1919 {
1920   // remove destroyed widget container from windows map
1921   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1922   {
1923     if ( itr.data() != ob )
1924       continue;
1925
1926     int key = itr.key();
1927     myWindows.remove( key );
1928     break;
1929   }
1930 }
1931
1932 /*! redefined to remove view manager from memory */
1933 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
1934 {
1935   disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1936            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1937   STD_Application::removeViewManager( vm );
1938   delete vm;
1939 }
1940
1941 /*! rename active window of desktop */
1942 void LightApp_Application::onRenameWindow()
1943 {
1944   if( !desktop() )
1945     return;
1946
1947   QWidget* w = desktop()->activeWindow();
1948   if( !w )
1949     return;
1950
1951   bool ok;
1952   QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
1953   if( ok && !name.isEmpty() )
1954     w->setCaption( name );
1955 }