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