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