Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/gui.git] / src / LightApp / LightApp_Application.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File:      LightApp_Application.cxx
20 // Created:   6/20/2005 18:39:45 PM
21 // Author:    Natalia Donis
22 // Copyright (C) CEA 2005
23
24 #ifndef DISABLE_PYCONSOLE
25   #include "PythonConsole_PyInterp.h" // WARNING! This include must be the first!
26   #include <PythonConsole_PyConsole.h>
27 #endif
28
29 #include "LightApp_Application.h"
30 #include "LightApp_WidgetContainer.h"
31 #include "LightApp_Module.h"
32 #include "LightApp_DataModel.h"
33 #include "LightApp_Study.h"
34 #include "LightApp_Preferences.h"
35 #include "LightApp_PreferencesDlg.h"
36 #include "LightApp_ModuleDlg.h"
37 #include "LightApp_AboutDlg.h"
38
39 #include "LightApp_OBFilter.h"
40
41 #include "LightApp_EventFilter.h"
42
43 #include "LightApp_OBSelector.h"
44 #include "LightApp_SelectionMgr.h"
45 #include "LightApp_DataObject.h"
46
47 #include <CAM_Module.h>
48 #include <CAM_DataModel.h>
49 #include <CAM_Study.h>
50 #include <STD_TabDesktop.h>
51
52 #include <SUIT_Session.h>
53 #include <SUIT_Study.h>
54 #include <SUIT_FileDlg.h>
55 #include <SUIT_ResourceMgr.h>
56 #include <SUIT_Tools.h>
57 #include <SUIT_Accel.h>
58
59 #include <QtxMRUAction.h>
60 #include <QtxDockAction.h>
61 #include <QtxToolBar.h>
62 #include <qprocess.h>
63
64 #include <LogWindow.h>
65 #include <OB_Browser.h>
66 #include <OB_ListView.h>
67 #include <OB_ObjSearch.h>
68
69 #ifndef DISABLE_GLVIEWER
70   #include <GLViewer_Viewer.h>
71   #include <GLViewer_ViewManager.h>
72   #include "LightApp_GLSelector.h"
73 #endif
74
75 #ifndef DISABLE_PLOT2DVIEWER
76   #include <Plot2d_ViewManager.h>
77   #include <Plot2d_ViewModel.h>
78 #ifndef DISABLE_SALOMEOBJECT
79   #include <SPlot2d_ViewModel.h>
80 #else
81   #include <Plot2d_ViewModel.h>
82 #endif
83 #endif
84
85 #ifndef DISABLE_OCCVIEWER
86   #include <OCCViewer_ViewManager.h>
87 #ifndef DISABLE_SALOMEOBJECT
88   #include <SOCC_ViewModel.h>
89 #else
90   #include <OCCViewer_ViewModel.h>
91 #endif
92   #include "LightApp_OCCSelector.h"
93 #endif
94
95 #ifndef DISABLE_VTKVIEWER
96 #ifndef DISABLE_SALOMEOBJECT
97   #include <SVTK_ViewModel.h>
98   #include <SVTK_ViewManager.h>
99   #include "LightApp_VTKSelector.h"
100 #else
101   #include <VTKViewer_ViewModel.h>
102   #include <VTKViewer_ViewManager.h>
103 #endif
104   #include <VTKViewer_ViewModel.h>
105 #endif
106
107 //#ifndef DISABLE_SUPERVGRAPHVIEWER
108 //  #include <SUPERVGraph_ViewModel.h>
109 //  #include <SUPERVGraph_ViewFrame.h>
110 //  #include <SUPERVGraph_ViewManager.h>
111 //#endif
112
113 #ifndef DISABLE_QXGRAPHVIEWER
114   #include <QxGraph_ViewModel.h>
115   #include <QxGraph_ViewWindow.h>
116   #include <QxGraph_ViewManager.h>
117 #endif
118
119 #include <QtxWorkstack.h>
120
121 #include <qdir.h>
122 #include <qimage.h>
123 #include <qstring.h>
124 #include <qwidget.h>
125 #include <qstringlist.h>
126 #include <qfile.h>
127 #include <qapplication.h>
128 #include <qmap.h>
129 #include <qstatusbar.h>
130 #include <qthread.h>
131 #include <qobjectlist.h>
132 #include <qcombobox.h>
133 #include <qinputdialog.h>
134 #include <qmessagebox.h>
135 #include <qfontdatabase.h>
136
137 #define FIRST_HELP_ID 1000000
138
139 #ifndef DISABLE_SALOMEOBJECT
140   #include "SALOME_InteractiveObject.hxx"
141   #include "SALOME_ListIO.hxx"
142 #endif
143
144 static const char* imageEmptyIcon[] = {
145 "20 20 1 1",
146 ".      c None",
147 "....................",
148 "....................",
149 "....................",
150 "....................",
151 "....................",
152 "....................",
153 "....................",
154 "....................",
155 "....................",
156 "....................",
157 "....................",
158 "....................",
159 "....................",
160 "....................",
161 "....................",
162 "....................",
163 "....................",
164 "....................",
165 "....................",
166 "...................."};
167
168 int LightApp_Application::lastStudyId = 0;
169
170 /*!
171   \return last global id of study
172 */
173 int LightApp_Application::studyId()
174 {
175   return LightApp_Application::lastStudyId;
176 }
177
178 /*!Create new instance of LightApp_Application.*/
179 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
180 {
181   return new LightApp_Application();
182 }
183
184 /*! \var global preferences of LightApp */
185 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
186
187 /*!
188   \class LightApp_Application
189   Application containing LightApp module
190 */
191
192 /*!Constructor.*/
193 LightApp_Application::LightApp_Application()
194 : CAM_Application( false ),
195 myPrefs( 0 )
196 {
197   STD_TabDesktop* desk = new STD_TabDesktop();
198
199   setDesktop( desk );
200
201   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
202   QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
203
204   desktop()->setIcon( aLogo );
205   desktop()->setDockableMenuBar( true );
206   desktop()->setDockableStatusBar( false );
207
208   // base logo (salome itself)
209   desktop()->addLogo( "_app_base",  aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
210   // extra logo (salome-based application)
211   desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
212
213   clearViewManagers();
214
215   mySelMgr = new LightApp_SelectionMgr( this );
216
217   myAccel = SUIT_Accel::getAccel();
218
219 #ifndef DISABLE_OCCVIEWER
220   myAccel->setActionKey( SUIT_Accel::PanLeft,     CTRL+Key_Left,     OCCViewer_Viewer::Type() );
221   myAccel->setActionKey( SUIT_Accel::PanRight,    CTRL+Key_Right,    OCCViewer_Viewer::Type() );
222   myAccel->setActionKey( SUIT_Accel::PanUp,       CTRL+Key_Up,       OCCViewer_Viewer::Type() );
223   myAccel->setActionKey( SUIT_Accel::PanDown,     CTRL+Key_Down,     OCCViewer_Viewer::Type() );
224   myAccel->setActionKey( SUIT_Accel::ZoomIn,      CTRL+Key_Plus,     OCCViewer_Viewer::Type() );
225   myAccel->setActionKey( SUIT_Accel::ZoomOut,     CTRL+Key_Minus,    OCCViewer_Viewer::Type() );
226   myAccel->setActionKey( SUIT_Accel::ZoomFit,     CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
227   myAccel->setActionKey( SUIT_Accel::RotateLeft,  ALT+Key_Left,      OCCViewer_Viewer::Type() );
228   myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right,     OCCViewer_Viewer::Type() );
229   myAccel->setActionKey( SUIT_Accel::RotateUp,    ALT+Key_Up,        OCCViewer_Viewer::Type() );
230   myAccel->setActionKey( SUIT_Accel::RotateDown,  ALT+Key_Down,      OCCViewer_Viewer::Type() );
231 #endif
232 #ifndef DISABLE_VTKVIEWER
233   myAccel->setActionKey( SUIT_Accel::PanLeft,     CTRL+Key_Left,     VTKViewer_Viewer::Type() );
234   myAccel->setActionKey( SUIT_Accel::PanRight,    CTRL+Key_Right,    VTKViewer_Viewer::Type() );
235   myAccel->setActionKey( SUIT_Accel::PanUp,       CTRL+Key_Up,       VTKViewer_Viewer::Type() );
236   myAccel->setActionKey( SUIT_Accel::PanDown,     CTRL+Key_Down,     VTKViewer_Viewer::Type() );
237   myAccel->setActionKey( SUIT_Accel::ZoomIn,      CTRL+Key_Plus,     VTKViewer_Viewer::Type() );
238   myAccel->setActionKey( SUIT_Accel::ZoomOut,     CTRL+Key_Minus,    VTKViewer_Viewer::Type() );
239   myAccel->setActionKey( SUIT_Accel::ZoomFit,     CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
240   myAccel->setActionKey( SUIT_Accel::RotateLeft,  ALT+Key_Left,      VTKViewer_Viewer::Type() );
241   myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right,     VTKViewer_Viewer::Type() );
242   myAccel->setActionKey( SUIT_Accel::RotateUp,    ALT+Key_Up,        VTKViewer_Viewer::Type() );
243   myAccel->setActionKey( SUIT_Accel::RotateDown,  ALT+Key_Down,      VTKViewer_Viewer::Type() );
244 #endif
245 #ifndef DISABLE_PLOT2DVIEWER
246   myAccel->setActionKey( SUIT_Accel::PanLeft,     CTRL+Key_Left,     Plot2d_Viewer::Type() );
247   myAccel->setActionKey( SUIT_Accel::PanRight,    CTRL+Key_Right,    Plot2d_Viewer::Type() );
248   myAccel->setActionKey( SUIT_Accel::PanUp,       CTRL+Key_Up,       Plot2d_Viewer::Type() );
249   myAccel->setActionKey( SUIT_Accel::PanDown,     CTRL+Key_Down,     Plot2d_Viewer::Type() );
250   myAccel->setActionKey( SUIT_Accel::ZoomIn,      CTRL+Key_Plus,     Plot2d_Viewer::Type() );
251   myAccel->setActionKey( SUIT_Accel::ZoomOut,     CTRL+Key_Minus,    Plot2d_Viewer::Type() );
252   myAccel->setActionKey( SUIT_Accel::ZoomFit,     CTRL+Key_Asterisk, Plot2d_Viewer::Type() );
253 #endif
254
255   connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
256
257   // Set existing font for the python console in resources
258   if( !aResMgr->hasValue( "PyConsole", "font" ) )
259     return;
260   
261   QFont f = aResMgr->fontValue( "PyConsole", "font" );
262   QFontDatabase fdb;
263   QStringList famdb = fdb.families();
264   
265   if ( famdb.contains(f.family()) || !aResMgr->hasValue( "PyConsole", "additional_families" ) )
266     return;
267   
268   QStringList anAddFamilies = QStringList::split( ";", aResMgr->stringValue( "PyConsole", "additional_families" ) );
269   QString aFamily;
270   for ( QStringList::Iterator it = anAddFamilies.begin(); it != anAddFamilies.end(); ++it )
271     {
272       aFamily = *it;
273       if ( famdb.contains(aFamily) )
274         {
275           f.setFamily( aFamily );
276           aResMgr->setValue( "PyConsole", "font", f );
277           break;
278         }
279     }
280 }
281
282 /*!Destructor.
283  *\li Save window geometry.
284  *\li Save desktop geometry.
285  *\li Save resource maneger.
286  *\li Delete selection manager.
287  */
288 LightApp_Application::~LightApp_Application()
289 {
290   delete mySelMgr;
291 }
292
293 /*!Start application.*/
294 void LightApp_Application::start()
295 {
296   if ( desktop() )
297     desktop()->loadGeometry( resourceMgr(), "desktop" );
298
299   CAM_Application::start();
300
301   QAction* a = action( ViewWindowsId );
302   if ( a && a->inherits( "QtxDockAction" ) )
303     ((QtxDockAction*)a)->setAutoPlace( true );
304
305   updateWindows();
306   updateViewManagers();
307
308   putInfo( "" );
309   desktop()->statusBar()->message( "" );
310
311   LightApp_EventFilter::Init();
312 }
313
314 /*!Gets application name.*/
315 QString LightApp_Application::applicationName() const
316 {
317   return tr( "APP_NAME" );
318 }
319
320 /*!Gets application version.*/
321 QString LightApp_Application::applicationVersion() const
322 {
323   static QString _app_version;
324
325   if ( _app_version.isEmpty() )
326   {
327     QString resVersion = tr( "APP_VERSION" );
328     if ( resVersion != "APP_VERSION" )
329     {
330       _app_version = resVersion;
331     }
332     else
333     {
334       QString path( ::getenv( "GUI_ROOT_DIR" ) );
335       if ( !path.isEmpty() )
336         path += QDir::separator();
337       path += QString( "bin/salome/VERSION" );
338
339       QFile vf( path );
340       if ( vf.open( IO_ReadOnly ) )
341       {
342         QString line;
343         vf.readLine( line, 1024 );
344         vf.close();
345
346         if ( !line.isEmpty() )
347         {
348           while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
349             line.remove( line.length() - 1, 1 );
350
351           int idx = line.findRev( ":" );
352           if ( idx != -1 )
353             _app_version = line.mid( idx + 1 ).stripWhiteSpace();
354         }
355       }
356     }
357   }
358   return _app_version;  
359 }
360
361 /*!Load module by \a name.*/
362 CAM_Module* LightApp_Application::loadModule( const QString& name )
363 {
364   CAM_Module* mod = CAM_Application::loadModule( name );
365   if ( mod )
366   {
367     connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
368     connect( this, SIGNAL( studySaved() ),  mod, SLOT( onModelSaved() ) );
369     connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
370   }
371   return mod;
372 }
373
374 /*!Activate module by \a modName*/
375 bool LightApp_Application::activateModule( const QString& modName )
376 {
377   QString actName;
378   CAM_Module* prevMod = activeModule();
379
380   if ( prevMod )
381     actName = prevMod->moduleName();
382
383   if ( actName == modName )
384     return true;
385
386   putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );  
387
388   saveWindowsGeometry();
389
390   bool status = CAM_Application::activateModule( modName );
391
392   updateModuleActions();
393
394   putInfo( "" );  
395
396   if ( !status )
397     return false;
398
399   updateWindows();
400   updateViewManagers();
401
402   return true;
403 }
404
405 /*!
406   Opens other study into active Study. If Study is empty - creates it.
407   \param theName - name of study
408 */
409 bool LightApp_Application::useStudy(const QString& theName)
410 {
411   createEmptyStudy();
412   LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
413   bool res = false;
414   if (aStudy)
415     res = aStudy->loadDocument( theName );
416   updateDesktopTitle();
417   updateCommandsStatus();
418   return res;
419 }
420
421 /*!Gets selection manager.*/
422 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
423 {
424   return mySelMgr;
425 }
426
427 /*!Creat action "New window" for certain type of viewer:*/
428 void LightApp_Application::createActionForViewer( const int id,
429                                                   const int parentId,
430                                                   const QString& suffix,
431                                                   const int accel )
432 {
433   QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ), QIconSet(),
434                                tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
435                                tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
436                                accel, desktop(), false, this, SLOT( onNewWindow() ) );
437   createMenu( a, parentId, -1 );
438 }
439
440 /*!Create actions:*/
441 void LightApp_Application::createActions()
442 {
443   STD_Application::createActions();
444
445   SUIT_Desktop* desk = desktop();
446   SUIT_ResourceMgr* resMgr = resourceMgr();
447
448   //! Preferences
449   createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
450                 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
451                 CTRL+Key_F, desk, false, this, SLOT( onPreferences() ) );
452
453   //! Help for modules
454   int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
455   int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
456   createMenu( separator(), helpMenu, -1, 1 );
457
458   QStringList aModuleList;
459   modules( aModuleList, false );
460
461   int id = LightApp_Application::UserID + FIRST_HELP_ID;
462   // help for KERNEL and GUI
463   QCString dir;
464   QString aFileName = "index.html";
465   QString root;
466   QAction* a;
467   if (dir = getenv("GUI_ROOT_DIR")) {
468     root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") +
469                           Qtx::addSlash("salome") + Qtx::addSlash("gui") +  Qtx::addSlash("GUI") );
470     if ( QFileInfo( root + aFileName ).exists() ) {
471       a = createAction( id, tr( QString("GUI Help") ), QIconSet(),
472                         tr( QString("GUI Help") ),
473                         tr( QString("GUI Help") ),
474                         0, desk, false, this, SLOT( onHelpContentsModule() ) );
475       a->setName( QString("GUI") );
476       createMenu( a, helpModuleMenu, -1 );
477       id++;
478     }
479   }
480   if (dir = getenv("KERNEL_ROOT_DIR")) {
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") ), QIconSet(),
485                         tr( QString("KERNEL Help") ),
486                         tr( QString("KERNEL Help") ),
487                         0, desk, false, this, SLOT( onHelpContentsModule() ) );
488       a->setName( QString("KERNEL") );
489       createMenu( a, helpModuleMenu, -1 );
490       id++;
491     }
492   }
493   // help for other existing modules
494   QStringList::Iterator it;
495   for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
496   {
497     if ( (*it).isEmpty() )
498       continue;
499
500     QString modName = moduleName( *it );
501     
502     if (dir = getenv( modName + "_ROOT_DIR")) {
503       root = Qtx::addSlash( Qtx::addSlash(dir) +  Qtx::addSlash("share") + Qtx::addSlash("doc") + 
504                             Qtx::addSlash("salome") + Qtx::addSlash("gui") +  Qtx::addSlash(modName) );
505       if ( QFileInfo( root + aFileName ).exists() ) {
506
507         QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
508                                    tr( moduleTitle(modName) + QString(" Help") ),
509                                    tr( moduleTitle(modName) + QString(" Help") ),
510                                    0, desk, false, this, SLOT( onHelpContentsModule() ) );
511         a->setName( modName );
512         createMenu( a, helpModuleMenu, -1 );
513         id++;
514       }
515     }
516   }
517
518   //! MRU
519   QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
520   connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
521   registerAction( MRUId, mru );
522
523   // default icon for neutral point ('SALOME' module)
524   QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
525   if ( defIcon.isNull() )
526     defIcon = QPixmap( imageEmptyIcon );
527
528   //! default icon for any module
529   QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
530   if ( modIcon.isNull() )
531     modIcon = QPixmap( imageEmptyIcon );
532
533   QStringList modList;
534   modules( modList, false );
535
536   if( modList.count()>1 )
537   {
538     QToolBar* modTBar = new QtxToolBar( true, desk );
539     modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
540
541     QActionGroup* modGroup = new QActionGroup( this );
542     modGroup->setExclusive( true );
543     modGroup->setUsesDropDown( true );
544
545     a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
546                       tr( "PRP_APP_MODULE" ), 0, desk, true );
547     modGroup->add( a );
548     myActions.insert( QString(), a );
549
550     QMap<QString, QString> iconMap;
551     moduleIconNames( iconMap );
552
553     const int iconSize = 20;
554
555     modGroup->addTo( modTBar );
556     QObjectList *l = modTBar->queryList( "QComboBox" );
557     QObjectListIt oit( *l );
558     while ( QObject* obj = oit.current() ) {
559       QComboBox* cb = (QComboBox*)obj;
560       if ( cb ) cb->setFocusPolicy( QWidget::NoFocus );
561     ++oit;
562     }
563     delete l;
564   
565     modTBar->addSeparator();
566
567     for ( it = modList.begin(); it != modList.end(); ++it )
568     {
569       if ( !isLibExists( *it ) )
570         continue;
571     
572       QString iconName;
573       if ( iconMap.contains( *it ) )
574         iconName = iconMap[*it];
575
576       QString modName = moduleName( *it );
577
578       QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
579       if ( icon.isNull() )
580       {
581         icon = modIcon;
582         printf( "****************************************************************\n" );
583         printf( "*    Icon for %s not found. Using the default one.\n", (*it).latin1() );
584         printf( "****************************************************************\n" );
585       }
586
587       icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
588
589       QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
590       a->addTo( modTBar );
591       modGroup->add( a );
592
593       myActions.insert( *it, a );
594     }
595
596     SUIT_Tools::simplifySeparators( modTBar );
597     connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
598   }
599
600   // New window
601   int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 );
602   int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
603   createMenu( separator(), windowMenu, -1, 1 );
604
605
606 #ifndef DISABLE_GLVIEWER
607   createActionForViewer( NewGLViewId, newWinMenu, QString::number( 0 ), ALT+Key_G );
608 #endif
609 #ifndef DISABLE_PLOT2DVIEWER
610   createActionForViewer( NewPlot2dId, newWinMenu, QString::number( 1 ), ALT+Key_P );
611 #endif
612 #ifndef DISABLE_OCCVIEWER
613   createActionForViewer( NewOCCViewId, newWinMenu, QString::number( 2 ), ALT+Key_O );
614 #endif
615 #ifndef DISABLE_VTKVIEWER
616   createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), ALT+Key_K );
617 #endif
618 #ifndef DISABLE_QXGRAPHVIEWER
619   createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), ALT+Key_C );
620 #endif
621
622
623   createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
624                 SHIFT+Key_R, desk, false, this, SLOT( onRenameWindow() ) );
625   createMenu( RenameId, windowMenu, -1 );
626
627   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
628   createMenu( PreferencesId, fileMenu, 15, -1 );
629   createMenu( separator(), fileMenu, -1, 15, -1 );
630
631   /*
632   createMenu( separator(), fileMenu, -1, 100, -1 );
633   createMenu( MRUId, fileMenu, 100, -1 );
634   createMenu( separator(), fileMenu, -1, 100, -1 );
635   */
636 }
637
638 /*!On module activation action.*/
639 void LightApp_Application::onModuleActivation( QAction* a )
640 {
641   if ( !a )
642     return;
643
644   QString modName = a->menuText();
645   if ( modName == tr( "APP_NAME" ) )
646     modName = QString::null;
647
648   // Force user to create/open a study before module activation
649   QMap<QString, QString> iconMap;
650   moduleIconNames( iconMap );
651   QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
652   if ( icon.isNull() )
653     icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
654
655   bool cancelled = false;
656   while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
657     LightApp_ModuleDlg aDlg( desktop(), modName, icon );
658     QMap<int, QString> opmap = activateModuleActions();
659     for ( QMap<int, QString>::ConstIterator it = opmap.begin(); it != opmap.end(); ++it )
660       aDlg.addButton( it.data(), it.key() );
661
662     int res = aDlg.exec();
663     if ( res != QDialog::Rejected ) {
664       // some operation is selected
665       moduleActionSelected( res );
666     }
667     else {
668       putInfo( tr("INF_CANCELLED") );
669       myActions[QString()]->setOn( true );
670       cancelled = true;
671     }
672   }
673
674   if ( !cancelled )
675     activateModule( modName );
676 }
677
678 /*!Default module activation.*/
679 QString LightApp_Application::defaultModule() const
680 {
681   QStringList aModuleNames;
682   modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
683   //! If there's the one and only module --> activate it automatically
684   //! TODO: Possible improvement - default module can be taken from preferences
685   return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
686 }
687
688 /*!On new window slot.*/
689 void LightApp_Application::onNewWindow()
690 {
691   const QObject* obj = sender();
692   if ( !obj || !obj->inherits( "QAction" ) )
693     return;
694
695   QString type;
696   int id = actionId( (QAction*)obj );
697   switch ( id )
698   {
699 #ifndef DISABLE_GLVIEWER
700   case NewGLViewId:
701     type = GLViewer_Viewer::Type();
702     break;
703 #endif
704 #ifndef DISABLE_PLOT2DVIEWER
705   case NewPlot2dId:
706     type = Plot2d_Viewer::Type();
707     break;
708 #endif
709 #ifndef DISABLE_OCCVIEWER
710   case NewOCCViewId:
711     type = OCCViewer_Viewer::Type();
712     break;
713 #endif
714 #ifndef DISABLE_VTKVIEWER
715   case NewVTKViewId:
716     type = VTKViewer_Viewer::Type();
717     break;
718 #endif
719 #ifndef DISABLE_QXGRAPHVIEWER
720   case NewQxGraphViewId:
721     type = QxGraph_Viewer::Type();
722     break;
723 #endif
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   SUIT_Study* study = activeStudy();
736
737   saveWindowsGeometry();
738
739   CAM_Application::onNewDoc();
740
741   if ( !study ) // new study will be create in THIS application
742   {
743     updateWindows();
744     updateViewManagers();
745   }
746 }
747
748 /*!
749   SLOT: Opens new document
750 */
751 void LightApp_Application::onOpenDoc()
752 {
753   SUIT_Study* study = activeStudy();
754   saveWindowsGeometry();
755
756   CAM_Application::onOpenDoc();
757
758   if ( !study ) // new study will be create in THIS application
759   {
760     updateWindows();
761     updateViewManagers();
762   }
763 }
764
765 #include "SUIT_MessageBox.h"
766
767 /*!
768   SLOT: Opens new document.
769   \param aName - name of file
770 */
771 bool LightApp_Application::onOpenDoc( const QString& aName )
772 {
773   bool isAlreadyOpen = false;
774
775   // Look among opened studies
776   if (activeStudy()) { // at least one study is opened
777     SUIT_Session* aSession = SUIT_Session::session();
778     QPtrList<SUIT_Application> aAppList = aSession->applications();
779     QPtrListIterator<SUIT_Application> it (aAppList);
780     SUIT_Application* aApp = 0;
781     // iterate on all applications
782     for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
783       if (aApp->activeStudy()->studyName() == aName) {
784         isAlreadyOpen = true; // Already opened, ask user what to do
785
786         // The document ... is already open.
787         // Do you want to reload it?
788         int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
789                                              tr("QUE_DOC_ALREADYOPEN").arg(aName),
790                                              tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
791         if (aAnswer == 1) { // reload
792           if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
793             // Opened in THIS (active) application.
794             STD_Application* app1 = (STD_Application*)aAppList.at(0);
795             STD_Application* app2 = (STD_Application*)aAppList.at(1);
796             if (!app1 || !app2) {
797               // Error
798               return false;
799             }
800             if (app1->activeStudy()->studyName() == aName) {
801               // app1 is this application, we need another one
802               app1 = app2;
803             }
804             // Close document of this application. This application will be destroyed.
805             onCloseDoc(/*ask = */false);
806             // Open the file with another application, as this one will be destroyed.
807             return app1->onOpenDoc(aName);
808           } else {
809             // Opened in another application.
810             STD_Application* app = (STD_Application*)aApp;
811             if (app)
812               app->onCloseDoc(/*ask = */false);
813           }
814         } else { // do not reload
815           // OK, the study will not be reloaded, but we call
816           // CAM_Application::onOpenDoc( aName ) all the same.
817           // It will activate a desktop of the study <aName>.
818         }
819       }
820     }
821   }
822
823   bool res = CAM_Application::onOpenDoc( aName );
824
825   QAction* a = action( MRUId );
826   if ( a && a->inherits( "QtxMRUAction" ) )
827   {
828     QtxMRUAction* mru = (QtxMRUAction*)a;
829     if ( res )
830       mru->insert( aName );
831     else
832       mru->remove( aName );
833   }
834   return res;
835 }
836
837 /*!
838   SLOT: Displays "About" message box
839 */
840 void LightApp_Application::onHelpAbout()
841 {
842   LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
843   dlg->exec();
844   delete dlg;
845 }
846
847 /*!
848   SLOT: Loads document
849   \param aName - name of document
850 */
851 bool LightApp_Application::onLoadDoc( const QString& aName )
852 {
853   bool res = CAM_Application::onLoadDoc( aName );
854
855   /*jfa tmp:QAction* a = action( MRUId );
856   if ( a && a->inherits( "QtxMRUAction" ) )
857   {
858     QtxMRUAction* mru = (QtxMRUAction*)a;
859     if ( res )
860       mru->insert( aName );
861     else
862       mru->remove( aName );
863   }*/
864   return res;
865 }
866
867 /*!
868   Private SLOT: Called on selection is changed
869   Dispatchs active module that selection is changed
870 */
871 void LightApp_Application::onSelection()
872 {
873   onSelectionChanged();
874
875   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
876     ((LightApp_Module*)activeModule())->selectionChanged();
877 }
878
879 /*!
880   Sets active study.
881  \param study - SUIT_Study.
882 */
883 void LightApp_Application::setActiveStudy( SUIT_Study* study )
884 {
885   CAM_Application::setActiveStudy( study );
886
887   activateWindows();
888 }
889
890 /*!
891   Enables/Disables menu items and toolbar buttons. Rebuild menu
892 */
893 void LightApp_Application::updateCommandsStatus()
894 {
895   CAM_Application::updateCommandsStatus();
896   QAction* a = 0;
897
898 #ifndef DISABLE_GLVIEWER
899   a = action( NewGLViewId );
900   if( a )
901     a->setEnabled( activeStudy() );
902 #endif
903
904 #ifndef DISABLE_PLOT2DVIEWER
905   a = action( NewPlot2dId );
906   if( a )
907     a->setEnabled( activeStudy() );
908 #endif
909
910 #ifndef DISABLE_OCCVIEWER
911   a = action( NewOCCViewId );
912   if( a )
913     a->setEnabled( activeStudy() );
914 #endif
915
916 #ifndef DISABLE_VTKVIEWER
917   a = action( NewVTKViewId );
918   if( a )
919     a->setEnabled( activeStudy() );
920 #endif
921
922 #ifndef DISABLE_QXGRAPHVIEWER
923   a = action( NewQxGraphViewId );
924   if( a )
925     a->setEnabled( activeStudy() );
926 #endif
927 }
928
929 /*!
930   \class RunBrowser
931   Runs system command in separate thread
932 */
933 class RunBrowser: public QThread
934 {
935 public:
936   RunBrowser (LightApp_Application* app, QString theApp, QString theParams,
937               QString theHelpFile, QString theContext=NULL)
938     : myApp(theApp), myParams(theParams), 
939 #ifdef WIN32
940       myHelpFile("file://" + theHelpFile + theContext), 
941 #else
942       myHelpFile("file:" + theHelpFile + theContext),
943 #endif
944       myStatus(0),
945       myLApp( app )
946   {
947   };
948
949   virtual void run()
950   {
951     QString aCommand;
952
953     if (!myApp.isEmpty())
954     {
955       //aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
956
957       //QProcess* proc = new QProcess();
958       //proc->addArgument( aCommand );
959
960       QProcess* proc = new QProcess();
961       proc->addArgument( myApp );
962       if (!myParams.isEmpty()) proc->addArgument( myParams );
963       proc->addArgument( myHelpFile );
964       //myStatus = system(aCommand);
965
966       //if(myStatus != 0)
967       if(!proc->start())
968       {
969         QCustomEvent* ce2000 = new QCustomEvent( 2000 );
970         QString* msg = new QString( QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").arg(myApp).arg(myHelpFile) );
971         ce2000->setData( msg );
972         postEvent( myLApp, ce2000 );
973       }
974     }
975   }
976
977 private:
978   QString myApp;
979   QString myParams;
980   QString myHelpFile;
981   int myStatus;
982   LightApp_Application* myLApp;
983 };
984
985 /*!
986   SLOT: Displays help contents for choosen module
987 */
988 void LightApp_Application::onHelpContentsModule()
989 {
990   const QAction* obj = (QAction*) sender();
991
992   QString aComponentName = obj->name();
993   QString aFileName = "index.html";
994
995   QCString dir = getenv( aComponentName + "_ROOT_DIR");
996   QString homeDir = !aComponentName.compare(QString("KERNEL")) ? 
997     Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") + Qtx::addSlash("salome") ) : 
998     Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("share") + Qtx::addSlash("doc") + Qtx::addSlash("salome") + Qtx::addSlash("gui") +  Qtx::addSlash(aComponentName) );
999   
1000   QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
1001   SUIT_ResourceMgr* resMgr = resourceMgr();
1002         QString platform;
1003 #ifdef WIN32
1004         platform = "winapplication";
1005 #else
1006         platform = "application";
1007 #endif
1008         QString anApp = resMgr->stringValue("ExternalBrowser", platform);
1009 #ifdef WIN32
1010         QString quote("\""); 
1011         anApp.prepend( quote ); 
1012         anApp.append( quote ); 
1013 #endif
1014   QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
1015
1016   if (!anApp.isEmpty()) {
1017     RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
1018     rs->start();
1019   }
1020   else {
1021     if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
1022                            tr("DEFINE_EXTERNAL_BROWSER"),
1023                            tr("BUT_OK"),tr("BUT_CANCEL"),0,1,0 )==0 )
1024       onPreferences();
1025   }
1026 }
1027
1028 /*!
1029   SLOT: Displays help contents for choosen dialog
1030 */
1031 void LightApp_Application::onHelpContextModule(const QString& theComponentName, const QString& theFileName)
1032 {
1033   QCString dir = getenv( theComponentName + "_ROOT_DIR");
1034   QString homeDir = Qtx::addSlash(Qtx::addSlash(dir)+Qtx::addSlash("share")+Qtx::addSlash("doc")+Qtx::addSlash("salome")+Qtx::addSlash("gui")+Qtx::addSlash(theComponentName));
1035
1036   QString helpFile = QFileInfo( homeDir + theFileName ).absFilePath();
1037   SUIT_ResourceMgr* resMgr = resourceMgr();
1038         QString platform;
1039 #ifdef WIN32
1040         platform = "winapplication";
1041 #else
1042         platform = "application";
1043 #endif
1044         QString anApp = resMgr->stringValue("ExternalBrowser", platform);
1045 #ifdef WIN32
1046         QString quote("\""); 
1047         anApp.prepend( quote ); 
1048         anApp.append( quote ); 
1049 #endif
1050   QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
1051
1052   if (!anApp.isEmpty()) {
1053     RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
1054     rs->start();
1055   }
1056   else {
1057     if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
1058                            tr("DEFINE_EXTERNAL_BROWSER"),
1059                            tr("BUT_OK"), tr("BUT_CANCEL"),0,1,0)==0 )
1060       onPreferences();
1061   }
1062 }
1063
1064 /*!
1065   Sets enable or disable some actions on selection changed.
1066 */
1067 void LightApp_Application::onSelectionChanged()
1068 {
1069 }
1070
1071 /*!
1072   \return window by key
1073   \param flag - key for window
1074   \param studyId - study id
1075   Flag used how identificator of window in windows list.
1076 */
1077 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
1078 {
1079   QWidget* wid = 0;
1080
1081  int sId = studyId;
1082   if ( sId < 0 )
1083   {
1084     if ( !activeStudy() )
1085       return 0;
1086     else
1087       sId = activeStudy()->id();
1088   }
1089
1090   if ( myWindows.contains( flag ) )
1091     wid = myWindows[flag]->widget( sId );
1092
1093   return wid;
1094 }
1095
1096 /*!
1097   Adds window to application.
1098   \param wid - QWidget
1099   \param flag - key for window
1100   \param studyId - study id
1101   Flag used how identificator of window in windows list.
1102 */
1103 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
1104 {
1105   if ( !wid )
1106     return;
1107
1108   int sId = studyId;
1109   if ( sId < 0 )
1110   {
1111     if ( !activeStudy() )
1112       return;
1113     else
1114       sId = activeStudy()->id();
1115   }
1116
1117   if ( !myWindows.contains( flag ) )
1118   {
1119     QMap<int, int> winMap;
1120     currentWindows( winMap );
1121
1122     LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
1123     connect( newWC, SIGNAL(  destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1124     // asv: connecting a slot for storing visibility flag of a window 
1125     connect( newWC, SIGNAL( visibilityChanged ( bool ) ), SLOT( onVisibilityChanged( bool ) ) );
1126     myWindows.insert( flag, newWC );
1127     if ( winMap.contains( flag ) )
1128       desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
1129
1130     myWindows[flag]->setResizeEnabled( true );
1131     myWindows[flag]->setCloseMode( QDockWindow::Always );
1132     myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
1133     myWindows[flag]->setFixedExtentWidth( wid->width() );
1134     myWindows[flag]->setFixedExtentHeight( wid->height() );
1135   }
1136
1137   QFont f;
1138 #ifndef DISABLE_PYCONSOLE
1139   if( wid->inherits( "PythonConsole" ) )
1140   {
1141     if( resourceMgr()->hasValue( "PyConsole", "font" ) )
1142       f = resourceMgr()->fontValue( "PyConsole", "font" );
1143     else
1144       {
1145         f = ( ( PythonConsole* )wid )->font();
1146         resourceMgr()->setValue( "PyConsole", "font", f );
1147       }
1148   }
1149   else
1150 #endif
1151     f = wid->font();
1152
1153   myWindows[flag]->insert( sId, wid );
1154   wid->setFont(f);
1155
1156   setWindowShown( flag, !myWindows[flag]->isEmpty() );
1157 }
1158
1159 /*!
1160   Removes window from application.
1161   \param flag - key for window
1162   \param studyId - study id
1163   Flag used how identificator of window in windows list.
1164 */
1165 void LightApp_Application::removeWindow( const int flag, const int studyId )
1166 {
1167   if ( !myWindows.contains( flag ) )
1168     return;
1169
1170   int sId = studyId;
1171   if ( sId < 0 )
1172   {
1173     if ( !activeStudy() )
1174       return;
1175     else
1176       sId = activeStudy()->id();
1177   }
1178
1179   bool anIsEmpty = !myWindows[flag]->isEmpty();
1180   QWidget* wid = myWindows[flag]->widget( sId );
1181   myWindows[flag]->remove( sId );
1182   delete wid;
1183
1184   //setWindowShown( flag, !myWindows[flag]->isEmpty() );
1185   setWindowShown( flag, anIsEmpty );
1186 }
1187
1188 /*!
1189   Gets window.
1190   \param flag - key for window
1191   \param studyId - study id
1192   Flag used how identificator of window in windows list.
1193 */
1194 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
1195 {
1196   QWidget* wid = window( flag, studyId );
1197   if ( !wid )
1198     addWindow( wid = createWindow( flag ), flag, studyId );
1199
1200   return wid;
1201 }
1202
1203 /*!
1204   \return is window visible
1205   \param type - flag of window
1206 */
1207 bool LightApp_Application::isWindowVisible( const int type ) const
1208 {
1209   bool res = false;
1210   if ( myWindows.contains( type ) )
1211   {
1212     SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
1213     res = desk && desk->appropriate( myWindows[type] );
1214   }
1215   return res;
1216 }
1217
1218 /*!
1219   Sets window show or hide.
1220   \param type - window identificator.
1221   \param on   - true/false (window show/hide)
1222 */
1223 void LightApp_Application::setWindowShown( const int type, const bool on )
1224 {
1225   if ( !desktop() || !myWindows.contains( type ) )
1226     return;
1227
1228   QDockWindow* dw = myWindows[type];
1229   desktop()->setAppropriate( dw, on );
1230   if( on )
1231     dw->show();
1232   else if( dw->isShown() )
1233   {
1234     dw->hide();
1235     myWindowsVisible[ type ] = true;
1236   }
1237 }
1238
1239 /*!
1240   \return Object Browser
1241 */
1242 OB_Browser* LightApp_Application::objectBrowser()
1243 {
1244   OB_Browser* ob = 0;
1245   QWidget* wid = window( WT_ObjectBrowser );
1246   if ( wid && wid->inherits( "OB_Browser" ) )
1247     ob = (OB_Browser*)wid;
1248   return ob;
1249 }
1250
1251 /*!
1252   \return Log Window
1253 */
1254 LogWindow* LightApp_Application::logWindow()
1255 {
1256   LogWindow* lw = 0;
1257   QWidget* wid = getWindow( WT_LogWindow );
1258   if ( wid->inherits( "LogWindow" ) )
1259     lw = (LogWindow*)wid;
1260   return lw;
1261 }
1262
1263 #ifndef DISABLE_PYCONSOLE
1264 /*!
1265   \return Python Console
1266 */
1267 PythonConsole* LightApp_Application::pythonConsole()
1268 {
1269   PythonConsole* console = 0;
1270   QWidget* wid = getWindow( WT_PyConsole );
1271   if ( wid->inherits( "PythonConsole" ) )
1272     console = (PythonConsole*)wid;
1273   return console;
1274 }
1275 #endif
1276
1277 /*!
1278   Updates object browser and maybe data models
1279   \param updateModels - if it is true, then data models are updated
1280 */
1281 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1282 {
1283   // update existing data models
1284   if ( updateModels ) 
1285   {
1286     const bool isAutoUpdate = objectBrowser() ? objectBrowser()->isAutoUpdate() : true;
1287     if( objectBrowser() )
1288       objectBrowser()->setAutoUpdate( false );
1289
1290     LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1291     if ( study ) {
1292       CAM_Study::ModelList dm_list;
1293       study->dataModels( dm_list );
1294       for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
1295         CAM_DataModel* camDM = it.current();
1296         if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1297           ((LightApp_DataModel*)camDM)->update();
1298       }
1299     }
1300
1301     if( objectBrowser() )
1302       objectBrowser()->setAutoUpdate( isAutoUpdate );
1303   }
1304   if ( objectBrowser() )
1305   {
1306     objectBrowser()->updateGeometry();
1307     objectBrowser()->updateTree( 0, false );
1308   }
1309 }
1310
1311 /*!
1312   \return preferences
1313 */
1314 LightApp_Preferences* LightApp_Application::preferences() const
1315 {
1316   return preferences( false );
1317 }
1318
1319 /*!
1320   \return first view manager of some type
1321   \param vmType - type of view manager
1322   \param create - is it necessary to create view manager in case, when there is no manager of such type
1323 */
1324 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1325 {
1326   SUIT_ViewManager* aVM = viewManager( vmType );
1327   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1328
1329   if ( anActiveVM && anActiveVM->getType() == vmType )
1330     aVM = anActiveVM;
1331
1332   if ( aVM && create )
1333   {
1334     if ( !aVM->getActiveView() )
1335       aVM->createView();
1336     else
1337       aVM->getActiveView()->setFocus();
1338   }
1339   else if ( create )
1340     aVM = createViewManager( vmType );
1341
1342   return aVM;
1343 }
1344
1345 /*!
1346   Creates view manager of some type
1347   \param vmType - type of view manager
1348 */
1349 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1350 {
1351   SUIT_ResourceMgr* resMgr = resourceMgr();
1352
1353   SUIT_ViewManager* viewMgr = 0;
1354 #ifndef DISABLE_GLVIEWER
1355   if( vmType == GLViewer_Viewer::Type() )
1356   {
1357     viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1358     new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1359   }
1360 #endif
1361 #ifndef DISABLE_PLOT2DVIEWER
1362   if( vmType == Plot2d_Viewer::Type() )
1363   {
1364     viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1365     Plot2d_Viewer* vm;
1366 #ifndef DISABLE_SALOMEOBJECT
1367     vm = new SPlot2d_Viewer();
1368 #else
1369     vm = new Plot2d_Viewer();
1370 #endif
1371     viewMgr->setViewModel( vm  );// custom view model, which extends SALOME_View interface 
1372     Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1373     if( wnd )
1374     {
1375       Plot2d_ViewFrame* frame = wnd->getViewFrame();
1376       frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1377     }
1378   }
1379 #endif
1380   //#ifndef DISABLE_SUPERVGRAPHVIEWER
1381   //  if( vmType == SUPERVGraph_Viewer::Type() )
1382   //  {
1383   //    viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop(), new SUPERVGraph_Viewer() );
1384   //  }
1385   //#endif
1386 #ifndef DISABLE_QXGRAPHVIEWER
1387   if( vmType == QxGraph_Viewer::Type() )
1388     {
1389       viewMgr = new QxGraph_ViewManager( activeStudy(), desktop(), new QxGraph_Viewer() );
1390     }
1391 #endif
1392 #ifndef DISABLE_OCCVIEWER
1393   if( vmType == OCCViewer_Viewer::Type() )
1394   {
1395     viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1396     OCCViewer_Viewer* vm;
1397 #ifndef DISABLE_SALOMEOBJECT
1398     vm = new SOCC_Viewer();
1399 #else
1400     vm = new OCCViewer_Viewer();
1401 #endif
1402     vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1403     vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1404     int u( 1 ), v( 1 );
1405     vm->isos( u, v );
1406     u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1407     v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1408     vm->setIsos( u, v );
1409     viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1410     new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1411   }
1412 #endif
1413 #ifndef DISABLE_VTKVIEWER
1414 #ifndef DISABLE_SALOMEOBJECT
1415   if ( vmType == SVTK_Viewer::Type() )
1416 #else
1417   if ( vmType == VTKViewer_Viewer::Type() )
1418 #endif
1419   {
1420 #ifndef DISABLE_SALOMEOBJECT
1421     viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1422     SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1423     if( vm )
1424     {
1425       vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1426       vm->setTrihedronSize( resMgr->doubleValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ),
1427                             resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) );
1428       new LightApp_VTKSelector( vm, mySelMgr );
1429     }
1430 #else
1431     viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
1432     VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
1433     if ( vm )
1434       vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1435 #endif
1436   }
1437 #endif
1438
1439   if ( !viewMgr )
1440     return 0;
1441
1442   addViewManager( viewMgr );
1443   SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1444
1445   if ( viewWin && desktop() )
1446     viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1447
1448   return viewMgr;
1449 }
1450
1451 /*!
1452   SLOT: Removes view manager from application
1453 */
1454 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1455 {
1456   removeViewManager( theVM );
1457 }
1458
1459 /*!
1460   Protected SLOT: On study created.
1461   \param theStudy - just created study
1462 */
1463 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1464 {
1465   SUIT_DataObject* aRoot = 0;
1466   if ( theStudy && theStudy->root() )
1467   {
1468     aRoot = theStudy->root();
1469     //aRoot->setName( tr( "DATA_MODELS" ) );
1470   }
1471   getWindow( WT_ObjectBrowser );
1472   if ( objectBrowser() != 0 )
1473     objectBrowser()->setRootObject( aRoot );
1474
1475   activateModule( defaultModule() );
1476
1477   if ( objectBrowser() )
1478     objectBrowser()->openLevels();
1479
1480   activateWindows();
1481 }
1482
1483 /*!
1484   Protected SLOT: On study opened.
1485   \param theStudy - just opened  study
1486 */
1487 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1488 {
1489   SUIT_DataObject* aRoot = 0;
1490   if ( theStudy && theStudy->root() )
1491   {
1492     aRoot = theStudy->root();
1493     //aRoot->dump();
1494   }
1495   getWindow( WT_ObjectBrowser );
1496   if ( objectBrowser() )
1497     objectBrowser()->setRootObject( aRoot );
1498
1499   activateModule( defaultModule() );
1500
1501   if ( objectBrowser() )
1502     objectBrowser()->openLevels();
1503
1504   activateWindows();
1505
1506   emit studyOpened();
1507 }
1508
1509 /*!Protected SLOT. On study saved.*/
1510 void LightApp_Application::onStudySaved( SUIT_Study* )
1511 {
1512   emit studySaved();
1513 }
1514
1515 /*!Protected SLOT. On study closed.*/
1516 void LightApp_Application::onStudyClosed( SUIT_Study* s )
1517 {
1518   // Bug 10396: clear selection
1519   mySelMgr->clearSelected();
1520
1521   // Bug 12944: emit signal only after clear selection
1522   emit studyClosed();
1523
1524   activateModule( "" );
1525
1526   for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1527     removeWindow( itr.key(), s->id() );
1528 }
1529
1530 /*!Protected SLOT.On desktop activated.*/
1531 void LightApp_Application::onDesktopActivated()
1532 {
1533   CAM_Application::onDesktopActivated();
1534   LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1535   if(aModule)
1536     aModule->studyActivated();
1537 }
1538
1539 /*!Gets file filter.
1540  *\retval QString "(*.bin)"
1541  */
1542 QString LightApp_Application::getFileFilter() const
1543 {
1544   //return "(*.bin)";
1545   // HDF persistence
1546   return "(*.hdf)";
1547 }
1548
1549 /*!
1550   Shows file dialog and return user selected file name
1551 */
1552 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters, 
1553                                            const QString& caption, QWidget* parent )
1554 {
1555   if ( !parent )
1556     parent = desktop();
1557   QStringList fls = QStringList::split( ";;", filters, false );
1558   return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1559 }
1560
1561 /*! Gets directory*/
1562 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1563 {
1564   if ( !parent )
1565     parent = desktop();
1566   return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1567 }
1568
1569 /*! Get open file names*/
1570 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters, 
1571                                                     const QString& caption, QWidget* parent )
1572 {
1573   if ( !parent )
1574     parent = desktop();
1575   QStringList fls = QStringList::split( ";;", filters, false );
1576   return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1577 }
1578
1579 /*!Private SLOT. Update object browser.*/
1580 void LightApp_Application::onRefresh()
1581 {
1582   updateObjectBrowser( true );
1583 }
1584
1585 /*!Private SLOT. On preferences.*/
1586 void LightApp_Application::onPreferences()
1587 {
1588   QApplication::setOverrideCursor( Qt::waitCursor );
1589
1590   LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1591
1592   QApplication::restoreOverrideCursor();
1593
1594   if ( !prefDlg )
1595     return;
1596
1597   if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) &&  resourceMgr() ) {
1598     if ( desktop() )
1599       desktop()->saveGeometry( resourceMgr(), "desktop" );
1600     resourceMgr()->save();
1601   }
1602
1603   delete prefDlg;
1604 }
1605
1606 /*!Protected SLOT. On preferences changed.*/
1607 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1608 {
1609   LightApp_Module* sMod = 0;
1610   CAM_Module* mod = module( modName );
1611   if ( mod && mod->inherits( "LightApp_Module" ) )
1612     sMod = (LightApp_Module*)mod;
1613
1614   if ( sMod )
1615     sMod->preferencesChanged( section, param );
1616   else
1617     preferencesChanged( section, param );
1618   // emit signal to allow additional preferences changing processing
1619   emit preferenceChanged( modName, section, param );
1620 }
1621
1622 /*!Private SLOT. On open document with name \a aName.*/
1623 void LightApp_Application::onMRUActivated( QString aName )
1624 {
1625   onOpenDoc( aName );
1626 }
1627
1628 /*!Remove all windows from study.*/
1629 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1630 {
1631   CAM_Application::beforeCloseDoc( s );
1632 }
1633
1634 /*!Update actions.*/
1635 void LightApp_Application::updateActions()
1636 {
1637   updateCommandsStatus();
1638 }
1639
1640 /*!
1641   Creates new study
1642 */
1643 SUIT_Study* LightApp_Application::createNewStudy()
1644 {
1645   LightApp_Application::lastStudyId++;
1646
1647   LightApp_Study* aStudy = new LightApp_Study( this );
1648
1649   // Set up processing of major study-related events
1650   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1651   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1652   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
1653   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1654
1655   return aStudy;
1656 }
1657
1658 /*!
1659   Creates window by flag.
1660   \param flag - identificator of window type
1661 */
1662 QWidget* LightApp_Application::createWindow( const int flag )
1663 {
1664   QWidget* wid = 0;
1665   if ( flag == WT_ObjectBrowser )
1666   {
1667     OB_Browser* ob = new OB_Browser( desktop() );
1668     ob->setSearch( new OB_ObjSearch( ob ) );
1669     ob->setAutoUpdate( true );
1670     //ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107
1671     ob->setCaption( tr( "OBJECT_BROWSER" ) );
1672
1673     OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1674     if( ob_list )
1675       ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1676
1677     ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1678     ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1679
1680     // Create OBSelector
1681     new LightApp_OBSelector( ob, mySelMgr );
1682
1683     wid = ob;
1684
1685     ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1686   }
1687 #ifndef DISABLE_PYCONSOLE
1688   else  if ( flag == WT_PyConsole )
1689   {
1690     PythonConsole* pyCons = new PythonConsole( desktop() );
1691     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1692     wid = pyCons;
1693     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1694   }
1695 #endif
1696   else if ( flag == WT_LogWindow )
1697   {
1698     LogWindow* logWin = new LogWindow( desktop() );
1699     logWin->setCaption( tr( "LOG_WINDOW" ) );
1700     wid = logWin;
1701     logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1702   }
1703   return wid;
1704 }
1705
1706 /*!
1707   \return default windows( Object Browser, Python Console )
1708   Adds to map \a aMap.
1709  */
1710 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1711 {  
1712   aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1713 #ifndef DISABLE_PYCONSOLE
1714   aMap.insert( WT_PyConsole, Qt::DockBottom );
1715 #endif
1716   //  aMap.insert( WT_LogWindow, Qt::DockBottom );
1717 }
1718
1719 /*!Default view managers*/
1720 void LightApp_Application::defaultViewManagers( QStringList& ) const
1721 {
1722   /*!Do nothing.*/
1723 }
1724
1725 /*!
1726   \return preferences.
1727   Create preferences, if \a crt = true.
1728 */
1729 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1730 {
1731   if ( myPrefs )
1732     return myPrefs;
1733
1734   LightApp_Application* that = (LightApp_Application*)this;
1735
1736   bool toCreate = !_prefs_ && crt;
1737   if( toCreate )
1738   {
1739     _prefs_ = new LightApp_Preferences( resourceMgr() );
1740     that->createPreferences( _prefs_ );
1741   }
1742
1743   that->myPrefs = _prefs_;
1744
1745   QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1746   for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1747   {
1748     if ( !appIt.current()->inherits( "LightApp_Application" ) )
1749       continue;
1750
1751     LightApp_Application* app = (LightApp_Application*)appIt.current();
1752
1753     QStringList modNameList;
1754     app->modules( modNameList, false );
1755     for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1756     {
1757       int id = _prefs_->addPreference( *it );
1758       _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1759     }
1760
1761     ModuleList modList;
1762     app->modules( modList );
1763     for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1764     {
1765       LightApp_Module* mod = 0;
1766       if ( itr.current()->inherits( "LightApp_Module" ) )
1767         mod = (LightApp_Module*)itr.current();
1768
1769       if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1770       {
1771         int modCat = _prefs_->addPreference( mod->moduleName() );
1772         _prefs_->setItemProperty( modCat, "info", QString::null );
1773         if( toCreate )
1774           mod->createPreferences();
1775       }
1776     }
1777   }
1778
1779   connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1780            this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1781
1782   return myPrefs;
1783 }
1784
1785 /*!
1786   Adds new module to application
1787 */
1788 void LightApp_Application::moduleAdded( CAM_Module* mod )
1789 {
1790   CAM_Application::moduleAdded( mod );
1791
1792   LightApp_Module* lightMod = 0;
1793   if ( mod && mod->inherits( "LightApp_Module" ) )
1794     lightMod = (LightApp_Module*)mod;
1795
1796   if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1797   {
1798     int modCat = myPrefs->addPreference( mod->moduleName() );
1799     myPrefs->setItemProperty( modCat, "info", QString::null );
1800     lightMod->createPreferences();
1801   }
1802 }
1803
1804 /*!
1805   Create preferences
1806 */
1807 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1808 {
1809   if ( !pref )
1810     return;
1811
1812   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1813
1814   int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1815   int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1816   pref->setItemProperty( studyGroup, "columns", 1 );
1817
1818   pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1819   pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1820   pref->addPreference( tr( "PREF_STORE_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
1821
1822   int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1823   pref->setItemProperty( extgroup, "columns", 1 );
1824         QString platform;
1825 #ifdef WIN32
1826         platform = "winapplication";
1827 #else
1828         platform = "application";
1829 #endif
1830   int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", platform );
1831   pref->setItemProperty( apppref, "existing", true );
1832   pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1833   pref->setItemProperty( apppref, "readOnly", false );
1834
1835   pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1836
1837   int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1838   pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1839   pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1840
1841   int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1842
1843   int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1844
1845   int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1846
1847   int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1848
1849   int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1850
1851   pref->setItemProperty( occGroup, "columns", 1 );
1852   pref->setItemProperty( vtkGroup, "columns", 1 );
1853   pref->setItemProperty( plot2dGroup, "columns", 1 );
1854
1855   int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1856                                    LightApp_Preferences::DblSpin, "OCCViewer", "trihedron_size" );
1857   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1858                        LightApp_Preferences::Color, "OCCViewer", "background" );
1859
1860   pref->setItemProperty( occTS, "min", 1.0E-06 );
1861   pref->setItemProperty( occTS, "max", 1000 );
1862
1863   int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1864                                   LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1865   int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1866                                   LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1867
1868   pref->setItemProperty( isoU, "min", 0 );
1869   pref->setItemProperty( isoU, "max", 100000 );
1870
1871   pref->setItemProperty( isoV, "min", 0 );
1872   pref->setItemProperty( isoV, "max", 100000 );
1873
1874   int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1875                                    LightApp_Preferences::DblSpin, "VTKViewer", "trihedron_size" );
1876   pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
1877   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1878                        LightApp_Preferences::Color, "VTKViewer", "background" );
1879
1880   pref->setItemProperty( vtkTS, "min", 1.0E-06 );
1881   pref->setItemProperty( vtkTS, "max", 150 );
1882
1883   pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1884                        LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1885
1886   int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1887                                             LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1888   QStringList aLegendPosList;
1889   aLegendPosList.append( tr("PREF_LEFT") );
1890   aLegendPosList.append( tr("PREF_RIGHT") );
1891   aLegendPosList.append( tr("PREF_TOP") );
1892   aLegendPosList.append( tr("PREF_BOTTOM") );
1893
1894   QValueList<QVariant> anIndexesList;
1895   anIndexesList.append(0);
1896   anIndexesList.append(1);
1897   anIndexesList.append(2);
1898   anIndexesList.append(3);
1899
1900   pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1901   pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1902
1903   int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1904                                        LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1905   QStringList aCurveTypesList;
1906   aCurveTypesList.append( tr("PREF_POINTS") );
1907   aCurveTypesList.append( tr("PREF_LINES") );
1908   aCurveTypesList.append( tr("PREF_SPLINE") );
1909
1910   anIndexesList.clear();
1911   anIndexesList.append(0);
1912   anIndexesList.append(1);
1913   anIndexesList.append(2);
1914   
1915   pref->setItemProperty( curveType, "strings", aCurveTypesList );
1916   pref->setItemProperty( curveType, "indexes", anIndexesList );
1917
1918   int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1919                                         LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1920
1921   pref->setItemProperty( markerSize, "min", 0 );
1922   pref->setItemProperty( markerSize, "max", 100 );
1923   
1924   QStringList aScaleModesList;
1925   aScaleModesList.append( tr("PREF_LINEAR") );
1926   aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1927   
1928   anIndexesList.clear();
1929   anIndexesList.append(0);
1930   anIndexesList.append(1);
1931
1932   int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1933                                       LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1934
1935   pref->setItemProperty( horScale, "strings", aScaleModesList );
1936   pref->setItemProperty( horScale, "indexes", anIndexesList );
1937
1938   int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1939                                       LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1940
1941   pref->setItemProperty( verScale, "strings", aScaleModesList );
1942   pref->setItemProperty( verScale, "indexes", anIndexesList );
1943
1944   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1945                        LightApp_Preferences::Color, "Plot2d", "Background" );
1946
1947   int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1948   int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1949   pref->setItemProperty( dirGroup, "columns", 1 );
1950   pref->addPreference( tr( "" ), dirGroup,
1951                        LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1952
1953   pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1954                        LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1955   pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1956                        LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1957 //  pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1958 //                     LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1959
1960   int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1961   int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1962   pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
1963                        "ObjectBrowser", "auto_size_first" );
1964   pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
1965                        "ObjectBrowser", "auto_size" );
1966 }
1967
1968 /*!
1969   Changes appearance of application according to changed preferences
1970   \param sec - section
1971   \param param - name of changed parameter
1972 */
1973 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1974 {
1975   SUIT_ResourceMgr* resMgr = resourceMgr();
1976   if ( !resMgr )
1977     return;
1978
1979 #ifndef DISABLE_OCCVIEWER
1980   if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1981   {
1982     double sz = resMgr->doubleValue( sec, param, -1 );
1983     QPtrList<SUIT_ViewManager> lst;
1984     viewManagers( OCCViewer_Viewer::Type(), lst );
1985     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1986     {
1987       SUIT_ViewModel* vm = it.current()->getViewModel();
1988       if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1989         continue;
1990
1991       OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1992       occVM->setTrihedronSize( sz );
1993       occVM->getAISContext()->UpdateCurrentViewer();
1994     }
1995   }
1996 #endif
1997
1998 #ifndef DISABLE_VTKVIEWER
1999   if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
2000   {
2001     double sz = resMgr->doubleValue( "VTKViewer", "trihedron_size", -1 );
2002     bool isRelative = resMgr->booleanValue( "VTKViewer", "relative_size", true );
2003     QPtrList<SUIT_ViewManager> lst;
2004 #ifndef DISABLE_SALOMEOBJECT
2005     viewManagers( SVTK_Viewer::Type(), lst );
2006     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
2007     {
2008       SUIT_ViewModel* vm = it.current()->getViewModel();
2009       if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2010         continue;
2011
2012       SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2013       if( vtkVM )
2014       {
2015         vtkVM->setTrihedronSize( sz, isRelative );
2016         vtkVM->Repaint();
2017       }
2018     }
2019 #endif
2020   }
2021 #endif
2022
2023 #ifndef DISABLE_OCCVIEWER
2024   if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
2025   {
2026     QPtrList<SUIT_ViewManager> lst;
2027     viewManagers( OCCViewer_Viewer::Type(), lst );
2028     int u = resMgr->integerValue( sec, "iso_number_u" );
2029     int v = resMgr->integerValue( sec, "iso_number_v" );
2030     for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
2031     {
2032       OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
2033       if( mgr && mgr->getOCCViewer() )
2034         mgr->getOCCViewer()->setIsos( u, v );
2035     }
2036   }
2037 #endif
2038
2039   if( sec=="ObjectBrowser" )
2040   {
2041     if( param=="auto_size" || param=="auto_size_first" )
2042     {
2043       OB_Browser* ob = objectBrowser();
2044       if( !ob )
2045         return;
2046
2047       bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ),
2048            autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
2049       ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
2050       ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual );
2051       if( autoSize )
2052         for( int i=1; i<ob->listView()->columns(); i++ )
2053           if( ob->listView()->columnWidth( i )>0 )
2054             ob->listView()->adjustColumn( i );
2055       updateObjectBrowser( false );
2056     }
2057   }
2058
2059   if( sec=="Study" )
2060   { 
2061     if( param=="store_positions" )
2062       updateWindows();
2063   }
2064
2065 #ifndef DISABLE_PYCONSOLE
2066   if( sec=="PyConsole" )
2067   {
2068     if( param=="font" )
2069       if( pythonConsole() )
2070         pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
2071   }
2072 #endif
2073 }
2074
2075 /*!
2076   Saves preferences
2077 */
2078 void LightApp_Application::savePreferences()
2079 {
2080   saveWindowsGeometry();
2081   
2082   if ( resourceMgr() )
2083     {
2084       if ( desktop() )
2085         desktop()->saveGeometry( resourceMgr(), "desktop" );
2086       resourceMgr()->save();
2087     }
2088 }
2089
2090 /*!
2091   Updates desktop title
2092 */
2093 void LightApp_Application::updateDesktopTitle() {
2094   QString aTitle = applicationName();
2095   QString aVer = applicationVersion();
2096   if ( !aVer.isEmpty() )
2097     aTitle += QString( " " ) + aVer;
2098
2099   if ( activeStudy() ) {
2100     QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
2101     aTitle += QString( " - [%1]" ).arg( sName );
2102   }
2103
2104   desktop()->setCaption( aTitle );
2105 }
2106
2107 /*!
2108   \brief Get module activation actions
2109   \return map <action_id><action_name> where
2110   - action_id is unique non-zero action identifier
2111   - action_name is action title
2112   \sa moduleActionSelected()
2113 */
2114 QMap<int, QString> LightApp_Application::activateModuleActions() const
2115 {
2116   QMap<int, QString> opmap;
2117   opmap.insert( NewStudyId,  tr( "ACTIVATE_MODULE_OP_NEW" ) );
2118   opmap.insert( OpenStudyId, tr( "ACTIVATE_MODULE_OP_OPEN" ) );
2119   return opmap;
2120 }
2121
2122 /*!
2123   \brief Process module activation action.
2124   \param id action identifier
2125   \sa activateModuleActions()
2126 */
2127 void LightApp_Application::moduleActionSelected( const int id )
2128 {
2129   switch ( id ) {
2130   case NewStudyId:
2131     onNewDoc();
2132     break;
2133   case OpenStudyId:
2134     onOpenDoc();
2135     break;
2136   default:
2137     break;
2138   }
2139 }
2140 /*!
2141   Updates windows after close document
2142 */
2143 void LightApp_Application::afterCloseDoc()
2144 {
2145   updateWindows();
2146
2147   CAM_Application::afterCloseDoc();
2148 }
2149
2150 /*!
2151   Updates actions of active module
2152 */
2153 void LightApp_Application::updateModuleActions()
2154 {
2155   QString modName;
2156   if ( activeModule() )
2157     modName = activeModule()->moduleName();
2158
2159   if ( myActions.contains( modName ) )
2160     myActions[modName]->setOn( true );
2161 }
2162
2163 /*!
2164   Gets current windows.
2165   \param winMap - output current windows map.
2166 */
2167 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
2168 {
2169   winMap.clear();
2170   if ( !activeStudy() )
2171     return;
2172
2173   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2174     ((LightApp_Module*)activeModule())->windows( winMap );
2175   else
2176     defaultWindows( winMap );
2177 }
2178
2179 /*!
2180   Gets current view managers.
2181   \param lst - output current view managers list.
2182 */
2183 void LightApp_Application::currentViewManagers( QStringList& lst ) const
2184 {
2185   lst.clear();
2186   if ( !activeStudy() )
2187     return;
2188
2189   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2190     ((LightApp_Module*)activeModule())->viewManagers( lst );
2191   else
2192     defaultViewManagers( lst );
2193 }
2194
2195 /*!
2196   Updates windows
2197 */
2198 void LightApp_Application::updateWindows()
2199 {
2200   QMap<int, int> winMap;
2201   currentWindows( winMap );
2202
2203   if ( activeStudy() ) {
2204     for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it ) {
2205       getWindow( it.key() ); 
2206       
2207       Dock dock; int index, extraOffset; bool nl;
2208       if ( desktop()->getLocation( myWindows[it.key()], dock, index, nl, extraOffset )
2209            &&
2210            dock != (Dock)it.data() )
2211         desktop()->moveDockWindow( myWindows[it.key()], (Dock)it.data() );
2212     }
2213
2214     loadWindowsGeometry();
2215   }
2216
2217   // setWindowShown should be done even if no study is active (open). in this case all open windows
2218   // will be hidden, which is neccessary in this case.
2219   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) {
2220     
2221     if ( myWindowsVisible.contains( itr.key() ) && 
2222          !myWindowsVisible[ itr.key() ] )
2223       continue;
2224
2225     setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
2226   }
2227 }
2228
2229 /*!
2230   Updates view managers
2231 */
2232 void LightApp_Application::updateViewManagers()
2233 {
2234   QStringList lst;
2235   currentViewManagers( lst );
2236
2237   for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
2238     getViewManager( *it, true );
2239 }
2240
2241 /*!
2242   Loads windows geometry
2243 */
2244 void LightApp_Application::loadWindowsGeometry()
2245 {
2246   bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2247   if( !store )
2248     return;
2249
2250   QtxDockAction* dockMgr = 0;
2251
2252   QAction* a = action( ViewWindowsId );
2253   if ( a && a->inherits( "QtxDockAction" ) )
2254     dockMgr = (QtxDockAction*)a;
2255
2256   if ( !dockMgr )
2257     return;
2258
2259   QString modName;
2260   if ( activeModule() )
2261     modName = activeModule()->name("");
2262
2263   QString section = QString( "windows_geometry" );
2264   if ( !modName.isEmpty() )
2265     section += QString( "." ) + modName;
2266
2267   dockMgr->loadGeometry( resourceMgr(), section, false );
2268   dockMgr->restoreGeometry();
2269 }
2270
2271 /*!
2272   Saves windows geometry
2273 */
2274 void LightApp_Application::saveWindowsGeometry()
2275 {
2276   bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2277   if( !store )
2278     return;
2279
2280   QtxDockAction* dockMgr = 0;
2281
2282   QAction* a = action( ViewWindowsId );
2283   if ( a && a->inherits( "QtxDockAction" ) )
2284     dockMgr = (QtxDockAction*)a;
2285
2286   if ( !dockMgr )
2287     return;
2288
2289   QString modName;
2290   if ( activeModule() )
2291     modName = activeModule()->name("");
2292
2293   QString section = QString( "windows_geometry" );
2294   if ( !modName.isEmpty() )
2295     section += QString( "." ) + modName;
2296
2297   dockMgr->storeGeometry();
2298   dockMgr->saveGeometry( resourceMgr(), section, false );
2299 }
2300
2301 /*!
2302   Activates windows
2303 */
2304 void LightApp_Application::activateWindows()
2305 {
2306   if ( activeStudy() )
2307   {
2308     for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2309       itr.data()->activate( activeStudy()->id() );
2310   }
2311 }
2312
2313 /*!
2314   Adds icon names for modules
2315 */
2316 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
2317 {
2318   iconMap.clear();
2319
2320   SUIT_ResourceMgr* resMgr = resourceMgr();
2321   if ( !resMgr )
2322     return;
2323
2324   QStringList modList;
2325   modules( modList, false );
2326
2327   for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
2328   {
2329     QString modName = *it;
2330     QString modIntr = moduleName( modName );
2331     QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
2332
2333     if ( modIcon.isEmpty() )
2334       continue;
2335
2336     if ( SUIT_Tools::extension( modIcon ).isEmpty() )
2337       modIcon += QString( ".png" );
2338
2339     iconMap.insert( modName, modIcon );
2340   }
2341 }
2342
2343 /*!
2344   Inserts items in popup, which necessary for current application
2345 */
2346 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
2347 {
2348   CAM_Application::contextMenuPopup( type, thePopup, title );
2349
2350   OB_Browser* ob = objectBrowser();
2351   if ( !ob || type != ob->popupClientType() )
2352     return;
2353
2354   thePopup->insertSeparator();
2355   thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
2356   thePopup->insertItem( tr( "MEN_FIND" ), this, SLOT( onFind() ) );
2357 }
2358
2359 /*!
2360   Create empty study
2361 */
2362 void LightApp_Application::createEmptyStudy()
2363 {
2364   CAM_Application::createEmptyStudy();
2365   if ( objectBrowser() )
2366     objectBrowser()->updateTree();
2367 }
2368
2369 /*!
2370   Activates module
2371   \param mod - module to be activated
2372 */
2373 bool LightApp_Application::activateModule( CAM_Module* mod )
2374 {
2375   bool res = CAM_Application::activateModule( mod );
2376   if ( objectBrowser() )
2377     objectBrowser()->updateTree();
2378   return res;
2379 }
2380
2381 /*!
2382   \return keyborad accelerators manager object
2383 */
2384 SUIT_Accel* LightApp_Application::accel() const
2385 {
2386   return myAccel;
2387 }
2388
2389 /*!
2390   Removes dead widget container from map
2391 */
2392 void LightApp_Application::onWCDestroyed( QObject* ob )
2393 {
2394   // remove destroyed widget container from windows map
2395   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2396   {
2397     if ( itr.data() != ob )
2398       continue;
2399
2400     int key = itr.key();
2401     myWindows.remove( key );
2402     break;
2403   }
2404 }
2405
2406 /*!
2407   Connects just added view manager
2408 */
2409 void LightApp_Application::addViewManager( SUIT_ViewManager* vm )
2410 {
2411   connect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2412            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2413   STD_Application::addViewManager( vm );
2414 }
2415
2416 /*!
2417   Remove view manager from memory
2418 */
2419 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
2420 {
2421   disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2422            this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2423   STD_Application::removeViewManager( vm );
2424   delete vm;
2425 }
2426
2427 /*!
2428   Renames active window of desktop
2429 */
2430 void LightApp_Application::onRenameWindow()
2431 {
2432   if( !desktop() )
2433     return;
2434
2435   QWidget* w = desktop()->activeWindow();
2436   if( !w )
2437     return;
2438
2439   bool ok;
2440   QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
2441   if( ok && !name.isEmpty() )
2442     w->setCaption( name );
2443 }
2444
2445 /*!
2446   \return if the library of module exists
2447   \param moduleTitle - title of module
2448 */
2449 bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
2450 {
2451   if( moduleTitle.isEmpty() )
2452     return false;
2453
2454   QString lib = moduleLibrary( moduleTitle );
2455   
2456   //abd: changed libSalomePyQtGUI to SalomePyQtGUI for WIN32
2457   bool isPythonModule = lib.contains("SalomePyQtGUI");
2458
2459   QStringList paths;
2460 #ifdef WIN32
2461   paths = QStringList::split( ";", ::getenv( "PATH" ) );
2462 #else
2463   paths = QStringList::split( ":", ::getenv( "LD_LIBRARY_PATH" ) );
2464 #endif
2465
2466   bool isLibFound = false;
2467   QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2468   for( ; anIt!=aLast; anIt++ )
2469   {
2470     QFileInfo inf( Qtx::addSlash( *anIt ) + lib );
2471     
2472     if( inf.exists() )
2473       {
2474         isLibFound = true;
2475         break;
2476       }
2477   }
2478   
2479   if ( !isLibFound )
2480     {
2481       printf( "****************************************************************\n" );
2482       printf( "*    Warning: library %s cannot be found\n", lib.latin1() );
2483       printf( "*    Module %s will not be available in GUI mode\n", moduleTitle.latin1() );
2484       printf( "****************************************************************\n" );
2485     }
2486   else if ( !isPythonModule )
2487     return true;
2488
2489   if ( isPythonModule )
2490     {
2491       QString pylib = moduleName( moduleTitle ) + QString(".py");
2492       QString pylibgui = moduleName( moduleTitle ) + QString("GUI.py");
2493
2494       // Check the python library
2495 #ifdef WIN32
2496       paths = QStringList::split( ";", ::getenv( "PATH" ) );
2497 #else
2498       paths = QStringList::split( ":", ::getenv( "PYTHONPATH" ) );
2499 #endif
2500       bool isPyLib = false, isPyGuiLib = false;
2501       QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2502       for( ; anIt!=aLast; anIt++ )
2503         {
2504           QFileInfo inf( Qtx::addSlash( *anIt ) + pylib );
2505           QFileInfo infgui( Qtx::addSlash( *anIt ) + pylibgui );
2506     
2507           if( !isPyLib && inf.exists() )
2508             isPyLib = true;
2509           
2510           if( !isPyGuiLib && infgui.exists() )
2511             isPyGuiLib = true;
2512           
2513           if ( isPyLib && isPyGuiLib && isLibFound)
2514             return true;
2515         }
2516       
2517       printf( "****************************************************************\n" );
2518       printf( "*    Warning: python library for %s cannot be found:\n", moduleTitle.latin1() );
2519       if (!isPyLib)
2520         printf( "*    No module named %s\n", moduleName( moduleTitle ).latin1() );
2521       if (!isPyGuiLib)
2522         printf( "*    No module named %s\n", (moduleName( moduleTitle ) + QString("GUI")).latin1() );
2523       printf( "****************************************************************\n" );
2524       return true;
2525   }
2526   return false;
2527 }
2528
2529 /*!
2530   \return default name for an active study
2531 */
2532 void LightApp_Application::setDefaultStudyName( const QString& theName )
2533 {
2534   QStringList anInfoList;
2535   modules( anInfoList, false );
2536
2537   LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
2538   if( anInfoList.count() == 1 && // to avoid a conflict between different modules
2539       !aStudy->isSaved() )
2540   {
2541     aStudy->setStudyName( theName );
2542     updateDesktopTitle();
2543   }
2544 }
2545
2546 /*! slot, called on show/hide of a dock window */
2547 void LightApp_Application::onVisibilityChanged( bool visible )
2548 {
2549   const QObject* win = sender();
2550  
2551   for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2552     if ( itr.data() == win ) 
2553     {
2554       myWindowsVisible[ itr.key() ] = visible;
2555       return;
2556     }
2557 }
2558
2559 /*!
2560   Custom event handler
2561 */
2562 bool LightApp_Application::event( QEvent* e )
2563 {
2564   if( e && e->type()==2000 )
2565   {
2566     QCustomEvent* ce = ( QCustomEvent* )e;
2567     QString* d = ( QString* )ce->data();
2568     if( SUIT_MessageBox::warn2(0, tr("WRN_WARNING"),
2569                            d ? *d : "",
2570                            tr("BUT_OK"), tr("BUT_CANCEL"), 0, 1, 0 )==0 )
2571        onPreferences();
2572     if( d )
2573       delete d;
2574     return true;
2575   }
2576   return CAM_Application::event( e );
2577 }
2578
2579 /*! Check data object */
2580 bool LightApp_Application::checkDataObject(LightApp_DataObject* theObj)
2581 {
2582   if (theObj)
2583     {
2584       bool isSuitable = !theObj->entry().isEmpty() && 
2585                         !theObj->componentDataType().isEmpty() && 
2586                         !theObj->name().isEmpty();
2587       return isSuitable;
2588     }
2589
2590   return false;
2591 }
2592
2593 void LightApp_Application::onFind()
2594 {
2595   objectBrowser()->enableSearch( true );
2596 }