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