Salome HOME
Clear info panel when module is deactivated
[modules/gui.git] / src / LightApp / LightApp_Application.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:      LightApp_Application.cxx
24 // Created:   6/20/2005 18:39:45 PM
25 // Author:    Natalia Donis
26
27 #ifdef WIN32
28 // E.A. : On windows with python 2.6, there is a conflict
29 // E.A. : between pymath.h and Standard_math.h which define
30 // E.A. : some same symbols : acosh, asinh, ...
31   #include <Standard_math.hxx>
32   #ifndef DISABLE_PYCONSOLE
33     #include <pymath.h>
34   #endif
35 #endif
36
37 #ifndef DISABLE_PYCONSOLE
38   #include "PyConsole_Interp.h"
39   #include "LightApp_PyEditor.h"
40   #include "PyConsole_Console.h"
41 #endif
42
43 #include "LightApp_Application.h"
44 #include "LightApp_Module.h"
45 #include "LightApp_DataModel.h"
46 #include "LightApp_DataOwner.h"
47 #include "LightApp_Displayer.h"
48 #include "LightApp_Study.h"
49 #include "LightApp_Preferences.h"
50 #include "LightApp_PreferencesDlg.h"
51 #include "LightApp_ModuleDlg.h"
52 #include "LightApp_AboutDlg.h"
53 #include "LightApp_ModuleAction.h"
54 // temporary commented
55 #include "LightApp_EventFilter.h"
56 #include "LightApp_OBSelector.h"
57 #include "LightApp_SelectionMgr.h"
58 #include "LightApp_DataObject.h"
59 #include "LightApp_WgViewModel.h"
60 #include "LightApp_FullScreenHelper.h"
61
62 #include <GUI_version.h>
63
64 #include <SALOME_Event.h>
65
66 #ifdef USE_SALOME_STYLE
67 #include <Style_Salome.h>
68 #include <Style_PrefDlg.h>
69 #endif // USE_SALOME_STYLE
70
71 #include <CAM_Module.h>
72 #include <CAM_DataModel.h>
73 #include <CAM_Study.h>
74 #include <STD_TabDesktop.h>
75
76 #include <SUIT_DataBrowser.h>
77 #include <SUIT_Session.h>
78 #include <SUIT_Study.h>
79 #include <SUIT_FileDlg.h>
80 #include <SUIT_ResourceMgr.h>
81 #include <SUIT_ShortcutMgr.h>
82 #include <SUIT_Tools.h>
83 #include <SUIT_Accel.h>
84 #include <SUIT_MessageBox.h>
85 #include <SUIT_ViewWindow.h>
86
87 #include <Qtx.h>
88 #include <QtxFontEdit.h>
89 #include <QtxToolBar.h>
90 #include <QtxTreeView.h>
91 #include <QtxInfoPanel.h>
92 #include <QtxMRUAction.h>
93 #include <QtxDockAction.h>
94 #include <QtxDockWidget.h>
95 #include <QtxActionToolMgr.h>
96 #include <QtxSearchTool.h>
97 #include <QtxWorkstack.h>
98 #include <QtxMap.h>
99
100 #include <LogWindow.h>
101
102 #ifndef DISABLE_GLVIEWER
103   #include <GLViewer_Viewer.h>
104   #include <GLViewer_ViewManager.h>
105   #include "LightApp_GLSelector.h"
106 #endif
107
108 #ifndef DISABLE_PLOT2DVIEWER
109   #include <Plot2d_ViewManager.h>
110   #include <Plot2d_ViewModel.h>
111   #include <Plot2d_ViewWindow.h>
112   #include <Plot2d_ViewFrame.h>
113   #include "LightApp_Plot2dSelector.h"
114 #ifndef DISABLE_SALOMEOBJECT
115   #include <SPlot2d_ViewModel.h>
116 #else
117   #include <Plot2d_ViewModel.h>
118 #endif
119 #endif
120
121 #ifndef DISABLE_OCCVIEWER
122   #include <OCCViewer_ViewManager.h>
123   #include <OCCViewer_ViewFrame.h>
124   #include <OCCViewer_ViewPort3d.h>
125 #ifndef DISABLE_SALOMEOBJECT
126   #include <SOCC_ViewModel.h>
127 #else
128   #include <OCCViewer_ViewModel.h>
129 #endif
130   #include "LightApp_OCCSelector.h"
131 #endif
132
133 #ifndef DISABLE_VTKVIEWER
134 #ifndef DISABLE_SALOMEOBJECT
135   #include <SVTK_ViewModel.h>
136   #include <SVTK_ViewManager.h>
137   #include "LightApp_VTKSelector.h"
138 #else
139   #include <VTKViewer_ViewModel.h>
140   #include <VTKViewer_ViewManager.h>
141 #endif
142   #include <VTKViewer_ViewModel.h>
143 #endif
144
145 #ifndef DISABLE_QXGRAPHVIEWER
146   #include <QxScene_ViewManager.h>
147   #include <QxScene_ViewModel.h>
148   #include <QxScene_ViewWindow.h>
149 #endif
150
151 #ifndef DISABLE_GRAPHICSVIEW
152   #include "GraphicsView_Viewer.h"
153   #include "GraphicsView_ViewManager.h"
154   #include "LightApp_GVSelector.h"
155 #endif
156
157 #ifndef DISABLE_PVVIEWER
158   #include "PVViewer_ViewManager.h"
159   #include "PVViewer_ViewWindow.h"
160   #include "PVViewer_ViewModel.h"
161 #endif
162
163 #ifndef DISABLE_PYVIEWER
164   #include <PyViewer_ViewManager.h>
165   #include <PyViewer_ViewModel.h>
166   #include <PyViewer_ViewWindow.h>
167 #endif
168
169
170 #define VISIBILITY_COLUMN_WIDTH 25
171
172 #include <QDir>
173 #include <QImage>
174 #include <QString>
175 #include <QWidget>
176 #include <QStringList>
177 #include <QFile>
178 #include <QApplication>
179 #include <QMap>
180 #include <QStatusBar>
181 #include <QThread>
182 #include <QObjectList>
183 #include <QComboBox>
184 #include <QInputDialog>
185 #include <QFontDatabase>
186 #include <QIcon>
187 #include <QByteArray>
188 #include <QMenu>
189 #include <QProcess>
190 #include <QTimer>
191 #include <QHeaderView>
192 #include <QTreeView>
193 #include <QMimeData>
194 #include <QShortcut>
195 #include <QRegExp>
196
197 #include <utilities.h>
198
199 #define FIRST_HELP_ID 1000000
200 #define HAS_WWW_URL true
201 #define HAS_FORUM_URL true
202 #define HAS_YOUTUBE_URL true
203 #define HAS_TUTORIAL_URL false
204
205 #ifndef DISABLE_SALOMEOBJECT
206   #include <SALOME_InteractiveObject.hxx>
207   #include <SALOME_ListIO.hxx>
208 #endif
209
210 #include <Standard_Version.hxx>
211
212 #define ToolBarMarker    0
213 #define DockWidgetMarker 1
214
215 static const char* imageEmptyIcon[] = {
216 "20 20 1 1",
217 ".      c None",
218 "....................",
219 "....................",
220 "....................",
221 "....................",
222 "....................",
223 "....................",
224 "....................",
225 "....................",
226 "....................",
227 "....................",
228 "....................",
229 "....................",
230 "....................",
231 "....................",
232 "....................",
233 "....................",
234 "....................",
235 "....................",
236 "....................",
237 "...................."};
238
239 // Markers used to parse array with dockable windows and toolbars state.
240 // For more details please see the qdockarealayout.cpp && qtoolbararealayout.cpp
241 // in the Qt source code.
242
243 #define QDockWidgetMarker 0xfd // = DockWidgetStateMarker
244 #define QToolBarMarker 0xfc    // = ToolBarStateMarkerEx
245
246 // Format of the Byte array with the windows and toolbar state is:
247 // VersionMarker|version|DockWidgetStateMarker|nbDockWidgetLines|...DocWidgetData...|ToolBarStateMarkerEx|nbToolBarLines|...ToolBarData...
248
249 //Find toolbar marker position in the array in the following way:
250 //since the 'toolbar marker' is not unique, find index of first occurrence of the
251 //'toolbar marker' in the array and check that next string is name of the toolbar
252
253 void LightAppCleanUpAppResources()
254 {
255   if ( LightApp_Application::_prefs_ ) {
256     delete LightApp_Application::_prefs_;
257     LightApp_Application::_prefs_ = 0;
258   }
259 }
260
261 namespace
262 {
263   int getToolbarMarkerIndex( QByteArray input, const QStringList& aFlags ) {
264     int aResult = -1,tmp = 0;
265     int inputLen = input.length();
266     QDataStream anInputData( &input, QIODevice::ReadOnly );
267     while ( tmp < inputLen ) {
268       tmp = input.indexOf( (uchar)QToolBarMarker, tmp + 1 );
269       if ( tmp < 0 )
270         break;
271       anInputData.device()->seek( tmp );
272       uchar mark;
273       anInputData >> mark;
274       int lines;
275       anInputData >> lines;
276
277       if ( lines == 0 && anInputData.atEnd() ) {
278         //Case then array doesn't contain information about toolbars,
279         aResult = tmp;
280         break;
281       }
282
283       int pos;
284       anInputData >> pos;
285       int cnt;
286       anInputData >> cnt;
287       QString str;
288       anInputData >> str;
289       if ( aFlags.contains( str ) ) {
290         aResult = tmp;
291         break;
292       }
293     }
294     return aResult;
295   }
296
297   QString langToName( const QString& lang )
298   {
299     // special processing for English language to avoid such result as "American English"
300     // as Qt cannot just say "English"
301     QString result;
302     if ( lang == "en" )
303       result = "English";
304     else
305       result = QLocale( lang ).nativeLanguageName();
306     return result;
307   }
308
309   QString getHelpItem( const QString& section, const QString& parameter, const QString& root = QString() )
310   {
311     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
312     foreach( QString item, resMgr->stringValue( section, parameter ).split( ";;", QString::SkipEmptyParts ) )
313     {
314       if ( item.startsWith( "http", Qt::CaseInsensitive ) )
315         return item;
316       QString path = item;
317       path.remove( QRegExp( "#.*$" ) );
318       QFileInfo fi( path );
319       if ( fi.isRelative() && !root.isEmpty() )
320         path = Qtx::addSlash( root ) + path;
321       if ( QFile::exists( path ) )
322         return item;
323     }
324     return QString();
325   }
326 }
327
328 /*!Create new instance of LightApp_Application.*/
329 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
330 {
331   return new LightApp_Application();
332 }
333
334 /*! \var global preferences of LightApp */
335 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
336
337
338 /*!
339   \class LightApp_Application
340   Application containing LightApp module
341 */
342
343 /*!Constructor.*/
344 LightApp_Application::LightApp_Application()
345 : CAM_Application( false ),
346   myPrefs( 0 ),
347   myScreenHelper(new LightApp_FullScreenHelper())
348 {
349   Q_INIT_RESOURCE( LightApp );
350
351   STD_TabDesktop* desk = new STD_TabDesktop();
352   desk->setFullScreenAllowed(false);
353   desk->setMinimizeAllowed(false);
354
355   setDesktop( desk );
356
357   // initialize auto save timer
358   myAutoSaveTimer = new QTimer( this );
359   myAutoSaveTimer->setSingleShot( true );
360   connect( myAutoSaveTimer, SIGNAL( timeout() ), this, SLOT( onSaveDoc() ) );
361
362   //connect( this, SIGNAL( moving() ), this, SLOT( onMoved() ) );
363
364   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
365   QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
366
367   desktop()->setWindowIcon( aLogo );
368   desktop()->setDockableMenuBar( false );
369   desktop()->setDockableStatusBar( false );
370
371   // base logo (salome itself)
372   desktop()->logoInsert( "_app_base",  aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
373   // extra logo (salome-based application)
374   desktop()->logoInsert( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
375
376   clearViewManagers();
377
378   mySelMgr = new LightApp_SelectionMgr( this );
379
380   myAccel = SUIT_Accel::getAccel();
381
382 #ifndef DISABLE_OCCVIEWER
383   myAccel->setActionKey( SUIT_Accel::PanLeft,     Qt::CTRL+Qt::Key_Left,     OCCViewer_Viewer::Type() );
384   myAccel->setActionKey( SUIT_Accel::PanRight,    Qt::CTRL+Qt::Key_Right,    OCCViewer_Viewer::Type() );
385   myAccel->setActionKey( SUIT_Accel::PanUp,       Qt::CTRL+Qt::Key_Up,       OCCViewer_Viewer::Type() );
386   myAccel->setActionKey( SUIT_Accel::PanDown,     Qt::CTRL+Qt::Key_Down,     OCCViewer_Viewer::Type() );
387   myAccel->setActionKey( SUIT_Accel::ZoomIn,      Qt::CTRL+Qt::Key_Plus,     OCCViewer_Viewer::Type() );
388   myAccel->setActionKey( SUIT_Accel::ZoomOut,     Qt::CTRL+Qt::Key_Minus,    OCCViewer_Viewer::Type() );
389   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::CTRL+Qt::Key_Asterisk, OCCViewer_Viewer::Type() );
390   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::Key_Space,             OCCViewer_Viewer::Type() );
391   myAccel->setActionKey( SUIT_Accel::RotateLeft,  Qt::ALT+Qt::Key_Left,      OCCViewer_Viewer::Type() );
392   myAccel->setActionKey( SUIT_Accel::RotateRight, Qt::ALT+Qt::Key_Right,     OCCViewer_Viewer::Type() );
393   myAccel->setActionKey( SUIT_Accel::RotateUp,    Qt::ALT+Qt::Key_Up,        OCCViewer_Viewer::Type() );
394   myAccel->setActionKey( SUIT_Accel::RotateDown,  Qt::ALT+Qt::Key_Down,      OCCViewer_Viewer::Type() );
395 #endif
396 #ifndef DISABLE_VTKVIEWER
397   myAccel->setActionKey( SUIT_Accel::PanLeft,     Qt::CTRL+Qt::Key_Left,     VTKViewer_Viewer::Type() );
398   myAccel->setActionKey( SUIT_Accel::PanRight,    Qt::CTRL+Qt::Key_Right,    VTKViewer_Viewer::Type() );
399   myAccel->setActionKey( SUIT_Accel::PanUp,       Qt::CTRL+Qt::Key_Up,       VTKViewer_Viewer::Type() );
400   myAccel->setActionKey( SUIT_Accel::PanDown,     Qt::CTRL+Qt::Key_Down,     VTKViewer_Viewer::Type() );
401   myAccel->setActionKey( SUIT_Accel::ZoomIn,      Qt::CTRL+Qt::Key_Plus,     VTKViewer_Viewer::Type() );
402   myAccel->setActionKey( SUIT_Accel::ZoomOut,     Qt::CTRL+Qt::Key_Minus,    VTKViewer_Viewer::Type() );
403   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::CTRL+Qt::Key_Asterisk, VTKViewer_Viewer::Type() );
404   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::Key_Space,             VTKViewer_Viewer::Type() );
405   myAccel->setActionKey( SUIT_Accel::RotateLeft,  Qt::ALT+Qt::Key_Left,      VTKViewer_Viewer::Type() );
406   myAccel->setActionKey( SUIT_Accel::RotateRight, Qt::ALT+Qt::Key_Right,     VTKViewer_Viewer::Type() );
407   myAccel->setActionKey( SUIT_Accel::RotateUp,    Qt::ALT+Qt::Key_Up,        VTKViewer_Viewer::Type() );
408   myAccel->setActionKey( SUIT_Accel::RotateDown,  Qt::ALT+Qt::Key_Down,      VTKViewer_Viewer::Type() );
409 #endif
410 #ifndef DISABLE_PLOT2DVIEWER
411   myAccel->setActionKey( SUIT_Accel::PanLeft,     Qt::CTRL+Qt::Key_Left,     Plot2d_Viewer::Type() );
412   myAccel->setActionKey( SUIT_Accel::PanRight,    Qt::CTRL+Qt::Key_Right,    Plot2d_Viewer::Type() );
413   myAccel->setActionKey( SUIT_Accel::PanUp,       Qt::CTRL+Qt::Key_Up,       Plot2d_Viewer::Type() );
414   myAccel->setActionKey( SUIT_Accel::PanDown,     Qt::CTRL+Qt::Key_Down,     Plot2d_Viewer::Type() );
415   myAccel->setActionKey( SUIT_Accel::ZoomIn,      Qt::CTRL+Qt::Key_Plus,     Plot2d_Viewer::Type() );
416   myAccel->setActionKey( SUIT_Accel::ZoomOut,     Qt::CTRL+Qt::Key_Minus,    Plot2d_Viewer::Type() );
417   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::CTRL+Qt::Key_Asterisk, Plot2d_Viewer::Type() );
418   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::Key_Space,             Plot2d_Viewer::Type() );
419 #endif
420
421   connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
422   connect( desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
423            this,      SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
424   connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
425            this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection );
426
427
428   // Set existing font for the python console in resources
429   if( !aResMgr->hasValue( "PyConsole", "font" ) )
430     return;
431
432   QFont f = aResMgr->fontValue( "PyConsole", "font" );
433   QFontDatabase fdb;
434   QStringList famdb = fdb.families();
435
436   if ( famdb.contains(f.family()) || !aResMgr->hasValue( "PyConsole", "additional_families" ) )
437     return;
438
439   QStringList anAddFamilies = aResMgr->stringValue( "PyConsole", "additional_families" ).split( ";", QString::SkipEmptyParts );
440   QString aFamily;
441   for ( QStringList::Iterator it = anAddFamilies.begin(); it != anAddFamilies.end(); ++it )
442   {
443     aFamily = *it;
444     if ( famdb.contains(aFamily) )
445     {
446       f.setFamily( aFamily );
447       aResMgr->setValue( "PyConsole", "font", f );
448       break;
449     }
450   }
451 }
452
453 /*!Destructor.
454  *\li Save window geometry.
455  *\li Save desktop geometry.
456  *\li Save resource maneger.
457  *\li Delete selection manager.
458  */
459 LightApp_Application::~LightApp_Application()
460 {
461   savePreferences();
462   delete mySelMgr;
463   delete myScreenHelper;
464   myPrefs = 0;
465 }
466
467 /*!Start application.*/
468 void LightApp_Application::start()
469 {
470   CAM_Application::start();
471
472   updateWindows();
473   updateViewManagers();
474   updateCommandsStatus();
475
476   putInfo( "" );
477   desktop()->statusBar()->showMessage( "" );
478
479   LightApp_EventFilter::Init();
480
481   onNewDoc();
482 }
483
484 /*!Closeapplication.*/
485 void LightApp_Application::closeApplication()
486 {
487 #ifndef DISABLE_QTXWEBBROWSER
488   QProcess::startDetached( "HelpBrowser",
489                            QStringList() << QString( "--remove=%1" ).arg( QApplication::instance()->applicationPid() ) );
490 #endif
491   CAM_Application::closeApplication();
492 }
493
494 /*!Gets application name.*/
495 QString LightApp_Application::applicationName() const
496 {
497   static QString _app_name;
498   if ( _app_name.isEmpty() )
499     _app_name = tr( "APP_NAME" );
500   return _app_name;
501 }
502
503 /*!Gets application version.*/
504 QString LightApp_Application::applicationVersion() const
505 {
506   static QString _app_version;
507
508   if ( _app_version.isEmpty() )
509   {
510     QString resVersion = tr( "APP_VERSION" );
511     if ( resVersion != "APP_VERSION" )
512     {
513       _app_version = resVersion;
514     }
515     else
516     {
517       _app_version = GUI_VERSION_STR;
518     }
519   }
520   return _app_version;
521 }
522
523 /*!Load module by \a name.*/
524 CAM_Module* LightApp_Application::loadModule( const QString& name, const bool showMsg )
525 {
526   CAM_Module* mod = CAM_Application::loadModule( name, showMsg );
527   if ( mod )
528   {
529     connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
530     connect( this, SIGNAL( studySaved() ),  mod, SLOT( onModelSaved() ) );
531     connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
532   }
533   return mod;
534 }
535
536 /*!Activate module by \a modName*/
537 bool LightApp_Application::activateModule( const QString& modName )
538 {
539   QString actName;
540   CAM_Module* prevMod = activeModule();
541
542   if ( prevMod )
543     actName = prevMod->moduleName();
544
545   if ( actName == modName )
546     return true;
547
548   putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
549
550   saveDockWindowsState();
551
552   if ( infoPanel() )
553     infoPanel()->clear();
554
555   bool status = CAM_Application::activateModule( modName );
556
557   updateModuleActions();
558
559   putInfo( "" );
560
561   if ( !status )
562     return false;
563
564   updateWindows();
565   updateViewManagers();
566
567   if ( activeStudy() && activeStudy()->root() && objectBrowser() ) {
568     if ( objectBrowser()->root() != activeStudy()->root() )
569       objectBrowser()->setRoot( activeStudy()->root() );
570     updateObjectBrowser( true );
571   }
572
573   if ( activeModule() ) activeModule()->updateModuleVisibilityState();
574
575   updateActions();
576   return true;
577 }
578
579 /*!Gets selection manager.*/
580 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
581 {
582   return mySelMgr;
583 }
584
585 /*!Creat action "New window" for certain type of viewer:*/
586 void LightApp_Application::createActionForViewer( const int id,
587                                                   const int parentId,
588                                                   const QString& suffix,
589                                                   const int accel )
590 {
591   QString vtlt = tr( QString( "NEW_WINDOW_%1" ).arg( suffix ).toLatin1().constData() );
592   QString tip = tr( "CREATING_NEW_WINDOW" ).arg( vtlt.remove( "&" ) );
593   QAction* a = createAction( id,                      // menu action id
594                              tip,                     // status tip
595                              QIcon(),                 // icon
596                              vtlt,                    // menu text
597                              tip,                     // tooltip
598                              accel,                   // shortcut
599                              desktop(),               // parent
600                              false,                   // toggle flag
601                              this,                    // receiver
602                              SLOT( onNewWindow() ) ); // slot
603   createMenu( a, parentId, -1 );
604 }
605
606 /*!Create actions:*/
607
608 void LightApp_Application::createActions()
609 {
610   CAM_Application::createActions();
611
612   SUIT_Desktop* desk = desktop();
613   SUIT_ResourceMgr* resMgr = resourceMgr();
614
615   // Preferences
616   createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIcon(),
617                 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
618                 Qt::CTRL+Qt::Key_P, desk, false, this, SLOT( onPreferences() ) );
619
620   // Help menu
621
622   int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
623
624   int id = LightApp_Application::UserID + FIRST_HELP_ID;
625
626   QString url;
627
628   // a) Link to web site
629   if ( HAS_WWW_URL ) {
630     url = resMgr->stringValue("GUI", "site_url");
631     if ( !url.isEmpty() ) {
632       QString title = tr ( "SALOME_SITE" );
633       QAction* as = createAction( WebSiteId, title,
634                                   resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ),
635                                   title, title,
636                                   0, desk, false, this, SLOT( onHelpContentsModule() ) );
637       as->setData( url );
638       createMenu( as, helpMenu, -1, 0 );
639     }
640   }
641
642   // b) Link to Forum
643   if ( HAS_FORUM_URL ) {
644     url = resMgr->stringValue("GUI", "forum_url");
645     if ( !url.isEmpty() ) {
646       QString title = tr ( "SALOME_FORUM" );
647       QAction* af = createAction( ForumId, title,
648                                   resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ),
649                                   title, title,
650                                   0, desk, false, this, SLOT( onHelpContentsModule() ) );
651       af->setData( url );
652       createMenu( af, helpMenu, -1, 0 );
653     }
654   }
655
656   // c) Link to YouTube channel
657   if ( HAS_YOUTUBE_URL ) {
658     url = resMgr->stringValue("GUI", "channel_url");
659     if ( !url.isEmpty() ) {
660       createMenu( separator(), helpMenu, -1, 0 );
661       QString title = tr ( "SALOME_VIDEO_TUTORIALS" );
662       QAction* av = createAction( VideosId, title,
663                                   resMgr->loadPixmap( "LightApp", tr( "ICON_LIFE_RIGN" ), false ),
664                                   title, tr( "PRP_SALOME_VIDEO_TUTORIALS" ),
665                                   0, desk, false, this, SLOT( onHelpContentsModule() ) );
666       av->setData( url );
667       createMenu( av, helpMenu, -1, 0 );
668     }
669   }
670
671   // d) Link to Tutorials
672   if ( HAS_TUTORIAL_URL ) {
673     url = resMgr->stringValue("GUI", "tutorials_url");
674     if ( !url.isEmpty() ) {
675       QString title = tr ( "SALOME_TUTORIALS" );
676       QAction* as = createAction( TutorialsId, title,
677                                   resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ),
678                                   title, tr( "PRP_SALOME_TUTORIALS" ),
679                                   0, desk, false, this, SLOT( onHelpContentsModule() ) );
680       as->setData( url );
681       createMenu( as, helpMenu, -1, 0 );
682     }
683   }
684
685   // e) Help for modules
686
687   // - First create top-level menus to preserve correct order
688   QString userGuide = "User's Guide";
689   QString devGuide = "Developer's Guide";
690   createMenu( userGuide, helpMenu, -1, 5 );
691   createMenu( devGuide, helpMenu, -1, 5 );
692
693   QStringList aModuleList;
694   modules( aModuleList, false );
695   aModuleList.prepend( "GUI" );
696   aModuleList.prepend( "KERNEL" );
697
698   QString aModule;
699   foreach( aModule, aModuleList ) {
700     if ( aModule.isEmpty() )                                         // module title (user name)
701       continue;
702     IMap <QString, QString> helpData;                                // list of help files for the module
703     QString helpSubMenu;                                             // help submenu name (empty if not needed)
704     QString modName = moduleName( aModule );                         // module name
705     if ( modName.isEmpty() ) modName = aModule;                      // for KERNEL and GUI
706     QString rootDir = QString( "%1_ROOT_DIR" ).arg( modName );       // module root dir env variable
707     QString modDir  = Qtx::getenv( rootDir.toUtf8().constData() );   // module root dir path
708     QString docSection;
709     if (resMgr->hasValue( modName, "documentation" ) )
710       docSection = resMgr->stringValue(modName, "documentation");
711     else if ( resMgr->hasSection( modName + "_documentation" ) )
712       docSection = modName + "_documentation";
713     if ( !docSection.isEmpty() ) {
714       helpSubMenu = resMgr->stringValue( docSection, "sub_menu", "" );
715       if ( helpSubMenu.contains( "%1" ) )
716         helpSubMenu = helpSubMenu.arg( aModule );
717       foreach( QString paramName, resMgr->parameters( docSection ) ) {
718         QString key = paramName.contains( "%1" ) ? paramName.arg( aModule ) : paramName;
719         QString helpItem = getHelpItem( docSection, paramName );
720         if ( !helpItem.isEmpty() )
721           helpData.insert( key, helpItem );
722       }
723     }
724
725     if ( helpData.isEmpty() && !modDir.isEmpty() ) {
726       QStringList idxLst = QStringList() << modDir << "share" << "doc" << "salome" << "gui" << modName << "index.html";
727       QString indexFile = idxLst.join( QDir::separator() );          // index file
728       if ( QFile::exists( indexFile ) )
729         helpData.insert( tr( "%1 module Users's Guide" ).arg( aModule ), indexFile );
730     }
731
732     IMapConstIterator<QString, QString > fileIt;
733     for ( fileIt = helpData.begin(); fileIt != helpData.end(); fileIt++ ) {
734       QString helpItemPath = fileIt.key();
735       // remove all '//' occurances
736       while ( helpItemPath.contains( "//" ) )
737         helpItemPath.replace( "//", "" );
738       // obtain submenus hierarchy if given
739       QStringList smenus = helpItemPath.split( "/" );
740       helpItemPath = smenus.takeLast();
741       // workaround for User's Guide and Developer's Guide to avoid having single item in module's submenu.
742       if ( helpItemPath == userGuide || helpItemPath == devGuide ) {
743         QString menuPath = smenus.join( "/" );
744         QStringList allKeys = helpData.keys();
745         QStringList total = allKeys.filter( QRegExp( QString( "^%1" ).arg( menuPath ) ) );
746         if ( total.count() == 1 && smenus.count() > 0 )
747           helpItemPath = smenus.takeLast();
748       }
749       QPixmap helpIcon = fileIt.value().startsWith( "http", Qt::CaseInsensitive ) ?
750         resMgr->loadPixmap( "STD", tr( "ICON_WWW" ), false ) : resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false );
751       QAction* a = createAction( id, helpItemPath, helpIcon, helpItemPath, helpItemPath,
752                                  0, desk, false, this, SLOT( onHelpContentsModule() ) );
753       a->setData( fileIt.value() );
754       if ( !helpSubMenu.isEmpty() ) {
755         smenus.prepend( helpSubMenu );
756       }
757       // create sub-menus hierarchy
758       int menuId = helpMenu;
759       foreach ( QString subMenu, smenus )
760         menuId = createMenu( subMenu, menuId, -1, 5 );
761       createMenu( a, menuId, -1, ( menuId != helpMenu && (helpItemPath == userGuide || helpItemPath == devGuide) ) ? 0 : 5 );
762       id++;
763     }
764   }
765
766   // - Additional help items
767
768   createMenu( separator(), helpMenu, -1, 10 );
769
770   QStringList addHelpItems = resMgr->parameters( "add_help" );
771   foreach ( QString paramName, addHelpItems ) {
772     QString helpItem = getHelpItem( "add_help", paramName );
773     if ( !helpItem.isEmpty() )
774     {
775       QPixmap helpIcon = helpItem.startsWith( "http", Qt::CaseInsensitive ) ?
776         resMgr->loadPixmap( "STD", tr( "ICON_WWW" ), false ) : resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false );
777       QAction* a = createAction( id++, paramName, helpIcon, paramName, paramName,
778                                  0, desk, false, this, SLOT( onHelpContentsModule() ) );
779       a->setData( helpItem );
780       createMenu( a, helpMenu, -1, 10 );
781     }
782   }
783
784   //! MRU
785   static QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), 0 );
786   connect( mru, SIGNAL( activated( const QString& ) ), this, SLOT( onMRUActivated( const QString& ) ) );
787   registerAction( MRUId, mru );
788
789   // default icon for neutral point ('SALOME' module)
790   QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
791   if ( defIcon.isNull() )
792     defIcon = QPixmap( imageEmptyIcon );
793
794   //! default icon for any module
795   QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
796   if ( modIcon.isNull() )
797     modIcon = QPixmap( imageEmptyIcon );
798
799   QStringList modList;
800   modules( modList, false );
801
802   if ( modList.count() > 1 )
803   {
804     LightApp_ModuleAction* moduleAction =
805       new LightApp_ModuleAction( tr( "APP_NAME" ), defIcon, desk );
806
807     QMap<QString, QString> iconMap;
808     moduleIconNames( iconMap );
809
810     const int iconSize = 20;
811
812     QStringList::Iterator it;
813     for ( it = modList.begin(); it != modList.end(); ++it )
814     {
815       QString modName = moduleName( *it );
816
817       QString iconName;
818       if ( iconMap.contains( *it ) )
819         iconName = iconMap[*it];
820
821       QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
822       if ( icon.isNull() )
823       {
824         icon = modIcon;
825         INFOS( std::endl <<
826                "****************************************************************" << std::endl <<
827                "     Warning: icon for " << qPrintable(*it) << " is not found!" << std::endl <<
828                "     Using the default icon." << std::endl <<
829                "****************************************************************" << std::endl);
830       }
831       icon = Qtx::scaleIcon( icon, iconSize );
832
833       moduleAction->insertModule( *it, icon );
834     }
835
836     connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ),
837              this, SLOT( onModuleActivation( const QString& ) ) );
838     registerAction( ModulesListId, moduleAction );
839   }
840
841   // New window
842   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 );
843   int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
844
845   createAction( CloseId, tr( "TOT_CLOSE" ), QIcon(), tr( "MEN_DESK_CLOSE" ), tr( "PRP_CLOSE" ),
846                 Qt::CTRL+Qt::Key_F4, desk, false, this, SLOT( onCloseWindow() ) );
847   createAction( CloseAllId, tr( "TOT_CLOSE_ALL" ), QIcon(), tr( "MEN_DESK_CLOSE_ALL" ), tr( "PRP_CLOSE_ALL" ),
848                 0, desk, false, this, SLOT( onCloseAllWindow() ) );
849   createAction( GroupAllId, tr( "TOT_GROUP_ALL" ), QIcon(), tr( "MEN_DESK_GROUP_ALL" ), tr( "PRP_GROUP_ALL" ),
850                 0, desk, false, this, SLOT( onGroupAllWindow() ) );
851
852   createMenu( CloseId,     windowMenu, 0, -1 );
853   createMenu( CloseAllId,  windowMenu, 0, -1 );
854   createMenu( GroupAllId,  windowMenu, 0, -1 );
855   createMenu( separator(), windowMenu, -1, 0 );
856
857 #ifndef DISABLE_GLVIEWER
858   createActionForViewer( NewGLViewId, newWinMenu, QString::number( 0 ), Qt::ALT+Qt::Key_G );
859 #endif
860 #ifndef DISABLE_PLOT2DVIEWER
861   createActionForViewer( NewPlot2dId, newWinMenu, QString::number( 1 ), Qt::ALT+Qt::Key_P );
862 #endif
863 #ifndef DISABLE_OCCVIEWER
864   createActionForViewer( NewOCCViewId, newWinMenu, QString::number( 2 ), Qt::ALT+Qt::Key_O );
865 #endif
866 #ifndef DISABLE_VTKVIEWER
867   createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), Qt::ALT+Qt::Key_K );
868 #endif
869 #ifndef DISABLE_QXGRAPHVIEWER
870   createActionForViewer( NewQxSceneViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_S );
871 #endif
872 #ifndef DISABLE_GRAPHICSVIEW
873   createActionForViewer( NewGraphicsViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_C );
874 #endif
875 #ifndef DISABLE_PVVIEWER
876   createActionForViewer( NewPVViewId, newWinMenu, QString::number( 6 ), Qt::ALT+Qt::Key_A );
877 #endif
878 #ifndef DISABLE_PYVIEWER
879   createActionForViewer( NewPyViewerId, newWinMenu, QString::number( 7 ), Qt::ALT+Qt::Key_Y );
880 #endif
881
882   createAction( RenameId, tr( "TOT_RENAME" ), QIcon(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
883                 Qt::ALT+Qt::SHIFT+Qt::Key_R, desk, false, this, SLOT( onRenameWindow() ) );
884   createMenu( RenameId, windowMenu, -1 );
885
886   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
887   createMenu( PreferencesId, fileMenu, 50, -1 );
888   createMenu( separator(), fileMenu, -1, 50, -1 );
889
890   createMenu( separator(), fileMenu, -1, 100, -1 );
891   createMenu( MRUId, fileMenu, 100, -1 );
892   createMenu( separator(), fileMenu, -1, 100, -1 );
893
894 #ifdef USE_SALOME_STYLE
895   createAction( StyleId, tr( "TOT_THEME" ), QIcon(), tr( "MEN_DESK_THEME" ), tr( "PRP_THEME" ),
896                 0, desk, false, this, SLOT( onStylePreferences() ) );
897 #endif // USE_SALOME_STYLE
898
899   createAction( FullScreenId, tr( "TOT_FULLSCREEN" ), QIcon(), tr( "MEN_DESK_FULLSCREEN" ), tr( "PRP_FULLSCREEN" ),
900                 Qt::Key_F11, desk, false, this, SLOT( onFullScreen() ) );
901
902
903   int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1 );
904   createMenu( separator(), viewMenu, -1, 20, -1 );
905 #ifdef USE_SALOME_STYLE
906   createMenu( StyleId, viewMenu, 20, -1 );
907 #endif // USE_SALOME_STYLE
908   createMenu( FullScreenId, viewMenu, 20, -1 );
909
910   int modTBar = createTool( tr( "INF_TOOLBAR_MODULES" ),    // title (language-dependant)
911                             QString( "SalomeModules" ) );   // name (language-independant)
912   createTool( ModulesListId, modTBar );
913 }
914
915 /*!On module activation action.*/
916 void LightApp_Application::onModuleActivation( const QString& modName )
917 {
918   // Force user to create/open a study before module activation
919   QMap<QString, QString> iconMap;
920   moduleIconNames( iconMap );
921   QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
922   if ( icon.isNull() )
923     icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
924
925   bool cancelled = false;
926
927   while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
928     LightApp_ModuleDlg aDlg( desktop(), modName, icon );
929     QMap<int, QString> opmap = activateModuleActions();
930     for ( QMap<int, QString>::ConstIterator it = opmap.begin(); it != opmap.end(); ++it )
931       aDlg.addButton( it.value(), it.key() );
932
933     int res = aDlg.exec();
934     if ( res ) {
935       // some operation is selected
936       moduleActionSelected( res );
937     }
938     else {
939       // cancelled
940       putInfo( tr("INF_CANCELLED") );
941
942       LightApp_ModuleAction* moduleAction =
943         qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
944       if ( moduleAction )
945         moduleAction->setActiveModule( QString() );
946       cancelled = true;
947     }
948   }
949
950   if ( !cancelled )
951     activateModule( modName );
952 }
953
954 /*!Default module activation.*/
955 QString LightApp_Application::defaultModule() const
956 {
957   QStringList aModuleNames;
958   modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
959   //! If there's the one and only module --> activate it automatically
960   //! TODO: Possible improvement - default module can be taken from preferences
961   return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
962 }
963
964 /*!On new window slot.*/
965 void LightApp_Application::onNewWindow()
966 {
967   const QObject* obj = sender();
968   if ( !obj || !obj->inherits( "QAction" ) )
969     return;
970
971   QString type;
972   int id = actionId( (QAction*)obj );
973   switch ( id )
974   {
975 #ifndef DISABLE_GLVIEWER
976   case NewGLViewId:
977     type = GLViewer_Viewer::Type();
978     break;
979 #endif
980 #ifndef DISABLE_PLOT2DVIEWER
981   case NewPlot2dId:
982     type = Plot2d_Viewer::Type();
983     break;
984 #endif
985 #ifndef DISABLE_OCCVIEWER
986   case NewOCCViewId:
987     type = OCCViewer_Viewer::Type();
988     break;
989 #endif
990 #ifndef DISABLE_VTKVIEWER
991   case NewVTKViewId:
992     type = VTKViewer_Viewer::Type();
993     break;
994 #endif
995 #ifndef DISABLE_QXGRAPHVIEWER
996   case NewQxSceneViewId:
997     type = QxScene_Viewer::Type();
998     break;
999 #endif
1000 #ifndef DISABLE_GRAPHICSVIEW
1001   case NewGraphicsViewId:
1002     type = GraphicsView_Viewer::Type();
1003     break;
1004 #endif
1005 #ifndef DISABLE_PVVIEWER
1006   case NewPVViewId:
1007     type = PVViewer_Viewer::Type();
1008     break;
1009 #endif
1010 #ifndef DISABLE_PYVIEWER
1011   case NewPyViewerId:
1012     type = PyViewer_Viewer::Type();
1013     break;
1014 #endif
1015   }
1016
1017   if ( !type.isEmpty() )
1018     createViewManager( type );
1019 }
1020
1021 /*!
1022   SLOT: Creates new document
1023 */
1024 void LightApp_Application::onNewDoc()
1025 {
1026   if ( !checkExistingDoc() )
1027     return;
1028
1029   //asl: fix for 0020515
1030   saveDockWindowsState();
1031
1032   CAM_Application::onNewDoc();
1033 }
1034
1035 /*!
1036   SLOT: Opens new document
1037 */
1038 void LightApp_Application::onOpenDoc()
1039 {
1040   SUIT_Study* study = activeStudy();
1041   
1042   if ( !checkExistingDoc( false ) )
1043     return;
1044   
1045   QString aName = getFileName( true, QString(), getFileFilter( true ), QString(), 0 );
1046   if ( aName.isNull() ) //Cancel
1047     return;
1048   
1049   onOpenDoc( aName );
1050   
1051   if ( !study ) // new study will be create in THIS application
1052   {
1053     updateWindows();
1054     updateViewManagers();
1055   }
1056 }
1057
1058 bool LightApp_Application::canOpenDoc( const QString& )
1059 {
1060   return true;
1061 }
1062
1063 /*!
1064   SLOT: Opens new document.
1065   \param aName - name of file
1066 */
1067 bool LightApp_Application::onOpenDoc( const QString& aName )
1068 {
1069   if ( !canOpenDoc(aName)) {
1070     bool showError = !property("open_study_from_command_line").isValid() ||
1071       !property("open_study_from_command_line").toBool();
1072
1073     putInfo( tr("OPEN_DOCUMENT_PROBLEM") );
1074     if ( showError )
1075       SUIT_MessageBox::critical( desktop(), tr("ERR_ERROR"), tr("OPEN_DOCUMENT_PROBLEM"));
1076
1077     return false;
1078   }
1079
1080   closeDoc(false);
1081
1082   if ( !checkExistingDoc() )
1083     return false;
1084
1085   saveDockWindowsState();
1086
1087   // We should take mru action first because this application instance can be deleted later.
1088   QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
1089
1090   bool res = CAM_Application::onOpenDoc( aName );
1091
1092   if ( mru )
1093   {
1094     if ( res )
1095       mru->insert( aName );
1096     else
1097       mru->remove( aName );
1098   }
1099   return res;
1100 }
1101
1102 /*!
1103   SLOT: Displays "About" message box
1104 */
1105 void LightApp_Application::onHelpAbout()
1106 {
1107   LightApp_AboutDlg dlg( applicationName(), applicationVersion(), desktop() );
1108   dlg.exec();
1109 }
1110
1111 /*!
1112   Private SLOT: Called on selection is changed
1113   Dispatchs active module that selection is changed
1114 */
1115 void LightApp_Application::onSelection()
1116 {
1117   //MESSAGE("onSelection")
1118   onSelectionChanged();
1119
1120   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
1121     ((LightApp_Module*)activeModule())->selectionChanged();
1122 }
1123
1124 /*!
1125   Sets active study.
1126  \param study - SUIT_Study.
1127 */
1128 void LightApp_Application::setActiveStudy( SUIT_Study* study )
1129 {
1130   CAM_Application::setActiveStudy( study );
1131 }
1132
1133 /*!
1134   Enables/Disables menu items and toolbar buttons. Rebuild menu
1135 */
1136 void LightApp_Application::updateCommandsStatus()
1137 {
1138   CAM_Application::updateCommandsStatus();
1139   QAction* a = 0;
1140
1141 #ifndef DISABLE_GLVIEWER
1142   a = action( NewGLViewId );
1143   if( a )
1144     a->setEnabled( activeStudy() );
1145 #endif
1146
1147 #ifndef DISABLE_PLOT2DVIEWER
1148   a = action( NewPlot2dId );
1149   if( a )
1150     a->setEnabled( activeStudy() );
1151 #endif
1152
1153 #ifndef DISABLE_OCCVIEWER
1154   a = action( NewOCCViewId );
1155   if( a )
1156     a->setEnabled( activeStudy() );
1157 #endif
1158
1159 #ifndef DISABLE_VTKVIEWER
1160   a = action( NewVTKViewId );
1161   if( a )
1162     a->setEnabled( activeStudy() );
1163 #endif
1164
1165 #ifndef DISABLE_QXGRAPHVIEWER
1166   a = action( NewQxSceneViewId );
1167   if( a )
1168     a->setEnabled( activeStudy() );
1169 #endif
1170
1171 #ifndef DISABLE_GRAPHICSVIEW
1172   a = action( NewGraphicsViewId );
1173   if( a )
1174     a->setEnabled( activeStudy() );
1175 #endif
1176
1177 #ifndef DISABLE_PVVIEWER
1178   a = action( NewPVViewId );
1179   if( a )
1180     a->setEnabled( activeStudy() );
1181 #endif
1182
1183 #ifndef DISABLE_PYVIEWER
1184   a = action( NewPyViewerId );
1185   if( a )
1186     a->setEnabled( activeStudy() );
1187 #endif
1188 }
1189
1190 /*!
1191   \class RunBrowser
1192   Runs system command in separate thread
1193 */
1194 class RunBrowser: public QThread
1195 {
1196 public:
1197   static void execute( LightApp_Application* application,
1198                        const QString& browser,
1199                        const QString& parameters,
1200                        const QString& url )
1201   {
1202     (new RunBrowser( application, browser, parameters, url ))->start();
1203   }
1204
1205 protected:
1206   RunBrowser( LightApp_Application* application,
1207               const QString&        browser,
1208               const QString&        parameters,
1209               const QString&        url)
1210     : myApplication( application ),
1211       myBrowser( browser ),
1212       myParameters( parameters ),
1213       myUrl( url )
1214   {
1215     if ( !myUrl.startsWith( "http", Qt::CaseInsensitive ) )
1216     {
1217       // normalize path
1218       if ( myUrl.startsWith( "file://", Qt::CaseInsensitive ) )
1219         myUrl = myUrl.remove( 0, QString( "file://" ).count() );
1220       // For the external browser we always specify 'file://' protocol,
1221       // because some web browsers (e.g. Mozilla Firefox) can't open local file without protocol.
1222       myUrl = myUrl.prepend( "file://" );
1223     }
1224     connect(this, SIGNAL(finished()), SLOT(deleteLater()));
1225   }
1226
1227   virtual void run()
1228   {
1229     if ( !myBrowser.isEmpty() && !myUrl.isEmpty() )
1230     {
1231       QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
1232 #ifdef WIN32
1233       QString cmdLine = QString( "\"%1\" %2 \"%3\"" ).arg( myBrowser, myParameters, myUrl );
1234 #else
1235       QString cmdLine = QString( "%1 %2 \"%3\"" ).arg( myBrowser, myParameters, myUrl );
1236       // remove LD_LIBRARY_PATH from the environement before starting launcher to avoid bad interactions.
1237       // (especially in the case of universal binaries) 
1238       env.remove("LD_LIBRARY_PATH");
1239 #endif
1240       QProcess* proc = new QProcess();
1241       proc->setProcessEnvironment(env);
1242       proc->start( cmdLine );
1243       if ( !proc->waitForStarted() )
1244       {
1245         SALOME_CustomEvent* ce2000 = new SALOME_CustomEvent( 2000 );
1246         QString* msg = new QString( QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).arg( myBrowser, myUrl ) );
1247         ce2000->setData( msg );
1248         QApplication::postEvent( myApplication, ce2000 );
1249       }
1250     }
1251   }
1252
1253 private:
1254   LightApp_Application* myApplication;
1255   QString               myBrowser;
1256   QString               myParameters;
1257   QString               myUrl;
1258 };
1259
1260 void LightApp_Application::showHelp( const QString& path )
1261 {
1262   SUIT_ResourceMgr* resMgr = resourceMgr();
1263
1264 #if DISABLE_QTXWEBBROWSER
1265   bool useExternalBrowser = true;
1266 #else
1267   bool useExternalBrowser = resMgr->booleanValue("ExternalBrowser", "use_external_browser", false );
1268 #endif
1269
1270   if ( useExternalBrowser )
1271   {
1272 #ifdef WIN32
1273     QString browser = resMgr->stringValue( "ExternalBrowser", "winapplication" ) ;
1274 #else
1275     QString browser = resMgr->stringValue( "ExternalBrowser", "application" );
1276 #endif
1277     QString parameters = resMgr->stringValue("ExternalBrowser", "parameters");
1278
1279     if ( !browser.isEmpty() )
1280     {
1281       RunBrowser::execute( this, browser, parameters, path );
1282     }
1283     else
1284     {
1285       if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ),
1286                                       SUIT_MessageBox::Yes | SUIT_MessageBox::No,
1287                                       SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
1288       {
1289         QStringList path;
1290         path << tr( "PREF_CATEGORY_SALOME" ) << tr( "PREF_TAB_GENERAL" )
1291              << tr( "PREF_GROUP_EXT_BROWSER" ) << tr( "PREF_APP" );
1292         showPreferences( path );
1293       }
1294     }
1295   }
1296   else
1297   {
1298     QStringList cmdLine;
1299     cmdLine << QString( "--language=%1" ).arg( resMgr->stringValue( "language", "language" ) );
1300     cmdLine << QString( "--add=%1" ).arg( QApplication::instance()->applicationPid() );
1301     cmdLine << path;
1302     QProcess::startDetached( "HelpBrowser", cmdLine );
1303   }
1304 }
1305
1306 /*!
1307   SLOT: Displays help contents for choosen module
1308 */
1309 void LightApp_Application::onHelpContentsModule()
1310 {
1311   const QAction* a = (QAction*) sender();
1312   QString helpFile = a->data().toString();
1313   if ( !helpFile.isEmpty() )
1314     showHelp( helpFile );
1315 }
1316
1317 /*!
1318   SLOT: Displays contextual help (e.g. for choosen dialog)
1319 */
1320 void LightApp_Application::onHelpContextModule( const QString& component,
1321                                                 const QString& url,
1322                                                 const QString& context )
1323 {
1324   QString path = url;
1325   if ( !url.startsWith( "http", Qt::CaseInsensitive ) )
1326   {
1327     // local file path
1328     QFileInfo fi( url );
1329     if ( fi.isRelative() && !component.isEmpty() )
1330     {
1331       QString rootDir = Qtx::getenv( (component + "_ROOT_DIR").toLatin1().constData() );
1332       if ( !rootDir.isEmpty() )
1333       {
1334         path = (QStringList() << rootDir << "share" << "doc" << "salome" << "gui" << component << url).join( QDir::separator() );
1335       }
1336     }
1337   }
1338   if ( !context.isEmpty() )
1339   {
1340     path += QString( "#%1" ).arg( context );
1341   }
1342   showHelp( path );
1343 }
1344
1345 /*!
1346   Sets enable or disable some actions on selection changed.
1347 */
1348 void LightApp_Application::onSelectionChanged()
1349 {
1350   LightApp_Module* m = dynamic_cast<LightApp_Module*>( activeModule() );
1351   bool canCopy  = m ? m->canCopy() : false;
1352   bool canPaste = m ? m->canPaste() : false;
1353
1354   action( EditCopyId )->setEnabled(canCopy);
1355   action( EditPasteId )->setEnabled(canPaste);
1356 }
1357
1358 /*!
1359   SLOT: Performs some actions when dockable windows are triggered
1360 */
1361 void LightApp_Application::onDockWindowVisibilityChanged( bool )
1362 {
1363 }
1364
1365 QWidget* LightApp_Application::dockWindow( const int id ) const
1366 {
1367   QWidget* wid = 0;
1368   if ( myWin.contains( id ) )
1369     wid = myWin[id];
1370   return wid;
1371 }
1372
1373 QDockWidget* LightApp_Application::windowDock( QWidget* wid ) const
1374 {
1375   if ( !wid )
1376     return 0;
1377
1378   QDockWidget* dock = 0;
1379   QWidget* w = wid->parentWidget();
1380   while ( w && !dock )
1381   {
1382     dock = ::qobject_cast<QDockWidget*>( w );
1383     w = w->parentWidget();
1384   }
1385   return dock;
1386 }
1387
1388 void LightApp_Application::insertDockWindow( const int id, QWidget* wid )
1389 {
1390   if ( !wid )
1391     return;
1392
1393   if ( wid != dockWindow( id ) )
1394     removeDockWindow( id );
1395
1396   myWin.insert( id, wid );
1397
1398   QtxDockWidget* dock = new QtxDockWidget( true, desktop() );
1399   if ( id == WT_InfoPanel ) {
1400     // Info panel's position is strongly limited to the right area;
1401     // It is not movable and not floatable.
1402     dock->setAllowedAreas( Qt::RightDockWidgetArea );
1403     dock->setFeatures( QDockWidget::DockWidgetClosable );
1404     connect( dock, SIGNAL( aboutToShow()), this, SLOT( onInfoPanelShown() ) );
1405   }
1406   else {
1407     dock->setFeatures( QDockWidget::AllDockWidgetFeatures );
1408   }
1409   connect( dock, SIGNAL(  destroyed( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1410
1411   dock->setObjectName( wid->objectName().isEmpty() ? QString( "window_%1" ).arg( id ) :
1412                        QString( "%1Dock" ).arg( wid->objectName() ) );
1413   dock->setWidget( wid );
1414   dock->toggleViewAction()->setData( QVariant( wid->objectName() ) );
1415   connect( dock->toggleViewAction(), SIGNAL( triggered( bool ) ),
1416            this, SLOT( onDockWindowVisibilityChanged( bool ) ) );
1417
1418   QKeySequence accel = wid->property( "shortcut" ).value<QKeySequence>();
1419   if ( !accel.isEmpty() )
1420     dock->toggleViewAction()->setShortcut( accel );
1421
1422   dock->show();
1423 }
1424
1425 void LightApp_Application::removeDockWindow( const int id )
1426 {
1427   QWidget* wid = dockWindow( id );
1428   if ( !wid )
1429     return;
1430
1431   myWin.remove( id );
1432
1433   QDockWidget* dock = windowDock( wid );
1434   if ( !dock )
1435     return;
1436
1437   dock->setWidget( 0 );
1438   wid->setParent( 0 );
1439   wid->setVisible( false );
1440   delete dock;
1441 }
1442
1443 void LightApp_Application::placeDockWindow( const int id, Qt::DockWidgetArea place )
1444 {
1445   QDockWidget* dock = windowDock( dockWindow( id ) );
1446   if ( dock && desktop() ) {
1447     desktop()->addDockWidget( place, dock );
1448     QtxDockAction* a = qobject_cast<QtxDockAction*>( action( ViewWindowsId ) );
1449     if ( a ) a->update();
1450   }
1451 }
1452
1453 /*!
1454   Gets window.
1455   \param flag - key for window
1456   Flag used how identificator of window in windows list.
1457 */
1458 QWidget* LightApp_Application::getWindow( const int flag)
1459 {
1460   QWidget* wid = dockWindow( flag );
1461   if ( !wid )
1462     insertDockWindow( flag, wid = createWindow( flag ) );
1463
1464   QMap<int, int> winMap;
1465   currentWindows( winMap );
1466   if ( winMap.contains( flag ) )
1467     placeDockWindow( flag, (Qt::DockWidgetArea)winMap[flag] );
1468
1469   return wid;
1470 }
1471
1472 /*!
1473   \return Object Browser
1474 */
1475 SUIT_DataBrowser* LightApp_Application::objectBrowser()
1476 {
1477   return qobject_cast<SUIT_DataBrowser*>( dockWindow( WT_ObjectBrowser ) );
1478 }
1479
1480 QtxInfoPanel* LightApp_Application::infoPanel()
1481 {
1482   return qobject_cast<QtxInfoPanel *>( dockWindow( WT_InfoPanel ));
1483 }
1484
1485 /*!
1486   \return Log Window
1487 */
1488 LogWindow* LightApp_Application::logWindow()
1489 {
1490   return qobject_cast<LogWindow*>( dockWindow( WT_LogWindow ) );
1491 }
1492
1493 #ifndef DISABLE_PYCONSOLE
1494 /*!
1495   This returns the python console integrated to the GUI. Depending
1496   when you request the python console, this function could return
1497   null. Then the optional parameter force (default to false) can be
1498   set to force the creation of the python console if it is not done
1499   already.
1500   \param force - if true, the pythonConsole is created if it does not exist yet
1501   \return Python Console
1502 */
1503 PyConsole_Console* LightApp_Application::pythonConsole(const bool force)
1504 {
1505   QWidget* wid = dockWindow( WT_PyConsole );
1506   if ( !wid && force==true) {
1507     wid = getWindow(WT_PyConsole);
1508   }
1509   return qobject_cast<PyConsole_Console*>( wid );
1510 }
1511 #endif
1512
1513 /*!
1514   Updates object browser and maybe data models
1515   \param updateModels - if it is true, then data models are updated
1516 */
1517 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1518 {
1519   // update existing data models
1520   if ( updateModels )
1521   {
1522     const bool isAutoUpdate = objectBrowser() ? objectBrowser()->autoUpdate() : true;
1523     if ( objectBrowser() )
1524       objectBrowser()->setAutoUpdate( false );
1525
1526     LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1527     if ( study ) {
1528       CAM_Study::ModelList dm_list;
1529       study->dataModels( dm_list );
1530       QListIterator<CAM_DataModel*> it( dm_list );
1531       while ( it.hasNext() ) {
1532         CAM_DataModel* camDM = it.next();
1533         if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1534           ((LightApp_DataModel*)camDM)->update();
1535       }
1536     }
1537
1538     if( objectBrowser() )
1539       objectBrowser()->setAutoUpdate( isAutoUpdate );
1540   }
1541
1542   if ( objectBrowser() ) {
1543     objectBrowser()->updateGeometry();
1544     objectBrowser()->updateTree( 0, false );
1545   }
1546 }
1547
1548 /*!
1549   \return preferences
1550 */
1551 LightApp_Preferences* LightApp_Application::preferences() const
1552 {
1553   return preferences( false );
1554 }
1555
1556 /*!
1557   \return first view manager of some type
1558   \param vmType - type of view manager
1559   \param create - is it necessary to create view manager in case, when there is no manager of such type
1560 */
1561 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1562 {
1563   SUIT_ViewManager* aVM = viewManager( vmType );
1564   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1565   MESSAGE("vmType: " << vmType.toStdString() << " aVM: " << aVM << " anActiveVM: " << anActiveVM );
1566   if ( anActiveVM && anActiveVM->getType() == vmType )
1567     {
1568       MESSAGE("aVM = anActiveVM");
1569       aVM = anActiveVM;
1570     }
1571
1572   bool keepDetached = property("keep_detached").toBool();
1573   if ( aVM && (!aVM->getDetached() || keepDetached) && create )
1574   {
1575     if ( !aVM->getActiveView() )
1576       {
1577         MESSAGE("aVM->createView()");
1578         aVM->createView();
1579       }
1580     else
1581       {
1582         MESSAGE("desktop()->setActiveWindow: " << aVM->getActiveView());
1583         desktop()->setActiveWindow( aVM->getActiveView() );
1584       }
1585   }
1586   else if ( create )
1587     {
1588       MESSAGE("aVM = createViewManager( vmType )");
1589       aVM = createViewManager( vmType );
1590     }
1591
1592   return aVM;
1593 }
1594
1595 /*!
1596   Creates view manager of some type
1597   \param vmType - type of view manager
1598 */
1599 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType, bool detached )
1600 {
1601   SUIT_ResourceMgr* resMgr = resourceMgr();
1602
1603   SUIT_ViewManager* viewMgr = 0;
1604 #ifndef DISABLE_GLVIEWER
1605   if( vmType == GLViewer_Viewer::Type() )
1606   {
1607     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1608     new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1609   }
1610 #endif
1611 #ifndef DISABLE_PLOT2DVIEWER
1612   if( vmType == Plot2d_Viewer::Type() )
1613   {
1614     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1615     Plot2d_Viewer* vm;
1616 #ifndef DISABLE_SALOMEOBJECT
1617     SPlot2d_Viewer* v = new SPlot2d_Viewer();
1618     vm = v;
1619     new LightApp_Plot2dSelector( v, mySelMgr );
1620 #else
1621     vm = new Plot2d_Viewer();
1622 #endif
1623     viewMgr->setViewModel( vm  );// custom view model, which extends SALOME_View interface
1624     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1625     if( wnd )
1626     {
1627       Plot2d_ViewFrame* frame = wnd->getViewFrame();
1628       frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1629     }
1630   }
1631 #endif
1632 #ifndef DISABLE_QXGRAPHVIEWER
1633   if( vmType == QxScene_Viewer::Type() )
1634   {
1635     viewMgr = new QxScene_ViewManager( activeStudy(), desktop() );
1636     QxScene_Viewer* vm = new QxScene_Viewer();
1637     viewMgr->setViewModel( vm  );
1638     //QxScene_ViewWindow* wnd = dynamic_cast<QxScene_ViewWindow*>( viewMgr->getActiveView() );
1639   }
1640 #endif
1641 #ifndef DISABLE_GRAPHICSVIEW
1642   if( vmType == GraphicsView_Viewer::Type() )
1643   {
1644     viewMgr = new GraphicsView_ViewManager( activeStudy(), desktop() );
1645     new LightApp_GVSelector( (GraphicsView_Viewer*)viewMgr->getViewModel(), mySelMgr );
1646   }
1647 #endif
1648 #ifndef DISABLE_PVVIEWER
1649   if( vmType == PVViewer_Viewer::Type() )
1650   {
1651     if (( viewMgr = dynamic_cast<PVViewer_ViewManager*>( getViewManager( vmType, false )))) {
1652       viewMgr->getActiveView()->setFocus();
1653       return 0;
1654     } else {
1655       viewMgr = new PVViewer_ViewManager( activeStudy(), desktop() );
1656     }
1657   }
1658 #endif
1659 #ifndef DISABLE_PYVIEWER
1660   if( vmType == PyViewer_Viewer::Type() )
1661   {
1662     viewMgr = new PyViewer_ViewManager( activeStudy(), desktop() );
1663   }
1664 #endif
1665 #ifndef DISABLE_OCCVIEWER
1666   if( vmType == OCCViewer_Viewer::Type() )
1667   {
1668     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1669     OCCViewer_Viewer* vm;
1670 #ifndef DISABLE_SALOMEOBJECT
1671     vm = new SOCC_Viewer();
1672 #else
1673     vm = new OCCViewer_Viewer( true );
1674 #endif
1675     vm->setBackground( OCCViewer_ViewFrame::TOP_LEFT,
1676                        resMgr->backgroundValue( "OCCViewer", "xz_background", vm->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
1677     vm->setBackground( OCCViewer_ViewFrame::TOP_RIGHT,
1678                        resMgr->backgroundValue( "OCCViewer", "yz_background", vm->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
1679     vm->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT,
1680                        resMgr->backgroundValue( "OCCViewer", "xy_background", vm->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
1681     vm->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
1682                        resMgr->backgroundValue( "OCCViewer", "background", vm->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
1683
1684     vm->setTrihedronSize(  resMgr->doubleValue( "3DViewer", "trihedron_size", vm->trihedronSize() ),
1685                            resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ));
1686     vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
1687     vm->setProjectionType( resMgr->integerValue( "OCCViewer", "projection_mode", vm->projectionType() ) );
1688     vm->setStereoType( resMgr->integerValue( "OCCViewer", "stereo_type", vm->stereoType() ) );
1689     vm->setAnaglyphFilter( resMgr->integerValue( "OCCViewer", "anaglyph_filter", vm->anaglyphFilter() ) );
1690     vm->setStereographicFocus( resMgr->integerValue( "OCCViewer", "focus_type", vm->stereographicFocusType() ),
1691                                resMgr->doubleValue( "OCCViewer", "focus_value", vm->stereographicFocusValue() ));
1692     vm->setInterocularDistance( resMgr->integerValue( "OCCViewer", "iod_type", vm->interocularDistanceType() ),
1693                                 resMgr->doubleValue( "OCCViewer", "iod_value", vm->interocularDistanceValue() ));
1694     vm->setSelectionStyle((OCCViewer_ViewWindow::SelectionStyle) resMgr->integerValue( "OCCViewer", "adv_selection_mode", vm->selectionStyle() ) );
1695
1696     vm->setReverseStereo( resMgr->booleanValue( "OCCViewer", "reverse_stereo", vm->isReverseStereo() ) );
1697     vm->setVSync( resMgr->booleanValue( "OCCViewer", "enable_vsync", vm->isVSync() ) );
1698     vm->setQuadBufferSupport( resMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", vm->isQuadBufferSupport() ) );
1699     vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
1700     vm->enablePreselection( resMgr->booleanValue( "OCCViewer", "enable_preselection", vm->isPreselectionEnabled() ) );
1701     vm->enableSelection(    resMgr->booleanValue( "OCCViewer", "enable_selection",    vm->isSelectionEnabled() ) );
1702     vm->setClippingColor( resMgr->colorValue( "OCCViewer", "clipping_color", vm->clippingColor() ) );
1703     vm->setClippingTextureParams( resMgr->booleanValue( "OCCViewer", "clipping_use_default_texture", vm->isDefaultTextureUsed() ),
1704                                   resMgr->stringValue( "OCCViewer", "clipping_texture", vm->clippingTexture() ),
1705                                   resMgr->booleanValue( "OCCViewer", "clipping_modulate", vm->isTextureModulated() ),
1706                                   resMgr->doubleValue( "OCCViewer", "clipping_scale", vm->clippingTextureScale() ) );
1707
1708
1709     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1710     new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1711   }
1712 #endif
1713 #ifndef DISABLE_VTKVIEWER
1714 #ifndef DISABLE_SALOMEOBJECT
1715   if ( vmType == SVTK_Viewer::Type() )
1716 #else
1717   if ( vmType == VTKViewer_Viewer::Type() )
1718 #endif
1719   {
1720 #ifndef DISABLE_SALOMEOBJECT
1721     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1722     SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1723     if( vm )
1724     {
1725       vm->setProjectionMode( resMgr->integerValue( "VTKViewer", "projection_mode", vm->projectionMode() ) );
1726       vm->setStereoType( resMgr->integerValue( "VTKViewer", "stereo_type", vm->stereoType() ) );
1727       vm->setAnaglyphFilter( resMgr->integerValue( "VTKViewer", "anaglyph_filter", vm->anaglyphFilter() ) );
1728       vm->setQuadBufferSupport( resMgr->booleanValue( "VTKViewer", "enable_quad_buffer_support", vm->isQuadBufferSupport() ) );
1729       vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) );
1730       vm->setTrihedronSize( resMgr->doubleValue( "3DViewer", "trihedron_size", vm->trihedronSize() ),
1731                             resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ) );
1732       vm->setStaticTrihedronVisible( resMgr->booleanValue( "3DViewer", "show_static_trihedron", vm->isStaticTrihedronVisible() ) );
1733       vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
1734       vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
1735       vm->setPreSelectionMode(resMgr->integerValue( "VTKViewer", "preselection", vm->preSelectionMode() ) );
1736       vm->enableSelection( resMgr->booleanValue( "VTKViewer", "enable_selection", vm->isSelectionEnabled() ) );
1737       vm->setIncrementalSpeed( resMgr->integerValue( "VTKViewer", "speed_value", vm->incrementalSpeed() ),
1738                                resMgr->integerValue( "VTKViewer", "speed_mode", vm->incrementalSpeedMode() ) );
1739       vm->setSpacemouseButtons( resMgr->integerValue( "VTKViewer", "spacemouse_func1_btn", vm->spacemouseBtn(1) ),
1740                                 resMgr->integerValue( "VTKViewer", "spacemouse_func2_btn", vm->spacemouseBtn(2) ),
1741                                 resMgr->integerValue( "VTKViewer", "spacemouse_func5_btn", vm->spacemouseBtn(3) ) );
1742       new LightApp_VTKSelector( vm, mySelMgr );
1743     }
1744 #else
1745     viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
1746     VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
1747     if ( vm )
1748       vm->setBackground( resMgr->backgroundValue( "VTKViewer", "background", vm->background() ) );
1749 #endif
1750   }
1751 #endif
1752
1753   if ( !viewMgr )
1754     return 0;
1755
1756   viewMgr->setDetached(detached);
1757   addViewManager( viewMgr );
1758   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1759
1760   if ( viewWin && desktop() ) {
1761     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1762     viewWin->setDropDownButtons( resMgr->booleanValue( "viewers", "drop_down_buttons", true ) );
1763   }
1764
1765   return viewMgr;
1766 }
1767
1768 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType, QWidget* w )
1769 {
1770   SUIT_ResourceMgr* resMgr = resourceMgr();
1771
1772   SUIT_ViewManager* vm = new SUIT_ViewManager( activeStudy(),
1773                                                desktop(),
1774                                                new LightApp_WgViewModel( vmType, w ) );
1775   vm->setTitle( QString( "%1: %M - viewer %V" ).arg( vmType ) );
1776
1777   addViewManager( vm );
1778   SUIT_ViewWindow* vw = vm->createViewWindow();
1779   if ( vw && desktop() ) {
1780     vw->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1781     vw->setDropDownButtons( resMgr->booleanValue( "viewers", "drop_down_buttons", true ) );
1782   }
1783
1784   if ( !vmType.isEmpty() && !myUserWmTypes.contains( vmType ) )
1785     myUserWmTypes << vmType;
1786
1787   return vm;
1788 }
1789
1790 SUIT_ViewManager* LightApp_Application::createViewManager( SUIT_ViewModel* theModel )
1791 {
1792   SUIT_ResourceMgr* resMgr = resourceMgr();
1793
1794   SUIT_ViewManager* vm = new SUIT_ViewManager( activeStudy(),
1795                                                desktop(),
1796                                                theModel );
1797
1798   QString vmType = vm->getType();
1799
1800   vm->setTitle( QString( "%1: %M - viewer %V" ).arg( vmType ) );
1801
1802   addViewManager( vm );
1803   SUIT_ViewWindow* vw = vm->createViewWindow();
1804   if ( vw && desktop() ) {
1805     vw->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1806     vw->setDropDownButtons( resMgr->booleanValue( "viewers", "drop_down_buttons", true ) );
1807   }
1808
1809   if ( !vmType.isEmpty() && !myUserWmTypes.contains( vmType ) )
1810     myUserWmTypes << vmType;
1811
1812   return vm;
1813 }
1814
1815 /*!
1816   SLOT: Removes view manager from application
1817 */
1818 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1819 {
1820   removeViewManager( theVM );
1821 }
1822
1823 /*!
1824   Protected SLOT: On study created.
1825   \param theStudy - just created study
1826 */
1827 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1828 {
1829   SUIT_DataObject* aRoot = 0;
1830   if ( theStudy && theStudy->root() )
1831   {
1832     aRoot = theStudy->root();
1833     //aRoot->setName( tr( "DATA_MODELS" ) );
1834   }
1835
1836   getWindow( WT_ObjectBrowser );
1837   getWindow( WT_InfoPanel );
1838
1839   loadDockWindowsState();
1840
1841   if ( objectBrowser() )
1842     objectBrowser()->setRoot( aRoot );
1843
1844   activateModule( defaultModule() );
1845
1846   if ( objectBrowser() )
1847     objectBrowser()->openLevels();
1848
1849 #ifndef DISABLE_PYCONSOLE
1850   if( pythonConsole() )
1851     getPyInterp()->initStudy();
1852 #endif
1853 }
1854
1855 /*!
1856   Protected SLOT: On study opened.
1857   \param theStudy - just opened  study
1858 */
1859 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1860 {
1861   SUIT_DataObject* aRoot = 0;
1862   if ( theStudy && theStudy->root() )
1863   {
1864     aRoot = theStudy->root();
1865     //aRoot->dump();
1866   }
1867
1868   getWindow( WT_ObjectBrowser );
1869   getWindow( WT_InfoPanel );
1870
1871   loadDockWindowsState();
1872
1873   if ( objectBrowser() )
1874     objectBrowser()->setRoot( aRoot );
1875
1876   activateModule( defaultModule() );
1877
1878   if ( objectBrowser() )
1879     objectBrowser()->openLevels();
1880
1881 #ifndef DISABLE_PYCONSOLE
1882   if( pythonConsole() )
1883     getPyInterp()->initStudy();
1884 #endif
1885
1886   emit studyOpened();
1887 }
1888
1889 /*!Protected SLOT. On study saved.*/
1890 void LightApp_Application::onStudySaved( SUIT_Study* s )
1891 {
1892   QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
1893   if ( mru && s )
1894     mru->insert( s->studyName() );
1895
1896   emit studySaved();
1897 }
1898
1899 /*!Protected SLOT. On study closed.*/
1900 void LightApp_Application::onStudyClosed( SUIT_Study* /*s*/ )
1901 {
1902   /*
1903   disconnect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),
1904               this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) );
1905   */
1906
1907   // stop auto-save timer
1908   myAutoSaveTimer->stop();
1909
1910   // Bug 10396: clear selection
1911   mySelMgr->clearSelected();
1912
1913   // Bug 12944: emit signal only after clear selection
1914   emit studyClosed();
1915
1916   activateModule( "" );
1917 }
1918
1919 /*!Protected SLOT.On desktop activated.*/
1920 void LightApp_Application::onDesktopActivated()
1921 {
1922   CAM_Application::onDesktopActivated();
1923   LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1924   if(aModule)
1925     aModule->studyActivated();
1926 }
1927
1928 void LightApp_Application::studyOpened( SUIT_Study* s )
1929 {
1930   CAM_Application::studyOpened( s );
1931
1932   updateWindows();
1933   updateViewManagers();
1934 }
1935
1936 void LightApp_Application::studySaved( SUIT_Study* s )
1937 {
1938   CAM_Application::studyOpened( s );
1939   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1940   if ( aResMgr && activeStudy() ) {
1941     int autoSaveInterval = aResMgr->integerValue( "Study", "auto_save_interval", 0 );
1942     if ( autoSaveInterval > 0 ) myAutoSaveTimer->start( autoSaveInterval*60000 );
1943   }
1944 }
1945
1946 void LightApp_Application::studyCreated( SUIT_Study* s )
1947 {
1948   CAM_Application::studyCreated( s );
1949
1950   updateWindows();
1951   updateViewManagers();
1952 }
1953
1954 /*!Gets file filter.
1955  *\retval QString "(*.hdf)"
1956  */
1957 QString LightApp_Application::getFileFilter( bool /*open*/) const
1958 {
1959   return "(*.hdf)";
1960 }
1961
1962 /*!
1963   Shows file dialog and return user selected file name
1964 */
1965 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1966                                            const QString& caption, QWidget* parent )
1967 {
1968   if ( !parent )
1969     parent = desktop();
1970   QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
1971   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1972 }
1973
1974 /*! Gets directory*/
1975 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1976 {
1977   if ( !parent )
1978     parent = desktop();
1979   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1980 }
1981
1982 /*! Get open file names*/
1983 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1984                                                     const QString& caption, QWidget* parent )
1985 {
1986   if ( !parent )
1987     parent = desktop();
1988   QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
1989   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1990 }
1991
1992 /*!Private SLOT. Update object browser.*/
1993 void LightApp_Application::onRefresh()
1994 {
1995   updateObjectBrowser( true );
1996 }
1997
1998 /*!Private SLOT. Update actions after rename object.*/
1999 void LightApp_Application::onRenamed()
2000 {
2001   activeStudy()->Modified();
2002   updateActions();
2003 }
2004
2005 // IMN 08.07.2015 : issue 002556: Some stereo outputs are affected by window position.
2006 // To prevent reversion the window should be either aligned during movement and resize.
2007 /*!Private SLOT. Update actions after rename object.*/
2008 /*void LightApp_Application::onMoved()
2009 {
2010   OCCViewer_ViewManager* viewMgr = 0;
2011   viewMgr = dynamic_cast<OCCViewer_ViewManager*>( getViewManager( OCCViewer_Viewer::Type(), false ) );
2012   if (viewMgr) {
2013     OCCViewer_ViewWindow* view = 0;
2014     view = dynamic_cast<OCCViewer_ViewWindow*>( viewMgr->getActiveView() );
2015     if (view) {
2016       view->getViewPort()->repaintViewAfterMove();
2017     }
2018   }
2019 }
2020 */
2021 /*!Private SLOT. Support drag-and-drop operation.*/
2022 void LightApp_Application::onDropped( const QList<SUIT_DataObject*>& objects, SUIT_DataObject* parent, int row, Qt::DropAction action )
2023 {
2024   LightApp_DataObject* parentObj = dynamic_cast<LightApp_DataObject*>( parent );
2025   if ( !parentObj )
2026     return;
2027
2028   LightApp_Module* aModule = dynamic_cast<LightApp_Module*>( parentObj->module() );
2029   if ( aModule )
2030     aModule->dropObjects( objects, parentObj, row, action );
2031 }
2032
2033 /*!Private SLOT. On preferences.*/
2034 void LightApp_Application::onPreferences()
2035 {
2036   showPreferences( activeModule() ? activeModule()->moduleName() : tr( "PREF_CATEGORY_SALOME" ) );
2037 }
2038
2039 /*!Private SLOT. On preferences.*/
2040 void LightApp_Application::showPreferences( const QString& path )
2041 {
2042   showPreferences( QStringList() << path );
2043 }
2044
2045 void LightApp_Application::showPreferences( const QStringList& path )
2046 {
2047   QApplication::setOverrideCursor( Qt::WaitCursor );
2048
2049   LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
2050
2051   QApplication::restoreOverrideCursor();
2052
2053   if ( !prefDlg )
2054     return;
2055
2056   preferences()->activateItem( path );
2057
2058   if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) &&  resourceMgr() )
2059   {
2060     if ( desktop() )
2061       resourceMgr()->setValue( "desktop", "geometry", desktop()->storeGeometry() );
2062     resourceMgr()->save();
2063
2064     // Update shortcuts
2065     shortcutMgr()->updateShortcuts();
2066   }
2067
2068   delete prefDlg;
2069 }
2070
2071 /*!Protected SLOT. On preferences changed.*/
2072 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
2073 {
2074   LightApp_Module* sMod = 0;
2075   CAM_Module* mod = module( modName );
2076   if ( mod && mod->inherits( "LightApp_Module" ) )
2077     sMod = (LightApp_Module*)mod;
2078
2079   if ( sMod )
2080     sMod->preferencesChanged( section, param );
2081   else
2082     preferencesChanged( section, param );
2083   // emit signal to allow additional preferences changing processing
2084   emit preferenceChanged( modName, section, param );
2085 }
2086
2087 /*!Remove all windows from study.*/
2088 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
2089 {
2090   saveDockWindowsState();
2091
2092   if ( SUIT_DataBrowser* ob = objectBrowser() )
2093     ob->setModel(0);
2094
2095   CAM_Application::beforeCloseDoc( s );
2096 }
2097
2098 /*!Update actions.*/
2099 void LightApp_Application::updateActions()
2100 {
2101   updateCommandsStatus();
2102 }
2103
2104 /*!
2105   Creates new study
2106 */
2107 SUIT_Study* LightApp_Application::createNewStudy()
2108 {
2109   LightApp_Study* aStudy = new LightApp_Study( this );
2110
2111   // Set up processing of major study-related events
2112   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
2113   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
2114   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
2115   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
2116
2117   return aStudy;
2118 }
2119
2120 /*!
2121   Creates window by flag.
2122   \param flag - identificator of window type
2123 */
2124 QWidget* LightApp_Application::createWindow( const int flag )
2125 {
2126   QWidget* wid = 0;
2127
2128   SUIT_ResourceMgr* resMgr = resourceMgr();
2129
2130   if ( flag == WT_ObjectBrowser )
2131   {
2132     SUIT_DataBrowser* ob = new SUIT_DataBrowser( new LightApp_DataObject(), desktop() );
2133     ob->setObjectName( "objectBrowser" );
2134     ob->setSortMenuEnabled( true );
2135     ob->setAutoUpdate( true );
2136     if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) )
2137       ob->searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
2138
2139     //ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107
2140     ob->setWindowTitle( tr( "OBJECT_BROWSER" ) );
2141     connect( ob, SIGNAL( requestUpdate() ), this, SLOT( onRefresh() ) );
2142
2143     QString EntryCol = QObject::tr( "ENTRY_COLUMN" );
2144     SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );
2145     treeModel->setSearcher( this );
2146     treeModel->registerColumn( 0, EntryCol, LightApp_DataObject::EntryId );
2147     treeModel->setAppropriate( EntryCol, Qtx::Toggled );
2148
2149     // Mantis issue 0020136: Drag&Drop in OB
2150     SUIT_ProxyModel* proxyModel = dynamic_cast<SUIT_ProxyModel*>(treeModel);
2151     if ( proxyModel ) {
2152       connect( proxyModel, SIGNAL( dropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ),
2153                this,       SLOT( onDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction ) ) );
2154       connect( proxyModel, SIGNAL( renamed( SUIT_DataObject* ) ),
2155                this,       SLOT( onRenamed( ) ) );
2156
2157     }
2158
2159     // temporary commented
2160     /*
2161     OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
2162     if( ob_list )
2163       ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
2164     */
2165
2166     // Create OBSelector
2167     new LightApp_OBSelector( ob, mySelMgr );
2168     ob->treeView()->header()->setSectionResizeMode(SUIT_DataObject::VisibilityId, QHeaderView::Fixed);
2169     ob->treeView()->header()->moveSection(SUIT_DataObject::NameId,SUIT_DataObject::VisibilityId);
2170     ob->treeView()->setColumnWidth(SUIT_DataObject::VisibilityId, VISIBILITY_COLUMN_WIDTH);
2171     ob->setProperty( "shortcut", QKeySequence( "Alt+Shift+O" ) );
2172     wid = ob;
2173     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
2174   }
2175   else if ( flag == WT_InfoPanel)
2176   {
2177     QtxInfoPanel* ipanel = new QtxInfoPanel( desktop() );
2178     ipanel->setObjectName( "infoPanel" );
2179     ipanel->setWindowTitle( tr( "INFO_PANEL" ) );
2180     wid = ipanel;
2181   }
2182 #ifndef DISABLE_PYCONSOLE
2183   else  if ( flag == WT_PyConsole )
2184   {
2185     PyConsole_Console* pyCons = new PyConsole_Console( desktop(), new LightApp_PyEditor( getPyInterp() ) );
2186     pyCons->setObjectName( "pythonConsole" );
2187     pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) );
2188     pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
2189     pyCons->setIsShowBanner( resMgr->booleanValue( "PyConsole", "show_banner", true ) );
2190     pyCons->setAutoCompletion( resMgr->booleanValue( "PyConsole", "auto_completion", true ) );
2191     pyCons->setProperty( "shortcut", QKeySequence( "Alt+Shift+P" ) );
2192     wid = pyCons;
2193   }
2194 #endif
2195   else if ( flag == WT_LogWindow )
2196   {
2197     LogWindow* logWin = new LogWindow( desktop() );
2198     logWin->handleQtMessages( true );
2199     logWin->setObjectName( "logWindow" );
2200     logWin->setWindowTitle( tr( "LOG_WINDOW" ) );
2201     logWin->setProperty( "shortcut", QKeySequence( "Alt+Shift+L" ) );
2202     wid = logWin;
2203     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
2204   }
2205   return wid;
2206 }
2207
2208 /*!
2209   \return default windows( Object Browser, Python Console )
2210   Adds to map \a aMap.
2211  */
2212 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
2213 {
2214 #ifndef DISABLE_PYCONSOLE
2215   aMap.insert( WT_PyConsole, Qt::BottomDockWidgetArea );
2216 #endif
2217   if ( activeStudy() ) {
2218     aMap.insert( WT_ObjectBrowser, Qt::LeftDockWidgetArea );
2219     aMap.insert( WT_InfoPanel, Qt::RightDockWidgetArea );
2220     //  aMap.insert( WT_LogWindow, Qt::DockBottom );
2221   }
2222 }
2223
2224 /*!Default view managers*/
2225 void LightApp_Application::defaultViewManagers( QStringList& ) const
2226 {
2227   /*!Do nothing.*/
2228 }
2229
2230 /*!
2231   \return preferences.
2232   Create preferences, if \a crt = true.
2233 */
2234 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
2235 {
2236   if ( myPrefs )
2237     return myPrefs;
2238
2239   LightApp_Application* that = (LightApp_Application*)this;
2240
2241   bool toCreate = !_prefs_ && crt;
2242   if ( toCreate )
2243   {
2244     _prefs_ = new LightApp_Preferences( resourceMgr() );
2245     that->createPreferences( _prefs_ );
2246     qAddPostRoutine( LightAppCleanUpAppResources );
2247   }
2248
2249   that->myPrefs = _prefs_;
2250
2251   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
2252            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ), Qt::UniqueConnection );
2253   connect( myPrefs, SIGNAL( resetToDefaults() ),
2254            this, SIGNAL( preferenceResetToDefaults() ), Qt::UniqueConnection );
2255
2256   if ( !crt )
2257     return myPrefs;
2258
2259   SUIT_ResourceMgr* resMgr = resourceMgr();
2260
2261   QList<SUIT_Application*> appList = SUIT_Session::session()->applications();
2262   for ( QList<SUIT_Application*>::iterator appIt = appList.begin(); appIt != appList.end(); ++appIt )
2263   {
2264     LightApp_Application* app = ::qobject_cast<LightApp_Application*>( *appIt );
2265     if ( !app )
2266       continue;
2267
2268     // all modules available in current session
2269     QStringList names;
2270     app->modules( names, false );
2271
2272     // icons of modules
2273     QMap<QString, QString> icons;
2274     app->moduleIconNames( icons );
2275
2276     // step 1: iterate through list of all available modules
2277     // and add empty preferences page
2278     for ( QStringList::const_iterator it = names.begin(); it != names.end(); ++it )
2279     {
2280       if ( !_prefs_->hasModule( *it ) ) // prevent possible duplications
2281       {
2282         int modId = _prefs_->addPreference( *it ); // add empty page
2283         if ( icons.contains( *it ) )               // set icon
2284           _prefs_->setItemIcon( modId, Qtx::scaleIcon( resMgr->loadPixmap( moduleName( *it ),
2285                                                                            icons[*it], false ), 20 ) );
2286       }
2287     }
2288
2289     // step 2: iterate through list of all loaded modules
2290     // and initialize their preferences
2291     ModuleList loadedModules;
2292     app->modules( loadedModules );
2293     QListIterator<CAM_Module*> itr( loadedModules );
2294     while ( itr.hasNext() )
2295     {
2296       LightApp_Module* module = 0;
2297       CAM_Module* m = itr.next();
2298       if ( m->inherits( "LightApp_Module" ) )
2299         module = (LightApp_Module*)m;
2300
2301       if ( module && !_prefs_->hasModule( module->moduleName() ) )
2302       {
2303         _prefs_->addPreference( module->moduleName() ); // add page (for sure, had to be done at step 1)
2304         module->createPreferences();                    // initialize preferences
2305         that->emptyPreferences( module->moduleName() ); // show dummy page if module does not export any preferences
2306       }
2307     }
2308   }
2309   _prefs_->setItemProperty( "info", tr( "PREFERENCES_NOT_LOADED" ) ); // dummy page for modules which are not loaded yet
2310
2311   return myPrefs;
2312 }
2313
2314 /*!
2315   Adds new module to application
2316 */
2317 void LightApp_Application::moduleAdded( CAM_Module* mod )
2318 {
2319   CAM_Application::moduleAdded( mod );
2320
2321   LightApp_Module* lightMod = 0;
2322   if ( mod && mod->inherits( "LightApp_Module" ) )
2323     lightMod = (LightApp_Module*)mod;
2324
2325   if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
2326   {
2327     myPrefs->addPreference( mod->moduleName() );
2328     lightMod->createPreferences();
2329     emptyPreferences( mod->moduleName() );
2330   }
2331 }
2332
2333 void LightApp_Application::moduleDeactivated( CAM_Module* /*mod*/ )
2334 {
2335   if ( infoPanel() )
2336     infoPanel()->clear();
2337 }
2338
2339 void LightApp_Application::emptyPreferences( const QString& modName )
2340 {
2341   QtxPreferenceItem* item = myPrefs->findItem( modName, true );
2342   if ( !item || !item->isEmpty() )
2343     return;
2344
2345   QtxPagePrefFrameItem* frm = new QtxPagePrefFrameItem( item->title(), item->parentItem() );
2346   frm->setIcon( item->icon() );
2347   frm->setStretch( false );
2348   item->parentItem()->insertItem( frm, item );
2349   new QtxPagePrefLabelItem( Qt::AlignCenter, tr( "PREFERENCES_NOT_SUPPORTED" ).arg( modName ), frm );
2350   delete item;
2351 }
2352
2353 /*!
2354   Create preferences
2355 */
2356 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
2357 {
2358   if ( !pref )
2359     return;
2360
2361   QStringList     aValuesList;
2362   QList<QVariant> anIndicesList;
2363   QIntList        idList;
2364   QIntList        txtList;
2365
2366   // . Top-level "SALOME" preferences group <<start>>
2367   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
2368   pref->setItemIcon( salomeCat, Qtx::scaleIcon( resourceMgr()->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ), 20 ) );
2369
2370   // .. "General" preferences tab <<start>>
2371   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
2372
2373   // ... "Language" group <<start>>
2374   int langGroup = pref->addPreference( tr( "PREF_GROUP_LANGUAGE" ), genTab );
2375   pref->setItemProperty( "columns", 2, langGroup );
2376   // .... -> application language
2377   int curLang = pref->addPreference( tr( "PREF_CURRENT_LANGUAGE" ), langGroup,
2378                                           LightApp_Preferences::Selector, "language", "language" );
2379   QStringList aLangs = SUIT_Session::session()->resourceMgr()->stringValue( "language", "languages", "en" ).split( "," );
2380   QList<QVariant> aIcons;
2381   QList<QVariant> aNumbers;
2382   QStringList aTitles;
2383   foreach ( QString aLang, aLangs ) {
2384     aIcons << QPixmap( QString( ":/images/%1" ).arg( aLang ) );
2385     aNumbers << aLang;
2386     aTitles << langToName( aLang );
2387   }
2388   pref->setItemProperty( "strings", aTitles, curLang );
2389   pref->setItemProperty( "ids",     aNumbers, curLang );
2390   pref->setItemProperty( "icons",   aIcons, curLang );
2391   pref->setItemProperty( "restart",  true, curLang );
2392
2393   int curLocale = pref->addPreference( tr( "PREF_CURRENT_LOCALE" ), langGroup,
2394                                           LightApp_Preferences::Bool, "language", "locale" );
2395   pref->setItemProperty( "restart",  true, curLocale );
2396   // ... "Language" group <<end>>
2397
2398   // ... "Look and feel" group <<start>>
2399   int lookGroup = pref->addPreference( tr( "PREF_GROUP_LOOK_AND_FEEL" ), genTab );
2400   pref->setItemProperty( "columns", 2, lookGroup );
2401   // .... -> show splash-screen
2402   pref->addPreference( tr( "PREF_SHOW_SPLASH" ), lookGroup, LightApp_Preferences::Bool, "launch", "splash" );
2403   // .... -> opaque resize
2404   pref->addPreference( tr( "PREF_OPAQUE_RESIZE" ), lookGroup, LightApp_Preferences::Bool, "desktop", "opaque_resize" );
2405   // .... -> drop-down buttons
2406   pref->addPreference( tr( "PREF_DROP_DOWN_BUTTONS" ), lookGroup, LightApp_Preferences::Bool, "viewers", "drop_down_buttons" );
2407   // .... -> Notification timeout
2408   int delay = pref->addPreference( tr( "PREF_NOTIFY_TIMEOUT" ), lookGroup, LightApp_Preferences::IntSpin, "notification", "timeout" );
2409   pref->setItemProperty( "special", tr("PREF_NOTIFY_TIMEOUT_NONE"), delay );
2410   pref->setItemProperty( "min", 0, delay );
2411   pref->setItemProperty( "max", 100, delay );
2412   pref->setItemProperty( "suffix", " sec", delay );
2413   // ... "Look and feel" group <<end>>
2414
2415   // ... "Study properties" group <<start>>
2416   int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
2417   pref->setItemProperty( "columns", 2, studyGroup );
2418   // .... -> multi-file save
2419   pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
2420   // .... -> ascii save mode
2421   pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
2422   // .... -> store windows geometry
2423   pref->addPreference( tr( "PREF_LOAD_LIGHT" ), studyGroup, LightApp_Preferences::Bool, "Study", "autoload_light_modules" );
2424   pref->addPreference( tr( "PREF_STORE_POS" ),  studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
2425   pref->addPreference( "", studyGroup, LightApp_Preferences::Space );
2426   pref->addPreference( tr( "PREF_STORE_TOOL_POS" ),  studyGroup, LightApp_Preferences::Bool, "Study", "store_tool_positions" );
2427   // .... -> auto-save
2428   int autoSaveInterval = pref->addPreference( tr( "PREF_AUTO_SAVE" ),  studyGroup,
2429                                               LightApp_Preferences::IntSpin, "Study", "auto_save_interval" );
2430   pref->setItemProperty( "min",        0, autoSaveInterval );
2431   pref->setItemProperty( "max",     1440, autoSaveInterval );
2432   pref->setItemProperty( "special", tr( "PREF_AUTO_SAVE_DISABLED" ), autoSaveInterval );
2433   // ... "Study properties" group <<end>>
2434
2435   // ... "Help browser" group <<start>>
2436 #ifndef DISABLE_QTXWEBBROWSER
2437   int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab, LightApp_Preferences::Auto, "ExternalBrowser", "use_external_browser");
2438 #else
2439   int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
2440 #endif
2441
2442 #ifdef WIN32
2443   QString platform = "winapplication";
2444 #else
2445   QString platform = "application";
2446 #endif
2447   // .... -> browser application
2448   int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", platform );
2449   pref->setItemProperty( "mode", Qtx::PT_OpenFile, apppref );
2450   // .... -> browser parameters
2451   pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
2452   // ... "Help browser" group <<end>>
2453
2454   // ... "Python console properties" group <<start>>
2455   int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
2456   pref->setItemProperty( "columns", 2, pythonConsoleGroup );
2457   // .... -> font
2458   pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
2459   // .... -> show banner
2460   pref->addPreference( tr( "PREF_SHOW_BANNER" ), pythonConsoleGroup, LightApp_Preferences::Bool, "PyConsole", "show_banner" );
2461   // .... -> auto-completion
2462   pref->addPreference( tr( "PREF_AUTO_COMPLETION" ), pythonConsoleGroup, LightApp_Preferences::Bool, "PyConsole", "auto_completion" );
2463   // ... "Python console properties" group <<end>>
2464
2465   // ... "MRU" preferences group <<start>>
2466   int mruGroup = pref->addPreference( tr( "PREF_GROUP_MRU" ), genTab, LightApp_Preferences::Auto, "MRU", "show_mru" );
2467   pref->setItemProperty( "columns", 4, mruGroup );
2468   // number of MRU items
2469   int mruVisCount = pref->addPreference( tr( "PREF_MRU_VISIBLE_COUNT" ), mruGroup, LightApp_Preferences::IntSpin,
2470                                          "MRU", "visible_count" );
2471   pref->setItemProperty( "min", 0,   mruVisCount );
2472   pref->setItemProperty( "max", 100, mruVisCount );
2473   // MRU links type
2474   int mruLinkType = pref->addPreference( tr( "PREF_MRU_LINK_TYPE" ), mruGroup, LightApp_Preferences::Selector,
2475                                          "MRU", "link_type" );
2476   aValuesList.clear();
2477   anIndicesList.clear();
2478   aValuesList   << tr("PREF_MRU_LINK_AUTO") << tr("PREF_MRU_LINK_SHORT") << tr("PREF_MRU_LINK_FULL");
2479   anIndicesList << 0                        << 1                         << 2                       ;
2480   pref->setItemProperty( "strings", aValuesList,   mruLinkType );
2481   pref->setItemProperty( "indexes", anIndicesList, mruLinkType );
2482   // ... "MRU" preferences group <<end>>
2483
2484   // ... "Full-screen" group <<start>>
2485   int fullScreenGroup = pref->addPreference( tr( "PREF_GROUP_FULL_SCREEN" ), genTab );
2486   pref->setItemProperty( "columns", 2, fullScreenGroup );
2487   // .... -> automatic hiding toolbars
2488   pref->addPreference( tr( "PREF_FULL_SCREEN_AUTO" ), fullScreenGroup,
2489                        LightApp_Preferences::Bool, "OCCViewer", "automatic_hiding" );
2490   // ... "Full-screen" group <<end>>
2491
2492   // .. "General" preferences tab <<end>>
2493
2494   // .. "3D viewer" group <<start>>
2495   int Viewer3DGroup = pref->addPreference( tr( "PREF_GROUP_3DVIEWER" ), salomeCat );
2496   // ... -> navigation mode
2497   int vtkStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), Viewer3DGroup,
2498                                           LightApp_Preferences::Selector, "3DViewer", "navigation_mode" );
2499   aValuesList.clear();
2500   anIndicesList.clear();
2501   aValuesList   << tr("PREF_STANDARD_STYLE") << tr("PREF_KEYFREE_STYLE");
2502   anIndicesList << 0                         << 1;
2503   pref->setItemProperty( "strings", aValuesList,   vtkStyleMode );
2504   pref->setItemProperty( "indexes", anIndicesList, vtkStyleMode );
2505   // ... -> zooming mode
2506   int occZoomingStyleMode = pref->addPreference( tr( "PREF_ZOOMING" ), Viewer3DGroup,
2507                                                  LightApp_Preferences::Selector, "3DViewer", "zooming_mode" );
2508   aValuesList.clear();
2509   anIndicesList.clear();
2510   aValuesList   << tr("PREF_ZOOMING_AT_CENTER") << tr("PREF_ZOOMING_AT_CURSOR");
2511   anIndicesList << 0                            << 1;
2512   pref->setItemProperty( "strings", aValuesList,   occZoomingStyleMode );
2513   pref->setItemProperty( "indexes", anIndicesList, occZoomingStyleMode );
2514   // ... "Trihedron" group <<start>>
2515   int occTriGroup = pref->addPreference( tr( "PREF_TRIHEDRON" ), Viewer3DGroup );
2516   pref->setItemProperty( "columns", 2, occTriGroup );
2517   // .... -> trihedron size
2518   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occTriGroup,
2519                                    LightApp_Preferences::DblSpin, "3DViewer", "trihedron_size" );
2520   pref->setItemProperty( "min", 1.0E-06, occTS );
2521   pref->setItemProperty( "max", 1000, occTS );
2522   // .... -> relative size of trihedron
2523   pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "relative_size" );
2524   // .... -> show static trihedron
2525   pref->addPreference( tr( "PREF_SHOW_STATIC_TRIHEDRON" ), occTriGroup, LightApp_Preferences::Bool, "3DViewer", "show_static_trihedron" );
2526   // ... "Trihedron" group <<end>>
2527   // .. "3D viewer" group <<end>>
2528
2529   QString formats;
2530   int bgId;
2531 #ifndef DISABLE_OCCVIEWER
2532   // .. "OCC viewer" group <<start>>
2533   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), salomeCat );
2534
2535   // .... -> Projection mode
2536   int occProjMode = pref->addPreference( tr( "PREF_PROJECTION_MODE" ), occGroup,
2537                                          LightApp_Preferences::Selector, "OCCViewer", "projection_mode" );
2538   aValuesList.clear();
2539   anIndicesList.clear();
2540   aValuesList   << tr("PREF_ORTHOGRAPHIC") << tr("PREF_PERSPECTIVE");
2541   anIndicesList << 0                       << 1;
2542   pref->setItemProperty( "strings", aValuesList,   occProjMode );
2543   pref->setItemProperty( "indexes", anIndicesList, occProjMode );
2544
2545   // .... -> Stereo group
2546   int stereoGroup = pref->addPreference( tr( "PREF_GROUP_STEREO" ), occGroup);
2547   pref->setItemProperty( "columns", 2, stereoGroup );
2548   // .... -> Stereo type
2549   int stereoType = pref->addPreference( tr( "PREF_STEREO_TYPE" ), stereoGroup,
2550                                             LightApp_Preferences::Selector, "OCCViewer", "stereo_type" );
2551   aValuesList.clear();
2552   anIndicesList.clear();
2553   idList.clear();
2554   OCCViewer_Viewer::stereoData( aValuesList, idList);
2555   foreach( int gid, idList ) anIndicesList << gid;
2556   pref->setItemProperty( "strings", aValuesList,   stereoType );
2557   pref->setItemProperty( "indexes", anIndicesList, stereoType );
2558
2559   // .... -> Anaglyph filter
2560   int anaglyphFilter = pref->addPreference( tr( "PREF_ANAGLYPH_FILTER" ), stereoGroup,
2561                                             LightApp_Preferences::Selector, "OCCViewer", "anaglyph_filter" );
2562   aValuesList.clear();
2563   anIndicesList.clear();
2564   aValuesList   << tr("PREF_ANAGLYPH_RED_CYAN") << tr("PREF_ANAGLYPH_YELLOW_BLUE") << tr("PREF_ANAGLYPH_GREEN_MAGENTA");
2565   anIndicesList << 0                            << 1                               << 2;
2566
2567   pref->setItemProperty( "strings", aValuesList,   anaglyphFilter );
2568   pref->setItemProperty( "indexes", anIndicesList, anaglyphFilter );
2569
2570   // .... -> Convergence distance type
2571   int occFocusType = pref->addPreference( tr( "PREF_FOCUS_TYPE" ), stereoGroup,
2572                                            LightApp_Preferences::Selector, "OCCViewer", "focus_type" );
2573   aValuesList.clear();
2574   anIndicesList.clear();
2575   aValuesList   << tr("PREF_ABSOLUTE") << tr("PREF_RELATIVE");
2576   anIndicesList << 0                   << 1;
2577   pref->setItemProperty( "strings", aValuesList,   occFocusType );
2578   pref->setItemProperty( "indexes", anIndicesList, occFocusType );
2579
2580   // .... -> Stereographic focus value
2581   int focusValue = pref->addPreference( tr( "PREF_FOCUS_VALUE" ), stereoGroup,
2582                LightApp_Preferences::DblSpin, "OCCViewer", "focus_value" );
2583   pref->setItemProperty( "precision", 3, focusValue );
2584   pref->setItemProperty( "min", 1.0E-03, focusValue );
2585   pref->setItemProperty( "max", 1.0E03, focusValue );
2586   pref->setItemProperty( "step", 0.05, focusValue );
2587
2588   // .... -> IOD type
2589   int occIODType = pref->addPreference( tr( "PREF_IOD_TYPE" ), stereoGroup,
2590                                            LightApp_Preferences::Selector, "OCCViewer", "iod_type" );
2591   aValuesList.clear();
2592   anIndicesList.clear();
2593   aValuesList   << tr("PREF_ABSOLUTE") << tr("PREF_RELATIVE");
2594   anIndicesList << 0                   << 1;
2595   pref->setItemProperty( "strings", aValuesList,   occIODType );
2596   pref->setItemProperty( "indexes", anIndicesList, occIODType );
2597
2598   // .... -> Interocular distance (IOD) value
2599   int IODValue = pref->addPreference( tr( "PREF_IOD_VALUE" ), stereoGroup,
2600                                       LightApp_Preferences::DblSpin, "OCCViewer", "iod_value" );
2601   pref->setItemProperty( "precision", 3, IODValue );
2602   pref->setItemProperty( "min", 1.0E-03, IODValue );
2603   pref->setItemProperty( "max", 1.0E03, IODValue );
2604   pref->setItemProperty( "step", 0.05, IODValue );
2605
2606   // .... -> Reverse stereo
2607   pref->addPreference( tr( "PREF_REVERSE_STEREO" ), stereoGroup,
2608                        LightApp_Preferences::Bool, "OCCViewer", "reverse_stereo" );
2609   // .... -> Enable V-Sync
2610   pref->addPreference( tr( "PREF_ENABLE_VSYNC" ), stereoGroup,
2611                        LightApp_Preferences::Bool, "OCCViewer", "enable_vsync" );
2612   // .... -> Enable quad-buffer support
2613   pref->addPreference( tr( "PREF_ENABLE_QUAD_BUFFER_SUPPORT" ), stereoGroup,
2614                        LightApp_Preferences::Bool, "OCCViewer", "enable_quad_buffer_support" );
2615
2616   // ... "Background" group <<start>>
2617   int bgGroup = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup );
2618   //  pref->setItemProperty( "columns", 2, bgGroup );
2619   aValuesList.clear();
2620   anIndicesList.clear();
2621   txtList.clear();
2622   idList.clear();
2623   formats = OCCViewer_Viewer::backgroundData( aValuesList, idList, txtList );
2624   foreach( int gid, idList ) anIndicesList << gid;
2625   // .... -> 3D viewer background
2626   bgId = pref->addPreference( tr( "PREF_3DVIEWER_BACKGROUND" ), bgGroup,
2627                                   LightApp_Preferences::Background, "OCCViewer", "background" );
2628   pref->setItemProperty( "gradient_names", aValuesList, bgId );
2629   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2630   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2631   pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2632   pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2633   pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2634   pref->setItemProperty( "custom_enabled", false, bgId );
2635   pref->setItemProperty( "image_formats", formats, bgId );
2636   // .... -> XZ viewer background
2637   bgId = pref->addPreference( tr( "PREF_XZVIEWER_BACKGROUND" ), bgGroup,
2638                               LightApp_Preferences::Background, "OCCViewer", "xz_background" );
2639   pref->setItemProperty( "gradient_names", aValuesList, bgId );
2640   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2641   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2642   pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2643   pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2644   pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2645   pref->setItemProperty( "custom_enabled", false, bgId );
2646   pref->setItemProperty( "image_formats", formats, bgId );
2647   // .... -> YZ viewer background
2648   bgId = pref->addPreference( tr( "PREF_YZVIEWER_BACKGROUND" ), bgGroup,
2649                               LightApp_Preferences::Background, "OCCViewer", "yz_background" );
2650   pref->setItemProperty( "gradient_names", aValuesList, bgId );
2651   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2652   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2653   pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2654   pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2655   pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2656   pref->setItemProperty( "custom_enabled", false, bgId );
2657   pref->setItemProperty( "image_formats", formats, bgId );
2658   // .... -> XY viewer background
2659   bgId = pref->addPreference( tr( "PREF_XYVIEWER_BACKGROUND" ), bgGroup,
2660                               LightApp_Preferences::Background, "OCCViewer", "xy_background" );
2661   pref->setItemProperty( "gradient_names", aValuesList, bgId );
2662   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2663   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2664   pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2665   pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2666   pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2667   pref->setItemProperty( "custom_enabled", false, bgId );
2668   pref->setItemProperty( "image_formats", formats, bgId );
2669   // ... "Background" group <<end>>
2670
2671
2672   // ... "Selection" group <<start>>
2673   int occSelectionGroup = pref->addPreference( tr( "PREF_GROUP_SELECTION" ), occGroup );
2674   pref->setItemProperty( "columns", 3, occSelectionGroup );
2675   // .... -> enable preselection
2676   pref->addPreference( tr( "PREF_ENABLE_PRESELECTION" ), occSelectionGroup,
2677                        LightApp_Preferences::Bool, "OCCViewer", "enable_preselection" );
2678   // .... -> enable selection
2679   pref->addPreference( tr( "PREF_ENABLE_SELECTION" ), occSelectionGroup,
2680                        LightApp_Preferences::Bool, "OCCViewer", "enable_selection" );
2681   // .... -> selection style
2682   int aSeleStyle = pref->addPreference( tr( "PREF_SELECTION_STYLE" ), occSelectionGroup,
2683                        LightApp_Preferences::Selector, "OCCViewer", "adv_selection_mode" );
2684   aValuesList.clear();
2685   anIndicesList.clear();
2686   aValuesList   << tr("PREF_POLYGON_SELECTION") << tr("PREF_CIRCLE_SELECTION");
2687   anIndicesList << 0 << 1;
2688   pref->setItemProperty( "strings", aValuesList, aSeleStyle);
2689   pref->setItemProperty( "indexes", anIndicesList, aSeleStyle);
2690   // ... "Selection" group <<end>>
2691
2692   // ... "Clipping" group <<start>>
2693   int occClippingGroup = pref->addPreference( tr( "PREF_GROUP_CLIPPING" ), occGroup );
2694   // .... -> clipping color
2695   pref->addPreference( tr( "PREF_CLIPPING_COLOR" ), occClippingGroup,
2696                        LightApp_Preferences::Color, "OCCViewer", "clipping_color" );
2697   int texturePref = pref->addPreference( "", occClippingGroup, LightApp_Preferences::Frame );
2698   pref->setItemProperty( "columns", 2, texturePref );
2699   // .... -> use default texture
2700   pref->addPreference( tr( "PREF_CLIPPING_DEFAULT_TEXTURE" ), texturePref,
2701                LightApp_Preferences::Bool, "OCCViewer", "clipping_use_default_texture" );
2702   // .... -> clipping texture
2703   int filePref = pref->addPreference( tr( "PREF_CLIPPING_TEXTURE" ), texturePref,
2704                LightApp_Preferences::File, "OCCViewer", "clipping_texture" );
2705   pref->setItemProperty( "path_filter", tr( "OCC_TEXTURE_FILES" ), filePref );
2706   // .... -> modulate
2707   pref->addPreference( tr( "PREF_CLIPPING_MODULATE" ), texturePref,
2708                LightApp_Preferences::Bool, "OCCViewer", "clipping_modulate" );
2709   // .... -> scale factor
2710   int scaleFactor = pref->addPreference( tr( "PREF_CLIPPING_SCALE" ), texturePref,
2711                LightApp_Preferences::DblSpin, "OCCViewer", "clipping_scale" );
2712   pref->setItemProperty( "precision", 3, scaleFactor );
2713   pref->setItemProperty( "min", 1.0E-03, scaleFactor );
2714   pref->setItemProperty( "max", 1.0E03, scaleFactor );
2715   pref->setItemProperty( "step", 0.1, scaleFactor );
2716   // ... "Clipping" group <<end>>
2717
2718   // ... "Ray tracing" group <<start>>
2719   int occRayTracingGroup = pref->addPreference( tr( "PREF_GROUP_RAY_TRACING" ), occGroup );
2720   int rtPref = pref->addPreference( "", occRayTracingGroup, LightApp_Preferences::Frame );
2721   pref->setItemProperty( "columns", 2, rtPref );
2722   // .... -> depth
2723   int rt_depth = pref->addPreference( tr( "PREF_RAY_TRACING_DEPTH" ), rtPref,
2724                LightApp_Preferences::IntSpin, "OCCViewer", "rt_depth" );
2725   pref->setItemProperty( "min", 1, rt_depth );
2726   pref->setItemProperty( "max", 10, rt_depth );
2727   pref->setItemProperty( "step", 1, rt_depth );
2728   pref->addPreference( "", rtPref, LightApp_Preferences::Frame );
2729   // .... -> specular reflections
2730   pref->addPreference( tr( "PREF_RAY_TRACING_REFLECTION" ), rtPref,
2731                LightApp_Preferences::Bool, "OCCViewer", "rt_reflection" );
2732   // .... -> adaptive anti-aliasing
2733   pref->addPreference( tr( "PREF_RAY_TRACING_ANTIALIASING" ), rtPref,
2734                LightApp_Preferences::Bool, "OCCViewer", "rt_antialiasing" );
2735   // .... -> shadows rendering
2736   pref->addPreference( tr( "PREF_RAY_TRACING_SHADOW" ), rtPref,
2737                LightApp_Preferences::Bool, "OCCViewer", "rt_shadow" );
2738   // .... -> transparent shadow
2739   pref->addPreference( tr( "PREF_RAY_TRACING_TRANS_SHADOW" ), rtPref,
2740                LightApp_Preferences::Bool, "OCCViewer", "rt_trans_shadow" );
2741   // ... "Ray tracing" group <<end>>
2742
2743   // ... "Light source" group <<start>>
2744   int occLightGroup = pref->addPreference( tr( "PREF_GROUP_LIGHT" ), occGroup );
2745   // .... -> light color
2746   pref->addPreference( tr( "PREF_LIGHT_COLOR" ), occLightGroup,
2747                LightApp_Preferences::Color, "OCCViewer", "light_color" );
2748   int directionPref = pref->addPreference( "", occLightGroup, LightApp_Preferences::Frame );
2749   pref->setItemProperty( "columns", 3, directionPref );
2750   // .... -> light direction (dx component)
2751   int light_dx = pref->addPreference( tr( "Dx" ), directionPref,
2752                LightApp_Preferences::DblSpin, "OCCViewer", "light_dx" );
2753   pref->setItemProperty( "precision", 2, light_dx );
2754   pref->setItemProperty( "min", -1.0E03, light_dx );
2755   pref->setItemProperty( "max", 1.0E03, light_dx );
2756   pref->setItemProperty( "step", 0.1, light_dx );
2757   // .... -> light direction (dy component)
2758   int light_dy = pref->addPreference( tr( "Dy" ), directionPref,
2759                LightApp_Preferences::DblSpin, "OCCViewer", "light_dy" );
2760   pref->setItemProperty( "precision", 2, light_dy );
2761   pref->setItemProperty( "min", -1.0E03, light_dy );
2762   pref->setItemProperty( "max", 1.0E03, light_dy );
2763   pref->setItemProperty( "step", 0.1, light_dy );
2764   // .... -> light direction (dz component)
2765   int light_dz = pref->addPreference( tr( "Dz" ), directionPref,
2766                LightApp_Preferences::DblSpin, "OCCViewer", "light_dz" );
2767   pref->setItemProperty( "precision", 2, light_dz );
2768   pref->setItemProperty( "min", -1.0E03, light_dz );
2769   pref->setItemProperty( "max", 1.0E03, light_dz );
2770   pref->setItemProperty( "step", 0.1, light_dz );
2771   // ... "Light source" group <<end>>
2772
2773   // ... -> empty frame (for layout) <<start>>
2774   int occGen = pref->addPreference( "", occGroup, LightApp_Preferences::Frame );
2775   pref->setItemProperty( "margin",  0, occGen );
2776   pref->setItemProperty( "columns", 2, occGen );
2777   // ... -> empty frame (for layout) <<end>>
2778
2779   // .. "OCC viewer" group <<end>>
2780 #endif
2781
2782 #ifndef DISABLE_VTKVIEWER
2783   // .. "VTK viewer" group <<start>>
2784   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), salomeCat ); //viewTab
2785
2786   // ... -> empty frame (for layout) <<start>>
2787   int vtkGen = pref->addPreference( "", vtkGroup, LightApp_Preferences::Frame );
2788   //pref->setItemProperty( "columns", 2, vtkGen );
2789   // .... -> projection mode
2790   int vtkProjMode = pref->addPreference( tr( "PREF_PROJECTION_MODE" ), vtkGen,
2791                                          LightApp_Preferences::Selector, "VTKViewer", "projection_mode" );
2792   aValuesList.clear();
2793   anIndicesList.clear();
2794   aValuesList   << tr("PREF_ORTHOGRAPHIC") << tr("PREF_PERSPECTIVE");
2795   anIndicesList << 0                       << 1;
2796   pref->setItemProperty( "strings", aValuesList,   vtkProjMode );
2797   pref->setItemProperty( "indexes", anIndicesList, vtkProjMode );
2798
2799   // .... -> Stereo group
2800   int vtkStereoGroup = pref->addPreference( tr( "PREF_GROUP_STEREO" ), vtkGroup);
2801   pref->setItemProperty( "columns", 2, vtkStereoGroup );
2802   // .... -> Stereo type
2803   int vtkStereoType = pref->addPreference( tr( "PREF_STEREO_TYPE" ), vtkStereoGroup,
2804                                            LightApp_Preferences::Selector, "VTKViewer", "stereo_type" );
2805   aValuesList.clear();
2806   anIndicesList.clear();
2807   idList.clear();
2808   SVTK_Viewer::stereoData( aValuesList, idList);
2809   foreach( int gid, idList ) anIndicesList << gid;
2810   pref->setItemProperty( "strings", aValuesList,   vtkStereoType );
2811   pref->setItemProperty( "indexes", anIndicesList, vtkStereoType );
2812   // .... -> Anaglyph filter
2813   int vtkAnaglyphFilter = pref->addPreference( tr( "PREF_ANAGLYPH_FILTER" ), vtkStereoGroup,
2814                                                LightApp_Preferences::Selector, "VTKViewer", "anaglyph_filter" );
2815   aValuesList.clear();
2816   anIndicesList.clear();
2817   aValuesList   << tr("PREF_ANAGLYPH_RED_CYAN") << tr("PREF_ANAGLYPH_YELLOW_BLUE") << tr("PREF_ANAGLYPH_GREEN_MAGENTA");
2818   anIndicesList << 0                            << 1                               << 2;
2819
2820   pref->setItemProperty( "strings", aValuesList,   vtkAnaglyphFilter );
2821   pref->setItemProperty( "indexes", anIndicesList, vtkAnaglyphFilter );
2822
2823   // .... -> Enable quad-buffer support
2824   pref->addPreference( tr( "PREF_ENABLE_QUAD_BUFFER_SUPPORT" ), vtkStereoGroup,
2825                        LightApp_Preferences::Bool, "VTKViewer", "enable_quad_buffer_support" );
2826
2827   // .... -> background
2828   aValuesList.clear();
2829   anIndicesList.clear();
2830   txtList.clear();
2831   idList.clear();
2832 #ifndef DISABLE_SALOMEOBJECT
2833   formats = SVTK_Viewer::backgroundData( aValuesList, idList, txtList );
2834 #endif
2835   foreach( int gid, idList ) anIndicesList << gid;
2836   bgId = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen,
2837                               LightApp_Preferences::Background, "VTKViewer", "background" );
2838   pref->setItemProperty( "gradient_names", aValuesList, bgId );
2839   pref->setItemProperty( "gradient_ids", anIndicesList, bgId );
2840   pref->setItemProperty( "texture_enabled", !txtList.isEmpty(), bgId );
2841   pref->setItemProperty( "texture_center_enabled", (bool)txtList.contains( Qtx::CenterTexture ), bgId );
2842   pref->setItemProperty( "texture_tile_enabled", (bool)txtList.contains( Qtx::TileTexture ), bgId );
2843   pref->setItemProperty( "texture_stretch_enabled", (bool)txtList.contains( Qtx::StretchTexture ), bgId );
2844   pref->setItemProperty( "custom_enabled", false, bgId );
2845 #ifndef DISABLE_SALOMEOBJECT
2846   pref->setItemProperty( "image_formats", formats, bgId );
2847 #endif
2848   // .... -> speed increment
2849   int vtkSpeed = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED" ), vtkGen,
2850                                       LightApp_Preferences::IntSpin, "VTKViewer", "speed_value" );
2851   pref->setItemProperty( "min", 1, vtkSpeed );
2852   pref->setItemProperty( "max", 1000, vtkSpeed );
2853   // .... -> speed mode
2854   int vtkSpeedMode = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED_MODE" ), vtkGen,
2855                                           LightApp_Preferences::Selector, "VTKViewer", "speed_mode" );
2856   aValuesList.clear();
2857   anIndicesList.clear();
2858   aValuesList   << tr("PREF_ARITHMETIC") << tr("PREF_GEOMETRICAL");
2859   anIndicesList << 0                     << 1;
2860   pref->setItemProperty( "strings", aValuesList,   vtkSpeedMode );
2861   pref->setItemProperty( "indexes", anIndicesList, vtkSpeedMode );
2862
2863   // ... "Selection" group <<start>>
2864   int vtkSelectionGroup = pref->addPreference( tr( "PREF_GROUP_SELECTION" ), vtkGroup );
2865   pref->setItemProperty( "columns", 2, vtkSelectionGroup );
2866   // .... -> preselection
2867   int vtkPreselection = pref->addPreference( tr( "PREF_PRESELECTION" ),  vtkSelectionGroup, 
2868                                              LightApp_Preferences::Selector, "VTKViewer", "preselection" );
2869   aValuesList.clear();
2870   anIndicesList.clear();
2871   aValuesList   << tr("PREF_PRESELECTION_STANDARD") << tr("PREF_PRESELECTION_DYNAMIC") << tr("PREF_PRESELECTION_DISABLED");
2872   anIndicesList << 0 << 1 << 2;
2873   pref->setItemProperty( "strings", aValuesList,   vtkPreselection );
2874   pref->setItemProperty( "indexes", anIndicesList, vtkPreselection );
2875   // .... -> enable selection
2876   pref->addPreference( tr( "PREF_ENABLE_SELECTION" ), vtkSelectionGroup, LightApp_Preferences::Bool, "VTKViewer", "enable_selection" );
2877   // ... "Selection" group <<end>>
2878
2879   // ... -> empty frame (for layout) <<end>>
2880
2881   // ... space mouse sub-group <<start>>
2882   int vtkSM = pref->addPreference( tr( "PREF_FRAME_SPACEMOUSE" ), vtkGroup, LightApp_Preferences::GroupBox );
2883   //pref->setItemProperty( "columns", 2, vtkSM );
2884   // .... -> decrease speed increment
2885   int spacemousePref1 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_1" ), vtkSM,
2886                                              LightApp_Preferences::Selector, "VTKViewer",
2887                                              "spacemouse_func1_btn" );
2888   // .... -> increase speed increment
2889   int spacemousePref2 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_2" ), vtkSM,
2890                                              LightApp_Preferences::Selector, "VTKViewer",
2891                                              "spacemouse_func2_btn" );
2892   // .... -> dominant / combined switch  
2893   int spacemousePref3 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_3" ), vtkSM,
2894                                              LightApp_Preferences::Selector, "VTKViewer",
2895                                              "spacemouse_func5_btn" ); //
2896   aValuesList.clear();
2897   anIndicesList.clear();
2898   aValuesList << tr( "PREF_SPACEMOUSE_BTN_1" )  << tr( "PREF_SPACEMOUSE_BTN_2" ) << tr( "PREF_SPACEMOUSE_BTN_3" );
2899   aValuesList << tr( "PREF_SPACEMOUSE_BTN_4" )  << tr( "PREF_SPACEMOUSE_BTN_5" ) << tr( "PREF_SPACEMOUSE_BTN_6" );
2900   aValuesList << tr( "PREF_SPACEMOUSE_BTN_7" )  << tr( "PREF_SPACEMOUSE_BTN_8" ) << tr( "PREF_SPACEMOUSE_BTN_*" );
2901   aValuesList << tr( "PREF_SPACEMOUSE_BTN_10" ) << tr( "PREF_SPACEMOUSE_BTN_11" );
2902   anIndicesList << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11;
2903   pref->setItemProperty( "strings", aValuesList,   spacemousePref1 );
2904   pref->setItemProperty( "indexes", anIndicesList, spacemousePref1 );
2905   pref->setItemProperty( "strings", aValuesList,   spacemousePref2 );
2906   pref->setItemProperty( "indexes", anIndicesList, spacemousePref2 );
2907   pref->setItemProperty( "strings", aValuesList,   spacemousePref3 );
2908   pref->setItemProperty( "indexes", anIndicesList, spacemousePref3 );
2909   // ... space mouse sub-group <<end>>
2910
2911   // ... avi recording sub-group <<start>>
2912   int vtkRec = pref->addPreference( tr( "PREF_FRAME_RECORDING" ), vtkGroup, LightApp_Preferences::GroupBox );
2913   pref->setItemProperty( "columns", 2, vtkRec );
2914   // .... -> recording mode
2915   int modePref = pref->addPreference( tr( "PREF_RECORDING_MODE" ), vtkRec,
2916                                       LightApp_Preferences::Selector, "VTKViewer", "recorder_mode" );
2917   aValuesList.clear();
2918   anIndicesList.clear();
2919   aValuesList   << tr( "PREF_SKIPPED_FRAMES" ) << tr( "PREF_ALL_DISLPAYED_FRAMES" );
2920   anIndicesList << 0                           << 1;
2921   pref->setItemProperty( "strings", aValuesList,   modePref );
2922   pref->setItemProperty( "indexes", anIndicesList, modePref );
2923   // .... -> fps
2924   int fpsPref = pref->addPreference( tr( "PREF_FPS" ), vtkRec,
2925                                      LightApp_Preferences::DblSpin, "VTKViewer", "recorder_fps" );
2926   pref->setItemProperty( "min", 0.1, fpsPref );
2927   pref->setItemProperty( "max", 100, fpsPref );
2928   // .... -> quality
2929   int qualityPref = pref->addPreference( tr( "PREF_QUALITY" ), vtkRec,
2930                                          LightApp_Preferences::IntSpin, "VTKViewer", "recorder_quality" );
2931   pref->setItemProperty( "min", 1, qualityPref );
2932   pref->setItemProperty( "max", 100, qualityPref );
2933   // .... -> progressive mode
2934   pref->addPreference( tr( "PREF_PROGRESSIVE" ), vtkRec,
2935                        LightApp_Preferences::Bool, "VTKViewer", "recorder_progressive" );
2936   // ... avi recording sub-group <<end>>
2937
2938   // ... group names sub-group <<start>>
2939   int vtkGN = pref->addPreference( tr( "PREF_FRAME_GROUP_NAMES" ), vtkGroup,
2940                                    LightApp_Preferences::GroupBox, "VTKViewer", "show_group_names" );
2941   pref->setItemProperty( "columns", 2, vtkGN );
2942   // .... -> text color
2943   pref->addPreference( tr(  "PREF_GROUP_NAMES_TEXT_COLOR" ), vtkGN,
2944                        LightApp_Preferences::Color, "VTKViewer", "group_names_text_color" );
2945   // .... -> transparency
2946   int transPref = pref->addPreference( tr( "PREF_GROUP_NAMES_TRANSPARENCY" ), vtkGN,
2947                                        LightApp_Preferences::DblSpin, "VTKViewer", "group_names_transparency" );
2948   pref->setItemProperty( "min", 0.0, transPref );
2949   pref->setItemProperty( "max", 1.0, transPref );
2950   pref->setItemProperty( "step", 0.1, transPref );
2951   // ... -> group names sub-group <<end>>
2952   // .. "VTK viewer" group <<end>>
2953 #endif
2954
2955   // .. "Plot2d viewer" group <<start>>
2956   int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), salomeCat ); //viewTab
2957   //pref->setItemProperty( "columns", 2, plot2dGroup );
2958
2959   // ... -> background
2960   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND_COLOR" ), plot2dGroup,
2961                        LightApp_Preferences::Color, "Plot2d", "Background" );
2962   // ... -> selection color
2963   pref->addPreference( tr( "PREF_VIEWER_SELECTION" ), plot2dGroup,
2964                        LightApp_Preferences::Color, "Plot2d", "SelectionColor" );
2965
2966   // ... "Viewer" group <<start>>
2967   int plot2dViewerGroup = pref->addPreference( tr( "PREF_GROUP_VIEWER" ), plot2dGroup );
2968
2969   // .... -> curve type
2970   int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dViewerGroup,
2971                                        LightApp_Preferences::Selector, "Plot2d", "CurveType" );
2972   aValuesList.clear();
2973   anIndicesList.clear();
2974   aValuesList   << tr("PREF_POINTS") << tr("PREF_LINES") << tr("PREF_SPLINE");
2975   anIndicesList << 0                 << 1                << 2                ;
2976   pref->setItemProperty( "strings", aValuesList,   curveType );
2977   pref->setItemProperty( "indexes", anIndicesList, curveType );
2978   // .... -> marker size
2979   int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dViewerGroup,
2980                                         LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
2981   pref->setItemProperty( "min", 0, markerSize );
2982   pref->setItemProperty( "max", 100, markerSize );
2983   // .... -> horizontal scaling mode
2984   int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dViewerGroup,
2985                                       LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
2986   aValuesList.clear();
2987   anIndicesList.clear();
2988   aValuesList   << tr("PREF_LINEAR") << tr("PREF_LOGARITHMIC");
2989   anIndicesList << 0                 << 1                     ;
2990   pref->setItemProperty( "strings", aValuesList,   horScale );
2991   pref->setItemProperty( "indexes", anIndicesList, horScale );
2992   // .... -> vertical scaling mode
2993   int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dViewerGroup,
2994                                       LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
2995   pref->setItemProperty( "strings", aValuesList,   verScale );
2996   pref->setItemProperty( "indexes", anIndicesList, verScale );
2997
2998   // .... -> errors/deviation colot
2999   pref->addPreference( tr( "PREF_DEVIATION_COLOR" ), plot2dViewerGroup,
3000                        LightApp_Preferences::Color, "Plot2d", "DeviationMarkerColor" );
3001   // .... -> deviation markers line size
3002   int deviationMarkerLw = pref->addPreference( tr( "PREF_DEVIATION_MARKER_LW" ), plot2dViewerGroup,
3003                                         LightApp_Preferences::IntSpin, "Plot2d", "DeviationMarkerLineWidth" );
3004   pref->setItemProperty( "min", 1, deviationMarkerLw );
3005   pref->setItemProperty( "max", 5, deviationMarkerLw );
3006   // .... -> deviation markers tick mark size
3007   int deviationMarkerTs = pref->addPreference( tr( "PREF_DEVIATION_MARKER_TS" ), plot2dViewerGroup,
3008                                         LightApp_Preferences::IntSpin, "Plot2d", "DeviationMarkerTickSize" );
3009   pref->setItemProperty( "min", 1, deviationMarkerTs );
3010   pref->setItemProperty( "max", 5, deviationMarkerTs );
3011   // .... "Viewer" group <<end>>
3012
3013   // ... "Legend" group <<start>>
3014   int plot2dLegendGroup = pref->addPreference( tr( "PREF_GROUP_LEGEND" ), plot2dGroup );
3015
3016   // .... -> show legend
3017   pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dLegendGroup,
3018                        LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
3019   // .... -> legend position
3020   int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dLegendGroup,
3021                                             LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
3022   aValuesList.clear();
3023   anIndicesList.clear();
3024   aValuesList   << tr("PREF_LEFT") << tr("PREF_RIGHT") << tr("PREF_TOP") << tr("PREF_BOTTOM");
3025   anIndicesList << 0               << 1                << 2              << 3                ;
3026   pref->setItemProperty( "strings", aValuesList,   legendPosition );
3027   pref->setItemProperty( "indexes", anIndicesList, legendPosition );
3028   // .... -> Symbol type
3029   int legendSymbolType = pref->addPreference( tr( "PREF_LEGEND_SYMBOL_TYPE" ), plot2dLegendGroup,
3030                                             LightApp_Preferences::Selector, "Plot2d", "LegendSymbolType" );
3031   aValuesList.clear();
3032   anIndicesList.clear();
3033   aValuesList   << tr("PREF_MARKER_ON_LINE") << tr("PREF_MARKER_ABOVE_LINE");
3034   anIndicesList << 0                            << 1                        ;
3035   pref->setItemProperty( "strings", aValuesList,   legendSymbolType );
3036   pref->setItemProperty( "indexes", anIndicesList, legendSymbolType );
3037   // .... -> legend font
3038   pref->addPreference( tr( "PREF_LEGEND_FONT" ), plot2dLegendGroup, LightApp_Preferences::Font, "Plot2d", "LegendFont" );
3039   // ... -> font color
3040   pref->addPreference( tr( "PREF_FONT_COLOR" ), plot2dLegendGroup, LightApp_Preferences::Color, "Plot2d", "LegendFontColor" );
3041   // ... -> selection font color
3042   pref->addPreference( tr( "PREF_SELECTED_FONT_COLOR" ), plot2dLegendGroup, LightApp_Preferences::Color, "Plot2d", "SelectedLegendFontColor" );
3043   // ... "Legend" group <<end>>
3044
3045   // .. "Plot2d viewer" group <<end>>
3046
3047   // .. "PyViewer" preferences tab <<start>>
3048   int pyeditTab = pref->addPreference( tr( "PREF_TAB_PYEDITOR" ), salomeCat );
3049   // ... "Font settings" group <<start>>
3050   int pyFontGroup = pref->addPreference( tr( "PREF_GROUP_PY_FONT" ), pyeditTab );
3051   int pyFont = pref->addPreference( tr( "PREF_PY_FONT" ), pyFontGroup,
3052                                     LightApp_Preferences::Font, "PyEditor", "Font" );
3053   pref->setItemProperty( "features", QtxFontEdit::Family | QtxFontEdit::Size | QtxFontEdit::UserSize, pyFont );
3054   // ... "Font settings" group <<end>>
3055   // ... "Display settings" group <<start>>
3056   int pyDispGroup = pref->addPreference( tr( "PREF_GROUP_PY_DISPLAY" ), pyeditTab );
3057   pref->setItemProperty( "columns", 2, pyDispGroup );
3058   // ... -> current line highlight
3059   pref->addPreference( tr( "PREF_PY_CURRLINE_HIGHLIGHT" ), pyDispGroup,
3060     LightApp_Preferences::Bool, "PyEditor", "HighlightCurrentLine" );
3061   // ... -> text wrapping
3062   pref->addPreference( tr( "PREF_PY_TEXT_WRAP" ), pyDispGroup,
3063     LightApp_Preferences::Bool, "PyEditor", "TextWrapping" );
3064   // ... -> center cursor on scroll
3065   pref->addPreference( tr( "PREF_PY_CURSON_ON_SCROLL" ), pyDispGroup,
3066     LightApp_Preferences::Bool, "PyEditor", "CenterCursorOnScroll" );
3067   // ... -> line numbers area
3068   pref->addPreference( tr( "PREF_PY_LINE_NUMBS_AREA" ), pyDispGroup,
3069     LightApp_Preferences::Bool, "PyEditor", "LineNumberArea" );
3070   // ... "Display settings" group <<end>>
3071
3072   // ... "Editor settings" group <<start>>
3073   int pyEditGroup = pref->addPreference( tr( "PREF_GROUP_PY_EDITOR" ), pyeditTab );
3074   // ... -> navigation mode
3075   int pyCompletion = pref->addPreference( tr( "PREF_PY_COMPLETION_MODE" ), pyEditGroup,
3076                                           LightApp_Preferences::Selector, "PyEditor", "CompletionPolicy" );
3077   aValuesList.clear();
3078   anIndicesList.clear();
3079   aValuesList   << tr("PREF_PY_NONE") << tr("PREF_PY_AUTO") << tr("PREF_PY_MANUAL") << tr("PREF_PY_ALWAYS");
3080   anIndicesList << 0                  << 1                  << 2                    << 3                   ;
3081   pref->setItemProperty( "strings", aValuesList, pyCompletion );
3082   pref->setItemProperty( "indexes", anIndicesList, pyCompletion );
3083   // ... "Editor settings" group <<end>>
3084
3085   // ... "Tab settings" group <<start>>
3086   int pyTabGroup = pref->addPreference( tr( "PREF_GROUP_PY_TAB" ), pyeditTab );
3087   pref->setItemProperty( "columns", 2, pyTabGroup );
3088   // ... -> tab whitespaces
3089   pref->addPreference( tr( "PREF_PY_TAB_WHITESPACES" ), pyTabGroup,
3090     LightApp_Preferences::Bool, "PyEditor", "TabSpaceVisible" );
3091   // ... -> tab size
3092   pref->addPreference( tr( "PREF_PY_TAB_SIZE" ), pyTabGroup,
3093     LightApp_Preferences::IntSpin, "PyEditor", "TabSize" );
3094   // ... "Tab settings" group <<end>>
3095   // ... "Vertical edge settings" group <<start>>
3096   int pyVertEdgeGroup = pref->addPreference( tr( "PREF_GROUP_VERT_EDGE" ), pyeditTab );
3097   pref->setItemProperty( "columns", 2, pyVertEdgeGroup );
3098   // ... -> vertical edge
3099   pref->addPreference( tr( "PREF_PY_VERT_EDGE" ), pyVertEdgeGroup,
3100     LightApp_Preferences::Bool, "PyEditor", "VerticalEdge" );
3101   // ... -> number of columns
3102   pref->addPreference( tr( "PREF_PY_NUM_COLUMNS" ), pyVertEdgeGroup,
3103     LightApp_Preferences::IntSpin, "PyEditor", "NumberColumns" );
3104   // ... "Vertical edge settings" group <<end>>
3105   // .. "PyEditor" preferences tab <<end>>
3106
3107   // .. "Directories" preferences tab <<start>>
3108   int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
3109   // ... --> quick directories list
3110   int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
3111   pref->addPreference( tr( "" ), dirGroup,
3112                        LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
3113   // .. "Directories" preferences tab <<end>>
3114
3115   // .. "Object browser" preferences tab <<start>>
3116   int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
3117
3118   // ... "Search tool" group <<start>>
3119   int stGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SEARCH_TOOL" ), obTab );
3120   // .... --> auto-hide
3121   pref->addPreference( tr( "PREF_AUTO_HIDE_SEARCH_TOOL" ), stGroup, LightApp_Preferences::Bool,
3122                        "ObjectBrowser", "auto_hide_search_tool" );
3123   // ... "Search tool" group <<end>>
3124
3125   // ... "Object browser settings" group <<start>>
3126   int objSetGroup = pref->addPreference( tr( "PREF_GROUP_LOOK_AND_FEEL" ), obTab );
3127   pref->setItemProperty( "columns", 2, objSetGroup );
3128   // .... -> auto size first column
3129   pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
3130                        "ObjectBrowser", "auto_size_first" );
3131   // .... -> auto size other columns
3132   pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
3133                        "ObjectBrowser", "auto_size" );
3134   // .... -> resize columns on expand item
3135   pref->addPreference( tr( "PREF_RESIZE_ON_EXPAND_ITEM" ), objSetGroup, LightApp_Preferences::Bool,
3136                        "ObjectBrowser", "resize_on_expand_item" );
3137   // .... -> browse to published object
3138   int browsePublished = pref->addPreference( tr( "PREF_BROWSE_TO_THE_PUBLISHED_OBJECT" ), objSetGroup, LightApp_Preferences::Selector,
3139                                              "ObjectBrowser", "browse_published_object" );
3140   aValuesList.clear();
3141   anIndicesList.clear();
3142   aValuesList << tr( "PREF_BROWSE_NEVER" ) << tr( "PREF_BROWSE_AFTER_APPLY_AND_CLOSE_ONLY" ) << tr( "PREF_BROWSE_ALWAYS" );
3143   anIndicesList << BP_Never << BP_ApplyAndClose << BP_Always;
3144   pref->setItemProperty( "strings", aValuesList,   browsePublished );
3145   pref->setItemProperty( "indexes", anIndicesList, browsePublished );
3146   // ... "Object browser settings" group <<end>>
3147   // .. "Object browser" preferences tab <<end>>
3148
3149   // .. "Shortcuts" preferences tab <<start>>
3150   int shortcutTab = pref->addPreference( tr( "PREF_TAB_SHORTCUTS" ), salomeCat );
3151   // ... "Shortcuts settings" group <<start>>
3152   int shortcutGroup = pref->addPreference( tr( "PREF_GROUP_SHORTCUTS" ), shortcutTab );
3153   pref->addPreference( tr( "" ), shortcutGroup,
3154                        LightApp_Preferences::ShortcutTree, "shortcuts" );
3155   // ... "Shortcuts settings" group <<end>>
3156   // .. "Shortcuts" preferences tab <<end>>
3157   // . Top-level "SALOME" preferences group <<end>>
3158
3159   pref->retrieve();
3160 }
3161
3162 /*!
3163   Changes appearance of application according to changed preferences
3164   \param sec - section
3165   \param param - name of changed parameter
3166 */
3167 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
3168 {
3169   SUIT_ResourceMgr* resMgr = resourceMgr();
3170   if ( !resMgr )
3171     return;
3172
3173   if ( sec == "viewers" && param == "drop_down_buttons" )
3174   {
3175     ViewManagerList vmlist = viewManagers();
3176     foreach( SUIT_ViewManager* vm, vmlist )
3177     {
3178       QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
3179       foreach( SUIT_ViewWindow* vw, vwlist )
3180         if ( vw ) vw->setDropDownButtons( resMgr->booleanValue( "viewers", "drop_down_buttons", true ) );
3181     }
3182   }
3183
3184   if ( sec == QString( "3DViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )))
3185   {
3186     double sz = resMgr->doubleValue( sec, "trihedron_size", -1 );
3187     bool relative = resMgr->booleanValue( sec, "relative_size", true );
3188     QList<SUIT_ViewManager*> lst;
3189 #ifndef DISABLE_OCCVIEWER
3190     viewManagers( OCCViewer_Viewer::Type(), lst );
3191     QListIterator<SUIT_ViewManager*> itOCC( lst );
3192     while ( itOCC.hasNext() && sz >= 0 )
3193     {
3194       SUIT_ViewModel* vm = itOCC.next()->getViewModel();
3195       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3196         continue;
3197
3198       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3199       occVM->setTrihedronSize( sz, relative );
3200       occVM->getAISContext()->UpdateCurrentViewer();
3201     }
3202 #endif
3203 #ifndef DISABLE_VTKVIEWER
3204 #ifndef DISABLE_SALOMEOBJECT
3205     viewManagers( SVTK_Viewer::Type(), lst );
3206     QListIterator<SUIT_ViewManager*> itVTK( lst );
3207     while ( itVTK.hasNext() && sz >= 0 )
3208     {
3209       SUIT_ViewModel* vm = itVTK.next()->getViewModel();
3210       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3211         continue;
3212
3213       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3214       if( vtkVM )
3215       {
3216         vtkVM->setTrihedronSize( sz, relative );
3217         vtkVM->Repaint();
3218       }
3219     }
3220 #endif
3221 #endif
3222   }
3223
3224   if ( sec == QString( "3DViewer" ) && param == QString( "show_static_trihedron" ) )
3225   {
3226     bool isVisible = resMgr->booleanValue( "3DViewer", "show_static_trihedron", true );
3227     QList<SUIT_ViewManager*> lst;
3228 #ifndef DISABLE_OCCVIEWER
3229     viewManagers( OCCViewer_Viewer::Type(), lst );
3230     QListIterator<SUIT_ViewManager*> itOCC( lst );
3231     while ( itOCC.hasNext() )
3232     {
3233       SUIT_ViewModel* vm = itOCC.next()->getViewModel();
3234       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3235         continue;
3236
3237       OCCViewer_Viewer* occVM = dynamic_cast<OCCViewer_Viewer*>( vm );
3238       if( occVM )
3239       {
3240         occVM->setStaticTrihedronDisplayed( isVisible );
3241       }
3242     }
3243 #endif
3244 #ifndef DISABLE_VTKVIEWER
3245 #ifndef DISABLE_SALOMEOBJECT
3246     viewManagers( SVTK_Viewer::Type(), lst );
3247     QListIterator<SUIT_ViewManager*> itVTK( lst );
3248     while ( itVTK.hasNext() )
3249     {
3250       SUIT_ViewModel* vm = itVTK.next()->getViewModel();
3251       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3252         continue;
3253
3254       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3255       if( vtkVM )
3256       {
3257         vtkVM->setStaticTrihedronVisible( isVisible );
3258         vtkVM->Repaint();
3259       }
3260     }
3261 #endif
3262 #endif
3263   }
3264
3265   if ( sec == QString( "3DViewer" ) && param == QString( "navigation_mode" ) )
3266   {
3267     int mode = resMgr->integerValue( "3DViewer", "navigation_mode", 0 );
3268     QList<SUIT_ViewManager*> lst;
3269 #ifndef DISABLE_OCCVIEWER
3270     viewManagers( OCCViewer_Viewer::Type(), lst );
3271     QListIterator<SUIT_ViewManager*> itOCC( lst );
3272     while ( itOCC.hasNext() )
3273     {
3274       SUIT_ViewModel* vm = itOCC.next()->getViewModel();
3275       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3276         continue;
3277
3278       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3279       occVM->setInteractionStyle( mode );
3280     }
3281 #endif
3282 #ifndef DISABLE_VTKVIEWER
3283 #ifndef DISABLE_SALOMEOBJECT
3284     viewManagers( SVTK_Viewer::Type(), lst );
3285     QListIterator<SUIT_ViewManager*> itVTK( lst );
3286     while ( itVTK.hasNext() )
3287     {
3288       SUIT_ViewModel* vm = itVTK.next()->getViewModel();
3289       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3290         continue;
3291
3292       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3293       if( vtkVM ) vtkVM->setInteractionStyle( mode );
3294     }
3295 #endif
3296 #endif
3297   }
3298
3299 #ifndef DISABLE_OCCVIEWER
3300   if ( sec == QString( "OCCViewer" ) && param == QString( "enable_preselection" ) )
3301   {
3302     bool isToEnablePreselection = resMgr->booleanValue( "OCCViewer", "enable_preselection", true );
3303     QList<SUIT_ViewManager*> lst;
3304     viewManagers( OCCViewer_Viewer::Type(), lst );
3305     QListIterator<SUIT_ViewManager*> it( lst );
3306     while ( it.hasNext() )
3307     {
3308       SUIT_ViewModel* vm = it.next()->getViewModel();
3309       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3310         continue;
3311
3312       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3313       occVM->enablePreselection( isToEnablePreselection );
3314     }
3315   }
3316 #endif
3317
3318 #ifndef DISABLE_OCCVIEWER
3319   if ( sec == QString( "OCCViewer" ) && param == QString( "enable_selection" ) )
3320   {
3321     bool isToEnableSelection = resMgr->booleanValue( "OCCViewer", "enable_selection", true );
3322     QList<SUIT_ViewManager*> lst;
3323     viewManagers( OCCViewer_Viewer::Type(), lst );
3324     QListIterator<SUIT_ViewManager*> it( lst );
3325     while ( it.hasNext() )
3326     {
3327       SUIT_ViewModel* vm = it.next()->getViewModel();
3328       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3329         continue;
3330
3331       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3332       occVM->enableSelection( isToEnableSelection );
3333     }
3334   }
3335 #endif
3336
3337 #ifndef DISABLE_OCCVIEWER
3338   if ( sec == QString( "OCCViewer" ) && param == QString( "clipping_color" ) )
3339   {
3340     QColor aColor = resMgr->colorValue( "OCCViewer", "clipping_color", QColor( 50, 50, 50 ) );
3341     QList<SUIT_ViewManager*> lst;
3342     viewManagers( OCCViewer_Viewer::Type(), lst );
3343     QListIterator<SUIT_ViewManager*> it( lst );
3344     while ( it.hasNext() )
3345     {
3346       SUIT_ViewModel* vm = it.next()->getViewModel();
3347       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3348         continue;
3349
3350       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3351       occVM->setClippingColor( aColor );
3352     }
3353   }
3354 #endif
3355
3356 #ifndef DISABLE_OCCVIEWER
3357   if ( sec == QString( "OCCViewer" ) && ( param == QString( "clipping_use_default_texture" ) ||
3358                                           param == QString( "clipping_texture" ) ||
3359                                           param == QString( "clipping_modulate" ) ||
3360                                           param == QString( "clipping_scale" ) ) )
3361   {
3362     bool isDefaultTextureUsed = resMgr->booleanValue( "OCCViewer", "clipping_use_default_texture" );
3363     QString aTexture = resMgr->stringValue( "OCCViewer", "clipping_texture" );
3364     bool isModulated = resMgr->booleanValue( "OCCViewer", "clipping_modulate" );
3365     double aScale = resMgr->doubleValue( "OCCViewer", "clipping_scale" );
3366     QList<SUIT_ViewManager*> lst;
3367     viewManagers( OCCViewer_Viewer::Type(), lst );
3368     QListIterator<SUIT_ViewManager*> it( lst );
3369     while ( it.hasNext() )
3370     {
3371       SUIT_ViewModel* vm = it.next()->getViewModel();
3372       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3373         continue;
3374
3375       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3376       occVM->setClippingTextureParams( isDefaultTextureUsed, aTexture, isModulated, aScale );
3377     }
3378   }
3379 #endif
3380
3381 #ifndef DISABLE_OCCVIEWER
3382   if ( sec == QString( "OCCViewer" ) && param == QString( "projection_mode" ) )
3383   {
3384     int mode = resMgr->integerValue( "OCCViewer", "projection_mode", 0 );
3385     QList<SUIT_ViewManager*> lst;
3386     viewManagers( OCCViewer_Viewer::Type(), lst );
3387     QListIterator<SUIT_ViewManager*> it( lst );
3388     while ( it.hasNext() )
3389     {
3390       SUIT_ViewModel* vm = it.next()->getViewModel();
3391       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3392         continue;
3393
3394       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3395       occVM->setProjectionType( mode );
3396     }
3397   }
3398 #endif
3399
3400
3401 #ifndef DISABLE_OCCVIEWER
3402   if (sec == QString("OCCViewer") && param == QString("adv_selection_mode"))
3403   {
3404     int mode = resMgr->integerValue("OCCViewer", "adv_selection_mode", 0);
3405     QList<SUIT_ViewManager*> lst;
3406     viewManagers(OCCViewer_Viewer::Type(), lst);
3407     QListIterator<SUIT_ViewManager*> it(lst);
3408     while (it.hasNext())
3409     {
3410       SUIT_ViewModel* vm = it.next()->getViewModel();
3411       if (!vm || !vm->inherits("OCCViewer_Viewer"))
3412         continue;
3413
3414       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3415       occVM->setSelectionStyle((OCCViewer_ViewWindow::SelectionStyle)mode);
3416     }
3417   }
3418 #endif
3419
3420
3421 #ifndef DISABLE_OCCVIEWER
3422   if ( sec == QString( "OCCViewer" ) && param == QString( "stereo_type" ) )
3423   {
3424     int mode = resMgr->integerValue( "OCCViewer", "stereo_type", 0 );
3425     QList<SUIT_ViewManager*> lst;
3426     viewManagers( OCCViewer_Viewer::Type(), lst );
3427     QListIterator<SUIT_ViewManager*> it( lst );
3428     while ( it.hasNext() )
3429     {
3430       SUIT_ViewModel* vm = it.next()->getViewModel();
3431       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3432         continue;
3433
3434       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3435       occVM->setStereoType( mode );
3436     }
3437   }
3438 #endif
3439
3440 #ifndef DISABLE_OCCVIEWER
3441   if ( sec == QString( "OCCViewer" ) && param == QString( "anaglyph_filter" ) )
3442   {
3443     int mode = resMgr->integerValue( "OCCViewer", "anaglyph_filter", 0 );
3444     QList<SUIT_ViewManager*> lst;
3445     viewManagers( OCCViewer_Viewer::Type(), lst );
3446     QListIterator<SUIT_ViewManager*> it( lst );
3447     while ( it.hasNext() )
3448     {
3449       SUIT_ViewModel* vm = it.next()->getViewModel();
3450       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3451         continue;
3452
3453       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3454       occVM->setAnaglyphFilter( mode );
3455     }
3456   }
3457 #endif
3458
3459 #ifndef DISABLE_OCCVIEWER
3460   if ( sec == QString( "OCCViewer" ) && ( param == QString( "focus_type" ) ||
3461                                           param == QString( "focus_value" ) ) )
3462   {
3463     int aType = resMgr->integerValue( "OCCViewer", "focus_type" );
3464     double aValue = resMgr->doubleValue( "OCCViewer", "focus_value" );
3465     QList<SUIT_ViewManager*> lst;
3466     viewManagers( OCCViewer_Viewer::Type(), lst );
3467     QListIterator<SUIT_ViewManager*> it( lst );
3468     while ( it.hasNext() )
3469     {
3470       SUIT_ViewModel* vm = it.next()->getViewModel();
3471       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3472         continue;
3473
3474       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3475       occVM->setStereographicFocus( aType, aValue );
3476     }
3477   }
3478 #endif
3479
3480 #ifndef DISABLE_OCCVIEWER
3481   if ( sec == QString( "OCCViewer" ) && ( param == QString( "iod_type" ) ||
3482                                           param == QString( "iod_value" ) ) )
3483   {
3484     int aType = resMgr->integerValue( "OCCViewer", "iod_type" );
3485     double aValue = resMgr->doubleValue( "OCCViewer", "iod_value" );
3486     QList<SUIT_ViewManager*> lst;
3487     viewManagers( OCCViewer_Viewer::Type(), lst );
3488     QListIterator<SUIT_ViewManager*> it( lst );
3489     while ( it.hasNext() )
3490     {
3491       SUIT_ViewModel* vm = it.next()->getViewModel();
3492       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3493         continue;
3494
3495       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3496       occVM->setInterocularDistance( aType, aValue );
3497     }
3498   }
3499 #endif
3500
3501 #ifndef DISABLE_OCCVIEWER
3502   if ( sec == QString( "OCCViewer" ) && param == QString( "reverse_stereo" ) )
3503   {
3504     bool reverse = resMgr->booleanValue( "OCCViewer", "reverse_stereo", false );
3505     QList<SUIT_ViewManager*> lst;
3506     viewManagers( OCCViewer_Viewer::Type(), lst );
3507     QListIterator<SUIT_ViewManager*> it( lst );
3508     while ( it.hasNext() )
3509     {
3510       SUIT_ViewModel* vm = it.next()->getViewModel();
3511       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3512         continue;
3513
3514       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3515       occVM->setReverseStereo( reverse );
3516     }
3517   }
3518 #endif
3519
3520 #ifndef DISABLE_OCCVIEWER
3521   if ( sec == QString( "OCCViewer" ) && param == QString( "enable_vsync" ) )
3522   {
3523     bool enable = resMgr->booleanValue( "OCCViewer", "enable_vsync", true );
3524     QList<SUIT_ViewManager*> lst;
3525     viewManagers( OCCViewer_Viewer::Type(), lst );
3526     QListIterator<SUIT_ViewManager*> it( lst );
3527     while ( it.hasNext() )
3528     {
3529       SUIT_ViewModel* vm = it.next()->getViewModel();
3530       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3531         continue;
3532
3533       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3534       occVM->setVSync( enable );
3535     }
3536   }
3537 #endif
3538
3539 #ifndef DISABLE_OCCVIEWER
3540   if ( sec == QString( "OCCViewer" ) && param == QString( "enable_quad_buffer_support" ) )
3541   {
3542     bool enable = resMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", false );
3543     QList<SUIT_ViewManager*> lst;
3544     viewManagers( OCCViewer_Viewer::Type(), lst );
3545     QListIterator<SUIT_ViewManager*> it( lst );
3546     while ( it.hasNext() )
3547     {
3548       SUIT_ViewModel* vm = it.next()->getViewModel();
3549       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3550         continue;
3551
3552       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3553       occVM->setQuadBufferSupport( enable );
3554     }
3555   }
3556 #endif
3557
3558   if ( sec == QString( "3DViewer" ) && param == QString( "zooming_mode" ) )
3559   {
3560     int mode = resMgr->integerValue( "3DViewer", "zooming_mode", 0 );
3561     QList<SUIT_ViewManager*> lst;
3562 #ifndef DISABLE_OCCVIEWER
3563     viewManagers( OCCViewer_Viewer::Type(), lst );
3564     QListIterator<SUIT_ViewManager*> itOCC( lst );
3565     while ( itOCC.hasNext() )
3566     {
3567       SUIT_ViewModel* vm = itOCC.next()->getViewModel();
3568       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
3569         continue;
3570
3571       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
3572       occVM->setZoomingStyle( mode );
3573     }
3574 #endif
3575 #ifndef DISABLE_VTKVIEWER
3576 #ifndef DISABLE_SALOMEOBJECT
3577     viewManagers( SVTK_Viewer::Type(), lst );
3578     QListIterator<SUIT_ViewManager*> itVTK( lst );
3579     while ( itVTK.hasNext() )
3580     {
3581       SUIT_ViewModel* vm = itVTK.next()->getViewModel();
3582       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3583         continue;
3584
3585       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3586       if( vtkVM ) vtkVM->setZoomingStyle( mode );
3587     }
3588 #endif
3589 #endif
3590   }
3591
3592 #ifndef DISABLE_VTKVIEWER
3593   if ( sec == QString( "VTKViewer" ) && (param == QString( "speed_value" ) || param == QString( "speed_mode" )) )
3594   {
3595     int speed = resMgr->integerValue( "VTKViewer", "speed_value", 10 );
3596     int mode = resMgr->integerValue( "VTKViewer", "speed_mode", 0 );
3597     QList<SUIT_ViewManager*> lst;
3598 #ifndef DISABLE_SALOMEOBJECT
3599     viewManagers( SVTK_Viewer::Type(), lst );
3600     QListIterator<SUIT_ViewManager*> it( lst );
3601     while ( it.hasNext() )
3602     {
3603       SUIT_ViewModel* vm = it.next()->getViewModel();
3604       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3605         continue;
3606
3607       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3608       if( vtkVM ) vtkVM->setIncrementalSpeed( speed, mode );
3609     }
3610 #endif
3611   }
3612 #endif
3613
3614 #ifndef DISABLE_VTKVIEWER
3615   if ( sec == QString( "VTKViewer" ) && param == QString( "projection_mode" ) )
3616   {
3617     int mode = resMgr->integerValue( "VTKViewer", "projection_mode", 0 );
3618     QList<SUIT_ViewManager*> lst;
3619 #ifndef DISABLE_SALOMEOBJECT
3620     viewManagers( SVTK_Viewer::Type(), lst );
3621     QListIterator<SUIT_ViewManager*> it( lst );
3622     while ( it.hasNext() )
3623     {
3624       SUIT_ViewModel* vm = it.next()->getViewModel();
3625       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3626         continue;
3627
3628       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3629       if( vtkVM ) vtkVM->setProjectionMode( mode );
3630     }
3631 #endif
3632   }
3633 #endif
3634
3635 #ifndef DISABLE_VTKVIEWER
3636   if ( sec == QString( "VTKViewer" ) && param == QString( "stereo_type" ) )
3637   {
3638     int mode = resMgr->integerValue( "VTKViewer", "stereo_type", 0 );
3639     QList<SUIT_ViewManager*> lst;
3640 #ifndef DISABLE_SALOMEOBJECT
3641     viewManagers( SVTK_Viewer::Type(), lst );
3642     QListIterator<SUIT_ViewManager*> it( lst );
3643     while ( it.hasNext() )
3644     {
3645       SUIT_ViewModel* vm = it.next()->getViewModel();
3646       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3647         continue;
3648
3649       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3650       if( vtkVM ) vtkVM->setStereoType( mode );
3651     }
3652 #endif
3653   }
3654 #endif
3655
3656 #ifndef DISABLE_VTKVIEWER
3657   if ( sec == QString( "VTKViewer" ) && param == QString( "anaglyph_filter" ) )
3658   {
3659     int mode = resMgr->integerValue( "VTKViewer", "anaglyph_filter", 0 );
3660     QList<SUIT_ViewManager*> lst;
3661 #ifndef DISABLE_SALOMEOBJECT
3662     viewManagers( SVTK_Viewer::Type(), lst );
3663     QListIterator<SUIT_ViewManager*> it( lst );
3664     while ( it.hasNext() )
3665     {
3666       SUIT_ViewModel* vm = it.next()->getViewModel();
3667       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3668         continue;
3669
3670       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3671       if( vtkVM ) vtkVM->setAnaglyphFilter( mode );
3672     }
3673 #endif
3674   }
3675 #endif
3676
3677 #ifndef DISABLE_VTKVIEWER
3678   if ( sec == QString( "VTKViewer" ) && param == QString( "enable_quad_buffer_support" ) )
3679   {
3680     int enable = resMgr->booleanValue( "VTKViewer", "enable_quad_buffer_support", false );
3681     QList<SUIT_ViewManager*> lst;
3682 #ifndef DISABLE_SALOMEOBJECT
3683     viewManagers( SVTK_Viewer::Type(), lst );
3684     QListIterator<SUIT_ViewManager*> it( lst );
3685     while ( it.hasNext() )
3686     {
3687       SUIT_ViewModel* vm = it.next()->getViewModel();
3688       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3689         continue;
3690
3691       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3692       if( vtkVM ) vtkVM->setQuadBufferSupport( enable );
3693     }
3694 #endif
3695   }
3696 #endif
3697
3698 #ifndef DISABLE_VTKVIEWER
3699   if ( sec == QString( "VTKViewer" ) && param == QString( "preselection" ) )
3700   {
3701     int mode = resMgr->integerValue( "VTKViewer", "preselection", 0 );
3702     QList<SUIT_ViewManager*> lst;
3703 #ifndef DISABLE_SALOMEOBJECT
3704     viewManagers( SVTK_Viewer::Type(), lst );
3705     QListIterator<SUIT_ViewManager*> it( lst );
3706     while ( it.hasNext() )
3707     {
3708       SUIT_ViewModel* vm = it.next()->getViewModel();
3709       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3710         continue;
3711
3712       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3713       if( vtkVM ) vtkVM->setPreSelectionMode( mode );
3714     }
3715 #endif
3716   }
3717 #endif
3718
3719 #ifndef DISABLE_VTKVIEWER
3720   if ( sec == QString( "VTKViewer" ) && param == QString( "enable_selection" ) )
3721   {
3722     bool isToEnableSelection = resMgr->booleanValue( "VTKViewer", "enable_selection", true );
3723     QList<SUIT_ViewManager*> lst;
3724 #ifndef DISABLE_SALOMEOBJECT
3725     viewManagers( SVTK_Viewer::Type(), lst );
3726     QListIterator<SUIT_ViewManager*> it( lst );
3727     while ( it.hasNext() )
3728     {
3729       SUIT_ViewModel* vm = it.next()->getViewModel();
3730       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3731         continue;
3732
3733       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3734       if( vtkVM ) vtkVM->enableSelection( isToEnableSelection );
3735     }
3736 #endif
3737   }
3738 #endif
3739
3740 #ifndef DISABLE_VTKVIEWER
3741   if ( sec == QString( "VTKViewer" ) && (param == QString( "spacemouse_func1_btn" ) ||
3742                                          param == QString( "spacemouse_func2_btn" ) ||
3743                                          param == QString( "spacemouse_func5_btn" ) ) )
3744   {
3745     int btn1 = resMgr->integerValue( "VTKViewer", "spacemouse_func1_btn", 1 );
3746     int btn2 = resMgr->integerValue( "VTKViewer", "spacemouse_func2_btn", 2 );
3747     int btn3 = resMgr->integerValue( "VTKViewer", "spacemouse_func5_btn", 9 );
3748     QList<SUIT_ViewManager*> lst;
3749 #ifndef DISABLE_SALOMEOBJECT
3750     viewManagers( SVTK_Viewer::Type(), lst );
3751     QListIterator<SUIT_ViewManager*> it( lst );
3752     while ( it.hasNext() )
3753     {
3754       SUIT_ViewModel* vm = it.next()->getViewModel();
3755       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
3756         continue;
3757
3758       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
3759       if( vtkVM ) vtkVM->setSpacemouseButtons( btn1, btn2, btn3 );
3760     }
3761 #endif
3762   }
3763 #endif
3764   if( sec=="ObjectBrowser" )
3765   {
3766     SUIT_DataBrowser* ob = objectBrowser();
3767     if ( !ob )
3768       return;
3769
3770     if ( param=="auto_size_first" )
3771     {
3772       bool autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
3773       ob->setAutoSizeFirstColumn( autoSizeFirst );
3774       if ( autoSizeFirst )
3775         ob->adjustFirstColumnWidth();
3776     }
3777     else if ( param=="auto_size" ) {
3778       bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
3779       ob->setAutoSizeColumns(autoSize);
3780       if ( autoSize )
3781         ob->adjustColumnsWidth();
3782     }
3783     else if ( param=="resize_on_expand_item" ) {
3784       bool resizeOnExpandItem = resMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
3785       ob->setResizeOnExpandItem(resizeOnExpandItem);
3786     }
3787     else if ( param == "auto_hide_search_tool" ) {
3788       ob->searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
3789     }
3790   }
3791
3792   if( sec=="Study" )
3793   {
3794     if( param=="auto_save_interval" ) {
3795       myAutoSaveTimer->stop();
3796       int autoSaveInterval = resMgr->integerValue( "Study", "auto_save_interval", 0 );
3797       if ( activeStudy() && autoSaveInterval > 0 ) myAutoSaveTimer->start( autoSaveInterval*60000 );
3798     }
3799   }
3800
3801 #ifndef DISABLE_PYCONSOLE
3802   if( sec=="PyConsole" && pythonConsole() )
3803   {
3804     if ( param=="font" ) {
3805       pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
3806     }
3807     else if ( param=="show_banner" ) {
3808       pythonConsole()->setIsShowBanner( resMgr->booleanValue( "PyConsole", "show_banner", true ) );
3809     }
3810     else if ( param=="auto_completion" ) {
3811       pythonConsole()->setAutoCompletion( resMgr->booleanValue( "PyConsole", "auto_completion", true ) );
3812     }
3813   }
3814 #endif
3815
3816   if( sec=="MRU" )
3817   {
3818     QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
3819     if ( mru ) {
3820       if ( param == "visible_count" )
3821         mru->setVisibleCount( resMgr->integerValue( "MRU", "visible_count", 5 ) );    // 5 MRU items by default
3822       else if ( param == "max_count" )
3823         mru->setHistoryCount( resMgr->integerValue( "MRU", "max_count", -1 ) );       // unlimited history by default
3824       else if ( param == "insert_mode" )
3825         mru->setInsertMode( resMgr->integerValue( "MRU", "insert_mode", 0 ) );        // QtxMRUAction::MoveFirst by default
3826       else if ( param == "link_type" )
3827         mru->setLinkType( resMgr->integerValue( "MRU", "link_type", 0 ) );            // QtxMRUAction::LinkAuto by default
3828       else if ( param == "show_clear" )
3829         mru->setClearPossible( resMgr->booleanValue( "MRU", "show_clear", false ) );  // do not show "Clear" item by default
3830       else if ( param == "show_mru" )
3831         mru->setVisible( resMgr->booleanValue( "MRU", "show_mru", false ) );          // do not show MRU menu item by default
3832     }
3833   }
3834   if ( sec == "language" && param == "language" )
3835   {
3836     // VSR 18.06.2015 : commented out : single warning dialog box is now shown by the LightApp_PreferencesDlg
3837     //SUIT_MessageBox::information( desktop(), tr( "WRN_WARNING" ), tr( "LANG_CHANGED" ) );
3838   }
3839   if ( sec == "language" && param == "locale")
3840   {
3841     // VSR 18.06.2015: commented out : single warning dialog box is now shown by the LightApp_PreferencesDlg
3842     //SUIT_MessageBox::information( desktop(), tr( "WRN_WARNING" ), tr( "LOCALE_CHANGED" ) );
3843   }
3844   if ( sec == "desktop" && param == "opaque_resize" ) {
3845     bool opaqueResize = resMgr->booleanValue( "desktop", "opaque_resize", false );
3846     // RNV: This code has been commented, because clearing of the QMainWindow::AnimatedDocks option
3847     //      leads to strange behaviour of the dockable windows (at least at qt-5.6.1):
3848     //      any dockable window can't be docked to the another area, except initial area.
3849     //      It is possible to move window to another area, but it always returns to the initial area.
3850     //
3851     //    QMainWindow::DockOptions dopts = desktop()->dockOptions();
3852     //    if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks;
3853     //     else                dopts &= ~QMainWindow::AnimatedDocks;
3854     //    desktop()->setDockOptions( dopts );
3855     desktop()->setOpaqueResize( opaqueResize );
3856     if ( dynamic_cast<STD_TabDesktop*>( desktop() ) )
3857       dynamic_cast<STD_TabDesktop*>( desktop() )->workstack()->setOpaqueResize( opaqueResize );
3858   }
3859
3860 #ifndef DISABLE_PLOT2DVIEWER
3861   QList<SUIT_ViewManager*> lst;
3862   viewManagers( Plot2d_Viewer::Type(), lst );
3863   QListIterator<SUIT_ViewManager*> itPlot2d( lst );
3864   while ( itPlot2d.hasNext() ) {
3865     SUIT_ViewManager* viewMgr = itPlot2d.next();
3866     SUIT_ViewModel* vm = viewMgr->getViewModel();
3867     if ( !vm || !vm->inherits( "Plot2d_Viewer" ) )
3868       continue;
3869
3870     //Plot2d_Viewer* Plot2dVM = dynamic_cast<Plot2d_Viewer*>( vm );
3871
3872     viewMgr->setViewModel( vm  );
3873     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
3874     if( wnd ) {
3875       Plot2d_ViewFrame* frame = wnd->getViewFrame();
3876       frame->SetPreference();
3877     }
3878   }
3879 #endif
3880 }
3881
3882 /*!
3883   Loads preferences
3884 */
3885 void LightApp_Application::loadPreferences()
3886 {
3887   CAM_Application::loadPreferences();
3888
3889   SUIT_ResourceMgr* aResMgr = resourceMgr();
3890
3891   if ( !aResMgr )
3892     return;
3893
3894   static bool mru_load = true;
3895   if ( mru_load )
3896   {
3897     QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
3898     if ( mru ) {
3899       mru->setVisible( aResMgr->booleanValue( "MRU", "show_mru", false ) );         // do not show MRU menu item by default
3900       mru->setVisibleCount( aResMgr->integerValue( "MRU", "visible_count", 5 ) );   // 5 MRU items by default
3901       mru->setHistoryCount( aResMgr->integerValue( "MRU", "max_count", -1 ) );      // unlimited history by default
3902       mru->setInsertMode( aResMgr->integerValue( "MRU", "insert_mode", 0 ) );       // QtxMRUAction::MoveFirst by default
3903       mru->setLinkType( aResMgr->integerValue( "MRU", "link_type", 0 ) );           // QtxMRUAction::LinkAuto by default
3904       mru->setClearPossible( aResMgr->booleanValue( "MRU", "show_clear", false ) ); // do not show "Clear" item by default
3905       mru->loadLinks( aResMgr, "MRU" );
3906     }
3907     mru_load = false;
3908   }
3909
3910   myWinVis.clear();
3911   QStringList mods = aResMgr->parameters( "windows_visibility" );
3912   for ( QStringList::const_iterator itr = mods.begin(); itr != mods.end(); ++itr )
3913   {
3914     QByteArray arr;
3915     if ( aResMgr->value( "windows_visibility", *itr, arr ) )
3916       myWinVis.insert( *itr, arr );
3917   }
3918
3919   if ( desktop() ) {
3920     desktop()->retrieveGeometry( aResMgr->stringValue( "desktop", "geometry" ) );
3921     bool opaqueResize = aResMgr->booleanValue( "desktop", "opaque_resize", false );
3922     //    QMainWindow::DockOptions dopts = desktop()->dockOptions();
3923     //    if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks;
3924     //    else                dopts &= ~QMainWindow::AnimatedDocks;
3925     //    desktop()->setDockOptions( dopts );
3926     desktop()->setOpaqueResize( opaqueResize );
3927     if ( dynamic_cast<STD_TabDesktop*>( desktop() ) )
3928       dynamic_cast<STD_TabDesktop*>( desktop() )->workstack()->setOpaqueResize( opaqueResize );
3929   }
3930 }
3931
3932 /*!
3933   Saves preferences
3934 */
3935 void LightApp_Application::savePreferences()
3936 {
3937   CAM_Application::savePreferences();
3938
3939   saveDockWindowsState();
3940
3941   SUIT_ResourceMgr* aResMgr = resourceMgr();
3942
3943   if ( !aResMgr )
3944     return;
3945
3946   QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
3947   if ( mru )
3948     mru->saveLinks( aResMgr, "MRU" );
3949
3950   for ( WinVis::const_iterator itr = myWinVis.begin(); itr != myWinVis.end(); ++itr )
3951     aResMgr->setValue( "windows_visibility", itr.key(), itr.value() );
3952
3953   if ( desktop() )
3954     aResMgr->setValue( "desktop", "geometry", desktop()->storeGeometry() );
3955
3956 #if GUI_DEVELOPMENT > 0
3957   aResMgr->setValue( "salome", "version", QString(GUI_VERSION_STR)+"dev" );
3958 #else
3959   aResMgr->setValue( "salome", "version", QString(GUI_VERSION_STR) );
3960 #endif
3961
3962   aResMgr->save();
3963 }
3964
3965 /*!
3966   Updates desktop title
3967 */
3968 void LightApp_Application::updateDesktopTitle()
3969 {
3970   QString aTitle = applicationName();
3971   QString aVer = applicationVersion();
3972   if ( !aVer.isEmpty() )
3973     aTitle += QString( " " ) + aVer;
3974
3975   if ( activeStudy() ) {
3976     QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false );
3977     aTitle += QString( " - [%1]" ).arg( sName );
3978   }
3979
3980   desktop()->setWindowTitle( aTitle );
3981 }
3982
3983 /*!
3984   \brief Get map of the operations which can be performed
3985   on the module activation.
3986
3987   The method should return the map of the kind \c {<id>:<name>}
3988   where \c <id> is an integer identifier of the operation and
3989   \c <name> is a title for the button to be added to the
3990   dialog box. After user selects the required operation by the
3991   clicking the corresponding button in the dialog box, its identifier
3992   is passed to the moduleActionSelected() method to process
3993   the made choice.
3994
3995   \return map of the operations
3996   \sa moduleActionSelected()
3997 */
3998 QMap<int, QString> LightApp_Application::activateModuleActions() const
3999 {
4000   QMap<int, QString> opmap;
4001   opmap.insert( NewStudyId,  tr( "ACTIVATE_MODULE_OP_NEW" ) );
4002   opmap.insert( OpenStudyId, tr( "ACTIVATE_MODULE_OP_OPEN" ) );
4003   return opmap;
4004 }
4005
4006 /*!
4007   \brief Called when the used selectes required operation chosen
4008   from "Activate module" dialog box.
4009
4010   Performs the required operation according to the user choice.
4011
4012   \param id operation identifier
4013   \sa activateModuleActions()
4014 */
4015 void LightApp_Application::moduleActionSelected( const int id )
4016 {
4017   switch ( id ) {
4018   case NewStudyId:
4019     onNewDoc();
4020     break;
4021   case OpenStudyId:
4022     onOpenDoc();
4023     break;
4024   default:
4025     break;
4026   }
4027 }
4028
4029 /*!
4030   Updates windows after close document
4031 */
4032 void LightApp_Application::afterCloseDoc()
4033 {
4034   updateWindows();
4035
4036   CAM_Application::afterCloseDoc();
4037 }
4038
4039 /*!
4040   Updates actions of active module
4041 */
4042 void LightApp_Application::updateModuleActions()
4043 {
4044   QString modName;
4045   if ( activeModule() )
4046     modName = activeModule()->moduleName();
4047
4048   LightApp_ModuleAction* moduleAction =
4049     qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
4050   if ( moduleAction )
4051     moduleAction->setActiveModule( modName );
4052 }
4053
4054 void LightApp_Application::removeModuleAction( const QString& modName )
4055 {
4056   LightApp_ModuleAction* moduleAction =
4057     qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
4058   if ( moduleAction )
4059     moduleAction->removeModule( modName );
4060 }
4061
4062 bool LightApp_Application::checkModule( const QString& title )
4063 {
4064   if ( title.isEmpty() )
4065     return false;
4066
4067   QString library = moduleLibrary( title, true );
4068   if ( library.isEmpty() )
4069     return false;
4070
4071   QString name = moduleName( title );
4072
4073   bool isPyModule = library.contains( "SalomePyQtGUI" ) || library.contains( "SalomePyQtGUILight" );
4074
4075   QStringList paths;
4076 #if defined(WIN32)
4077   paths = QString( Qtx::getenv( "PATH" ) ).split( ";", QString::SkipEmptyParts );
4078 #elif defined(__APPLE__)
4079   paths = QString( Qtx::getenv( "DYLD_LIBRARY_PATH" ) ).split( ":", QString::SkipEmptyParts );
4080 #else
4081   paths = QString( Qtx::getenv( "LD_LIBRARY_PATH" ) ).split( ":", QString::SkipEmptyParts );
4082 #endif
4083
4084   bool isFound = false;
4085   QStringList::const_iterator it;
4086   for ( it = paths.begin(); it != paths.end() && !isFound; ++it )
4087   {
4088     isFound = QFileInfo( Qtx::addSlash( *it ) + library ).exists();
4089   }
4090
4091   if ( !isFound )
4092   {
4093     INFOS( std::endl <<
4094            "****************************************************************" << std::endl <<
4095            "     Warning: library " << qPrintable( library ) << " is not found!" << std::endl <<
4096            "     Module " << qPrintable( title ) << " will not be available in GUI mode!" << std::endl <<
4097            "****************************************************************" << std::endl);
4098     return false;
4099   }
4100
4101   if ( isPyModule )
4102   {
4103     QString pyModule = QString( "%1GUI.py" ).arg( name );
4104 #if defined(WIN32)
4105     paths = QString( Qtx::getenv( "PYTHONPATH" ) ).split( ";", QString::SkipEmptyParts );
4106 #else
4107     paths = QString( Qtx::getenv( "PYTHONPATH" ) ).split( ":", QString::SkipEmptyParts );
4108 #endif
4109     isFound = false;
4110     for ( it = paths.begin(); it != paths.end() && !isFound; ++it )
4111     {
4112       isFound = QFileInfo( Qtx::addSlash( *it ) + pyModule ).exists();
4113     }
4114
4115     if ( !isFound )
4116     {
4117       INFOS( std::endl <<
4118              "****************************************************************" << std::endl <<
4119              "     Warning: Python module " << qPrintable( pyModule ) << " is not found!" << std::endl <<
4120              "     Module " << qPrintable( title ) << " will not be available in GUI mode!" << std::endl <<
4121              "****************************************************************" << std::endl);
4122       return false;
4123     }
4124   }
4125
4126   return true;
4127 }
4128
4129 /*!
4130   Gets current windows.
4131   \param winMap - output current windows map.
4132 */
4133 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
4134 {
4135   winMap.clear();
4136   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
4137     ((LightApp_Module*)activeModule())->windows( winMap );
4138   else
4139     defaultWindows( winMap );
4140 }
4141
4142 /*!
4143   Gets current view managers.
4144   \param lst - output current view managers list.
4145 */
4146 void LightApp_Application::currentViewManagers( QStringList& lst ) const
4147 {
4148   lst.clear();
4149   if ( !activeStudy() )
4150     return;
4151
4152   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
4153     ((LightApp_Module*)activeModule())->viewManagers( lst );
4154   else
4155     defaultViewManagers( lst );
4156 }
4157
4158 /*!
4159   Updates windows
4160 */
4161 void LightApp_Application::updateWindows()
4162 {
4163   QMap<int, int> winMap;
4164   currentWindows( winMap );
4165
4166   for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
4167   {
4168     if ( !dockWindow( it.key() ) )
4169       getWindow( it.key() );
4170   }
4171
4172   for ( WinMap::ConstIterator it = myWin.begin(); it != myWin.end(); ++it )
4173   {
4174     QWidget* wid = it.value();
4175     if ( !wid )
4176       continue;
4177     if ( winMap.contains( it.key() ) )
4178       wid->setVisible( true );
4179     else if ( !activeStudy() )
4180       delete wid;
4181     else
4182       wid->setVisible( false );
4183   }
4184
4185   loadDockWindowsState();
4186
4187   if ( !activeModule() && infoPanel() )
4188   {
4189     infoPanel()->clear();
4190     infoPanel()->setTitle( tr( "INFO_WELCOME_TO_SALOME" ) );
4191
4192     int grp = infoPanel()->addGroup( tr( "INFO_GETTING_STARTED" ) );
4193     infoPanel()->addAction( action( FileNewId ), grp );
4194     infoPanel()->addLabel( action( FileNewId )->statusTip(), grp );
4195     infoPanel()->addAction( action( FileOpenId ), grp );
4196     infoPanel()->addLabel( action( FileOpenId )->statusTip(), grp );
4197     if ( HAS_TUTORIAL_URL ) {
4198       infoPanel()->addAction( action( TutorialsId ), grp );
4199       infoPanel()->addLabel( action( TutorialsId )->statusTip(), grp );
4200     }
4201     infoPanel()->addAction( action( VideosId ), grp );
4202     infoPanel()->addLabel( action( VideosId )->statusTip(), grp );
4203
4204     LightApp_ModuleAction* ma = qobject_cast<LightApp_ModuleAction*>(action(ModulesListId));
4205     if ( ma && ma->count() > 0 )
4206     {
4207       grp = infoPanel()->addGroup( tr( "INFO_AVAILABLE_MODULES" ) );
4208       foreach ( QString mname, ma->modules() )
4209       {
4210         infoPanel()->addAction( ma->moduleAction( mname ), grp );
4211         if ( !moduleDescription( mname ).isEmpty() )
4212           infoPanel()->addLabel( moduleDescription( mname ), grp );
4213       }
4214     }
4215   }
4216 }
4217
4218 /*!
4219   Updates view managers
4220 */
4221 void LightApp_Application::updateViewManagers()
4222 {
4223   QStringList lst;
4224   currentViewManagers( lst );
4225
4226   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
4227     getViewManager( *it, true );
4228 }
4229
4230 /*!
4231   Loads windows geometry
4232 */
4233 void LightApp_Application::loadDockWindowsState()
4234 {
4235   if ( !desktop() )
4236     return;
4237   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
4238   bool storeWin = aResMgr->booleanValue( "Study", "store_positions", true );
4239   bool storeTb = aResMgr->booleanValue( "Study", "store_tool_positions", true );
4240
4241   QString modName;
4242   if ( activeModule() )
4243     modName = activeModule()->name();
4244   else if ( activeStudy() )
4245     modName = "nomodule";
4246
4247   QtxResourceMgr::WorkingMode prevMode = aResMgr->setWorkingMode( QtxResourceMgr::IgnoreUserValues );
4248   QByteArray aDefaultState;
4249   aResMgr->value( "windows_geometry", modName, aDefaultState );
4250   QByteArray aDefaultVisibility;
4251   aResMgr->value( "windows_visibility", modName, aDefaultVisibility );
4252   bool hasDefaultVisibility = !aDefaultVisibility.isEmpty();
4253   aResMgr->setWorkingMode( prevMode );
4254   
4255   if( !storeWin && !storeTb && aDefaultState.isEmpty() && !hasDefaultVisibility)
4256     return;
4257
4258   if ( aResMgr->hasValue("windows_geometry" ,modName ) ) {
4259     long version = Qtx::versionToId( aResMgr->stringValue( "windows_geometry_version", modName, "" ) );
4260     QByteArray arr;
4261     if ( version > Qtx::versionToId( "7.4.1" ) )
4262       aResMgr->value( "windows_geometry", modName , arr );
4263     else
4264       arr = aDefaultState;
4265     QByteArray aTargetArray = processState(arr, storeWin, storeTb, true, aDefaultState);
4266     desktop()->restoreState( aTargetArray );
4267   }
4268
4269   QStringList mainToolbarsNames;
4270   mainToolbarsNames << "SalomeStandard" << "SalomeModules";
4271   QList<QToolBar*> mainToolbars = findToolBars( mainToolbarsNames );
4272   foreach( QToolBar* tb, mainToolbars ) tb->setVisible( true );
4273   /*
4274   if ( !myWinVis.contains( modName ) && aDefaultVisibility.isEmpty())
4275     return;
4276
4277   QMap<QString, bool> *tbMap = 0;
4278   QMap<QString, bool> *dwMap = 0;
4279   
4280   QMap<QString, bool> userTbMap, userDwMap;
4281   dockWindowsState( myWinVis[modName], userTbMap, userDwMap );
4282
4283   QMap<QString, bool> defaultTbMap, defaultDwMap;
4284   if(hasDefaultVisibility) {
4285     dockWindowsState( aDefaultVisibility, defaultTbMap, defaultDwMap);    
4286   }
4287
4288   if(storeTb) {
4289     tbMap =  &userTbMap;
4290   } else {
4291     if(hasDefaultVisibility){
4292       tbMap =  &defaultTbMap;
4293     }
4294   }
4295
4296   if(storeWin) {
4297     dwMap =  &userDwMap;
4298   } else {
4299     if(hasDefaultVisibility){
4300       dwMap =  &defaultDwMap;
4301     }
4302   }
4303
4304   if(tbMap) {
4305     QList<QToolBar*> tbList = findToolBars();
4306     for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit )
4307       { 
4308         QToolBar* tb = *tit;
4309         if ( tbMap->contains( tb->objectName() ) ) {      
4310           tb->setVisible( (*tbMap)[tb->objectName()] );
4311         }
4312       }
4313   }
4314
4315   if(dwMap) {
4316     QList<QDockWidget*> dwList = desktop()->findChildren<QDockWidget*>();
4317     for ( QList<QDockWidget*>::iterator dit = dwList.begin(); dit != dwList.end(); ++dit )
4318       {
4319         QDockWidget* dw = *dit;
4320         
4321         QObject* po = Qtx::findParent( dw, "QMainWindow" );
4322         if ( po != desktop() )
4323           continue;
4324         
4325         if ( dwMap->contains( dw->objectName() ) )
4326           dw->setVisible( (*dwMap)[dw->objectName()] );
4327       }
4328   }
4329   */
4330 }
4331
4332
4333 /*!
4334   Saves windows geometry
4335 */
4336 void LightApp_Application::saveDockWindowsState()
4337 {
4338   if ( !desktop() )
4339     return;
4340
4341   bool storeWin = resourceMgr()->booleanValue( "Study", "store_positions", true );
4342   bool storeTb = resourceMgr()->booleanValue( "Study", "store_tool_positions", true );
4343
4344   if( !storeWin && !storeTb )
4345     return;
4346
4347   QString modName;
4348   if ( activeModule() )
4349     modName = activeModule()->name();
4350   else if ( activeStudy() )
4351     modName = "nomodule";
4352
4353   QString versionId = GUI_VERSION_STR;
4354 #if GUI_DEVELOPMENT > 0
4355   versionId += "dev";
4356 #endif
4357
4358   QByteArray arr = desktop()->saveState();
4359   resourceMgr()->setValue( "windows_geometry", modName, processState(arr, storeWin, storeTb, false) );
4360   resourceMgr()->setValue( "windows_geometry_version", modName, versionId );
4361
4362   QByteArray visArr;
4363   if ( myWinVis.contains( modName ) )
4364     visArr = myWinVis[modName];
4365
4366   QMap<QString, bool> tbMap, dwMap;
4367   dockWindowsState( visArr, tbMap, dwMap );
4368
4369   QList<QToolBar*> tbList = desktop()->findChildren<QToolBar*>();
4370   for ( QList<QToolBar*>::iterator it = tbList.begin(); it != tbList.end(); ++it )
4371   {
4372     QToolBar* tb = *it;
4373     tbMap.insert( tb->objectName(), tb->toggleViewAction()->isChecked() );
4374   }
4375
4376   QList<QDockWidget*> dwList = desktop()->findChildren<QDockWidget*>();
4377   for ( QList<QDockWidget*>::iterator it = dwList.begin(); it != dwList.end(); ++it )
4378   {
4379     QDockWidget* wid = *it;
4380     dwMap.insert( wid->objectName(), wid->toggleViewAction()->isChecked() );
4381   }
4382
4383   visArr = dockWindowsState( tbMap, dwMap );
4384
4385   myWinVis.insert( modName, visArr );
4386 }
4387
4388 QByteArray LightApp_Application::dockWindowsState( const QMap<QString, bool>& tb, const QMap<QString, bool>& dw ) const
4389 {
4390   QByteArray visArr;
4391   QDataStream stream( &visArr, QIODevice::WriteOnly );
4392
4393   stream << (uchar)ToolBarMarker;
4394   stream << tb.size();
4395   for ( QMap<QString, bool>::const_iterator tit = tb.begin(); tit != tb.end(); ++tit )
4396   {
4397     stream << tit.key();
4398     stream << (uchar)( tit.value() ? 1 : 0 );
4399   }
4400
4401   stream << (uchar)DockWidgetMarker;
4402   stream << dw.size();
4403   for ( QMap<QString, bool>::const_iterator wit = dw.begin(); wit != dw.end(); ++wit )
4404   {
4405     stream << wit.key();
4406     stream << (uchar)( wit.value() ? 1 : 0 );
4407   }
4408
4409   return visArr;
4410 }
4411
4412 void LightApp_Application::dockWindowsState( const QByteArray& arr, QMap<QString, bool>& tb, QMap<QString, bool>& dw ) const
4413 {
4414   tb.clear();
4415   dw.clear();
4416
4417   QByteArray visArr = arr;
4418   QDataStream stream( &visArr, QIODevice::ReadOnly );
4419
4420   uchar marker;
4421   stream >> marker;
4422   if ( marker != ToolBarMarker )
4423     return;
4424
4425   int lines;
4426   stream >> lines;
4427   for ( int i = 0; i < lines; ++i )
4428   {
4429     QString objectName;
4430     stream >> objectName;
4431     uchar shown;
4432     stream >> shown;
4433     tb.insert( objectName, shown );
4434   }
4435
4436   stream >> marker;
4437   if ( marker != DockWidgetMarker )
4438     return;
4439
4440   stream >> lines;
4441   for ( int j = 0; j < lines; ++j )
4442   {
4443     QString objectName;
4444     stream >> objectName;
4445     uchar shown;
4446     stream >> shown;
4447     dw.insert( objectName, shown );
4448   }
4449 }
4450
4451 /*!
4452   Adds icon names for modules
4453 */
4454 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
4455 {
4456   iconMap.clear();
4457
4458   SUIT_ResourceMgr* resMgr = resourceMgr();
4459   if ( !resMgr )
4460     return;
4461
4462   QStringList modList;
4463   modules( modList, false );
4464
4465   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
4466   {
4467     QString modName = *it;
4468     QString modIntr = moduleName( modName );
4469     QString modIcon = resMgr->stringValue( modIntr, "icon", QString() );
4470
4471     if ( modIcon.isEmpty() )
4472       continue;
4473
4474     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
4475       modIcon += QString( ".png" );
4476
4477     iconMap.insert( modName, modIcon );
4478   }
4479 }
4480
4481 /*!
4482   Inserts items in popup, which necessary for current application
4483 */
4484 void LightApp_Application::contextMenuPopup( const QString& type, QMenu* thePopup, QString& title )
4485 {
4486   //Add "Rename" item
4487   LightApp_SelectionMgr* selMgr = LightApp_Application::selectionMgr();
4488   bool cacheIsOn = selMgr->isSelectionCacheEnabled();
4489   selMgr->setSelectionCacheEnabled( true );
4490
4491   SUIT_DataBrowser* ob = objectBrowser();
4492
4493   CAM_Application::contextMenuPopup( type, thePopup, title );
4494
4495   if ( ob && type == ob->popupClientType() ) {
4496     thePopup->addSeparator();
4497     QAction* a = thePopup->addAction( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
4498     if ( ob->shortcutKey(SUIT_DataBrowser::UpdateShortcut) )
4499       a->setShortcut( ob->shortcutKey(SUIT_DataBrowser::UpdateShortcut) );
4500   }
4501
4502 #ifndef DISABLE_SALOMEOBJECT
4503   if ( selMgr && ob ) {
4504     SALOME_ListIO selected;
4505     selMgr->selectedObjects( selected );
4506     if(selected.Extent() == 1){
4507       Handle(SALOME_InteractiveObject) anIObject = selected.First();
4508       SUIT_DataObject* obj = findObject(anIObject->getEntry());
4509       if(obj && obj->renameAllowed()) {
4510         QAction* a = new QAction(tr("MEN_RENAME_OBJ"), thePopup);
4511         connect( a, SIGNAL( triggered(bool) ), ob, SLOT( onStartEditing() ) );
4512         if ( ob->shortcutKey(SUIT_DataBrowser::RenameShortcut) )
4513           a->setShortcut( ob->shortcutKey(SUIT_DataBrowser::RenameShortcut) );
4514
4515         QList<QAction*> acts = thePopup->actions();
4516         QAction* firstAction = acts.count() > 0 ? acts.first() : 0;
4517         thePopup->insertAction(firstAction,a);
4518       }
4519     }
4520   }
4521 #endif
4522
4523   selMgr->setSelectionCacheEnabled( cacheIsOn );
4524 }
4525
4526 /*!
4527   Create empty study
4528 */
4529 void LightApp_Application::createEmptyStudy()
4530 {
4531   CAM_Application::createEmptyStudy();
4532
4533   if ( objectBrowser() )
4534     objectBrowser()->updateTree();
4535
4536   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
4537   if ( aResMgr && activeStudy() ) {
4538     int autoSaveInterval = aResMgr->integerValue( "Study", "auto_save_interval", 0 );
4539     if ( autoSaveInterval > 0 ) myAutoSaveTimer->start( autoSaveInterval*60000 );
4540   }
4541 }
4542
4543 /*!Set desktop:*/
4544 void LightApp_Application::setDesktop( SUIT_Desktop* desk )
4545 {
4546   CAM_Application::setDesktop( desk );
4547
4548   if ( desk ) {
4549     connect( desk, SIGNAL( message( const QString& ) ),
4550              this, SLOT( onDesktopMessage( const QString& ) ), Qt::UniqueConnection );
4551     connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
4552              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
4553     /* connect( desk, SIGNAL( windowMoved( SUIT_ViewWindow* ) ),
4554              this, SLOT( onWindowMoved( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); */
4555   }
4556 }
4557
4558 /*!
4559   Activates module
4560   \param mod - module to be activated
4561 */
4562 bool LightApp_Application::activateModule( CAM_Module* mod )
4563 {
4564   bool res = CAM_Application::activateModule( mod );
4565
4566   if ( objectBrowser() )
4567     objectBrowser()->updateTree();
4568
4569   return res;
4570 }
4571
4572 /*!
4573   \return keyborad accelerators manager object
4574 */
4575 SUIT_Accel* LightApp_Application::accel() const
4576 {
4577   return myAccel;
4578 }
4579
4580 /*!
4581   Removes dead widget container from map
4582 */
4583 void LightApp_Application::onWCDestroyed( QObject* ob )
4584 {
4585   // remove destroyed widget container from windows map
4586   for ( WinMap::ConstIterator itr = myWin.begin(); itr != myWin.end(); ++itr )
4587   {
4588     if ( itr.value() != ob )
4589       continue;
4590
4591     int key = itr.key();
4592     myWin.remove( key );
4593     break;
4594   }
4595 }
4596
4597 void LightApp_Application::onMRUActivated( const QString& name )
4598 {
4599   SUIT_Session* s = SUIT_Session::session();
4600   if ( s && s->activeApplication() == this )
4601     onOpenDoc( name );
4602 }
4603
4604 void LightApp_Application::onStylePreferences()
4605 {
4606 #ifdef USE_SALOME_STYLE
4607   Style_PrefDlg dlg( desktop() );
4608   dlg.exec();
4609
4610   resourceMgr()->setValue( "Style", "use_salome_style", Style_Salome::isActive() );
4611 #endif // USE_SALOME_STYLE
4612 }
4613
4614 void LightApp_Application::onFullScreen(){
4615   if(myScreenHelper) {
4616     if(desktop()->isFullScreen())
4617       myScreenHelper->switchToNormalScreen();
4618     else
4619       myScreenHelper->switchToFullScreen();
4620   }
4621 }
4622
4623 /*!
4624   Connects just added view manager
4625 */
4626 void LightApp_Application::addViewManager( SUIT_ViewManager* vm )
4627 {
4628   connect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
4629            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
4630   CAM_Application::addViewManager( vm );
4631 }
4632
4633 /*!
4634   Remove view manager from memory
4635 */
4636 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
4637 {
4638   disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
4639            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
4640   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
4641   if (aStudy )
4642     aStudy->removeObjectProperties( vm->getGlobalId() );
4643
4644   CAM_Application::removeViewManager( vm );
4645
4646   LightApp_SelectionMgr* selMgr = selectionMgr();
4647   QList<SUIT_Selector*> selectors;
4648   selMgr->selectors( selectors );
4649   foreach( SUIT_Selector* selector, selectors ) {
4650     if ( selector->owner() == vm->getViewModel() ) {
4651       delete selector;
4652     }
4653   }
4654
4655   // IPAL22894: Crash on closing OCC view
4656   //delete vm;
4657   vm->deleteLater();
4658 }
4659
4660 /*!
4661   Renames active window of desktop
4662 */
4663 void LightApp_Application::onRenameWindow()
4664 {
4665   if( !desktop() )
4666     return;
4667
4668   QWidget* w = desktop()->activeWindow();
4669   if( !w )
4670     return;
4671
4672   bool ok;
4673   QString name = QInputDialog::getText( w, tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->windowTitle(), &ok );
4674   if( ok && !name.isEmpty() )
4675     w->setWindowTitle( name );
4676 }
4677
4678 /*!
4679   Closes active window of desktop
4680 */
4681 void LightApp_Application::onCloseWindow()
4682 {
4683   if( !desktop() )
4684     return;
4685
4686   QWidget* w = desktop()->activeWindow();
4687   if( !w )
4688     return;
4689
4690   w->close();
4691 }
4692
4693 /*!
4694   Closes all windows of desktop
4695 */
4696 void LightApp_Application::onCloseAllWindow()
4697 {
4698   STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
4699   if( !desk )
4700     return;
4701
4702   QList<SUIT_ViewWindow*> wndList = desk->windows();
4703   SUIT_ViewWindow* wnd;
4704   foreach( wnd, wndList )
4705   {
4706     if ( wnd )
4707       wnd->close();
4708   }
4709 }
4710
4711 /*!
4712   Groups all windows of desktop
4713 */
4714 void LightApp_Application::onGroupAllWindow()
4715 {
4716   STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
4717   if( !desk )
4718     return;
4719
4720   QtxWorkstack* wgStack = desk->workstack();
4721   if ( wgStack )
4722     wgStack->stack();
4723 }
4724
4725 /*!
4726   \return default name for an active study
4727 */
4728 void LightApp_Application::setDefaultStudyName( const QString& theName )
4729 {
4730   QStringList anInfoList;
4731   modules( anInfoList, false );
4732
4733   LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
4734   if( anInfoList.count() == 1 && // to avoid a conflict between different modules
4735       !aStudy->isSaved() )
4736   {
4737     aStudy->setStudyName( theName );
4738     updateDesktopTitle();
4739   }
4740 }
4741
4742 /*!
4743   Custom event handler
4744 */
4745 bool LightApp_Application::event( QEvent* e )
4746 {
4747   if( e && e->type()==2000 )
4748   {
4749     SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
4750     QString* d = ( QString* )ce->data();
4751     if( SUIT_MessageBox::question(0, tr("WRN_WARNING"),
4752                                   d ? *d : "",
4753                                   SUIT_MessageBox::Yes | SUIT_MessageBox::No,
4754                                   SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
4755     {
4756       QStringList path;
4757       path << tr( "PREF_CATEGORY_SALOME" ) << tr( "PREF_TAB_GENERAL" )
4758            << tr( "PREF_GROUP_EXT_BROWSER" ) << tr( "PREF_APP" );
4759       showPreferences( path );
4760     }
4761     if( d )
4762       delete d;
4763     return true;
4764   }
4765   return CAM_Application::event( e );
4766 }
4767
4768 /*! Check data object */
4769 bool LightApp_Application::checkDataObject(LightApp_DataObject* theObj)
4770 {
4771   if (theObj)
4772     {
4773       bool isSuitable = !theObj->entry().isEmpty() &&
4774                         !theObj->componentDataType().isEmpty() &&
4775                         !theObj->name().isEmpty();
4776       return isSuitable;
4777     }
4778
4779   return false;
4780 }
4781
4782 int LightApp_Application::openChoice( const QString& aName )
4783 {
4784   int choice = CAM_Application::openChoice( aName );
4785
4786   if ( choice == OpenExist ) // The document is already open.
4787   {
4788     // Do you want to reload it?
4789     if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "QUE_DOC_ALREADYOPEN" ).arg( aName ),
4790                                     SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No ) == SUIT_MessageBox::Yes )
4791       choice = OpenReload;
4792   }
4793
4794   return choice;
4795 }
4796
4797 bool LightApp_Application::openAction( const int choice, const QString& aName )
4798 {
4799   bool res = false;
4800   switch ( choice )
4801   {
4802   case OpenReload:
4803     {
4804       STD_Application* app = 0;
4805       SUIT_Session* session = SUIT_Session::session();
4806       QList<SUIT_Application*> appList = session->applications();
4807       for ( QList<SUIT_Application*>::iterator it = appList.begin(); it != appList.end() && !app; ++it )
4808       {
4809         if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName )
4810           app = ::qobject_cast<STD_Application*>( *it );
4811       }
4812
4813       if ( app )
4814       {
4815         app->onCloseDoc( false );
4816         appList = session->applications();
4817         STD_Application* other = 0;
4818         for ( QList<SUIT_Application*>::iterator it = appList.begin(); it != appList.end() && !other; ++it )
4819           other = ::qobject_cast<STD_Application*>( *it );
4820
4821         if ( other )
4822           res = other->onOpenDoc( aName );
4823       }
4824     }
4825     break;
4826   default:
4827     res = CAM_Application::openAction( choice, aName );
4828     break;
4829   }
4830
4831   return res;
4832 }
4833
4834 QStringList LightApp_Application::viewManagersTypes() const
4835 {
4836   QStringList aTypesList;
4837   aTypesList += myUserWmTypes;
4838 #ifndef DISABLE_GLVIEWER
4839   aTypesList<<GLViewer_Viewer::Type();
4840 #endif
4841 #ifndef DISABLE_PLOT2DVIEWER
4842   aTypesList<<Plot2d_Viewer::Type();
4843 #endif
4844 #ifndef DISABLE_QXGRAPHVIEWER
4845   aTypesList<<QxScene_Viewer::Type();
4846 #endif
4847 #ifndef DISABLE_PVVIEWER
4848   aTypesList<<PVViewer_Viewer::Type();
4849 #endif
4850 #ifndef DISABLE_PYVIEWER
4851   aTypesList<<PyViewer_Viewer::Type();
4852 #endif
4853 #ifndef DISABLE_OCCVIEWER
4854   aTypesList<<OCCViewer_Viewer::Type();
4855 #endif
4856 #ifndef DISABLE_VTKVIEWER
4857  #ifndef DISABLE_SALOMEOBJECT
4858   aTypesList<<SVTK_Viewer::Type();
4859  #else
4860   aTypesList<<VTKViewer_Viewer::Type();
4861  #endif
4862 #endif
4863   return aTypesList;
4864 }
4865 /*!
4866  * Removes all view managers of known types
4867  * Other view managers are ignored
4868  */
4869 void LightApp_Application::clearKnownViewManagers()
4870 {
4871   QStringList aTypesList = viewManagersTypes();
4872   QList<SUIT_ViewManager*> aMgrList;
4873   viewManagers( aMgrList );
4874   foreach (SUIT_ViewManager* aMgr, aMgrList) {
4875     if (aTypesList.contains(aMgr->getType()))
4876       removeViewManager(aMgr);
4877   }
4878 }
4879
4880 /*!
4881   Copy of current selection
4882  */
4883 void LightApp_Application::onCopy()
4884 {
4885   LightApp_Module* m = dynamic_cast<LightApp_Module*>( activeModule() );
4886   if( m )
4887     m->copy();
4888 }
4889
4890 /*!
4891   Paste of current data in clipboard
4892  */
4893 void LightApp_Application::onPaste()
4894 {
4895   LightApp_Module* m = dynamic_cast<LightApp_Module*>( activeModule() );
4896   if( m )
4897     m->paste();
4898 }
4899
4900 /*!
4901   Browse (i.e. set focus on) the published objects
4902   \param theIsApplyAndClose - flag indicating that the dialog for creating objects
4903                               has been accepted by Ok (or Apply & Close) button
4904   \param theIsOptimizedBrowsing - flag switching to optimized browsing mode
4905                                   (to select the first published object only)
4906   \return entry of the selected object
4907  */
4908 QString LightApp_Application::browseObjects( const QStringList& theEntryList,
4909                                              const bool theIsApplyAndClose,
4910                                              const bool theIsOptimizedBrowsing )
4911 {
4912   QString aResult;
4913   if( SUIT_ResourceMgr* aResourceMgr = resourceMgr() )
4914   {
4915     int aBrowsePolicy = aResourceMgr->integerValue( "ObjectBrowser", "browse_published_object", (int)BP_Never );
4916     switch( aBrowsePolicy )
4917     {
4918       case BP_Never:
4919         return aResult;
4920       case BP_ApplyAndClose:
4921         if( !theIsApplyAndClose )
4922           return aResult;
4923       case BP_Always:
4924       default:
4925         break;
4926     }
4927   }
4928
4929   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( activeStudy() );
4930   if( !aStudy )
4931     return aResult;
4932
4933   SUIT_DataBrowser* anOB = objectBrowser();
4934   if( !anOB )
4935     return aResult;
4936
4937   SUIT_AbstractModel* aModel = dynamic_cast<SUIT_AbstractModel*>( anOB->model() );
4938   if( !aModel )
4939     return aResult;
4940
4941   QStringListIterator anIter( theEntryList );
4942   if( theIsOptimizedBrowsing )
4943   {
4944     // go to the last entry
4945     anIter.toBack();
4946     if( anIter.hasPrevious() )
4947       anIter.previous();
4948   }
4949
4950   // scroll to each entry in the list
4951   // (in optimized mode - to the last entry only)
4952   QString anEntry;
4953   LightApp_DataObject* anObject = 0;
4954   while( anIter.hasNext() )
4955   {
4956     anEntry = anIter.next();
4957     if( !anEntry.isEmpty() )
4958     {
4959       anObject = aStudy->findObjectByEntry( anEntry );
4960       if( anObject )
4961       {
4962         QModelIndex anIndex = aModel->index( anObject );
4963         anOB->treeView()->scrollTo( anIndex );
4964       }
4965     }
4966   }
4967
4968   // always select the last object
4969   if( anObject && !anEntry.isEmpty() )
4970   {
4971     QList<SUIT_Selector*> aSelectorList;
4972     selectionMgr()->selectors( "ObjectBrowser", aSelectorList );
4973     if( !aSelectorList.isEmpty() )
4974     {
4975       if( LightApp_OBSelector* aSelector = dynamic_cast<LightApp_OBSelector*>( aSelectorList.first() ) )
4976       {
4977         bool anIsAutoBlock = aSelector->autoBlock();
4978
4979         // temporarily disable auto block, to emit LightApp_SelectionMgr::currentSelectionChanged() signal
4980         aSelector->setAutoBlock( false );
4981
4982         SUIT_DataOwnerPtrList aList;
4983 #ifndef DISABLE_SALOMEOBJECT
4984         Handle(SALOME_InteractiveObject) aSObj = new SALOME_InteractiveObject
4985           ( anObject->entry().toUtf8().constData(),
4986             anObject->componentDataType().toLatin1().constData(),
4987             anObject->name().toUtf8().constData() );
4988         LightApp_DataOwner* owner = new LightApp_DataOwner( aSObj  );
4989 #else
4990         LightApp_DataOwner* owner = new LightApp_DataOwner( anEntry );
4991 #endif
4992
4993         aList.append( owner );
4994         selectionMgr()->setSelected( aList );
4995         aResult = anEntry;
4996
4997         // restore auto block flag
4998         aSelector->setAutoBlock( anIsAutoBlock );
4999       }
5000     }
5001   }
5002
5003   return aResult;
5004 }
5005
5006 SUIT_DataObject* LightApp_Application::findObject( const QString& id ) const
5007 {
5008   LightApp_Study* study = dynamic_cast<LightApp_Study*>( activeStudy() );
5009   return study ? study->findObjectByEntry( id ) : 0;
5010 }
5011
5012 /*!
5013   Checks that an object can be renamed.
5014   \param entry entry of the object
5015   \brief Return \c true if object can be renamed
5016 */
5017 bool LightApp_Application::renameAllowed( const QString& /*entry*/) const {
5018   return false;
5019 }
5020
5021 /*!
5022   Rename object by entry.
5023   \param entry entry of the object
5024   \param name new name of the object
5025   \brief Return \c true if rename operation finished successfully, \c false otherwise.
5026 */
5027 bool LightApp_Application::renameObject( const QString& /*entry*/, const QString& /*name*/ ) {
5028   return false;
5029 }
5030
5031 /*! Process standard messages from desktop */
5032 void LightApp_Application::onDesktopMessage( const QString& message )
5033 {
5034   const QString sectionSeparator = "/";
5035
5036   if ( message.toLower() == "updateobjectbrowser" ||
5037        message.toLower() == "updateobjbrowser" ) {
5038     // update object browser
5039     updateObjectBrowser();
5040   }
5041   else if ( message.toLower().startsWith( "activate_viewer" ) ) {
5042     QString vtype = message.split( sectionSeparator ).last();
5043     if ( !vtype.isEmpty() )
5044       getViewManager( vtype, true );
5045   }
5046   else if ( message.toLower().startsWith("register_module_in_study" ) ) {
5047     QString moduleName = message.split( sectionSeparator ).last();
5048     // Check name of current activating module name in order to avoid ciclik 
5049     // call because of messages
5050     if (!property("activateModule").toBool()) {
5051       CAM_Module* mod = module(moduleName);
5052       if (!mod)
5053         mod = module(moduleTitle(moduleName));
5054       if (!mod) {
5055         mod = loadModule(moduleName);
5056         if (!mod)
5057           mod = loadModule(moduleTitle(moduleName));
5058         if (mod) {
5059           addModule(mod);
5060         }
5061       }
5062       if (mod) {
5063         CAM_Study* anActiveStudy = dynamic_cast<CAM_Study*>(activeStudy());
5064         if (anActiveStudy) {
5065           mod->connectToStudy(anActiveStudy);
5066           LightApp_DataModel* aDM = dynamic_cast<LightApp_DataModel*>(mod->dataModel());
5067           if(aDM) {
5068             aDM->initRootObject();
5069           }
5070         }
5071       }
5072     }
5073   }
5074   else {
5075     QStringList data = message.split( sectionSeparator );
5076     if ( data.count() > 1 ) {
5077       QString msgType = data[0].trimmed();
5078       LightApp_Module* sMod = 0;
5079       CAM_Module* mod = module( msgType );
5080       if ( !mod )
5081         mod = module( moduleTitle( msgType ) );
5082       if ( mod && mod->inherits( "LightApp_Module" ) )
5083         sMod = (LightApp_Module*)mod;
5084
5085       if ( msgType.toLower() == "preferences" ) {
5086         // requested preferences change: should be given as "preferences/<section>/<name>/<value>"
5087         // for example "preferences/Study/multi_file_dump/true"
5088         if ( data.count() > 3 ) {
5089           QString section = data[1].trimmed();
5090           QString param   = data[2].trimmed();
5091           QString value   = QStringList( data.mid(3) ).join( sectionSeparator );
5092           resourceMgr()->setValue( section, param, value );
5093         }
5094       }
5095       else if ( sMod ) {
5096         // received message for the module
5097         QString msg = QStringList( data.mid(1) ).join( sectionSeparator );
5098         sMod->message( msg );
5099       }
5100     }
5101   }
5102 }
5103
5104 void LightApp_Application::onInfoPanelShown()
5105 {
5106   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
5107     ((LightApp_Module*)activeModule())->updateInfoPanel();
5108 }
5109
5110 /*!
5111   Internal method. 
5112   Returns all top level toolbars.
5113   Note : Result list contains only main window toolbars, not including toolbars from viewers.
5114 */
5115 QList<QToolBar*> LightApp_Application::findToolBars( const QStringList& names )
5116 {
5117   QList<QToolBar*> aResult;
5118   QList<QToolBar*> tbList = desktop()->findChildren<QToolBar*>();
5119   for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit ) {
5120     QToolBar* tb = *tit;
5121     QObject* po = Qtx::findParent( tb, "QMainWindow" );
5122     if ( po != desktop() )
5123       continue;
5124     if ( names.isEmpty() || names.contains( tb->objectName() ) )
5125       aResult.append(tb);
5126   }
5127   return aResult;
5128 }
5129
5130 /*!
5131   Internal method to parse toolbars and dockable windows state.
5132 */
5133 QByteArray LightApp_Application::processState(QByteArray& input,
5134                                               const bool processWin,
5135                                               const bool processTb,
5136                                               const bool isRestoring,
5137                                               QByteArray defaultState) {
5138
5139   QByteArray aRes;
5140   bool hasDefaultState  = !defaultState.isEmpty();
5141   bool isDockWinWriten = false;
5142   int nbDocWin = -1;
5143   //Write date from users settings
5144   if(isRestoring){
5145     QDataStream tmpInputData(&input, QIODevice::ReadOnly);
5146     int marker, version;
5147     uchar dockmarker;
5148     tmpInputData >> marker;
5149     tmpInputData >> version;
5150     tmpInputData >> dockmarker;
5151     tmpInputData >> nbDocWin;
5152   }
5153   if(processWin && processTb && !isRestoring) {
5154     aRes = input;
5155   } else if(!processWin && !processTb ) {
5156     if(hasDefaultState)
5157       aRes = defaultState;
5158   } else {
5159     QDataStream aData(&aRes, QIODevice::WriteOnly);
5160     QList<QToolBar*> aToolBars = findToolBars();
5161
5162     QStringList aNames;
5163     for ( QList<QToolBar*>::iterator tit = aToolBars.begin(); tit != aToolBars.end(); ++tit ) {
5164       QToolBar* tb = *tit;
5165       aNames.append(tb->objectName());
5166     }
5167
5168     int toolBarMarkerIndex = getToolbarMarkerIndex(input,aNames);
5169     if(toolBarMarkerIndex < 0)
5170       return aRes;
5171     QDataStream anInputData(&input, QIODevice::ReadOnly);
5172
5173     int toolBarMarkerIndexDef = 0;
5174     if(hasDefaultState) {
5175       toolBarMarkerIndexDef = getToolbarMarkerIndex(defaultState, aNames);
5176       if(toolBarMarkerIndexDef < 0)
5177         return aRes;
5178     }
5179     QDataStream anInputDataDef(&defaultState, QIODevice::ReadOnly);
5180
5181     QDataStream* aTargetData = 0;
5182     int          aTargetIndex = -1;
5183
5184     QByteArray currentArr = desktop()->saveState();
5185     QDataStream anInputDataCur(&currentArr, QIODevice::ReadOnly);
5186     bool useInputData = !isRestoring || (isRestoring && nbDocWin > 0);
5187     if(processWin && useInputData) {
5188       aTargetData = &anInputData;
5189       aTargetIndex = toolBarMarkerIndex;
5190     } else {
5191       //Write date from default settings
5192       if(hasDefaultState) {
5193         aTargetData = &anInputDataDef;
5194         aTargetIndex = toolBarMarkerIndexDef;
5195       } else {
5196         //If no default state, write current snapshot of the dockable windows
5197         if(isRestoring) {
5198           aTargetData = &anInputDataCur;
5199           int toolBarMarkerIndexCur = getToolbarMarkerIndex(currentArr, aNames);
5200           aTargetIndex = toolBarMarkerIndexCur;
5201         }
5202       }
5203     }
5204
5205     if(aTargetData && aTargetIndex >= 0 ) {
5206       aTargetData->device()->seek(0);
5207       while( aTargetData->device()->pos() < aTargetIndex ) {
5208         uchar ch;
5209         *aTargetData >> ch;
5210         aData<<ch;
5211       }
5212       isDockWinWriten = true;
5213     }
5214
5215     aTargetData = 0;
5216     aTargetIndex = -1;
5217
5218     if(processTb) {
5219       aTargetData = &anInputData;
5220       aTargetIndex = toolBarMarkerIndex;
5221     } else {
5222       if(hasDefaultState) {
5223         aTargetData = &anInputDataDef;
5224         aTargetIndex = toolBarMarkerIndexDef;
5225       }
5226     }
5227
5228     if(aTargetData && aTargetIndex >= 0) {
5229       int index;
5230       if(!isDockWinWriten ) {
5231         //Write version marker
5232         int marker, version;
5233         aTargetData->device()->seek(0);
5234         *aTargetData >> marker;
5235         *aTargetData >> version;
5236         aData << marker;
5237         aData << version;
5238         aData << (uchar) QDockWidgetMarker;
5239         aData << (int) 0;
5240         int shift = 4*sizeof(int) + sizeof(QSize);
5241         index = aTargetIndex - shift;
5242       } else {
5243         index = aTargetIndex;
5244       }
5245
5246       aTargetData->device()->seek(index);
5247       while(!aTargetData->atEnd()) {
5248         uchar ch;
5249         *aTargetData >> ch;
5250         aData << ch;
5251       }
5252     } else { // Not treat toolbars
5253       aData << (uchar) QToolBarMarker;
5254       aData << (int) 0; //Nb toolbars = 0
5255     }
5256   }
5257   return aRes;
5258 }
5259
5260 /*!
5261   \brief Emits operationFinished signal.
5262   \param theModuleName the name of the module which perfomed the operation
5263   \param theOperationName the operation name
5264   \param theEntryList the list of the created objects entries
5265 */
5266 void LightApp_Application::emitOperationFinished( const QString& theModuleName,
5267                                                   const QString& theOperationName,
5268                                                   const QStringList& theEntryList )
5269 {
5270   emit operationFinished( theModuleName, theOperationName, theEntryList );
5271 }
5272
5273 /*!
5274   Update visibility state of given objects
5275 */
5276 void LightApp_Application::updateVisibilityState( DataObjectList& theList,
5277                                                   SUIT_ViewModel* theViewModel )
5278 {
5279   if ( !theViewModel || theList.isEmpty() ) return;
5280
5281   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
5282   if ( !aStudy ) return;
5283
5284   SALOME_View* aView = dynamic_cast<SALOME_View*>( theViewModel );
5285
5286   for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) {
5287     LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(*itr);
5288
5289     if ( !obj || aStudy->isComponent( obj->entry() ) )
5290       continue;
5291
5292     QString mname = aStudy->componentDataType(obj->entry());
5293     LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(mname, false);
5294     if ( aDisplayer ) {
5295       Qtx::VisibilityState anObjState = Qtx::UnpresentableState;
5296       if ( aDisplayer->canBeDisplayed( obj->entry(), theViewModel->getType() ) ) {
5297         if ( aDisplayer->IsDisplayed( obj->entry(), aView ) )
5298           anObjState = Qtx::ShownState;
5299         else
5300           anObjState = Qtx::HiddenState;
5301       }
5302       aStudy->setVisibilityState( obj->entry(), anObjState );
5303     }
5304   }
5305 }
5306
5307 /*!
5308   Update presentations of all displayed objects of theComponent in specified viewers
5309 */
5310 void LightApp_Application::updatePresentations( const QString& theComponent,
5311                                                 const QStringList& theViewManagerTypes )
5312 {
5313   LightApp_Displayer* aDisplayer = LightApp_Displayer::FindDisplayer(theComponent, false);
5314   if ( aDisplayer ) {
5315     LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
5316     DataObjectList aComps;
5317     bool isFound = false;
5318     aStudy->root()->children( aComps );
5319     DataObjectList::const_iterator aCompsIt = aComps.begin();
5320     for ( ; aCompsIt != aComps.end() && !isFound; aCompsIt++ ) {
5321       LightApp_DataObject* aComp = dynamic_cast<LightApp_DataObject*>( *aCompsIt );
5322       if ( aComp && aComp->componentDataType() ==  theComponent) {
5323         isFound = true;
5324         DataObjectList anObjs;
5325         aComp->children(anObjs, true);
5326
5327         QList<SUIT_ViewManager*> aViewMgrs;
5328         QStringList::const_iterator itVMTypes = theViewManagerTypes.begin();
5329         for ( ; itVMTypes != theViewManagerTypes.end(); ++itVMTypes )
5330           viewManagers( *itVMTypes, aViewMgrs );
5331
5332         DataObjectList::const_iterator itObjs = anObjs.begin();
5333         for ( ; itObjs != anObjs.end(); itObjs++ ) {
5334           LightApp_DataObject* anObj = dynamic_cast<LightApp_DataObject*>( *itObjs );
5335           QString anEntry = anObj->entry();
5336
5337           QListIterator<SUIT_ViewManager*> itViewMgrs( aViewMgrs );
5338           while ( itViewMgrs.hasNext()) {
5339             SUIT_ViewModel* aVM = itViewMgrs.next()->getViewModel();
5340             if ( aVM ) {
5341               SALOME_View* aView = dynamic_cast<SALOME_View*>(aVM);
5342               if ( aView ) {
5343                 bool isDisp = aDisplayer->IsDisplayed( anEntry, aView );
5344                 aDisplayer->Erase( anEntry, true, false, aView );
5345                 if ( isDisp ) {
5346                   aDisplayer->Display( anEntry, false, aView );
5347                 }
5348               }
5349             }
5350           }
5351         }
5352       }
5353     }
5354   }
5355 }
5356
5357 /*!
5358  * Called when window activated
5359  */
5360 void LightApp_Application::onWindowActivated( SUIT_ViewWindow* theViewWindow )
5361 {
5362   SUIT_DataBrowser* anOB = objectBrowser();
5363   if ( !anOB )
5364     return;
5365   SUIT_DataObject* rootObj = anOB->root();
5366   if ( !rootObj )
5367     return;
5368
5369   DataObjectList listObj = rootObj->children( true );
5370
5371   SUIT_ViewModel* vmod = 0;
5372   if ( SUIT_ViewManager* vman = theViewWindow->getViewManager() )
5373     vmod = vman->getViewModel();
5374   updateVisibilityState( listObj, vmod );
5375 }
5376
5377 /*!
5378   Called then view manager removed
5379 */
5380 void LightApp_Application::onViewManagerRemoved( SUIT_ViewManager* )
5381 {
5382   ViewManagerList lst;
5383   viewManagers( lst );
5384   if ( lst.count() == 1) { // in case if closed last view window
5385     LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( activeStudy() );
5386     if ( aStudy )
5387       aStudy->setVisibilityStateForAll( Qtx::UnpresentableState );
5388   }
5389 }
5390
5391 /*!
5392   Check existing document.
5393 */
5394 bool LightApp_Application::checkExistingDoc( bool closeExistingDoc )
5395 {
5396   bool result = true;
5397   if( activeStudy() ) {
5398     int answer = !activeStudy()->isModified() ? 1 :
5399                  SUIT_MessageBox::question( desktop(),
5400                                             tr( "APPCLOSE_CAPTION" ),
5401                                             tr( "STUDYCLOSE_DESCRIPTION" ),
5402                                             tr( "APPCLOSE_SAVE" ),
5403                                             tr( "APPCLOSE_CLOSE" ),
5404                                             tr( "APPCLOSE_CANCEL" ), 0 );
5405     if(answer == 0) {
5406       if ( activeStudy()->isSaved() ) {
5407         onSaveDoc();
5408                 if (closeExistingDoc) {
5409                         closeDoc(false);
5410                 }
5411       } else if ( onSaveAsDoc() ) {
5412          if (closeExistingDoc) {
5413            if( !closeDoc( false ) ) {
5414              result = false;
5415            }
5416         }
5417       } else {
5418         result = false;
5419       }
5420     }
5421     else if( answer == 1 ) {
5422       if (closeExistingDoc) {
5423         closeDoc( false );
5424       }
5425     } else if( answer == 2 ) {
5426       result = false;
5427     }
5428   }
5429   return result;
5430 }
5431
5432 #ifndef DISABLE_PYCONSOLE
5433
5434 PyConsole_Interp* LightApp_Application::getPyInterp()
5435 {
5436   static PyConsole_Interp* myInterp = 0;
5437   if ( !myInterp ) {
5438     myInterp = createPyInterp();
5439     myInterp->initialize();
5440   }
5441   return myInterp;
5442 }
5443
5444 PyConsole_Interp* LightApp_Application::createPyInterp()
5445 {
5446   return new PyConsole_Interp();
5447 }
5448
5449 #endif // DISABLE_PYCONSOLE