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" ), false );
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" ), false );
297 if ( defIcon.isNull() )
298 defIcon = QPixmap( imageEmptyIcon );
300 // default icon for any module
301 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
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, false );
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 ], false );
408 icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
410 bool cancelled = false;
411 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
412 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
413 int res = aDlg.exec();
427 putInfo( tr("INF_CANCELLED") );
428 myActions[QString()]->setOn( true );
434 activateModule( modName );
437 QString SalomeApp_Application::defaultModule() const
439 QStringList aModuleNames;
440 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
441 // If there's the one and only module --> activate it automatically
442 // TODO: Possible improvement - default module can be taken from preferences
443 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
446 void SalomeApp_Application::onNewWindow()
448 const QObject* obj = sender();
449 if ( !obj || !obj->inherits( "QAction" ) )
453 int id = actionId( (QAction*)obj );
457 type = GLViewer_Viewer::Type();
460 type = Plot2d_Viewer::Type();
463 type = OCCViewer_Viewer::Type();
466 type = VTKViewer_Viewer::Type();
470 if ( !type.isEmpty() )
471 createViewManager( type );
474 //=======================================================================
476 // Purpose : SLOT. Create new document
477 //=======================================================================
478 void SalomeApp_Application::onNewDoc()
480 SUIT_Study* study = activeStudy();
482 saveWindowsGeometry();
484 CAM_Application::onNewDoc();
486 if ( !study ) // new study will be create in THIS application
489 updateViewManagers();
493 //=======================================================================
495 // Purpose : SLOT. Open new document
496 //=======================================================================
497 void SalomeApp_Application::onOpenDoc()
499 SUIT_Study* study = activeStudy();
500 saveWindowsGeometry();
502 CAM_Application::onOpenDoc();
504 if ( !study ) // new study will be create in THIS application
507 updateViewManagers();
511 bool SalomeApp_Application::onOpenDoc( const QString& aName )
513 bool res = CAM_Application::onOpenDoc( aName );
515 QAction* a = action( MRUId );
516 if ( a && a->inherits( "QtxMRUAction" ) )
518 QtxMRUAction* mru = (QtxMRUAction*)a;
520 mru->insert( aName );
522 mru->remove( aName );
527 void SalomeApp_Application::onSelection()
529 onSelectionChanged();
531 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
532 ((SalomeApp_Module*)activeModule())->selectionChanged();
535 void SalomeApp_Application::onCopy()
538 SalomeApp_SelectionMgr* mgr = selectionMgr();
539 mgr->selectedObjects(list);
541 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
542 if(study == NULL) return;
544 _PTR(Study) stdDS = study->studyDS();
547 SALOME_ListIteratorOfListIO it( list );
550 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
552 studyMgr()->Copy(so);
553 onSelectionChanged();
560 void SalomeApp_Application::onPaste()
563 SalomeApp_SelectionMgr* mgr = selectionMgr();
564 mgr->selectedObjects(list);
566 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
567 if(study == NULL) return;
569 _PTR(Study) stdDS = study->studyDS();
572 SALOME_ListIteratorOfListIO it( list );
575 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
577 studyMgr()->Paste(so);
578 updateObjectBrowser( true );
585 void SalomeApp_Application::onSelectionChanged()
588 SalomeApp_SelectionMgr* mgr = selectionMgr();
589 mgr->selectedObjects(list);
591 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
592 if(study == NULL) return;
594 _PTR(Study) stdDS = study->studyDS();
599 SALOME_ListIteratorOfListIO it( list );
600 if(it.More() && list.Extent() == 1)
602 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
604 qaction = action(EditCopyId);
605 if(studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
606 else qaction->setEnabled(false);
608 qaction = action(EditPasteId);
609 if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
610 else qaction->setEnabled(false);
613 qaction = action(EditCopyId);
614 qaction->setEnabled(false);
615 qaction = action(EditPasteId);
616 qaction->setEnabled(false);
620 void SalomeApp_Application::onRefresh()
622 updateObjectBrowser( true );
626 void SalomeApp_Application::onOpenWith()
628 QApplication::setOverrideCursor( Qt::waitCursor );
630 SalomeApp_SelectionMgr* mgr = selectionMgr();
631 mgr->selectedObjects(aList);
632 if (aList.Extent() != 1)
634 QApplication::restoreOverrideCursor();
637 Handle(SALOME_InteractiveObject) aIObj = aList.First();
638 QString aModuleName(aIObj->getComponentDataType());
639 QString aModuleTitle = moduleTitle(aModuleName);
640 activateModule(aModuleTitle);
641 QApplication::restoreOverrideCursor();
644 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
646 CAM_Application::setActiveStudy( study );
651 //=======================================================================
652 // name : createNewStudy
653 // Purpose : Create new study
654 //=======================================================================
655 SUIT_Study* SalomeApp_Application::createNewStudy()
657 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
659 // Set up processing of major study-related events
660 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
661 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
662 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
663 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
668 //=======================================================================
669 // name : createNewStudy
670 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
671 //=======================================================================
672 void SalomeApp_Application::updateCommandsStatus()
674 CAM_Application::updateCommandsStatus();
676 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
678 QAction* a = action( id );
680 a->setEnabled( activeStudy() );
684 QAction* a = action( DumpStudyId );
686 a->setEnabled( activeStudy() );
689 a = action( LoadScriptId );
691 a->setEnabled( activeStudy() );
693 a = action( PropertiesId );
695 a->setEnabled( activeStudy() );
697 a = action(EditCopyId);
698 a->setEnabled(false);
699 a = action(EditPasteId);
700 a->setEnabled(false);
703 //=======================================================================
704 // name : onHelpAbout
705 // Purpose : SLOT. Display "About" message box
706 //=======================================================================
707 void SalomeApp_Application::onHelpAbout()
709 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
714 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
721 if ( !activeStudy() )
724 sId = activeStudy()->id();
727 if ( myWindows.contains( flag ) )
728 wid = myWindows[flag]->widget( sId );
733 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
741 if ( !activeStudy() )
744 sId = activeStudy()->id();
747 if ( !myWindows.contains( flag ) )
749 QMap<int, int> winMap;
750 currentWindows( winMap );
752 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
753 if ( winMap.contains( flag ) )
754 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
756 myWindows[flag]->setResizeEnabled( true );
757 myWindows[flag]->setCloseMode( QDockWindow::Always );
758 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
761 myWindows[flag]->insert( sId, wid );
763 setWindowShown( flag, !myWindows[flag]->isEmpty() );
766 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
768 if ( !myWindows.contains( flag ) )
774 if ( !activeStudy() )
777 sId = activeStudy()->id();
780 QWidget* wid = myWindows[flag]->widget( sId );
781 myWindows[flag]->remove( sId );
784 setWindowShown( flag, !myWindows[flag]->isEmpty() );
787 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
789 QWidget* wid = window( flag, studyId );
791 addWindow( wid = createWindow( flag ), flag, studyId );
796 bool SalomeApp_Application::isWindowVisible( const int type ) const
799 if ( myWindows.contains( type ) )
801 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
802 res = desk && desk->appropriate( myWindows[type] );
807 void SalomeApp_Application::setWindowShown( const int type, const bool on )
809 if ( !desktop() || !myWindows.contains( type ) )
812 QDockWindow* dw = myWindows[type];
813 desktop()->setAppropriate( dw, on );
814 on ? dw->show() : dw->hide();
817 OB_Browser* SalomeApp_Application::objectBrowser()
820 QWidget* wid = getWindow( WT_ObjectBrowser );
821 if ( wid->inherits( "OB_Browser" ) )
822 ob = (OB_Browser*)wid;
826 LogWindow* SalomeApp_Application::logWindow()
829 QWidget* wid = getWindow( WT_LogWindow );
830 if ( wid->inherits( "LogWindow" ) )
831 lw = (LogWindow*)wid;
835 PythonConsole* SalomeApp_Application::pythonConsole()
837 PythonConsole* console = 0;
838 QWidget* wid = getWindow( WT_PyConsole );
839 if ( wid->inherits( "PythonConsole" ) )
840 console = (PythonConsole*)wid;
844 SalomeApp_Preferences* SalomeApp_Application::preferences() const
846 return preferences( false );
849 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
851 SUIT_ViewManager* aVM = viewManager( vmType );
852 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
854 if ( anActiveVM && anActiveVM->getType() == vmType )
859 if ( !aVM->getActiveView() )
862 aVM->getActiveView()->setFocus();
865 aVM = createViewManager( vmType );
870 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
872 SUIT_ResourceMgr* resMgr = resourceMgr();
874 SUIT_ViewManager* viewMgr = 0;
875 if ( vmType == GLViewer_Viewer::Type() )
877 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
878 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
880 else if ( vmType == Plot2d_Viewer::Type() )
882 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
883 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
885 else if ( vmType == OCCViewer_Viewer::Type() )
887 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
888 SOCC_Viewer* vm = new SOCC_Viewer();
889 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
890 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
893 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
894 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
895 // vm->setIsos( u, v );
896 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
897 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
899 else if ( vmType == SVTK_Viewer::Type() )
901 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
902 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
903 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
904 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
905 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
911 addViewManager( viewMgr );
912 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
914 if ( viewWin && desktop() )
915 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
917 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
918 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
923 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
925 removeViewManager( theVM );
928 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
930 SUIT_DataObject* aRoot = 0;
931 if ( theStudy && theStudy->root() )
933 aRoot = theStudy->root();
934 //aRoot->setName( tr( "DATA_MODELS" ) );
936 if ( objectBrowser() != 0 )
937 objectBrowser()->setRootObject( aRoot );
939 activateModule( defaultModule() );
944 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
946 SUIT_DataObject* aRoot = 0;
947 if ( theStudy && theStudy->root() )
949 aRoot = theStudy->root();
952 if ( objectBrowser() != 0 ) {
953 objectBrowser()->setRootObject( aRoot );
956 activateModule( defaultModule() );
963 void SalomeApp_Application::onStudySaved( SUIT_Study* )
968 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
972 activateModule( "" );
974 saveWindowsGeometry();
977 void SalomeApp_Application::onDumpStudy( )
979 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
980 if ( !appStudy ) return;
981 _PTR(Study) aStudy = appStudy->studyDS();
983 QStringList aFilters;
984 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
986 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
987 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
988 fd->setFilters( aFilters );
989 fd->SetChecked(true);
991 QString aFileName = fd->selectedFile();
992 bool toPublish = fd->IsChecked();
995 if(!aFileName.isEmpty()) {
996 QFileInfo aFileInfo(aFileName);
997 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1001 void SalomeApp_Application::onLoadScript( )
1003 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1004 if ( !appStudy ) return;
1005 _PTR(Study) aStudy = appStudy->studyDS();
1007 if ( aStudy->GetProperties()->IsLocked() ) {
1008 SUIT_MessageBox::warn1 ( desktop(),
1009 QObject::tr("WRN_WARNING"),
1010 QObject::tr("WRN_STUDY_LOCKED"),
1011 QObject::tr("BUT_OK") );
1015 QStringList filtersList;
1016 filtersList.append(tr("PYTHON_FILES_FILTER"));
1017 filtersList.append(tr("ALL_FILES_FILTER"));
1019 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1021 if ( !aFile.isEmpty() )
1023 QString command = QString("execfile(\"%1\")").arg(aFile);
1025 PythonConsole* pyConsole = pythonConsole();
1028 pyConsole->exec( command );
1032 void SalomeApp_Application::onPreferences()
1034 QApplication::setOverrideCursor( Qt::waitCursor );
1036 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1038 QApplication::restoreOverrideCursor();
1048 void SalomeApp_Application::onMRUActivated( QString aName )
1053 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1055 SalomeApp_Module* sMod = 0;
1056 CAM_Module* mod = module( modName );
1057 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1058 sMod = (SalomeApp_Module*)mod;
1061 sMod->preferencesChanged( section, param );
1063 preferencesChanged( section, param );
1066 QString SalomeApp_Application::getFileFilter() const
1071 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1073 CAM_Application::beforeCloseDoc( s );
1075 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1076 removeWindow( itr.key(), s->id() );
1079 void SalomeApp_Application::updateActions()
1081 updateCommandsStatus();
1084 QWidget* SalomeApp_Application::createWindow( const int flag )
1088 SUIT_ResourceMgr* resMgr = resourceMgr();
1090 if ( flag == WT_ObjectBrowser )
1092 OB_Browser* ob = new OB_Browser( desktop() );
1093 ob->setAutoUpdate( true );
1094 ob->setAutoOpenLevel( 1 );
1095 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1096 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1097 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1099 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1101 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1103 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1104 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1105 QString().sprintf( "visibility_column_%d", i ), true ) );
1108 // Create OBSelector
1109 new SalomeApp_OBSelector( ob, mySelMgr );
1113 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1115 else if ( flag == WT_PyConsole )
1117 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1118 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1121 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1123 else if ( flag == WT_LogWindow )
1125 LogWindow* logWin = new LogWindow( desktop() );
1126 logWin->setCaption( tr( "LOG_WINDOW" ) );
1129 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1135 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1137 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1138 aMap.insert( WT_PyConsole, Qt::DockBottom );
1139 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1142 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1146 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1151 SalomeApp_Application* that = (SalomeApp_Application*)this;
1153 if ( !_prefs_ && crt )
1155 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1156 that->createPreferences( _prefs_ );
1159 that->myPrefs = _prefs_;
1161 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1162 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1164 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1167 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1169 QStringList modNameList;
1170 app->modules( modNameList, false );
1171 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1173 int id = _prefs_->addPreference( *it );
1174 _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1178 app->modules( modList );
1179 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1181 SalomeApp_Module* mod = 0;
1182 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1183 mod = (SalomeApp_Module*)itr.current();
1185 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1186 mod->createPreferences();
1190 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1191 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1196 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1198 CAM_Application::moduleAdded( mod );
1200 SalomeApp_Module* salomeMod = 0;
1201 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1202 salomeMod = (SalomeApp_Module*)mod;
1204 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1205 salomeMod->createPreferences();
1208 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1213 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1215 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1217 int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1218 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1220 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1221 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1223 pref->setProperty( obGroup, "columns", 1 );
1225 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1227 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1229 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1230 pref->setProperty( occGroup, "columns", 1 );
1231 pref->setProperty( vtkGroup, "columns", 1 );
1233 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1234 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1235 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1236 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1238 pref->setProperty( occTS, "min", 1 );
1239 pref->setProperty( occTS, "max", 150 );
1241 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1242 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1243 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1244 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1246 pref->setProperty( isoU, "min", 0 );
1247 pref->setProperty( isoU, "max", 100000 );
1249 pref->setProperty( isoV, "min", 0 );
1250 pref->setProperty( isoV, "max", 100000 );
1252 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1253 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1254 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1255 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1257 pref->setProperty( vtkTS, "min", 1 );
1258 pref->setProperty( vtkTS, "max", 150 );
1261 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1263 SUIT_ResourceMgr* resMgr = resourceMgr();
1267 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1269 int sz = resMgr->integerValue( sec, param, -1 );
1270 QPtrList<SUIT_ViewManager> lst;
1271 viewManagers( OCCViewer_Viewer::Type(), lst );
1272 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1274 SUIT_ViewModel* vm = it.current()->getViewModel();
1275 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1278 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1279 occVM->setTrihedronSize( sz );
1280 occVM->getAISContext()->UpdateCurrentViewer();
1284 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1286 int sz = resMgr->integerValue( sec, param, -1 );
1287 QPtrList<SUIT_ViewManager> lst;
1288 viewManagers( SVTK_Viewer::Type(), lst );
1289 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1291 SUIT_ViewModel* vm = it.current()->getViewModel();
1292 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1295 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1296 vtkVM->setTrihedronSize( sz );
1301 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1303 QPtrList<SUIT_ViewManager> lst;
1304 viewManagers( OCCViewer_Viewer::Type(), lst );
1305 int u = resMgr->integerValue( sec, "iso_number_u" );
1306 int v = resMgr->integerValue( sec, "iso_number_v" );
1307 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1308 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1313 void SalomeApp_Application::afterCloseDoc()
1317 CAM_Application::afterCloseDoc();
1320 CORBA::ORB_var SalomeApp_Application::orb()
1322 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1323 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1327 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1329 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1333 SALOME_NamingService* SalomeApp_Application::namingService()
1335 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1339 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1341 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1345 QString SalomeApp_Application::defaultEngineIOR()
1347 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1348 QString anIOR( "" );
1349 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1350 if ( !CORBA::is_nil( anEngine ) )
1351 anIOR = orb()->object_to_string( anEngine );
1355 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1359 SUIT_ResourceMgr* resMgr = resourceMgr();
1363 QStringList modList;
1364 modules( modList, false );
1366 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1368 QString modName = *it;
1369 QString modIntr = moduleName( modName );
1370 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1372 if ( modIcon.isEmpty() )
1375 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1376 modIcon += QString( ".png" );
1378 iconMap.insert( modName, modIcon );
1382 void SalomeApp_Application::updateModuleActions()
1385 if ( activeModule() )
1386 modName = activeModule()->moduleName();
1388 if ( myActions.contains( modName ) )
1389 myActions[modName]->setOn( true );
1392 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1395 if ( !activeStudy() )
1398 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1399 ((SalomeApp_Module*)activeModule())->windows( winMap );
1401 defaultWindows( winMap );
1404 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1407 if ( !activeStudy() )
1410 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1411 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1413 defaultViewManagers( lst );
1416 void SalomeApp_Application::updateWindows()
1418 QMap<int, int> winMap;
1419 currentWindows( winMap );
1421 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1422 getWindow( it.key() );
1424 loadWindowsGeometry();
1426 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1427 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1430 void SalomeApp_Application::updateViewManagers()
1433 currentViewManagers( lst );
1435 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1436 getViewManager( *it, true );
1439 void SalomeApp_Application::loadWindowsGeometry()
1441 QtxDockAction* dockMgr = 0;
1443 QAction* a = action( ViewWindowsId );
1444 if ( a && a->inherits( "QtxDockAction" ) )
1445 dockMgr = (QtxDockAction*)a;
1451 if ( activeModule() )
1452 modName = moduleLibrary( activeModule()->moduleName(), false );
1454 QString section = QString( "windows_geometry" );
1455 if ( !modName.isEmpty() )
1456 section += QString( "." ) + modName;
1458 dockMgr->loadGeometry( resourceMgr(), section, false );
1459 dockMgr->restoreGeometry();
1462 void SalomeApp_Application::saveWindowsGeometry()
1464 QtxDockAction* dockMgr = 0;
1466 QAction* a = action( ViewWindowsId );
1467 if ( a && a->inherits( "QtxDockAction" ) )
1468 dockMgr = (QtxDockAction*)a;
1474 if ( activeModule() )
1475 modName = moduleLibrary( activeModule()->moduleName(), false );
1477 QString section = QString( "windows_geometry" );
1478 if ( !modName.isEmpty() )
1479 section += QString( "." ) + modName;
1481 dockMgr->storeGeometry();
1482 dockMgr->saveGeometry( resourceMgr(), section, false );
1485 void SalomeApp_Application::activateWindows()
1487 if ( activeStudy() )
1489 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1490 itr.data()->activate( activeStudy()->id() );
1494 void SalomeApp_Application::onProperties()
1496 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1500 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1503 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1504 int res = aDlg.exec();
1505 if( res==QDialog::Accepted && aDlg.isChanged() )
1506 SB->CommitCommand();
1510 //study->updateCaptions();
1513 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1514 const QString& caption, QWidget* parent )
1518 QStringList fls = QStringList::split( ";;", filters, false );
1519 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1522 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1526 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1529 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1530 const QString& caption, QWidget* parent )
1534 QStringList fls = QStringList::split( ";;", filters, false );
1535 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1538 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1540 CAM_Application::contextMenuPopup( type, thePopup, title );
1541 thePopup->insertSeparator();
1542 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1544 // "Activate module" item should appear only if it's necessary
1545 OB_Browser* ob = objectBrowser();
1546 if ( !ob || type != ob->popupClientType() )
1548 SALOME_ListIO aList;
1549 SalomeApp_SelectionMgr* mgr = selectionMgr();
1550 mgr->selectedObjects(aList);
1551 if (aList.Extent() != 1)
1553 Handle(SALOME_InteractiveObject) aIObj = aList.First();
1554 QString aModuleName(aIObj->getComponentDataType());
1555 QString aModuleTitle = moduleTitle(aModuleName);
1556 CAM_Module* currentModule = activeModule();
1557 if (currentModule && currentModule->moduleName() == aModuleTitle)
1559 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1562 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1566 for ( ModuleListIterator it = modules(); it.current(); ++it )
1568 CAM_DataModel* camDM = it.current()->dataModel();
1569 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1570 ((SalomeApp_DataModel*)camDM)->update();
1573 if ( objectBrowser() )
1574 objectBrowser()->updateTree();