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) return;
633 Handle(SALOME_InteractiveObject) aIObj = aList.First();
634 QString aModuleName(aIObj->getComponentDataType());
635 QString aModuleTitle = moduleTitle(aModuleName);
636 activateModule(aModuleTitle);
637 QApplication::restoreOverrideCursor();
640 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
642 CAM_Application::setActiveStudy( study );
647 //=======================================================================
648 // name : createNewStudy
649 // Purpose : Create new study
650 //=======================================================================
651 SUIT_Study* SalomeApp_Application::createNewStudy()
653 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
655 // Set up processing of major study-related events
656 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
657 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
658 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
659 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
664 //=======================================================================
665 // name : createNewStudy
666 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
667 //=======================================================================
668 void SalomeApp_Application::updateCommandsStatus()
670 CAM_Application::updateCommandsStatus();
672 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
674 QAction* a = action( id );
676 a->setEnabled( activeStudy() );
680 QAction* a = action( DumpStudyId );
682 a->setEnabled( activeStudy() );
685 a = action( LoadScriptId );
687 a->setEnabled( activeStudy() );
689 a = action( PropertiesId );
691 a->setEnabled( activeStudy() );
693 a = action(EditCopyId);
694 a->setEnabled(false);
695 a = action(EditPasteId);
696 a->setEnabled(false);
699 //=======================================================================
700 // name : onHelpAbout
701 // Purpose : SLOT. Display "About" message box
702 //=======================================================================
703 void SalomeApp_Application::onHelpAbout()
705 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
710 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
717 if ( !activeStudy() )
720 sId = activeStudy()->id();
723 if ( myWindows.contains( flag ) )
724 wid = myWindows[flag]->widget( sId );
729 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
737 if ( !activeStudy() )
740 sId = activeStudy()->id();
743 if ( !myWindows.contains( flag ) )
745 QMap<int, int> winMap;
746 currentWindows( winMap );
748 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
749 if ( winMap.contains( flag ) )
750 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
752 myWindows[flag]->setResizeEnabled( true );
753 myWindows[flag]->setCloseMode( QDockWindow::Always );
754 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
757 myWindows[flag]->insert( sId, wid );
759 setWindowShown( flag, !myWindows[flag]->isEmpty() );
762 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
764 if ( !myWindows.contains( flag ) )
770 if ( !activeStudy() )
773 sId = activeStudy()->id();
776 QWidget* wid = myWindows[flag]->widget( sId );
777 myWindows[flag]->remove( sId );
780 setWindowShown( flag, !myWindows[flag]->isEmpty() );
783 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
785 QWidget* wid = window( flag, studyId );
787 addWindow( wid = createWindow( flag ), flag, studyId );
792 bool SalomeApp_Application::isWindowVisible( const int type ) const
795 if ( myWindows.contains( type ) )
797 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
798 res = desk && desk->appropriate( myWindows[type] );
803 void SalomeApp_Application::setWindowShown( const int type, const bool on )
805 if ( !desktop() || !myWindows.contains( type ) )
808 QDockWindow* dw = myWindows[type];
809 desktop()->setAppropriate( dw, on );
810 on ? dw->show() : dw->hide();
813 OB_Browser* SalomeApp_Application::objectBrowser()
816 QWidget* wid = getWindow( WT_ObjectBrowser );
817 if ( wid->inherits( "OB_Browser" ) )
818 ob = (OB_Browser*)wid;
822 LogWindow* SalomeApp_Application::logWindow()
825 QWidget* wid = getWindow( WT_LogWindow );
826 if ( wid->inherits( "LogWindow" ) )
827 lw = (LogWindow*)wid;
831 PythonConsole* SalomeApp_Application::pythonConsole()
833 PythonConsole* console = 0;
834 QWidget* wid = getWindow( WT_PyConsole );
835 if ( wid->inherits( "PythonConsole" ) )
836 console = (PythonConsole*)wid;
840 SalomeApp_Preferences* SalomeApp_Application::preferences() const
842 return preferences( false );
845 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
847 SUIT_ViewManager* aVM = viewManager( vmType );
848 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
850 if ( anActiveVM && anActiveVM->getType() == vmType )
855 if ( !aVM->getActiveView() )
858 aVM->getActiveView()->setFocus();
861 aVM = createViewManager( vmType );
866 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
868 SUIT_ResourceMgr* resMgr = resourceMgr();
870 SUIT_ViewManager* viewMgr = 0;
871 if ( vmType == GLViewer_Viewer::Type() )
873 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
874 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
876 else if ( vmType == Plot2d_Viewer::Type() )
878 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
879 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
881 else if ( vmType == OCCViewer_Viewer::Type() )
883 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
884 SOCC_Viewer* vm = new SOCC_Viewer();
885 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
886 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
889 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
890 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
891 // vm->setIsos( u, v );
892 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
893 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
895 else if ( vmType == SVTK_Viewer::Type() )
897 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
898 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
899 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
900 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
901 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
907 addViewManager( viewMgr );
908 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
910 if ( viewWin && desktop() )
911 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
913 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
914 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
919 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
921 removeViewManager( theVM );
924 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
926 SUIT_DataObject* aRoot = 0;
927 if ( theStudy && theStudy->root() )
929 aRoot = theStudy->root();
930 //aRoot->setName( tr( "DATA_MODELS" ) );
932 if ( objectBrowser() != 0 )
933 objectBrowser()->setRootObject( aRoot );
935 activateModule( defaultModule() );
940 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
942 SUIT_DataObject* aRoot = 0;
943 if ( theStudy && theStudy->root() )
945 aRoot = theStudy->root();
948 if ( objectBrowser() != 0 ) {
949 objectBrowser()->setRootObject( aRoot );
952 activateModule( defaultModule() );
959 void SalomeApp_Application::onStudySaved( SUIT_Study* )
964 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
968 activateModule( "" );
970 saveWindowsGeometry();
973 void SalomeApp_Application::onDumpStudy( )
975 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
976 if ( !appStudy ) return;
977 _PTR(Study) aStudy = appStudy->studyDS();
979 QStringList aFilters;
980 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
982 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
983 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
984 fd->setFilters( aFilters );
985 fd->SetChecked(true);
987 QString aFileName = fd->selectedFile();
988 bool toPublish = fd->IsChecked();
991 if(!aFileName.isEmpty()) {
992 QFileInfo aFileInfo(aFileName);
993 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
997 void SalomeApp_Application::onLoadScript( )
999 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1000 if ( !appStudy ) return;
1001 _PTR(Study) aStudy = appStudy->studyDS();
1003 if ( aStudy->GetProperties()->IsLocked() ) {
1004 SUIT_MessageBox::warn1 ( desktop(),
1005 QObject::tr("WRN_WARNING"),
1006 QObject::tr("WRN_STUDY_LOCKED"),
1007 QObject::tr("BUT_OK") );
1011 QStringList filtersList;
1012 filtersList.append(tr("PYTHON_FILES_FILTER"));
1013 filtersList.append(tr("ALL_FILES_FILTER"));
1015 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1017 if ( !aFile.isEmpty() )
1019 QString command = QString("execfile(\"%1\")").arg(aFile);
1021 PythonConsole* pyConsole = pythonConsole();
1024 pyConsole->exec( command );
1028 void SalomeApp_Application::onPreferences()
1030 QApplication::setOverrideCursor( Qt::waitCursor );
1032 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1034 QApplication::restoreOverrideCursor();
1044 void SalomeApp_Application::onMRUActivated( QString aName )
1049 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1051 SalomeApp_Module* sMod = 0;
1052 CAM_Module* mod = module( modName );
1053 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1054 sMod = (SalomeApp_Module*)mod;
1057 sMod->preferencesChanged( section, param );
1059 preferencesChanged( section, param );
1062 QString SalomeApp_Application::getFileFilter() const
1067 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1069 CAM_Application::beforeCloseDoc( s );
1071 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1072 removeWindow( itr.key(), s->id() );
1075 void SalomeApp_Application::updateActions()
1077 updateCommandsStatus();
1080 QWidget* SalomeApp_Application::createWindow( const int flag )
1084 SUIT_ResourceMgr* resMgr = resourceMgr();
1086 if ( flag == WT_ObjectBrowser )
1088 OB_Browser* ob = new OB_Browser( desktop() );
1089 ob->setAutoUpdate( true );
1090 ob->setAutoOpenLevel( 1 );
1091 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1092 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1093 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1095 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1097 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1099 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1100 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1101 QString().sprintf( "visibility_column_%d", i ), true ) );
1104 // Create OBSelector
1105 new SalomeApp_OBSelector( ob, mySelMgr );
1109 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1111 else if ( flag == WT_PyConsole )
1113 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1114 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1117 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1119 else if ( flag == WT_LogWindow )
1121 LogWindow* logWin = new LogWindow( desktop() );
1122 logWin->setCaption( tr( "LOG_WINDOW" ) );
1125 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1131 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1133 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1134 aMap.insert( WT_PyConsole, Qt::DockBottom );
1135 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1138 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1142 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1147 SalomeApp_Application* that = (SalomeApp_Application*)this;
1149 if ( !_prefs_ && crt )
1151 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1152 that->createPreferences( _prefs_ );
1155 that->myPrefs = _prefs_;
1157 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1158 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1160 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1163 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1165 QStringList modNameList;
1166 app->modules( modNameList, false );
1167 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1169 int id = _prefs_->addPreference( *it );
1170 _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1174 app->modules( modList );
1175 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1177 SalomeApp_Module* mod = 0;
1178 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1179 mod = (SalomeApp_Module*)itr.current();
1181 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1182 mod->createPreferences();
1186 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1187 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1192 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1194 CAM_Application::moduleAdded( mod );
1196 SalomeApp_Module* salomeMod = 0;
1197 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1198 salomeMod = (SalomeApp_Module*)mod;
1200 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1201 salomeMod->createPreferences();
1204 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1209 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1211 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1213 int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1214 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1216 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1217 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1219 pref->setProperty( obGroup, "columns", 1 );
1221 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1223 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1225 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1226 pref->setProperty( occGroup, "columns", 1 );
1227 pref->setProperty( vtkGroup, "columns", 1 );
1229 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1230 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1231 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1232 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1234 pref->setProperty( occTS, "min", 1 );
1235 pref->setProperty( occTS, "max", 150 );
1237 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1238 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1239 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1240 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1242 pref->setProperty( isoU, "min", 0 );
1243 pref->setProperty( isoU, "max", 100000 );
1245 pref->setProperty( isoV, "min", 0 );
1246 pref->setProperty( isoV, "max", 100000 );
1248 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1249 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1250 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1251 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1253 pref->setProperty( vtkTS, "min", 1 );
1254 pref->setProperty( vtkTS, "max", 150 );
1257 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1259 SUIT_ResourceMgr* resMgr = resourceMgr();
1263 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1265 int sz = resMgr->integerValue( sec, param, -1 );
1266 QPtrList<SUIT_ViewManager> lst;
1267 viewManagers( OCCViewer_Viewer::Type(), lst );
1268 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1270 SUIT_ViewModel* vm = it.current()->getViewModel();
1271 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1274 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1275 occVM->setTrihedronSize( sz );
1276 occVM->getAISContext()->UpdateCurrentViewer();
1280 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1282 int sz = resMgr->integerValue( sec, param, -1 );
1283 QPtrList<SUIT_ViewManager> lst;
1284 viewManagers( SVTK_Viewer::Type(), lst );
1285 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1287 SUIT_ViewModel* vm = it.current()->getViewModel();
1288 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1291 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1292 vtkVM->setTrihedronSize( sz );
1297 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1299 QPtrList<SUIT_ViewManager> lst;
1300 viewManagers( OCCViewer_Viewer::Type(), lst );
1301 int u = resMgr->integerValue( sec, "iso_number_u" );
1302 int v = resMgr->integerValue( sec, "iso_number_v" );
1303 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1304 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1309 void SalomeApp_Application::afterCloseDoc()
1313 CAM_Application::afterCloseDoc();
1316 CORBA::ORB_var SalomeApp_Application::orb()
1318 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1319 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1323 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1325 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1329 SALOME_NamingService* SalomeApp_Application::namingService()
1331 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1335 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1337 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1341 QString SalomeApp_Application::defaultEngineIOR()
1343 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1344 QString anIOR( "" );
1345 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1346 if ( !CORBA::is_nil( anEngine ) )
1347 anIOR = orb()->object_to_string( anEngine );
1351 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1355 SUIT_ResourceMgr* resMgr = resourceMgr();
1359 QStringList modList;
1360 modules( modList, false );
1362 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1364 QString modName = *it;
1365 QString modIntr = moduleName( modName );
1366 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1368 if ( modIcon.isEmpty() )
1371 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1372 modIcon += QString( ".png" );
1374 iconMap.insert( modName, modIcon );
1378 void SalomeApp_Application::updateModuleActions()
1381 if ( activeModule() )
1382 modName = activeModule()->moduleName();
1384 if ( myActions.contains( modName ) )
1385 myActions[modName]->setOn( true );
1388 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1391 if ( !activeStudy() )
1394 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1395 ((SalomeApp_Module*)activeModule())->windows( winMap );
1397 defaultWindows( winMap );
1400 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1403 if ( !activeStudy() )
1406 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1407 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1409 defaultViewManagers( lst );
1412 void SalomeApp_Application::updateWindows()
1414 QMap<int, int> winMap;
1415 currentWindows( winMap );
1417 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1418 getWindow( it.key() );
1420 loadWindowsGeometry();
1422 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1423 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1426 void SalomeApp_Application::updateViewManagers()
1429 currentViewManagers( lst );
1431 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1432 getViewManager( *it, true );
1435 void SalomeApp_Application::loadWindowsGeometry()
1437 QtxDockAction* dockMgr = 0;
1439 QAction* a = action( ViewWindowsId );
1440 if ( a && a->inherits( "QtxDockAction" ) )
1441 dockMgr = (QtxDockAction*)a;
1447 if ( activeModule() )
1448 modName = moduleLibrary( activeModule()->moduleName(), false );
1450 QString section = QString( "windows_geometry" );
1451 if ( !modName.isEmpty() )
1452 section += QString( "." ) + modName;
1454 dockMgr->loadGeometry( resourceMgr(), section, false );
1455 dockMgr->restoreGeometry();
1458 void SalomeApp_Application::saveWindowsGeometry()
1460 QtxDockAction* dockMgr = 0;
1462 QAction* a = action( ViewWindowsId );
1463 if ( a && a->inherits( "QtxDockAction" ) )
1464 dockMgr = (QtxDockAction*)a;
1470 if ( activeModule() )
1471 modName = moduleLibrary( activeModule()->moduleName(), false );
1473 QString section = QString( "windows_geometry" );
1474 if ( !modName.isEmpty() )
1475 section += QString( "." ) + modName;
1477 dockMgr->storeGeometry();
1478 dockMgr->saveGeometry( resourceMgr(), section, false );
1481 void SalomeApp_Application::activateWindows()
1483 if ( activeStudy() )
1485 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1486 itr.data()->activate( activeStudy()->id() );
1490 void SalomeApp_Application::onProperties()
1492 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1496 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1499 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1500 int res = aDlg.exec();
1501 if( res==QDialog::Accepted && aDlg.isChanged() )
1502 SB->CommitCommand();
1506 //study->updateCaptions();
1509 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1510 const QString& caption, QWidget* parent )
1514 QStringList fls = QStringList::split( ";;", filters, false );
1515 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1518 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1522 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1525 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1526 const QString& caption, QWidget* parent )
1530 QStringList fls = QStringList::split( ";;", filters, false );
1531 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1534 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1536 CAM_Application::contextMenuPopup( type, thePopup, title );
1537 thePopup->insertSeparator();
1538 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1539 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1542 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1546 for ( ModuleListIterator it = modules(); it.current(); ++it )
1548 CAM_DataModel* camDM = it.current()->dataModel();
1549 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1550 ((SalomeApp_DataModel*)camDM)->update();
1553 if ( objectBrowser() )
1554 objectBrowser()->updateTree();