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