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 #include "SALOME_ListIteratorOfListIO.hxx"
78 #include "SALOME_ListIO.hxx"
80 #define OBJECT_BROWSER_WIDTH 300
82 static const char* imageEmptyIcon[] = {
85 "....................",
86 "....................",
87 "....................",
88 "....................",
89 "....................",
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "...................."};
106 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
108 return new SalomeApp_Application();
112 Class : SalomeApp_Application
113 Description : Application containing SalomeApp module
116 SalomeApp_Application::SalomeApp_Application()
117 : CAM_Application( false ),
120 STD_TabDesktop* desk = new STD_TabDesktop();
124 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
125 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
127 desktop()->setIcon( aLogo );
128 desktop()->setDockableMenuBar( true );
129 desktop()->setDockableStatusBar( false );
133 mySelMgr = new SalomeApp_SelectionMgr( this );
135 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
136 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
138 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
141 SalomeApp_Application::~SalomeApp_Application()
143 saveWindowsGeometry();
148 desktop()->saveGeometry( resourceMgr(), "desktop" );
149 resourceMgr()->save();
154 SalomeApp_EventFilter::Destroy();
157 void SalomeApp_Application::start()
160 desktop()->loadGeometry( resourceMgr(), "desktop" );
162 CAM_Application::start();
164 QAction* a = action( ViewWindowsId );
165 if ( a && a->inherits( "QtxDockAction" ) )
166 ((QtxDockAction*)a)->setAutoPlace( true );
168 SalomeApp_EventFilter::Init();
171 updateViewManagers();
176 QString SalomeApp_Application::applicationName() const
178 return tr( "APP_NAME" );
181 QString SalomeApp_Application::applicationVersion() const
183 static QString _app_version;
185 if ( _app_version.isEmpty() )
187 QString path( ::getenv( "GUI_ROOT_DIR" ) );
188 if ( !path.isEmpty() )
189 path += QDir::separator();
190 path += QString( "bin/salome/VERSION" );
193 if ( vf.open( IO_ReadOnly ) )
196 vf.readLine( line, 1024 );
199 if ( !line.isEmpty() )
201 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
202 line.remove( line.length() - 1, 1 );
204 int idx = line.findRev( ":" );
206 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
214 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
216 CAM_Module* mod = CAM_Application::loadModule( name );
219 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
220 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
221 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
226 bool SalomeApp_Application::activateModule( const QString& modName )
229 CAM_Module* prevMod = activeModule();
232 actName = prevMod->moduleName();
234 if ( actName == modName )
237 saveWindowsGeometry();
239 bool status = CAM_Application::activateModule( modName );
241 updateModuleActions();
247 updateViewManagers();
252 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
257 void SalomeApp_Application::createActions()
259 STD_Application::createActions();
261 SUIT_Desktop* desk = desktop();
262 SUIT_ResourceMgr* resMgr = resourceMgr();
265 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
266 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
267 0, desk, false, this, SLOT( onLoadScript() ) );
268 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
269 createMenu( LoadScriptId, fileMenu, 10, -1 );
271 createAction( PropertiesId, tr( "TOT_DESK_FILE_PROPERTIES" ), QIconSet(),
272 tr( "MEN_DESK_FILE_PROPERTIES" ), tr( "PRP_DESK_FILE_PROPERTIES" ),
273 0, desk, false, this, SLOT( onProperties() ) );
274 createMenu( PropertiesId, fileMenu, 10, -1 );
277 // default icon for neutral point ('SALOME' module)
278 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
279 if ( defIcon.isNull() )
280 defIcon = QPixmap( imageEmptyIcon );
282 // default icon for any module
283 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
284 if ( modIcon.isNull() )
285 modIcon = QPixmap( imageEmptyIcon );
287 QToolBar* modTBar = new QtxToolBar( true, desk );
288 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
290 QActionGroup* modGroup = new QActionGroup( this );
291 modGroup->setExclusive( true );
292 modGroup->setUsesDropDown( true );
294 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
295 tr( "PRP_APP_MODULE" ), 0, desk, true );
297 myActions.insert( QString(), a );
299 QMap<QString, QString> iconMap;
300 moduleIconNames( iconMap );
302 const int iconSize = 20;
304 modGroup->addTo( modTBar );
305 modTBar->addSeparator();
308 modules( modList, false );
310 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
312 if ( (*it).isEmpty() )
316 if ( iconMap.contains( *it ) )
317 iconName = iconMap[*it];
319 QString modName = moduleName( *it );
321 QPixmap icon = resMgr->loadPixmap( modName, iconName );
325 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
327 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
331 myActions.insert( *it, a );
334 SUIT_Tools::simplifySeparators( modTBar );
338 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
339 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
340 createMenu( separator(), windowMenu, -1, 1 );
342 QMap<int, int> accelMap;
343 accelMap[NewGLViewId] = ALT+Key_G;
344 accelMap[NewPlot2dId] = ALT+Key_P;
345 accelMap[NewOCCViewId] = ALT+Key_O;
346 accelMap[NewVTKViewId] = ALT+Key_K;
348 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
350 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
351 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
352 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
353 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
354 createMenu( a, newWinMenu, -1 );
357 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
360 void SalomeApp_Application::onModuleActivation( QAction* a )
365 QString modName = a->menuText();
366 if ( modName == tr( "APP_NAME" ) )
367 modName = QString::null;
369 // Force user to create/open a study before module activation
370 QMap<QString, QString> iconMap;
371 moduleIconNames( iconMap );
372 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
374 bool cancelled = false;
375 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
376 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
377 int res = aDlg.exec();
391 putInfo( tr("INF_CANCELLED") );
392 myActions[QString()]->setOn( true );
398 activateModule( modName );
401 QString SalomeApp_Application::defaultModule() const
403 QStringList aModuleNames;
404 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
405 // If there's the one and only module --> activate it automatically
406 // TODO: Possible improvement - default module can be taken from preferences
407 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
410 void SalomeApp_Application::onNewWindow()
412 const QObject* obj = sender();
413 if ( !obj || !obj->inherits( "QAction" ) )
417 int id = actionId( (QAction*)obj );
421 type = GLViewer_Viewer::Type();
424 type = Plot2d_Viewer::Type();
427 type = OCCViewer_Viewer::Type();
430 type = VTKViewer_Viewer::Type();
434 if ( !type.isEmpty() )
435 createViewManager( type );
438 //=======================================================================
440 // Purpose : SLOT. Create new document
441 //=======================================================================
442 void SalomeApp_Application::onNewDoc()
444 SUIT_Study* study = activeStudy();
446 saveWindowsGeometry();
448 CAM_Application::onNewDoc();
450 if ( !study ) // new study will be create in THIS application
453 updateViewManagers();
457 //=======================================================================
459 // Purpose : SLOT. Open new document
460 //=======================================================================
461 void SalomeApp_Application::onOpenDoc()
463 SUIT_Study* study = activeStudy();
464 saveWindowsGeometry();
466 CAM_Application::onOpenDoc();
468 if ( !study ) // new study will be create in THIS application
471 updateViewManagers();
475 void SalomeApp_Application::onSelection()
477 onSelectionChanged();
479 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
480 ((SalomeApp_Module*)activeModule())->selectionChanged();
483 void SalomeApp_Application::onSelectionChanged()
486 SalomeApp_Module* module = dynamic_cast<SalomeApp_Module*>(activeModule());
487 if(module == NULL) return;
489 QString ior = module->engineIOR();
490 if(ior.length() < 5) return; //Not a real CORBA IOR
491 CORBA::Object_var obj = orb()->string_to_object(ior.latin1());
492 if(CORBA::is_nil(obj)) return;
494 SALOMEDS::Driver_var engine = SALOMEDS::Driver::_narrow(obj);
495 if(CORBA::is_nil(engine)) return;
499 SalomeApp_SelectionMgr* mgr = selectionMgr();
500 mgr->selectedObjects(list);
502 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
503 if(study == NULL) return;
505 _PTR(Study) stdDS = study->studyDS();
510 for ( SALOME_ListIteratorOfListIO it( list ); it.More(); it.Next() )
512 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
513 qaction = action(EditCutId);
514 if( studyMgr()->CanCopy(so) ) {
515 qaction->setEnabled(true);
516 qaction = action(EditCopyId);
517 qaction->setEnabled(true);
520 qaction->setEnabled(false);
521 qaction = action(EditCopyId);
522 qaction->setEnabled(false);
524 qaction = action(EditPasteId);
525 if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
526 else qaction->setEnabled(false);
531 void SalomeApp_Application::onRefresh()
533 for ( ModuleListIterator it = modules(); it.current(); ++it )
535 CAM_DataModel* camDM = it.current()->dataModel();
536 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
537 ((SalomeApp_DataModel*)camDM)->update();
539 objectBrowser()->updateTree();
542 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
544 CAM_Application::setActiveStudy( study );
549 //=======================================================================
550 // name : createNewStudy
551 // Purpose : Create new study
552 //=======================================================================
553 SUIT_Study* SalomeApp_Application::createNewStudy()
555 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
557 // Set up processing of major study-related events
558 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
559 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
560 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
561 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
566 //=======================================================================
567 // name : createNewStudy
568 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
569 //=======================================================================
570 void SalomeApp_Application::updateCommandsStatus()
572 CAM_Application::updateCommandsStatus();
574 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
576 QAction* a = action( id );
578 a->setEnabled( activeStudy() );
582 QAction* a = action( LoadScriptId );
584 a->setEnabled( activeStudy() );
586 a = action( PropertiesId );
588 a->setEnabled( activeStudy() );
590 a = action(EditCutId);
591 a->setEnabled(false);
592 a = action(EditCopyId);
593 a->setEnabled(false);
594 a = action(EditPasteId);
595 a->setEnabled(false);
598 //=======================================================================
599 // name : onHelpAbout
600 // Purpose : SLOT. Display "About" message box
601 //=======================================================================
602 void SalomeApp_Application::onHelpAbout()
604 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
609 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
616 if ( !activeStudy() )
619 sId = activeStudy()->id();
622 if ( myWindows.contains( flag ) )
623 wid = myWindows[flag]->widget( sId );
628 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
636 if ( !activeStudy() )
639 sId = activeStudy()->id();
642 if ( !myWindows.contains( flag ) )
644 QMap<int, int> winMap;
645 currentWindows( winMap );
647 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
648 if ( winMap.contains( flag ) )
649 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
651 myWindows[flag]->setResizeEnabled( true );
652 myWindows[flag]->setCloseMode( QDockWindow::Always );
653 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
656 myWindows[flag]->insert( sId, wid );
658 setWindowShown( flag, !myWindows[flag]->isEmpty() );
661 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
663 if ( !myWindows.contains( flag ) )
669 if ( !activeStudy() )
672 sId = activeStudy()->id();
675 QWidget* wid = myWindows[flag]->widget( sId );
676 myWindows[flag]->remove( sId );
679 setWindowShown( flag, !myWindows[flag]->isEmpty() );
682 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
684 QWidget* wid = window( flag, studyId );
686 addWindow( wid = createWindow( flag ), flag, studyId );
691 bool SalomeApp_Application::isWindowVisible( const int type ) const
694 if ( myWindows.contains( type ) )
696 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
697 res = desk && desk->appropriate( myWindows[type] );
702 void SalomeApp_Application::setWindowShown( const int type, const bool on )
704 if ( !desktop() || !myWindows.contains( type ) )
707 QDockWindow* dw = myWindows[type];
708 desktop()->setAppropriate( dw, on );
709 on ? dw->show() : dw->hide();
712 OB_Browser* SalomeApp_Application::objectBrowser()
715 QWidget* wid = getWindow( WT_ObjectBrowser );
716 if ( wid->inherits( "OB_Browser" ) )
717 ob = (OB_Browser*)wid;
721 LogWindow* SalomeApp_Application::logWindow()
724 QWidget* wid = getWindow( WT_LogWindow );
725 if ( wid->inherits( "LogWindow" ) )
726 lw = (LogWindow*)wid;
730 PythonConsole* SalomeApp_Application::pythonConsole()
732 PythonConsole* console = 0;
733 QWidget* wid = getWindow( WT_PyConsole );
734 if ( wid->inherits( "PythonConsole" ) )
735 console = (PythonConsole*)wid;
739 QtxResourceEdit* SalomeApp_Application::resourceEdit() const
743 QtxResourceEdit* edit = 0;
746 SalomeApp_Application* that = (SalomeApp_Application*)this;
747 that->myPrefDlg = new SalomeApp_PreferencesDlg( that->desktop() );
749 edit = myPrefDlg->resourceEdit();
752 modules( modList, false );
753 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
755 int id = edit->addItem( *it );
756 edit->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
760 edit = myPrefDlg->resourceEdit();
764 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
766 SUIT_ViewManager* aVM = viewManager( vmType );
767 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
769 if ( anActiveVM && anActiveVM->getType() == vmType )
774 if ( !aVM->getActiveView() )
777 aVM->getActiveView()->setFocus();
780 aVM = createViewManager( vmType );
785 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
787 SUIT_ViewManager* viewMgr = 0;
788 if ( vmType == GLViewer_Viewer::Type() )
790 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
791 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
793 else if ( vmType == Plot2d_Viewer::Type() )
795 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
796 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
798 else if ( vmType == OCCViewer_Viewer::Type() )
800 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
801 viewMgr->setViewModel( new SOCC_Viewer() );// custom view model, which extends SALOME_View interface
802 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
804 else if ( vmType == SVTK_Viewer::Type() )
806 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
807 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
813 addViewManager( viewMgr );
814 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
816 if ( viewWin && desktop() )
817 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
819 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
820 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
825 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
827 removeViewManager( theVM );
830 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
832 SUIT_DataObject* aRoot = 0;
833 if ( theStudy && theStudy->root() )
835 aRoot = theStudy->root();
836 //aRoot->setName( tr( "DATA_MODELS" ) );
838 if ( objectBrowser() != 0 )
839 objectBrowser()->setRootObject( aRoot );
841 activateModule( defaultModule() );
846 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
848 SUIT_DataObject* aRoot = 0;
849 if ( theStudy && theStudy->root() )
851 aRoot = theStudy->root();
854 if ( objectBrowser() != 0 ) {
855 objectBrowser()->setRootObject( aRoot );
858 activateModule( defaultModule() );
865 void SalomeApp_Application::onStudySaved( SUIT_Study* )
870 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
874 activateModule( "" );
876 saveWindowsGeometry();
879 void SalomeApp_Application::onLoadScript( )
881 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
882 if ( !appStudy ) return;
883 _PTR(Study) aStudy = appStudy->studyDS();
885 if ( aStudy->GetProperties()->IsLocked() ) {
886 SUIT_MessageBox::warn1 ( desktop(),
887 QObject::tr("WRN_WARNING"),
888 QObject::tr("WRN_STUDY_LOCKED"),
889 QObject::tr("BUT_OK") );
893 QStringList filtersList;
894 filtersList.append(tr("PYTHON_FILES_FILTER"));
895 filtersList.append(tr("ALL_FILES_FILTER"));
897 QString aFile = SUIT_FileDlg::getFileName(desktop(), "", filtersList, tr("TOT_DESK_FILE_LOAD_SCRIPT"), true, true );
898 if(!aFile.isEmpty()) {
899 QString command = QString("execfile(\"%1\")").arg(aFile);
901 PythonConsole* pyConsole = pythonConsole();
904 pyConsole->exec(command);
908 QString SalomeApp_Application::getFileFilter() const
913 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
915 CAM_Application::beforeCloseDoc( s );
917 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
918 removeWindow( itr.key(), s->id() );
921 void SalomeApp_Application::updateActions()
923 updateCommandsStatus();
926 QWidget* SalomeApp_Application::createWindow( const int flag )
930 if ( flag == WT_ObjectBrowser )
932 OB_Browser* ob = new OB_Browser( desktop() );
933 ob->setAutoUpdate( true );
934 ob->setAutoOpenLevel( 1 );
935 ob->setCaption( tr( "OBJECT_BROWSER" ) );
936 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
937 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
939 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
940 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
941 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
944 new SalomeApp_OBSelector( ob, mySelMgr );
948 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
950 else if ( flag == WT_PyConsole )
952 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
953 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
956 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
958 else if ( flag == WT_LogWindow )
960 LogWindow* logWin = new LogWindow( desktop() );
961 logWin->setCaption( tr( "LOG_WINDOW" ) );
964 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
970 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
972 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
973 aMap.insert( WT_PyConsole, Qt::DockBottom );
974 aMap.insert( WT_LogWindow, Qt::DockBottom );
977 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
981 void SalomeApp_Application::afterCloseDoc()
985 CAM_Application::afterCloseDoc();
988 CORBA::ORB_var SalomeApp_Application::orb()
990 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
991 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
995 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
997 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1001 SALOME_NamingService* SalomeApp_Application::namingService()
1003 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1007 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1009 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1013 QString SalomeApp_Application::defaultEngineIOR()
1015 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1016 QString anIOR( "" );
1017 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1018 if ( !CORBA::is_nil( anEngine ) )
1019 anIOR = orb()->object_to_string( anEngine );
1023 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1027 SUIT_ResourceMgr* resMgr = resourceMgr();
1031 QStringList modList;
1032 modules( modList, false );
1034 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1036 QString modName = *it;
1037 QString modIntr = moduleName( modName );
1038 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1040 if ( modIcon.isEmpty() )
1043 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1044 modIcon += QString( ".png" );
1046 iconMap.insert( modName, modIcon );
1050 void SalomeApp_Application::updateModuleActions()
1053 if ( activeModule() )
1054 modName = activeModule()->moduleName();
1056 if ( myActions.contains( modName ) )
1057 myActions[modName]->setOn( true );
1060 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1063 if ( !activeStudy() )
1066 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1067 ((SalomeApp_Module*)activeModule())->windows( winMap );
1069 defaultWindows( winMap );
1072 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1075 if ( !activeStudy() )
1078 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1079 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1081 defaultViewManagers( lst );
1084 void SalomeApp_Application::updateWindows()
1086 QMap<int, int> winMap;
1087 currentWindows( winMap );
1089 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1090 getWindow( it.key() );
1092 loadWindowsGeometry();
1094 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1095 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1098 void SalomeApp_Application::updateViewManagers()
1101 currentViewManagers( lst );
1103 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1104 getViewManager( *it, true );
1107 void SalomeApp_Application::loadWindowsGeometry()
1109 QtxDockAction* dockMgr = 0;
1111 QAction* a = action( ViewWindowsId );
1112 if ( a && a->inherits( "QtxDockAction" ) )
1113 dockMgr = (QtxDockAction*)a;
1119 if ( activeModule() )
1120 modName = moduleLibrary( activeModule()->moduleName(), false );
1122 QString section = QString( "windows_geometry" );
1123 if ( !modName.isEmpty() )
1124 section += QString( "." ) + modName;
1126 dockMgr->loadGeometry( resourceMgr(), section, false );
1127 dockMgr->restoreGeometry();
1130 void SalomeApp_Application::saveWindowsGeometry()
1132 QtxDockAction* dockMgr = 0;
1134 QAction* a = action( ViewWindowsId );
1135 if ( a && a->inherits( "QtxDockAction" ) )
1136 dockMgr = (QtxDockAction*)a;
1142 if ( activeModule() )
1143 modName = moduleLibrary( activeModule()->moduleName(), false );
1145 QString section = QString( "windows_geometry" );
1146 if ( !modName.isEmpty() )
1147 section += QString( "." ) + modName;
1149 dockMgr->storeGeometry();
1150 dockMgr->saveGeometry( resourceMgr(), section, false );
1153 void SalomeApp_Application::activateWindows()
1155 if ( activeStudy() )
1157 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1158 itr.data()->activate( activeStudy()->id() );
1162 void SalomeApp_Application::onProperties()
1164 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1168 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1171 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1172 int res = aDlg.exec();
1173 if( res==QDialog::Accepted && aDlg.isChanged() )
1174 SB->CommitCommand();
1178 //study->updateCaptions();
1181 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1182 const QString& caption, QWidget* parent )
1186 QStringList fls = QStringList::split( ";", filters, false );
1187 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1190 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1192 CAM_Application::contextMenuPopup( type, thePopup, title );
1193 thePopup->insertSeparator();
1194 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );