1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: LightApp_Application.cxx
23 // Created: 6/20/2005 18:39:45 PM
24 // Author: Natalia Donis
26 #ifndef DISABLE_PYCONSOLE
27 #include <PyConsole_Interp.h> // WARNING! This include must be the first!
28 #include <PyConsole_Console.h>
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"
47 #include <SALOME_Event.h>
49 #include <Style_Salome.h>
50 #include <Style_PrefDlg.h>
52 #include <CAM_Module.h>
53 #include <CAM_DataModel.h>
54 #include <CAM_Study.h>
55 #include <STD_TabDesktop.h>
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>
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>
77 #include <LogWindow.h>
79 #ifndef DISABLE_GLVIEWER
80 #include <GLViewer_Viewer.h>
81 #include <GLViewer_ViewManager.h>
82 #include "LightApp_GLSelector.h"
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>
92 #include <Plot2d_ViewModel.h>
96 #include <QxScene_ViewManager.h>
97 #include <QxScene_ViewModel.h>
98 #include <QxScene_ViewWindow.h>
100 #ifndef DISABLE_OCCVIEWER
101 #include <OCCViewer_ViewManager.h>
102 #ifndef DISABLE_SALOMEOBJECT
103 #include <SOCC_ViewModel.h>
105 #include <OCCViewer_ViewModel.h>
107 #include "LightApp_OCCSelector.h"
110 #ifndef DISABLE_VTKVIEWER
111 #ifndef DISABLE_SALOMEOBJECT
112 #include <SVTK_ViewModel.h>
113 #include <SVTK_ViewManager.h>
114 #include "LightApp_VTKSelector.h"
116 #include <VTKViewer_ViewModel.h>
117 #include <VTKViewer_ViewManager.h>
119 #include <VTKViewer_ViewModel.h>
122 //#ifndef DISABLE_SUPERVGRAPHVIEWER
123 // #include <SUPERVGraph_ViewModel.h>
124 // #include <SUPERVGraph_ViewFrame.h>
125 // #include <SUPERVGraph_ViewManager.h>
128 #ifndef DISABLE_QXGRAPHVIEWER
129 #include <QxGraph_ViewModel.h>
130 #include <QxGraph_ViewWindow.h>
131 #include <QxGraph_ViewManager.h>
138 #include <QStringList>
140 #include <QApplication>
142 #include <QStatusBar>
144 #include <QObjectList>
146 #include <QInputDialog>
147 #include <QFontDatabase>
149 #include <QByteArray>
153 #include <utilities.h>
155 #define FIRST_HELP_ID 1000000
157 #ifndef DISABLE_SALOMEOBJECT
158 #include <SALOME_InteractiveObject.hxx>
159 #include <SALOME_ListIO.hxx>
162 #define ToolBarMarker 0
163 #define DockWidgetMarker 1
165 static const char* imageEmptyIcon[] = {
168 "....................",
169 "....................",
170 "....................",
171 "....................",
172 "....................",
173 "....................",
174 "....................",
175 "....................",
176 "....................",
177 "....................",
178 "....................",
179 "....................",
180 "....................",
181 "....................",
182 "....................",
183 "....................",
184 "....................",
185 "....................",
186 "....................",
187 "...................."};
189 int LightApp_Application::lastStudyId = 0;
192 \return last global id of study
194 int LightApp_Application::studyId()
196 return LightApp_Application::lastStudyId;
199 /*!Create new instance of LightApp_Application.*/
200 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
202 return new LightApp_Application();
205 /*! \var global preferences of LightApp */
206 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
209 \class LightApp_Application
210 Application containing LightApp module
214 LightApp_Application::LightApp_Application()
215 : CAM_Application( false ),
218 STD_TabDesktop* desk = new STD_TabDesktop();
222 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
223 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
225 desktop()->setWindowIcon( aLogo );
226 desktop()->setDockableMenuBar( false );
227 desktop()->setDockableStatusBar( false );
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 ) );
236 mySelMgr = new LightApp_SelectionMgr( this );
238 myAccel = SUIT_Accel::getAccel();
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() );
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() );
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() );
276 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
278 // Set existing font for the python console in resources
279 if( !aResMgr->hasValue( "PyConsole", "font" ) )
282 QFont f = aResMgr->fontValue( "PyConsole", "font" );
284 QStringList famdb = fdb.families();
286 if ( famdb.contains(f.family()) || !aResMgr->hasValue( "PyConsole", "additional_families" ) )
289 QStringList anAddFamilies = aResMgr->stringValue( "PyConsole", "additional_families" ).split( ";", QString::SkipEmptyParts );
291 for ( QStringList::Iterator it = anAddFamilies.begin(); it != anAddFamilies.end(); ++it )
294 if ( famdb.contains(aFamily) )
296 f.setFamily( aFamily );
297 aResMgr->setValue( "PyConsole", "font", f );
304 *\li Save window geometry.
305 *\li Save desktop geometry.
306 *\li Save resource maneger.
307 *\li Delete selection manager.
309 LightApp_Application::~LightApp_Application()
314 /*!Start application.*/
315 void LightApp_Application::start()
317 CAM_Application::start();
320 updateViewManagers();
323 desktop()->statusBar()->showMessage( "" );
325 LightApp_EventFilter::Init();
328 /*!Gets application name.*/
329 QString LightApp_Application::applicationName() const
331 return tr( "APP_NAME" );
334 /*!Gets application version.*/
335 QString LightApp_Application::applicationVersion() const
337 static QString _app_version;
339 if ( _app_version.isEmpty() )
341 QString resVersion = tr( "APP_VERSION" );
342 if ( resVersion != "APP_VERSION" )
344 _app_version = resVersion;
348 QString path( ::getenv( "GUI_ROOT_DIR" ) );
349 if ( !path.isEmpty() )
350 path += QDir::separator();
351 path += QString( "bin/salome/VERSION" );
354 if ( vf.open( QIODevice::ReadOnly ) )
356 QString line( vf.readLine( 1024 ) );
359 if ( !line.isEmpty() )
361 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
362 line.remove( line.length() - 1, 1 );
364 int idx = line.lastIndexOf( ":" );
366 _app_version = line.mid( idx + 1 ).trimmed();
374 /*!Load module by \a name.*/
375 CAM_Module* LightApp_Application::loadModule( const QString& name, const bool showMsg )
377 CAM_Module* mod = CAM_Application::loadModule( name, showMsg );
380 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
381 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
382 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
387 /*!Activate module by \a modName*/
388 bool LightApp_Application::activateModule( const QString& modName )
391 CAM_Module* prevMod = activeModule();
394 actName = prevMod->moduleName();
396 if ( actName == modName )
399 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
401 saveDockWindowsState();
403 bool status = CAM_Application::activateModule( modName );
405 updateModuleActions();
413 updateViewManagers();
418 /*!Gets selection manager.*/
419 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
424 /*!Creat action "New window" for certain type of viewer:*/
425 void LightApp_Application::createActionForViewer( const int id,
427 const QString& suffix,
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 );
438 void LightApp_Application::createActions()
440 STD_Application::createActions();
442 SUIT_Desktop* desk = desktop();
443 SUIT_ResourceMgr* resMgr = resourceMgr();
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() ) );
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 );
455 QStringList aModuleList;
456 modules( aModuleList, false );
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";
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 );
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 );
494 // help for other existing modules
495 QStringList::Iterator it;
496 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
498 if ( (*it).isEmpty() )
501 QString modName = moduleName( *it );
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() ) {
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 );
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 );
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 );
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 );
537 modules( modList, false );
539 if ( modList.count() > 1 )
541 LightApp_ModuleAction* moduleAction =
542 new LightApp_ModuleAction( tr( "APP_NAME" ), defIcon, desk );
544 QMap<QString, QString> iconMap;
545 moduleIconNames( iconMap );
547 const int iconSize = 20;
549 for ( it = modList.begin(); it != modList.end(); ++it )
551 if ( !isLibExists( *it ) )
555 if ( iconMap.contains( *it ) )
556 iconName = iconMap[*it];
558 QString modName = moduleName( *it );
560 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
564 INFOS ( "****************************************************************" << std::endl
565 << "* Icon for " << (*it).toLatin1().constData() << " not found. Using the default one." << std::endl
566 << "****************************************************************" << std::endl );
569 icon = Qtx::scaleIcon( icon, iconSize );
571 moduleAction->insertModule( *it, icon );
575 connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ), this, SLOT( onModuleActivation( const QString& ) ) );
576 registerAction( ModulesListId, moduleAction );
580 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 );
581 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
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() ) );
590 createMenu( CloseId, windowMenu, 0, -1 );
591 createMenu( CloseAllId, windowMenu, 0, -1 );
592 createMenu( GroupAllId, windowMenu, 0, -1 );
593 createMenu( separator(), windowMenu, -1, 0 );
595 #ifndef DISABLE_GLVIEWER
596 createActionForViewer( NewGLViewId, newWinMenu, QString::number( 0 ), Qt::ALT+Qt::Key_G );
598 #ifndef DISABLE_PLOT2DVIEWER
599 createActionForViewer( NewPlot2dId, newWinMenu, QString::number( 1 ), Qt::ALT+Qt::Key_P );
601 #ifndef DISABLE_OCCVIEWER
602 createActionForViewer( NewOCCViewId, newWinMenu, QString::number( 2 ), Qt::ALT+Qt::Key_O );
604 #ifndef DISABLE_VTKVIEWER
605 createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), Qt::ALT+Qt::Key_K );
607 #ifndef DISABLE_QXGRAPHVIEWER
608 createActionForViewer( NewQxGraphViewId, newWinMenu, QString::number( 4 ), Qt::ALT+Qt::Key_C );
611 createActionForViewer( NewQxSceneViewId, newWinMenu, QString::number( 5 ), Qt::ALT+Qt::Key_S );
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 );
617 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
618 createMenu( PreferencesId, fileMenu, 50, -1 );
619 createMenu( separator(), fileMenu, -1, 50, -1 );
621 createMenu( separator(), fileMenu, -1, 100, -1 );
622 createMenu( MRUId, fileMenu, 100, -1 );
623 createMenu( separator(), fileMenu, -1, 100, -1 );
625 createAction( StyleId, tr( "TOT_THEME" ), QIcon(), tr( "MEN_DESK_THEME" ), tr( "PRP_THEME" ),
626 0, desk, false, this, SLOT( onStylePreferences() ) );
628 int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1 );
629 createMenu( separator(), viewMenu, -1, 20, -1 );
630 createMenu( StyleId, viewMenu, 20, -1 );
632 int modTBar = createTool( tr( "INF_TOOLBAR_MODULES" ) );
633 createTool( ModulesListId, modTBar );
636 /*!On module activation action.*/
637 void LightApp_Application::onModuleActivation( const QString& modName )
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 );
644 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
646 bool cancelled = false;
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() );
654 int res = aDlg.exec();
656 // some operation is selected
657 moduleActionSelected( res );
661 putInfo( tr("INF_CANCELLED") );
663 LightApp_ModuleAction* moduleAction =
664 qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
666 moduleAction->setActiveModule( QString() );
672 activateModule( modName );
675 /*!Default module activation.*/
676 QString LightApp_Application::defaultModule() const
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() : "" );
685 /*!On new window slot.*/
686 void LightApp_Application::onNewWindow()
688 const QObject* obj = sender();
689 if ( !obj || !obj->inherits( "QAction" ) )
693 int id = actionId( (QAction*)obj );
696 #ifndef DISABLE_GLVIEWER
698 type = GLViewer_Viewer::Type();
701 #ifndef DISABLE_PLOT2DVIEWER
703 type = Plot2d_Viewer::Type();
706 #ifndef DISABLE_OCCVIEWER
708 type = OCCViewer_Viewer::Type();
711 #ifndef DISABLE_VTKVIEWER
713 type = VTKViewer_Viewer::Type();
716 #ifndef DISABLE_QXGRAPHVIEWER
717 case NewQxGraphViewId:
718 type = QxGraph_Viewer::Type();
721 case NewQxSceneViewId:
722 type = QxScene_Viewer::Type();
726 if ( !type.isEmpty() )
727 createViewManager( type );
731 SLOT: Creates new document
733 void LightApp_Application::onNewDoc()
735 saveDockWindowsState();
737 CAM_Application::onNewDoc();
741 SLOT: Opens new document
743 void LightApp_Application::onOpenDoc()
745 SUIT_Study* study = activeStudy();
746 saveDockWindowsState();
748 CAM_Application::onOpenDoc();
750 if ( !study ) // new study will be create in THIS application
753 updateViewManagers();
758 SLOT: Opens new document.
759 \param aName - name of file
761 bool LightApp_Application::onOpenDoc( const QString& aName )
763 // We should take mru action first because this application instance can be deleted later.
764 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
766 bool res = CAM_Application::onOpenDoc( aName );
771 mru->insert( aName );
773 mru->remove( aName );
779 SLOT: Displays "About" message box
781 void LightApp_Application::onHelpAbout()
783 LightApp_AboutDlg dlg( applicationName(), applicationVersion(), desktop() );
788 Private SLOT: Called on selection is changed
789 Dispatchs active module that selection is changed
791 void LightApp_Application::onSelection()
793 onSelectionChanged();
795 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
796 ((LightApp_Module*)activeModule())->selectionChanged();
801 \param study - SUIT_Study.
803 void LightApp_Application::setActiveStudy( SUIT_Study* study )
805 CAM_Application::setActiveStudy( study );
809 Enables/Disables menu items and toolbar buttons. Rebuild menu
811 void LightApp_Application::updateCommandsStatus()
813 CAM_Application::updateCommandsStatus();
816 #ifndef DISABLE_GLVIEWER
817 a = action( NewGLViewId );
819 a->setEnabled( activeStudy() );
822 #ifndef DISABLE_PLOT2DVIEWER
823 a = action( NewPlot2dId );
825 a->setEnabled( activeStudy() );
828 #ifndef DISABLE_OCCVIEWER
829 a = action( NewOCCViewId );
831 a->setEnabled( activeStudy() );
834 #ifndef DISABLE_VTKVIEWER
835 a = action( NewVTKViewId );
837 a->setEnabled( activeStudy() );
840 #ifndef DISABLE_QXGRAPHVIEWER
841 a = action( NewQxGraphViewId );
843 a->setEnabled( activeStudy() );
845 a = action( NewQxSceneViewId );
847 a->setEnabled( activeStudy() );
852 Runs system command in separate thread
854 class RunBrowser: public QThread
857 RunBrowser( LightApp_Application* app,
858 const QString& theApp,
859 const QString& theParams,
860 const QString& theHelpFile,
861 const QString& theContext = QString() )
863 myParams( theParams ),
865 myHelpFile( "file://" + theHelpFile ),
867 myHelpFile( "file:" + theHelpFile ),
869 myContext( theContext ),
877 if ( !myApp.isEmpty()) {
878 QString aCommand = QString( "%1 %2 %3" ).arg( myApp, myParams, myHelpFile );
879 if ( !myContext.isEmpty() )
880 aCommand += "#" + myContext;
882 QProcess* proc = new QProcess();
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 );
900 LightApp_Application* myLApp;
904 SLOT: Displays help contents for choosen module
906 void LightApp_Application::onHelpContentsModule()
908 const QAction* obj = (QAction*) sender();
910 QString aComponentName = obj->objectName();
911 QString aFileName = "index.html";
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) );
918 QString helpFile = QFileInfo( homeDir + aFileName ).absoluteFilePath();
919 SUIT_ResourceMgr* resMgr = resourceMgr();
922 platform = "winapplication";
924 platform = "application";
926 QString anApp = resMgr->stringValue("ExternalBrowser", platform);
929 anApp.prepend( quote );
930 anApp.append( quote );
932 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
934 if ( !anApp.isEmpty() )
936 RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
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 )
945 showPreferences( tr( "PREF_APP" ) );
950 SLOT: Displays help contents for choosen dialog
952 void LightApp_Application::onHelpContextModule( const QString& theComponentName,
953 const QString& theFileName,
954 const QString& theContext )
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 ) );
968 QString helpFile = QFileInfo( homeDir + theFileName ).absoluteFilePath();
969 SUIT_ResourceMgr* resMgr = resourceMgr();
972 platform = "winapplication";
974 platform = "application";
976 QString anApp = resMgr->stringValue("ExternalBrowser", platform);
979 anApp.prepend( quote );
980 anApp.append( quote );
982 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
984 if ( !anApp.isEmpty() )
986 RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile, theContext );
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" ) );
999 Sets enable or disable some actions on selection changed.
1001 void LightApp_Application::onSelectionChanged()
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.
1013 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
1021 if ( !activeStudy() )
1024 sId = activeStudy()->id();
1027 if ( !myWindows.contains( flag ) )
1029 QMap<int, int> winMap;
1030 currentWindows( winMap );
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] );
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() );
1051 #ifndef DISABLE_PYCONSOLE
1052 if( wid->inherits( "PyConsole_Console" ) )
1054 if( resourceMgr()->hasValue( "PyConsole", "font" ) )
1055 f = resourceMgr()->fontValue( "PyConsole", "font" );
1058 f = ( ( PyConsole_Console* )wid )->font();
1059 resourceMgr()->setValue( "PyConsole", "font", f );
1066 myWindows[flag]->insert( sId, wid );
1069 setWindowShown( flag, !myWindows[flag]->isEmpty() );
1073 QWidget* LightApp_Application::dockWindow( const int id ) const
1076 if ( myWin.contains( id ) )
1081 QDockWidget* LightApp_Application::windowDock( QWidget* wid ) const
1086 QDockWidget* dock = 0;
1087 QWidget* w = wid->parentWidget();
1088 while ( w && !dock )
1090 dock = ::qobject_cast<QDockWidget*>( w );
1091 w = w->parentWidget();
1096 void LightApp_Application::insertDockWindow( const int id, QWidget* wid )
1101 if ( wid != dockWindow( id ) )
1102 removeDockWindow( id );
1104 myWin.insert( id, wid );
1106 QtxDockWidget* dock = new QtxDockWidget( true, desktop() );
1107 connect( dock, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1109 dock->setFeatures( QDockWidget::AllDockWidgetFeatures );
1110 dock->setObjectName( QString( "window_%1" ).arg( id ) );
1111 dock->setWidget( wid );
1115 void LightApp_Application::removeDockWindow( const int id )
1117 QWidget* wid = dockWindow( id );
1123 QDockWidget* dock = windowDock( wid );
1127 dock->setWidget( 0 );
1128 wid->setParent( 0 );
1129 wid->setVisible( false );
1133 void LightApp_Application::placeDockWindow( const int id, Qt::DockWidgetArea place )
1135 QDockWidget* dock = windowDock( dockWindow( id ) );
1136 if ( dock && desktop() )
1137 desktop()->addDockWidget( place, dock );
1142 \param flag - key for window
1143 \param studyId - study id
1144 Flag used how identificator of window in windows list.
1146 QWidget* LightApp_Application::getWindow( const int flag, const int )
1148 QWidget* wid = dockWindow( flag );
1150 insertDockWindow( flag, wid = createWindow( flag ) );
1152 QMap<int, int> winMap;
1153 currentWindows( winMap );
1154 if ( winMap.contains( flag ) )
1155 placeDockWindow( flag, (Qt::DockWidgetArea)winMap[flag] );
1161 \return Object Browser
1163 SUIT_DataBrowser* LightApp_Application::objectBrowser()
1165 return qobject_cast<SUIT_DataBrowser*>( dockWindow( WT_ObjectBrowser ) );
1171 LogWindow* LightApp_Application::logWindow()
1173 return qobject_cast<LogWindow*>( dockWindow( WT_LogWindow ) );
1176 #ifndef DISABLE_PYCONSOLE
1178 \return Python Console
1180 PyConsole_Console* LightApp_Application::pythonConsole()
1182 return qobject_cast<PyConsole_Console*>( dockWindow( WT_PyConsole ) );
1187 Updates object browser and maybe data models
1188 \param updateModels - if it is true, then data models are updated
1190 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1192 // update existing data models
1195 const bool isAutoUpdate = objectBrowser() ? objectBrowser()->autoUpdate() : true;
1196 if ( objectBrowser() )
1197 objectBrowser()->setAutoUpdate( false );
1199 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
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();
1211 if( objectBrowser() )
1212 objectBrowser()->setAutoUpdate( isAutoUpdate );
1215 if ( objectBrowser() ) {
1216 objectBrowser()->updateGeometry();
1217 objectBrowser()->updateTree( 0, false );
1224 LightApp_Preferences* LightApp_Application::preferences() const
1226 return preferences( false );
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
1234 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1236 SUIT_ViewManager* aVM = viewManager( vmType );
1237 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1239 if ( anActiveVM && anActiveVM->getType() == vmType )
1242 if ( aVM && create )
1244 if ( !aVM->getActiveView() )
1247 aVM->getActiveView()->setFocus();
1250 aVM = createViewManager( vmType );
1256 Creates view manager of some type
1257 \param vmType - type of view manager
1259 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1261 SUIT_ResourceMgr* resMgr = resourceMgr();
1263 SUIT_ViewManager* viewMgr = 0;
1264 #ifndef DISABLE_GLVIEWER
1265 if( vmType == GLViewer_Viewer::Type() )
1267 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1268 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1271 #ifndef DISABLE_PLOT2DVIEWER
1272 if( vmType == Plot2d_Viewer::Type() )
1274 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1276 #ifndef DISABLE_SALOMEOBJECT
1277 SPlot2d_Viewer* v = new SPlot2d_Viewer();
1279 new LightApp_Plot2dSelector( v, mySelMgr );
1281 vm = new Plot2d_Viewer();
1283 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1284 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1287 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1288 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1292 if( vmType == QxScene_Viewer::Type() )
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() );
1299 //#ifndef DISABLE_SUPERVGRAPHVIEWER
1300 // if( vmType == SUPERVGraph_Viewer::Type() )
1302 // viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop(), new SUPERVGraph_Viewer() );
1305 #ifndef DISABLE_QXGRAPHVIEWER
1306 if( vmType == QxGraph_Viewer::Type() )
1308 viewMgr = new QxGraph_ViewManager( activeStudy(), desktop(), new QxGraph_Viewer() );
1311 #ifndef DISABLE_OCCVIEWER
1312 if( vmType == OCCViewer_Viewer::Type() )
1314 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1315 OCCViewer_Viewer* vm;
1316 #ifndef DISABLE_SALOMEOBJECT
1317 vm = new SOCC_Viewer();
1319 vm = new OCCViewer_Viewer( true, resMgr->booleanValue( "OCCViewer", "static_trihedron", true ) );
1321 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1322 vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
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 );
1332 #ifndef DISABLE_VTKVIEWER
1333 #ifndef DISABLE_SALOMEOBJECT
1334 if ( vmType == SVTK_Viewer::Type() )
1336 if ( vmType == VTKViewer_Viewer::Type() )
1339 #ifndef DISABLE_SALOMEOBJECT
1340 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1341 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
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 );
1357 viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
1358 VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
1360 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1368 addViewManager( viewMgr );
1369 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1371 if ( viewWin && desktop() )
1372 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1378 SLOT: Removes view manager from application
1380 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1382 removeViewManager( theVM );
1386 Protected SLOT: On study created.
1387 \param theStudy - just created study
1389 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1391 SUIT_DataObject* aRoot = 0;
1392 if ( theStudy && theStudy->root() )
1394 aRoot = theStudy->root();
1395 //aRoot->setName( tr( "DATA_MODELS" ) );
1398 getWindow( WT_ObjectBrowser );
1400 loadDockWindowsState();
1402 if ( objectBrowser() )
1403 objectBrowser()->setRoot( aRoot );
1405 activateModule( defaultModule() );
1407 if ( objectBrowser() )
1408 objectBrowser()->openLevels();
1412 Protected SLOT: On study opened.
1413 \param theStudy - just opened study
1415 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1417 SUIT_DataObject* aRoot = 0;
1418 if ( theStudy && theStudy->root() )
1420 aRoot = theStudy->root();
1424 getWindow( WT_ObjectBrowser );
1426 loadDockWindowsState();
1428 if ( objectBrowser() )
1429 objectBrowser()->setRoot( aRoot );
1431 activateModule( defaultModule() );
1433 if ( objectBrowser() )
1434 objectBrowser()->openLevels();
1439 /*!Protected SLOT. On study saved.*/
1440 void LightApp_Application::onStudySaved( SUIT_Study* s )
1442 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
1444 mru->insert( s->studyName() );
1449 /*!Protected SLOT. On study closed.*/
1450 void LightApp_Application::onStudyClosed( SUIT_Study* s )
1452 // Bug 10396: clear selection
1453 mySelMgr->clearSelected();
1455 // Bug 12944: emit signal only after clear selection
1458 activateModule( "" );
1461 /*!Protected SLOT.On desktop activated.*/
1462 void LightApp_Application::onDesktopActivated()
1464 CAM_Application::onDesktopActivated();
1465 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1467 aModule->studyActivated();
1470 void LightApp_Application::studyOpened( SUIT_Study* s )
1472 CAM_Application::studyOpened( s );
1475 updateViewManagers();
1478 void LightApp_Application::studyCreated( SUIT_Study* s )
1480 CAM_Application::studyCreated( s );
1483 updateViewManagers();
1486 /*!Gets file filter.
1487 *\retval QString "(*.bin)"
1489 QString LightApp_Application::getFileFilter() const
1497 Shows file dialog and return user selected file name
1499 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1500 const QString& caption, QWidget* parent )
1504 QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
1505 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1508 /*! Gets directory*/
1509 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1513 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1516 /*! Get open file names*/
1517 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1518 const QString& caption, QWidget* parent )
1522 QStringList fls = filters.split( ";;", QString::SkipEmptyParts );
1523 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1526 /*!Private SLOT. Update object browser.*/
1527 void LightApp_Application::onRefresh()
1529 updateObjectBrowser( true );
1532 /*!Private SLOT. On preferences.*/
1533 void LightApp_Application::onPreferences()
1535 showPreferences( activeModule() ? activeModule()->moduleName() : tr( "PREF_CATEGORY_SALOME" ) );
1538 /*!Private SLOT. On preferences.*/
1539 void LightApp_Application::showPreferences( const QString& itemText )
1541 QApplication::setOverrideCursor( Qt::WaitCursor );
1543 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1545 QApplication::restoreOverrideCursor();
1550 preferences()->activateItem( itemText );
1552 if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) && resourceMgr() )
1555 resourceMgr()->setValue( "desktop", "geometry", desktop()->storeGeometry() );
1556 resourceMgr()->save();
1562 /*!Protected SLOT. On preferences changed.*/
1563 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1565 LightApp_Module* sMod = 0;
1566 CAM_Module* mod = module( modName );
1567 if ( mod && mod->inherits( "LightApp_Module" ) )
1568 sMod = (LightApp_Module*)mod;
1571 sMod->preferencesChanged( section, param );
1573 preferencesChanged( section, param );
1574 // emit signal to allow additional preferences changing processing
1575 emit preferenceChanged( modName, section, param );
1578 /*!Remove all windows from study.*/
1579 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1581 CAM_Application::beforeCloseDoc( s );
1584 /*!Update actions.*/
1585 void LightApp_Application::updateActions()
1587 updateCommandsStatus();
1593 SUIT_Study* LightApp_Application::createNewStudy()
1595 LightApp_Application::lastStudyId++;
1597 LightApp_Study* aStudy = new LightApp_Study( this );
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* ) ) );
1609 Creates window by flag.
1610 \param flag - identificator of window type
1612 QWidget* LightApp_Application::createWindow( const int flag )
1616 SUIT_ResourceMgr* resMgr = resourceMgr();
1618 if ( flag == WT_ObjectBrowser )
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" ) );
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() ) );
1630 // temporary commented
1632 OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1634 ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1636 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1639 // Create OBSelector
1640 new LightApp_OBSelector( ob, mySelMgr );
1644 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1646 #ifndef DISABLE_PYCONSOLE
1647 else if ( flag == WT_PyConsole )
1649 PyConsole_Console* pyCons = new PyConsole_Console( desktop() );
1650 pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) );
1652 pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1655 else if ( flag == WT_LogWindow )
1657 LogWindow* logWin = new LogWindow( desktop() );
1658 logWin->setWindowTitle( tr( "LOG_WINDOW" ) );
1660 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1666 \return default windows( Object Browser, Python Console )
1667 Adds to map \a aMap.
1669 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1671 aMap.insert( WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1672 #ifndef DISABLE_PYCONSOLE
1673 aMap.insert( WT_PyConsole, Qt::BottomDockWidgetArea );
1675 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1678 /*!Default view managers*/
1679 void LightApp_Application::defaultViewManagers( QStringList& ) const
1685 \return preferences.
1686 Create preferences, if \a crt = true.
1688 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1693 LightApp_Application* that = (LightApp_Application*)this;
1695 bool toCreate = !_prefs_ && crt;
1698 _prefs_ = new LightApp_Preferences( resourceMgr() );
1699 that->createPreferences( _prefs_ );
1702 that->myPrefs = _prefs_;
1707 SUIT_ResourceMgr* resMgr = resourceMgr();
1709 QList<SUIT_Application*> appList = SUIT_Session::session()->applications();
1710 for ( QList<SUIT_Application*>::iterator appIt = appList.begin(); appIt != appList.end(); ++appIt )
1712 LightApp_Application* app = ::qobject_cast<LightApp_Application*>( *appIt );
1716 QStringList modNameList;
1717 app->modules( modNameList, false );
1719 QMap<QString, QString> iconMap;
1720 app->moduleIconNames( iconMap );
1722 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1724 if ( !app->isLibExists( *it ) )
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 ) );
1733 app->modules( modList );
1734 QListIterator<CAM_Module*> itr( modList );
1735 while ( itr.hasNext() )
1737 LightApp_Module* mod = 0;
1739 CAM_Module* anItem = itr.next();
1740 if ( anItem->inherits( "LightApp_Module" ) )
1741 mod = (LightApp_Module*)anItem;
1743 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1745 _prefs_->addPreference( mod->moduleName() );
1746 mod->createPreferences();
1747 that->emptyPreferences( mod->moduleName() );
1751 _prefs_->setItemProperty( "info", tr( "PREFERENCES_NOT_LOADED" ) );
1753 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1754 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1760 Adds new module to application
1762 void LightApp_Application::moduleAdded( CAM_Module* mod )
1764 CAM_Application::moduleAdded( mod );
1766 LightApp_Module* lightMod = 0;
1767 if ( mod && mod->inherits( "LightApp_Module" ) )
1768 lightMod = (LightApp_Module*)mod;
1770 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1772 myPrefs->addPreference( mod->moduleName() );
1773 lightMod->createPreferences();
1774 emptyPreferences( mod->moduleName() );
1778 void LightApp_Application::emptyPreferences( const QString& modName )
1780 QtxPreferenceItem* item = myPrefs->findItem( modName, true );
1781 if ( !item || !item->isEmpty() )
1784 printf( "---------------------> Modify for empty module.\n" );
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 );
1797 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1802 QStringList aValuesList;
1803 QList<QVariant> anIndicesList;
1805 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1806 pref->setItemIcon( salomeCat, Qtx::scaleIcon( resourceMgr()->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ), 20 ) );
1808 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1809 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1811 pref->setItemProperty( "columns", 2, studyGroup );
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" );
1817 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1820 platform = "winapplication";
1822 platform = "application";
1824 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", platform );
1825 pref->setItemProperty( "mode", Qtx::PT_OpenFile, apppref );
1827 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1829 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1830 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1832 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1834 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1836 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1838 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1840 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1842 pref->setItemProperty( "columns", 2, occGroup );
1843 pref->setItemProperty( "columns", 1, vtkGroup );
1844 pref->setItemProperty( "columns", 2, plot2dGroup );
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 );
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 );
1858 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1859 LightApp_Preferences::Color, "OCCViewer", "background" );
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 );
1867 int vtkGen = pref->addPreference( "", vtkGroup, LightApp_Preferences::Frame );
1868 pref->setItemProperty( "columns", 2, vtkGen );
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") );
1876 QList<QVariant> aModeIndexesList;
1877 aModeIndexesList.append(0);
1878 aModeIndexesList.append(1);
1880 pref->setItemProperty( "strings", aProjModeList, vtkProjMode );
1881 pref->setItemProperty( "indexes", aModeIndexesList, vtkProjMode );
1883 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGen,
1884 LightApp_Preferences::Color, "VTKViewer", "background" );
1886 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGen,
1887 LightApp_Preferences::DblSpin, "VTKViewer", "trihedron_size" );
1889 pref->setItemProperty( "min", 1.0E-06, vtkTS );
1890 pref->setItemProperty( "max", 150, vtkTS );
1892 pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGen, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
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") );
1900 pref->setItemProperty( "strings", aStyleModeList, vtkStyleMode );
1901 pref->setItemProperty( "indexes", aModeIndexesList, vtkStyleMode );
1903 pref->addPreference( "", vtkGroup, LightApp_Preferences::Space );
1905 int vtkSpeed = pref->addPreference( tr( "PREF_INCREMENTAL_SPEED" ), vtkGen,
1906 LightApp_Preferences::IntSpin, "VTKViewer", "speed_value" );
1908 pref->setItemProperty( "min", 1, vtkSpeed );
1909 pref->setItemProperty( "max", 1000, vtkSpeed );
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") );
1917 pref->setItemProperty( "strings", aSpeedModeList, vtkSpeedMode );
1918 pref->setItemProperty( "indexes", aModeIndexesList, vtkSpeedMode );
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
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 );
1963 int vtkRec = pref->addPreference( tr( "PREF_FRAME_RECORDING" ), vtkGroup, LightApp_Preferences::GroupBox );
1964 pref->setItemProperty( "columns", 2, vtkRec );
1966 int modePref = pref->addPreference( tr( "PREF_RECORDING_MODE" ), vtkRec,
1967 LightApp_Preferences::Selector, "VTKViewer", "recorder_mode" );
1969 values.append( tr( "PREF_SKIPPED_FRAMES" ) );
1970 values.append( tr( "PREF_ALL_DISLPAYED_FRAMES" ) );
1972 indices.append( 0 );
1973 indices.append( 1 );
1974 pref->setItemProperty( "strings", values, modePref );
1975 pref->setItemProperty( "indexes", indices, modePref );
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 );
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 );
1987 pref->addPreference( tr( "PREF_PROGRESSIVE" ), vtkRec,
1988 LightApp_Preferences::Bool, "VTKViewer", "recorder_progressive" );
1991 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1992 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
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 ;
2001 pref->setItemProperty( "strings", aValuesList, legendPosition );
2002 pref->setItemProperty( "indexes", anIndicesList, legendPosition );
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 ;
2011 pref->setItemProperty( "strings", aValuesList, curveType );
2012 pref->setItemProperty( "indexes", anIndicesList, curveType );
2014 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
2015 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
2017 pref->setItemProperty( "min", 0, markerSize );
2018 pref->setItemProperty( "max", 100, markerSize );
2020 aValuesList.clear();
2021 anIndicesList.clear();
2022 aValuesList << tr("PREF_LINEAR") << tr("PREF_LOGARITHMIC");
2023 anIndicesList << 0 << 1 ;
2025 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
2026 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
2028 pref->setItemProperty( "strings", aValuesList, horScale );
2029 pref->setItemProperty( "indexes", anIndicesList, horScale );
2031 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
2032 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
2034 pref->setItemProperty( "strings", aValuesList, verScale );
2035 pref->setItemProperty( "indexes", anIndicesList, verScale );
2037 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
2038 LightApp_Preferences::Color, "Plot2d", "Background" );
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" );
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" );
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" );
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" );
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 );
2087 Changes appearance of application according to changed preferences
2088 \param sec - section
2089 \param param - name of changed parameter
2091 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
2093 SUIT_ResourceMgr* resMgr = resourceMgr();
2097 #ifndef DISABLE_OCCVIEWER
2098 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
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 )
2106 SUIT_ViewModel* vm = it.next()->getViewModel();
2107 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
2110 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
2111 occVM->setTrihedronSize( sz );
2112 occVM->getAISContext()->UpdateCurrentViewer();
2117 #ifndef DISABLE_VTKVIEWER
2118 if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
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 )
2128 SUIT_ViewModel* vm = it.next()->getViewModel();
2129 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2132 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2135 vtkVM->setTrihedronSize( sz, isRelative );
2143 #ifndef DISABLE_VTKVIEWER
2144 if ( sec == QString( "VTKViewer" ) && (param == QString( "speed_value" ) || param == QString( "speed_mode" )) )
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() )
2154 SUIT_ViewModel* vm = it.next()->getViewModel();
2155 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2158 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2159 if( vtkVM ) vtkVM->setIncrementalSpeed( speed, mode );
2165 #ifndef DISABLE_VTKVIEWER
2166 if ( sec == QString( "VTKViewer" ) && param == QString( "projection_mode" ) )
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() )
2175 SUIT_ViewModel* vm = it.next()->getViewModel();
2176 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2179 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2180 if( vtkVM ) vtkVM->setProjectionMode( mode );
2186 #ifndef DISABLE_VTKVIEWER
2187 if ( sec == QString( "VTKViewer" ) && param == QString( "navigation_mode" ) )
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() )
2196 SUIT_ViewModel* vm = it.next()->getViewModel();
2197 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2200 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2201 if( vtkVM ) vtkVM->setInteractionStyle( mode );
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" ) ) )
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() )
2221 SUIT_ViewModel* vm = it.next()->getViewModel();
2222 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
2225 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
2226 if( vtkVM ) vtkVM->setSpacemouseButtons( btn1, btn2, btn3 );
2232 #ifndef DISABLE_OCCVIEWER
2233 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
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() )
2242 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.next() );
2243 if( mgr && mgr->getOCCViewer() )
2244 mgr->getOCCViewer()->setIsos( u, v );
2249 if( sec=="ObjectBrowser" )
2251 SUIT_DataBrowser* ob = objectBrowser();
2255 if ( param=="auto_size_first" )
2257 bool autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
2258 ob->setAutoSizeFirstColumn( autoSizeFirst );
2259 if ( autoSizeFirst )
2260 ob->adjustFirstColumnWidth();
2262 else if ( param=="auto_size" ) {
2263 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
2264 ob->setAutoSizeColumns(autoSize);
2266 ob->adjustColumnsWidth();
2268 else if ( param=="resize_on_expand_item" ) {
2269 bool resizeOnExpandItem = resMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", false );
2270 ob->setResizeOnExpandItem(resizeOnExpandItem);
2272 else if ( param == "auto_hide_search_tool" ) {
2273 ob->searchTool()->enableAutoHide( resMgr->booleanValue( "ObjectBrowser", "auto_hide_search_tool" ) );
2279 if( param=="store_positions" )
2283 #ifndef DISABLE_PYCONSOLE
2284 if( sec=="PyConsole" )
2287 if( pythonConsole() )
2288 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
2294 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
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
2315 void LightApp_Application::loadPreferences()
2317 CAM_Application::loadPreferences();
2319 SUIT_ResourceMgr* aResMgr = resourceMgr();
2324 static bool mru_load = true;
2327 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
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" );
2341 QStringList mods = aResMgr->parameters( "windows_geometry" );
2342 for ( QStringList::const_iterator it = mods.begin(); it != mods.end(); ++it )
2345 if ( aResMgr->value( "windows_geometry", *it, arr ) )
2346 myWinGeom.insert( *it, arr );
2350 mods = aResMgr->parameters( "windows_visibility" );
2351 for ( QStringList::const_iterator itr = mods.begin(); itr != mods.end(); ++itr )
2354 if ( aResMgr->value( "windows_visibility", *itr, arr ) )
2355 myWinVis.insert( *itr, arr );
2359 desktop()->retrieveGeometry( aResMgr->stringValue( "desktop", "geometry" ) );
2365 void LightApp_Application::savePreferences()
2367 CAM_Application::savePreferences();
2369 saveDockWindowsState();
2371 SUIT_ResourceMgr* aResMgr = resourceMgr();
2376 QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
2378 mru->saveLinks( aResMgr, "MRU" );
2380 for ( WinGeom::const_iterator it = myWinGeom.begin(); it != myWinGeom.end(); ++it )
2381 aResMgr->setValue( "windows_geometry", it.key(), it.value() );
2383 for ( WinVis::const_iterator itr = myWinVis.begin(); itr != myWinVis.end(); ++itr )
2384 aResMgr->setValue( "windows_visibility", itr.key(), itr.value() );
2387 aResMgr->setValue( "desktop", "geometry", desktop()->storeGeometry() );
2393 Updates desktop title
2395 void LightApp_Application::updateDesktopTitle()
2397 QString aTitle = applicationName();
2398 QString aVer = applicationVersion();
2399 if ( !aVer.isEmpty() )
2400 aTitle += QString( " " ) + aVer;
2402 if ( activeStudy() ) {
2403 QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false );
2404 aTitle += QString( " - [%1]" ).arg( sName );
2407 desktop()->setWindowTitle( aTitle );
2411 \brief Get map of the operations which can be performed
2412 on the module activation.
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
2422 \return map of the operations
2423 \sa moduleActionSelected()
2425 QMap<int, QString> LightApp_Application::activateModuleActions() const
2427 QMap<int, QString> opmap;
2428 opmap.insert( NewStudyId, tr( "ACTIVATE_MODULE_OP_NEW" ) );
2429 opmap.insert( OpenStudyId, tr( "ACTIVATE_MODULE_OP_OPEN" ) );
2434 \brief Called when the used selectes required operation chosen
2435 from "Activate module" dialog box.
2437 Performs the required operation according to the user choice.
2439 \param id operation identifier
2440 \sa activateModuleActions()
2442 void LightApp_Application::moduleActionSelected( const int id )
2457 Updates windows after close document
2459 void LightApp_Application::afterCloseDoc()
2463 CAM_Application::afterCloseDoc();
2467 Updates actions of active module
2469 void LightApp_Application::updateModuleActions()
2472 if ( activeModule() )
2473 modName = activeModule()->moduleName();
2475 LightApp_ModuleAction* moduleAction =
2476 qobject_cast<LightApp_ModuleAction*>( action( ModulesListId ) );
2478 moduleAction->setActiveModule( modName );
2482 Gets current windows.
2483 \param winMap - output current windows map.
2485 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
2488 if ( !activeStudy() )
2491 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2492 ((LightApp_Module*)activeModule())->windows( winMap );
2494 defaultWindows( winMap );
2498 Gets current view managers.
2499 \param lst - output current view managers list.
2501 void LightApp_Application::currentViewManagers( QStringList& lst ) const
2504 if ( !activeStudy() )
2507 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2508 ((LightApp_Module*)activeModule())->viewManagers( lst );
2510 defaultViewManagers( lst );
2516 void LightApp_Application::updateWindows()
2518 QMap<int, int> winMap;
2519 currentWindows( winMap );
2521 if ( activeStudy() )
2523 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
2525 if ( !dockWindow( it.key() ) )
2526 getWindow( it.key() );
2530 for ( WinMap::ConstIterator it = myWin.begin(); it != myWin.end(); ++it )
2532 QWidget* wid = it.value();
2533 if ( activeStudy() )
2534 wid->setVisible( winMap.contains( it.key() ) );
2539 if ( activeStudy() )
2540 loadDockWindowsState();
2546 Updates view managers
2548 void LightApp_Application::updateViewManagers()
2551 currentViewManagers( lst );
2553 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
2554 getViewManager( *it, true );
2558 Loads windows geometry
2560 void LightApp_Application::loadDockWindowsState()
2565 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2570 if ( activeModule() )
2571 modName = activeModule()->name();
2573 if ( myWinGeom.contains( modName ) )
2574 desktop()->restoreState( myWinGeom[modName] );
2576 if ( !myWinVis.contains( modName ) )
2579 QMap<QString, bool> tbMap, dwMap;
2580 dockWindowsState( myWinVis[modName], tbMap, dwMap );
2582 QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
2583 for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit )
2585 QToolBar* tb = *tit;
2587 QObject* po = Qtx::findParent( tb, "QMainWindow" );
2588 if ( po != desktop() )
2591 if ( tbMap.contains( tb->objectName() ) )
2592 tb->setVisible( tbMap[tb->objectName()] );
2595 QList<QDockWidget*> dwList = qFindChildren<QDockWidget*>( desktop() );
2596 for ( QList<QDockWidget*>::iterator dit = dwList.begin(); dit != dwList.end(); ++dit )
2598 QDockWidget* dw = *dit;
2600 QObject* po = Qtx::findParent( dw, "QMainWindow" );
2601 if ( po != desktop() )
2604 if ( dwMap.contains( dw->objectName() ) )
2605 dw->setVisible( dwMap[dw->objectName()] );
2610 Saves windows geometry
2612 void LightApp_Application::saveDockWindowsState()
2617 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2622 if ( activeModule() )
2623 modName = activeModule()->name();
2625 myWinGeom.insert( modName, desktop()->saveState() );
2628 if ( myWinVis.contains( modName ) )
2629 visArr = myWinVis[modName];
2631 QMap<QString, bool> tbMap, dwMap;
2632 dockWindowsState( visArr, tbMap, dwMap );
2634 QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
2635 for ( QList<QToolBar*>::iterator it = tbList.begin(); it != tbList.end(); ++it )
2638 tbMap.insert( tb->objectName(), tb->toggleViewAction()->isChecked() );
2641 QList<QDockWidget*> dwList = qFindChildren<QDockWidget*>( desktop() );
2642 for ( QList<QDockWidget*>::iterator it = dwList.begin(); it != dwList.end(); ++it )
2644 QDockWidget* wid = *it;
2645 dwMap.insert( wid->objectName(), wid->toggleViewAction()->isChecked() );
2648 visArr = dockWindowsState( tbMap, dwMap );
2650 myWinVis.insert( modName, visArr );
2653 QByteArray LightApp_Application::dockWindowsState( const QMap<QString, bool>& tb, const QMap<QString, bool>& dw ) const
2656 QDataStream stream( &visArr, QIODevice::WriteOnly );
2658 stream << (uchar)ToolBarMarker;
2659 stream << tb.size();
2660 for ( QMap<QString, bool>::const_iterator tit = tb.begin(); tit != tb.end(); ++tit )
2662 stream << tit.key();
2663 stream << (uchar)( tit.value() ? 1 : 0 );
2666 stream << (uchar)DockWidgetMarker;
2667 stream << dw.size();
2668 for ( QMap<QString, bool>::const_iterator wit = dw.begin(); wit != dw.end(); ++wit )
2670 stream << wit.key();
2671 stream << (uchar)( wit.value() ? 1 : 0 );
2677 void LightApp_Application::dockWindowsState( const QByteArray& arr, QMap<QString, bool>& tb, QMap<QString, bool>& dw ) const
2682 QByteArray visArr = arr;
2683 QDataStream stream( &visArr, QIODevice::ReadOnly );
2687 if ( marker != ToolBarMarker )
2692 for ( int i = 0; i < lines; ++i )
2695 stream >> objectName;
2698 tb.insert( objectName, shown );
2702 if ( marker != DockWidgetMarker )
2706 for ( int j = 0; j < lines; ++j )
2709 stream >> objectName;
2712 dw.insert( objectName, shown );
2717 Adds icon names for modules
2719 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
2723 SUIT_ResourceMgr* resMgr = resourceMgr();
2727 QStringList modList;
2728 modules( modList, false );
2730 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
2732 QString modName = *it;
2733 QString modIntr = moduleName( modName );
2734 QString modIcon = resMgr->stringValue( modIntr, "icon", QString() );
2736 if ( modIcon.isEmpty() )
2739 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
2740 modIcon += QString( ".png" );
2742 iconMap.insert( modName, modIcon );
2747 Inserts items in popup, which necessary for current application
2749 void LightApp_Application::contextMenuPopup( const QString& type, QMenu* thePopup, QString& title )
2751 CAM_Application::contextMenuPopup( type, thePopup, title );
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() );
2765 void LightApp_Application::createEmptyStudy()
2767 CAM_Application::createEmptyStudy();
2769 if ( objectBrowser() )
2770 objectBrowser()->updateTree();
2775 \param mod - module to be activated
2777 bool LightApp_Application::activateModule( CAM_Module* mod )
2779 bool res = CAM_Application::activateModule( mod );
2781 if ( objectBrowser() )
2782 objectBrowser()->updateTree();
2788 \return keyborad accelerators manager object
2790 SUIT_Accel* LightApp_Application::accel() const
2796 Removes dead widget container from map
2798 void LightApp_Application::onWCDestroyed( QObject* ob )
2800 // remove destroyed widget container from windows map
2801 for ( WinMap::ConstIterator itr = myWin.begin(); itr != myWin.end(); ++itr )
2803 if ( itr.value() != ob )
2806 int key = itr.key();
2807 myWin.remove( key );
2812 void LightApp_Application::onMRUActivated( const QString& name )
2814 SUIT_Session* s = SUIT_Session::session();
2815 if ( s && s->activeApplication() == this )
2819 void LightApp_Application::onStylePreferences()
2821 Style_PrefDlg dlg( desktop() );
2824 resourceMgr()->setValue( "Style", "use_salome_style", Style_Salome::isActive() );
2828 Connects just added view manager
2830 void LightApp_Application::addViewManager( SUIT_ViewManager* vm )
2832 connect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2833 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2834 STD_Application::addViewManager( vm );
2838 Remove view manager from memory
2840 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
2842 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2843 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2844 STD_Application::removeViewManager( vm );
2849 Renames active window of desktop
2851 void LightApp_Application::onRenameWindow()
2856 QWidget* w = desktop()->activeWindow();
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 );
2867 Closes active window of desktop
2869 void LightApp_Application::onCloseWindow()
2874 QWidget* w = desktop()->activeWindow();
2882 Closes all windows of desktop
2884 void LightApp_Application::onCloseAllWindow()
2886 STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
2890 QList<SUIT_ViewWindow*> wndList = desk->windows();
2891 SUIT_ViewWindow* wnd;
2892 foreach( wnd, wndList )
2900 Groups all windows of desktop
2902 void LightApp_Application::onGroupAllWindow()
2904 STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
2908 QtxWorkstack* wgStack = desk->workstack();
2914 \return if the library of module exists
2915 \param moduleTitle - title of module
2917 bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
2919 if( moduleTitle.isEmpty() )
2922 QString lib = moduleLibrary( moduleTitle );
2924 //abd: changed libSalomePyQtGUI to SalomePyQtGUI for WIN32
2925 bool isPythonModule = lib.contains("SalomePyQtGUI");
2929 paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
2931 paths = QString(::getenv( "LD_LIBRARY_PATH" )).split( ":", QString::SkipEmptyParts );
2934 bool isLibFound = false;
2935 QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2936 for( ; anIt!=aLast; anIt++ )
2938 QFileInfo inf( Qtx::addSlash( *anIt ) + lib );
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 );
2954 else if ( !isPythonModule )
2957 if ( isPythonModule )
2959 QString pylib = moduleName( moduleTitle ) + QString(".py");
2960 QString pylibgui = moduleName( moduleTitle ) + QString("GUI.py");
2962 // Check the python library
2964 paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
2966 paths = QString(::getenv( "PYTHONPATH" )).split( ":", QString::SkipEmptyParts );
2968 bool isPyLib = false, isPyGuiLib = false;
2969 QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2970 for( ; anIt!=aLast; anIt++ )
2972 QFileInfo inf( Qtx::addSlash( *anIt ) + pylib );
2973 QFileInfo infgui( Qtx::addSlash( *anIt ) + pylibgui );
2975 if( !isPyLib && inf.exists() )
2978 if( !isPyGuiLib && infgui.exists() )
2981 if ( isPyLib && isPyGuiLib && isLibFound)
2985 printf( "****************************************************************\n" );
2986 printf( "* Warning: python library for %s cannot be found:\n", moduleTitle.toLatin1().constData() );
2988 printf( "* No module named %s\n", moduleName( moduleTitle ).toLatin1().constData() );
2990 printf( "* No module named %s\n", (moduleName( moduleTitle ) + QString("GUI")).toLatin1().constData() );
2991 printf( "****************************************************************\n" );
2998 \return default name for an active study
3000 void LightApp_Application::setDefaultStudyName( const QString& theName )
3002 QStringList anInfoList;
3003 modules( anInfoList, false );
3005 LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
3006 if( anInfoList.count() == 1 && // to avoid a conflict between different modules
3007 !aStudy->isSaved() )
3009 aStudy->setStudyName( theName );
3010 updateDesktopTitle();
3015 Custom event handler
3017 bool LightApp_Application::event( QEvent* e )
3019 if( e && e->type()==2000 )
3021 SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
3022 QString* d = ( QString* )ce->data();
3023 if( SUIT_MessageBox::question(0, tr("WRN_WARNING"),
3025 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
3026 SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
3027 showPreferences( tr( "PREF_APP" ) );
3032 return CAM_Application::event( e );
3035 /*! Check data object */
3036 bool LightApp_Application::checkDataObject(LightApp_DataObject* theObj)
3040 bool isSuitable = !theObj->entry().isEmpty() &&
3041 !theObj->componentDataType().isEmpty() &&
3042 !theObj->name().isEmpty();
3049 int LightApp_Application::openChoice( const QString& aName )
3051 int choice = CAM_Application::openChoice( aName );
3053 if ( choice == OpenExist ) // The document is already open.
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;
3064 bool LightApp_Application::openAction( const int choice, const QString& aName )
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 )
3076 if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName )
3077 app = ::qobject_cast<STD_Application*>( *it );
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 );
3089 res = other->onOpenDoc( aName );
3094 res = CAM_Application::openAction( choice, aName );