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