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