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