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