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