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