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