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