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 for ( ModuleListIterator it = modules(); it.current(); ++it )
488 CAM_DataModel* camDM = it.current()->dataModel();
489 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
490 ((SalomeApp_DataModel*)camDM)->update();
494 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
496 CAM_Application::setActiveStudy( study );
501 //=======================================================================
502 // name : createNewStudy
503 // Purpose : Create new study
504 //=======================================================================
505 SUIT_Study* SalomeApp_Application::createNewStudy()
507 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
509 // Set up processing of major study-related events
510 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
511 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
512 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
513 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
518 //=======================================================================
519 // name : createNewStudy
520 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
521 //=======================================================================
522 void SalomeApp_Application::updateCommandsStatus()
524 CAM_Application::updateCommandsStatus();
526 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
528 QAction* a = action( id );
530 a->setEnabled( activeStudy() );
534 QAction* a = action( LoadScriptId );
536 a->setEnabled( activeStudy() );
538 a = action( PropertiesId );
540 a->setEnabled( activeStudy() );
543 //=======================================================================
544 // name : onHelpAbout
545 // Purpose : SLOT. Display "About" message box
546 //=======================================================================
547 void SalomeApp_Application::onHelpAbout()
549 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
554 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
561 if ( !activeStudy() )
564 sId = activeStudy()->id();
567 if ( myWindows.contains( flag ) )
568 wid = myWindows[flag]->widget( sId );
573 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
581 if ( !activeStudy() )
584 sId = activeStudy()->id();
587 if ( !myWindows.contains( flag ) )
589 QMap<int, int> winMap;
590 currentWindows( winMap );
592 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
593 if ( winMap.contains( flag ) )
594 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
596 myWindows[flag]->setResizeEnabled( true );
597 myWindows[flag]->setCloseMode( QDockWindow::Always );
598 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
601 myWindows[flag]->insert( sId, wid );
603 setWindowShown( flag, !myWindows[flag]->isEmpty() );
606 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
608 if ( !myWindows.contains( flag ) )
614 if ( !activeStudy() )
617 sId = activeStudy()->id();
620 QWidget* wid = myWindows[flag]->widget( sId );
621 myWindows[flag]->remove( sId );
624 setWindowShown( flag, !myWindows[flag]->isEmpty() );
627 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
629 QWidget* wid = window( flag, studyId );
631 addWindow( wid = createWindow( flag ), flag, studyId );
636 bool SalomeApp_Application::isWindowVisible( const int type ) const
639 if ( myWindows.contains( type ) )
641 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
642 res = desk && desk->appropriate( myWindows[type] );
647 void SalomeApp_Application::setWindowShown( const int type, const bool on )
649 if ( !desktop() || !myWindows.contains( type ) )
652 QDockWindow* dw = myWindows[type];
653 desktop()->setAppropriate( dw, on );
654 on ? dw->show() : dw->hide();
657 OB_Browser* SalomeApp_Application::objectBrowser()
660 QWidget* wid = getWindow( WT_ObjectBrowser );
661 if ( wid->inherits( "OB_Browser" ) )
662 ob = (OB_Browser*)wid;
666 LogWindow* SalomeApp_Application::logWindow()
669 QWidget* wid = getWindow( WT_LogWindow );
670 if ( wid->inherits( "LogWindow" ) )
671 lw = (LogWindow*)wid;
675 PythonConsole* SalomeApp_Application::pythonConsole()
677 PythonConsole* console = 0;
678 QWidget* wid = getWindow( WT_PyConsole );
679 if ( wid->inherits( "PythonConsole" ) )
680 console = (PythonConsole*)wid;
684 QtxResourceEdit* SalomeApp_Application::resourceEdit() const
688 QtxResourceEdit* edit = 0;
691 SalomeApp_Application* that = (SalomeApp_Application*)this;
692 that->myPrefDlg = new SalomeApp_PreferencesDlg( that->desktop() );
694 edit = myPrefDlg->resourceEdit();
697 modules( modList, false );
698 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
700 int id = edit->addItem( *it );
701 edit->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
705 edit = myPrefDlg->resourceEdit();
709 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
711 SUIT_ViewManager* aVM = viewManager( vmType );
712 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
714 if ( anActiveVM && anActiveVM->getType() == vmType )
719 if ( !aVM->getActiveView() )
722 aVM->getActiveView()->setFocus();
725 aVM = createViewManager( vmType );
730 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
732 SUIT_ViewManager* viewMgr = 0;
733 if ( vmType == GLViewer_Viewer::Type() )
735 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
736 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
738 else if ( vmType == Plot2d_Viewer::Type() )
740 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
741 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
743 else if ( vmType == OCCViewer_Viewer::Type() )
745 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
746 viewMgr->setViewModel( new SOCC_Viewer() );// custom view model, which extends SALOME_View interface
747 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
749 else if ( vmType == SVTK_Viewer::Type() )
751 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
752 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
758 addViewManager( viewMgr );
759 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
761 if ( viewWin && desktop() )
762 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
764 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
765 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
770 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
772 removeViewManager( theVM );
775 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
777 SUIT_DataObject* aRoot = 0;
778 if ( theStudy && theStudy->root() )
780 aRoot = theStudy->root();
781 //aRoot->setName( tr( "DATA_MODELS" ) );
783 if ( objectBrowser() != 0 )
784 objectBrowser()->setRootObject( aRoot );
786 activateModule( defaultModule() );
791 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
793 SUIT_DataObject* aRoot = 0;
794 if ( theStudy && theStudy->root() )
796 aRoot = theStudy->root();
799 if ( objectBrowser() != 0 ) {
800 objectBrowser()->setRootObject( aRoot );
803 activateModule( defaultModule() );
810 void SalomeApp_Application::onStudySaved( SUIT_Study* )
815 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
819 activateModule( "" );
821 saveWindowsGeometry();
824 void SalomeApp_Application::onLoadScript( )
826 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
827 if ( !appStudy ) return;
828 _PTR(Study) aStudy = appStudy->studyDS();
830 if ( aStudy->GetProperties()->IsLocked() ) {
831 SUIT_MessageBox::warn1 ( desktop(),
832 QObject::tr("WRN_WARNING"),
833 QObject::tr("WRN_STUDY_LOCKED"),
834 QObject::tr("BUT_OK") );
838 QStringList filtersList;
839 filtersList.append(tr("PYTHON_FILES_FILTER"));
840 filtersList.append(tr("ALL_FILES_FILTER"));
842 QString aFile = SUIT_FileDlg::getFileName(desktop(), "", filtersList, tr("TOT_DESK_FILE_LOAD_SCRIPT"), true, true );
843 if(!aFile.isEmpty()) {
844 QString command = QString("execfile(\"%1\")").arg(aFile);
846 PythonConsole* pyConsole = pythonConsole();
849 pyConsole->exec(command);
853 QString SalomeApp_Application::getFileFilter() const
858 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
860 CAM_Application::beforeCloseDoc( s );
862 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
863 removeWindow( itr.key(), s->id() );
866 void SalomeApp_Application::updateActions()
868 updateCommandsStatus();
871 QWidget* SalomeApp_Application::createWindow( const int flag )
875 if ( flag == WT_ObjectBrowser )
877 OB_Browser* ob = new OB_Browser( desktop() );
878 ob->setAutoUpdate( true );
879 ob->setAutoOpenLevel( 1 );
880 ob->setCaption( tr( "OBJECT_BROWSER" ) );
881 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
882 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
884 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
885 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
886 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
889 new SalomeApp_OBSelector( ob, mySelMgr );
893 connect( ob, SIGNAL( aboutRefresh() ), this, SLOT( onAboutRefresh() ) );
894 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
896 else if ( flag == WT_PyConsole )
898 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
899 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
902 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
904 else if ( flag == WT_LogWindow )
906 LogWindow* logWin = new LogWindow( desktop() );
907 logWin->setCaption( tr( "LOG_WINDOW" ) );
910 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
916 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
918 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
919 aMap.insert( WT_PyConsole, Qt::DockBottom );
920 aMap.insert( WT_LogWindow, Qt::DockBottom );
923 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
927 void SalomeApp_Application::afterCloseDoc()
931 CAM_Application::afterCloseDoc();
934 CORBA::ORB_var SalomeApp_Application::orb()
936 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
937 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
941 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
943 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
947 SALOME_NamingService* SalomeApp_Application::namingService()
949 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
953 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
955 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
959 QString SalomeApp_Application::defaultEngineIOR()
961 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
963 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
964 if ( !CORBA::is_nil( anEngine ) )
965 anIOR = orb()->object_to_string( anEngine );
969 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
973 SUIT_ResourceMgr* resMgr = resourceMgr();
978 modules( modList, false );
980 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
982 QString modName = *it;
983 QString modIntr = moduleName( modName );
984 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
986 if ( modIcon.isEmpty() )
989 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
990 modIcon += QString( ".png" );
992 iconMap.insert( modName, modIcon );
996 void SalomeApp_Application::updateModuleActions()
999 if ( activeModule() )
1000 modName = activeModule()->moduleName();
1002 if ( myActions.contains( modName ) )
1003 myActions[modName]->setOn( true );
1006 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1009 if ( !activeStudy() )
1012 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1013 ((SalomeApp_Module*)activeModule())->windows( winMap );
1015 defaultWindows( winMap );
1018 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1021 if ( !activeStudy() )
1024 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1025 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1027 defaultViewManagers( lst );
1030 void SalomeApp_Application::updateWindows()
1032 QMap<int, int> winMap;
1033 currentWindows( winMap );
1035 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1036 getWindow( it.key() );
1038 loadWindowsGeometry();
1040 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1041 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1044 void SalomeApp_Application::updateViewManagers()
1047 currentViewManagers( lst );
1049 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1050 getViewManager( *it, true );
1053 void SalomeApp_Application::loadWindowsGeometry()
1055 QtxDockAction* dockMgr = 0;
1057 QAction* a = action( ViewWindowsId );
1058 if ( a && a->inherits( "QtxDockAction" ) )
1059 dockMgr = (QtxDockAction*)a;
1065 if ( activeModule() )
1066 modName = moduleLibrary( activeModule()->moduleName(), false );
1068 QString section = QString( "windows_geometry" );
1069 if ( !modName.isEmpty() )
1070 section += QString( "." ) + modName;
1072 dockMgr->loadGeometry( resourceMgr(), section, false );
1073 dockMgr->restoreGeometry();
1076 void SalomeApp_Application::saveWindowsGeometry()
1078 QtxDockAction* dockMgr = 0;
1080 QAction* a = action( ViewWindowsId );
1081 if ( a && a->inherits( "QtxDockAction" ) )
1082 dockMgr = (QtxDockAction*)a;
1088 if ( activeModule() )
1089 modName = moduleLibrary( activeModule()->moduleName(), false );
1091 QString section = QString( "windows_geometry" );
1092 if ( !modName.isEmpty() )
1093 section += QString( "." ) + modName;
1095 dockMgr->storeGeometry();
1096 dockMgr->saveGeometry( resourceMgr(), section, false );
1099 void SalomeApp_Application::activateWindows()
1101 if ( activeStudy() )
1103 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1104 itr.data()->activate( activeStudy()->id() );
1108 void SalomeApp_Application::onProperties()
1110 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1114 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1117 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1118 int res = aDlg.exec();
1119 if( res==QDialog::Accepted && aDlg.isChanged() )
1120 SB->CommitCommand();
1124 //study->updateCaptions();
1127 QString SalomeApp_Application::getFileName( bool open )
1129 QStringList filtersList;
1130 filtersList.append( getFileFilter() );
1131 QString initial = open ? QString( "" ) : ( activeStudy() ? activeStudy()->studyName() : QString( "" ) );
1132 return SUIT_FileDlg::getFileName( desktop(), initial, filtersList, QString::null, open, true );