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"
24 #include "SalomeApp_GLSelector.h"
25 #include "SalomeApp_OBSelector.h"
26 #include "SalomeApp_OCCSelector.h"
27 #include "SalomeApp_VTKSelector.h"
28 #include "SalomeApp_SelectionMgr.h"
30 #include <LogWindow.h>
32 #include <GLViewer_Viewer.h>
33 #include <GLViewer_ViewManager.h>
35 #include <Plot2d_ViewManager.h>
36 #include <SPlot2d_ViewModel.h>
38 #include <OCCViewer_ViewManager.h>
39 #include <SOCC_ViewModel.h>
41 #include <SVTK_ViewModel.h>
42 #include <SVTK_ViewManager.h>
44 #include <STD_TabDesktop.h>
46 #include <SUIT_Tools.h>
47 #include <SUIT_Session.h>
49 #include <QtxToolBar.h>
50 #include <QtxMRUAction.h>
51 #include <QtxDockAction.h>
52 #include <QtxResourceEdit.h>
54 #include <OB_Browser.h>
56 #include <PythonConsole_PyConsole.h>
58 #include <SUIT_FileDlg.h>
59 #include <SUIT_MessageBox.h>
60 #include <SUIT_ResourceMgr.h>
61 #include <SUIT_ActionOperation.h>
63 #include <Utils_ORB_INIT.hxx>
64 #include <Utils_SINGLETON.hxx>
65 #include <SALOME_ModuleCatalog_impl.hxx>
66 #include <SALOME_LifeCycleCORBA.hxx>
74 #include <qcombobox.h>
75 #include <qmessagebox.h>
76 #include <qapplication.h>
78 #include "SALOMEDS_StudyManager.hxx"
80 #include "SALOME_ListIteratorOfListIO.hxx"
81 #include "SALOME_ListIO.hxx"
83 #define OBJECT_BROWSER_WIDTH 300
85 static const char* imageEmptyIcon[] = {
88 "....................",
89 "....................",
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "...................."};
109 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
111 return new SalomeApp_Application();
114 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
117 Class : SalomeApp_Application
118 Description : Application containing SalomeApp module
121 SalomeApp_Application::SalomeApp_Application()
122 : CAM_Application( false ),
125 STD_TabDesktop* desk = new STD_TabDesktop();
129 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
130 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
132 desktop()->setIcon( aLogo );
133 desktop()->setDockableMenuBar( true );
134 desktop()->setDockableStatusBar( false );
138 mySelMgr = new SalomeApp_SelectionMgr( this );
140 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
141 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
143 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
146 SalomeApp_Application::~SalomeApp_Application()
148 saveWindowsGeometry();
153 desktop()->saveGeometry( resourceMgr(), "desktop" );
154 resourceMgr()->save();
159 SalomeApp_EventFilter::Destroy();
162 void SalomeApp_Application::start()
165 desktop()->loadGeometry( resourceMgr(), "desktop" );
167 CAM_Application::start();
169 QAction* a = action( ViewWindowsId );
170 if ( a && a->inherits( "QtxDockAction" ) )
171 ((QtxDockAction*)a)->setAutoPlace( true );
173 SalomeApp_EventFilter::Init();
176 updateViewManagers();
181 QString SalomeApp_Application::applicationName() const
183 return tr( "APP_NAME" );
186 QString SalomeApp_Application::applicationVersion() const
188 static QString _app_version;
190 if ( _app_version.isEmpty() )
192 QString path( ::getenv( "GUI_ROOT_DIR" ) );
193 if ( !path.isEmpty() )
194 path += QDir::separator();
195 path += QString( "bin/salome/VERSION" );
198 if ( vf.open( IO_ReadOnly ) )
201 vf.readLine( line, 1024 );
204 if ( !line.isEmpty() )
206 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
207 line.remove( line.length() - 1, 1 );
209 int idx = line.findRev( ":" );
211 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
219 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
221 CAM_Module* mod = CAM_Application::loadModule( name );
224 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
225 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
226 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
231 bool SalomeApp_Application::activateModule( const QString& modName )
234 CAM_Module* prevMod = activeModule();
237 actName = prevMod->moduleName();
239 if ( actName == modName )
242 saveWindowsGeometry();
244 bool status = CAM_Application::activateModule( modName );
246 updateModuleActions();
252 updateViewManagers();
257 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
262 void SalomeApp_Application::createActions()
264 STD_Application::createActions();
266 SUIT_Desktop* desk = desktop();
267 SUIT_ResourceMgr* resMgr = resourceMgr();
270 createAction( LoadScriptId, tr( "TOT_DESK_LOADSCRIPT" ), QIconSet(),
271 tr( "MEN_DESK_LOADSCRIPT" ), tr( "PRP_DESK_LOADSCRIPT" ),
272 0, desk, false, this, SLOT( onLoadScript() ) );
275 createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
276 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
277 0, desk, false, this, SLOT( onProperties() ) );
280 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
281 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
282 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
285 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
286 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
287 registerAction( MRUId, mru );
289 // default icon for neutral point ('SALOME' module)
290 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
291 if ( defIcon.isNull() )
292 defIcon = QPixmap( imageEmptyIcon );
294 // default icon for any module
295 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
296 if ( modIcon.isNull() )
297 modIcon = QPixmap( imageEmptyIcon );
299 QToolBar* modTBar = new QtxToolBar( true, desk );
300 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
302 QActionGroup* modGroup = new QActionGroup( this );
303 modGroup->setExclusive( true );
304 modGroup->setUsesDropDown( true );
306 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
307 tr( "PRP_APP_MODULE" ), 0, desk, true );
309 myActions.insert( QString(), a );
311 QMap<QString, QString> iconMap;
312 moduleIconNames( iconMap );
314 const int iconSize = 20;
316 modGroup->addTo( modTBar );
317 modTBar->addSeparator();
320 modules( modList, false );
322 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
324 if ( (*it).isEmpty() )
328 if ( iconMap.contains( *it ) )
329 iconName = iconMap[*it];
331 QString modName = moduleName( *it );
333 QPixmap icon = resMgr->loadPixmap( modName, iconName );
337 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
339 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
343 myActions.insert( *it, a );
346 SUIT_Tools::simplifySeparators( modTBar );
350 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
351 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
352 createMenu( separator(), windowMenu, -1, 1 );
354 QMap<int, int> accelMap;
355 accelMap[NewGLViewId] = ALT+Key_G;
356 accelMap[NewPlot2dId] = ALT+Key_P;
357 accelMap[NewOCCViewId] = ALT+Key_O;
358 accelMap[NewVTKViewId] = ALT+Key_K;
360 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
362 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
363 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
364 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
365 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
366 createMenu( a, newWinMenu, -1 );
368 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
372 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
374 createMenu( separator(), fileMenu, -1, 15, -1 );
375 createMenu( LoadScriptId, fileMenu, 15, -1 );
376 createMenu( separator(), fileMenu, -1, 15, -1 );
377 createMenu( PropertiesId, fileMenu, 10, -1 );
378 createMenu( separator(), fileMenu, -1, 15, -1 );
379 createMenu( PreferencesId, fileMenu, 15, -1 );
380 createMenu( separator(), fileMenu, -1, 15, -1 );
383 createMenu( separator(), fileMenu, -1, 100, -1 );
384 createMenu( MRUId, fileMenu, 100, -1 );
385 createMenu( separator(), fileMenu, -1, 100, -1 );
389 void SalomeApp_Application::onModuleActivation( QAction* a )
394 QString modName = a->menuText();
395 if ( modName == tr( "APP_NAME" ) )
396 modName = QString::null;
398 // Force user to create/open a study before module activation
399 QMap<QString, QString> iconMap;
400 moduleIconNames( iconMap );
401 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
403 bool cancelled = false;
404 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
405 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
406 int res = aDlg.exec();
420 putInfo( tr("INF_CANCELLED") );
421 myActions[QString()]->setOn( true );
427 activateModule( modName );
430 QString SalomeApp_Application::defaultModule() const
432 QStringList aModuleNames;
433 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
434 // If there's the one and only module --> activate it automatically
435 // TODO: Possible improvement - default module can be taken from preferences
436 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
439 void SalomeApp_Application::onNewWindow()
441 const QObject* obj = sender();
442 if ( !obj || !obj->inherits( "QAction" ) )
446 int id = actionId( (QAction*)obj );
450 type = GLViewer_Viewer::Type();
453 type = Plot2d_Viewer::Type();
456 type = OCCViewer_Viewer::Type();
459 type = VTKViewer_Viewer::Type();
463 if ( !type.isEmpty() )
464 createViewManager( type );
467 //=======================================================================
469 // Purpose : SLOT. Create new document
470 //=======================================================================
471 void SalomeApp_Application::onNewDoc()
473 SUIT_Study* study = activeStudy();
475 saveWindowsGeometry();
477 CAM_Application::onNewDoc();
479 if ( !study ) // new study will be create in THIS application
482 updateViewManagers();
486 //=======================================================================
488 // Purpose : SLOT. Open new document
489 //=======================================================================
490 void SalomeApp_Application::onOpenDoc()
492 SUIT_Study* study = activeStudy();
493 saveWindowsGeometry();
495 CAM_Application::onOpenDoc();
497 if ( !study ) // new study will be create in THIS application
500 updateViewManagers();
504 bool SalomeApp_Application::onOpenDoc( const QString& aName )
506 bool res = CAM_Application::onOpenDoc( aName );
508 QAction* a = action( MRUId );
509 if ( a && a->inherits( "QtxMRUAction" ) )
511 QtxMRUAction* mru = (QtxMRUAction*)a;
513 mru->insert( aName );
515 mru->remove( aName );
520 void SalomeApp_Application::onSelection()
522 onSelectionChanged();
524 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
525 ((SalomeApp_Module*)activeModule())->selectionChanged();
528 void SalomeApp_Application::onSelectionChanged()
531 SalomeApp_Module* module = dynamic_cast<SalomeApp_Module*>(activeModule());
532 if(module == NULL) return;
534 QString ior = module->engineIOR();
535 if(ior.length() < 5) return; //Not a real CORBA IOR
536 CORBA::Object_var obj = orb()->string_to_object(ior.latin1());
537 if(CORBA::is_nil(obj)) return;
539 SALOMEDS::Driver_var engine = SALOMEDS::Driver::_narrow(obj);
540 if(CORBA::is_nil(engine)) return;
544 SalomeApp_SelectionMgr* mgr = selectionMgr();
545 mgr->selectedObjects(list);
547 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
548 if(study == NULL) return;
550 _PTR(Study) stdDS = study->studyDS();
555 for ( SALOME_ListIteratorOfListIO it( list ); it.More(); it.Next() )
557 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
558 qaction = action(EditCutId);
559 if( studyMgr()->CanCopy(so) ) {
560 qaction->setEnabled(true);
561 qaction = action(EditCopyId);
562 qaction->setEnabled(true);
565 qaction->setEnabled(false);
566 qaction = action(EditCopyId);
567 qaction->setEnabled(false);
569 qaction = action(EditPasteId);
570 if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
571 else qaction->setEnabled(false);
575 void SalomeApp_Application::onRefresh()
577 updateObjectBrowser( true );
580 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
582 CAM_Application::setActiveStudy( study );
587 //=======================================================================
588 // name : createNewStudy
589 // Purpose : Create new study
590 //=======================================================================
591 SUIT_Study* SalomeApp_Application::createNewStudy()
593 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
595 // Set up processing of major study-related events
596 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
597 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
598 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
599 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
604 //=======================================================================
605 // name : createNewStudy
606 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
607 //=======================================================================
608 void SalomeApp_Application::updateCommandsStatus()
610 CAM_Application::updateCommandsStatus();
612 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
614 QAction* a = action( id );
616 a->setEnabled( activeStudy() );
620 QAction* a = action( LoadScriptId );
622 a->setEnabled( activeStudy() );
624 a = action( PropertiesId );
626 a->setEnabled( activeStudy() );
628 a = action(EditCutId);
629 a->setEnabled(false);
630 a = action(EditCopyId);
631 a->setEnabled(false);
632 a = action(EditPasteId);
633 a->setEnabled(false);
636 //=======================================================================
637 // name : onHelpAbout
638 // Purpose : SLOT. Display "About" message box
639 //=======================================================================
640 void SalomeApp_Application::onHelpAbout()
642 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
647 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
654 if ( !activeStudy() )
657 sId = activeStudy()->id();
660 if ( myWindows.contains( flag ) )
661 wid = myWindows[flag]->widget( sId );
666 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
674 if ( !activeStudy() )
677 sId = activeStudy()->id();
680 if ( !myWindows.contains( flag ) )
682 QMap<int, int> winMap;
683 currentWindows( winMap );
685 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
686 if ( winMap.contains( flag ) )
687 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
689 myWindows[flag]->setResizeEnabled( true );
690 myWindows[flag]->setCloseMode( QDockWindow::Always );
691 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
694 myWindows[flag]->insert( sId, wid );
696 setWindowShown( flag, !myWindows[flag]->isEmpty() );
699 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
701 if ( !myWindows.contains( flag ) )
707 if ( !activeStudy() )
710 sId = activeStudy()->id();
713 QWidget* wid = myWindows[flag]->widget( sId );
714 myWindows[flag]->remove( sId );
717 setWindowShown( flag, !myWindows[flag]->isEmpty() );
720 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
722 QWidget* wid = window( flag, studyId );
724 addWindow( wid = createWindow( flag ), flag, studyId );
729 bool SalomeApp_Application::isWindowVisible( const int type ) const
732 if ( myWindows.contains( type ) )
734 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
735 res = desk && desk->appropriate( myWindows[type] );
740 void SalomeApp_Application::setWindowShown( const int type, const bool on )
742 if ( !desktop() || !myWindows.contains( type ) )
745 QDockWindow* dw = myWindows[type];
746 desktop()->setAppropriate( dw, on );
747 on ? dw->show() : dw->hide();
750 OB_Browser* SalomeApp_Application::objectBrowser()
753 QWidget* wid = getWindow( WT_ObjectBrowser );
754 if ( wid->inherits( "OB_Browser" ) )
755 ob = (OB_Browser*)wid;
759 LogWindow* SalomeApp_Application::logWindow()
762 QWidget* wid = getWindow( WT_LogWindow );
763 if ( wid->inherits( "LogWindow" ) )
764 lw = (LogWindow*)wid;
768 PythonConsole* SalomeApp_Application::pythonConsole()
770 PythonConsole* console = 0;
771 QWidget* wid = getWindow( WT_PyConsole );
772 if ( wid->inherits( "PythonConsole" ) )
773 console = (PythonConsole*)wid;
777 SalomeApp_Preferences* SalomeApp_Application::preferences() const
779 return preferences( false );
782 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
784 SUIT_ViewManager* aVM = viewManager( vmType );
785 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
787 if ( anActiveVM && anActiveVM->getType() == vmType )
792 if ( !aVM->getActiveView() )
795 aVM->getActiveView()->setFocus();
798 aVM = createViewManager( vmType );
803 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
805 SUIT_ResourceMgr* resMgr = resourceMgr();
807 SUIT_ViewManager* viewMgr = 0;
808 if ( vmType == GLViewer_Viewer::Type() )
810 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
811 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
813 else if ( vmType == Plot2d_Viewer::Type() )
815 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
816 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
818 else if ( vmType == OCCViewer_Viewer::Type() )
820 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
821 SOCC_Viewer* vm = new SOCC_Viewer();
822 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
823 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
824 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
825 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
827 else if ( vmType == SVTK_Viewer::Type() )
829 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
830 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
831 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
832 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
838 addViewManager( viewMgr );
839 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
841 if ( viewWin && desktop() )
842 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
844 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
845 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
850 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
852 removeViewManager( theVM );
855 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
857 SUIT_DataObject* aRoot = 0;
858 if ( theStudy && theStudy->root() )
860 aRoot = theStudy->root();
861 //aRoot->setName( tr( "DATA_MODELS" ) );
863 if ( objectBrowser() != 0 )
864 objectBrowser()->setRootObject( aRoot );
866 activateModule( defaultModule() );
871 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
873 SUIT_DataObject* aRoot = 0;
874 if ( theStudy && theStudy->root() )
876 aRoot = theStudy->root();
879 if ( objectBrowser() != 0 ) {
880 objectBrowser()->setRootObject( aRoot );
883 activateModule( defaultModule() );
890 void SalomeApp_Application::onStudySaved( SUIT_Study* )
895 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
899 activateModule( "" );
901 saveWindowsGeometry();
904 void SalomeApp_Application::onLoadScript( )
906 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
907 if ( !appStudy ) return;
908 _PTR(Study) aStudy = appStudy->studyDS();
910 if ( aStudy->GetProperties()->IsLocked() ) {
911 SUIT_MessageBox::warn1 ( desktop(),
912 QObject::tr("WRN_WARNING"),
913 QObject::tr("WRN_STUDY_LOCKED"),
914 QObject::tr("BUT_OK") );
918 QStringList filtersList;
919 filtersList.append(tr("PYTHON_FILES_FILTER"));
920 filtersList.append(tr("ALL_FILES_FILTER"));
922 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_LOADSCRIPT" ), true, true );
924 if ( !aFile.isEmpty() )
926 QString command = QString("execfile(\"%1\")").arg(aFile);
928 PythonConsole* pyConsole = pythonConsole();
931 pyConsole->exec( command );
935 void SalomeApp_Application::onPreferences()
937 QApplication::setOverrideCursor( Qt::waitCursor );
939 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
941 QApplication::restoreOverrideCursor();
951 void SalomeApp_Application::onMRUActivated( QString aName )
956 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
958 SalomeApp_Module* sMod = 0;
959 CAM_Module* mod = module( modName );
960 if ( mod && mod->inherits( "SalomeApp_Module" ) )
961 sMod = (SalomeApp_Module*)mod;
964 sMod->preferencesChanged( section, param );
966 preferencesChanged( section, param );
969 QString SalomeApp_Application::getFileFilter() const
974 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
976 CAM_Application::beforeCloseDoc( s );
978 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
979 removeWindow( itr.key(), s->id() );
982 void SalomeApp_Application::updateActions()
984 updateCommandsStatus();
987 QWidget* SalomeApp_Application::createWindow( const int flag )
991 SUIT_ResourceMgr* resMgr = resourceMgr();
993 if ( flag == WT_ObjectBrowser )
995 OB_Browser* ob = new OB_Browser( desktop() );
996 ob->setAutoUpdate( true );
997 ob->setAutoOpenLevel( 1 );
998 ob->setCaption( tr( "OBJECT_BROWSER" ) );
999 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1000 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1002 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1004 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1006 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1007 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1008 QString().sprintf( "visibility_column_%d", i ), true ) );
1011 // Create OBSelector
1012 new SalomeApp_OBSelector( ob, mySelMgr );
1016 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1018 else if ( flag == WT_PyConsole )
1020 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1021 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1024 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1026 else if ( flag == WT_LogWindow )
1028 LogWindow* logWin = new LogWindow( desktop() );
1029 logWin->setCaption( tr( "LOG_WINDOW" ) );
1032 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1038 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1040 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1041 aMap.insert( WT_PyConsole, Qt::DockBottom );
1042 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1045 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1049 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1054 SalomeApp_Application* that = (SalomeApp_Application*)this;
1056 if ( !_prefs_ && crt )
1058 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1059 that->createPreferences( _prefs_ );
1062 that->myPrefs = _prefs_;
1064 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1065 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1067 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1070 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1072 QStringList modNameList;
1073 app->modules( modNameList, false );
1074 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1076 int id = _prefs_->addPreference( *it );
1077 _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1081 app->modules( modList );
1082 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1084 SalomeApp_Module* mod = 0;
1085 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1086 mod = (SalomeApp_Module*)itr.current();
1088 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1089 mod->createPreferences();
1093 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1094 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1099 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1101 CAM_Application::moduleAdded( mod );
1103 SalomeApp_Module* salomeMod = 0;
1104 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1105 salomeMod = (SalomeApp_Module*)mod;
1107 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1108 salomeMod->createPreferences();
1111 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1116 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1118 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1120 int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1121 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1123 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1124 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1126 pref->setProperty( obGroup, "columns", 1 );
1128 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1130 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1132 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1133 pref->setProperty( occGroup, "columns", 1 );
1134 pref->setProperty( vtkGroup, "columns", 1 );
1136 pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1137 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1138 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1139 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1141 pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1142 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1143 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1144 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1147 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1149 SUIT_ResourceMgr* resMgr = resourceMgr();
1153 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1155 int sz = resMgr->integerValue( sec, param, -1 );
1156 QPtrList<SUIT_ViewManager> lst;
1157 viewManagers( OCCViewer_Viewer::Type(), lst );
1158 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1160 SUIT_ViewModel* vm = it.current()->getViewModel();
1161 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1164 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1165 occVM->setTrihedronSize( sz );
1166 occVM->getAISContext()->UpdateCurrentViewer();
1171 void SalomeApp_Application::afterCloseDoc()
1175 CAM_Application::afterCloseDoc();
1178 CORBA::ORB_var SalomeApp_Application::orb()
1180 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1181 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1185 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1187 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1191 SALOME_NamingService* SalomeApp_Application::namingService()
1193 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1197 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1199 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1203 QString SalomeApp_Application::defaultEngineIOR()
1205 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1206 QString anIOR( "" );
1207 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1208 if ( !CORBA::is_nil( anEngine ) )
1209 anIOR = orb()->object_to_string( anEngine );
1213 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1217 SUIT_ResourceMgr* resMgr = resourceMgr();
1221 QStringList modList;
1222 modules( modList, false );
1224 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1226 QString modName = *it;
1227 QString modIntr = moduleName( modName );
1228 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1230 if ( modIcon.isEmpty() )
1233 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1234 modIcon += QString( ".png" );
1236 iconMap.insert( modName, modIcon );
1240 void SalomeApp_Application::updateModuleActions()
1243 if ( activeModule() )
1244 modName = activeModule()->moduleName();
1246 if ( myActions.contains( modName ) )
1247 myActions[modName]->setOn( true );
1250 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1253 if ( !activeStudy() )
1256 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1257 ((SalomeApp_Module*)activeModule())->windows( winMap );
1259 defaultWindows( winMap );
1262 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1265 if ( !activeStudy() )
1268 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1269 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1271 defaultViewManagers( lst );
1274 void SalomeApp_Application::updateWindows()
1276 QMap<int, int> winMap;
1277 currentWindows( winMap );
1279 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1280 getWindow( it.key() );
1282 loadWindowsGeometry();
1284 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1285 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1288 void SalomeApp_Application::updateViewManagers()
1291 currentViewManagers( lst );
1293 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1294 getViewManager( *it, true );
1297 void SalomeApp_Application::loadWindowsGeometry()
1299 QtxDockAction* dockMgr = 0;
1301 QAction* a = action( ViewWindowsId );
1302 if ( a && a->inherits( "QtxDockAction" ) )
1303 dockMgr = (QtxDockAction*)a;
1309 if ( activeModule() )
1310 modName = moduleLibrary( activeModule()->moduleName(), false );
1312 QString section = QString( "windows_geometry" );
1313 if ( !modName.isEmpty() )
1314 section += QString( "." ) + modName;
1316 dockMgr->loadGeometry( resourceMgr(), section, false );
1317 dockMgr->restoreGeometry();
1320 void SalomeApp_Application::saveWindowsGeometry()
1322 QtxDockAction* dockMgr = 0;
1324 QAction* a = action( ViewWindowsId );
1325 if ( a && a->inherits( "QtxDockAction" ) )
1326 dockMgr = (QtxDockAction*)a;
1332 if ( activeModule() )
1333 modName = moduleLibrary( activeModule()->moduleName(), false );
1335 QString section = QString( "windows_geometry" );
1336 if ( !modName.isEmpty() )
1337 section += QString( "." ) + modName;
1339 dockMgr->storeGeometry();
1340 dockMgr->saveGeometry( resourceMgr(), section, false );
1343 void SalomeApp_Application::activateWindows()
1345 if ( activeStudy() )
1347 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1348 itr.data()->activate( activeStudy()->id() );
1352 void SalomeApp_Application::onProperties()
1354 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1358 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1361 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1362 int res = aDlg.exec();
1363 if( res==QDialog::Accepted && aDlg.isChanged() )
1364 SB->CommitCommand();
1368 //study->updateCaptions();
1371 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1372 const QString& caption, QWidget* parent )
1376 QStringList fls = QStringList::split( ";;", filters, false );
1377 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1380 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1384 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1387 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1388 const QString& caption, QWidget* parent )
1392 QStringList fls = QStringList::split( ";;", filters, false );
1393 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1396 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1398 CAM_Application::contextMenuPopup( type, thePopup, title );
1399 thePopup->insertSeparator();
1400 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1403 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1407 for ( ModuleListIterator it = modules(); it.current(); ++it )
1409 CAM_DataModel* camDM = it.current()->dataModel();
1410 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1411 ((SalomeApp_DataModel*)camDM)->update();
1414 if ( objectBrowser() )
1415 objectBrowser()->updateTree();