1 // File: SalomeApp_Application.cxx
2 // Created: 10/22/2004 3:23:45 PM
3 // Author: Sergey LITONIN
4 // Copyright (C) CEA 2004
6 #include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
8 #include "SalomeApp_Application.h"
10 #include "SalomeApp_Study.h"
11 #include "SalomeApp_Module.h"
12 #include "SalomeApp_OBFilter.h"
13 #include "SalomeApp_DataModel.h"
14 #include "SalomeApp_DataObject.h"
15 #include "SalomeApp_EventFilter.h"
16 #include "SalomeApp_WidgetContainer.h"
18 #include "SalomeApp_AboutDlg.h"
19 #include "SalomeApp_ModuleDlg.h"
20 #include "SalomeApp_PreferencesDlg.h"
21 #include "SalomeApp_StudyPropertiesDlg.h"
23 #include "SalomeApp_GLSelector.h"
24 #include "SalomeApp_OBSelector.h"
25 #include "SalomeApp_OCCSelector.h"
26 #include "SalomeApp_VTKSelector.h"
27 #include "SalomeApp_SelectionMgr.h"
29 #include <LogWindow.h>
31 #include <GLViewer_Viewer.h>
32 #include <GLViewer_ViewManager.h>
34 #include <Plot2d_ViewManager.h>
35 #include <SPlot2d_ViewModel.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <SOCC_ViewModel.h>
40 #include <SVTK_ViewModel.h>
41 #include <SVTK_ViewManager.h>
43 #include <STD_TabDesktop.h>
45 #include <SUIT_Tools.h>
46 #include <SUIT_Session.h>
48 #include <QtxToolBar.h>
49 #include <QtxDockAction.h>
51 #include <OB_Browser.h>
53 #include <PythonConsole_PyConsole.h>
55 #include <SUIT_FileDlg.h>
56 #include <SUIT_MessageBox.h>
57 #include <SUIT_ResourceMgr.h>
58 #include <SUIT_ActionOperation.h>
60 #include <Utils_ORB_INIT.hxx>
61 #include <Utils_SINGLETON.hxx>
62 #include <SALOME_ModuleCatalog_impl.hxx>
63 #include <SALOME_LifeCycleCORBA.hxx>
71 #include <qcombobox.h>
72 #include <qmessagebox.h>
73 #include <qapplication.h>
75 #include "SALOMEDS_StudyManager.hxx"
77 #define OBJECT_BROWSER_WIDTH 300
79 static const char* imageEmptyIcon[] = {
82 "....................",
83 "....................",
84 "....................",
85 "....................",
86 "....................",
87 "....................",
88 "....................",
89 "....................",
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "...................."};
103 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
105 return new SalomeApp_Application();
109 Class : SalomeApp_Application
110 Description : Application containing SalomeApp module
113 SalomeApp_Application::SalomeApp_Application()
114 : CAM_Application( false ),
117 STD_TabDesktop* desk = new STD_TabDesktop();
121 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
122 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
124 desktop()->setIcon( aLogo );
125 desktop()->setDockableMenuBar( true );
126 desktop()->setDockableStatusBar( false );
130 mySelMgr = new SalomeApp_SelectionMgr( this );
132 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
133 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
135 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
138 SalomeApp_Application::~SalomeApp_Application()
140 saveWindowsGeometry();
145 desktop()->saveGeometry( resourceMgr(), "desktop" );
146 resourceMgr()->save();
151 SalomeApp_EventFilter::Destroy();
154 void SalomeApp_Application::start()
157 desktop()->loadGeometry( resourceMgr(), "desktop" );
159 CAM_Application::start();
161 QAction* a = action( ViewWindowsId );
162 if ( a && a->inherits( "QtxDockAction" ) )
163 ((QtxDockAction*)a)->setAutoPlace( true );
165 SalomeApp_EventFilter::Init();
168 updateViewManagers();
173 QString SalomeApp_Application::applicationName() const
175 return tr( "APP_NAME" );
178 QString SalomeApp_Application::applicationVersion() const
180 static QString _app_version;
182 if ( _app_version.isEmpty() )
184 QString path( ::getenv( "GUI_ROOT_DIR" ) );
185 if ( !path.isEmpty() )
186 path += QDir::separator();
187 path += QString( "bin/salome/VERSION" );
190 if ( vf.open( IO_ReadOnly ) )
193 vf.readLine( line, 1024 );
196 if ( !line.isEmpty() )
198 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
199 line.remove( line.length() - 1, 1 );
201 int idx = line.findRev( ":" );
203 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
211 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
213 CAM_Module* mod = CAM_Application::loadModule( name );
216 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
217 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
218 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
223 bool SalomeApp_Application::activateModule( const QString& modName )
226 CAM_Module* prevMod = activeModule();
229 actName = prevMod->moduleName();
231 if ( actName == modName )
234 saveWindowsGeometry();
236 bool status = CAM_Application::activateModule( modName );
238 updateModuleActions();
244 updateViewManagers();
249 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
254 void SalomeApp_Application::createActions()
256 STD_Application::createActions();
258 SUIT_Desktop* desk = desktop();
259 SUIT_ResourceMgr* resMgr = resourceMgr();
262 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
263 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
264 0, desk, false, this, SLOT( onLoadScript() ) );
265 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
266 createMenu( LoadScriptId, fileMenu, 10, -1 );
268 createAction( PropertiesId, tr( "TOT_DESK_FILE_PROPERTIES" ), QIconSet(),
269 tr( "MEN_DESK_FILE_PROPERTIES" ), tr( "PRP_DESK_FILE_PROPERTIES" ),
270 0, desk, false, this, SLOT( onProperties() ) );
271 createMenu( PropertiesId, fileMenu, 10, -1 );
274 // default icon for neutral point ('SALOME' module)
275 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
276 if ( defIcon.isNull() )
277 defIcon = QPixmap( imageEmptyIcon );
279 // default icon for any module
280 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
281 if ( modIcon.isNull() )
282 modIcon = QPixmap( imageEmptyIcon );
284 QToolBar* modTBar = new QtxToolBar( true, desk );
285 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
287 QActionGroup* modGroup = new QActionGroup( this );
288 modGroup->setExclusive( true );
289 modGroup->setUsesDropDown( true );
291 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
292 tr( "PRP_APP_MODULE" ), 0, desk, true );
294 myActions.insert( QString(), a );
296 QMap<QString, QString> iconMap;
297 moduleIconNames( iconMap );
299 const int iconSize = 20;
301 modGroup->addTo( modTBar );
302 modTBar->addSeparator();
305 modules( modList, false );
307 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
309 if ( (*it).isEmpty() )
313 if ( iconMap.contains( *it ) )
314 iconName = iconMap[*it];
316 QString modName = moduleName( *it );
318 QPixmap icon = resMgr->loadPixmap( modName, iconName );
322 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
324 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
328 myActions.insert( *it, a );
331 SUIT_Tools::simplifySeparators( modTBar );
335 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
336 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
337 createMenu( separator(), windowMenu, -1, 1 );
339 QMap<int, int> accelMap;
340 accelMap[NewGLViewId] = ALT+Key_G;
341 accelMap[NewPlot2dId] = ALT+Key_P;
342 accelMap[NewOCCViewId] = ALT+Key_O;
343 accelMap[NewVTKViewId] = ALT+Key_K;
345 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
347 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
348 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
349 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
350 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
351 createMenu( a, newWinMenu, -1 );
354 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
357 void SalomeApp_Application::onModuleActivation( QAction* a )
362 QString modName = a->menuText();
363 if ( modName == tr( "APP_NAME" ) )
364 modName = QString::null;
366 // Force user to create/open a study before module activation
367 QMap<QString, QString> iconMap;
368 moduleIconNames( iconMap );
369 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
371 bool cancelled = false;
372 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
373 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
374 int res = aDlg.exec();
388 putInfo( tr("INF_CANCELLED") );
389 myActions[QString()]->setOn( true );
395 activateModule( modName );
398 QString SalomeApp_Application::defaultModule() const
400 QStringList aModuleNames;
401 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
402 // If there's the one and only module --> activate it automatically
403 // TODO: Possible improvement - default module can be taken from preferences
404 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
407 void SalomeApp_Application::onNewWindow()
409 const QObject* obj = sender();
410 if ( !obj || !obj->inherits( "QAction" ) )
414 int id = actionId( (QAction*)obj );
418 type = GLViewer_Viewer::Type();
421 type = Plot2d_Viewer::Type();
424 type = OCCViewer_Viewer::Type();
427 type = VTKViewer_Viewer::Type();
431 if ( !type.isEmpty() )
432 createViewManager( type );
435 //=======================================================================
437 // Purpose : SLOT. Create new document
438 //=======================================================================
439 void SalomeApp_Application::onNewDoc()
441 SUIT_Study* study = activeStudy();
443 saveWindowsGeometry();
445 CAM_Application::onNewDoc();
447 if ( !study ) // new study will be create in THIS application
450 updateViewManagers();
454 //=======================================================================
456 // Purpose : SLOT. Open new document
457 //=======================================================================
458 void SalomeApp_Application::onOpenDoc()
460 SUIT_Study* study = activeStudy();
461 saveWindowsGeometry();
463 CAM_Application::onOpenDoc();
465 if ( !study ) // new study will be create in THIS application
468 updateViewManagers();
472 void SalomeApp_Application::onSelection()
474 onSelectionChanged();
476 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
477 ((SalomeApp_Module*)activeModule())->selectionChanged();
480 void SalomeApp_Application::onSelectionChanged()
484 void SalomeApp_Application::onAboutRefresh()
486 SalomeApp_DataModel* dm = 0;
487 if ( activeModule() )
489 CAM_DataModel* camDM = activeModule()->dataModel();
490 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
491 dm = (SalomeApp_DataModel*)camDM;
498 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
500 CAM_Application::setActiveStudy( study );
505 //=======================================================================
506 // name : createNewStudy
507 // Purpose : Create new study
508 //=======================================================================
509 SUIT_Study* SalomeApp_Application::createNewStudy()
511 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
513 // Set up processing of major study-related events
514 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
515 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
516 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
517 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
522 //=======================================================================
523 // name : createNewStudy
524 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
525 //=======================================================================
526 void SalomeApp_Application::updateCommandsStatus()
528 CAM_Application::updateCommandsStatus();
530 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
532 QAction* a = action( id );
534 a->setEnabled( activeStudy() );
538 QAction* a = action( LoadScriptId );
540 a->setEnabled( activeStudy() );
542 a = action( PropertiesId );
544 a->setEnabled( activeStudy() );
547 //=======================================================================
548 // name : onHelpAbout
549 // Purpose : SLOT. Display "About" message box
550 //=======================================================================
551 void SalomeApp_Application::onHelpAbout()
553 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
558 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
565 if ( !activeStudy() )
568 sId = activeStudy()->id();
571 if ( myWindows.contains( flag ) )
572 wid = myWindows[flag]->widget( sId );
577 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
585 if ( !activeStudy() )
588 sId = activeStudy()->id();
591 if ( !myWindows.contains( flag ) )
593 QMap<int, int> winMap;
594 currentWindows( winMap );
596 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
597 if ( winMap.contains( flag ) )
598 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
600 myWindows[flag]->setResizeEnabled( true );
601 myWindows[flag]->setCloseMode( QDockWindow::Always );
602 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
605 myWindows[flag]->insert( sId, wid );
607 setWindowShown( flag, !myWindows[flag]->isEmpty() );
610 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
612 if ( !myWindows.contains( flag ) )
618 if ( !activeStudy() )
621 sId = activeStudy()->id();
624 QWidget* wid = myWindows[flag]->widget( sId );
625 myWindows[flag]->remove( sId );
628 setWindowShown( flag, !myWindows[flag]->isEmpty() );
631 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
633 QWidget* wid = window( flag, studyId );
635 addWindow( wid = createWindow( flag ), flag, studyId );
640 bool SalomeApp_Application::isWindowVisible( const int type ) const
643 if ( myWindows.contains( type ) )
645 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
646 res = desk && desk->appropriate( myWindows[type] );
651 void SalomeApp_Application::setWindowShown( const int type, const bool on )
653 if ( !desktop() || !myWindows.contains( type ) )
656 QDockWindow* dw = myWindows[type];
657 desktop()->setAppropriate( dw, on );
658 on ? dw->show() : dw->hide();
661 OB_Browser* SalomeApp_Application::objectBrowser()
664 QWidget* wid = getWindow( WT_ObjectBrowser );
665 if ( wid->inherits( "OB_Browser" ) )
666 ob = (OB_Browser*)wid;
670 LogWindow* SalomeApp_Application::logWindow()
673 QWidget* wid = getWindow( WT_LogWindow );
674 if ( wid->inherits( "LogWindow" ) )
675 lw = (LogWindow*)wid;
679 PythonConsole* SalomeApp_Application::pythonConsole()
681 PythonConsole* console = 0;
682 QWidget* wid = getWindow( WT_PyConsole );
683 if ( wid->inherits( "PythonConsole" ) )
684 console = (PythonConsole*)wid;
688 QtxResourceEdit* SalomeApp_Application::resourceEdit() const
692 QtxResourceEdit* edit = 0;
695 SalomeApp_Application* that = (SalomeApp_Application*)this;
696 that->myPrefDlg = new SalomeApp_PreferencesDlg( that->desktop() );
698 edit = myPrefDlg->resourceEdit();
701 modules( modList, false );
702 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
704 int id = edit->addItem( *it );
705 edit->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
709 edit = myPrefDlg->resourceEdit();
713 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
715 SUIT_ViewManager* aVM = viewManager( vmType );
716 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
718 if ( anActiveVM && anActiveVM->getType() == vmType )
723 if ( !aVM->getActiveView() )
726 aVM->getActiveView()->setFocus();
729 aVM = createViewManager( vmType );
734 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
736 SUIT_ViewManager* viewMgr = 0;
737 if ( vmType == GLViewer_Viewer::Type() )
739 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
740 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
742 else if ( vmType == Plot2d_Viewer::Type() )
744 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
745 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
747 else if ( vmType == OCCViewer_Viewer::Type() )
749 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
750 viewMgr->setViewModel( new SOCC_Viewer() );// custom view model, which extends SALOME_View interface
751 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
753 else if ( vmType == SVTK_Viewer::Type() )
755 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
756 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
762 addViewManager( viewMgr );
763 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
765 if ( viewWin && desktop() )
766 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
768 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
769 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
774 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
776 removeViewManager( theVM );
779 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
781 SUIT_DataObject* aRoot = 0;
782 if ( theStudy && theStudy->root() )
784 aRoot = theStudy->root();
785 //aRoot->setName( tr( "DATA_MODELS" ) );
787 if ( objectBrowser() != 0 )
788 objectBrowser()->setRootObject( aRoot );
790 activateModule( defaultModule() );
795 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
797 SUIT_DataObject* aRoot = 0;
798 if ( theStudy && theStudy->root() )
800 aRoot = theStudy->root();
803 if ( objectBrowser() != 0 ) {
804 objectBrowser()->setRootObject( aRoot );
807 activateModule( defaultModule() );
814 void SalomeApp_Application::onStudySaved( SUIT_Study* )
819 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
823 activateModule( "" );
825 saveWindowsGeometry();
828 void SalomeApp_Application::onLoadScript( )
830 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
831 if ( !appStudy ) return;
832 _PTR(Study) aStudy = appStudy->studyDS();
834 if ( aStudy->GetProperties()->IsLocked() ) {
835 SUIT_MessageBox::warn1 ( desktop(),
836 QObject::tr("WRN_WARNING"),
837 QObject::tr("WRN_STUDY_LOCKED"),
838 QObject::tr("BUT_OK") );
842 QStringList filtersList;
843 filtersList.append(tr("PYTHON_FILES_FILTER"));
844 filtersList.append(tr("ALL_FILES_FILTER"));
846 QString aFile = SUIT_FileDlg::getFileName(desktop(), "", filtersList, tr("TOT_DESK_FILE_LOAD_SCRIPT"), true, false);
847 if(!aFile.isEmpty()) {
848 QString command = QString("execfile(\"%1\")").arg(aFile);
850 PythonConsole* pyConsole = pythonConsole();
853 pyConsole->exec(command);
857 QString SalomeApp_Application::getFileFilter() const
862 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
864 CAM_Application::beforeCloseDoc( s );
866 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
867 removeWindow( itr.key(), s->id() );
870 void SalomeApp_Application::updateActions()
872 updateCommandsStatus();
875 QWidget* SalomeApp_Application::createWindow( const int flag )
879 if ( flag == WT_ObjectBrowser )
881 OB_Browser* ob = new OB_Browser( desktop() );
882 ob->setAutoUpdate( true );
883 ob->setAutoOpenLevel( 1 );
884 ob->setCaption( tr( "OBJECT_BROWSER" ) );
885 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
886 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
888 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
889 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
890 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
893 new SalomeApp_OBSelector( ob, mySelMgr );
897 connect( ob, SIGNAL( aboutRefresh() ), this, SLOT( onAboutRefresh() ) );
898 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
900 else if ( flag == WT_PyConsole )
902 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
903 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
906 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
908 else if ( flag == WT_LogWindow )
910 LogWindow* logWin = new LogWindow( desktop() );
911 logWin->setCaption( tr( "LOG_WINDOW" ) );
914 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
920 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
922 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
923 aMap.insert( WT_PyConsole, Qt::DockBottom );
924 aMap.insert( WT_LogWindow, Qt::DockBottom );
927 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
931 void SalomeApp_Application::afterCloseDoc()
935 CAM_Application::afterCloseDoc();
938 CORBA::ORB_var SalomeApp_Application::orb()
940 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
941 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
945 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
947 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
951 SALOME_NamingService* SalomeApp_Application::namingService()
953 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
957 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
959 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
963 QString SalomeApp_Application::defaultEngineIOR()
965 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
967 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
968 if ( !CORBA::is_nil( anEngine ) )
969 anIOR = orb()->object_to_string( anEngine );
973 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
977 SUIT_ResourceMgr* resMgr = resourceMgr();
982 modules( modList, false );
984 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
986 QString modName = *it;
987 QString modIntr = moduleName( modName );
988 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
990 if ( modIcon.isEmpty() )
993 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
994 modIcon += QString( ".png" );
996 iconMap.insert( modName, modIcon );
1000 void SalomeApp_Application::updateModuleActions()
1003 if ( activeModule() )
1004 modName = activeModule()->moduleName();
1006 if ( myActions.contains( modName ) )
1007 myActions[modName]->setOn( true );
1010 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1013 if ( !activeStudy() )
1016 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1017 ((SalomeApp_Module*)activeModule())->windows( winMap );
1019 defaultWindows( winMap );
1022 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1025 if ( !activeStudy() )
1028 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1029 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1031 defaultViewManagers( lst );
1034 void SalomeApp_Application::updateWindows()
1036 QMap<int, int> winMap;
1037 currentWindows( winMap );
1039 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1040 getWindow( it.key() );
1042 loadWindowsGeometry();
1044 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1045 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1048 void SalomeApp_Application::updateViewManagers()
1051 currentViewManagers( lst );
1053 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1054 getViewManager( *it, true );
1057 void SalomeApp_Application::loadWindowsGeometry()
1059 QtxDockAction* dockMgr = 0;
1061 QAction* a = action( ViewWindowsId );
1062 if ( a && a->inherits( "QtxDockAction" ) )
1063 dockMgr = (QtxDockAction*)a;
1069 if ( activeModule() )
1070 modName = moduleLibrary( activeModule()->moduleName(), false );
1072 QString section = QString( "windows_geometry" );
1073 if ( !modName.isEmpty() )
1074 section += QString( "." ) + modName;
1076 dockMgr->loadGeometry( resourceMgr(), section, false );
1077 dockMgr->restoreGeometry();
1080 void SalomeApp_Application::saveWindowsGeometry()
1082 QtxDockAction* dockMgr = 0;
1084 QAction* a = action( ViewWindowsId );
1085 if ( a && a->inherits( "QtxDockAction" ) )
1086 dockMgr = (QtxDockAction*)a;
1092 if ( activeModule() )
1093 modName = moduleLibrary( activeModule()->moduleName(), false );
1095 QString section = QString( "windows_geometry" );
1096 if ( !modName.isEmpty() )
1097 section += QString( "." ) + modName;
1099 dockMgr->storeGeometry();
1100 dockMgr->saveGeometry( resourceMgr(), section, false );
1103 void SalomeApp_Application::activateWindows()
1105 if ( activeStudy() )
1107 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1108 itr.data()->activate( activeStudy()->id() );
1112 void SalomeApp_Application::onProperties()
1114 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1118 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1121 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1122 int res = aDlg.exec();
1123 if( res==QDialog::Accepted && aDlg.isChanged() )
1124 SB->CommitCommand();
1128 //study->updateCaptions();