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