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