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