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