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