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_Preferences.h"
21 #include "SalomeApp_PreferencesDlg.h"
22 #include "SalomeApp_StudyPropertiesDlg.h"
23 #include "SalomeApp_CheckFileDlg.h"
25 #include "SalomeApp_GLSelector.h"
26 #include "SalomeApp_OBSelector.h"
27 #include "SalomeApp_OCCSelector.h"
28 #include "SalomeApp_VTKSelector.h"
29 #include "SalomeApp_SelectionMgr.h"
31 #include <LogWindow.h>
33 #include <GLViewer_Viewer.h>
34 #include <GLViewer_ViewManager.h>
36 #include <Plot2d_ViewManager.h>
37 #include <SPlot2d_ViewModel.h>
39 #include <OCCViewer_ViewManager.h>
40 #include <SOCC_ViewModel.h>
42 #include <SVTK_ViewModel.h>
43 #include <SVTK_ViewManager.h>
45 #include <STD_TabDesktop.h>
47 #include "STD_LoadStudiesDlg.h"
49 #include <SUIT_Tools.h>
50 #include <SUIT_Session.h>
52 #include <QtxToolBar.h>
53 #include <QtxMRUAction.h>
54 #include <QtxDockAction.h>
55 #include <QtxResourceEdit.h>
57 #include <OB_Browser.h>
59 #include <PythonConsole_PyConsole.h>
61 #include <SUIT_FileDlg.h>
62 #include <SUIT_MessageBox.h>
63 #include <SUIT_ResourceMgr.h>
64 #include <SUIT_ActionOperation.h>
66 #include <Utils_ORB_INIT.hxx>
67 #include <Utils_SINGLETON.hxx>
68 #include <SALOME_ModuleCatalog_impl.hxx>
69 #include <SALOME_LifeCycleCORBA.hxx>
77 #include <qcombobox.h>
78 #include <qmessagebox.h>
79 #include <qapplication.h>
83 #include "SALOMEDS_StudyManager.hxx"
85 #include "SALOME_ListIteratorOfListIO.hxx"
86 #include "SALOME_ListIO.hxx"
88 #define OBJECT_BROWSER_WIDTH 300
90 static const char* imageEmptyIcon[] = {
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "....................",
111 "....................",
112 "...................."};
114 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
116 return new SalomeApp_Application();
119 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
122 Class : SalomeApp_Application
123 Description : Application containing SalomeApp module
126 SalomeApp_Application::SalomeApp_Application()
127 : CAM_Application( false ),
130 STD_TabDesktop* desk = new STD_TabDesktop();
134 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
135 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
137 desktop()->setIcon( aLogo );
138 desktop()->setDockableMenuBar( true );
139 desktop()->setDockableStatusBar( false );
143 mySelMgr = new SalomeApp_SelectionMgr( this );
145 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
146 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
148 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
151 SalomeApp_Application::~SalomeApp_Application()
153 saveWindowsGeometry();
158 desktop()->saveGeometry( resourceMgr(), "desktop" );
159 resourceMgr()->save();
164 SalomeApp_EventFilter::Destroy();
167 void SalomeApp_Application::start()
170 desktop()->loadGeometry( resourceMgr(), "desktop" );
172 CAM_Application::start();
174 QAction* a = action( ViewWindowsId );
175 if ( a && a->inherits( "QtxDockAction" ) )
176 ((QtxDockAction*)a)->setAutoPlace( true );
178 SalomeApp_EventFilter::Init();
181 updateViewManagers();
186 QString SalomeApp_Application::applicationName() const
188 return tr( "APP_NAME" );
191 QString SalomeApp_Application::applicationVersion() const
193 static QString _app_version;
195 if ( _app_version.isEmpty() )
197 QString path( ::getenv( "GUI_ROOT_DIR" ) );
198 if ( !path.isEmpty() )
199 path += QDir::separator();
200 path += QString( "bin/salome/VERSION" );
203 if ( vf.open( IO_ReadOnly ) )
206 vf.readLine( line, 1024 );
209 if ( !line.isEmpty() )
211 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
212 line.remove( line.length() - 1, 1 );
214 int idx = line.findRev( ":" );
216 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
224 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
226 CAM_Module* mod = CAM_Application::loadModule( name );
229 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
230 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
231 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
236 bool SalomeApp_Application::activateModule( const QString& modName )
239 CAM_Module* prevMod = activeModule();
242 actName = prevMod->moduleName();
244 if ( actName == modName )
247 saveWindowsGeometry();
249 bool status = CAM_Application::activateModule( modName );
251 updateModuleActions();
257 updateViewManagers();
262 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
267 void SalomeApp_Application::createActions()
269 STD_Application::createActions();
271 SUIT_Desktop* desk = desktop();
272 SUIT_ResourceMgr* resMgr = resourceMgr();
275 createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
276 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
277 0, desk, false, this, SLOT( onDumpStudy() ) );
280 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
281 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
282 0, desk, false, this, SLOT( onLoadScript() ) );
285 createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
286 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
287 0, desk, false, this, SLOT( onProperties() ) );
290 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
291 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
292 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
295 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
296 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
297 registerAction( MRUId, mru );
299 // default icon for neutral point ('SALOME' module)
300 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
301 if ( defIcon.isNull() )
302 defIcon = QPixmap( imageEmptyIcon );
304 // default icon for any module
305 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
306 if ( modIcon.isNull() )
307 modIcon = QPixmap( imageEmptyIcon );
309 QToolBar* modTBar = new QtxToolBar( true, desk );
310 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
312 QActionGroup* modGroup = new QActionGroup( this );
313 modGroup->setExclusive( true );
314 modGroup->setUsesDropDown( true );
316 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
317 tr( "PRP_APP_MODULE" ), 0, desk, true );
319 myActions.insert( QString(), a );
321 QMap<QString, QString> iconMap;
322 moduleIconNames( iconMap );
324 const int iconSize = 20;
326 modGroup->addTo( modTBar );
327 modTBar->addSeparator();
330 modules( modList, false );
332 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
334 if ( (*it).isEmpty() )
338 if ( iconMap.contains( *it ) )
339 iconName = iconMap[*it];
341 QString modName = moduleName( *it );
343 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
347 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
349 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
353 myActions.insert( *it, a );
356 SUIT_Tools::simplifySeparators( modTBar );
360 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
361 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
362 createMenu( separator(), windowMenu, -1, 1 );
364 QMap<int, int> accelMap;
365 accelMap[NewGLViewId] = ALT+Key_G;
366 accelMap[NewPlot2dId] = ALT+Key_P;
367 accelMap[NewOCCViewId] = ALT+Key_O;
368 accelMap[NewVTKViewId] = ALT+Key_K;
370 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
372 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
373 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
374 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
375 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
376 createMenu( a, newWinMenu, -1 );
378 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
380 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
382 createMenu( DumpStudyId, fileMenu, 10, -1 );
383 createMenu( separator(), fileMenu, -1, 15, -1 );
384 createMenu( LoadScriptId, fileMenu, 10, -1 );
385 createMenu( separator(), fileMenu, -1, 15, -1 );
386 createMenu( PropertiesId, fileMenu, 10, -1 );
387 createMenu( separator(), fileMenu, -1, 15, -1 );
388 createMenu( PreferencesId, fileMenu, 15, -1 );
389 createMenu( separator(), fileMenu, -1, 15, -1 );
392 createMenu( separator(), fileMenu, -1, 100, -1 );
393 createMenu( MRUId, fileMenu, 100, -1 );
394 createMenu( separator(), fileMenu, -1, 100, -1 );
398 void SalomeApp_Application::onModuleActivation( QAction* a )
403 QString modName = a->menuText();
404 if ( modName == tr( "APP_NAME" ) )
405 modName = QString::null;
407 // Force user to create/open a study before module activation
408 QMap<QString, QString> iconMap;
409 moduleIconNames( iconMap );
410 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
412 icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
414 bool cancelled = false;
415 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
416 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
417 int res = aDlg.exec();
431 putInfo( tr("INF_CANCELLED") );
432 myActions[QString()]->setOn( true );
438 activateModule( modName );
441 QString SalomeApp_Application::defaultModule() const
443 QStringList aModuleNames;
444 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
445 // If there's the one and only module --> activate it automatically
446 // TODO: Possible improvement - default module can be taken from preferences
447 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
450 void SalomeApp_Application::onNewWindow()
452 const QObject* obj = sender();
453 if ( !obj || !obj->inherits( "QAction" ) )
457 int id = actionId( (QAction*)obj );
461 type = GLViewer_Viewer::Type();
464 type = Plot2d_Viewer::Type();
467 type = OCCViewer_Viewer::Type();
470 type = VTKViewer_Viewer::Type();
474 if ( !type.isEmpty() )
475 createViewManager( type );
478 //=======================================================================
480 // Purpose : SLOT. Create new document
481 //=======================================================================
482 void SalomeApp_Application::onNewDoc()
484 SUIT_Study* study = activeStudy();
486 saveWindowsGeometry();
488 CAM_Application::onNewDoc();
490 if ( !study ) // new study will be create in THIS application
493 updateViewManagers();
497 //=======================================================================
499 // Purpose : SLOT. Open new document
500 //=======================================================================
501 void SalomeApp_Application::onOpenDoc()
503 SUIT_Study* study = activeStudy();
504 saveWindowsGeometry();
506 CAM_Application::onOpenDoc();
508 if ( !study ) // new study will be create in THIS application
511 updateViewManagers();
515 bool SalomeApp_Application::onOpenDoc( const QString& aName )
517 bool res = CAM_Application::onOpenDoc( aName );
519 QAction* a = action( MRUId );
520 if ( a && a->inherits( "QtxMRUAction" ) )
522 QtxMRUAction* mru = (QtxMRUAction*)a;
524 mru->insert( aName );
526 mru->remove( aName );
531 void SalomeApp_Application::onLoadDoc()
533 QString name, studyname, ext;
535 STD_LoadStudiesDlg aDlg( desktop(), TRUE);
537 std::vector<std::string> List = studyMgr()->GetOpenStudies();
539 SUIT_Session* aSession = SUIT_Session::session();
540 QPtrList<SUIT_Application> aAppList = aSession->applications();
541 SUIT_Application* aApp = 0;
543 for (unsigned int ind = 0; ind < List.size(); ind++) {
544 studyname = List[ind];
545 //Add to list only unloaded studies
546 bool isAlreadyOpen = false;
547 for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
550 if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
553 if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
556 int retVal = aDlg.exec();
557 studyname = aDlg.ListComponent->currentText();
559 if (retVal == QDialog::Rejected)
562 if ( studyname.isNull() || studyname.isEmpty() )
566 name.replace( QRegExp(":"), "/" );
568 if(onLoadDoc(name)) {
570 updateViewManagers();
576 bool SalomeApp_Application::onLoadDoc( const QString& aName )
578 bool res = CAM_Application::onLoadDoc( aName );
580 /*jfa tmp:QAction* a = action( MRUId );
581 if ( a && a->inherits( "QtxMRUAction" ) )
583 QtxMRUAction* mru = (QtxMRUAction*)a;
585 mru->insert( aName );
587 mru->remove( aName );
592 void SalomeApp_Application::onSelection()
594 onSelectionChanged();
596 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
597 ((SalomeApp_Module*)activeModule())->selectionChanged();
600 void SalomeApp_Application::onCopy()
603 SalomeApp_SelectionMgr* mgr = selectionMgr();
604 mgr->selectedObjects(list);
606 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
607 if(study == NULL) return;
609 _PTR(Study) stdDS = study->studyDS();
612 SALOME_ListIteratorOfListIO it( list );
615 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
617 studyMgr()->Copy(so);
618 onSelectionChanged();
625 void SalomeApp_Application::onPaste()
628 SalomeApp_SelectionMgr* mgr = selectionMgr();
629 mgr->selectedObjects(list);
631 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
632 if(study == NULL) return;
634 _PTR(Study) stdDS = study->studyDS();
637 SALOME_ListIteratorOfListIO it( list );
640 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
642 studyMgr()->Paste(so);
643 updateObjectBrowser( true );
644 updateActions(); //SRN: BugID IPAL9377, case 3
651 void SalomeApp_Application::onSelectionChanged()
654 SalomeApp_SelectionMgr* mgr = selectionMgr();
655 mgr->selectedObjects(list);
657 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
658 if(study == NULL) return;
660 _PTR(Study) stdDS = study->studyDS();
665 SALOME_ListIteratorOfListIO it( list );
666 if(it.More() && list.Extent() == 1)
668 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
670 qaction = action(EditCopyId);
671 if(studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
672 else qaction->setEnabled(false);
674 qaction = action(EditPasteId);
675 if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
676 else qaction->setEnabled(false);
679 qaction = action(EditCopyId);
680 qaction->setEnabled(false);
681 qaction = action(EditPasteId);
682 qaction->setEnabled(false);
686 void SalomeApp_Application::onRefresh()
688 updateObjectBrowser( true );
692 void SalomeApp_Application::onOpenWith()
694 QApplication::setOverrideCursor( Qt::waitCursor );
696 SalomeApp_SelectionMgr* mgr = selectionMgr();
697 mgr->selectedObjects(aList);
698 if (aList.Extent() != 1)
700 QApplication::restoreOverrideCursor();
703 Handle(SALOME_InteractiveObject) aIObj = aList.First();
704 QString aModuleName(aIObj->getComponentDataType());
705 QString aModuleTitle = moduleTitle(aModuleName);
706 activateModule(aModuleTitle);
707 QApplication::restoreOverrideCursor();
710 bool SalomeApp_Application::useStudy(const QString& theName)
713 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
716 res = aStudy->loadDocument( theName );
717 updateDesktopTitle();
718 updateCommandsStatus();
722 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
724 CAM_Application::setActiveStudy( study );
729 //=======================================================================
730 // name : createNewStudy
731 // Purpose : Create new study
732 //=======================================================================
733 SUIT_Study* SalomeApp_Application::createNewStudy()
735 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
737 // Set up processing of major study-related events
738 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
739 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
740 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
741 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
746 //=======================================================================
747 // name : createNewStudy
748 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
749 //=======================================================================
750 void SalomeApp_Application::updateCommandsStatus()
752 CAM_Application::updateCommandsStatus();
754 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
756 QAction* a = action( id );
758 a->setEnabled( activeStudy() );
762 QAction* a = action( DumpStudyId );
764 a->setEnabled( activeStudy() );
767 a = action( LoadScriptId );
769 a->setEnabled( activeStudy() );
771 a = action( PropertiesId );
773 a->setEnabled( activeStudy() );
775 a = action(EditCopyId);
776 a->setEnabled(false);
777 a = action(EditPasteId);
778 a->setEnabled(false);
781 //=======================================================================
782 // name : onHelpAbout
783 // Purpose : SLOT. Display "About" message box
784 //=======================================================================
785 void SalomeApp_Application::onHelpAbout()
787 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
792 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
799 if ( !activeStudy() )
802 sId = activeStudy()->id();
805 if ( myWindows.contains( flag ) )
806 wid = myWindows[flag]->widget( sId );
811 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
819 if ( !activeStudy() )
822 sId = activeStudy()->id();
825 if ( !myWindows.contains( flag ) )
827 QMap<int, int> winMap;
828 currentWindows( winMap );
830 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
831 if ( winMap.contains( flag ) )
832 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
834 myWindows[flag]->setResizeEnabled( true );
835 myWindows[flag]->setCloseMode( QDockWindow::Always );
836 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
839 myWindows[flag]->insert( sId, wid );
841 setWindowShown( flag, !myWindows[flag]->isEmpty() );
844 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
846 if ( !myWindows.contains( flag ) )
852 if ( !activeStudy() )
855 sId = activeStudy()->id();
858 QWidget* wid = myWindows[flag]->widget( sId );
859 myWindows[flag]->remove( sId );
862 setWindowShown( flag, !myWindows[flag]->isEmpty() );
865 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
867 QWidget* wid = window( flag, studyId );
869 addWindow( wid = createWindow( flag ), flag, studyId );
874 bool SalomeApp_Application::isWindowVisible( const int type ) const
877 if ( myWindows.contains( type ) )
879 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
880 res = desk && desk->appropriate( myWindows[type] );
885 void SalomeApp_Application::setWindowShown( const int type, const bool on )
887 if ( !desktop() || !myWindows.contains( type ) )
890 QDockWindow* dw = myWindows[type];
891 desktop()->setAppropriate( dw, on );
892 on ? dw->show() : dw->hide();
895 OB_Browser* SalomeApp_Application::objectBrowser()
898 QWidget* wid = getWindow( WT_ObjectBrowser );
899 if ( wid->inherits( "OB_Browser" ) )
900 ob = (OB_Browser*)wid;
904 LogWindow* SalomeApp_Application::logWindow()
907 QWidget* wid = getWindow( WT_LogWindow );
908 if ( wid->inherits( "LogWindow" ) )
909 lw = (LogWindow*)wid;
913 PythonConsole* SalomeApp_Application::pythonConsole()
915 PythonConsole* console = 0;
916 QWidget* wid = getWindow( WT_PyConsole );
917 if ( wid->inherits( "PythonConsole" ) )
918 console = (PythonConsole*)wid;
922 SalomeApp_Preferences* SalomeApp_Application::preferences() const
924 return preferences( false );
927 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
929 SUIT_ViewManager* aVM = viewManager( vmType );
930 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
932 if ( anActiveVM && anActiveVM->getType() == vmType )
937 if ( !aVM->getActiveView() )
940 aVM->getActiveView()->setFocus();
943 aVM = createViewManager( vmType );
948 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
950 SUIT_ResourceMgr* resMgr = resourceMgr();
952 SUIT_ViewManager* viewMgr = 0;
953 if ( vmType == GLViewer_Viewer::Type() )
955 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
956 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
958 else if ( vmType == Plot2d_Viewer::Type() )
960 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
961 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
963 else if ( vmType == OCCViewer_Viewer::Type() )
965 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
966 SOCC_Viewer* vm = new SOCC_Viewer();
967 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
968 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
971 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
972 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
974 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
975 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
977 else if ( vmType == SVTK_Viewer::Type() )
979 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
980 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
981 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
982 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
983 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
989 addViewManager( viewMgr );
990 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
992 if ( viewWin && desktop() )
993 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
995 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
996 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1001 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1003 removeViewManager( theVM );
1006 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1008 SUIT_DataObject* aRoot = 0;
1009 if ( theStudy && theStudy->root() )
1011 aRoot = theStudy->root();
1012 //aRoot->setName( tr( "DATA_MODELS" ) );
1014 if ( objectBrowser() != 0 )
1015 objectBrowser()->setRootObject( aRoot );
1017 activateModule( defaultModule() );
1022 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1024 SUIT_DataObject* aRoot = 0;
1025 if ( theStudy && theStudy->root() )
1027 aRoot = theStudy->root();
1030 if ( objectBrowser() != 0 ) {
1031 objectBrowser()->setRootObject( aRoot );
1034 activateModule( defaultModule() );
1041 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1046 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1050 activateModule( "" );
1052 saveWindowsGeometry();
1055 void SalomeApp_Application::onDumpStudy( )
1057 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1058 if ( !appStudy ) return;
1059 _PTR(Study) aStudy = appStudy->studyDS();
1061 QStringList aFilters;
1062 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1064 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1065 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1066 fd->setFilters( aFilters );
1067 fd->SetChecked(true);
1069 QString aFileName = fd->selectedFile();
1070 bool toPublish = fd->IsChecked();
1073 if(!aFileName.isEmpty()) {
1074 QFileInfo aFileInfo(aFileName);
1075 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1079 void SalomeApp_Application::onLoadScript( )
1081 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1082 if ( !appStudy ) return;
1083 _PTR(Study) aStudy = appStudy->studyDS();
1085 if ( aStudy->GetProperties()->IsLocked() ) {
1086 SUIT_MessageBox::warn1 ( desktop(),
1087 QObject::tr("WRN_WARNING"),
1088 QObject::tr("WRN_STUDY_LOCKED"),
1089 QObject::tr("BUT_OK") );
1093 QStringList filtersList;
1094 filtersList.append(tr("PYTHON_FILES_FILTER"));
1095 filtersList.append(tr("ALL_FILES_FILTER"));
1097 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1099 if ( !aFile.isEmpty() )
1101 QString command = QString("execfile(\"%1\")").arg(aFile);
1103 PythonConsole* pyConsole = pythonConsole();
1106 pyConsole->exec( command );
1110 void SalomeApp_Application::onPreferences()
1112 QApplication::setOverrideCursor( Qt::waitCursor );
1114 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1116 QApplication::restoreOverrideCursor();
1126 void SalomeApp_Application::onMRUActivated( QString aName )
1131 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1133 SalomeApp_Module* sMod = 0;
1134 CAM_Module* mod = module( modName );
1135 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1136 sMod = (SalomeApp_Module*)mod;
1139 sMod->preferencesChanged( section, param );
1141 preferencesChanged( section, param );
1144 QString SalomeApp_Application::getFileFilter() const
1149 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1151 CAM_Application::beforeCloseDoc( s );
1153 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1154 removeWindow( itr.key(), s->id() );
1157 void SalomeApp_Application::updateActions()
1159 updateCommandsStatus();
1162 QWidget* SalomeApp_Application::createWindow( const int flag )
1166 SUIT_ResourceMgr* resMgr = resourceMgr();
1168 if ( flag == WT_ObjectBrowser )
1170 OB_Browser* ob = new OB_Browser( desktop() );
1171 ob->setAutoUpdate( true );
1172 ob->setAutoOpenLevel( 1 );
1173 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1174 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1175 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1177 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1179 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1181 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1182 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1183 QString().sprintf( "visibility_column_%d", i ), true ) );
1186 // Create OBSelector
1187 new SalomeApp_OBSelector( ob, mySelMgr );
1191 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1193 else if ( flag == WT_PyConsole )
1195 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1196 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1199 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1201 else if ( flag == WT_LogWindow )
1203 LogWindow* logWin = new LogWindow( desktop() );
1204 logWin->setCaption( tr( "LOG_WINDOW" ) );
1207 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1213 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1215 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1216 aMap.insert( WT_PyConsole, Qt::DockBottom );
1217 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1220 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1224 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1229 SalomeApp_Application* that = (SalomeApp_Application*)this;
1231 if ( !_prefs_ && crt )
1233 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1234 that->createPreferences( _prefs_ );
1237 that->myPrefs = _prefs_;
1239 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1240 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1242 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1245 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1247 QStringList modNameList;
1248 app->modules( modNameList, false );
1249 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1251 int id = _prefs_->addPreference( *it );
1252 _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1256 app->modules( modList );
1257 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1259 SalomeApp_Module* mod = 0;
1260 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1261 mod = (SalomeApp_Module*)itr.current();
1263 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1264 mod->createPreferences();
1268 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1269 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1274 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1276 CAM_Application::moduleAdded( mod );
1278 SalomeApp_Module* salomeMod = 0;
1279 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1280 salomeMod = (SalomeApp_Module*)mod;
1282 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1283 salomeMod->createPreferences();
1286 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1291 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1293 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1295 int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1296 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1298 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1299 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1301 pref->setProperty( obGroup, "columns", 1 );
1303 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1305 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1307 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1308 pref->setProperty( occGroup, "columns", 1 );
1309 pref->setProperty( vtkGroup, "columns", 1 );
1311 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1312 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1313 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1314 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1316 pref->setProperty( occTS, "min", 1 );
1317 pref->setProperty( occTS, "max", 150 );
1319 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1320 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1321 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1322 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1324 pref->setProperty( isoU, "min", 0 );
1325 pref->setProperty( isoU, "max", 100000 );
1327 pref->setProperty( isoV, "min", 0 );
1328 pref->setProperty( isoV, "max", 100000 );
1330 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1331 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1332 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1333 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1335 pref->setProperty( vtkTS, "min", 1 );
1336 pref->setProperty( vtkTS, "max", 150 );
1339 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1341 SUIT_ResourceMgr* resMgr = resourceMgr();
1345 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1347 int sz = resMgr->integerValue( sec, param, -1 );
1348 QPtrList<SUIT_ViewManager> lst;
1349 viewManagers( OCCViewer_Viewer::Type(), lst );
1350 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1352 SUIT_ViewModel* vm = it.current()->getViewModel();
1353 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1356 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1357 occVM->setTrihedronSize( sz );
1358 occVM->getAISContext()->UpdateCurrentViewer();
1362 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1364 int sz = resMgr->integerValue( sec, param, -1 );
1365 QPtrList<SUIT_ViewManager> lst;
1366 viewManagers( SVTK_Viewer::Type(), lst );
1367 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1369 SUIT_ViewModel* vm = it.current()->getViewModel();
1370 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1373 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1374 vtkVM->setTrihedronSize( sz );
1379 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1381 QPtrList<SUIT_ViewManager> lst;
1382 viewManagers( OCCViewer_Viewer::Type(), lst );
1383 int u = resMgr->integerValue( sec, "iso_number_u" );
1384 int v = resMgr->integerValue( sec, "iso_number_v" );
1385 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1386 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1391 void SalomeApp_Application::updateDesktopTitle() {
1392 QString aTitle = applicationName();
1393 QString aVer = applicationVersion();
1394 if ( !aVer.isEmpty() )
1395 aTitle += QString( " " ) + aVer;
1397 if ( activeStudy() )
1399 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1400 if ( !sName.isEmpty() ) {
1401 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1402 _PTR(Study) stdDS = study->studyDS();
1404 if ( stdDS->GetProperties()->IsLocked() ) {
1405 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1407 aTitle += QString( " - [%1]" ).arg( sName );
1413 desktop()->setCaption( aTitle );
1416 void SalomeApp_Application::afterCloseDoc()
1420 CAM_Application::afterCloseDoc();
1423 CORBA::ORB_var SalomeApp_Application::orb()
1425 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1426 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1430 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1432 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1436 SALOME_NamingService* SalomeApp_Application::namingService()
1438 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1442 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1444 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1448 QString SalomeApp_Application::defaultEngineIOR()
1450 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1451 QString anIOR( "" );
1452 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1453 if ( !CORBA::is_nil( anEngine ) )
1454 anIOR = orb()->object_to_string( anEngine );
1458 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1462 SUIT_ResourceMgr* resMgr = resourceMgr();
1466 QStringList modList;
1467 modules( modList, false );
1469 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1471 QString modName = *it;
1472 QString modIntr = moduleName( modName );
1473 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1475 if ( modIcon.isEmpty() )
1478 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1479 modIcon += QString( ".png" );
1481 iconMap.insert( modName, modIcon );
1485 void SalomeApp_Application::updateModuleActions()
1488 if ( activeModule() )
1489 modName = activeModule()->moduleName();
1491 if ( myActions.contains( modName ) )
1492 myActions[modName]->setOn( true );
1495 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1498 if ( !activeStudy() )
1501 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1502 ((SalomeApp_Module*)activeModule())->windows( winMap );
1504 defaultWindows( winMap );
1507 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1510 if ( !activeStudy() )
1513 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1514 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1516 defaultViewManagers( lst );
1519 void SalomeApp_Application::updateWindows()
1521 QMap<int, int> winMap;
1522 currentWindows( winMap );
1524 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1525 getWindow( it.key() );
1527 loadWindowsGeometry();
1529 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1530 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1533 void SalomeApp_Application::updateViewManagers()
1536 currentViewManagers( lst );
1538 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1539 getViewManager( *it, true );
1542 void SalomeApp_Application::loadWindowsGeometry()
1544 QtxDockAction* dockMgr = 0;
1546 QAction* a = action( ViewWindowsId );
1547 if ( a && a->inherits( "QtxDockAction" ) )
1548 dockMgr = (QtxDockAction*)a;
1554 if ( activeModule() )
1555 modName = moduleLibrary( activeModule()->moduleName(), false );
1557 QString section = QString( "windows_geometry" );
1558 if ( !modName.isEmpty() )
1559 section += QString( "." ) + modName;
1561 dockMgr->loadGeometry( resourceMgr(), section, false );
1562 dockMgr->restoreGeometry();
1565 void SalomeApp_Application::saveWindowsGeometry()
1567 QtxDockAction* dockMgr = 0;
1569 QAction* a = action( ViewWindowsId );
1570 if ( a && a->inherits( "QtxDockAction" ) )
1571 dockMgr = (QtxDockAction*)a;
1577 if ( activeModule() )
1578 modName = moduleLibrary( activeModule()->moduleName(), false );
1580 QString section = QString( "windows_geometry" );
1581 if ( !modName.isEmpty() )
1582 section += QString( "." ) + modName;
1584 dockMgr->storeGeometry();
1585 dockMgr->saveGeometry( resourceMgr(), section, false );
1588 void SalomeApp_Application::activateWindows()
1590 if ( activeStudy() )
1592 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1593 itr.data()->activate( activeStudy()->id() );
1597 void SalomeApp_Application::onProperties()
1599 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1603 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1606 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1607 int res = aDlg.exec();
1608 if( res==QDialog::Accepted && aDlg.isChanged() )
1609 SB->CommitCommand();
1613 //study->updateCaptions();
1614 updateDesktopTitle();
1617 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1618 const QString& caption, QWidget* parent )
1622 QStringList fls = QStringList::split( ";;", filters, false );
1623 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1626 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1630 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1633 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1634 const QString& caption, QWidget* parent )
1638 QStringList fls = QStringList::split( ";;", filters, false );
1639 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1642 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1644 CAM_Application::contextMenuPopup( type, thePopup, title );
1645 thePopup->insertSeparator();
1646 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1648 // "Activate module" item should appear only if it's necessary
1649 OB_Browser* ob = objectBrowser();
1650 if ( !ob || type != ob->popupClientType() )
1652 SALOME_ListIO aList;
1653 SalomeApp_SelectionMgr* mgr = selectionMgr();
1654 mgr->selectedObjects(aList);
1655 if (aList.Extent() != 1)
1657 Handle(SALOME_InteractiveObject) aIObj = aList.First();
1658 QString aModuleName(aIObj->getComponentDataType());
1659 QString aModuleTitle = moduleTitle(aModuleName);
1660 CAM_Module* currentModule = activeModule();
1661 if (currentModule && currentModule->moduleName() == aModuleTitle)
1663 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1666 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1668 // update existing data models (already loaded SComponents)
1671 for ( ModuleListIterator it = modules(); it.current(); ++it )
1673 CAM_DataModel* camDM = it.current()->dataModel();
1674 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1675 ((SalomeApp_DataModel*)camDM)->update();
1678 // update "non-existing" (not loaded yet) data models
1679 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1682 _PTR(Study) stdDS = study->studyDS();
1685 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
1687 _PTR(SComponent) aComponent ( it->Value() );
1689 if ( aComponent->ComponentDataType() == "Interface Applicative" )
1690 continue; // skip the magic "Interface Applicative" component
1692 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
1697 if ( objectBrowser() )
1698 objectBrowser()->updateTree();
1702 //************************************************************
1703 void SalomeApp_Application::onDesktopActivated()
1705 CAM_Application::onDesktopActivated();
1706 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
1708 aModule->studyActivated();
1711 void SalomeApp_Application::createEmptyStudy()
1713 CAM_Application::createEmptyStudy();
1714 if ( objectBrowser() )
1715 objectBrowser()->updateTree();
1718 bool SalomeApp_Application::activateModule( CAM_Module* mod )
1720 bool res = CAM_Application::activateModule( mod );
1721 if ( objectBrowser() )
1722 objectBrowser()->updateTree();