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::onSelectionChanged()
538 SalomeApp_Module* module = dynamic_cast<SalomeApp_Module*>(activeModule());
539 if(module == NULL) return;
541 QString ior = module->engineIOR();
542 if(ior.length() < 5) return; //Not a real CORBA IOR
543 CORBA::Object_var obj = orb()->string_to_object(ior.latin1());
544 if(CORBA::is_nil(obj)) return;
546 SALOMEDS::Driver_var engine = SALOMEDS::Driver::_narrow(obj);
547 if(CORBA::is_nil(engine)) return;
551 SalomeApp_SelectionMgr* mgr = selectionMgr();
552 mgr->selectedObjects(list);
554 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
555 if(study == NULL) return;
557 _PTR(Study) stdDS = study->studyDS();
561 //Varibales isEnabledCopy and isEnabledPaste are used for multi selection.
562 bool isEnabledCopy = true;
563 bool isEnabledPaste = true;
565 for ( SALOME_ListIteratorOfListIO it( list ); it.More() && (isEnabledCopy || isEnabledPaste); it.Next() )
567 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
569 qaction = action(EditCopyId);
570 if( isEnabledCopy && studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
572 isEnabledCopy = false;
573 qaction->setEnabled(false);
576 qaction = action(EditPasteId);
577 if( isEnabledPaste && studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
579 isEnabledPaste = false;
580 qaction->setEnabled(false);
585 void SalomeApp_Application::onRefresh()
587 updateObjectBrowser( true );
591 void SalomeApp_Application::onOpenWith()
593 QApplication::setOverrideCursor( Qt::waitCursor );
595 SalomeApp_SelectionMgr* mgr = selectionMgr();
596 mgr->selectedObjects(aList);
597 if (aList.Extent() > 1) return;
598 Handle(SALOME_InteractiveObject) aIObj = aList.First();
599 QString aModuleName(aIObj->getComponentDataType());
600 QString aModuleTitle = moduleTitle(aModuleName);
601 activateModule(aModuleTitle);
602 QApplication::restoreOverrideCursor();
605 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
607 CAM_Application::setActiveStudy( study );
612 //=======================================================================
613 // name : createNewStudy
614 // Purpose : Create new study
615 //=======================================================================
616 SUIT_Study* SalomeApp_Application::createNewStudy()
618 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
620 // Set up processing of major study-related events
621 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
622 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
623 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
624 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
629 //=======================================================================
630 // name : createNewStudy
631 // Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu
632 //=======================================================================
633 void SalomeApp_Application::updateCommandsStatus()
635 CAM_Application::updateCommandsStatus();
637 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
639 QAction* a = action( id );
641 a->setEnabled( activeStudy() );
645 QAction* a = action( DumpStudyId );
647 a->setEnabled( activeStudy() );
650 a = action( LoadScriptId );
652 a->setEnabled( activeStudy() );
654 a = action( PropertiesId );
656 a->setEnabled( activeStudy() );
658 a = action(EditCopyId);
659 a->setEnabled(false);
660 a = action(EditPasteId);
661 a->setEnabled(false);
664 //=======================================================================
665 // name : onHelpAbout
666 // Purpose : SLOT. Display "About" message box
667 //=======================================================================
668 void SalomeApp_Application::onHelpAbout()
670 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
675 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
682 if ( !activeStudy() )
685 sId = activeStudy()->id();
688 if ( myWindows.contains( flag ) )
689 wid = myWindows[flag]->widget( sId );
694 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
702 if ( !activeStudy() )
705 sId = activeStudy()->id();
708 if ( !myWindows.contains( flag ) )
710 QMap<int, int> winMap;
711 currentWindows( winMap );
713 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
714 if ( winMap.contains( flag ) )
715 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
717 myWindows[flag]->setResizeEnabled( true );
718 myWindows[flag]->setCloseMode( QDockWindow::Always );
719 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
722 myWindows[flag]->insert( sId, wid );
724 setWindowShown( flag, !myWindows[flag]->isEmpty() );
727 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
729 if ( !myWindows.contains( flag ) )
735 if ( !activeStudy() )
738 sId = activeStudy()->id();
741 QWidget* wid = myWindows[flag]->widget( sId );
742 myWindows[flag]->remove( sId );
745 setWindowShown( flag, !myWindows[flag]->isEmpty() );
748 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
750 QWidget* wid = window( flag, studyId );
752 addWindow( wid = createWindow( flag ), flag, studyId );
757 bool SalomeApp_Application::isWindowVisible( const int type ) const
760 if ( myWindows.contains( type ) )
762 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
763 res = desk && desk->appropriate( myWindows[type] );
768 void SalomeApp_Application::setWindowShown( const int type, const bool on )
770 if ( !desktop() || !myWindows.contains( type ) )
773 QDockWindow* dw = myWindows[type];
774 desktop()->setAppropriate( dw, on );
775 on ? dw->show() : dw->hide();
778 OB_Browser* SalomeApp_Application::objectBrowser()
781 QWidget* wid = getWindow( WT_ObjectBrowser );
782 if ( wid->inherits( "OB_Browser" ) )
783 ob = (OB_Browser*)wid;
787 LogWindow* SalomeApp_Application::logWindow()
790 QWidget* wid = getWindow( WT_LogWindow );
791 if ( wid->inherits( "LogWindow" ) )
792 lw = (LogWindow*)wid;
796 PythonConsole* SalomeApp_Application::pythonConsole()
798 PythonConsole* console = 0;
799 QWidget* wid = getWindow( WT_PyConsole );
800 if ( wid->inherits( "PythonConsole" ) )
801 console = (PythonConsole*)wid;
805 SalomeApp_Preferences* SalomeApp_Application::preferences() const
807 return preferences( false );
810 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
812 SUIT_ViewManager* aVM = viewManager( vmType );
813 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
815 if ( anActiveVM && anActiveVM->getType() == vmType )
820 if ( !aVM->getActiveView() )
823 aVM->getActiveView()->setFocus();
826 aVM = createViewManager( vmType );
831 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
833 SUIT_ResourceMgr* resMgr = resourceMgr();
835 SUIT_ViewManager* viewMgr = 0;
836 if ( vmType == GLViewer_Viewer::Type() )
838 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
839 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
841 else if ( vmType == Plot2d_Viewer::Type() )
843 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
844 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
846 else if ( vmType == OCCViewer_Viewer::Type() )
848 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
849 SOCC_Viewer* vm = new SOCC_Viewer();
850 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
851 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
854 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
855 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
856 // vm->setIsos( u, v );
857 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
858 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
860 else if ( vmType == SVTK_Viewer::Type() )
862 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
863 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
864 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
865 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
866 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
872 addViewManager( viewMgr );
873 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
875 if ( viewWin && desktop() )
876 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
878 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
879 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
884 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
886 removeViewManager( theVM );
889 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
891 SUIT_DataObject* aRoot = 0;
892 if ( theStudy && theStudy->root() )
894 aRoot = theStudy->root();
895 //aRoot->setName( tr( "DATA_MODELS" ) );
897 if ( objectBrowser() != 0 )
898 objectBrowser()->setRootObject( aRoot );
900 activateModule( defaultModule() );
905 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
907 SUIT_DataObject* aRoot = 0;
908 if ( theStudy && theStudy->root() )
910 aRoot = theStudy->root();
913 if ( objectBrowser() != 0 ) {
914 objectBrowser()->setRootObject( aRoot );
917 activateModule( defaultModule() );
924 void SalomeApp_Application::onStudySaved( SUIT_Study* )
929 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
933 activateModule( "" );
935 saveWindowsGeometry();
938 void SalomeApp_Application::onDumpStudy( )
940 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
941 if ( !appStudy ) return;
942 _PTR(Study) aStudy = appStudy->studyDS();
944 QStringList aFilters;
945 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
947 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
948 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
949 fd->setFilters( aFilters );
950 fd->SetChecked(true);
952 QString aFileName = fd->selectedFile();
953 bool toPublish = fd->IsChecked();
956 if(!aFileName.isEmpty()) {
957 QFileInfo aFileInfo(aFileName);
958 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
962 void SalomeApp_Application::onLoadScript( )
964 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
965 if ( !appStudy ) return;
966 _PTR(Study) aStudy = appStudy->studyDS();
968 if ( aStudy->GetProperties()->IsLocked() ) {
969 SUIT_MessageBox::warn1 ( desktop(),
970 QObject::tr("WRN_WARNING"),
971 QObject::tr("WRN_STUDY_LOCKED"),
972 QObject::tr("BUT_OK") );
976 QStringList filtersList;
977 filtersList.append(tr("PYTHON_FILES_FILTER"));
978 filtersList.append(tr("ALL_FILES_FILTER"));
980 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
982 if ( !aFile.isEmpty() )
984 QString command = QString("execfile(\"%1\")").arg(aFile);
986 PythonConsole* pyConsole = pythonConsole();
989 pyConsole->exec( command );
993 void SalomeApp_Application::onPreferences()
995 QApplication::setOverrideCursor( Qt::waitCursor );
997 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
999 QApplication::restoreOverrideCursor();
1009 void SalomeApp_Application::onMRUActivated( QString aName )
1014 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1016 SalomeApp_Module* sMod = 0;
1017 CAM_Module* mod = module( modName );
1018 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1019 sMod = (SalomeApp_Module*)mod;
1022 sMod->preferencesChanged( section, param );
1024 preferencesChanged( section, param );
1027 QString SalomeApp_Application::getFileFilter() const
1032 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1034 CAM_Application::beforeCloseDoc( s );
1036 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1037 removeWindow( itr.key(), s->id() );
1040 void SalomeApp_Application::updateActions()
1042 updateCommandsStatus();
1045 QWidget* SalomeApp_Application::createWindow( const int flag )
1049 SUIT_ResourceMgr* resMgr = resourceMgr();
1051 if ( flag == WT_ObjectBrowser )
1053 OB_Browser* ob = new OB_Browser( desktop() );
1054 ob->setAutoUpdate( true );
1055 ob->setAutoOpenLevel( 1 );
1056 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1057 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1058 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1060 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1062 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1064 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1065 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1066 QString().sprintf( "visibility_column_%d", i ), true ) );
1069 // Create OBSelector
1070 new SalomeApp_OBSelector( ob, mySelMgr );
1074 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1076 else if ( flag == WT_PyConsole )
1078 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1079 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1082 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1084 else if ( flag == WT_LogWindow )
1086 LogWindow* logWin = new LogWindow( desktop() );
1087 logWin->setCaption( tr( "LOG_WINDOW" ) );
1090 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1096 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1098 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1099 aMap.insert( WT_PyConsole, Qt::DockBottom );
1100 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1103 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1107 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1112 SalomeApp_Application* that = (SalomeApp_Application*)this;
1114 if ( !_prefs_ && crt )
1116 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1117 that->createPreferences( _prefs_ );
1120 that->myPrefs = _prefs_;
1122 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1123 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1125 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1128 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1130 QStringList modNameList;
1131 app->modules( modNameList, false );
1132 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1134 int id = _prefs_->addPreference( *it );
1135 _prefs_->setProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1139 app->modules( modList );
1140 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1142 SalomeApp_Module* mod = 0;
1143 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1144 mod = (SalomeApp_Module*)itr.current();
1146 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1147 mod->createPreferences();
1151 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1152 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1157 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1159 CAM_Application::moduleAdded( mod );
1161 SalomeApp_Module* salomeMod = 0;
1162 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1163 salomeMod = (SalomeApp_Module*)mod;
1165 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ))
1166 salomeMod->createPreferences();
1169 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1174 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1176 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1178 int obGroup = pref->addPreference( tr( "PREF_GROUP_OBJBROWSER" ), genTab );
1179 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1181 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), obGroup,
1182 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1184 pref->setProperty( obGroup, "columns", 1 );
1186 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1188 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1190 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1191 pref->setProperty( occGroup, "columns", 1 );
1192 pref->setProperty( vtkGroup, "columns", 1 );
1194 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1195 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1196 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1197 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1199 pref->setProperty( occTS, "min", 1 );
1200 pref->setProperty( occTS, "max", 150 );
1202 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1203 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1204 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1205 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1207 pref->setProperty( isoU, "min", 0 );
1208 pref->setProperty( isoU, "max", 100000 );
1210 pref->setProperty( isoV, "min", 0 );
1211 pref->setProperty( isoV, "max", 100000 );
1213 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1214 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1215 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1216 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1218 pref->setProperty( vtkTS, "min", 1 );
1219 pref->setProperty( vtkTS, "max", 150 );
1222 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1224 SUIT_ResourceMgr* resMgr = resourceMgr();
1228 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1230 int sz = resMgr->integerValue( sec, param, -1 );
1231 QPtrList<SUIT_ViewManager> lst;
1232 viewManagers( OCCViewer_Viewer::Type(), lst );
1233 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1235 SUIT_ViewModel* vm = it.current()->getViewModel();
1236 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1239 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1240 occVM->setTrihedronSize( sz );
1241 occVM->getAISContext()->UpdateCurrentViewer();
1245 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1247 int sz = resMgr->integerValue( sec, param, -1 );
1248 QPtrList<SUIT_ViewManager> lst;
1249 viewManagers( SVTK_Viewer::Type(), lst );
1250 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1252 SUIT_ViewModel* vm = it.current()->getViewModel();
1253 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1256 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1257 vtkVM->setTrihedronSize( sz );
1262 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1264 QPtrList<SUIT_ViewManager> lst;
1265 viewManagers( OCCViewer_Viewer::Type(), lst );
1266 int u = resMgr->integerValue( sec, "iso_number_u" );
1267 int v = resMgr->integerValue( sec, "iso_number_v" );
1268 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1269 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1274 void SalomeApp_Application::afterCloseDoc()
1278 CAM_Application::afterCloseDoc();
1281 CORBA::ORB_var SalomeApp_Application::orb()
1283 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1284 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1288 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1290 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1294 SALOME_NamingService* SalomeApp_Application::namingService()
1296 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1300 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1302 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1306 QString SalomeApp_Application::defaultEngineIOR()
1308 // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1309 QString anIOR( "" );
1310 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1311 if ( !CORBA::is_nil( anEngine ) )
1312 anIOR = orb()->object_to_string( anEngine );
1316 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1320 SUIT_ResourceMgr* resMgr = resourceMgr();
1324 QStringList modList;
1325 modules( modList, false );
1327 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1329 QString modName = *it;
1330 QString modIntr = moduleName( modName );
1331 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1333 if ( modIcon.isEmpty() )
1336 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1337 modIcon += QString( ".png" );
1339 iconMap.insert( modName, modIcon );
1343 void SalomeApp_Application::updateModuleActions()
1346 if ( activeModule() )
1347 modName = activeModule()->moduleName();
1349 if ( myActions.contains( modName ) )
1350 myActions[modName]->setOn( true );
1353 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1356 if ( !activeStudy() )
1359 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1360 ((SalomeApp_Module*)activeModule())->windows( winMap );
1362 defaultWindows( winMap );
1365 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1368 if ( !activeStudy() )
1371 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1372 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1374 defaultViewManagers( lst );
1377 void SalomeApp_Application::updateWindows()
1379 QMap<int, int> winMap;
1380 currentWindows( winMap );
1382 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1383 getWindow( it.key() );
1385 loadWindowsGeometry();
1387 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1388 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1391 void SalomeApp_Application::updateViewManagers()
1394 currentViewManagers( lst );
1396 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1397 getViewManager( *it, true );
1400 void SalomeApp_Application::loadWindowsGeometry()
1402 QtxDockAction* dockMgr = 0;
1404 QAction* a = action( ViewWindowsId );
1405 if ( a && a->inherits( "QtxDockAction" ) )
1406 dockMgr = (QtxDockAction*)a;
1412 if ( activeModule() )
1413 modName = moduleLibrary( activeModule()->moduleName(), false );
1415 QString section = QString( "windows_geometry" );
1416 if ( !modName.isEmpty() )
1417 section += QString( "." ) + modName;
1419 dockMgr->loadGeometry( resourceMgr(), section, false );
1420 dockMgr->restoreGeometry();
1423 void SalomeApp_Application::saveWindowsGeometry()
1425 QtxDockAction* dockMgr = 0;
1427 QAction* a = action( ViewWindowsId );
1428 if ( a && a->inherits( "QtxDockAction" ) )
1429 dockMgr = (QtxDockAction*)a;
1435 if ( activeModule() )
1436 modName = moduleLibrary( activeModule()->moduleName(), false );
1438 QString section = QString( "windows_geometry" );
1439 if ( !modName.isEmpty() )
1440 section += QString( "." ) + modName;
1442 dockMgr->storeGeometry();
1443 dockMgr->saveGeometry( resourceMgr(), section, false );
1446 void SalomeApp_Application::activateWindows()
1448 if ( activeStudy() )
1450 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1451 itr.data()->activate( activeStudy()->id() );
1455 void SalomeApp_Application::onProperties()
1457 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1461 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1464 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1465 int res = aDlg.exec();
1466 if( res==QDialog::Accepted && aDlg.isChanged() )
1467 SB->CommitCommand();
1471 //study->updateCaptions();
1474 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1475 const QString& caption, QWidget* parent )
1479 QStringList fls = QStringList::split( ";;", filters, false );
1480 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1483 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1487 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1490 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1491 const QString& caption, QWidget* parent )
1495 QStringList fls = QStringList::split( ";;", filters, false );
1496 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1499 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1501 CAM_Application::contextMenuPopup( type, thePopup, title );
1502 thePopup->insertSeparator();
1503 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1504 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1507 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1511 for ( ModuleListIterator it = modules(); it.current(); ++it )
1513 CAM_DataModel* camDM = it.current()->dataModel();
1514 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1515 ((SalomeApp_DataModel*)camDM)->update();
1518 if ( objectBrowser() )
1519 objectBrowser()->updateTree();