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