Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / LightApp / LightApp_Application.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      LightApp_Application.cxx
23 // Created:   6/20/2005 18:39:45 PM
24 // Author:    Natalia Donis
25 //
26 #ifndef DISABLE_PYCONSOLE
27   #include <PyConsole_Interp.h> // WARNING! This include must be the first!
28   #include <PyConsole_Console.h>
29 #endif
30
31 #include "LightApp_Application.h"
32 #include "LightApp_Module.h"
33 #include "LightApp_DataModel.h"
34 #include "LightApp_Study.h"
35 #include "LightApp_Preferences.h"
36 #include "LightApp_PreferencesDlg.h"
37 #include "LightApp_ModuleDlg.h"
38 #include "LightApp_AboutDlg.h"
39 #include "LightApp_ModuleAction.h"
40 // temporary commented
41 //#include "LightApp_OBFilter.h"
42 #include "LightApp_EventFilter.h"
43 #include "LightApp_OBSelector.h"
44 #include "LightApp_SelectionMgr.h"
45 #include "LightApp_DataObject.h"
46
47 #include <SALOME_Event.h>
48
49 #include <Style_Salome.h>
50 #include <Style_PrefDlg.h>
51
52 #include <CAM_Module.h>
53 #include <CAM_DataModel.h>
54 #include <CAM_Study.h>
55 #include <STD_TabDesktop.h>
56
57 #include <SUIT_DataBrowser.h>
58 #include <SUIT_Session.h>
59 #include <SUIT_Study.h>
60 #include <SUIT_FileDlg.h>
61 #include <SUIT_ResourceMgr.h>
62 #include <SUIT_Tools.h>
63 #include <SUIT_Accel.h>
64 #include <SUIT_MessageBox.h>
65 #include <SUIT_ViewWindow.h>
66
67 #include <Qtx.h>
68 #include <QtxToolBar.h>
69 #include <QtxTreeView.h>
70 #include <QtxMRUAction.h>
71 #include <QtxDockAction.h>
72 #include <QtxDockWidget.h>
73 #include <QtxActionToolMgr.h>
74 #include <QtxSearchTool.h>
75 #include <QtxWorkstack.h>
76
77 #include <LogWindow.h>
78
79 #ifndef DISABLE_GLVIEWER
80   #include <GLViewer_Viewer.h>
81   #include <GLViewer_ViewManager.h>
82   #include "LightApp_GLSelector.h"
83 #endif
84
85 #ifndef DISABLE_PLOT2DVIEWER
86   #include <Plot2d_ViewManager.h>
87   #include <Plot2d_ViewModel.h>
88   #include "LightApp_Plot2dSelector.h"
89 #ifndef DISABLE_SALOMEOBJECT
90   #include <SPlot2d_ViewModel.h>
91 #else
92   #include <Plot2d_ViewModel.h>
93 #endif
94 #endif
95
96 #include <QxScene_ViewManager.h>
97 #include <QxScene_ViewModel.h>
98 #include <QxScene_ViewWindow.h>
99
100 #ifndef DISABLE_OCCVIEWER
101   #include <OCCViewer_ViewManager.h>
102 #ifndef DISABLE_SALOMEOBJECT
103   #include <SOCC_ViewModel.h>
104 #else
105   #include <OCCViewer_ViewModel.h>
106 #endif
107   #include "LightApp_OCCSelector.h"
108 #endif
109
110 #ifndef DISABLE_VTKVIEWER
111 #ifndef DISABLE_SALOMEOBJECT
112   #include <SVTK_ViewModel.h>
113   #include <SVTK_ViewManager.h>
114   #include "LightApp_VTKSelector.h"
115 #else
116   #include <VTKViewer_ViewModel.h>
117   #include <VTKViewer_ViewManager.h>
118 #endif
119   #include <VTKViewer_ViewModel.h>
120 #endif
121
122 //#ifndef DISABLE_SUPERVGRAPHVIEWER
123 //  #include <SUPERVGraph_ViewModel.h>
124 //  #include <SUPERVGraph_ViewFrame.h>
125 //  #include <SUPERVGraph_ViewManager.h>
126 //#endif
127
128 #ifndef DISABLE_QXGRAPHVIEWER
129   #include <QxGraph_ViewModel.h>
130   #include <QxGraph_ViewWindow.h>
131   #include <QxGraph_ViewManager.h>
132 #endif
133
134 #include <QDir>
135 #include <QImage>
136 #include <QString>
137 #include <QWidget>
138 #include <QStringList>
139 #include <QFile>
140 #include <QApplication>
141 #include <QMap>
142 #include <QStatusBar>
143 #include <QThread>
144 #include <QObjectList>
145 #include <QComboBox>
146 #include <QInputDialog>
147 #include <QFontDatabase>
148 #include <QIcon>
149 #include <QByteArray>
150 #include <QMenu>
151 #include <QProcess>
152
153 #include <utilities.h>
154
155 #define FIRST_HELP_ID 1000000
156
157 #ifndef DISABLE_SALOMEOBJECT
158   #include <SALOME_InteractiveObject.hxx>
159   #include <SALOME_ListIO.hxx>
160 #endif
161
162 #define ToolBarMarker    0
163 #define DockWidgetMarker 1
164
165 static const char* imageEmptyIcon[] = {
166 "20 20 1 1",
167 ".      c None",
168 "....................",
169 "....................",
170 "....................",
171 "....................",
172 "....................",
173 "....................",
174 "....................",
175 "....................",
176 "....................",
177 "....................",
178 "....................",
179 "....................",
180 "....................",
181 "....................",
182 "....................",
183 "....................",
184 "....................",
185 "....................",
186 "....................",
187 "...................."};
188
189 int LightApp_Application::lastStudyId = 0;
190
191 /*!
192   \return last global id of study
193 */
194 int LightApp_Application::studyId()
195 {
196   return LightApp_Application::lastStudyId;
197 }
198
199 /*!Create new instance of LightApp_Application.*/
200 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
201 {
202   return new LightApp_Application();
203 }
204
205 /*! \var global preferences of LightApp */
206 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
207
208 /*!
209   \class LightApp_Application
210   Application containing LightApp module
211 */
212
213 /*!Constructor.*/
214 LightApp_Application::LightApp_Application()
215 : CAM_Application( false ),
216   myPrefs( 0 )
217 {
218   STD_TabDesktop* desk = new STD_TabDesktop();
219
220   setDesktop( desk );
221
222   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
223   QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
224
225   desktop()->setWindowIcon( aLogo );
226   desktop()->setDockableMenuBar( false );
227   desktop()->setDockableStatusBar( false );
228
229   // base logo (salome itself)
230   desktop()->logoInsert( "_app_base",  aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
231   // extra logo (salome-based application)
232   desktop()->logoInsert( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
233
234   clearViewManagers();
235
236   mySelMgr = new LightApp_SelectionMgr( this );
237
238   myAccel = SUIT_Accel::getAccel();
239
240 #ifndef DISABLE_OCCVIEWER
241   myAccel->setActionKey( SUIT_Accel::PanLeft,     Qt::CTRL+Qt::Key_Left,     OCCViewer_Viewer::Type() );
242   myAccel->setActionKey( SUIT_Accel::PanRight,    Qt::CTRL+Qt::Key_Right,    OCCViewer_Viewer::Type() );
243   myAccel->setActionKey( SUIT_Accel::PanUp,       Qt::CTRL+Qt::Key_Up,       OCCViewer_Viewer::Type() );
244   myAccel->setActionKey( SUIT_Accel::PanDown,     Qt::CTRL+Qt::Key_Down,     OCCViewer_Viewer::Type() );
245   myAccel->setActionKey( SUIT_Accel::ZoomIn,      Qt::CTRL+Qt::Key_Plus,     OCCViewer_Viewer::Type() );
246   myAccel->setActionKey( SUIT_Accel::ZoomOut,     Qt::CTRL+Qt::Key_Minus,    OCCViewer_Viewer::Type() );
247   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::CTRL+Qt::Key_Asterisk, OCCViewer_Viewer::Type() );
248   myAccel->setActionKey( SUIT_Accel::RotateLeft,  Qt::ALT+Qt::Key_Left,      OCCViewer_Viewer::Type() );
249   myAccel->setActionKey( SUIT_Accel::RotateRight, Qt::ALT+Qt::Key_Right,     OCCViewer_Viewer::Type() );
250   myAccel->setActionKey( SUIT_Accel::RotateUp,    Qt::ALT+Qt::Key_Up,        OCCViewer_Viewer::Type() );
251   myAccel->setActionKey( SUIT_Accel::RotateDown,  Qt::ALT+Qt::Key_Down,      OCCViewer_Viewer::Type() );
252 #endif
253 #ifndef DISABLE_VTKVIEWER
254   myAccel->setActionKey( SUIT_Accel::PanLeft,     Qt::CTRL+Qt::Key_Left,     VTKViewer_Viewer::Type() );
255   myAccel->setActionKey( SUIT_Accel::PanRight,    Qt::CTRL+Qt::Key_Right,    VTKViewer_Viewer::Type() );
256   myAccel->setActionKey( SUIT_Accel::PanUp,       Qt::CTRL+Qt::Key_Up,       VTKViewer_Viewer::Type() );
257   myAccel->setActionKey( SUIT_Accel::PanDown,     Qt::CTRL+Qt::Key_Down,     VTKViewer_Viewer::Type() );
258   myAccel->setActionKey( SUIT_Accel::ZoomIn,      Qt::CTRL+Qt::Key_Plus,     VTKViewer_Viewer::Type() );
259   myAccel->setActionKey( SUIT_Accel::ZoomOut,     Qt::CTRL+Qt::Key_Minus,    VTKViewer_Viewer::Type() );
260   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::CTRL+Qt::Key_Asterisk, VTKViewer_Viewer::Type() );
261   myAccel->setActionKey( SUIT_Accel::RotateLeft,  Qt::ALT+Qt::Key_Left,      VTKViewer_Viewer::Type() );
262   myAccel->setActionKey( SUIT_Accel::RotateRight, Qt::ALT+Qt::Key_Right,     VTKViewer_Viewer::Type() );
263   myAccel->setActionKey( SUIT_Accel::RotateUp,    Qt::ALT+Qt::Key_Up,        VTKViewer_Viewer::Type() );
264   myAccel->setActionKey( SUIT_Accel::RotateDown,  Qt::ALT+Qt::Key_Down,      VTKViewer_Viewer::Type() );
265 #endif
266 #ifndef DISABLE_PLOT2DVIEWER
267   myAccel->setActionKey( SUIT_Accel::PanLeft,     Qt::CTRL+Qt::Key_Left,     Plot2d_Viewer::Type() );
268   myAccel->setActionKey( SUIT_Accel::PanRight,    Qt::CTRL+Qt::Key_Right,    Plot2d_Viewer::Type() );
269   myAccel->setActionKey( SUIT_Accel::PanUp,       Qt::CTRL+Qt::Key_Up,       Plot2d_Viewer::Type() );
270   myAccel->setActionKey( SUIT_Accel::PanDown,     Qt::CTRL+Qt::Key_Down,     Plot2d_Viewer::Type() );
271   myAccel->setActionKey( SUIT_Accel::ZoomIn,      Qt::CTRL+Qt::Key_Plus,     Plot2d_Viewer::Type() );
272   myAccel->setActionKey( SUIT_Accel::ZoomOut,     Qt::CTRL+Qt::Key_Minus,    Plot2d_Viewer::Type() );
273   myAccel->setActionKey( SUIT_Accel::ZoomFit,     Qt::CTRL+Qt::Key_Asterisk, Plot2d_Viewer::Type() );
274 #endif
275
276   connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
277
278   // Set existing font for the python console in resources
279   if( !aResMgr->hasValue( "PyConsole", "font" ) )
280     return;
281
282   QFont f = aResMgr->fontValue( "PyConsole", "font" );
283   QFontDatabase fdb;
284   QStringList famdb = fdb.families();
285
286   if ( famdb.contains(f.family()) || !aResMgr->hasValue( "PyConsole", "additional_families" ) )
287     return;
288
289   QStringList anAddFamilies = aResMgr->stringValue( "PyConsole", "additional_families" ).split( ";", QString::SkipEmptyParts );
290   QString aFamily;
291   for ( QStringList::Iterator it = anAddFamilies.begin(); it != anAddFamilies.end(); ++it )
292     {
293       aFamily = *it;
294       if ( famdb.contains(aFamily) )
295         {
296           f.setFamily( aFamily );
297           aResMgr->setValue( "PyConsole", "font", f );
298           break;
299         }
300     }
301 }
302
303 /*!Destructor.
304  *\li Save window geometry.
305  *\li Save desktop geometry.
306  *\li Save resource maneger.
307  *\li Delete selection manager.
308  */
309 LightApp_Application::~LightApp_Application()
310 {
311   delete mySelMgr;
312 }
313
314 /*!Start application.*/
315 void LightApp_Application::start()
316 {
317   CAM_Application::start();
318
319   updateWindows();
320   updateViewManagers();
321
322   putInfo( "" );
323   desktop()->statusBar()->showMessage( "" );
324
325   LightApp_EventFilter::Init();
326 }
327
328 /*!Gets application name.*/
329 QString LightApp_Application::applicationName() const
330 {
331   return tr( "APP_NAME" );
332 }
333
334 /*!Gets application version.*/
335 QString LightApp_Application::applicationVersion() const
336 {
337   static QString _app_version;
338
339   if ( _app_version.isEmpty() )
340   {
341     QString resVersion = tr( "APP_VERSION" );
342     if ( resVersion != "APP_VERSION" )
343     {
344       _app_version = resVersion;
345     }
346     else
347     {
348       QString path( ::getenv( "GUI_ROOT_DIR" ) );
349       if ( !path.isEmpty() )
350         path += QDir::separator();
351       path += QString( "bin/salome/VERSION" );
352
353       QFile vf( path );
354       if ( vf.open( QIODevice::ReadOnly ) )
355       {
356         QString line( vf.readLine( 1024 ) );
357         vf.close();
358
359         if ( !line.isEmpty() )
360         {
361           while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
362             line.remove( line.length() - 1, 1 );
363
364           int idx = line.lastIndexOf( ":" );
365           if ( idx != -1 )
366             _app_version = line.mid( idx + 1 ).trimmed();
367         }
368       }
369     }
370   }
371   return _app_version;
372 }
373
374 /*!Load module by \a name.*/
375 CAM_Module* LightApp_Application::loadModule( const QString& name, const bool showMsg )
376 {
377   CAM_Module* mod = CAM_Application::loadModule( name, showMsg );
378   if ( mod )
379   {
380     connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
381     connect( this, SIGNAL( studySaved() ),  mod, SLOT( onModelSaved() ) );
382     connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
383   }
384   return mod;
385 }
386
387 /*!Activate module by \a modName*/
388 bool LightApp_Application::activateModule( const QString& modName )
389 {
390   QString actName;
391   CAM_Module* prevMod = activeModule();
392
393   if ( prevMod )
394     actName = prevMod->moduleName();
395
396   if ( actName == modName )
397     return true;
398
399   putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
400
401   saveDockWindowsState();
402
403   bool status = CAM_Application::activateModule( modName );
404
405   updateModuleActions();
406
407   putInfo( "" );
408
409   if ( !status )
410     return false;
411
412   updateWindows();
413   updateViewManagers();
414
415   return true;
416 }
417
418 /*!Gets selection manager.*/
419 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
420 {
421   return mySelMgr;
422 }
423
424 /*!Creat action "New window" for certain type of viewer:*/
425 void LightApp_Application::createActionForViewer( const int id,
426                                                   const int parentId,
427                                                   const QString& suffix,
428                                                   const int accel )
429 {
430   QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( suffix ).toLatin1().constData() ), QIcon(),
431                              tr( QString( "NEW_WINDOW_%1" ).arg( suffix ).toLatin1().constData() ),
432                              tr( QString( "NEW_WINDOW_%1" ).arg( suffix ).toLatin1().constData() ),
433                              accel, desktop(), false, this, SLOT( onNewWindow() ) );
434   createMenu( a, parentId, -1 );
435 }
436
437 /*!Create actions:*/
438 void LightApp_Application::createActions()
439 {
440   STD_Application::createActions();
441
442   SUIT_Desktop* desk = desktop();
443   SUIT_ResourceMgr* resMgr = resourceMgr();
444
445   //! Preferences
446   createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIcon(),
447                 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
448                 Qt::CTRL+Qt::Key_R, desk, false, this, SLOT( onPreferences() ) );
449
450   //! Help for modules
451   int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
452   int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
453   createMenu( separator(), helpMenu, -1, 1 );
454
455   QStringList aModuleList;
456   modules( aModuleList, false );
457
458   int id = LightApp_Application::UserID + FIRST_HELP_ID;
459   // help for KERNEL and GUI
460   QString dir;//QByteArray dir;
461   QString aFileName = "index.html";
462   QString root;
463   QAction* a;
464   dir = getenv("GUI_ROOT_DIR");
465   if ( !dir.isEmpty() ) {
466     root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") +
467                           Qtx::addSlash("salome") + Qtx::addSlash("gui") +  Qtx::addSlash("GUI") );
468     if ( QFileInfo( root + aFileName ).exists() ) {
469       a = createAction( id, tr( QString("GUI Help").toLatin1().constData() ),
470                         resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false ),
471                         tr( QString("GUI Help").toLatin1().constData() ),
472                         tr( QString("GUI Help").toLatin1().constData() ),
473                         0, desk, false, this, SLOT( onHelpContentsModule() ) );
474       a->setObjectName( QString("GUI") );
475       createMenu( a, helpModuleMenu, -1 );
476       id++;
477     }
478   }
479   dir = getenv("KERNEL_ROOT_DIR");
480   if ( !dir.isEmpty() ) {
481     root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") +
482                           Qtx::addSlash("salome") );
483     if ( QFileInfo( root + aFileName ).exists() ) {
484       a = createAction( id, tr( QString("KERNEL Help").toLatin1().constData() ),
485                         resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false ),
486                         tr( QString("KERNEL Help").toLatin1().constData() ),
487                         tr( QString("KERNEL Help").toLatin1().constData() ),
488                         0, desk, false, this, SLOT( onHelpContentsModule() ) );
489       a->setObjectName( QString("KERNEL") );
490       createMenu( a, helpModuleMenu, -1 );
491       id++;
492     }
493   }
494   // help for other existing modules
495   QStringList::Iterator it;
496   for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
497   {
498     if ( (*it).isEmpty() )
499       continue;
500
501     QString modName = moduleName( *it );
502
503     dir = getenv( (modName + "_ROOT_DIR").toLatin1().constData() );
504     if ( !dir.isEmpty() ) {
505       root = Qtx::addSlash( Qtx::addSlash(dir) +  Qtx::addSlash("share") + Qtx::addSlash("doc") +
506                             Qtx::addSlash("salome") + Qtx::addSlash("gui") +  Qtx::addSlash(modName) );
507       if ( QFileInfo( root + aFileName ).exists() ) {
508
509         QAction* a = createAction( id, tr( (moduleTitle(modName) + QString(" Help")).toLatin1().constData() ),
510                                    resMgr->loadPixmap( "STD", tr( "ICON_HELP" ), false ),
511                                    tr( (moduleTitle(modName) + QString(" Help")).toLatin1().constData() ),
512                                    tr( (moduleTitle(modName) + QString(" Help")).toLatin1().constData() ),
513                                    0, desk, false, this, SLOT( onHelpContentsModule() ) );
514         a->setObjectName( modName );
515         createMenu( a, helpModuleMenu, -1 );
516         id++;
517       }
518     }
519   }
520
521   //! MRU
522   static QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), 0 );
523   connect( mru, SIGNAL( activated( const QString& ) ), this, SLOT( onMRUActivated( const QString& ) ) );
524   registerAction( MRUId, mru );
525
526   // default icon for neutral point ('SALOME' module)
527   QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
528   if ( defIcon.isNull() )
529     defIcon = QPixmap( imageEmptyIcon );
530
531   //! default icon for any module
532   QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
533   if ( modIcon.isNull() )
534     modIcon = QPixmap( imageEmptyIcon );
535
536   QStringList modList;
537   modules( modList, false );
538
539   if ( modList.count() > 1 )
540   {
541     LightApp_ModuleAction* moduleAction =
542       new LightApp_ModuleAction( tr( "APP_NAME" ), defIcon, desk );
543
544     QMap<QString, QString> iconMap;
545     moduleIconNames( iconMap );
546
547     const int iconSize = 20;
548
549     for ( it = modList.begin(); it != modList.end(); ++it )
550     {
551       if ( !isLibExists( *it ) )
552         continue;
553
554       QString iconName;
555       if ( iconMap.contains( *it ) )
556         iconName = iconMap[*it];
557
558       QString modName = moduleName( *it );
559
560       QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
561       if ( icon.isNull() )
562       {
563         icon = modIcon;
564         INFOS ( "****************************************************************" << std::endl
565              << "*    Icon for " << (*it).toLatin1().constData() << " not found. Using the default one." << std::endl
566              << "****************************************************************" << std::endl );
567       }
568
569       icon = Qtx::scaleIcon( icon, iconSize );
570
571       moduleAction->insertModule( *it, icon );
572     }
573
574
575     connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ), this, SLOT( onModuleActivation( const QString& ) ) );
576     registerAction( ModulesListId, moduleAction );
577   }
578
579   // New window
580   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 );
581   int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
582
583   createAction( CloseId, tr( "TOT_CLOSE" ), QIcon(), tr( "MEN_DESK_CLOSE" ), tr( "PRP_CLOSE" ),
584                 Qt::SHIFT+Qt::Key_C, desk, false, this, SLOT( onCloseWindow() ) );
585   createAction( CloseAllId, tr( "TOT_CLOSE_ALL" ), QIcon(), tr( "MEN_DESK_CLOSE_ALL" ), tr( "PRP_CLOSE_ALL" ),
586                 0, desk, false, this, SLOT( onCloseAllWindow() ) );
587   createAction( GroupAllId, tr( "TOT_GROUP_ALL" ), QIcon(), tr( "MEN_DESK_GROUP_ALL" ), tr( "PRP_GROUP_ALL" ),
588                 0, desk, false, this, SLOT( onGroupAllWindow() ) );
589
590   createMenu( CloseId,     windowMenu, 0, -1 );
591   createMenu( CloseAllId,  windowMenu, 0, -1 );
592   createMenu( GroupAllId,  windowMenu, 0, -1 );
593   createMenu( separator(), windowMenu, -1, 0 );
594
595 #ifndef DISABLE_GLVIEWER
596   createActionForViewer( NewGLViewId, newWinMenu, QString::number( 0 ), Qt::ALT+Qt::Key_G );
597 #endif
598 #ifndef DISABLE_PLOT2DVIEWER
599   createActionForViewer( NewPlot2dId, newWinMenu, QString::number( 1 ), Qt::ALT+Qt::Key_P );
600 #endif
601 #ifndef DISABLE_OCCVIEWER
602   createActionForViewer( NewOCCViewId, newWinMenu, QString::number( 2 ), Qt::ALT+Qt::Key_O );
603 #endif
604 #ifndef DISABLE_VTKVIEWER
605   createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), Qt::ALT+Qt::Key_K );
606 #endif
607 #ifndef DISABLE_QXGRAPHVIEWER
608   createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_C );
609 #endif
610
611   createActionForViewer( NewQxSceneViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_S );
612
613   createAction( RenameId, tr( "TOT_RENAME" ), QIcon(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
614                 Qt::SHIFT+Qt::Key_R, desk, false, this, SLOT( onRenameWindow() ) );
615   createMenu( RenameId, windowMenu, -1 );
616
617   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
618   createMenu( PreferencesId, fileMenu, 50, -1 );
619   createMenu( separator(), fileMenu, -1, 50, -1 );
620
621   createMenu( separator(), fileMenu, -1, 100, -1 );
622   createMenu( MRUId, fileMenu, 100, -1 );
623   createMenu( separator(), fileMenu, -1, 100, -1 );
624
625   createAction( StyleId, tr( "TOT_THEME" ), QIcon(), tr( "MEN_DESK_THEME" ), tr( "PRP_THEME" ),
626                 0, desk, false, this, SLOT( onStylePreferences() ) );
627
628   int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1 );
629   createMenu( separator(), viewMenu, -1, 20, -1 );
630   createMenu( StyleId, viewMenu, 20, -1 );
631
632   int modTBar = createTool( tr( "INF_TOOLBAR_MODULES" ) );
633   createTool( ModulesListId, modTBar );
634 }
635
636 /*!On module activation action.*/
637 void LightApp_Application::onModuleActivation( const QString& modName )
638 {
639   // Force user to create/open a study before module activation
640   QMap<QString, QString> iconMap;
641   moduleIconNames( iconMap );
642   QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
643   if ( icon.isNull() )
644     icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
645
646   bool cancelled = false;
647
648   while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
649     LightApp_ModuleDlg aDlg( desktop(), modName, icon );
650     QMap<int, QString> opmap = activateModuleActions();
651     for ( QMap<int, QString>::ConstIterator it = opmap.begin(); it != opmap.end(); ++it )
652       aDlg.addButton( it.value(), it.key() );
653
654     int res = aDlg.exec();
655     if ( res ) {
656       // some operation is selected
657       moduleActionSelected( res );
658     }
659     else {
660       // cancelled
661       putInfo( tr("INF_CANCELLED") );
662
663       LightApp_ModuleAction* moduleAction =
664         qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
665       if ( moduleAction )
666         moduleAction->setActiveModule( QString() );
667       cancelled = true;
668     }
669   }
670
671   if ( !cancelled )
672     activateModule( modName );
673 }
674
675 /*!Default module activation.*/
676 QString LightApp_Application::defaultModule() const
677 {
678   QStringList aModuleNames;
679   modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
680   //! If there's the one and only module --> activate it automatically
681   //! TODO: Possible improvement - default module can be taken from preferences
682   return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
683 }
684
685 /*!On new window slot.*/
686 void LightApp_Application::onNewWindow()
687 {
688   const QObject* obj = sender();
689   if ( !obj || !obj->inherits( "QAction" ) )
690     return;
691
692   QString type;
693   int id = actionId( (QAction*)obj );
694   switch ( id )
695   {
696 #ifndef DISABLE_GLVIEWER
697   case NewGLViewId:
698     type = GLViewer_Viewer::Type();
699     break;
700 #endif
701 #ifndef DISABLE_PLOT2DVIEWER
702   case NewPlot2dId:
703     type = Plot2d_Viewer::Type();
704     break;
705 #endif
706 #ifndef DISABLE_OCCVIEWER
707   case NewOCCViewId:
708     type = OCCViewer_Viewer::Type();
709     break;
710 #endif
711 #ifndef DISABLE_VTKVIEWER
712   case NewVTKViewId:
713     type = VTKViewer_Viewer::Type();
714     break;
715 #endif
716 #ifndef DISABLE_QXGRAPHVIEWER
717   case NewQxGraphViewId:
718     type = QxGraph_Viewer::Type();
719     break;
720 #endif
721   case NewQxSceneViewId:
722     type = QxScene_Viewer::Type();
723     break;
724   }
725
726   if ( !type.isEmpty() )
727     createViewManager( type );
728 }
729
730 /*!
731   SLOT: Creates new document
732 */
733 void LightApp_Application::onNewDoc()
734 {
735   saveDockWindowsState();
736
737   CAM_Application::onNewDoc();
738 }
739
740 /*!
741   SLOT: Opens new document
742 */
743 void LightApp_Application::onOpenDoc()
744 {
745   SUIT_Study* study = activeStudy();
746   saveDockWindowsState();
747
748   CAM_Application::onOpenDoc();
749
750   if ( !study ) // new study will be create in THIS application
751   {
752     updateWindows();
753     updateViewManagers();
754   }
755 }
756
757 /*!
758   SLOT: Opens new document.
759   \param aName - name of file
760 */
761 bool LightApp_Application::onOpenDoc( const QString& aName )
762 {
763   // We should take mru action first because this application instance can be deleted later.
764   QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
765
766   bool res = CAM_Application::onOpenDoc( aName );
767
768   if ( mru )
769   {
770     if ( res )
771       mru->insert( aName );
772     else
773       mru->remove( aName );
774   }
775   return res;
776 }
777
778 /*!
779   SLOT: Displays "About" message box
780 */
781 void LightApp_Application::onHelpAbout()
782 {
783   LightApp_AboutDlg dlg( applicationName(), applicationVersion(), desktop() );
784   dlg.exec();
785 }
786
787 /*!
788   Private SLOT: Called on selection is changed
789   Dispatchs active module that selection is changed
790 */
791 void LightApp_Application::onSelection()
792 {
793   onSelectionChanged();
794
795   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
796     ((LightApp_Module*)activeModule())->selectionChanged();
797 }
798
799 /*!
800   Sets active study.
801  \param study - SUIT_Study.
802 */
803 void LightApp_Application::setActiveStudy( SUIT_Study* study )
804 {
805   CAM_Application::setActiveStudy( study );
806 }
807
808 /*!
809   Enables/Disables menu items and toolbar buttons. Rebuild menu
810 */
811 void LightApp_Application::updateCommandsStatus()
812 {
813   CAM_Application::updateCommandsStatus();
814   QAction* a = 0;
815
816 #ifndef DISABLE_GLVIEWER
817   a = action( NewGLViewId );
818   if( a )
819     a->setEnabled( activeStudy() );
820 #endif
821
822 #ifndef DISABLE_PLOT2DVIEWER
823   a = action( NewPlot2dId );
824   if( a )
825     a->setEnabled( activeStudy() );
826 #endif
827
828 #ifndef DISABLE_OCCVIEWER
829   a = action( NewOCCViewId );
830   if( a )
831     a->setEnabled( activeStudy() );
832 #endif
833
834 #ifndef DISABLE_VTKVIEWER
835   a = action( NewVTKViewId );
836   if( a )
837     a->setEnabled( activeStudy() );
838 #endif
839
840 #ifndef DISABLE_QXGRAPHVIEWER
841   a = action( NewQxGraphViewId );
842   if( a )
843     a->setEnabled( activeStudy() );
844 #endif
845   a = action( NewQxSceneViewId );
846   if( a )
847     a->setEnabled( activeStudy() );
848 }
849
850 /*!
851   \class RunBrowser
852   Runs system command in separate thread
853 */
854 class RunBrowser: public QThread
855 {
856 public:
857   RunBrowser( LightApp_Application* app,
858               const QString&        theApp,
859               const QString&        theParams,
860               const QString&        theHelpFile,
861               const QString&        theContext = QString() )
862     : myApp( theApp ),
863       myParams( theParams ),
864 #ifdef WIN32
865       myHelpFile( "file://" + theHelpFile ),
866 #else
867       myHelpFile( "file:" + theHelpFile ),
868 #endif
869       myContext( theContext ),
870       myStatus(0),
871       myLApp( app )
872   {
873   }
874
875   virtual void run()
876   {
877     if ( !myApp.isEmpty()) {
878       QString aCommand = QString( "%1 %2 %3" ).arg( myApp, myParams, myHelpFile );
879       if ( !myContext.isEmpty() )
880         aCommand += "#" + myContext;
881
882       QProcess* proc = new QProcess();
883
884       proc->start( aCommand );
885       if ( !proc->waitForStarted() ) {
886         SALOME_CustomEvent* ce2000 = new SALOME_CustomEvent( 2000 );
887         QString* msg = new QString( QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).arg( myApp, myHelpFile ) );
888         ce2000->setData( msg );
889         QApplication::postEvent( myLApp, ce2000 );
890       }
891     }
892   }
893
894 private:
895   QString               myApp;
896   QString               myParams;
897   QString               myHelpFile;
898   QString               myContext;
899   int                   myStatus;
900   LightApp_Application* myLApp;
901 };
902
903 /*!
904   SLOT: Displays help contents for choosen module
905 */
906 void LightApp_Application::onHelpContentsModule()
907 {
908   const QAction* obj = (QAction*) sender();
909
910   QString aComponentName = obj->objectName();
911   QString aFileName = "index.html";
912
913   QString dir = getenv( (aComponentName + "_ROOT_DIR").toLatin1().constData() );
914   QString homeDir = !aComponentName.compare(QString("KERNEL")) ?
915     Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") + Qtx::addSlash("salome") ) :
916     Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") + Qtx::addSlash("salome") + Qtx::addSlash("gui") +  Qtx::addSlash(aComponentName) );
917
918   QString helpFile = QFileInfo( homeDir + aFileName ).absoluteFilePath();
919   SUIT_ResourceMgr* resMgr = resourceMgr();
920         QString platform;
921 #ifdef WIN32
922         platform = "winapplication";
923 #else
924         platform = "application";
925 #endif
926         QString anApp = resMgr->stringValue("ExternalBrowser", platform);
927 #ifdef WIN32
928         QString quote("\"");
929         anApp.prepend( quote );
930         anApp.append( quote );
931 #endif
932   QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
933
934   if ( !anApp.isEmpty() )
935   {
936     RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
937     rs->start();
938   }
939   else
940   {
941     if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ),
942                                     SUIT_MessageBox::Yes | SUIT_MessageBox::No,
943                                     SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
944
945       showPreferences( tr( "PREF_APP" ) );
946   }
947 }
948
949 /*!
950   SLOT: Displays help contents for choosen dialog
951 */
952 void LightApp_Application::onHelpContextModule( const QString& theComponentName,
953                                                 const QString& theFileName,
954                                                 const QString& theContext )
955 {
956   QString homeDir = "";
957   if ( !theComponentName.isEmpty() ) {
958     QString dir = getenv( ( theComponentName + "_ROOT_DIR" ).toLatin1().constData() );
959     if ( !dir.isEmpty() )
960       homeDir = Qtx::addSlash( Qtx::addSlash( dir )      +
961                                Qtx::addSlash( "share" )  +
962                                Qtx::addSlash( "doc" )    +
963                                Qtx::addSlash( "salome" ) +
964                                Qtx::addSlash( "gui" )    +
965                                Qtx::addSlash( theComponentName ) );
966   }
967
968   QString helpFile = QFileInfo( homeDir + theFileName ).absoluteFilePath();
969   SUIT_ResourceMgr* resMgr = resourceMgr();
970         QString platform;
971 #ifdef WIN32
972         platform = "winapplication";
973 #else
974         platform = "application";
975 #endif
976         QString anApp = resMgr->stringValue("ExternalBrowser", platform);
977 #ifdef WIN32
978         QString quote("\"");
979         anApp.prepend( quote );
980         anApp.append( quote );
981 #endif
982   QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
983
984   if ( !anApp.isEmpty() )
985   {
986     RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile, theContext );
987     rs->start();
988   }
989   else
990   {
991     if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ),
992                                     SUIT_MessageBox::Yes | SUIT_MessageBox::No,
993                                     SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
994       showPreferences( tr( "PREF_APP" ) );
995   }
996 }
997
998 /*!
999   Sets enable or disable some actions on selection changed.
1000 */
1001 void LightApp_Application::onSelectionChanged()
1002 {
1003 }
1004
1005 /*!
1006   Adds window to application.
1007   \param wid - QWidget
1008   \param flag - key for window
1009   \param studyId - study id
1010   Flag used how identificator of window in windows list.
1011 */
1012 /*
1013 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
1014 {
1015   if ( !wid )
1016     return;
1017
1018   int sId = studyId;
1019   if ( sId < 0 )
1020   {
1021     if ( !activeStudy() )
1022       return;
1023     else
1024       sId = activeStudy()->id();
1025   }
1026
1027   if ( !myWindows.contains( flag ) )
1028   {
1029     QMap<int, int> winMap;
1030     currentWindows( winMap );
1031
1032     LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
1033     connect( newWC, SIGNAL(  destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1034     // asv: connecting a slot for storing visibility flag of a window
1035     connect( newWC, SIGNAL( visibilityChanged ( bool ) ), SLOT( onVisibilityChanged( bool ) ) );
1036     myWindows.insert( flag, newWC );
1037     if ( winMap.contains( flag ) ) {
1038       //desktop()->removeDockWidget( myWindows[flag] );
1039       desktop()->addDockWidget( (Qt::DockWidgetArea)winMap[flag], myWindows[flag] );
1040     }
1041
1042     //myWindows[flag]->setResizeEnabled( true );
1043     myWindows[flag]->setFeatures( QDockWidget::AllDockWidgetFeatures );
1044     myWindows[flag]->setObjectName( QString( "dock_window_%1" ).arg( flag ) );
1045     //myWindows[flag]->setFixedExtentWidth( wid->width() );
1046     //myWindows[flag]->setFixedExtentHeight( wid->height() );
1047     myWindows[flag]->resize( wid->width(), wid->height() );
1048   }
1049
1050   QFont f;
1051 #ifndef DISABLE_PYCONSOLE
1052   if( wid->inherits( "PyConsole_Console" ) )
1053   {
1054     if( resourceMgr()->hasValue( "PyConsole", "font" ) )
1055       f = resourceMgr()->fontValue( "PyConsole", "font" );
1056     else
1057       {
1058         f = ( ( PyConsole_Console* )wid )->font();
1059         resourceMgr()->setValue( "PyConsole", "font", f );
1060       }
1061   }
1062   else
1063 #endif
1064     f = wid->font();
1065
1066   myWindows[flag]->insert( sId, wid );
1067   wid->setFont( f );
1068
1069   setWindowShown( flag, !myWindows[flag]->isEmpty() );
1070 }
1071 */
1072
1073 QWidget* LightApp_Application::dockWindow( const int id ) const
1074 {
1075   QWidget* wid = 0;
1076   if ( myWin.contains( id ) )
1077     wid = myWin[id];
1078   return wid;
1079 }
1080
1081 QDockWidget* LightApp_Application::windowDock( QWidget* wid ) const
1082 {
1083   if ( !wid )
1084     return 0;
1085
1086   QDockWidget* dock = 0;
1087   QWidget* w = wid->parentWidget();
1088   while ( w && !dock )
1089   {
1090     dock = ::qobject_cast<QDockWidget*>( w );
1091     w = w->parentWidget();
1092   }
1093   return dock;
1094 }
1095
1096 void LightApp_Application::insertDockWindow( const int id, QWidget* wid )
1097 {
1098   if ( !wid )
1099     return;
1100
1101   if ( wid != dockWindow( id ) )
1102     removeDockWindow( id );
1103
1104   myWin.insert( id, wid );
1105
1106   QtxDockWidget* dock = new QtxDockWidget( true, desktop() );
1107   connect( dock, SIGNAL(  destroyed( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1108
1109   dock->setFeatures( QDockWidget::AllDockWidgetFeatures );
1110   dock->setObjectName( QString( "window_%1" ).arg( id ) );
1111   dock->setWidget( wid );
1112   dock->show();
1113 }
1114
1115 void LightApp_Application::removeDockWindow( const int id )
1116 {
1117   QWidget* wid = dockWindow( id );
1118   if ( !wid )
1119     return;
1120
1121   myWin.remove( id );
1122
1123   QDockWidget* dock = windowDock( wid );
1124   if ( !dock )
1125     return;
1126
1127   dock->setWidget( 0 );
1128   wid->setParent( 0 );
1129   wid->setVisible( false );
1130   delete dock;
1131 }
1132
1133 void LightApp_Application::placeDockWindow( const int id, Qt::DockWidgetArea place )
1134 {
1135   QDockWidget* dock = windowDock( dockWindow( id ) );
1136   if ( dock && desktop() )
1137     desktop()->addDockWidget( place, dock );
1138 }
1139
1140 /*!
1141   Gets window.
1142   \param flag - key for window
1143   \param studyId - study id
1144   Flag used how identificator of window in windows list.
1145 */
1146 QWidget* LightApp_Application::getWindow( const int flag, const int )
1147 {
1148   QWidget* wid = dockWindow( flag );
1149   if ( !wid )
1150     insertDockWindow( flag, wid = createWindow( flag ) );
1151
1152   QMap<int, int> winMap;
1153   currentWindows( winMap );
1154   if ( winMap.contains( flag ) )
1155     placeDockWindow( flag, (Qt::DockWidgetArea)winMap[flag] );
1156
1157   return wid;
1158 }
1159
1160 /*!
1161   \return Object Browser
1162 */
1163 SUIT_DataBrowser* LightApp_Application::objectBrowser()
1164 {
1165   return qobject_cast<SUIT_DataBrowser*>( dockWindow( WT_ObjectBrowser ) );
1166 }
1167
1168 /*!
1169   \return Log Window
1170 */
1171 LogWindow* LightApp_Application::logWindow()
1172 {
1173   return qobject_cast<LogWindow*>( dockWindow( WT_LogWindow ) );
1174 }
1175
1176 #ifndef DISABLE_PYCONSOLE
1177 /*!
1178   \return Python Console
1179 */
1180 PyConsole_Console* LightApp_Application::pythonConsole()
1181 {
1182   return qobject_cast<PyConsole_Console*>( dockWindow( WT_PyConsole ) );
1183 }
1184 #endif
1185
1186 /*!
1187   Updates object browser and maybe data models
1188   \param updateModels - if it is true, then data models are updated
1189 */
1190 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1191 {
1192   // update existing data models
1193   if ( updateModels )
1194   {
1195     const bool isAutoUpdate = objectBrowser() ? objectBrowser()->autoUpdate() : true;
1196     if ( objectBrowser() )
1197       objectBrowser()->setAutoUpdate( false );
1198
1199     LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1200     if ( study ) {
1201       CAM_Study::ModelList dm_list;
1202       study->dataModels( dm_list );
1203       QListIterator<CAM_DataModel*> it( dm_list );
1204       while ( it.hasNext() ) {
1205         CAM_DataModel* camDM = it.next();
1206         if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1207           ((LightApp_DataModel*)camDM)->update();
1208       }
1209     }
1210
1211     if( objectBrowser() )
1212       objectBrowser()->setAutoUpdate( isAutoUpdate );
1213   }
1214
1215   if ( objectBrowser() ) {
1216     objectBrowser()->updateGeometry();
1217     objectBrowser()->updateTree( 0, false );
1218   }
1219 }
1220
1221 /*!
1222   \return preferences
1223 */
1224 LightApp_Preferences* LightApp_Application::preferences() const
1225 {
1226   return preferences( false );
1227 }
1228
1229 /*!
1230   \return first view manager of some type
1231   \param vmType - type of view manager
1232   \param create - is it necessary to create view manager in case, when there is no manager of such type
1233 */
1234 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1235 {
1236   SUIT_ViewManager* aVM = viewManager( vmType );
1237   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1238
1239   if ( anActiveVM && anActiveVM->getType() == vmType )
1240     aVM = anActiveVM;
1241
1242   if ( aVM && create )
1243   {
1244     if ( !aVM->getActiveView() )
1245       aVM->createView();
1246     else
1247       aVM->getActiveView()->setFocus();
1248   }
1249   else if ( create )
1250     aVM = createViewManager( vmType );
1251
1252   return aVM;
1253 }
1254
1255 /*!
1256   Creates view manager of some type
1257   \param vmType - type of view manager
1258 */
1259 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1260 {
1261   SUIT_ResourceMgr* resMgr = resourceMgr();
1262
1263   SUIT_ViewManager* viewMgr = 0;
1264 #ifndef DISABLE_GLVIEWER
1265   if( vmType == GLViewer_Viewer::Type() )
1266   {
1267     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1268     new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1269   }
1270 #endif
1271 #ifndef DISABLE_PLOT2DVIEWER
1272   if( vmType == Plot2d_Viewer::Type() )
1273   {
1274     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1275     Plot2d_Viewer* vm;
1276 #ifndef DISABLE_SALOMEOBJECT
1277     SPlot2d_Viewer* v = new SPlot2d_Viewer();
1278     vm = v;
1279     new LightApp_Plot2dSelector( v, mySelMgr );
1280 #else
1281     vm = new Plot2d_Viewer();
1282 #endif
1283     viewMgr->setViewModel( vm  );// custom view model, which extends SALOME_View interface
1284     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1285     if( wnd )
1286     {
1287       Plot2d_ViewFrame* frame = wnd->getViewFrame();
1288       frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1289     }
1290   }
1291 #endif
1292   if( vmType == QxScene_Viewer::Type() )
1293   {
1294     viewMgr = new QxScene_ViewManager( activeStudy(), desktop() );
1295     QxScene_Viewer* vm = new QxScene_Viewer();
1296     viewMgr->setViewModel( vm  );
1297     //QxScene_ViewWindow* wnd = dynamic_cast<QxScene_ViewWindow*>( viewMgr->getActiveView() );
1298   }
1299   //#ifndef DISABLE_SUPERVGRAPHVIEWER
1300   //  if( vmType == SUPERVGraph_Viewer::Type() )
1301   //  {
1302   //    viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop(), new SUPERVGraph_Viewer() );
1303   //  }
1304   //#endif
1305 #ifndef DISABLE_QXGRAPHVIEWER
1306   if( vmType == QxGraph_Viewer::Type() )
1307     {
1308       viewMgr = new QxGraph_ViewManager( activeStudy(), desktop(), new QxGraph_Viewer() );
1309     }
1310 #endif
1311 #ifndef DISABLE_OCCVIEWER
1312   if( vmType == OCCViewer_Viewer::Type() )
1313   {
1314     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1315     OCCViewer_Viewer* vm;
1316 #ifndef DISABLE_SALOMEOBJECT
1317     vm = new SOCC_Viewer();
1318 #else
1319     vm = new OCCViewer_Viewer( true, resMgr->booleanValue( "OCCViewer", "static_trihedron", true ) );
1320 #endif
1321     vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1322     vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1323     int u( 1 ), v( 1 );
1324     vm->isos( u, v );
1325     u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1326     v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1327     vm->setIsos( u, v );
1328     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1329     new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1330   }
1331 #endif
1332 #ifndef DISABLE_VTKVIEWER
1333 #ifndef DISABLE_SALOMEOBJECT
1334   if ( vmType == SVTK_Viewer::Type() )
1335 #else
1336   if ( vmType == VTKViewer_Viewer::Type() )
1337 #endif
1338   {
1339 #ifndef DISABLE_SALOMEOBJECT
1340     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1341     SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1342     if( vm )
1343     {
1344       vm->setProjectionMode( resMgr->integerValue( "VTKViewer", "projection_mode", vm->projectionMode() ) );
1345       vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1346       vm->setTrihedronSize( resMgr->doubleValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ),
1347                             resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) );
1348       vm->setInteractionStyle( resMgr->integerValue( "VTKViewer", "navigation_mode", vm->interactionStyle() ) );
1349       vm->setIncrementalSpeed( resMgr->integerValue( "VTKViewer", "speed_value", vm->incrementalSpeed() ),
1350                                resMgr->integerValue( "VTKViewer", "speed_mode", vm->incrementalSpeedMode() ) );
1351       vm->setSpacemouseButtons( resMgr->integerValue( "VTKViewer", "spacemouse_func1_btn", vm->spacemouseBtn(1) ),
1352                                 resMgr->integerValue( "VTKViewer", "spacemouse_func2_btn", vm->spacemouseBtn(2) ),
1353                                 resMgr->integerValue( "VTKViewer", "spacemouse_func5_btn", vm->spacemouseBtn(3) ) );
1354       new LightApp_VTKSelector( vm, mySelMgr );
1355     }
1356 #else
1357     viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
1358     VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
1359     if ( vm )
1360       vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1361 #endif
1362   }
1363 #endif
1364
1365   if ( !viewMgr )
1366     return 0;
1367
1368   addViewManager( viewMgr );
1369   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1370
1371   if ( viewWin && desktop() )
1372     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1373
1374   return viewMgr;
1375 }
1376
1377 /*!
1378   SLOT: Removes view manager from application
1379 */
1380 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1381 {
1382   removeViewManager( theVM );
1383 }
1384
1385 /*!
1386   Protected SLOT: On study created.
1387   \param theStudy - just created study
1388 */
1389 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1390 {
1391   SUIT_DataObject* aRoot = 0;
1392   if ( theStudy && theStudy->root() )
1393   {
1394     aRoot = theStudy->root();
1395     //aRoot->setName( tr( "DATA_MODELS" ) );
1396   }
1397
1398   getWindow( WT_ObjectBrowser );
1399
1400   loadDockWindowsState();
1401
1402   if ( objectBrowser() )
1403     objectBrowser()->setRoot( aRoot );
1404
1405   activateModule( defaultModule() );
1406
1407   if ( objectBrowser() )
1408     objectBrowser()->openLevels();
1409 }
1410
1411 /*!
1412   Protected SLOT: On study opened.
1413   \param theStudy - just opened  study
1414 */
1415 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1416 {
1417   SUIT_DataObject* aRoot = 0;
1418   if ( theStudy && theStudy->root() )
1419   {
1420     aRoot = theStudy->root();
1421     //aRoot->dump();
1422   }
1423
1424   getWindow( WT_ObjectBrowser );
1425
1426   loadDockWindowsState();
1427
1428   if ( objectBrowser() )
1429     objectBrowser()->setRoot( aRoot );
1430
1431   activateModule( defaultModule() );
1432
1433   if ( objectBrowser() )
1434     objectBrowser()->openLevels();
1435
1436   emit studyOpened();
1437 }
1438
1439 /*!Protected SLOT. On study saved.*/
1440 void LightApp_Application::onStudySaved( SUIT_Study* s )
1441 {
1442   QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
1443   if ( mru && s )
1444       mru->insert( s->studyName() );
1445
1446   emit studySaved();
1447 }
1448
1449 /*!Protected SLOT. On study closed.*/
1450 void LightApp_Application::onStudyClosed( SUIT_Study* s )
1451 {
1452   // Bug 10396: clear selection
1453   mySelMgr->clearSelected();
1454
1455   // Bug 12944: emit signal only after clear selection
1456   emit studyClosed();
1457
1458   activateModule( "" );
1459 }
1460
1461 /*!Protected SLOT.On desktop activated.*/
1462 void LightApp_Application::onDesktopActivated()
1463 {
1464   CAM_Application::onDesktopActivated();
1465   LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1466   if(aModule)
1467     aModule->studyActivated();
1468 }
1469
1470 void LightApp_Application::studyOpened( SUIT_Study* s )
1471 {
1472   CAM_Application::studyOpened( s );
1473
1474   updateWindows();
1475   updateViewManagers();
1476 }
1477
1478 void LightApp_Application::studyCreated( SUIT_Study* s )
1479 {
1480   CAM_Application::studyCreated( s );
1481
1482   updateWindows();
1483   updateViewManagers();
1484 }
1485
1486 /*!Gets file filter.
1487  *\retval QString "(*.bin)"
1488  */
1489 QString LightApp_Application::getFileFilter() const
1490 {
1491   //return "(*.bin)";
1492   // HDF persistence
1493   return "(*.hdf)";
1494 }
1495
1496 /*!
1497   Shows file dialog and return user selected file name
1498 */
1499 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1500                                            const QString& caption, QWidget* parent )
1501 {
1502   if ( !parent )
1503     parent = desktop();
1504   QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
1505   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1506 }
1507
1508 /*! Gets directory*/
1509 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1510 {
1511   if ( !parent )
1512     parent = desktop();
1513   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1514 }
1515
1516 /*! Get open file names*/
1517 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1518                                                     const QString& caption, QWidget* parent )
1519 {
1520   if ( !parent )
1521     parent = desktop();
1522   QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
1523   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1524 }
1525
1526 /*!Private SLOT. Update object browser.*/
1527 void LightApp_Application::onRefresh()
1528 {
1529   updateObjectBrowser( true );
1530 }
1531
1532 /*!Private SLOT. On preferences.*/
1533 void LightApp_Application::onPreferences()
1534 {
1535   showPreferences( activeModule() ? activeModule()->moduleName() : tr( "PREF_CATEGORY_SALOME" ) );
1536 }
1537
1538 /*!Private SLOT. On preferences.*/
1539 void LightApp_Application::showPreferences( const QString& itemText )
1540 {
1541   QApplication::setOverrideCursor( Qt::WaitCursor );
1542
1543   LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1544
1545   QApplication::restoreOverrideCursor();
1546
1547   if ( !prefDlg )
1548     return;
1549
1550   preferences()->activateItem( itemText );
1551
1552   if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) &&  resourceMgr() )
1553   {
1554     if ( desktop() )
1555       resourceMgr()->setValue( "desktop", "geometry", desktop()->storeGeometry() );
1556     resourceMgr()->save();
1557   }
1558
1559   delete prefDlg;
1560 }
1561
1562 /*!Protected SLOT. On preferences changed.*/
1563 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1564 {
1565   LightApp_Module* sMod = 0;
1566   CAM_Module* mod = module( modName );
1567   if ( mod && mod->inherits( "LightApp_Module" ) )
1568     sMod = (LightApp_Module*)mod;
1569
1570   if ( sMod )
1571     sMod->preferencesChanged( section, param );
1572   else
1573     preferencesChanged( section, param );
1574   // emit signal to allow additional preferences changing processing
1575   emit preferenceChanged( modName, section, param );
1576 }
1577
1578 /*!Remove all windows from study.*/
1579 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1580 {
1581   CAM_Application::beforeCloseDoc( s );
1582 }
1583
1584 /*!Update actions.*/
1585 void LightApp_Application::updateActions()
1586 {
1587   updateCommandsStatus();
1588 }
1589
1590 /*!
1591   Creates new study
1592 */
1593 SUIT_Study* LightApp_Application::createNewStudy()
1594 {
1595   LightApp_Application::lastStudyId++;
1596
1597   LightApp_Study* aStudy = new LightApp_Study( this );
1598
1599   // Set up processing of major study-related events
1600   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1601   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1602   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
1603   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1604
1605   return aStudy;
1606 }
1607
1608 /*!
1609   Creates window by flag.
1610   \param flag - identificator of window type
1611 */
1612 QWidget* LightApp_Application::createWindow( const int flag )
1613 {
1614   QWidget* wid = 0;
1615
1616   SUIT_ResourceMgr* resMgr = resourceMgr();
1617
1618   if ( flag == WT_ObjectBrowser )
1619   {
1620     SUIT_DataBrowser* ob = new SUIT_DataBrowser( new LightApp_DataObject(), desktop() );
1621     ob->setSortMenuEnabled( true );
1622     ob->setAutoUpdate( true );
1623     if ( resMgr->hasValue( "ObjectBrowser", "auto_hide_search_tool" ) )
1624       ob->searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
1625
1626     //ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107
1627     ob->setWindowTitle( tr( "OBJECT_BROWSER" ) );
1628     connect( ob, SIGNAL( requestUpdate() ), this, SLOT( onRefresh() ) );
1629
1630     // temporary commented
1631     /*
1632     OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1633     if( ob_list )
1634       ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1635
1636     ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1637     */
1638
1639     // Create OBSelector
1640     new LightApp_OBSelector( ob, mySelMgr );
1641
1642     wid = ob;
1643
1644     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1645   }
1646 #ifndef DISABLE_PYCONSOLE
1647   else  if ( flag == WT_PyConsole )
1648   {
1649     PyConsole_Console* pyCons = new PyConsole_Console( desktop() );
1650     pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) );
1651     wid = pyCons;
1652     pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1653   }
1654 #endif
1655   else if ( flag == WT_LogWindow )
1656   {
1657     LogWindow* logWin = new LogWindow( desktop() );
1658     logWin->setWindowTitle( tr( "LOG_WINDOW" ) );
1659     wid = logWin;
1660     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1661   }
1662   return wid;
1663 }
1664
1665 /*!
1666   \return default windows( Object Browser, Python Console )
1667   Adds to map \a aMap.
1668  */
1669 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1670 {
1671   aMap.insert( WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1672 #ifndef DISABLE_PYCONSOLE
1673   aMap.insert( WT_PyConsole, Qt::BottomDockWidgetArea );
1674 #endif
1675   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1676 }
1677
1678 /*!Default view managers*/
1679 void LightApp_Application::defaultViewManagers( QStringList& ) const
1680 {
1681   /*!Do nothing.*/
1682 }
1683
1684 /*!
1685   \return preferences.
1686   Create preferences, if \a crt = true.
1687 */
1688 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1689 {
1690   if ( myPrefs )
1691     return myPrefs;
1692
1693   LightApp_Application* that = (LightApp_Application*)this;
1694
1695   bool toCreate = !_prefs_ && crt;
1696   if ( toCreate )
1697   {
1698     _prefs_ = new LightApp_Preferences( resourceMgr() );
1699     that->createPreferences( _prefs_ );
1700   }
1701
1702   that->myPrefs = _prefs_;
1703
1704   if ( !toCreate )
1705     return myPrefs;
1706
1707   SUIT_ResourceMgr* resMgr = resourceMgr();
1708
1709   QList<SUIT_Application*> appList = SUIT_Session::session()->applications();
1710   for ( QList<SUIT_Application*>::iterator appIt = appList.begin(); appIt != appList.end(); ++appIt )
1711   {
1712     LightApp_Application* app = ::qobject_cast<LightApp_Application*>( *appIt );
1713     if ( !app )
1714       continue;
1715
1716     QStringList modNameList;
1717     app->modules( modNameList, false );
1718
1719     QMap<QString, QString> iconMap;
1720     app->moduleIconNames( iconMap );
1721
1722     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1723     {
1724       if ( !app->isLibExists( *it ) )
1725         continue;
1726
1727       int modId = _prefs_->addPreference( *it );
1728       if ( iconMap.contains( *it ) )
1729         _prefs_->setItemIcon( modId, Qtx::scaleIcon( resMgr->loadPixmap( moduleName( *it ), iconMap[*it], false ), 20 ) );
1730     }
1731
1732     ModuleList modList;
1733     app->modules( modList );
1734     QListIterator<CAM_Module*> itr( modList );
1735     while ( itr.hasNext() )
1736     {
1737       LightApp_Module* mod = 0;
1738
1739       CAM_Module* anItem = itr.next();
1740       if ( anItem->inherits( "LightApp_Module" ) )
1741         mod = (LightApp_Module*)anItem;
1742
1743       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1744       {
1745         _prefs_->addPreference( mod->moduleName() );
1746         mod->createPreferences();
1747         that->emptyPreferences( mod->moduleName() );
1748       }
1749     }
1750   }
1751   _prefs_->setItemProperty( "info", tr( "PREFERENCES_NOT_LOADED" ) );
1752
1753   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1754            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1755
1756   return myPrefs;
1757 }
1758
1759 /*!
1760   Adds new module to application
1761 */
1762 void LightApp_Application::moduleAdded( CAM_Module* mod )
1763 {
1764   CAM_Application::moduleAdded( mod );
1765
1766   LightApp_Module* lightMod = 0;
1767   if ( mod && mod->inherits( "LightApp_Module" ) )
1768     lightMod = (LightApp_Module*)mod;
1769
1770   if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1771   {
1772     myPrefs->addPreference( mod->moduleName() );
1773     lightMod->createPreferences();
1774     emptyPreferences( mod->moduleName() );
1775   }
1776 }
1777
1778 void LightApp_Application::emptyPreferences( const QString& modName )
1779 {
1780   QtxPreferenceItem* item = myPrefs->findItem( modName, true );
1781   if ( !item || !item->isEmpty() )
1782     return;
1783
1784   printf( "---------------------> Modify for empty module.\n" );
1785
1786   QtxPagePrefFrameItem* frm = new QtxPagePrefFrameItem( item->title(), item->parentItem() );
1787   frm->setIcon( item->icon() );
1788   frm->setStretch( false );
1789   item->parentItem()->insertItem( frm, item );
1790   new QtxPagePrefLabelItem( Qt::AlignCenter, tr( "PREFERENCES_NOT_SUPPORTED" ).arg( modName ), frm );
1791   delete item;
1792 }
1793
1794 /*!
1795   Create preferences
1796 */
1797 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1798 {
1799   if ( !pref )
1800     return;
1801
1802   QStringList     aValuesList;
1803   QList<QVariant> anIndicesList;
1804
1805   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1806   pref->setItemIcon( salomeCat, Qtx::scaleIcon( resourceMgr()->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ), 20 ) );
1807
1808   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1809   int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1810
1811   pref->setItemProperty( "columns", 2, studyGroup );
1812
1813   pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1814   pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1815   pref->addPreference( tr( "PREF_STORE_POS" ),  studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
1816
1817   int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1818   QString platform;
1819 #ifdef WIN32
1820   platform = "winapplication";
1821 #else
1822   platform = "application";
1823 #endif
1824   int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", platform );
1825   pref->setItemProperty( "mode", Qtx::PT_OpenFile, apppref );
1826
1827   pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1828
1829   int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1830   pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1831
1832   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1833
1834   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1835
1836   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1837
1838   int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1839
1840   int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1841
1842   pref->setItemProperty( "columns", 2, occGroup );
1843   pref->setItemProperty( "columns", 1, vtkGroup );
1844   pref->setItemProperty( "columns", 2, plot2dGroup );
1845
1846   // OCC Viewer
1847   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1848                                    LightApp_Preferences::DblSpin, "OCCViewer", "trihedron_size" );
1849   pref->setItemProperty( "min", 1.0E-06, occTS );
1850   pref->setItemProperty( "max", 1000, occTS );
1851
1852
1853   int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1854                                   LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1855   pref->setItemProperty( "min", 0, isoU );
1856   pref->setItemProperty( "max", 100000, isoU );
1857
1858   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1859                        LightApp_Preferences::Color, "OCCViewer", "background" );
1860
1861   int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1862                                   LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1863   pref->setItemProperty( "min", 0, isoV );
1864   pref->setItemProperty( "max", 100000, isoV );
1865
1866   // VTK Viewer
1867   int vtkGen = pref->addPreference( "", vtkGroup, LightApp_Preferences::Frame );
1868   pref->setItemProperty( "columns", 2, vtkGen );
1869
1870   int vtkProjMode = pref->addPreference( tr( "PREF_PROJECTION_MODE" ), vtkGen,
1871                                          LightApp_Preferences::Selector, "VTKViewer", "projection_mode" );
1872   QStringList aProjModeList;
1873   aProjModeList.append( tr("PREF_ORTHOGRAPHIC") );
1874   aProjModeList.append( tr("PREF_PERSPECTIVE") );
1875
1876   QList<QVariant> aModeIndexesList;
1877   aModeIndexesList.append(0);
1878   aModeIndexesList.append(1);
1879
1880   pref->setItemProperty( "strings", aProjModeList, vtkProjMode );
1881   pref->setItemProperty( "indexes", aModeIndexesList, vtkProjMode );
1882
1883   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen,
1884                        LightApp_Preferences::Color, "VTKViewer", "background" );
1885
1886   int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGen,
1887                                    LightApp_Preferences::DblSpin, "VTKViewer", "trihedron_size" );
1888
1889   pref->setItemProperty( "min", 1.0E-06, vtkTS );
1890   pref->setItemProperty( "max", 150, vtkTS );
1891
1892   pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGen, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
1893
1894   int vtkStyleMode = pref->addPreference( tr( "PREF_NAVIGATION" ), vtkGen,
1895                                           LightApp_Preferences::Selector, "VTKViewer", "navigation_mode" );
1896   QStringList aStyleModeList;
1897   aStyleModeList.append( tr("PREF_STANDARD_STYLE") );
1898   aStyleModeList.append( tr("PREF_KEYFREE_STYLE") );
1899
1900   pref->setItemProperty( "strings", aStyleModeList, vtkStyleMode );
1901   pref->setItemProperty( "indexes", aModeIndexesList, vtkStyleMode );
1902
1903   pref->addPreference( "", vtkGroup, LightApp_Preferences::Space );
1904
1905   int vtkSpeed = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED" ), vtkGen,
1906                                       LightApp_Preferences::IntSpin, "VTKViewer", "speed_value" );
1907
1908   pref->setItemProperty( "min", 1, vtkSpeed );
1909   pref->setItemProperty( "max", 1000, vtkSpeed );
1910
1911   int vtkSpeedMode = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED_MODE" ), vtkGen,
1912                                           LightApp_Preferences::Selector, "VTKViewer", "speed_mode" );
1913   QStringList aSpeedModeList;
1914   aSpeedModeList.append( tr("PREF_ARITHMETIC") );
1915   aSpeedModeList.append( tr("PREF_GEOMETRICAL") );
1916
1917   pref->setItemProperty( "strings", aSpeedModeList, vtkSpeedMode );
1918   pref->setItemProperty( "indexes", aModeIndexesList, vtkSpeedMode );
1919
1920   int vtkSM = pref->addPreference( tr( "PREF_FRAME_SPACEMOUSE" ), vtkGroup, LightApp_Preferences::GroupBox );
1921   pref->setItemProperty( "columns", 2, vtkSM );
1922   int spacemousePref1 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_1" ), vtkSM,
1923                                              LightApp_Preferences::Selector, "VTKViewer",
1924                                              "spacemouse_func1_btn" ); //decrease_speed_increment
1925   int spacemousePref2 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_2" ), vtkSM,
1926                                              LightApp_Preferences::Selector, "VTKViewer",
1927                                              "spacemouse_func2_btn" ); //increase_speed_increment
1928   int spacemousePref3 = pref->addPreference( tr( "PREF_SPACEMOUSE_FUNC_3" ), vtkSM,
1929                                              LightApp_Preferences::Selector, "VTKViewer",
1930                                              "spacemouse_func5_btn" ); //dominant_combined_switch
1931
1932   QStringList values;
1933   values.append( tr( "PREF_SPACEMOUSE_BTN_1" ) );
1934   values.append( tr( "PREF_SPACEMOUSE_BTN_2" ) );
1935   values.append( tr( "PREF_SPACEMOUSE_BTN_3" ) );
1936   values.append( tr( "PREF_SPACEMOUSE_BTN_4" ) );
1937   values.append( tr( "PREF_SPACEMOUSE_BTN_5" ) );
1938   values.append( tr( "PREF_SPACEMOUSE_BTN_6" ) );
1939   values.append( tr( "PREF_SPACEMOUSE_BTN_7" ) );
1940   values.append( tr( "PREF_SPACEMOUSE_BTN_8" ) );
1941   values.append( tr( "PREF_SPACEMOUSE_BTN_*" ) );
1942   values.append( tr( "PREF_SPACEMOUSE_BTN_10" ) );
1943   values.append( tr( "PREF_SPACEMOUSE_BTN_11" ) );
1944   QList<QVariant> indices;
1945   indices.append( 1 );
1946   indices.append( 2 );
1947   indices.append( 3 );
1948   indices.append( 4 );
1949   indices.append( 5 );
1950   indices.append( 6 );
1951   indices.append( 7 );
1952   indices.append( 8 );
1953   indices.append( 9 ); // == button_*
1954   indices.append( 10 );
1955   indices.append( 11 );
1956   pref->setItemProperty( "strings", values, spacemousePref1 );
1957   pref->setItemProperty( "indexes", indices, spacemousePref1 );
1958   pref->setItemProperty( "strings", values, spacemousePref2 );
1959   pref->setItemProperty( "indexes", indices, spacemousePref2 );
1960   pref->setItemProperty( "strings", values, spacemousePref3 );
1961   pref->setItemProperty( "indexes", indices, spacemousePref3 );
1962
1963   int vtkRec = pref->addPreference( tr( "PREF_FRAME_RECORDING" ), vtkGroup, LightApp_Preferences::GroupBox );
1964   pref->setItemProperty( "columns", 2, vtkRec );
1965
1966   int modePref = pref->addPreference( tr( "PREF_RECORDING_MODE" ), vtkRec,
1967                                       LightApp_Preferences::Selector, "VTKViewer", "recorder_mode" );
1968   values.clear();
1969   values.append( tr( "PREF_SKIPPED_FRAMES" ) );
1970   values.append( tr( "PREF_ALL_DISLPAYED_FRAMES" ) );
1971   indices.clear();
1972   indices.append( 0 );
1973   indices.append( 1 );
1974   pref->setItemProperty( "strings", values, modePref );
1975   pref->setItemProperty( "indexes", indices, modePref );
1976
1977   int fpsPref = pref->addPreference( tr( "PREF_FPS" ), vtkRec,
1978                                      LightApp_Preferences::DblSpin, "VTKViewer", "recorder_fps" );
1979   pref->setItemProperty( "min", 0.1, fpsPref );
1980   pref->setItemProperty( "max", 100, fpsPref );
1981
1982   int qualityPref = pref->addPreference( tr( "PREF_QUALITY" ), vtkRec,
1983                                          LightApp_Preferences::IntSpin, "VTKViewer", "recorder_quality" );
1984   pref->setItemProperty( "min", 1, qualityPref );
1985   pref->setItemProperty( "max", 100, qualityPref );
1986
1987   pref->addPreference( tr( "PREF_PROGRESSIVE" ), vtkRec,
1988                        LightApp_Preferences::Bool, "VTKViewer", "recorder_progressive" );
1989
1990   // Plot2d
1991   pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1992                        LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1993
1994   int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1995                                             LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1996   aValuesList.clear();
1997   anIndicesList.clear();
1998   aValuesList   << tr("PREF_LEFT") << tr("PREF_RIGHT") << tr("PREF_TOP") << tr("PREF_BOTTOM");
1999   anIndicesList << 0               << 1                << 2              << 3                ;
2000
2001   pref->setItemProperty( "strings", aValuesList,   legendPosition );
2002   pref->setItemProperty( "indexes", anIndicesList, legendPosition );
2003
2004   int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
2005                                        LightApp_Preferences::Selector, "Plot2d", "CurveType" );
2006   aValuesList.clear();
2007   anIndicesList.clear();
2008   aValuesList   << tr("PREF_POINTS") << tr("PREF_LINES") << tr("PREF_SPLINE");
2009   anIndicesList << 0                 << 1                << 2                ;
2010
2011   pref->setItemProperty( "strings", aValuesList,   curveType );
2012   pref->setItemProperty( "indexes", anIndicesList, curveType );
2013
2014   int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
2015                                         LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
2016
2017   pref->setItemProperty( "min", 0, markerSize );
2018   pref->setItemProperty( "max", 100, markerSize );
2019
2020   aValuesList.clear();
2021   anIndicesList.clear();
2022   aValuesList   << tr("PREF_LINEAR") << tr("PREF_LOGARITHMIC");
2023   anIndicesList << 0                 << 1                     ;
2024
2025   int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
2026                                       LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
2027
2028   pref->setItemProperty( "strings", aValuesList,   horScale );
2029   pref->setItemProperty( "indexes", anIndicesList, horScale );
2030
2031   int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
2032                                       LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
2033
2034   pref->setItemProperty( "strings", aValuesList,   verScale );
2035   pref->setItemProperty( "indexes", anIndicesList, verScale );
2036
2037   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
2038                        LightApp_Preferences::Color, "Plot2d", "Background" );
2039
2040   int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
2041   int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
2042   pref->addPreference( tr( "" ), dirGroup,
2043                        LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
2044
2045   pref->setItemProperty( "columns", 4, supervGroup );
2046   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
2047                        LightApp_Preferences::Color, "SUPERVGraph", "Background" );
2048   pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
2049                        LightApp_Preferences::Color, "SUPERVGraph", "Title" );
2050 //  pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
2051 //                     LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
2052
2053   int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
2054   int stGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SEARCH_TOOL" ), obTab );
2055   pref->addPreference( tr( "PREF_AUTO_HIDE_SEARCH_TOOL" ), stGroup, LightApp_Preferences::Bool,
2056                        "ObjectBrowser", "auto_hide_search_tool" );
2057
2058   int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
2059   pref->setItemProperty( "columns", 2, objSetGroup );
2060   pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
2061                        "ObjectBrowser", "auto_size_first" );
2062   pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
2063                        "ObjectBrowser", "auto_size" );
2064   pref->addPreference( tr( "PREF_RESIZE_ON_EXPAND_ITEM" ), objSetGroup, LightApp_Preferences::Bool,
2065                        "ObjectBrowser", "resize_on_expand_item" );
2066
2067   // MRU preferences
2068   int mruGroup = pref->addPreference( tr( "PREF_GROUP_MRU" ), genTab, LightApp_Preferences::Auto, "MRU", "show_mru" );
2069   pref->setItemProperty( "columns", 4, mruGroup );
2070   int mruVisCount = pref->addPreference( tr( "PREF_MRU_VISIBLE_COUNT" ), mruGroup, LightApp_Preferences::IntSpin,
2071                                          "MRU", "visible_count" );
2072   pref->setItemProperty( "min", 0,   mruVisCount );
2073   pref->setItemProperty( "max", 100, mruVisCount );
2074   int mruLinkType = pref->addPreference( tr( "PREF_MRU_LINK_TYPE" ), mruGroup, LightApp_Preferences::Selector,
2075                                          "MRU", "link_type" );
2076   aValuesList.clear();
2077   anIndicesList.clear();
2078   aValuesList   << tr("PREF_MRU_LINK_AUTO") << tr("PREF_MRU_LINK_SHORT") << tr("PREF_MRU_LINK_FULL");
2079   anIndicesList << 0                        << 1                         << 2                       ;
2080   pref->setItemProperty( "strings", aValuesList,   mruLinkType );
2081   pref->setItemProperty( "indexes", anIndicesList, mruLinkType );
2082
2083   pref->retrieve();
2084 }
2085
2086 /*!
2087   Changes appearance of application according to changed preferences
2088   \param sec - section
2089   \param param - name of changed parameter
2090 */
2091 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
2092 {
2093   SUIT_ResourceMgr* resMgr = resourceMgr();
2094   if ( !resMgr )
2095     return;
2096
2097 #ifndef DISABLE_OCCVIEWER
2098   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
2099   {
2100     double sz = resMgr->doubleValue( sec, param, -1 );
2101     QList<SUIT_ViewManager*> lst;
2102     viewManagers( OCCViewer_Viewer::Type(), lst );
2103     QListIterator<SUIT_ViewManager*> it( lst );
2104     while ( it.hasNext() && sz >= 0 )
2105     {
2106       SUIT_ViewModel* vm = it.next()->getViewModel();
2107       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
2108         continue;
2109
2110       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
2111       occVM->setTrihedronSize( sz );
2112       occVM->getAISContext()->UpdateCurrentViewer();
2113     }
2114   }
2115 #endif
2116
2117 #ifndef DISABLE_VTKVIEWER
2118   if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
2119   {
2120     double sz = resMgr->doubleValue( "VTKViewer", "trihedron_size", -1 );
2121     bool isRelative = resMgr->booleanValue( "VTKViewer", "relative_size", true );
2122     QList<SUIT_ViewManager*> lst;
2123 #ifndef DISABLE_SALOMEOBJECT
2124     viewManagers( SVTK_Viewer::Type(), lst );
2125     QListIterator<SUIT_ViewManager*> it( lst );
2126     while ( it.hasNext() && sz >= 0 )
2127     {
2128       SUIT_ViewModel* vm = it.next()->getViewModel();
2129       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2130         continue;
2131
2132       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2133       if( vtkVM )
2134       {
2135         vtkVM->setTrihedronSize( sz, isRelative );
2136         vtkVM->Repaint();
2137       }
2138     }
2139 #endif
2140   }
2141 #endif
2142
2143 #ifndef DISABLE_VTKVIEWER
2144   if ( sec == QString( "VTKViewer" ) && (param == QString( "speed_value" ) || param == QString( "speed_mode" )) )
2145   {
2146     int speed = resMgr->integerValue( "VTKViewer", "speed_value", 10 );
2147     int mode = resMgr->integerValue( "VTKViewer", "speed_mode", 0 );
2148     QList<SUIT_ViewManager*> lst;
2149 #ifndef DISABLE_SALOMEOBJECT
2150     viewManagers( SVTK_Viewer::Type(), lst );
2151     QListIterator<SUIT_ViewManager*> it( lst );
2152     while ( it.hasNext() )
2153     {
2154       SUIT_ViewModel* vm = it.next()->getViewModel();
2155       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2156         continue;
2157
2158       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2159       if( vtkVM ) vtkVM->setIncrementalSpeed( speed, mode );
2160     }
2161 #endif
2162   }
2163 #endif
2164
2165 #ifndef DISABLE_VTKVIEWER
2166   if ( sec == QString( "VTKViewer" ) && param == QString( "projection_mode" ) )
2167   {
2168     int mode = resMgr->integerValue( "VTKViewer", "projection_mode", 0 );
2169     QList<SUIT_ViewManager*> lst;
2170 #ifndef DISABLE_SALOMEOBJECT
2171     viewManagers( SVTK_Viewer::Type(), lst );
2172     QListIterator<SUIT_ViewManager*> it( lst );
2173     while ( it.hasNext() )
2174     {
2175       SUIT_ViewModel* vm = it.next()->getViewModel();
2176       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2177         continue;
2178
2179       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2180       if( vtkVM ) vtkVM->setProjectionMode( mode );
2181     }
2182 #endif
2183   }
2184 #endif
2185
2186 #ifndef DISABLE_VTKVIEWER
2187   if ( sec == QString( "VTKViewer" ) && param == QString( "navigation_mode" ) )
2188   {
2189     int mode = resMgr->integerValue( "VTKViewer", "navigation_mode", 0 );
2190     QList<SUIT_ViewManager*> lst;
2191 #ifndef DISABLE_SALOMEOBJECT
2192     viewManagers( SVTK_Viewer::Type(), lst );
2193     QListIterator<SUIT_ViewManager*> it( lst );
2194     while ( it.hasNext() )
2195     {
2196       SUIT_ViewModel* vm = it.next()->getViewModel();
2197       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2198         continue;
2199
2200       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2201       if( vtkVM ) vtkVM->setInteractionStyle( mode );
2202     }
2203 #endif
2204   }
2205 #endif
2206
2207 #ifndef DISABLE_VTKVIEWER
2208   if ( sec == QString( "VTKViewer" ) && (param == QString( "spacemouse_func1_btn" ) ||
2209                                          param == QString( "spacemouse_func2_btn" ) ||
2210                                          param == QString( "spacemouse_func5_btn" ) ) )
2211   {
2212     int btn1 = resMgr->integerValue( "VTKViewer", "spacemouse_func1_btn", 1 );
2213     int btn2 = resMgr->integerValue( "VTKViewer", "spacemouse_func2_btn", 2 );
2214     int btn3 = resMgr->integerValue( "VTKViewer", "spacemouse_func5_btn", 9 );
2215     QList<SUIT_ViewManager*> lst;
2216 #ifndef DISABLE_SALOMEOBJECT
2217     viewManagers( SVTK_Viewer::Type(), lst );
2218     QListIterator<SUIT_ViewManager*> it( lst );
2219     while ( it.hasNext() )
2220     {
2221       SUIT_ViewModel* vm = it.next()->getViewModel();
2222       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2223         continue;
2224
2225       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2226       if( vtkVM ) vtkVM->setSpacemouseButtons( btn1, btn2, btn3 );
2227     }
2228 #endif
2229   }
2230 #endif
2231
2232 #ifndef DISABLE_OCCVIEWER
2233   if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
2234   {
2235     QList<SUIT_ViewManager*> lst;
2236     viewManagers( OCCViewer_Viewer::Type(), lst );
2237     int u = resMgr->integerValue( sec, "iso_number_u" );
2238     int v = resMgr->integerValue( sec, "iso_number_v" );
2239     QListIterator<SUIT_ViewManager*> it( lst );
2240     while ( it.hasNext() )
2241     {
2242       OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.next() );
2243       if( mgr && mgr->getOCCViewer() )
2244         mgr->getOCCViewer()->setIsos( u, v );
2245     }
2246   }
2247 #endif
2248
2249   if( sec=="ObjectBrowser" )
2250   {
2251     SUIT_DataBrowser* ob = objectBrowser();
2252     if ( !ob )
2253       return;
2254
2255     if ( param=="auto_size_first" )
2256     {
2257       bool autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
2258       ob->setAutoSizeFirstColumn( autoSizeFirst );
2259       if ( autoSizeFirst )
2260         ob->adjustFirstColumnWidth();
2261     }
2262     else if ( param=="auto_size" ) {
2263       bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
2264       ob->setAutoSizeColumns(autoSize);
2265       if ( autoSize )
2266         ob->adjustColumnsWidth();
2267     }
2268     else if ( param=="resize_on_expand_item" ) {
2269       bool resizeOnExpandItem = resMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
2270       ob->setResizeOnExpandItem(resizeOnExpandItem);
2271     }
2272     else if ( param == "auto_hide_search_tool" ) {
2273       ob->searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
2274     }
2275   }
2276
2277   if( sec=="Study" )
2278   {
2279     if( param=="store_positions" )
2280       updateWindows();
2281   }
2282
2283 #ifndef DISABLE_PYCONSOLE
2284   if( sec=="PyConsole" )
2285   {
2286     if( param=="font" )
2287       if( pythonConsole() )
2288         pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
2289   }
2290 #endif
2291
2292   if( sec=="MRU" )
2293   {
2294     QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
2295     if ( mru ) {
2296       if ( param == "visible_count" )
2297         mru->setVisibleCount( resMgr->integerValue( "MRU", "visible_count", 5 ) );    // 5 MRU items by default
2298       else if ( param == "max_count" )
2299         mru->setHistoryCount( resMgr->integerValue( "MRU", "max_count", -1 ) );       // unlimited history by default
2300       else if ( param == "insert_mode" )
2301         mru->setInsertMode( resMgr->integerValue( "MRU", "insert_mode", 0 ) );        // QtxMRUAction::MoveFirst by default
2302       else if ( param == "link_type" )
2303         mru->setLinkType( resMgr->integerValue( "MRU", "link_type", 0 ) );            // QtxMRUAction::LinkAuto by default
2304       else if ( param == "show_clear" )
2305         mru->setClearPossible( resMgr->booleanValue( "MRU", "show_clear", false ) );  // do not show "Clear" item by default
2306       else if ( param == "show_mru" )
2307         mru->setVisible( resMgr->booleanValue( "MRU", "show_mru", false ) );          // do not show MRU menu item by default
2308     }
2309   }
2310 }
2311
2312 /*!
2313   Loads preferences
2314 */
2315 void LightApp_Application::loadPreferences()
2316 {
2317   CAM_Application::loadPreferences();
2318
2319   SUIT_ResourceMgr* aResMgr = resourceMgr();
2320
2321   if ( !aResMgr )
2322     return;
2323
2324   static bool mru_load = true;
2325   if ( mru_load )
2326   {
2327     QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
2328     if ( mru ) {
2329       mru->setVisible( aResMgr->booleanValue( "MRU", "show_mru", false ) );         // do not show MRU menu item by default
2330       mru->setVisibleCount( aResMgr->integerValue( "MRU", "visible_count", 5 ) );   // 5 MRU items by default
2331       mru->setHistoryCount( aResMgr->integerValue( "MRU", "max_count", -1 ) );      // unlimited history by default
2332       mru->setInsertMode( aResMgr->integerValue( "MRU", "insert_mode", 0 ) );       // QtxMRUAction::MoveFirst by default
2333       mru->setLinkType( aResMgr->integerValue( "MRU", "link_type", 0 ) );           // QtxMRUAction::LinkAuto by default
2334       mru->setClearPossible( aResMgr->booleanValue( "MRU", "show_clear", false ) ); // do not show "Clear" item by default
2335       mru->loadLinks( aResMgr, "MRU" );
2336     }
2337     mru_load = false;
2338   }
2339
2340   myWinGeom.clear();
2341   QStringList mods = aResMgr->parameters( "windows_geometry" );
2342   for ( QStringList::const_iterator it = mods.begin(); it != mods.end(); ++it )
2343   {
2344     QByteArray arr;
2345     if ( aResMgr->value( "windows_geometry", *it, arr ) )
2346       myWinGeom.insert( *it, arr );
2347   }
2348
2349   myWinVis.clear();
2350   mods = aResMgr->parameters( "windows_visibility" );
2351   for ( QStringList::const_iterator itr = mods.begin(); itr != mods.end(); ++itr )
2352   {
2353     QByteArray arr;
2354     if ( aResMgr->value( "windows_visibility", *itr, arr ) )
2355       myWinVis.insert( *itr, arr );
2356   }
2357
2358   if ( desktop() )
2359     desktop()->retrieveGeometry( aResMgr->stringValue( "desktop", "geometry" ) );
2360 }
2361
2362 /*!
2363   Saves preferences
2364 */
2365 void LightApp_Application::savePreferences()
2366 {
2367   CAM_Application::savePreferences();
2368
2369   saveDockWindowsState();
2370
2371   SUIT_ResourceMgr* aResMgr = resourceMgr();
2372
2373   if ( !aResMgr )
2374     return;
2375
2376   QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
2377   if ( mru )
2378     mru->saveLinks( aResMgr, "MRU" );
2379
2380   for ( WinGeom::const_iterator it = myWinGeom.begin(); it != myWinGeom.end(); ++it )
2381     aResMgr->setValue( "windows_geometry", it.key(), it.value() );
2382
2383   for ( WinVis::const_iterator itr = myWinVis.begin(); itr != myWinVis.end(); ++itr )
2384     aResMgr->setValue( "windows_visibility", itr.key(), itr.value() );
2385
2386   if ( desktop() )
2387     aResMgr->setValue( "desktop", "geometry", desktop()->storeGeometry() );
2388
2389   aResMgr->save();
2390 }
2391
2392 /*!
2393   Updates desktop title
2394 */
2395 void LightApp_Application::updateDesktopTitle()
2396 {
2397   QString aTitle = applicationName();
2398   QString aVer = applicationVersion();
2399   if ( !aVer.isEmpty() )
2400     aTitle += QString( " " ) + aVer;
2401
2402   if ( activeStudy() ) {
2403     QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false );
2404     aTitle += QString( " - [%1]" ).arg( sName );
2405   }
2406
2407   desktop()->setWindowTitle( aTitle );
2408 }
2409
2410 /*!
2411   \brief Get map of the operations which can be performed
2412   on the module activation.
2413
2414   The method should return the map of the kind \c {<id>:<name>}
2415   where \c <id> is an integer identifier of the operation and
2416   \c <name> is a title for the button to be added to the
2417   dialog box. After user selects the required operation by the
2418   clicking the corresponding button in the dialog box, its identifier
2419   is passed to the moduleActionSelected() method to process
2420   the made choice.
2421
2422   \return map of the operations
2423   \sa moduleActionSelected()
2424 */
2425 QMap<int, QString> LightApp_Application::activateModuleActions() const
2426 {
2427   QMap<int, QString> opmap;
2428   opmap.insert( NewStudyId,  tr( "ACTIVATE_MODULE_OP_NEW" ) );
2429   opmap.insert( OpenStudyId, tr( "ACTIVATE_MODULE_OP_OPEN" ) );
2430   return opmap;
2431 }
2432
2433 /*!
2434   \brief Called when the used selectes required operation chosen
2435   from "Activate module" dialog box.
2436
2437   Performs the required operation according to the user choice.
2438
2439   \param id operation identifier
2440   \sa activateModuleActions()
2441 */
2442 void LightApp_Application::moduleActionSelected( const int id )
2443 {
2444   switch ( id ) {
2445   case NewStudyId:
2446     onNewDoc();
2447     break;
2448   case OpenStudyId:
2449     onOpenDoc();
2450     break;
2451   default:
2452     break;
2453   }
2454 }
2455
2456 /*!
2457   Updates windows after close document
2458 */
2459 void LightApp_Application::afterCloseDoc()
2460 {
2461   updateWindows();
2462
2463   CAM_Application::afterCloseDoc();
2464 }
2465
2466 /*!
2467   Updates actions of active module
2468 */
2469 void LightApp_Application::updateModuleActions()
2470 {
2471   QString modName;
2472   if ( activeModule() )
2473     modName = activeModule()->moduleName();
2474
2475   LightApp_ModuleAction* moduleAction =
2476     qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
2477   if ( moduleAction )
2478     moduleAction->setActiveModule( modName );
2479 }
2480
2481 /*!
2482   Gets current windows.
2483   \param winMap - output current windows map.
2484 */
2485 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
2486 {
2487   winMap.clear();
2488   if ( !activeStudy() )
2489     return;
2490
2491   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2492     ((LightApp_Module*)activeModule())->windows( winMap );
2493   else
2494     defaultWindows( winMap );
2495 }
2496
2497 /*!
2498   Gets current view managers.
2499   \param lst - output current view managers list.
2500 */
2501 void LightApp_Application::currentViewManagers( QStringList& lst ) const
2502 {
2503   lst.clear();
2504   if ( !activeStudy() )
2505     return;
2506
2507   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2508     ((LightApp_Module*)activeModule())->viewManagers( lst );
2509   else
2510     defaultViewManagers( lst );
2511 }
2512
2513 /*!
2514   Updates windows
2515 */
2516 void LightApp_Application::updateWindows()
2517 {
2518   QMap<int, int> winMap;
2519   currentWindows( winMap );
2520
2521   if ( activeStudy() )
2522   {
2523     for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
2524     {
2525       if ( !dockWindow( it.key() ) )
2526         getWindow( it.key() );
2527     }
2528   }
2529
2530   for ( WinMap::ConstIterator it = myWin.begin(); it != myWin.end(); ++it )
2531   {
2532     QWidget* wid = it.value();
2533     if ( activeStudy() )
2534       wid->setVisible( winMap.contains( it.key() ) );
2535     else
2536       delete wid;
2537   }
2538
2539   if ( activeStudy() )
2540     loadDockWindowsState();
2541   else
2542     myWin.clear();
2543 }
2544
2545 /*!
2546   Updates view managers
2547 */
2548 void LightApp_Application::updateViewManagers()
2549 {
2550   QStringList lst;
2551   currentViewManagers( lst );
2552
2553   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
2554     getViewManager( *it, true );
2555 }
2556
2557 /*!
2558   Loads windows geometry
2559 */
2560 void LightApp_Application::loadDockWindowsState()
2561 {
2562   if ( !desktop() )
2563     return;
2564
2565   bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2566   if( !store )
2567     return;
2568
2569   QString modName;
2570   if ( activeModule() )
2571     modName = activeModule()->name();
2572
2573   if ( myWinGeom.contains( modName ) )
2574     desktop()->restoreState( myWinGeom[modName] );
2575
2576   if ( !myWinVis.contains( modName ) )
2577     return;
2578
2579   QMap<QString, bool> tbMap, dwMap;
2580   dockWindowsState( myWinVis[modName], tbMap, dwMap );
2581
2582   QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
2583   for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit )
2584   {
2585     QToolBar* tb = *tit;
2586
2587     QObject* po = Qtx::findParent( tb, "QMainWindow" );
2588     if ( po != desktop() )
2589       continue;
2590
2591     if ( tbMap.contains( tb->objectName() ) )
2592       tb->setVisible( tbMap[tb->objectName()] );
2593   }
2594
2595   QList<QDockWidget*> dwList = qFindChildren<QDockWidget*>( desktop() );
2596   for ( QList<QDockWidget*>::iterator dit = dwList.begin(); dit != dwList.end(); ++dit )
2597   {
2598     QDockWidget* dw = *dit;
2599
2600     QObject* po = Qtx::findParent( dw, "QMainWindow" );
2601     if ( po != desktop() )
2602       continue;
2603
2604     if ( dwMap.contains( dw->objectName() ) )
2605       dw->setVisible( dwMap[dw->objectName()] );
2606   }
2607 }
2608
2609 /*!
2610   Saves windows geometry
2611 */
2612 void LightApp_Application::saveDockWindowsState()
2613 {
2614   if ( !desktop() )
2615     return;
2616
2617   bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2618   if( !store )
2619     return;
2620
2621   QString modName;
2622   if ( activeModule() )
2623     modName = activeModule()->name();
2624
2625   myWinGeom.insert( modName, desktop()->saveState() );
2626
2627   QByteArray visArr;
2628   if ( myWinVis.contains( modName ) )
2629     visArr = myWinVis[modName];
2630
2631   QMap<QString, bool> tbMap, dwMap;
2632   dockWindowsState( visArr, tbMap, dwMap );
2633
2634   QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
2635   for ( QList<QToolBar*>::iterator it = tbList.begin(); it != tbList.end(); ++it )
2636   {
2637     QToolBar* tb = *it;
2638     tbMap.insert( tb->objectName(), tb->toggleViewAction()->isChecked() );
2639   }
2640
2641   QList<QDockWidget*> dwList = qFindChildren<QDockWidget*>( desktop() );
2642   for ( QList<QDockWidget*>::iterator it = dwList.begin(); it != dwList.end(); ++it )
2643   {
2644     QDockWidget* wid = *it;
2645     dwMap.insert( wid->objectName(), wid->toggleViewAction()->isChecked() );
2646   }
2647
2648   visArr = dockWindowsState( tbMap, dwMap );
2649
2650   myWinVis.insert( modName, visArr );
2651 }
2652
2653 QByteArray LightApp_Application::dockWindowsState( const QMap<QString, bool>& tb, const QMap<QString, bool>& dw ) const
2654 {
2655   QByteArray visArr;
2656   QDataStream stream( &visArr, QIODevice::WriteOnly );
2657
2658   stream << (uchar)ToolBarMarker;
2659   stream << tb.size();
2660   for ( QMap<QString, bool>::const_iterator tit = tb.begin(); tit != tb.end(); ++tit )
2661   {
2662     stream << tit.key();
2663     stream << (uchar)( tit.value() ? 1 : 0 );
2664   }
2665
2666   stream << (uchar)DockWidgetMarker;
2667   stream << dw.size();
2668   for ( QMap<QString, bool>::const_iterator wit = dw.begin(); wit != dw.end(); ++wit )
2669   {
2670     stream << wit.key();
2671     stream << (uchar)( wit.value() ? 1 : 0 );
2672   }
2673
2674   return visArr;
2675 }
2676
2677 void LightApp_Application::dockWindowsState( const QByteArray& arr, QMap<QString, bool>& tb, QMap<QString, bool>& dw ) const
2678 {
2679   tb.clear();
2680   dw.clear();
2681
2682   QByteArray visArr = arr;
2683   QDataStream stream( &visArr, QIODevice::ReadOnly );
2684
2685   uchar marker;
2686   stream >> marker;
2687   if ( marker != ToolBarMarker )
2688     return;
2689
2690   int lines;
2691   stream >> lines;
2692   for ( int i = 0; i < lines; ++i )
2693   {
2694     QString objectName;
2695     stream >> objectName;
2696     uchar shown;
2697     stream >> shown;
2698     tb.insert( objectName, shown );
2699   }
2700
2701   stream >> marker;
2702   if ( marker != DockWidgetMarker )
2703     return;
2704
2705   stream >> lines;
2706   for ( int j = 0; j < lines; ++j )
2707   {
2708     QString objectName;
2709     stream >> objectName;
2710     uchar shown;
2711     stream >> shown;
2712     dw.insert( objectName, shown );
2713   }
2714 }
2715
2716 /*!
2717   Adds icon names for modules
2718 */
2719 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
2720 {
2721   iconMap.clear();
2722
2723   SUIT_ResourceMgr* resMgr = resourceMgr();
2724   if ( !resMgr )
2725     return;
2726
2727   QStringList modList;
2728   modules( modList, false );
2729
2730   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
2731   {
2732     QString modName = *it;
2733     QString modIntr = moduleName( modName );
2734     QString modIcon = resMgr->stringValue( modIntr, "icon", QString() );
2735
2736     if ( modIcon.isEmpty() )
2737       continue;
2738
2739     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
2740       modIcon += QString( ".png" );
2741
2742     iconMap.insert( modName, modIcon );
2743   }
2744 }
2745
2746 /*!
2747   Inserts items in popup, which necessary for current application
2748 */
2749 void LightApp_Application::contextMenuPopup( const QString& type, QMenu* thePopup, QString& title )
2750 {
2751   CAM_Application::contextMenuPopup( type, thePopup, title );
2752
2753   SUIT_DataBrowser* ob = objectBrowser();
2754   if ( ob && type == ob->popupClientType() ) {
2755     thePopup->addSeparator();
2756     QAction* a = thePopup->addAction( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
2757     if ( ob->updateKey() )
2758       a->setShortcut( ob->updateKey() );
2759   }
2760 }
2761
2762 /*!
2763   Create empty study
2764 */
2765 void LightApp_Application::createEmptyStudy()
2766 {
2767   CAM_Application::createEmptyStudy();
2768
2769   if ( objectBrowser() )
2770     objectBrowser()->updateTree();
2771 }
2772
2773 /*!
2774   Activates module
2775   \param mod - module to be activated
2776 */
2777 bool LightApp_Application::activateModule( CAM_Module* mod )
2778 {
2779   bool res = CAM_Application::activateModule( mod );
2780
2781   if ( objectBrowser() )
2782     objectBrowser()->updateTree();
2783
2784   return res;
2785 }
2786
2787 /*!
2788   \return keyborad accelerators manager object
2789 */
2790 SUIT_Accel* LightApp_Application::accel() const
2791 {
2792   return myAccel;
2793 }
2794
2795 /*!
2796   Removes dead widget container from map
2797 */
2798 void LightApp_Application::onWCDestroyed( QObject* ob )
2799 {
2800   // remove destroyed widget container from windows map
2801   for ( WinMap::ConstIterator itr = myWin.begin(); itr != myWin.end(); ++itr )
2802   {
2803     if ( itr.value() != ob )
2804       continue;
2805
2806     int key = itr.key();
2807     myWin.remove( key );
2808     break;
2809   }
2810 }
2811
2812 void LightApp_Application::onMRUActivated( const QString& name )
2813 {
2814   SUIT_Session* s = SUIT_Session::session();
2815   if ( s && s->activeApplication() == this )
2816     onOpenDoc( name );
2817 }
2818
2819 void LightApp_Application::onStylePreferences()
2820 {
2821   Style_PrefDlg dlg( desktop() );
2822   dlg.exec();
2823
2824   resourceMgr()->setValue( "Style", "use_salome_style", Style_Salome::isActive() );
2825 }
2826
2827 /*!
2828   Connects just added view manager
2829 */
2830 void LightApp_Application::addViewManager( SUIT_ViewManager* vm )
2831 {
2832   connect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2833            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2834   STD_Application::addViewManager( vm );
2835 }
2836
2837 /*!
2838   Remove view manager from memory
2839 */
2840 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
2841 {
2842   disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2843            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2844   STD_Application::removeViewManager( vm );
2845   delete vm;
2846 }
2847
2848 /*!
2849   Renames active window of desktop
2850 */
2851 void LightApp_Application::onRenameWindow()
2852 {
2853   if( !desktop() )
2854     return;
2855
2856   QWidget* w = desktop()->activeWindow();
2857   if( !w )
2858     return;
2859
2860   bool ok;
2861   QString name = QInputDialog::getText( w, tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->windowTitle(), &ok );
2862   if( ok && !name.isEmpty() )
2863     w->setWindowTitle( name );
2864 }
2865
2866 /*!
2867   Closes active window of desktop
2868 */
2869 void LightApp_Application::onCloseWindow()
2870 {
2871   if( !desktop() )
2872     return;
2873
2874   QWidget* w = desktop()->activeWindow();
2875   if( !w )
2876     return;
2877
2878   w->close();
2879 }
2880
2881 /*!
2882   Closes all windows of desktop
2883 */
2884 void LightApp_Application::onCloseAllWindow()
2885 {
2886   STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
2887   if( !desk )
2888     return;
2889
2890   QList<SUIT_ViewWindow*> wndList = desk->windows();
2891   SUIT_ViewWindow* wnd;
2892   foreach( wnd, wndList )
2893   {
2894     if ( wnd )
2895       wnd->close();
2896   }
2897 }
2898
2899 /*!
2900   Groups all windows of desktop
2901 */
2902 void LightApp_Application::onGroupAllWindow()
2903 {
2904   STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
2905   if( !desk )
2906     return;
2907
2908   QtxWorkstack* wgStack = desk->workstack();
2909   if ( wgStack )
2910     wgStack->stack();
2911 }
2912
2913 /*!
2914   \return if the library of module exists
2915   \param moduleTitle - title of module
2916 */
2917 bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
2918 {
2919   if( moduleTitle.isEmpty() )
2920     return false;
2921
2922   QString lib = moduleLibrary( moduleTitle );
2923
2924   //abd: changed libSalomePyQtGUI to SalomePyQtGUI for WIN32
2925   bool isPythonModule = lib.contains("SalomePyQtGUI");
2926
2927   QStringList paths;
2928 #ifdef WIN32
2929   paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
2930 #else
2931   paths = QString(::getenv( "LD_LIBRARY_PATH" )).split( ":", QString::SkipEmptyParts );
2932 #endif
2933
2934   bool isLibFound = false;
2935   QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2936   for( ; anIt!=aLast; anIt++ )
2937   {
2938     QFileInfo inf( Qtx::addSlash( *anIt ) + lib );
2939
2940     if( inf.exists() )
2941       {
2942         isLibFound = true;
2943         break;
2944       }
2945   }
2946
2947   if ( !isLibFound )
2948     {
2949       INFOS( "****************************************************************" << std::endl
2950           << "*    Warning: library " << lib.toLatin1().constData() << " cannot be found" << std::endl
2951           << "*    Module " << moduleTitle.toLatin1().constData() << " will not be available in GUI mode" << std::endl
2952           << "****************************************************************" << std::endl );
2953     }
2954   else if ( !isPythonModule )
2955     return true;
2956
2957   if ( isPythonModule )
2958     {
2959       QString pylib = moduleName( moduleTitle ) + QString(".py");
2960       QString pylibgui = moduleName( moduleTitle ) + QString("GUI.py");
2961
2962       // Check the python library
2963 #ifdef WIN32
2964       paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
2965 #else
2966       paths = QString(::getenv( "PYTHONPATH" )).split( ":", QString::SkipEmptyParts );
2967 #endif
2968       bool isPyLib = false, isPyGuiLib = false;
2969       QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2970       for( ; anIt!=aLast; anIt++ )
2971         {
2972           QFileInfo inf( Qtx::addSlash( *anIt ) + pylib );
2973           QFileInfo infgui( Qtx::addSlash( *anIt ) + pylibgui );
2974
2975           if( !isPyLib && inf.exists() )
2976             isPyLib = true;
2977
2978           if( !isPyGuiLib && infgui.exists() )
2979             isPyGuiLib = true;
2980
2981           if ( isPyLib && isPyGuiLib && isLibFound)
2982             return true;
2983         }
2984
2985       printf( "****************************************************************\n" );
2986       printf( "*    Warning: python library for %s cannot be found:\n", moduleTitle.toLatin1().constData() );
2987       if (!isPyLib)
2988         printf( "*    No module named %s\n", moduleName( moduleTitle ).toLatin1().constData() );
2989       if (!isPyGuiLib)
2990         printf( "*    No module named %s\n", (moduleName( moduleTitle ) + QString("GUI")).toLatin1().constData() );
2991       printf( "****************************************************************\n" );
2992       return true;
2993   }
2994   return false;
2995 }
2996
2997 /*!
2998   \return default name for an active study
2999 */
3000 void LightApp_Application::setDefaultStudyName( const QString& theName )
3001 {
3002   QStringList anInfoList;
3003   modules( anInfoList, false );
3004
3005   LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
3006   if( anInfoList.count() == 1 && // to avoid a conflict between different modules
3007       !aStudy->isSaved() )
3008   {
3009     aStudy->setStudyName( theName );
3010     updateDesktopTitle();
3011   }
3012 }
3013
3014 /*!
3015   Custom event handler
3016 */
3017 bool LightApp_Application::event( QEvent* e )
3018 {
3019   if( e && e->type()==2000 )
3020   {
3021     SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
3022     QString* d = ( QString* )ce->data();
3023     if( SUIT_MessageBox::question(0, tr("WRN_WARNING"),
3024                                   d ? *d : "",
3025                                   SUIT_MessageBox::Yes | SUIT_MessageBox::No,
3026                                   SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
3027       showPreferences( tr( "PREF_APP" ) );
3028     if( d )
3029       delete d;
3030     return true;
3031   }
3032   return CAM_Application::event( e );
3033 }
3034
3035 /*! Check data object */
3036 bool LightApp_Application::checkDataObject(LightApp_DataObject* theObj)
3037 {
3038   if (theObj)
3039     {
3040       bool isSuitable = !theObj->entry().isEmpty() &&
3041                         !theObj->componentDataType().isEmpty() &&
3042                         !theObj->name().isEmpty();
3043       return isSuitable;
3044     }
3045
3046   return false;
3047 }
3048
3049 int LightApp_Application::openChoice( const QString& aName )
3050 {
3051   int choice = CAM_Application::openChoice( aName );
3052
3053   if ( choice == OpenExist ) // The document is already open.
3054   {
3055     // Do you want to reload it?
3056     if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "QUE_DOC_ALREADYOPEN" ).arg( aName ),
3057                                     SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No ) == SUIT_MessageBox::Yes )
3058       choice = OpenReload;
3059   }
3060
3061   return choice;
3062 }
3063
3064 bool LightApp_Application::openAction( const int choice, const QString& aName )
3065 {
3066   bool res = false;
3067   switch ( choice )
3068   {
3069   case OpenReload:
3070     {
3071       STD_Application* app = 0;
3072       SUIT_Session* session = SUIT_Session::session();
3073       QList<SUIT_Application*> appList = session->applications();
3074       for ( QList<SUIT_Application*>::iterator it = appList.begin(); it != appList.end() && !app; ++it )
3075       {
3076         if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName )
3077           app = ::qobject_cast<STD_Application*>( *it );
3078       }
3079
3080       if ( app )
3081       {
3082         app->onCloseDoc( false );
3083         appList = session->applications();
3084         STD_Application* other = 0;
3085         for ( QList<SUIT_Application*>::iterator it = appList.begin(); it != appList.end() && !other; ++it )
3086           other = ::qobject_cast<STD_Application*>( *it );
3087
3088         if ( other )
3089           res = other->onOpenDoc( aName );
3090       }
3091     }
3092     break;
3093   default:
3094     res = CAM_Application::openAction( choice, aName );
3095     break;
3096   }
3097
3098   return res;
3099 }