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);
576 void SalomeApp_Application::onRefresh()
578 for ( ModuleListIterator it = modules(); it.current(); ++it )
580 CAM_DataModel* camDM = it.current()->dataModel();
581 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
582 ((SalomeApp_DataModel*)camDM)->update();
584 objectBrowser()->updateTree();
587 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
589 CAM_Application::setActiveStudy( study );
594 //=======================================================================
595 // name : createNewStudy
596 // Purpose : Create new study
597 //=======================================================================
598 SUIT_Study* SalomeApp_Application::createNewStudy()
600 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
602 // Set up processing of major study-related events
603 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
604 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
605 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
606 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
611 //=======================================================================
612 // name : createNewStudy
613 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
614 //=======================================================================
615 void SalomeApp_Application::updateCommandsStatus()
617 CAM_Application::updateCommandsStatus();
619 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
621 QAction* a = action( id );
623 a->setEnabled( activeStudy() );
627 QAction* a = action( LoadScriptId );
629 a->setEnabled( activeStudy() );
631 a = action( PropertiesId );
633 a->setEnabled( activeStudy() );
635 a = action(EditCutId);
636 a->setEnabled(false);
637 a = action(EditCopyId);
638 a->setEnabled(false);
639 a = action(EditPasteId);
640 a->setEnabled(false);
643 //=======================================================================
644 // name : onHelpAbout
645 // Purpose : SLOT. Display "About" message box
646 //=======================================================================
647 void SalomeApp_Application::onHelpAbout()
649 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
654 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
661 if ( !activeStudy() )
664 sId = activeStudy()->id();
667 if ( myWindows.contains( flag ) )
668 wid = myWindows[flag]->widget( sId );
673 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
681 if ( !activeStudy() )
684 sId = activeStudy()->id();
687 if ( !myWindows.contains( flag ) )
689 QMap<int, int> winMap;
690 currentWindows( winMap );
692 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
693 if ( winMap.contains( flag ) )
694 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
696 myWindows[flag]->setResizeEnabled( true );
697 myWindows[flag]->setCloseMode( QDockWindow::Always );
698 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
701 myWindows[flag]->insert( sId, wid );
703 setWindowShown( flag, !myWindows[flag]->isEmpty() );
706 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
708 if ( !myWindows.contains( flag ) )
714 if ( !activeStudy() )
717 sId = activeStudy()->id();
720 QWidget* wid = myWindows[flag]->widget( sId );
721 myWindows[flag]->remove( sId );
724 setWindowShown( flag, !myWindows[flag]->isEmpty() );
727 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
729 QWidget* wid = window( flag, studyId );
731 addWindow( wid = createWindow( flag ), flag, studyId );
736 bool SalomeApp_Application::isWindowVisible( const int type ) const
739 if ( myWindows.contains( type ) )
741 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
742 res = desk && desk->appropriate( myWindows[type] );
747 void SalomeApp_Application::setWindowShown( const int type, const bool on )
749 if ( !desktop() || !myWindows.contains( type ) )
752 QDockWindow* dw = myWindows[type];
753 desktop()->setAppropriate( dw, on );
754 on ? dw->show() : dw->hide();
757 OB_Browser* SalomeApp_Application::objectBrowser()
760 QWidget* wid = getWindow( WT_ObjectBrowser );
761 if ( wid->inherits( "OB_Browser" ) )
762 ob = (OB_Browser*)wid;
766 LogWindow* SalomeApp_Application::logWindow()
769 QWidget* wid = getWindow( WT_LogWindow );
770 if ( wid->inherits( "LogWindow" ) )
771 lw = (LogWindow*)wid;
775 PythonConsole* SalomeApp_Application::pythonConsole()
777 PythonConsole* console = 0;
778 QWidget* wid = getWindow( WT_PyConsole );
779 if ( wid->inherits( "PythonConsole" ) )
780 console = (PythonConsole*)wid;
784 SalomeApp_Preferences* SalomeApp_Application::preferences() const
786 return preferences( false );
789 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
791 SUIT_ViewManager* aVM = viewManager( vmType );
792 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
794 if ( anActiveVM && anActiveVM->getType() == vmType )
799 if ( !aVM->getActiveView() )
802 aVM->getActiveView()->setFocus();
805 aVM = createViewManager( vmType );
810 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
812 SUIT_ResourceMgr* resMgr = resourceMgr();
814 SUIT_ViewManager* viewMgr = 0;
815 if ( vmType == GLViewer_Viewer::Type() )
817 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
818 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
820 else if ( vmType == Plot2d_Viewer::Type() )
822 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
823 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
825 else if ( vmType == OCCViewer_Viewer::Type() )
827 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
828 SOCC_Viewer* vm = new SOCC_Viewer();
829 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
830 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
831 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
832 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
834 else if ( vmType == SVTK_Viewer::Type() )
836 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
837 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
838 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
839 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
845 addViewManager( viewMgr );
846 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
848 if ( viewWin && desktop() )
849 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
851 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
852 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
857 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
859 removeViewManager( theVM );
862 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
864 SUIT_DataObject* aRoot = 0;
865 if ( theStudy && theStudy->root() )
867 aRoot = theStudy->root();
868 //aRoot->setName( tr( "DATA_MODELS" ) );
870 if ( objectBrowser() != 0 )
871 objectBrowser()->setRootObject( aRoot );
873 activateModule( defaultModule() );
878 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
880 SUIT_DataObject* aRoot = 0;
881 if ( theStudy && theStudy->root() )
883 aRoot = theStudy->root();
886 if ( objectBrowser() != 0 ) {
887 objectBrowser()->setRootObject( aRoot );
890 activateModule( defaultModule() );
897 void SalomeApp_Application::onStudySaved( SUIT_Study* )
902 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
906 activateModule( "" );
908 saveWindowsGeometry();
911 void SalomeApp_Application::onLoadScript( )
913 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
914 if ( !appStudy ) return;
915 _PTR(Study) aStudy = appStudy->studyDS();
917 if ( aStudy->GetProperties()->IsLocked() ) {
918 SUIT_MessageBox::warn1 ( desktop(),
919 QObject::tr("WRN_WARNING"),
920 QObject::tr("WRN_STUDY_LOCKED"),
921 QObject::tr("BUT_OK") );
925 QStringList filtersList;
926 filtersList.append(tr("PYTHON_FILES_FILTER"));
927 filtersList.append(tr("ALL_FILES_FILTER"));
929 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_LOADSCRIPT" ), true, true );
931 if ( !aFile.isEmpty() )
933 QString command = QString("execfile(\"%1\")").arg(aFile);
935 PythonConsole* pyConsole = pythonConsole();
938 pyConsole->exec( command );
942 void SalomeApp_Application::onPreferences()
944 QApplication::setOverrideCursor( Qt::waitCursor );
946 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
948 QApplication::restoreOverrideCursor();
958 void SalomeApp_Application::onMRUActivated( QString aName )
963 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
965 SalomeApp_Module* sMod = 0;
966 CAM_Module* mod = module( modName );
967 if ( mod && mod->inherits( "SalomeApp_Module" ) )
968 sMod = (SalomeApp_Module*)mod;
971 sMod->preferencesChanged( section, param );
973 preferencesChanged( section, param );
976 QString SalomeApp_Application::getFileFilter() const
981 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
983 CAM_Application::beforeCloseDoc( s );
985 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
986 removeWindow( itr.key(), s->id() );
989 void SalomeApp_Application::updateActions()
991 updateCommandsStatus();
994 QWidget* SalomeApp_Application::createWindow( const int flag )
998 SUIT_ResourceMgr* resMgr = resourceMgr();
1000 if ( flag == WT_ObjectBrowser )
1002 OB_Browser* ob = new OB_Browser( desktop() );
1003 ob->setAutoUpdate( true );
1004 ob->setAutoOpenLevel( 1 );
1005 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1006 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1007 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1009 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1011 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1013 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1014 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1015 QString().sprintf( "visibility_column_%d", i ), true ) );
1018 // Create OBSelector
1019 new SalomeApp_OBSelector( ob, mySelMgr );
1023 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1025 else if ( flag == WT_PyConsole )
1027 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1028 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1031 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1033 else if ( flag == WT_LogWindow )
1035 LogWindow* logWin = new LogWindow( desktop() );
1036 logWin->setCaption( tr( "LOG_WINDOW" ) );
1039 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1045 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1047 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1048 aMap.insert( WT_PyConsole, Qt::DockBottom );
1049 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1052 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1056 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1061 SalomeApp_Application* that = (SalomeApp_Application*)this;
1063 if ( !_prefs_ && crt )
1065 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1066 that->createPreferences( _prefs_ );
1069 that->myPrefs = _prefs_;
1071 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1072 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1074 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1077 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1079 QStringList modNameList;
1080 app->modules( modNameList, false );
1081 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1083 int id = _prefs_->addPreference( *it );
1084 _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1088 app->modules( modList );
1089 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1091 SalomeApp_Module* mod = 0;
1092 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1093 mod = (SalomeApp_Module*)itr.current();
1095 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1096 mod->createPreferences();
1100 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1101 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1106 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1108 CAM_Application::moduleAdded( mod );
1110 SalomeApp_Module* salomeMod = 0;
1111 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1112 salomeMod = (SalomeApp_Module*)mod;
1114 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1115 salomeMod->createPreferences();
1118 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1123 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1125 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1127 int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1128 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1130 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1131 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1133 pref->setProperty( obGroup, "columns", 1 );
1135 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1137 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1139 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1140 pref->setProperty( occGroup, "columns", 1 );
1141 pref->setProperty( vtkGroup, "columns", 1 );
1143 pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1144 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1145 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1146 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1148 pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1149 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1150 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1151 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1154 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1156 SUIT_ResourceMgr* resMgr = resourceMgr();
1160 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1162 int sz = resMgr->integerValue( sec, param, -1 );
1163 QPtrList<SUIT_ViewManager> lst;
1164 viewManagers( OCCViewer_Viewer::Type(), lst );
1165 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1167 SUIT_ViewModel* vm = it.current()->getViewModel();
1168 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1171 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1172 occVM->setTrihedronSize( sz );
1173 occVM->getAISContext()->UpdateCurrentViewer();
1178 void SalomeApp_Application::afterCloseDoc()
1182 CAM_Application::afterCloseDoc();
1185 CORBA::ORB_var SalomeApp_Application::orb()
1187 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1188 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1192 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1194 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1198 SALOME_NamingService* SalomeApp_Application::namingService()
1200 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1204 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1206 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1210 QString SalomeApp_Application::defaultEngineIOR()
1212 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1213 QString anIOR( "" );
1214 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1215 if ( !CORBA::is_nil( anEngine ) )
1216 anIOR = orb()->object_to_string( anEngine );
1220 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1224 SUIT_ResourceMgr* resMgr = resourceMgr();
1228 QStringList modList;
1229 modules( modList, false );
1231 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1233 QString modName = *it;
1234 QString modIntr = moduleName( modName );
1235 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1237 if ( modIcon.isEmpty() )
1240 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1241 modIcon += QString( ".png" );
1243 iconMap.insert( modName, modIcon );
1247 void SalomeApp_Application::updateModuleActions()
1250 if ( activeModule() )
1251 modName = activeModule()->moduleName();
1253 if ( myActions.contains( modName ) )
1254 myActions[modName]->setOn( true );
1257 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1260 if ( !activeStudy() )
1263 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1264 ((SalomeApp_Module*)activeModule())->windows( winMap );
1266 defaultWindows( winMap );
1269 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1272 if ( !activeStudy() )
1275 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1276 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1278 defaultViewManagers( lst );
1281 void SalomeApp_Application::updateWindows()
1283 QMap<int, int> winMap;
1284 currentWindows( winMap );
1286 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1287 getWindow( it.key() );
1289 loadWindowsGeometry();
1291 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1292 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1295 void SalomeApp_Application::updateViewManagers()
1298 currentViewManagers( lst );
1300 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1301 getViewManager( *it, true );
1304 void SalomeApp_Application::loadWindowsGeometry()
1306 QtxDockAction* dockMgr = 0;
1308 QAction* a = action( ViewWindowsId );
1309 if ( a && a->inherits( "QtxDockAction" ) )
1310 dockMgr = (QtxDockAction*)a;
1316 if ( activeModule() )
1317 modName = moduleLibrary( activeModule()->moduleName(), false );
1319 QString section = QString( "windows_geometry" );
1320 if ( !modName.isEmpty() )
1321 section += QString( "." ) + modName;
1323 dockMgr->loadGeometry( resourceMgr(), section, false );
1324 dockMgr->restoreGeometry();
1327 void SalomeApp_Application::saveWindowsGeometry()
1329 QtxDockAction* dockMgr = 0;
1331 QAction* a = action( ViewWindowsId );
1332 if ( a && a->inherits( "QtxDockAction" ) )
1333 dockMgr = (QtxDockAction*)a;
1339 if ( activeModule() )
1340 modName = moduleLibrary( activeModule()->moduleName(), false );
1342 QString section = QString( "windows_geometry" );
1343 if ( !modName.isEmpty() )
1344 section += QString( "." ) + modName;
1346 dockMgr->storeGeometry();
1347 dockMgr->saveGeometry( resourceMgr(), section, false );
1350 void SalomeApp_Application::activateWindows()
1352 if ( activeStudy() )
1354 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1355 itr.data()->activate( activeStudy()->id() );
1359 void SalomeApp_Application::onProperties()
1361 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1365 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1368 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1369 int res = aDlg.exec();
1370 if( res==QDialog::Accepted && aDlg.isChanged() )
1371 SB->CommitCommand();
1375 //study->updateCaptions();
1378 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1379 const QString& caption, QWidget* parent )
1383 QStringList fls = QStringList::split( ";;", filters, false );
1384 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1387 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1391 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1394 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1396 CAM_Application::contextMenuPopup( type, thePopup, title );
1397 thePopup->insertSeparator();
1398 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );