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