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