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 <SUIT_Tools.h>
48 #include <SUIT_Session.h>
50 #include <QtxToolBar.h>
51 #include <QtxMRUAction.h>
52 #include <QtxDockAction.h>
53 #include <QtxResourceEdit.h>
55 #include <OB_Browser.h>
57 #include <PythonConsole_PyConsole.h>
59 #include <SUIT_FileDlg.h>
60 #include <SUIT_MessageBox.h>
61 #include <SUIT_ResourceMgr.h>
62 #include <SUIT_ActionOperation.h>
64 #include <Utils_ORB_INIT.hxx>
65 #include <Utils_SINGLETON.hxx>
66 #include <SALOME_ModuleCatalog_impl.hxx>
67 #include <SALOME_LifeCycleCORBA.hxx>
75 #include <qcombobox.h>
76 #include <qmessagebox.h>
77 #include <qapplication.h>
79 #include "SALOMEDS_StudyManager.hxx"
81 #include "SALOME_ListIteratorOfListIO.hxx"
82 #include "SALOME_ListIO.hxx"
84 #define OBJECT_BROWSER_WIDTH 300
86 static const char* imageEmptyIcon[] = {
89 "....................",
90 "....................",
91 "....................",
92 "....................",
93 "....................",
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "...................."};
110 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
112 return new SalomeApp_Application();
115 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
118 Class : SalomeApp_Application
119 Description : Application containing SalomeApp module
122 SalomeApp_Application::SalomeApp_Application()
123 : CAM_Application( false ),
126 STD_TabDesktop* desk = new STD_TabDesktop();
130 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
131 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
133 desktop()->setIcon( aLogo );
134 desktop()->setDockableMenuBar( true );
135 desktop()->setDockableStatusBar( false );
139 mySelMgr = new SalomeApp_SelectionMgr( this );
141 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
142 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
144 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
147 SalomeApp_Application::~SalomeApp_Application()
149 saveWindowsGeometry();
154 desktop()->saveGeometry( resourceMgr(), "desktop" );
155 resourceMgr()->save();
160 SalomeApp_EventFilter::Destroy();
163 void SalomeApp_Application::start()
166 desktop()->loadGeometry( resourceMgr(), "desktop" );
168 CAM_Application::start();
170 QAction* a = action( ViewWindowsId );
171 if ( a && a->inherits( "QtxDockAction" ) )
172 ((QtxDockAction*)a)->setAutoPlace( true );
174 SalomeApp_EventFilter::Init();
177 updateViewManagers();
182 QString SalomeApp_Application::applicationName() const
184 return tr( "APP_NAME" );
187 QString SalomeApp_Application::applicationVersion() const
189 static QString _app_version;
191 if ( _app_version.isEmpty() )
193 QString path( ::getenv( "GUI_ROOT_DIR" ) );
194 if ( !path.isEmpty() )
195 path += QDir::separator();
196 path += QString( "bin/salome/VERSION" );
199 if ( vf.open( IO_ReadOnly ) )
202 vf.readLine( line, 1024 );
205 if ( !line.isEmpty() )
207 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
208 line.remove( line.length() - 1, 1 );
210 int idx = line.findRev( ":" );
212 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
220 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
222 CAM_Module* mod = CAM_Application::loadModule( name );
225 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
226 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
227 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
232 bool SalomeApp_Application::activateModule( const QString& modName )
235 CAM_Module* prevMod = activeModule();
238 actName = prevMod->moduleName();
240 if ( actName == modName )
243 saveWindowsGeometry();
245 bool status = CAM_Application::activateModule( modName );
247 updateModuleActions();
253 updateViewManagers();
258 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
263 void SalomeApp_Application::createActions()
265 STD_Application::createActions();
267 SUIT_Desktop* desk = desktop();
268 SUIT_ResourceMgr* resMgr = resourceMgr();
271 createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
272 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
273 0, desk, false, this, SLOT( onDumpStudy() ) );
276 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
277 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
278 0, desk, false, this, SLOT( onLoadScript() ) );
281 createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
282 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
283 0, desk, false, this, SLOT( onProperties() ) );
286 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
287 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
288 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
291 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
292 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
293 registerAction( MRUId, mru );
295 // default icon for neutral point ('SALOME' module)
296 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) );
297 if ( defIcon.isNull() )
298 defIcon = QPixmap( imageEmptyIcon );
300 // default icon for any module
301 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) );
302 if ( modIcon.isNull() )
303 modIcon = QPixmap( imageEmptyIcon );
305 QToolBar* modTBar = new QtxToolBar( true, desk );
306 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
308 QActionGroup* modGroup = new QActionGroup( this );
309 modGroup->setExclusive( true );
310 modGroup->setUsesDropDown( true );
312 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
313 tr( "PRP_APP_MODULE" ), 0, desk, true );
315 myActions.insert( QString(), a );
317 QMap<QString, QString> iconMap;
318 moduleIconNames( iconMap );
320 const int iconSize = 20;
322 modGroup->addTo( modTBar );
323 modTBar->addSeparator();
326 modules( modList, false );
328 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
330 if ( (*it).isEmpty() )
334 if ( iconMap.contains( *it ) )
335 iconName = iconMap[*it];
337 QString modName = moduleName( *it );
339 QPixmap icon = resMgr->loadPixmap( modName, iconName );
343 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
345 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
349 myActions.insert( *it, a );
352 SUIT_Tools::simplifySeparators( modTBar );
356 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
357 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
358 createMenu( separator(), windowMenu, -1, 1 );
360 QMap<int, int> accelMap;
361 accelMap[NewGLViewId] = ALT+Key_G;
362 accelMap[NewPlot2dId] = ALT+Key_P;
363 accelMap[NewOCCViewId] = ALT+Key_O;
364 accelMap[NewVTKViewId] = ALT+Key_K;
366 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
368 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
369 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
370 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
371 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
372 createMenu( a, newWinMenu, -1 );
374 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
376 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
378 createMenu( DumpStudyId, fileMenu, 10, -1 );
379 createMenu( separator(), fileMenu, -1, 15, -1 );
380 createMenu( LoadScriptId, fileMenu, 10, -1 );
381 createMenu( separator(), fileMenu, -1, 15, -1 );
382 createMenu( PropertiesId, fileMenu, 10, -1 );
383 createMenu( separator(), fileMenu, -1, 15, -1 );
384 createMenu( PreferencesId, fileMenu, 15, -1 );
385 createMenu( separator(), fileMenu, -1, 15, -1 );
388 createMenu( separator(), fileMenu, -1, 100, -1 );
389 createMenu( MRUId, fileMenu, 100, -1 );
390 createMenu( separator(), fileMenu, -1, 100, -1 );
394 void SalomeApp_Application::onModuleActivation( QAction* a )
399 QString modName = a->menuText();
400 if ( modName == tr( "APP_NAME" ) )
401 modName = QString::null;
403 // Force user to create/open a study before module activation
404 QMap<QString, QString> iconMap;
405 moduleIconNames( iconMap );
406 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] );
408 bool cancelled = false;
409 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
410 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
411 int res = aDlg.exec();
425 putInfo( tr("INF_CANCELLED") );
426 myActions[QString()]->setOn( true );
432 activateModule( modName );
435 QString SalomeApp_Application::defaultModule() const
437 QStringList aModuleNames;
438 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
439 // If there's the one and only module --> activate it automatically
440 // TODO: Possible improvement - default module can be taken from preferences
441 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
444 void SalomeApp_Application::onNewWindow()
446 const QObject* obj = sender();
447 if ( !obj || !obj->inherits( "QAction" ) )
451 int id = actionId( (QAction*)obj );
455 type = GLViewer_Viewer::Type();
458 type = Plot2d_Viewer::Type();
461 type = OCCViewer_Viewer::Type();
464 type = VTKViewer_Viewer::Type();
468 if ( !type.isEmpty() )
469 createViewManager( type );
472 //=======================================================================
474 // Purpose : SLOT. Create new document
475 //=======================================================================
476 void SalomeApp_Application::onNewDoc()
478 SUIT_Study* study = activeStudy();
480 saveWindowsGeometry();
482 CAM_Application::onNewDoc();
484 if ( !study ) // new study will be create in THIS application
487 updateViewManagers();
491 //=======================================================================
493 // Purpose : SLOT. Open new document
494 //=======================================================================
495 void SalomeApp_Application::onOpenDoc()
497 SUIT_Study* study = activeStudy();
498 saveWindowsGeometry();
500 CAM_Application::onOpenDoc();
502 if ( !study ) // new study will be create in THIS application
505 updateViewManagers();
509 bool SalomeApp_Application::onOpenDoc( const QString& aName )
511 bool res = CAM_Application::onOpenDoc( aName );
513 QAction* a = action( MRUId );
514 if ( a && a->inherits( "QtxMRUAction" ) )
516 QtxMRUAction* mru = (QtxMRUAction*)a;
518 mru->insert( aName );
520 mru->remove( aName );
525 void SalomeApp_Application::onSelection()
527 onSelectionChanged();
529 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
530 ((SalomeApp_Module*)activeModule())->selectionChanged();
533 void SalomeApp_Application::onSelectionChanged()
536 SalomeApp_Module* module = dynamic_cast<SalomeApp_Module*>(activeModule());
537 if(module == NULL) return;
539 QString ior = module->engineIOR();
540 if(ior.length() < 5) return; //Not a real CORBA IOR
541 CORBA::Object_var obj = orb()->string_to_object(ior.latin1());
542 if(CORBA::is_nil(obj)) return;
544 SALOMEDS::Driver_var engine = SALOMEDS::Driver::_narrow(obj);
545 if(CORBA::is_nil(engine)) return;
549 SalomeApp_SelectionMgr* mgr = selectionMgr();
550 mgr->selectedObjects(list);
552 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
553 if(study == NULL) return;
555 _PTR(Study) stdDS = study->studyDS();
559 //Varibales isEnabledCopy and isEnabledPaste are used for multi selection.
560 bool isEnabledCopy = true;
561 bool isEnabledPaste = true;
563 for ( SALOME_ListIteratorOfListIO it( list ); it.More() && (isEnabledCopy || isEnabledPaste); it.Next() )
565 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
567 qaction = action(EditCopyId);
568 if( isEnabledCopy && studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
570 isEnabledCopy = false;
571 qaction->setEnabled(false);
574 qaction = action(EditPasteId);
575 if( isEnabledPaste && studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
577 isEnabledPaste = false;
578 qaction->setEnabled(false);
583 void SalomeApp_Application::onRefresh()
585 updateObjectBrowser( true );
589 void SalomeApp_Application::onOpenWith()
591 QApplication::setOverrideCursor( Qt::waitCursor );
593 SalomeApp_SelectionMgr* mgr = selectionMgr();
594 mgr->selectedObjects(aList);
595 if (aList.Extent() > 1) return;
596 Handle(SALOME_InteractiveObject) aIObj = aList.First();
597 QString aModuleName(aIObj->getComponentDataType());
598 QString aModuleTitle = moduleTitle(aModuleName);
599 activateModule(aModuleTitle);
600 QApplication::restoreOverrideCursor();
603 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
605 CAM_Application::setActiveStudy( study );
610 //=======================================================================
611 // name : createNewStudy
612 // Purpose : Create new study
613 //=======================================================================
614 SUIT_Study* SalomeApp_Application::createNewStudy()
616 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
618 // Set up processing of major study-related events
619 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
620 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
621 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
622 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
627 //=======================================================================
628 // name : createNewStudy
629 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
630 //=======================================================================
631 void SalomeApp_Application::updateCommandsStatus()
633 CAM_Application::updateCommandsStatus();
635 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
637 QAction* a = action( id );
639 a->setEnabled( activeStudy() );
643 QAction* a = action( DumpStudyId );
645 a->setEnabled( activeStudy() );
648 a = action( LoadScriptId );
650 a->setEnabled( activeStudy() );
652 a = action( PropertiesId );
654 a->setEnabled( activeStudy() );
656 a = action(EditCopyId);
657 a->setEnabled(false);
658 a = action(EditPasteId);
659 a->setEnabled(false);
662 //=======================================================================
663 // name : onHelpAbout
664 // Purpose : SLOT. Display "About" message box
665 //=======================================================================
666 void SalomeApp_Application::onHelpAbout()
668 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
673 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
680 if ( !activeStudy() )
683 sId = activeStudy()->id();
686 if ( myWindows.contains( flag ) )
687 wid = myWindows[flag]->widget( sId );
692 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
700 if ( !activeStudy() )
703 sId = activeStudy()->id();
706 if ( !myWindows.contains( flag ) )
708 QMap<int, int> winMap;
709 currentWindows( winMap );
711 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
712 if ( winMap.contains( flag ) )
713 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
715 myWindows[flag]->setResizeEnabled( true );
716 myWindows[flag]->setCloseMode( QDockWindow::Always );
717 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
720 myWindows[flag]->insert( sId, wid );
722 setWindowShown( flag, !myWindows[flag]->isEmpty() );
725 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
727 if ( !myWindows.contains( flag ) )
733 if ( !activeStudy() )
736 sId = activeStudy()->id();
739 QWidget* wid = myWindows[flag]->widget( sId );
740 myWindows[flag]->remove( sId );
743 setWindowShown( flag, !myWindows[flag]->isEmpty() );
746 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
748 QWidget* wid = window( flag, studyId );
750 addWindow( wid = createWindow( flag ), flag, studyId );
755 bool SalomeApp_Application::isWindowVisible( const int type ) const
758 if ( myWindows.contains( type ) )
760 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
761 res = desk && desk->appropriate( myWindows[type] );
766 void SalomeApp_Application::setWindowShown( const int type, const bool on )
768 if ( !desktop() || !myWindows.contains( type ) )
771 QDockWindow* dw = myWindows[type];
772 desktop()->setAppropriate( dw, on );
773 on ? dw->show() : dw->hide();
776 OB_Browser* SalomeApp_Application::objectBrowser()
779 QWidget* wid = getWindow( WT_ObjectBrowser );
780 if ( wid->inherits( "OB_Browser" ) )
781 ob = (OB_Browser*)wid;
785 LogWindow* SalomeApp_Application::logWindow()
788 QWidget* wid = getWindow( WT_LogWindow );
789 if ( wid->inherits( "LogWindow" ) )
790 lw = (LogWindow*)wid;
794 PythonConsole* SalomeApp_Application::pythonConsole()
796 PythonConsole* console = 0;
797 QWidget* wid = getWindow( WT_PyConsole );
798 if ( wid->inherits( "PythonConsole" ) )
799 console = (PythonConsole*)wid;
803 SalomeApp_Preferences* SalomeApp_Application::preferences() const
805 return preferences( false );
808 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
810 SUIT_ViewManager* aVM = viewManager( vmType );
811 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
813 if ( anActiveVM && anActiveVM->getType() == vmType )
818 if ( !aVM->getActiveView() )
821 aVM->getActiveView()->setFocus();
824 aVM = createViewManager( vmType );
829 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
831 SUIT_ResourceMgr* resMgr = resourceMgr();
833 SUIT_ViewManager* viewMgr = 0;
834 if ( vmType == GLViewer_Viewer::Type() )
836 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
837 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
839 else if ( vmType == Plot2d_Viewer::Type() )
841 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
842 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
844 else if ( vmType == OCCViewer_Viewer::Type() )
846 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
847 SOCC_Viewer* vm = new SOCC_Viewer();
848 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
849 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
850 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
851 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
853 else if ( vmType == SVTK_Viewer::Type() )
855 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
856 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
857 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
858 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
864 addViewManager( viewMgr );
865 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
867 if ( viewWin && desktop() )
868 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
870 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
871 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
876 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
878 removeViewManager( theVM );
881 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
883 SUIT_DataObject* aRoot = 0;
884 if ( theStudy && theStudy->root() )
886 aRoot = theStudy->root();
887 //aRoot->setName( tr( "DATA_MODELS" ) );
889 if ( objectBrowser() != 0 )
890 objectBrowser()->setRootObject( aRoot );
892 activateModule( defaultModule() );
897 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
899 SUIT_DataObject* aRoot = 0;
900 if ( theStudy && theStudy->root() )
902 aRoot = theStudy->root();
905 if ( objectBrowser() != 0 ) {
906 objectBrowser()->setRootObject( aRoot );
909 activateModule( defaultModule() );
916 void SalomeApp_Application::onStudySaved( SUIT_Study* )
921 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
925 activateModule( "" );
927 saveWindowsGeometry();
930 void SalomeApp_Application::onDumpStudy( )
932 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
933 if ( !appStudy ) return;
934 _PTR(Study) aStudy = appStudy->studyDS();
936 QStringList aFilters;
937 aFilters.append(tr("PYTHON_FILES_FILTER"));
939 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
940 fd->setCaption(tr("TOT_DESK_FILE_DUMP_STUDY"));
941 fd->setFilters( aFilters );
942 fd->SetChecked(true);
944 QString aFileName = fd->selectedFile();
945 bool toPublish = fd->IsChecked();
948 if(!aFileName.isEmpty()) {
949 QFileInfo aFileInfo(aFileName);
950 aStudy->DumpStudy(aFileInfo.dirPath(true), aFileInfo.baseName(), toPublish);
954 void SalomeApp_Application::onLoadScript( )
956 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
957 if ( !appStudy ) return;
958 _PTR(Study) aStudy = appStudy->studyDS();
960 if ( aStudy->GetProperties()->IsLocked() ) {
961 SUIT_MessageBox::warn1 ( desktop(),
962 QObject::tr("WRN_WARNING"),
963 QObject::tr("WRN_STUDY_LOCKED"),
964 QObject::tr("BUT_OK") );
968 QStringList filtersList;
969 filtersList.append(tr("PYTHON_FILES_FILTER"));
970 filtersList.append(tr("ALL_FILES_FILTER"));
972 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
974 if ( !aFile.isEmpty() )
976 QString command = QString("execfile(\"%1\")").arg(aFile);
978 PythonConsole* pyConsole = pythonConsole();
981 pyConsole->exec( command );
985 void SalomeApp_Application::onPreferences()
987 QApplication::setOverrideCursor( Qt::waitCursor );
989 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
991 QApplication::restoreOverrideCursor();
1001 void SalomeApp_Application::onMRUActivated( QString aName )
1006 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1008 SalomeApp_Module* sMod = 0;
1009 CAM_Module* mod = module( modName );
1010 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1011 sMod = (SalomeApp_Module*)mod;
1014 sMod->preferencesChanged( section, param );
1016 preferencesChanged( section, param );
1019 QString SalomeApp_Application::getFileFilter() const
1024 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1026 CAM_Application::beforeCloseDoc( s );
1028 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1029 removeWindow( itr.key(), s->id() );
1032 void SalomeApp_Application::updateActions()
1034 updateCommandsStatus();
1037 QWidget* SalomeApp_Application::createWindow( const int flag )
1041 SUIT_ResourceMgr* resMgr = resourceMgr();
1043 if ( flag == WT_ObjectBrowser )
1045 OB_Browser* ob = new OB_Browser( desktop() );
1046 ob->setAutoUpdate( true );
1047 ob->setAutoOpenLevel( 1 );
1048 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1049 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1050 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1052 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1054 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1056 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1057 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1058 QString().sprintf( "visibility_column_%d", i ), true ) );
1061 // Create OBSelector
1062 new SalomeApp_OBSelector( ob, mySelMgr );
1066 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1068 else if ( flag == WT_PyConsole )
1070 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1071 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1074 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1076 else if ( flag == WT_LogWindow )
1078 LogWindow* logWin = new LogWindow( desktop() );
1079 logWin->setCaption( tr( "LOG_WINDOW" ) );
1082 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1088 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1090 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1091 aMap.insert( WT_PyConsole, Qt::DockBottom );
1092 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1095 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1099 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1104 SalomeApp_Application* that = (SalomeApp_Application*)this;
1106 if ( !_prefs_ && crt )
1108 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1109 that->createPreferences( _prefs_ );
1112 that->myPrefs = _prefs_;
1114 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1115 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1117 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1120 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1122 QStringList modNameList;
1123 app->modules( modNameList, false );
1124 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1126 int id = _prefs_->addPreference( *it );
1127 _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1131 app->modules( modList );
1132 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1134 SalomeApp_Module* mod = 0;
1135 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1136 mod = (SalomeApp_Module*)itr.current();
1138 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1139 mod->createPreferences();
1143 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1144 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1149 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1151 CAM_Application::moduleAdded( mod );
1153 SalomeApp_Module* salomeMod = 0;
1154 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1155 salomeMod = (SalomeApp_Module*)mod;
1157 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1158 salomeMod->createPreferences();
1161 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1166 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1168 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1170 int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1171 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1173 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1174 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1176 pref->setProperty( obGroup, "columns", 1 );
1178 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1180 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1182 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1183 pref->setProperty( occGroup, "columns", 1 );
1184 pref->setProperty( vtkGroup, "columns", 1 );
1186 pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1187 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1188 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1189 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1191 pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1192 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1193 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1194 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1197 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1199 SUIT_ResourceMgr* resMgr = resourceMgr();
1203 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1205 int sz = resMgr->integerValue( sec, param, -1 );
1206 QPtrList<SUIT_ViewManager> lst;
1207 viewManagers( OCCViewer_Viewer::Type(), lst );
1208 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1210 SUIT_ViewModel* vm = it.current()->getViewModel();
1211 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1214 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1215 occVM->setTrihedronSize( sz );
1216 occVM->getAISContext()->UpdateCurrentViewer();
1221 void SalomeApp_Application::afterCloseDoc()
1225 CAM_Application::afterCloseDoc();
1228 CORBA::ORB_var SalomeApp_Application::orb()
1230 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1231 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1235 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1237 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1241 SALOME_NamingService* SalomeApp_Application::namingService()
1243 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1247 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1249 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1253 QString SalomeApp_Application::defaultEngineIOR()
1255 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1256 QString anIOR( "" );
1257 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1258 if ( !CORBA::is_nil( anEngine ) )
1259 anIOR = orb()->object_to_string( anEngine );
1263 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1267 SUIT_ResourceMgr* resMgr = resourceMgr();
1271 QStringList modList;
1272 modules( modList, false );
1274 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1276 QString modName = *it;
1277 QString modIntr = moduleName( modName );
1278 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1280 if ( modIcon.isEmpty() )
1283 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1284 modIcon += QString( ".png" );
1286 iconMap.insert( modName, modIcon );
1290 void SalomeApp_Application::updateModuleActions()
1293 if ( activeModule() )
1294 modName = activeModule()->moduleName();
1296 if ( myActions.contains( modName ) )
1297 myActions[modName]->setOn( true );
1300 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1303 if ( !activeStudy() )
1306 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1307 ((SalomeApp_Module*)activeModule())->windows( winMap );
1309 defaultWindows( winMap );
1312 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1315 if ( !activeStudy() )
1318 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1319 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1321 defaultViewManagers( lst );
1324 void SalomeApp_Application::updateWindows()
1326 QMap<int, int> winMap;
1327 currentWindows( winMap );
1329 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1330 getWindow( it.key() );
1332 loadWindowsGeometry();
1334 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1335 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1338 void SalomeApp_Application::updateViewManagers()
1341 currentViewManagers( lst );
1343 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1344 getViewManager( *it, true );
1347 void SalomeApp_Application::loadWindowsGeometry()
1349 QtxDockAction* dockMgr = 0;
1351 QAction* a = action( ViewWindowsId );
1352 if ( a && a->inherits( "QtxDockAction" ) )
1353 dockMgr = (QtxDockAction*)a;
1359 if ( activeModule() )
1360 modName = moduleLibrary( activeModule()->moduleName(), false );
1362 QString section = QString( "windows_geometry" );
1363 if ( !modName.isEmpty() )
1364 section += QString( "." ) + modName;
1366 dockMgr->loadGeometry( resourceMgr(), section, false );
1367 dockMgr->restoreGeometry();
1370 void SalomeApp_Application::saveWindowsGeometry()
1372 QtxDockAction* dockMgr = 0;
1374 QAction* a = action( ViewWindowsId );
1375 if ( a && a->inherits( "QtxDockAction" ) )
1376 dockMgr = (QtxDockAction*)a;
1382 if ( activeModule() )
1383 modName = moduleLibrary( activeModule()->moduleName(), false );
1385 QString section = QString( "windows_geometry" );
1386 if ( !modName.isEmpty() )
1387 section += QString( "." ) + modName;
1389 dockMgr->storeGeometry();
1390 dockMgr->saveGeometry( resourceMgr(), section, false );
1393 void SalomeApp_Application::activateWindows()
1395 if ( activeStudy() )
1397 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1398 itr.data()->activate( activeStudy()->id() );
1402 void SalomeApp_Application::onProperties()
1404 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1408 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1411 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1412 int res = aDlg.exec();
1413 if( res==QDialog::Accepted && aDlg.isChanged() )
1414 SB->CommitCommand();
1418 //study->updateCaptions();
1421 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1422 const QString& caption, QWidget* parent )
1426 QStringList fls = QStringList::split( ";;", filters, false );
1427 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1430 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1434 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1437 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1438 const QString& caption, QWidget* parent )
1442 QStringList fls = QStringList::split( ";;", filters, false );
1443 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1446 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1448 CAM_Application::contextMenuPopup( type, thePopup, title );
1449 thePopup->insertSeparator();
1450 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1451 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1454 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1458 for ( ModuleListIterator it = modules(); it.current(); ++it )
1460 CAM_DataModel* camDM = it.current()->dataModel();
1461 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1462 ((SalomeApp_DataModel*)camDM)->update();
1465 if ( objectBrowser() )
1466 objectBrowser()->updateTree();