1 // File: LightApp_Application.cxx
2 // Created: 6/20/2005 18:39:45 PM
3 // Author: Natalia Donis
4 // Copyright (C) CEA 2005
6 #ifndef DISABLE_PYCONSOLE
7 #include "PythonConsole_PyInterp.h" // WARNING! This include must be the first!
8 #include <PythonConsole_PyConsole.h>
11 #include "LightApp_Application.h"
12 #include "LightApp_WidgetContainer.h"
13 #include "LightApp_Module.h"
14 #include "LightApp_DataModel.h"
15 #include "LightApp_Study.h"
16 #include "LightApp_Preferences.h"
17 #include "LightApp_PreferencesDlg.h"
18 #include "LightApp_ModuleDlg.h"
19 #include "LightApp_AboutDlg.h"
21 #include "LightApp_OBFilter.h"
23 #include "LightApp_OBSelector.h"
24 #include "LightApp_SelectionMgr.h"
26 #include <CAM_Module.h>
27 #include <CAM_DataModel.h>
28 #include <CAM_Study.h>
29 #include <STD_TabDesktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Study.h>
33 #include <SUIT_FileDlg.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Tools.h>
36 #include <SUIT_Accel.h>
38 #include <QtxMRUAction.h>
39 #include <QtxDockAction.h>
40 #include <QtxToolBar.h>
42 #include <LogWindow.h>
43 #include <OB_Browser.h>
44 #include <OB_ListView.h>
46 #ifndef DISABLE_GLVIEWER
47 #include <GLViewer_Viewer.h>
48 #include <GLViewer_ViewManager.h>
49 #include "LightApp_GLSelector.h"
52 #ifndef DISABLE_PLOT2DVIEWER
53 #include <Plot2d_ViewManager.h>
54 #include <Plot2d_ViewModel.h>
55 #ifndef DISABLE_SALOMEOBJECT
56 #include <SPlot2d_ViewModel.h>
58 #include <Plot2d_ViewModel.h>
62 #ifndef DISABLE_OCCVIEWER
63 #include <OCCViewer_ViewManager.h>
64 #ifndef DISABLE_SALOMEOBJECT
65 #include <SOCC_ViewModel.h>
67 #include <OCCViewer_ViewModel.h>
69 #include "LightApp_OCCSelector.h"
72 #ifndef DISABLE_VTKVIEWER
73 #ifndef DISABLE_SALOMEOBJECT
74 #include <SVTK_ViewModel.h>
75 #include <SVTK_ViewManager.h>
76 #include "LightApp_VTKSelector.h"
78 #include <VTKViewer_ViewModel.h>
79 #include <VTKViewer_ViewManager.h>
81 #include <VTKViewer_ViewModel.h>
84 //#ifndef DISABLE_SUPERVGRAPHVIEWER
85 // #include <SUPERVGraph_ViewModel.h>
86 // #include <SUPERVGraph_ViewFrame.h>
87 // #include <SUPERVGraph_ViewManager.h>
90 #include <QtxWorkstack.h>
96 #include <qstringlist.h>
98 #include <qapplication.h>
100 #include <qstatusbar.h>
102 #include <qobjectlist.h>
103 #include <qcombobox.h>
104 #include <qinputdialog.h>
105 #include <qmessagebox.h>
106 #include <qfontdatabase.h>
108 #define FIRST_HELP_ID 1000000
110 #ifndef DISABLE_SALOMEOBJECT
111 #include "SALOME_InteractiveObject.hxx"
112 #include "SALOME_ListIO.hxx"
115 static const char* imageEmptyIcon[] = {
118 "....................",
119 "....................",
120 "....................",
121 "....................",
122 "....................",
123 "....................",
124 "....................",
125 "....................",
126 "....................",
127 "....................",
128 "....................",
129 "....................",
130 "....................",
131 "....................",
132 "....................",
133 "....................",
134 "....................",
135 "....................",
136 "....................",
137 "...................."};
139 int LightApp_Application::lastStudyId = 0;
142 \return last global id of study
144 int LightApp_Application::studyId()
146 return LightApp_Application::lastStudyId;
149 /*!Create new instance of LightApp_Application.*/
150 extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication()
152 return new LightApp_Application();
155 /*! \var global preferences of LightApp */
156 LightApp_Preferences* LightApp_Application::_prefs_ = 0;
159 \class LightApp_Application
160 Application containing LightApp module
164 LightApp_Application::LightApp_Application()
165 : CAM_Application( false ),
168 STD_TabDesktop* desk = new STD_TabDesktop();
172 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
173 QPixmap aLogo = aResMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
175 desktop()->setIcon( aLogo );
176 desktop()->setDockableMenuBar( true );
177 desktop()->setDockableStatusBar( false );
179 // base logo (salome itself)
180 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "LightApp", tr( "APP_BASE_LOGO" ), false ) );
181 // extra logo (salome-based application)
182 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "LightApp", tr( "APP_EXTRA_LOGO" ), false ) );
186 mySelMgr = new LightApp_SelectionMgr( this );
188 myAccel = SUIT_Accel::getAccel();
190 #ifndef DISABLE_OCCVIEWER
191 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
192 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
193 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
194 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
195 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
196 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
197 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
198 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
199 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
200 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
201 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
203 #ifndef DISABLE_VTKVIEWER
204 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
205 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
206 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
207 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
208 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
209 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
210 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
211 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
212 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
213 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
214 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
217 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
219 // Set existing font for the python console in resources
220 if( !aResMgr->hasValue( "PyConsole", "font" ) )
223 QFont f = aResMgr->fontValue( "PyConsole", "font" );
225 QStringList famdb = fdb.families();
227 if ( famdb.contains(f.family()) || !aResMgr->hasValue( "PyConsole", "additional_families" ) )
230 QStringList anAddFamilies = QStringList::split( ";", aResMgr->stringValue( "PyConsole", "additional_families" ) );
232 for ( QStringList::Iterator it = anAddFamilies.begin(); it != anAddFamilies.end(); ++it )
235 if ( famdb.contains(aFamily) )
237 f.setFamily( aFamily );
238 aResMgr->setValue( "PyConsole", "font", f );
245 *\li Save window geometry.
246 *\li Save desktop geometry.
247 *\li Save resource maneger.
248 *\li Delete selection manager.
250 LightApp_Application::~LightApp_Application()
255 /*!Start application.*/
256 void LightApp_Application::start()
259 desktop()->loadGeometry( resourceMgr(), "desktop" );
261 CAM_Application::start();
263 QAction* a = action( ViewWindowsId );
264 if ( a && a->inherits( "QtxDockAction" ) )
265 ((QtxDockAction*)a)->setAutoPlace( true );
268 updateViewManagers();
271 desktop()->statusBar()->message( "" );
274 /*!Gets application name.*/
275 QString LightApp_Application::applicationName() const
277 return tr( "APP_NAME" );
280 /*!Gets application version.*/
281 QString LightApp_Application::applicationVersion() const
283 static QString _app_version;
285 if ( _app_version.isEmpty() )
287 QString resVersion = tr( "APP_VERSION" );
288 if ( resVersion != "APP_VERSION" )
290 _app_version = resVersion;
294 QString path( ::getenv( "GUI_ROOT_DIR" ) );
295 if ( !path.isEmpty() )
296 path += QDir::separator();
297 path += QString( "bin/salome/VERSION" );
300 if ( vf.open( IO_ReadOnly ) )
303 vf.readLine( line, 1024 );
306 if ( !line.isEmpty() )
308 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
309 line.remove( line.length() - 1, 1 );
311 int idx = line.findRev( ":" );
313 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
321 /*!Load module by \a name.*/
322 CAM_Module* LightApp_Application::loadModule( const QString& name )
324 CAM_Module* mod = CAM_Application::loadModule( name );
327 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
328 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
329 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
334 /*!Activate module by \a modName*/
335 bool LightApp_Application::activateModule( const QString& modName )
338 CAM_Module* prevMod = activeModule();
341 actName = prevMod->moduleName();
343 if ( actName == modName )
346 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
348 saveWindowsGeometry();
350 bool status = CAM_Application::activateModule( modName );
352 updateModuleActions();
360 updateViewManagers();
366 Opens other study into active Study. If Study is empty - creates it.
367 \param theName - name of study
369 bool LightApp_Application::useStudy(const QString& theName)
372 LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
375 res = aStudy->loadDocument( theName );
376 updateDesktopTitle();
377 updateCommandsStatus();
381 /*!Gets selection manager.*/
382 LightApp_SelectionMgr* LightApp_Application::selectionMgr() const
387 /*!Creat action "New window" for certain type of viewer:*/
388 void LightApp_Application::createActionForViewer( const int id,
390 const QString& suffix,
393 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ), QIconSet(),
394 tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
395 tr( QString( "NEW_WINDOW_%1" ).arg( suffix ) ),
396 accel, desktop(), false, this, SLOT( onNewWindow() ) );
397 createMenu( a, parentId, -1 );
401 void LightApp_Application::createActions()
403 STD_Application::createActions();
405 SUIT_Desktop* desk = desktop();
406 SUIT_ResourceMgr* resMgr = resourceMgr();
409 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
410 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
411 CTRL+Key_F, desk, false, this, SLOT( onPreferences() ) );
414 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
415 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
416 createMenu( separator(), helpMenu, -1, 1 );
418 QStringList aModuleList;
419 modules( aModuleList, false );
421 int id = LightApp_Application::UserID + FIRST_HELP_ID;
422 // help for KERNEL and GUI
427 if (dir = getenv("GUI_ROOT_DIR")) {
428 aFileName = "GUI_index_v3.1.0.html";
429 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
430 if ( QFileInfo( root + aFileName ).exists() ) {
431 a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
432 tr( QString("Kernel && GUI Help") ),
433 tr( QString("Kernel & GUI Help") ),
434 0, desk, false, this, SLOT( onHelpContentsModule() ) );
435 a->setName( QString("GUI") );
436 createMenu( a, helpModuleMenu, -1 );
440 // help for other existing modules
441 QStringList::Iterator it;
442 for ( it = aModuleList.begin(); it != aModuleList.end(); ++it )
444 if ( (*it).isEmpty() )
447 QString modName = moduleName( *it );
448 aFileName = modName + "_index_v3.1.0.html";
450 if (dir = getenv( modName + "_ROOT_DIR")) {
451 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
452 if ( QFileInfo( root + aFileName ).exists() ) {
454 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
455 tr( moduleTitle(modName) + QString(" Help") ),
456 tr( moduleTitle(modName) + QString(" Help") ),
457 0, desk, false, this, SLOT( onHelpContentsModule() ) );
458 a->setName( modName );
459 createMenu( a, helpModuleMenu, -1 );
466 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
467 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
468 registerAction( MRUId, mru );
470 // default icon for neutral point ('SALOME' module)
471 QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false );
472 if ( defIcon.isNull() )
473 defIcon = QPixmap( imageEmptyIcon );
475 //! default icon for any module
476 QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false );
477 if ( modIcon.isNull() )
478 modIcon = QPixmap( imageEmptyIcon );
480 QToolBar* modTBar = new QtxToolBar( true, desk );
481 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
483 QActionGroup* modGroup = new QActionGroup( this );
484 modGroup->setExclusive( true );
485 modGroup->setUsesDropDown( true );
487 a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
488 tr( "PRP_APP_MODULE" ), 0, desk, true );
490 myActions.insert( QString(), a );
492 QMap<QString, QString> iconMap;
493 moduleIconNames( iconMap );
495 const int iconSize = 20;
497 modGroup->addTo( modTBar );
498 QObjectList *l = modTBar->queryList( "QComboBox" );
499 QObjectListIt oit( *l );
500 while ( QObject* obj = oit.current() ) {
501 QComboBox* cb = (QComboBox*)obj;
502 if ( cb ) cb->setFocusPolicy( QWidget::NoFocus );
507 modTBar->addSeparator();
510 modules( modList, false );
512 for ( it = modList.begin(); it != modList.end(); ++it )
514 if ( !isLibExists( *it ) )
516 qDebug( QString( "Library '%1' cannot be found" ).arg( *it ) );
521 if ( iconMap.contains( *it ) )
522 iconName = iconMap[*it];
524 QString modName = moduleName( *it );
526 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
530 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
532 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
536 myActions.insert( *it, a );
539 SUIT_Tools::simplifySeparators( modTBar );
542 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 );
543 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
544 createMenu( separator(), windowMenu, -1, 1 );
547 #ifndef DISABLE_GLVIEWER
548 createActionForViewer( NewGLViewId, newWinMenu, QString::number( 0 ), ALT+Key_G );
550 #ifndef DISABLE_PLOT2DVIEWER
551 createActionForViewer( NewPlot2dId, newWinMenu, QString::number( 1 ), ALT+Key_P );
553 #ifndef DISABLE_OCCVIEWER
554 createActionForViewer( NewOCCViewId, newWinMenu, QString::number( 2 ), ALT+Key_O );
556 #ifndef DISABLE_VTKVIEWER
557 createActionForViewer( NewVTKViewId, newWinMenu, QString::number( 3 ), ALT+Key_K );
561 createAction( RenameId, tr( "TOT_RENAME" ), QIconSet(), tr( "MEN_DESK_RENAME" ), tr( "PRP_RENAME" ),
562 SHIFT+Key_R, desk, false, this, SLOT( onRenameWindow() ) );
563 createMenu( RenameId, windowMenu, -1 );
565 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
567 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
568 createMenu( PreferencesId, fileMenu, 15, -1 );
569 createMenu( separator(), fileMenu, -1, 15, -1 );
572 createMenu( separator(), fileMenu, -1, 100, -1 );
573 createMenu( MRUId, fileMenu, 100, -1 );
574 createMenu( separator(), fileMenu, -1, 100, -1 );
578 /*!On module activation action.*/
579 void LightApp_Application::onModuleActivation( QAction* a )
584 QString modName = a->menuText();
585 if ( modName == tr( "APP_NAME" ) )
586 modName = QString::null;
588 // Force user to create/open a study before module activation
589 QMap<QString, QString> iconMap;
590 moduleIconNames( iconMap );
591 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
593 icon = resourceMgr()->loadPixmap( "LightApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
595 bool cancelled = false;
596 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
597 LightApp_ModuleDlg aDlg( desktop(), modName, icon );
598 int res = aDlg.exec();
612 putInfo( tr("INF_CANCELLED") );
613 myActions[QString()]->setOn( true );
619 activateModule( modName );
622 /*!Default module activation.*/
623 QString LightApp_Application::defaultModule() const
625 QStringList aModuleNames;
626 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
627 //! If there's the one and only module --> activate it automatically
628 //! TODO: Possible improvement - default module can be taken from preferences
629 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
632 /*!On new window slot.*/
633 void LightApp_Application::onNewWindow()
635 const QObject* obj = sender();
636 if ( !obj || !obj->inherits( "QAction" ) )
640 int id = actionId( (QAction*)obj );
643 #ifndef DISABLE_GLVIEWER
645 type = GLViewer_Viewer::Type();
648 #ifndef DISABLE_PLOT2DVIEWER
650 type = Plot2d_Viewer::Type();
653 #ifndef DISABLE_OCCVIEWER
655 type = OCCViewer_Viewer::Type();
658 #ifndef DISABLE_VTKVIEWER
660 type = VTKViewer_Viewer::Type();
665 if ( !type.isEmpty() )
666 createViewManager( type );
670 SLOT: Creates new document
672 void LightApp_Application::onNewDoc()
674 SUIT_Study* study = activeStudy();
676 saveWindowsGeometry();
678 CAM_Application::onNewDoc();
680 if ( !study ) // new study will be create in THIS application
683 updateViewManagers();
688 SLOT: Opens new document
690 void LightApp_Application::onOpenDoc()
692 SUIT_Study* study = activeStudy();
693 saveWindowsGeometry();
695 CAM_Application::onOpenDoc();
697 if ( !study ) // new study will be create in THIS application
700 updateViewManagers();
704 #include "SUIT_MessageBox.h"
707 SLOT: Opens new document.
708 \param aName - name of file
710 bool LightApp_Application::onOpenDoc( const QString& aName )
712 bool isAlreadyOpen = false;
714 // Look among opened studies
715 if (activeStudy()) { // at least one study is opened
716 SUIT_Session* aSession = SUIT_Session::session();
717 QPtrList<SUIT_Application> aAppList = aSession->applications();
718 QPtrListIterator<SUIT_Application> it (aAppList);
719 SUIT_Application* aApp = 0;
720 // iterate on all applications
721 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
722 if (aApp->activeStudy()->studyName() == aName) {
723 isAlreadyOpen = true; // Already opened, ask user what to do
725 // The document ... is already open.
726 // Do you want to reload it?
727 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
728 tr("QUE_DOC_ALREADYOPEN").arg(aName),
729 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
730 if (aAnswer == 1) { // reload
731 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
732 // Opened in THIS (active) application.
733 STD_Application* app1 = (STD_Application*)aAppList.at(0);
734 STD_Application* app2 = (STD_Application*)aAppList.at(1);
735 if (!app1 || !app2) {
739 if (app1->activeStudy()->studyName() == aName) {
740 // app1 is this application, we need another one
743 // Close document of this application. This application will be destroyed.
744 onCloseDoc(/*ask = */false);
745 // Open the file with another application, as this one will be destroyed.
746 return app1->onOpenDoc(aName);
748 // Opened in another application.
749 STD_Application* app = (STD_Application*)aApp;
751 app->onCloseDoc(/*ask = */false);
753 } else { // do not reload
754 // OK, the study will not be reloaded, but we call
755 // CAM_Application::onOpenDoc( aName ) all the same.
756 // It will activate a desktop of the study <aName>.
762 bool res = CAM_Application::onOpenDoc( aName );
764 QAction* a = action( MRUId );
765 if ( a && a->inherits( "QtxMRUAction" ) )
767 QtxMRUAction* mru = (QtxMRUAction*)a;
769 mru->insert( aName );
771 mru->remove( aName );
777 SLOT: Displays "About" message box
779 void LightApp_Application::onHelpAbout()
781 LightApp_AboutDlg* dlg = new LightApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
788 \param aName - name of document
790 bool LightApp_Application::onLoadDoc( const QString& aName )
792 bool res = CAM_Application::onLoadDoc( aName );
794 /*jfa tmp:QAction* a = action( MRUId );
795 if ( a && a->inherits( "QtxMRUAction" ) )
797 QtxMRUAction* mru = (QtxMRUAction*)a;
799 mru->insert( aName );
801 mru->remove( aName );
807 Private SLOT: Called on selection is changed
808 Dispatchs active module that selection is changed
810 void LightApp_Application::onSelection()
812 onSelectionChanged();
814 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
815 ((LightApp_Module*)activeModule())->selectionChanged();
820 \param study - SUIT_Study.
822 void LightApp_Application::setActiveStudy( SUIT_Study* study )
824 CAM_Application::setActiveStudy( study );
830 Enables/Disables menu items and toolbar buttons. Rebuild menu
832 void LightApp_Application::updateCommandsStatus()
834 CAM_Application::updateCommandsStatus();
837 #ifndef DISABLE_GLVIEWER
838 a = action( NewGLViewId );
840 a->setEnabled( activeStudy() );
843 #ifndef DISABLE_PLOT2DVIEWER
844 a = action( NewPlot2dId );
846 a->setEnabled( activeStudy() );
849 #ifndef DISABLE_OCCVIEWER
850 a = action( NewOCCViewId );
852 a->setEnabled( activeStudy() );
855 #ifndef DISABLE_VTKVIEWER
856 a = action( NewVTKViewId );
858 a->setEnabled( activeStudy() );
864 Runs system command in separate thread
866 class RunBrowser: public QThread {
869 RunBrowser( LightApp_Application* app, QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
870 myApp(theApp), myParams(theParams),
872 myHelpFile("file://" + theHelpFile + theContext),
874 myHelpFile("file:" + theHelpFile + theContext),
885 if ( !myApp.isEmpty())
887 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
888 myStatus = system(aCommand);
891 QCustomEvent* ce2000 = new QCustomEvent( 2000 );
892 QString* msg = new QString( QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").arg(myApp).arg(myHelpFile) );
893 ce2000->setData( msg );
894 postEvent( myLApp, ce2000 );
904 LightApp_Application* myLApp;
908 SLOT: Displays help contents for choosen module
910 void LightApp_Application::onHelpContentsModule()
912 const QAction* obj = (QAction*) sender();
914 QString aComponentName = obj->name();
915 QString aFileName = aComponentName + "_index_v3.1.0.html";
917 QCString dir = getenv( aComponentName + "_ROOT_DIR");
918 QString homeDir = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") );
920 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
921 SUIT_ResourceMgr* resMgr = resourceMgr();
922 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
923 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
925 if (!anApp.isEmpty()) {
926 RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
930 if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
931 tr("DEFINE_EXTERNAL_BROWSER"),
932 tr("BUT_OK"),tr("BUT_CANCEL"),0,1,0 )==0 )
938 SLOT: Displays help contents for choosen dialog
940 void LightApp_Application::onHelpContextModule(const QString& theComponentName, const QString& theFileName)
942 QCString dir = getenv( theComponentName + "_ROOT_DIR");
943 QString homeDir = Qtx::addSlash(Qtx::addSlash(dir)+Qtx::addSlash("doc")+Qtx::addSlash("salome")+Qtx::addSlash("gui")+Qtx::addSlash(theComponentName));
945 QString helpFile = QFileInfo( homeDir + theFileName ).absFilePath();
946 SUIT_ResourceMgr* resMgr = resourceMgr();
947 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
948 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
950 if (!anApp.isEmpty()) {
951 RunBrowser* rs = new RunBrowser( this, anApp, aParams, helpFile );
955 if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
956 tr("DEFINE_EXTERNAL_BROWSER"),
957 tr("BUT_OK"), tr("BUT_CANCEL"),0,1,0)==0 )
963 Sets enable or disable some actions on selection changed.
965 void LightApp_Application::onSelectionChanged()
970 \return window by key
971 \param flag - key for window
972 \param studyId - study id
973 Flag used how identificator of window in windows list.
975 QWidget* LightApp_Application::window( const int flag, const int studyId ) const
982 if ( !activeStudy() )
985 sId = activeStudy()->id();
988 if ( myWindows.contains( flag ) )
989 wid = myWindows[flag]->widget( sId );
995 Adds window to application.
997 \param flag - key for window
998 \param studyId - study id
999 Flag used how identificator of window in windows list.
1001 void LightApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
1009 if ( !activeStudy() )
1012 sId = activeStudy()->id();
1015 if ( !myWindows.contains( flag ) )
1017 QMap<int, int> winMap;
1018 currentWindows( winMap );
1020 LightApp_WidgetContainer* newWC = new LightApp_WidgetContainer( flag, desktop() );
1021 connect( newWC, SIGNAL( destroyed ( QObject* ) ), this, SLOT( onWCDestroyed( QObject* ) ) );
1022 // asv: connecting a slot for storing visibility flag of a window
1023 connect( newWC, SIGNAL( visibilityChanged ( bool ) ), SLOT( onVisibilityChanged( bool ) ) );
1024 myWindows.insert( flag, newWC );
1025 if ( winMap.contains( flag ) )
1026 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
1028 myWindows[flag]->setResizeEnabled( true );
1029 myWindows[flag]->setCloseMode( QDockWindow::Always );
1030 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
1031 myWindows[flag]->setFixedExtentWidth( wid->width() );
1032 myWindows[flag]->setFixedExtentHeight( wid->height() );
1036 #ifndef DISABLE_PYCONSOLE
1037 if( wid->inherits( "PythonConsole" ) )
1039 if( resourceMgr()->hasValue( "PyConsole", "font" ) )
1040 f = resourceMgr()->fontValue( "PyConsole", "font" );
1043 f = ( ( PythonConsole* )wid )->font();
1044 resourceMgr()->setValue( "PyConsole", "font", f );
1051 myWindows[flag]->insert( sId, wid );
1054 setWindowShown( flag, !myWindows[flag]->isEmpty() );
1058 Removes window from application.
1059 \param flag - key for window
1060 \param studyId - study id
1061 Flag used how identificator of window in windows list.
1063 void LightApp_Application::removeWindow( const int flag, const int studyId )
1065 if ( !myWindows.contains( flag ) )
1071 if ( !activeStudy() )
1074 sId = activeStudy()->id();
1077 QWidget* wid = myWindows[flag]->widget( sId );
1078 myWindows[flag]->remove( sId );
1081 setWindowShown( flag, !myWindows[flag]->isEmpty() );
1086 \param flag - key for window
1087 \param studyId - study id
1088 Flag used how identificator of window in windows list.
1090 QWidget* LightApp_Application::getWindow( const int flag, const int studyId )
1092 QWidget* wid = window( flag, studyId );
1094 addWindow( wid = createWindow( flag ), flag, studyId );
1100 \return is window visible
1101 \param type - flag of window
1103 bool LightApp_Application::isWindowVisible( const int type ) const
1106 if ( myWindows.contains( type ) )
1108 SUIT_Desktop* desk = ((LightApp_Application*)this)->desktop();
1109 res = desk && desk->appropriate( myWindows[type] );
1115 Sets window show or hide.
1116 \param type - window identificator.
1117 \param on - true/false (window show/hide)
1119 void LightApp_Application::setWindowShown( const int type, const bool on )
1121 if ( !desktop() || !myWindows.contains( type ) )
1124 QDockWindow* dw = myWindows[type];
1125 desktop()->setAppropriate( dw, on );
1128 else if( dw->isShown() )
1131 myWindowsVisible[ type ] = true;
1136 \return Object Browser
1138 OB_Browser* LightApp_Application::objectBrowser()
1141 QWidget* wid = window( WT_ObjectBrowser );
1142 if ( wid && wid->inherits( "OB_Browser" ) )
1143 ob = (OB_Browser*)wid;
1150 LogWindow* LightApp_Application::logWindow()
1153 QWidget* wid = getWindow( WT_LogWindow );
1154 if ( wid->inherits( "LogWindow" ) )
1155 lw = (LogWindow*)wid;
1159 #ifndef DISABLE_PYCONSOLE
1161 \return Python Console
1163 PythonConsole* LightApp_Application::pythonConsole()
1165 PythonConsole* console = 0;
1166 QWidget* wid = getWindow( WT_PyConsole );
1167 if ( wid->inherits( "PythonConsole" ) )
1168 console = (PythonConsole*)wid;
1174 Updates object browser and maybe data models
1175 \param updateModels - if it is true, then data models are updated
1177 void LightApp_Application::updateObjectBrowser( const bool updateModels )
1179 // update existing data models
1182 const bool isAutoUpdate = objectBrowser() ? objectBrowser()->isAutoUpdate() : true;
1183 if( objectBrowser() )
1184 objectBrowser()->setAutoUpdate( false );
1186 LightApp_Study* study = dynamic_cast<LightApp_Study*>(activeStudy());
1188 CAM_Study::ModelList dm_list;
1189 study->dataModels( dm_list );
1190 for ( CAM_Study::ModelListIterator it( dm_list ); it.current(); ++it ) {
1191 CAM_DataModel* camDM = it.current();
1192 if ( camDM && camDM->inherits( "LightApp_DataModel" ) )
1193 ((LightApp_DataModel*)camDM)->update();
1197 if( objectBrowser() )
1198 objectBrowser()->setAutoUpdate( isAutoUpdate );
1200 if ( objectBrowser() )
1202 objectBrowser()->updateGeometry();
1203 objectBrowser()->updateTree( 0, false );
1210 LightApp_Preferences* LightApp_Application::preferences() const
1212 return preferences( false );
1216 \return first view manager of some type
1217 \param vmType - type of view manager
1218 \param create - is it necessary to create view manager in case, when there is no manager of such type
1220 SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, const bool create )
1222 SUIT_ViewManager* aVM = viewManager( vmType );
1223 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1225 if ( anActiveVM && anActiveVM->getType() == vmType )
1228 if ( aVM && create )
1230 if ( !aVM->getActiveView() )
1233 aVM->getActiveView()->setFocus();
1236 aVM = createViewManager( vmType );
1242 Creates view manager of some type
1243 \param vmType - type of view manager
1245 SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType )
1247 SUIT_ResourceMgr* resMgr = resourceMgr();
1249 SUIT_ViewManager* viewMgr = 0;
1250 #ifndef DISABLE_GLVIEWER
1251 if( vmType == GLViewer_Viewer::Type() )
1253 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1254 new LightApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1257 #ifndef DISABLE_PLOT2DVIEWER
1258 if( vmType == Plot2d_Viewer::Type() )
1260 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1262 #ifndef DISABLE_SALOMEOBJECT
1263 vm = new SPlot2d_Viewer();
1265 vm = new Plot2d_Viewer();
1267 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1268 Plot2d_ViewWindow* wnd = dynamic_cast<Plot2d_ViewWindow*>( viewMgr->getActiveView() );
1271 Plot2d_ViewFrame* frame = wnd->getViewFrame();
1272 frame->setBackgroundColor( resMgr->colorValue( "Plot2d", "Background", frame->backgroundColor() ) );
1276 //#ifndef DISABLE_SUPERVGRAPHVIEWER
1277 // if( vmType == SUPERVGraph_Viewer::Type() )
1279 // viewMgr = new SUPERVGraph_ViewManager( activeStudy(), desktop(), new SUPERVGraph_Viewer() );
1282 #ifndef DISABLE_OCCVIEWER
1283 if( vmType == OCCViewer_Viewer::Type() )
1285 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1286 OCCViewer_Viewer* vm;
1287 #ifndef DISABLE_SALOMEOBJECT
1288 vm = new SOCC_Viewer();
1290 vm = new OCCViewer_Viewer();
1292 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1293 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1296 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1297 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1298 vm->setIsos( u, v );
1299 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1300 new LightApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1303 #ifndef DISABLE_VTKVIEWER
1304 #ifndef DISABLE_SALOMEOBJECT
1305 if ( vmType == SVTK_Viewer::Type() )
1307 if ( vmType == VTKViewer_Viewer::Type() )
1310 #ifndef DISABLE_SALOMEOBJECT
1311 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1312 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1315 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1316 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ),
1317 resMgr->booleanValue( "VTKViewer", "relative_size", vm->trihedronRelative() ) );
1318 new LightApp_VTKSelector( vm, mySelMgr );
1321 viewMgr = new VTKViewer_ViewManager( activeStudy(), desktop() );
1322 VTKViewer_Viewer* vm = dynamic_cast<VTKViewer_Viewer*>( viewMgr->getViewModel() );
1324 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1332 addViewManager( viewMgr );
1333 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1335 if ( viewWin && desktop() )
1336 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1342 SLOT: Removes view manager from application
1344 void LightApp_Application::onCloseView( SUIT_ViewManager* theVM )
1346 removeViewManager( theVM );
1350 Protected SLOT: On study created.
1351 \param theStudy - just created study
1353 void LightApp_Application::onStudyCreated( SUIT_Study* theStudy )
1355 SUIT_DataObject* aRoot = 0;
1356 if ( theStudy && theStudy->root() )
1358 aRoot = theStudy->root();
1359 //aRoot->setName( tr( "DATA_MODELS" ) );
1361 getWindow( WT_ObjectBrowser );
1362 if ( objectBrowser() != 0 )
1363 objectBrowser()->setRootObject( aRoot );
1365 activateModule( defaultModule() );
1371 Protected SLOT: On study opened.
1372 \param theStudy - just opened study
1374 void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
1376 SUIT_DataObject* aRoot = 0;
1377 if ( theStudy && theStudy->root() )
1379 aRoot = theStudy->root();
1382 getWindow( WT_ObjectBrowser );
1383 if ( objectBrowser() != 0 ) {
1384 objectBrowser()->setRootObject( aRoot );
1387 activateModule( defaultModule() );
1394 /*!Protected SLOT. On study saved.*/
1395 void LightApp_Application::onStudySaved( SUIT_Study* )
1400 /*!Protected SLOT. On study closed.*/
1401 void LightApp_Application::onStudyClosed( SUIT_Study* )
1405 // Bug 10396: clear selection
1406 mySelMgr->clearSelected();
1408 activateModule( "" );
1410 saveWindowsGeometry();
1413 /*!Protected SLOT.On desktop activated.*/
1414 void LightApp_Application::onDesktopActivated()
1416 CAM_Application::onDesktopActivated();
1417 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>(activeModule());
1419 aModule->studyActivated();
1422 /*!Gets file filter.
1423 *\retval QString "(*.bin)"
1425 QString LightApp_Application::getFileFilter() const
1433 Shows file dialog and return user selected file name
1435 QString LightApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1436 const QString& caption, QWidget* parent )
1440 QStringList fls = QStringList::split( ";;", filters, false );
1441 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1444 /*! Gets directory*/
1445 QString LightApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1449 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1452 /*! Get open file names*/
1453 QStringList LightApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1454 const QString& caption, QWidget* parent )
1458 QStringList fls = QStringList::split( ";;", filters, false );
1459 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1462 /*!Private SLOT. Update object browser.*/
1463 void LightApp_Application::onRefresh()
1465 updateObjectBrowser( true );
1468 /*!Private SLOT. On preferences.*/
1469 void LightApp_Application::onPreferences()
1471 QApplication::setOverrideCursor( Qt::waitCursor );
1473 LightApp_PreferencesDlg* prefDlg = new LightApp_PreferencesDlg( preferences( true ), desktop());
1475 QApplication::restoreOverrideCursor();
1480 if ( ( prefDlg->exec() == QDialog::Accepted || prefDlg->isSaved() ) && resourceMgr() ) {
1482 desktop()->saveGeometry( resourceMgr(), "desktop" );
1483 resourceMgr()->save();
1489 /*!Protected SLOT. On preferences changed.*/
1490 void LightApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1492 LightApp_Module* sMod = 0;
1493 CAM_Module* mod = module( modName );
1494 if ( mod && mod->inherits( "LightApp_Module" ) )
1495 sMod = (LightApp_Module*)mod;
1498 sMod->preferencesChanged( section, param );
1500 preferencesChanged( section, param );
1503 /*!Private SLOT. On open document with name \a aName.*/
1504 void LightApp_Application::onMRUActivated( QString aName )
1509 /*!Remove all windows from study.*/
1510 void LightApp_Application::beforeCloseDoc( SUIT_Study* s )
1512 CAM_Application::beforeCloseDoc( s );
1514 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1515 removeWindow( itr.key(), s->id() );
1518 /*!Update actions.*/
1519 void LightApp_Application::updateActions()
1521 updateCommandsStatus();
1527 SUIT_Study* LightApp_Application::createNewStudy()
1529 LightApp_Application::lastStudyId++;
1531 LightApp_Study* aStudy = new LightApp_Study( this );
1533 // Set up processing of major study-related events
1534 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
1535 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
1536 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
1537 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
1543 Creates window by flag.
1544 \param flag - identificator of window type
1546 QWidget* LightApp_Application::createWindow( const int flag )
1549 if ( flag == WT_ObjectBrowser )
1551 OB_Browser* ob = new OB_Browser( desktop() );
1552 ob->setAutoUpdate( true );
1553 //ob->setAutoOpenLevel( 1 ); // commented by ASV as a fix to bug IPAL10107
1554 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1556 OB_ListView* ob_list = dynamic_cast<OB_ListView*>( const_cast<QListView*>( ob->listView() ) );
1558 ob_list->setColumnMaxWidth( 0, desktop()->width()/4 );
1560 ob->setFilter( new LightApp_OBFilter( selectionMgr() ) );
1561 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1563 // Create OBSelector
1564 new LightApp_OBSelector( ob, mySelMgr );
1568 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1570 #ifndef DISABLE_PYCONSOLE
1571 else if ( flag == WT_PyConsole )
1573 PythonConsole* pyCons = new PythonConsole( desktop() );
1574 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1576 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1579 else if ( flag == WT_LogWindow )
1581 LogWindow* logWin = new LogWindow( desktop() );
1582 logWin->setCaption( tr( "LOG_WINDOW" ) );
1584 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1590 \return default windows( Object Browser, Python Console )
1591 Adds to map \a aMap.
1593 void LightApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1595 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1596 #ifndef DISABLE_PYCONSOLE
1597 aMap.insert( WT_PyConsole, Qt::DockBottom );
1599 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1602 /*!Default view managers*/
1603 void LightApp_Application::defaultViewManagers( QStringList& ) const
1609 \return preferences.
1610 Create preferences, if \a crt = true.
1612 LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
1617 LightApp_Application* that = (LightApp_Application*)this;
1619 bool toCreate = !_prefs_ && crt;
1622 _prefs_ = new LightApp_Preferences( resourceMgr() );
1623 that->createPreferences( _prefs_ );
1626 that->myPrefs = _prefs_;
1628 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1629 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1631 if ( !appIt.current()->inherits( "LightApp_Application" ) )
1634 LightApp_Application* app = (LightApp_Application*)appIt.current();
1636 QStringList modNameList;
1637 app->modules( modNameList, false );
1638 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1640 int id = _prefs_->addPreference( *it );
1641 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1645 app->modules( modList );
1646 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1648 LightApp_Module* mod = 0;
1649 if ( itr.current()->inherits( "LightApp_Module" ) )
1650 mod = (LightApp_Module*)itr.current();
1652 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1654 int modCat = _prefs_->addPreference( mod->moduleName() );
1655 _prefs_->setItemProperty( modCat, "info", QString::null );
1657 mod->createPreferences();
1662 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1663 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1669 Adds new module to application
1671 void LightApp_Application::moduleAdded( CAM_Module* mod )
1673 CAM_Application::moduleAdded( mod );
1675 LightApp_Module* lightMod = 0;
1676 if ( mod && mod->inherits( "LightApp_Module" ) )
1677 lightMod = (LightApp_Module*)mod;
1679 if ( myPrefs && lightMod && !myPrefs->hasModule( lightMod->moduleName() ))
1681 int modCat = myPrefs->addPreference( mod->moduleName() );
1682 myPrefs->setItemProperty( modCat, "info", QString::null );
1683 lightMod->createPreferences();
1690 void LightApp_Application::createPreferences( LightApp_Preferences* pref )
1695 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1697 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1698 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1699 pref->setItemProperty( studyGroup, "columns", 1 );
1701 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file" );
1702 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "ascii_file" );
1703 pref->addPreference( tr( "PREF_STORE_POS" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_positions" );
1705 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1706 pref->setItemProperty( extgroup, "columns", 1 );
1707 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, LightApp_Preferences::File, "ExternalBrowser", "application" );
1708 pref->setItemProperty( apppref, "existing", true );
1709 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1710 pref->setItemProperty( apppref, "readOnly", false );
1712 pref->addPreference( tr( "PREF_PARAM" ), extgroup, LightApp_Preferences::String, "ExternalBrowser", "parameters" );
1714 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1715 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1716 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" );
1718 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1720 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1722 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1724 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1726 int supervGroup = pref->addPreference( tr( "PREF_GROUP_SUPERV" ), viewTab );
1728 pref->setItemProperty( occGroup, "columns", 1 );
1729 pref->setItemProperty( vtkGroup, "columns", 1 );
1730 pref->setItemProperty( plot2dGroup, "columns", 1 );
1732 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1733 LightApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1734 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1735 LightApp_Preferences::Color, "OCCViewer", "background" );
1737 pref->setItemProperty( occTS, "min", 1 );
1738 pref->setItemProperty( occTS, "max", 1000 );
1740 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1741 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1742 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1743 LightApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1745 pref->setItemProperty( isoU, "min", 0 );
1746 pref->setItemProperty( isoU, "max", 100000 );
1748 pref->setItemProperty( isoV, "min", 0 );
1749 pref->setItemProperty( isoV, "max", 100000 );
1751 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1752 LightApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1753 pref->addPreference( tr( "PREF_RELATIVE_SIZE" ), vtkGroup, LightApp_Preferences::Bool, "VTKViewer", "relative_size" );
1754 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1755 LightApp_Preferences::Color, "VTKViewer", "background" );
1757 pref->setItemProperty( vtkTS, "min", 1 );
1758 pref->setItemProperty( vtkTS, "max", 150 );
1760 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1761 LightApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1763 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1764 LightApp_Preferences::Selector, "Plot2d", "LegendPos" );
1765 QStringList aLegendPosList;
1766 aLegendPosList.append( tr("PREF_LEFT") );
1767 aLegendPosList.append( tr("PREF_RIGHT") );
1768 aLegendPosList.append( tr("PREF_TOP") );
1769 aLegendPosList.append( tr("PREF_BOTTOM") );
1771 QValueList<QVariant> anIndexesList;
1772 anIndexesList.append(0);
1773 anIndexesList.append(1);
1774 anIndexesList.append(2);
1775 anIndexesList.append(3);
1777 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1778 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1780 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1781 LightApp_Preferences::Selector, "Plot2d", "CurveType" );
1782 QStringList aCurveTypesList;
1783 aCurveTypesList.append( tr("PREF_POINTS") );
1784 aCurveTypesList.append( tr("PREF_LINES") );
1785 aCurveTypesList.append( tr("PREF_SPLINE") );
1787 anIndexesList.clear();
1788 anIndexesList.append(0);
1789 anIndexesList.append(1);
1790 anIndexesList.append(2);
1792 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1793 pref->setItemProperty( curveType, "indexes", anIndexesList );
1795 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1796 LightApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1798 pref->setItemProperty( markerSize, "min", 0 );
1799 pref->setItemProperty( markerSize, "max", 100 );
1801 QStringList aScaleModesList;
1802 aScaleModesList.append( tr("PREF_LINEAR") );
1803 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1805 anIndexesList.clear();
1806 anIndexesList.append(0);
1807 anIndexesList.append(1);
1809 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1810 LightApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1812 pref->setItemProperty( horScale, "strings", aScaleModesList );
1813 pref->setItemProperty( horScale, "indexes", anIndexesList );
1815 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1816 LightApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1818 pref->setItemProperty( verScale, "strings", aScaleModesList );
1819 pref->setItemProperty( verScale, "indexes", anIndexesList );
1821 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1822 LightApp_Preferences::Color, "Plot2d", "Background" );
1824 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1825 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1826 pref->setItemProperty( dirGroup, "columns", 1 );
1827 pref->addPreference( tr( "" ), dirGroup,
1828 LightApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1830 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), supervGroup,
1831 LightApp_Preferences::Color, "SUPERVGraph", "Background" );
1832 pref->addPreference( tr( "PREF_SUPERV_TITLE_COLOR" ), supervGroup,
1833 LightApp_Preferences::Color, "SUPERVGraph", "Title" );
1834 // pref->addPreference( tr( "PREF_SUPERV_CTRL_COLOR" ), supervGroup,
1835 // LightApp_Preferences::Color, "SUPERVGraph", "Ctrl" );
1837 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1838 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1839 pref->addPreference( tr( "PREF_AUTO_SIZE_FIRST" ), objSetGroup, LightApp_Preferences::Bool,
1840 "ObjectBrowser", "auto_size_first" );
1841 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool,
1842 "ObjectBrowser", "auto_size" );
1846 Changes appearance of application according to changed preferences
1847 \param sec - section
1848 \param param - name of changed parameter
1850 void LightApp_Application::preferencesChanged( const QString& sec, const QString& param )
1852 SUIT_ResourceMgr* resMgr = resourceMgr();
1856 #ifndef DISABLE_OCCVIEWER
1857 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1859 int sz = resMgr->integerValue( sec, param, -1 );
1860 QPtrList<SUIT_ViewManager> lst;
1861 viewManagers( OCCViewer_Viewer::Type(), lst );
1862 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1864 SUIT_ViewModel* vm = it.current()->getViewModel();
1865 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1868 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1869 occVM->setTrihedronSize( sz );
1870 occVM->getAISContext()->UpdateCurrentViewer();
1875 #ifndef DISABLE_VTKVIEWER
1876 if ( sec == QString( "VTKViewer" ) && (param == QString( "trihedron_size" ) || param == QString( "relative_size" )) )
1878 int sz = resMgr->integerValue( "VTKViewer", "trihedron_size", -1 );
1879 bool isRelative = resMgr->booleanValue( "VTKViewer", "relative_size", true );
1880 QPtrList<SUIT_ViewManager> lst;
1881 #ifndef DISABLE_SALOMEOBJECT
1882 viewManagers( SVTK_Viewer::Type(), lst );
1883 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1885 SUIT_ViewModel* vm = it.current()->getViewModel();
1886 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1889 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1892 vtkVM->setTrihedronSize( sz, isRelative );
1900 #ifndef DISABLE_OCCVIEWER
1901 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1903 QPtrList<SUIT_ViewManager> lst;
1904 viewManagers( OCCViewer_Viewer::Type(), lst );
1905 int u = resMgr->integerValue( sec, "iso_number_u" );
1906 int v = resMgr->integerValue( sec, "iso_number_v" );
1907 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1909 OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>( it.current() );
1910 if( mgr && mgr->getOCCViewer() )
1911 mgr->getOCCViewer()->setIsos( u, v );
1916 if( sec=="ObjectBrowser" )
1918 if( param=="auto_size" || param=="auto_size_first" )
1920 OB_Browser* ob = objectBrowser();
1924 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ),
1925 autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );
1926 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1927 ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual );
1929 for( int i=1; i<ob->listView()->columns(); i++ )
1930 if( ob->listView()->columnWidth( i )>0 )
1931 ob->listView()->adjustColumn( i );
1932 updateObjectBrowser( false );
1938 if( param=="store_positions" )
1942 #ifndef DISABLE_PYCONSOLE
1943 if( sec=="PyConsole" )
1946 if( pythonConsole() )
1947 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1955 void LightApp_Application::savePreferences()
1957 saveWindowsGeometry();
1959 if ( resourceMgr() )
1962 desktop()->saveGeometry( resourceMgr(), "desktop" );
1963 resourceMgr()->save();
1968 Updates desktop title
1970 void LightApp_Application::updateDesktopTitle() {
1971 QString aTitle = applicationName();
1972 QString aVer = applicationVersion();
1973 if ( !aVer.isEmpty() )
1974 aTitle += QString( " " ) + aVer;
1976 if ( activeStudy() ) {
1977 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1978 aTitle += QString( " - [%1]" ).arg( sName );
1981 desktop()->setCaption( aTitle );
1985 Updates windows after close document
1987 void LightApp_Application::afterCloseDoc()
1991 CAM_Application::afterCloseDoc();
1995 Updates actions of active module
1997 void LightApp_Application::updateModuleActions()
2000 if ( activeModule() )
2001 modName = activeModule()->moduleName();
2003 if ( myActions.contains( modName ) )
2004 myActions[modName]->setOn( true );
2008 Gets current windows.
2009 \param winMap - output current windows map.
2011 void LightApp_Application::currentWindows( QMap<int, int>& winMap ) const
2014 if ( !activeStudy() )
2017 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2018 ((LightApp_Module*)activeModule())->windows( winMap );
2020 defaultWindows( winMap );
2024 Gets current view managers.
2025 \param lst - output current view managers list.
2027 void LightApp_Application::currentViewManagers( QStringList& lst ) const
2030 if ( !activeStudy() )
2033 if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
2034 ((LightApp_Module*)activeModule())->viewManagers( lst );
2036 defaultViewManagers( lst );
2042 void LightApp_Application::updateWindows()
2044 QMap<int, int> winMap;
2045 currentWindows( winMap );
2047 if ( activeStudy() ) {
2048 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
2049 getWindow( it.key() );
2051 loadWindowsGeometry();
2054 // setWindowShown should be done even if no study is active (open). in this case all open windows
2055 // will be hidden, which is neccessary in this case.
2056 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) {
2058 if ( myWindowsVisible.contains( itr.key() ) &&
2059 !myWindowsVisible[ itr.key() ] )
2062 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
2067 Updates view managers
2069 void LightApp_Application::updateViewManagers()
2072 currentViewManagers( lst );
2074 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
2075 getViewManager( *it, true );
2079 Loads windows geometry
2081 void LightApp_Application::loadWindowsGeometry()
2083 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2087 QtxDockAction* dockMgr = 0;
2089 QAction* a = action( ViewWindowsId );
2090 if ( a && a->inherits( "QtxDockAction" ) )
2091 dockMgr = (QtxDockAction*)a;
2097 if ( activeModule() )
2098 modName = activeModule()->name("");
2100 QString section = QString( "windows_geometry" );
2101 if ( !modName.isEmpty() )
2102 section += QString( "." ) + modName;
2104 dockMgr->loadGeometry( resourceMgr(), section, false );
2105 dockMgr->restoreGeometry();
2109 Saves windows geometry
2111 void LightApp_Application::saveWindowsGeometry()
2113 bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
2117 QtxDockAction* dockMgr = 0;
2119 QAction* a = action( ViewWindowsId );
2120 if ( a && a->inherits( "QtxDockAction" ) )
2121 dockMgr = (QtxDockAction*)a;
2127 if ( activeModule() )
2128 modName = activeModule()->name("");
2130 QString section = QString( "windows_geometry" );
2131 if ( !modName.isEmpty() )
2132 section += QString( "." ) + modName;
2134 dockMgr->storeGeometry();
2135 dockMgr->saveGeometry( resourceMgr(), section, false );
2141 void LightApp_Application::activateWindows()
2143 if ( activeStudy() )
2145 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2146 itr.data()->activate( activeStudy()->id() );
2151 Adds icon names for modules
2153 void LightApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
2157 SUIT_ResourceMgr* resMgr = resourceMgr();
2161 QStringList modList;
2162 modules( modList, false );
2164 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
2166 QString modName = *it;
2167 QString modIntr = moduleName( modName );
2168 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
2170 if ( modIcon.isEmpty() )
2173 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
2174 modIcon += QString( ".png" );
2176 iconMap.insert( modName, modIcon );
2181 Inserts items in popup, which necessary for current application
2183 void LightApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
2185 CAM_Application::contextMenuPopup( type, thePopup, title );
2187 OB_Browser* ob = objectBrowser();
2188 if ( !ob || type != ob->popupClientType() )
2191 thePopup->insertSeparator();
2192 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
2198 void LightApp_Application::createEmptyStudy()
2200 CAM_Application::createEmptyStudy();
2201 if ( objectBrowser() )
2202 objectBrowser()->updateTree();
2207 \param mod - module to be activated
2209 bool LightApp_Application::activateModule( CAM_Module* mod )
2211 bool res = CAM_Application::activateModule( mod );
2212 if ( objectBrowser() )
2213 objectBrowser()->updateTree();
2218 \return keyborad accelerators manager object
2220 SUIT_Accel* LightApp_Application::accel() const
2226 Removes dead widget container from map
2228 void LightApp_Application::onWCDestroyed( QObject* ob )
2230 // remove destroyed widget container from windows map
2231 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2233 if ( itr.data() != ob )
2236 int key = itr.key();
2237 myWindows.remove( key );
2243 Connects just added view manager
2245 void LightApp_Application::addViewManager( SUIT_ViewManager* vm )
2247 connect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2248 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2249 STD_Application::addViewManager( vm );
2253 Remove view manager from memory
2255 void LightApp_Application::removeViewManager( SUIT_ViewManager* vm )
2257 disconnect( vm, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
2258 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
2259 STD_Application::removeViewManager( vm );
2264 Renames active window of desktop
2266 void LightApp_Application::onRenameWindow()
2271 QWidget* w = desktop()->activeWindow();
2276 QString name = QInputDialog::getText( tr( "TOT_RENAME" ), tr( "PRP_RENAME" ), QLineEdit::Normal, w->caption(), &ok, w );
2277 if( ok && !name.isEmpty() )
2278 w->setCaption( name );
2282 \return if the library of module exists
2283 \param moduleTitle - title of module
2285 bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
2287 if( moduleTitle.isEmpty() )
2290 QString lib = moduleLibrary( moduleTitle );
2293 paths = QStringList::split( ";", ::getenv( "PATH" ) );
2295 paths = QStringList::split( ":", ::getenv( "LD_LIBRARY_PATH" ) );
2298 QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
2299 for( ; anIt!=aLast; anIt++ )
2301 QFileInfo inf( Qtx::addSlash( *anIt ) + lib );
2309 \return default name for an active study
2311 void LightApp_Application::setDefaultStudyName( const QString& theName )
2313 QStringList anInfoList;
2314 modules( anInfoList, false );
2316 LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
2317 if( anInfoList.count() == 1 && // to avoid a conflict between different modules
2318 !aStudy->isSaved() )
2320 aStudy->setStudyName( theName );
2321 updateDesktopTitle();
2325 /*! slot, called on show/hide of a dock window */
2326 void LightApp_Application::onVisibilityChanged( bool visible )
2328 const QObject* win = sender();
2330 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2331 if ( itr.data() == win )
2333 myWindowsVisible[ itr.key() ] = visible;
2339 Custom event handler
2341 bool LightApp_Application::event( QEvent* e )
2343 if( e && e->type()==2000 )
2345 QCustomEvent* ce = ( QCustomEvent* )e;
2346 QString* d = ( QString* )ce->data();
2347 if( SUIT_MessageBox::warn2(0, tr("WRN_WARNING"),
2349 tr("BUT_OK"), tr("BUT_CANCEL"), 0, 1, 0 )==0 )
2355 return CAM_Application::event( e );