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].c_str();
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 || !aApp->activeStudy()) continue;
551 if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
554 if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
557 int retVal = aDlg.exec();
558 studyname = aDlg.ListComponent->currentText();
560 if (retVal == QDialog::Rejected)
563 if ( studyname.isNull() || studyname.isEmpty() )
567 name.replace( QRegExp(":"), "/" );
569 if(onLoadDoc(name)) {
571 updateViewManagers();
572 updateObjectBrowser(true);
578 bool SalomeApp_Application::onLoadDoc( const QString& aName )
580 bool res = CAM_Application::onLoadDoc( aName );
582 /*jfa tmp:QAction* a = action( MRUId );
583 if ( a && a->inherits( "QtxMRUAction" ) )
585 QtxMRUAction* mru = (QtxMRUAction*)a;
587 mru->insert( aName );
589 mru->remove( aName );
594 void SalomeApp_Application::onSelection()
596 onSelectionChanged();
598 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
599 ((SalomeApp_Module*)activeModule())->selectionChanged();
602 void SalomeApp_Application::onCopy()
605 SalomeApp_SelectionMgr* mgr = selectionMgr();
606 mgr->selectedObjects(list);
608 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
609 if(study == NULL) return;
611 _PTR(Study) stdDS = study->studyDS();
614 SALOME_ListIteratorOfListIO it( list );
617 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
619 studyMgr()->Copy(so);
620 onSelectionChanged();
627 void SalomeApp_Application::onPaste()
630 SalomeApp_SelectionMgr* mgr = selectionMgr();
631 mgr->selectedObjects(list);
633 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
634 if(study == NULL) return;
636 _PTR(Study) stdDS = study->studyDS();
639 SALOME_ListIteratorOfListIO it( list );
642 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
644 studyMgr()->Paste(so);
645 updateObjectBrowser( true );
646 updateActions(); //SRN: BugID IPAL9377, case 3
653 void SalomeApp_Application::onSelectionChanged()
656 SalomeApp_SelectionMgr* mgr = selectionMgr();
657 mgr->selectedObjects(list);
659 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
660 if(study == NULL) return;
662 _PTR(Study) stdDS = study->studyDS();
667 SALOME_ListIteratorOfListIO it( list );
668 if(it.More() && list.Extent() == 1)
670 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
672 qaction = action(EditCopyId);
673 if(studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
674 else qaction->setEnabled(false);
676 qaction = action(EditPasteId);
677 if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
678 else qaction->setEnabled(false);
681 qaction = action(EditCopyId);
682 qaction->setEnabled(false);
683 qaction = action(EditPasteId);
684 qaction->setEnabled(false);
688 void SalomeApp_Application::onRefresh()
690 updateObjectBrowser( true );
694 void SalomeApp_Application::onOpenWith()
696 QApplication::setOverrideCursor( Qt::waitCursor );
698 SalomeApp_SelectionMgr* mgr = selectionMgr();
699 mgr->selectedObjects(aList);
700 if (aList.Extent() != 1)
702 QApplication::restoreOverrideCursor();
705 Handle(SALOME_InteractiveObject) aIObj = aList.First();
706 QString aModuleName(aIObj->getComponentDataType());
707 QString aModuleTitle = moduleTitle(aModuleName);
708 activateModule(aModuleTitle);
709 QApplication::restoreOverrideCursor();
712 bool SalomeApp_Application::useStudy(const QString& theName)
715 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
718 res = aStudy->loadDocument( theName );
719 updateDesktopTitle();
720 updateCommandsStatus();
724 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
726 CAM_Application::setActiveStudy( study );
731 //=======================================================================
732 // name : createNewStudy
733 // Purpose : Create new study
734 //=======================================================================
735 SUIT_Study* SalomeApp_Application::createNewStudy()
737 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
739 // Set up processing of major study-related events
740 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
741 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
742 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
743 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
748 //=======================================================================
749 // name : createNewStudy
750 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
751 //=======================================================================
752 void SalomeApp_Application::updateCommandsStatus()
754 CAM_Application::updateCommandsStatus();
756 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
758 QAction* a = action( id );
760 a->setEnabled( activeStudy() );
764 QAction* a = action( DumpStudyId );
766 a->setEnabled( activeStudy() );
769 a = action( LoadScriptId );
771 a->setEnabled( activeStudy() );
773 a = action( PropertiesId );
775 a->setEnabled( activeStudy() );
777 a = action(EditCopyId);
778 a->setEnabled(false);
779 a = action(EditPasteId);
780 a->setEnabled(false);
783 //=======================================================================
784 // name : onHelpAbout
785 // Purpose : SLOT. Display "About" message box
786 //=======================================================================
787 void SalomeApp_Application::onHelpAbout()
789 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
794 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
801 if ( !activeStudy() )
804 sId = activeStudy()->id();
807 if ( myWindows.contains( flag ) )
808 wid = myWindows[flag]->widget( sId );
813 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
821 if ( !activeStudy() )
824 sId = activeStudy()->id();
827 if ( !myWindows.contains( flag ) )
829 QMap<int, int> winMap;
830 currentWindows( winMap );
832 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
833 if ( winMap.contains( flag ) )
834 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
836 myWindows[flag]->setResizeEnabled( true );
837 myWindows[flag]->setCloseMode( QDockWindow::Always );
838 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
841 myWindows[flag]->insert( sId, wid );
843 setWindowShown( flag, !myWindows[flag]->isEmpty() );
846 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
848 if ( !myWindows.contains( flag ) )
854 if ( !activeStudy() )
857 sId = activeStudy()->id();
860 QWidget* wid = myWindows[flag]->widget( sId );
861 myWindows[flag]->remove( sId );
864 setWindowShown( flag, !myWindows[flag]->isEmpty() );
867 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
869 QWidget* wid = window( flag, studyId );
871 addWindow( wid = createWindow( flag ), flag, studyId );
876 bool SalomeApp_Application::isWindowVisible( const int type ) const
879 if ( myWindows.contains( type ) )
881 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
882 res = desk && desk->appropriate( myWindows[type] );
887 void SalomeApp_Application::setWindowShown( const int type, const bool on )
889 if ( !desktop() || !myWindows.contains( type ) )
892 QDockWindow* dw = myWindows[type];
893 desktop()->setAppropriate( dw, on );
894 on ? dw->show() : dw->hide();
897 OB_Browser* SalomeApp_Application::objectBrowser()
900 QWidget* wid = getWindow( WT_ObjectBrowser );
901 if ( wid->inherits( "OB_Browser" ) )
902 ob = (OB_Browser*)wid;
906 LogWindow* SalomeApp_Application::logWindow()
909 QWidget* wid = getWindow( WT_LogWindow );
910 if ( wid->inherits( "LogWindow" ) )
911 lw = (LogWindow*)wid;
915 PythonConsole* SalomeApp_Application::pythonConsole()
917 PythonConsole* console = 0;
918 QWidget* wid = getWindow( WT_PyConsole );
919 if ( wid->inherits( "PythonConsole" ) )
920 console = (PythonConsole*)wid;
924 SalomeApp_Preferences* SalomeApp_Application::preferences() const
926 return preferences( false );
929 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
931 SUIT_ViewManager* aVM = viewManager( vmType );
932 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
934 if ( anActiveVM && anActiveVM->getType() == vmType )
939 if ( !aVM->getActiveView() )
942 aVM->getActiveView()->setFocus();
945 aVM = createViewManager( vmType );
950 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
952 SUIT_ResourceMgr* resMgr = resourceMgr();
954 SUIT_ViewManager* viewMgr = 0;
955 if ( vmType == GLViewer_Viewer::Type() )
957 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
958 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
960 else if ( vmType == Plot2d_Viewer::Type() )
962 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
963 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
965 else if ( vmType == OCCViewer_Viewer::Type() )
967 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
968 SOCC_Viewer* vm = new SOCC_Viewer();
969 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
970 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
973 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
974 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
976 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
977 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
979 else if ( vmType == SVTK_Viewer::Type() )
981 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
982 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
983 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
984 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
985 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
991 addViewManager( viewMgr );
992 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
994 if ( viewWin && desktop() )
995 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
997 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
998 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1003 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1005 removeViewManager( theVM );
1008 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1010 SUIT_DataObject* aRoot = 0;
1011 if ( theStudy && theStudy->root() )
1013 aRoot = theStudy->root();
1014 //aRoot->setName( tr( "DATA_MODELS" ) );
1016 if ( objectBrowser() != 0 )
1017 objectBrowser()->setRootObject( aRoot );
1019 activateModule( defaultModule() );
1024 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1026 SUIT_DataObject* aRoot = 0;
1027 if ( theStudy && theStudy->root() )
1029 aRoot = theStudy->root();
1032 if ( objectBrowser() != 0 ) {
1033 objectBrowser()->setRootObject( aRoot );
1036 activateModule( defaultModule() );
1043 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1048 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1052 activateModule( "" );
1054 saveWindowsGeometry();
1057 void SalomeApp_Application::onDumpStudy( )
1059 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1060 if ( !appStudy ) return;
1061 _PTR(Study) aStudy = appStudy->studyDS();
1063 QStringList aFilters;
1064 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1066 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1067 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1068 fd->setFilters( aFilters );
1069 fd->SetChecked(true);
1071 QString aFileName = fd->selectedFile();
1072 bool toPublish = fd->IsChecked();
1075 if(!aFileName.isEmpty()) {
1076 QFileInfo aFileInfo(aFileName);
1077 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1081 void SalomeApp_Application::onLoadScript( )
1083 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1084 if ( !appStudy ) return;
1085 _PTR(Study) aStudy = appStudy->studyDS();
1087 if ( aStudy->GetProperties()->IsLocked() ) {
1088 SUIT_MessageBox::warn1 ( desktop(),
1089 QObject::tr("WRN_WARNING"),
1090 QObject::tr("WRN_STUDY_LOCKED"),
1091 QObject::tr("BUT_OK") );
1095 QStringList filtersList;
1096 filtersList.append(tr("PYTHON_FILES_FILTER"));
1097 filtersList.append(tr("ALL_FILES_FILTER"));
1099 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1101 if ( !aFile.isEmpty() )
1103 QString command = QString("execfile(\"%1\")").arg(aFile);
1105 PythonConsole* pyConsole = pythonConsole();
1108 pyConsole->exec( command );
1112 void SalomeApp_Application::onPreferences()
1114 QApplication::setOverrideCursor( Qt::waitCursor );
1116 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1118 QApplication::restoreOverrideCursor();
1128 void SalomeApp_Application::onMRUActivated( QString aName )
1133 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1135 SalomeApp_Module* sMod = 0;
1136 CAM_Module* mod = module( modName );
1137 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1138 sMod = (SalomeApp_Module*)mod;
1141 sMod->preferencesChanged( section, param );
1143 preferencesChanged( section, param );
1146 QString SalomeApp_Application::getFileFilter() const
1151 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1153 CAM_Application::beforeCloseDoc( s );
1155 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1156 removeWindow( itr.key(), s->id() );
1159 void SalomeApp_Application::updateActions()
1161 updateCommandsStatus();
1164 QWidget* SalomeApp_Application::createWindow( const int flag )
1168 SUIT_ResourceMgr* resMgr = resourceMgr();
1170 if ( flag == WT_ObjectBrowser )
1172 OB_Browser* ob = new OB_Browser( desktop() );
1173 ob->setAutoUpdate( true );
1174 ob->setAutoOpenLevel( 1 );
1175 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1176 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1177 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1179 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1181 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1183 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1184 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1185 QString().sprintf( "visibility_column_%d", i ), true ) );
1188 // Create OBSelector
1189 new SalomeApp_OBSelector( ob, mySelMgr );
1193 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1195 else if ( flag == WT_PyConsole )
1197 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1198 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1201 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1203 else if ( flag == WT_LogWindow )
1205 LogWindow* logWin = new LogWindow( desktop() );
1206 logWin->setCaption( tr( "LOG_WINDOW" ) );
1209 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1215 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1217 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1218 aMap.insert( WT_PyConsole, Qt::DockBottom );
1219 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1222 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1226 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1231 SalomeApp_Application* that = (SalomeApp_Application*)this;
1233 if ( !_prefs_ && crt )
1235 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1236 that->createPreferences( _prefs_ );
1239 that->myPrefs = _prefs_;
1241 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1242 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1244 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1247 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1249 QStringList modNameList;
1250 app->modules( modNameList, false );
1251 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1253 int id = _prefs_->addPreference( *it );
1254 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1258 app->modules( modList );
1259 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1261 SalomeApp_Module* mod = 0;
1262 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1263 mod = (SalomeApp_Module*)itr.current();
1265 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1267 int modCat = _prefs_->addPreference( mod->moduleName() );
1268 _prefs_->setItemProperty( modCat, "info", QString::null );
1269 mod->createPreferences();
1274 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1275 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1280 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1282 CAM_Application::moduleAdded( mod );
1284 SalomeApp_Module* salomeMod = 0;
1285 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1286 salomeMod = (SalomeApp_Module*)mod;
1288 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1290 int modCat = myPrefs->addPreference( mod->moduleName() );
1291 myPrefs->setItemProperty( modCat, "info", QString::null );
1292 salomeMod->createPreferences();
1296 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1301 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1303 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1305 int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1306 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1308 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1309 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1311 pref->setItemProperty( obGroup, "columns", 1 );
1313 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1315 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1317 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1318 pref->setItemProperty( occGroup, "columns", 1 );
1319 pref->setItemProperty( vtkGroup, "columns", 1 );
1321 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1322 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1323 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1324 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1326 pref->setItemProperty( occTS, "min", 1 );
1327 pref->setItemProperty( occTS, "max", 150 );
1329 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1330 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1331 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1332 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1334 pref->setItemProperty( isoU, "min", 0 );
1335 pref->setItemProperty( isoU, "max", 100000 );
1337 pref->setItemProperty( isoV, "min", 0 );
1338 pref->setItemProperty( isoV, "max", 100000 );
1340 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1341 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1342 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1343 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1345 pref->setItemProperty( vtkTS, "min", 1 );
1346 pref->setItemProperty( vtkTS, "max", 150 );
1348 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1349 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1350 pref->setItemProperty( dirGroup, "columns", 1 );
1351 pref->addPreference( tr( "" ), dirGroup,
1352 SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1355 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1357 SUIT_ResourceMgr* resMgr = resourceMgr();
1361 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1363 int sz = resMgr->integerValue( sec, param, -1 );
1364 QPtrList<SUIT_ViewManager> lst;
1365 viewManagers( OCCViewer_Viewer::Type(), lst );
1366 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1368 SUIT_ViewModel* vm = it.current()->getViewModel();
1369 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1372 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1373 occVM->setTrihedronSize( sz );
1374 occVM->getAISContext()->UpdateCurrentViewer();
1378 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1380 int sz = resMgr->integerValue( sec, param, -1 );
1381 QPtrList<SUIT_ViewManager> lst;
1382 viewManagers( SVTK_Viewer::Type(), lst );
1383 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1385 SUIT_ViewModel* vm = it.current()->getViewModel();
1386 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1389 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1390 vtkVM->setTrihedronSize( sz );
1395 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1397 QPtrList<SUIT_ViewManager> lst;
1398 viewManagers( OCCViewer_Viewer::Type(), lst );
1399 int u = resMgr->integerValue( sec, "iso_number_u" );
1400 int v = resMgr->integerValue( sec, "iso_number_v" );
1401 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1402 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1407 void SalomeApp_Application::updateDesktopTitle() {
1408 QString aTitle = applicationName();
1409 QString aVer = applicationVersion();
1410 if ( !aVer.isEmpty() )
1411 aTitle += QString( " " ) + aVer;
1413 if ( activeStudy() )
1415 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1416 if ( !sName.isEmpty() ) {
1417 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1418 _PTR(Study) stdDS = study->studyDS();
1420 if ( stdDS->GetProperties()->IsLocked() ) {
1421 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1423 aTitle += QString( " - [%1]" ).arg( sName );
1429 desktop()->setCaption( aTitle );
1432 void SalomeApp_Application::afterCloseDoc()
1436 CAM_Application::afterCloseDoc();
1439 CORBA::ORB_var SalomeApp_Application::orb()
1441 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1442 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1446 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1448 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1452 SALOME_NamingService* SalomeApp_Application::namingService()
1454 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1458 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1460 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1464 QString SalomeApp_Application::defaultEngineIOR()
1466 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1467 QString anIOR( "" );
1468 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1469 if ( !CORBA::is_nil( anEngine ) )
1470 anIOR = orb()->object_to_string( anEngine );
1474 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1478 SUIT_ResourceMgr* resMgr = resourceMgr();
1482 QStringList modList;
1483 modules( modList, false );
1485 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1487 QString modName = *it;
1488 QString modIntr = moduleName( modName );
1489 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1491 if ( modIcon.isEmpty() )
1494 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1495 modIcon += QString( ".png" );
1497 iconMap.insert( modName, modIcon );
1501 void SalomeApp_Application::updateModuleActions()
1504 if ( activeModule() )
1505 modName = activeModule()->moduleName();
1507 if ( myActions.contains( modName ) )
1508 myActions[modName]->setOn( true );
1511 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1514 if ( !activeStudy() )
1517 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1518 ((SalomeApp_Module*)activeModule())->windows( winMap );
1520 defaultWindows( winMap );
1523 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1526 if ( !activeStudy() )
1529 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1530 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1532 defaultViewManagers( lst );
1535 void SalomeApp_Application::updateWindows()
1537 QMap<int, int> winMap;
1538 currentWindows( winMap );
1540 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1541 getWindow( it.key() );
1543 loadWindowsGeometry();
1545 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1546 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1549 void SalomeApp_Application::updateViewManagers()
1552 currentViewManagers( lst );
1554 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1555 getViewManager( *it, true );
1558 void SalomeApp_Application::loadWindowsGeometry()
1560 QtxDockAction* dockMgr = 0;
1562 QAction* a = action( ViewWindowsId );
1563 if ( a && a->inherits( "QtxDockAction" ) )
1564 dockMgr = (QtxDockAction*)a;
1570 if ( activeModule() )
1571 modName = moduleLibrary( activeModule()->moduleName(), false );
1573 QString section = QString( "windows_geometry" );
1574 if ( !modName.isEmpty() )
1575 section += QString( "." ) + modName;
1577 dockMgr->loadGeometry( resourceMgr(), section, false );
1578 dockMgr->restoreGeometry();
1581 void SalomeApp_Application::saveWindowsGeometry()
1583 QtxDockAction* dockMgr = 0;
1585 QAction* a = action( ViewWindowsId );
1586 if ( a && a->inherits( "QtxDockAction" ) )
1587 dockMgr = (QtxDockAction*)a;
1593 if ( activeModule() )
1594 modName = moduleLibrary( activeModule()->moduleName(), false );
1596 QString section = QString( "windows_geometry" );
1597 if ( !modName.isEmpty() )
1598 section += QString( "." ) + modName;
1600 dockMgr->storeGeometry();
1601 dockMgr->saveGeometry( resourceMgr(), section, false );
1604 void SalomeApp_Application::activateWindows()
1606 if ( activeStudy() )
1608 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1609 itr.data()->activate( activeStudy()->id() );
1613 void SalomeApp_Application::onProperties()
1615 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1619 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1622 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1623 int res = aDlg.exec();
1624 if( res==QDialog::Accepted && aDlg.isChanged() )
1625 SB->CommitCommand();
1629 //study->updateCaptions();
1630 updateDesktopTitle();
1633 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1634 const QString& caption, QWidget* parent )
1638 QStringList fls = QStringList::split( ";;", filters, false );
1639 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1642 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1646 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1649 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1650 const QString& caption, QWidget* parent )
1654 QStringList fls = QStringList::split( ";;", filters, false );
1655 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1658 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1660 CAM_Application::contextMenuPopup( type, thePopup, title );
1661 thePopup->insertSeparator();
1662 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1664 // "Activate module" item should appear only if it's necessary
1665 OB_Browser* ob = objectBrowser();
1666 if ( !ob || type != ob->popupClientType() )
1668 SALOME_ListIO aList;
1669 SalomeApp_SelectionMgr* mgr = selectionMgr();
1670 mgr->selectedObjects(aList);
1671 if (aList.Extent() != 1)
1673 Handle(SALOME_InteractiveObject) aIObj = aList.First();
1674 QString aModuleName(aIObj->getComponentDataType());
1675 QString aModuleTitle = moduleTitle(aModuleName);
1676 CAM_Module* currentModule = activeModule();
1677 if (currentModule && currentModule->moduleName() == aModuleTitle)
1679 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1682 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1684 // update existing data models (already loaded SComponents)
1687 for ( ModuleListIterator it = modules(); it.current(); ++it )
1689 CAM_DataModel* camDM = it.current()->dataModel();
1690 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1691 ((SalomeApp_DataModel*)camDM)->update();
1694 // update "non-existing" (not loaded yet) data models
1695 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1698 _PTR(Study) stdDS = study->studyDS();
1701 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
1703 _PTR(SComponent) aComponent ( it->Value() );
1705 if ( aComponent->ComponentDataType() == "Interface Applicative" )
1706 continue; // skip the magic "Interface Applicative" component
1708 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
1713 if ( objectBrowser() )
1714 objectBrowser()->updateTree();
1718 //************************************************************
1719 void SalomeApp_Application::onDesktopActivated()
1721 CAM_Application::onDesktopActivated();
1722 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
1724 aModule->studyActivated();
1727 void SalomeApp_Application::createEmptyStudy()
1729 CAM_Application::createEmptyStudy();
1730 if ( objectBrowser() )
1731 objectBrowser()->updateTree();
1734 bool SalomeApp_Application::activateModule( CAM_Module* mod )
1736 bool res = CAM_Application::activateModule( mod );
1737 if ( objectBrowser() )
1738 objectBrowser()->updateTree();