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