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