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 "STD_LoadStudiesDlg.h"
49 #include <SUIT_Tools.h>
50 #include <SUIT_Session.h>
52 #include <QtxToolBar.h>
53 #include <QtxMRUAction.h>
54 #include <QtxDockAction.h>
55 #include <QtxResourceEdit.h>
57 #include <OB_Browser.h>
59 #include <PythonConsole_PyConsole.h>
61 #include <SUIT_FileDlg.h>
62 #include <SUIT_MessageBox.h>
63 #include <SUIT_ResourceMgr.h>
64 #include <SUIT_ActionOperation.h>
66 #include <Utils_ORB_INIT.hxx>
67 #include <Utils_SINGLETON.hxx>
68 #include <SALOME_ModuleCatalog_impl.hxx>
69 #include <SALOME_LifeCycleCORBA.hxx>
77 #include <qcombobox.h>
78 #include <qmessagebox.h>
79 #include <qapplication.h>
83 #include "SALOMEDS_StudyManager.hxx"
85 #include "SALOME_ListIteratorOfListIO.hxx"
86 #include "SALOME_ListIO.hxx"
88 #include "ToolsGUI_CatalogGeneratorDlg.h"
89 #include "ToolsGUI_RegWidget.h"
91 #define OBJECT_BROWSER_WIDTH 300
93 /*!Image for empty icon.*/
94 static const char* imageEmptyIcon[] = {
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "....................",
111 "....................",
112 "....................",
113 "....................",
114 "....................",
115 "....................",
116 "...................."};
118 /*!Create new instance of SalomeApp_Application.*/
119 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
121 return new SalomeApp_Application();
124 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
127 Class : SalomeApp_Application
128 Description : Application containing SalomeApp module
132 SalomeApp_Application::SalomeApp_Application()
133 : CAM_Application( false ),
136 STD_TabDesktop* desk = new STD_TabDesktop();
140 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
141 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
143 desktop()->setIcon( aLogo );
144 desktop()->setDockableMenuBar( true );
145 desktop()->setDockableStatusBar( false );
149 mySelMgr = new SalomeApp_SelectionMgr( this );
151 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
152 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
154 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
158 *\li Save window geometry.
159 *\li Save desktop geometry.
160 *\li Save resource maneger.
161 *\li Delete selection manager.
162 *\li Destroy event filter.
164 SalomeApp_Application::~SalomeApp_Application()
166 saveWindowsGeometry();
171 desktop()->saveGeometry( resourceMgr(), "desktop" );
172 resourceMgr()->save();
177 SalomeApp_EventFilter::Destroy();
180 /*!Start application.*/
181 void SalomeApp_Application::start()
184 desktop()->loadGeometry( resourceMgr(), "desktop" );
186 CAM_Application::start();
188 QAction* a = action( ViewWindowsId );
189 if ( a && a->inherits( "QtxDockAction" ) )
190 ((QtxDockAction*)a)->setAutoPlace( true );
192 SalomeApp_EventFilter::Init();
195 updateViewManagers();
200 /*!Gets application name.*/
201 QString SalomeApp_Application::applicationName() const
203 return tr( "APP_NAME" );
206 /*!Gets application version.*/
207 QString SalomeApp_Application::applicationVersion() const
209 static QString _app_version;
211 if ( _app_version.isEmpty() )
213 QString path( ::getenv( "GUI_ROOT_DIR" ) );
214 if ( !path.isEmpty() )
215 path += QDir::separator();
216 path += QString( "bin/salome/VERSION" );
219 if ( vf.open( IO_ReadOnly ) )
222 vf.readLine( line, 1024 );
225 if ( !line.isEmpty() )
227 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
228 line.remove( line.length() - 1, 1 );
230 int idx = line.findRev( ":" );
232 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
240 /*!Load module by \a name.*/
241 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
243 CAM_Module* mod = CAM_Application::loadModule( name );
246 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
247 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
248 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
253 /*!Activate module by \a modName*/
254 bool SalomeApp_Application::activateModule( const QString& modName )
257 CAM_Module* prevMod = activeModule();
260 actName = prevMod->moduleName();
262 if ( actName == modName )
265 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
267 saveWindowsGeometry();
269 bool status = CAM_Application::activateModule( modName );
271 updateModuleActions();
279 updateViewManagers();
284 /*!Gets selection manager.*/
285 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
291 void SalomeApp_Application::createActions()
293 STD_Application::createActions();
295 SUIT_Desktop* desk = desktop();
296 SUIT_ResourceMgr* resMgr = resourceMgr();
299 createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
300 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
301 0, desk, false, this, SLOT( onDumpStudy() ) );
304 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
305 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
306 0, desk, false, this, SLOT( onLoadScript() ) );
309 createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
310 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
311 0, desk, false, this, SLOT( onProperties() ) );
314 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
315 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
316 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
318 //! Catalog Generator
319 createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIconSet(),
320 tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ),
321 0, desk, false, this, SLOT( onCatalogGen() ) );
324 createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIconSet(),
325 tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ),
326 0, desk, false, this, SLOT( onRegDisplay() ) );
329 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
330 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
331 registerAction( MRUId, mru );
333 //! default icon for neutral point ('SALOME' module)
334 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
335 if ( defIcon.isNull() )
336 defIcon = QPixmap( imageEmptyIcon );
338 //! default icon for any module
339 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
340 if ( modIcon.isNull() )
341 modIcon = QPixmap( imageEmptyIcon );
343 QToolBar* modTBar = new QtxToolBar( true, desk );
344 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
346 QActionGroup* modGroup = new QActionGroup( this );
347 modGroup->setExclusive( true );
348 modGroup->setUsesDropDown( true );
350 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
351 tr( "PRP_APP_MODULE" ), 0, desk, true );
353 myActions.insert( QString(), a );
355 QMap<QString, QString> iconMap;
356 moduleIconNames( iconMap );
358 const int iconSize = 20;
360 modGroup->addTo( modTBar );
361 modTBar->addSeparator();
364 modules( modList, false );
366 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
368 if ( (*it).isEmpty() )
372 if ( iconMap.contains( *it ) )
373 iconName = iconMap[*it];
375 QString modName = moduleName( *it );
377 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
381 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
383 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
387 myActions.insert( *it, a );
390 SUIT_Tools::simplifySeparators( modTBar );
394 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
395 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
396 createMenu( separator(), windowMenu, -1, 1 );
398 QMap<int, int> accelMap;
399 accelMap[NewGLViewId] = ALT+Key_G;
400 accelMap[NewPlot2dId] = ALT+Key_P;
401 accelMap[NewOCCViewId] = ALT+Key_O;
402 accelMap[NewVTKViewId] = ALT+Key_K;
404 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
406 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
407 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
408 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
409 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
410 createMenu( a, newWinMenu, -1 );
412 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
414 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
416 createMenu( DumpStudyId, fileMenu, 10, -1 );
417 createMenu( separator(), fileMenu, -1, 15, -1 );
418 createMenu( LoadScriptId, fileMenu, 10, -1 );
419 createMenu( separator(), fileMenu, -1, 15, -1 );
420 createMenu( PropertiesId, fileMenu, 10, -1 );
421 createMenu( separator(), fileMenu, -1, 15, -1 );
422 createMenu( PreferencesId, fileMenu, 15, -1 );
423 createMenu( separator(), fileMenu, -1, 15, -1 );
425 int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, -1, 50 );
426 createMenu( CatalogGenId, toolsMenu, 10, -1 );
427 createMenu( RegDisplayId, toolsMenu, 10, -1 );
428 createMenu( separator(), toolsMenu, -1, 15, -1 );
431 createMenu( separator(), fileMenu, -1, 100, -1 );
432 createMenu( MRUId, fileMenu, 100, -1 );
433 createMenu( separator(), fileMenu, -1, 100, -1 );
437 /*!On module activation action.*/
438 void SalomeApp_Application::onModuleActivation( QAction* a )
443 QString modName = a->menuText();
444 if ( modName == tr( "APP_NAME" ) )
445 modName = QString::null;
447 // Force user to create/open a study before module activation
448 QMap<QString, QString> iconMap;
449 moduleIconNames( iconMap );
450 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
452 icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
454 bool cancelled = false;
455 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
456 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
457 int res = aDlg.exec();
471 putInfo( tr("INF_CANCELLED") );
472 myActions[QString()]->setOn( true );
478 activateModule( modName );
481 /*!Default module activation.*/
482 QString SalomeApp_Application::defaultModule() const
484 QStringList aModuleNames;
485 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
486 //! If there's the one and only module --> activate it automatically
487 //! TODO: Possible improvement - default module can be taken from preferences
488 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
491 /*!On new window slot.*/
492 void SalomeApp_Application::onNewWindow()
494 const QObject* obj = sender();
495 if ( !obj || !obj->inherits( "QAction" ) )
499 int id = actionId( (QAction*)obj );
503 type = GLViewer_Viewer::Type();
506 type = Plot2d_Viewer::Type();
509 type = OCCViewer_Viewer::Type();
512 type = VTKViewer_Viewer::Type();
516 if ( !type.isEmpty() )
517 createViewManager( type );
520 //=======================================================================
522 /*! Purpose : SLOT. Create new document*/
523 //=======================================================================
524 void SalomeApp_Application::onNewDoc()
526 SUIT_Study* study = activeStudy();
528 saveWindowsGeometry();
530 CAM_Application::onNewDoc();
532 if ( !study ) // new study will be create in THIS application
535 updateViewManagers();
539 //=======================================================================
541 /*! Purpose : SLOT. Open new document*/
542 //=======================================================================
543 void SalomeApp_Application::onOpenDoc()
545 SUIT_Study* study = activeStudy();
546 saveWindowsGeometry();
548 CAM_Application::onOpenDoc();
550 if ( !study ) // new study will be create in THIS application
553 updateViewManagers();
557 /*! Purpose : SLOT. Open new document with \a aName.*/
558 bool SalomeApp_Application::onOpenDoc( const QString& aName )
560 bool res = CAM_Application::onOpenDoc( aName );
562 QAction* a = action( MRUId );
563 if ( a && a->inherits( "QtxMRUAction" ) )
565 QtxMRUAction* mru = (QtxMRUAction*)a;
567 mru->insert( aName );
569 mru->remove( aName );
574 /*!SLOT. Load document.*/
575 void SalomeApp_Application::onLoadDoc()
577 QString name, studyname, ext;
579 STD_LoadStudiesDlg aDlg( desktop(), TRUE);
581 std::vector<std::string> List = studyMgr()->GetOpenStudies();
583 SUIT_Session* aSession = SUIT_Session::session();
584 QPtrList<SUIT_Application> aAppList = aSession->applications();
585 SUIT_Application* aApp = 0;
587 for (unsigned int ind = 0; ind < List.size(); ind++) {
588 studyname = List[ind].c_str();
589 //Add to list only unloaded studies
590 bool isAlreadyOpen = false;
591 for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
594 if(!aApp || !aApp->activeStudy()) continue;
595 if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
598 if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
601 int retVal = aDlg.exec();
602 studyname = aDlg.ListComponent->currentText();
604 if (retVal == QDialog::Rejected)
607 if ( studyname.isNull() || studyname.isEmpty() )
611 name.replace( QRegExp(":"), "/" );
613 if(onLoadDoc(name)) {
615 updateViewManagers();
616 updateObjectBrowser(true);
621 /*!SLOT. Load document with \a aName.*/
622 bool SalomeApp_Application::onLoadDoc( const QString& aName )
624 bool res = CAM_Application::onLoadDoc( aName );
626 /*jfa tmp:QAction* a = action( MRUId );
627 if ( a && a->inherits( "QtxMRUAction" ) )
629 QtxMRUAction* mru = (QtxMRUAction*)a;
631 mru->insert( aName );
633 mru->remove( aName );
638 /*!Private SLOT. Selection.*/
639 void SalomeApp_Application::onSelection()
641 onSelectionChanged();
643 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
644 ((SalomeApp_Module*)activeModule())->selectionChanged();
647 /*!SLOT. Copy objects to study maneger from selection maneger..*/
648 void SalomeApp_Application::onCopy()
651 SalomeApp_SelectionMgr* mgr = selectionMgr();
652 mgr->selectedObjects(list);
654 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
655 if(study == NULL) return;
657 _PTR(Study) stdDS = study->studyDS();
660 SALOME_ListIteratorOfListIO it( list );
663 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
665 studyMgr()->Copy(so);
666 onSelectionChanged();
673 /*!SLOT. Paste objects to study maneger from selection manager.*/
674 void SalomeApp_Application::onPaste()
677 SalomeApp_SelectionMgr* mgr = selectionMgr();
678 mgr->selectedObjects(list);
680 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
681 if(study == NULL) return;
683 _PTR(Study) stdDS = study->studyDS();
686 SALOME_ListIteratorOfListIO it( list );
689 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
691 studyMgr()->Paste(so);
692 updateObjectBrowser( true );
693 updateActions(); //SRN: BugID IPAL9377, case 3
700 /*!Sets enable or disable some actions on selection changed.*/
701 void SalomeApp_Application::onSelectionChanged()
704 SalomeApp_SelectionMgr* mgr = selectionMgr();
705 mgr->selectedObjects(list);
707 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
708 if(study == NULL) return;
710 _PTR(Study) stdDS = study->studyDS();
715 SALOME_ListIteratorOfListIO it( list );
716 if(it.More() && list.Extent() == 1)
718 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
720 qaction = action(EditCopyId);
721 if(studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
722 else qaction->setEnabled(false);
724 qaction = action(EditPasteId);
725 if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
726 else qaction->setEnabled(false);
729 qaction = action(EditCopyId);
730 qaction->setEnabled(false);
731 qaction = action(EditPasteId);
732 qaction->setEnabled(false);
736 /*!Update object browser.*/
737 void SalomeApp_Application::onRefresh()
739 updateObjectBrowser( true );
743 void SalomeApp_Application::onOpenWith()
745 QApplication::setOverrideCursor( Qt::waitCursor );
747 SalomeApp_SelectionMgr* mgr = selectionMgr();
748 mgr->selectedObjects(aList);
749 if (aList.Extent() != 1)
751 QApplication::restoreOverrideCursor();
754 Handle(SALOME_InteractiveObject) aIObj = aList.First();
755 QString aModuleName(aIObj->getComponentDataType());
756 QString aModuleTitle = moduleTitle(aModuleName);
757 activateModule(aModuleTitle);
758 QApplication::restoreOverrideCursor();
761 bool SalomeApp_Application::useStudy(const QString& theName)
764 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
767 res = aStudy->loadDocument( theName );
768 updateDesktopTitle();
769 updateCommandsStatus();
774 *\param study - SUIT_Study.
776 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
778 CAM_Application::setActiveStudy( study );
783 //=======================================================================
784 // name : createNewStudy
785 /*! Purpose : Create new study*/
786 //=======================================================================
787 SUIT_Study* SalomeApp_Application::createNewStudy()
789 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
791 // Set up processing of major study-related events
792 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
793 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
794 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
795 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
800 //=======================================================================
801 // name : createNewStudy
802 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
803 //=======================================================================
804 void SalomeApp_Application::updateCommandsStatus()
806 CAM_Application::updateCommandsStatus();
808 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
810 QAction* a = action( id );
812 a->setEnabled( activeStudy() );
816 QAction* a = action( DumpStudyId );
818 a->setEnabled( activeStudy() );
821 a = action( LoadScriptId );
823 a->setEnabled( activeStudy() );
825 a = action( PropertiesId );
827 a->setEnabled( activeStudy() );
829 a = action(EditCopyId);
830 a->setEnabled(false);
831 a = action(EditPasteId);
832 a->setEnabled(false);
835 //=======================================================================
836 // name : onHelpAbout
837 /*! Purpose : SLOT. Display "About" message box*/
838 //=======================================================================
839 void SalomeApp_Application::onHelpAbout()
841 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
846 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
853 if ( !activeStudy() )
856 sId = activeStudy()->id();
859 if ( myWindows.contains( flag ) )
860 wid = myWindows[flag]->widget( sId );
865 /*!Adds window to application.
866 *\param wid - QWidget
867 *\param flag - key wor window
868 *\param studyId - study id
869 * Flag used how identificator of window in windows list.
871 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
879 if ( !activeStudy() )
882 sId = activeStudy()->id();
885 if ( !myWindows.contains( flag ) )
887 QMap<int, int> winMap;
888 currentWindows( winMap );
890 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
891 if ( winMap.contains( flag ) )
892 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
894 myWindows[flag]->setResizeEnabled( true );
895 myWindows[flag]->setCloseMode( QDockWindow::Always );
896 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
900 if( wid->inherits( "PythonConsole" ) )
901 f = ( ( PythonConsole* )wid )->font();
905 myWindows[flag]->insert( sId, wid );
908 setWindowShown( flag, !myWindows[flag]->isEmpty() );
911 /*!Remove window from application.
912 *\param flag - key wor window
913 *\param studyId - study id
914 * Flag used how identificator of window in windows list.
916 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
918 if ( !myWindows.contains( flag ) )
924 if ( !activeStudy() )
927 sId = activeStudy()->id();
930 QWidget* wid = myWindows[flag]->widget( sId );
931 myWindows[flag]->remove( sId );
934 setWindowShown( flag, !myWindows[flag]->isEmpty() );
938 *\param flag - key wor window
939 *\param studyId - study id
940 * Flag used how identificator of window in windows list.
942 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
944 QWidget* wid = window( flag, studyId );
946 addWindow( wid = createWindow( flag ), flag, studyId );
951 /*!Check is window visible?(with identificator \a type)*/
952 bool SalomeApp_Application::isWindowVisible( const int type ) const
955 if ( myWindows.contains( type ) )
957 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
958 res = desk && desk->appropriate( myWindows[type] );
963 /*!Sets window show or hide.
964 *\param type - window identificator.
965 *\param on - true/false (window show/hide)
967 void SalomeApp_Application::setWindowShown( const int type, const bool on )
969 if ( !desktop() || !myWindows.contains( type ) )
972 QDockWindow* dw = myWindows[type];
973 desktop()->setAppropriate( dw, on );
974 on ? dw->show() : dw->hide();
977 OB_Browser* SalomeApp_Application::objectBrowser()
980 QWidget* wid = getWindow( WT_ObjectBrowser );
981 if ( wid->inherits( "OB_Browser" ) )
982 ob = (OB_Browser*)wid;
986 /*!Gets "LogWindow".*/
987 LogWindow* SalomeApp_Application::logWindow()
990 QWidget* wid = getWindow( WT_LogWindow );
991 if ( wid->inherits( "LogWindow" ) )
992 lw = (LogWindow*)wid;
996 /*!Get "PythonConsole"*/
997 PythonConsole* SalomeApp_Application::pythonConsole()
999 PythonConsole* console = 0;
1000 QWidget* wid = getWindow( WT_PyConsole );
1001 if ( wid->inherits( "PythonConsole" ) )
1002 console = (PythonConsole*)wid;
1006 /*!Gets preferences.*/
1007 SalomeApp_Preferences* SalomeApp_Application::preferences() const
1009 return preferences( false );
1012 /*!Gets view manager*/
1013 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
1015 SUIT_ViewManager* aVM = viewManager( vmType );
1016 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1018 if ( anActiveVM && anActiveVM->getType() == vmType )
1021 if ( aVM && create )
1023 if ( !aVM->getActiveView() )
1026 aVM->getActiveView()->setFocus();
1029 aVM = createViewManager( vmType );
1034 /*!Create view manager.*/
1035 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
1037 SUIT_ResourceMgr* resMgr = resourceMgr();
1039 SUIT_ViewManager* viewMgr = 0;
1040 if ( vmType == GLViewer_Viewer::Type() )
1042 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1043 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1045 else if ( vmType == Plot2d_Viewer::Type() )
1047 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1048 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
1050 else if ( vmType == OCCViewer_Viewer::Type() )
1052 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1053 SOCC_Viewer* vm = new SOCC_Viewer();
1054 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1055 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1058 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1059 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1060 vm->setIsos( u, v );
1061 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1062 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1064 else if ( vmType == SVTK_Viewer::Type() )
1066 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1067 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
1068 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1069 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1070 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
1076 addViewManager( viewMgr );
1077 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1079 if ( viewWin && desktop() )
1080 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1082 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1083 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1088 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1090 removeViewManager( theVM );
1093 /*!Private SLOT. On study created.*/
1094 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1096 SUIT_DataObject* aRoot = 0;
1097 if ( theStudy && theStudy->root() )
1099 aRoot = theStudy->root();
1100 //aRoot->setName( tr( "DATA_MODELS" ) );
1102 if ( objectBrowser() != 0 )
1103 objectBrowser()->setRootObject( aRoot );
1105 activateModule( defaultModule() );
1110 /*!Private SLOT. On study opened.*/
1111 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1113 SUIT_DataObject* aRoot = 0;
1114 if ( theStudy && theStudy->root() )
1116 aRoot = theStudy->root();
1119 if ( objectBrowser() != 0 ) {
1120 objectBrowser()->setRootObject( aRoot );
1123 activateModule( defaultModule() );
1130 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1135 /*!Private SLOT. On study closed.*/
1136 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1140 activateModule( "" );
1142 saveWindowsGeometry();
1145 /*!Private SLOT. On dump study.*/
1146 void SalomeApp_Application::onDumpStudy( )
1148 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1149 if ( !appStudy ) return;
1150 _PTR(Study) aStudy = appStudy->studyDS();
1152 QStringList aFilters;
1153 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1155 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1156 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1157 fd->setFilters( aFilters );
1158 fd->SetChecked(true);
1160 QString aFileName = fd->selectedFile();
1161 bool toPublish = fd->IsChecked();
1164 if(!aFileName.isEmpty()) {
1165 QFileInfo aFileInfo(aFileName);
1166 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1170 /*!Private SLOT. On load script.*/
1171 void SalomeApp_Application::onLoadScript( )
1173 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1174 if ( !appStudy ) return;
1175 _PTR(Study) aStudy = appStudy->studyDS();
1177 if ( aStudy->GetProperties()->IsLocked() ) {
1178 SUIT_MessageBox::warn1 ( desktop(),
1179 QObject::tr("WRN_WARNING"),
1180 QObject::tr("WRN_STUDY_LOCKED"),
1181 QObject::tr("BUT_OK") );
1185 QStringList filtersList;
1186 filtersList.append(tr("PYTHON_FILES_FILTER"));
1187 filtersList.append(tr("ALL_FILES_FILTER"));
1189 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1191 if ( !aFile.isEmpty() )
1193 QString command = QString("execfile(\"%1\")").arg(aFile);
1195 PythonConsole* pyConsole = pythonConsole();
1198 pyConsole->exec( command );
1202 /*!Private SLOT. On preferences.*/
1203 void SalomeApp_Application::onPreferences()
1205 QApplication::setOverrideCursor( Qt::waitCursor );
1207 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1209 QApplication::restoreOverrideCursor();
1219 /*!Private SLOT. On open document with name \a aName.*/
1220 void SalomeApp_Application::onMRUActivated( QString aName )
1225 /*!Private SLOT. On preferences changed.*/
1226 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1228 SalomeApp_Module* sMod = 0;
1229 CAM_Module* mod = module( modName );
1230 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1231 sMod = (SalomeApp_Module*)mod;
1234 sMod->preferencesChanged( section, param );
1236 preferencesChanged( section, param );
1239 /*!Gets file filter.
1240 *\retval QString "(*.hdf)"
1242 QString SalomeApp_Application::getFileFilter() const
1247 /*!Remove all windows from study.*/
1248 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1250 CAM_Application::beforeCloseDoc( s );
1252 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1253 removeWindow( itr.key(), s->id() );
1256 /*!Update actions.*/
1257 void SalomeApp_Application::updateActions()
1259 updateCommandsStatus();
1263 QWidget* SalomeApp_Application::createWindow( const int flag )
1267 SUIT_ResourceMgr* resMgr = resourceMgr();
1269 if ( flag == WT_ObjectBrowser )
1271 OB_Browser* ob = new OB_Browser( desktop() );
1272 ob->setAutoUpdate( true );
1273 ob->setAutoOpenLevel( 1 );
1274 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1275 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1276 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1278 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1280 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1281 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1283 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1284 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1285 QString().sprintf( "visibility_column_%d", i ), true ) );
1287 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1289 // Create OBSelector
1290 new SalomeApp_OBSelector( ob, mySelMgr );
1294 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1296 else if ( flag == WT_PyConsole )
1298 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1299 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1300 pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1303 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1305 else if ( flag == WT_LogWindow )
1307 LogWindow* logWin = new LogWindow( desktop() );
1308 logWin->setCaption( tr( "LOG_WINDOW" ) );
1311 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1317 /*!Default windows(Object Browser, Python Console).
1318 * Adds to map \a aMap.
1320 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1322 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1323 aMap.insert( WT_PyConsole, Qt::DockBottom );
1324 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1327 /*!Default view manager.*/
1328 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1333 /*!Gets preferences.
1334 * Create preferences, if \a crt = true.
1336 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1341 SalomeApp_Application* that = (SalomeApp_Application*)this;
1343 if ( !_prefs_ && crt )
1345 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1346 that->createPreferences( _prefs_ );
1349 that->myPrefs = _prefs_;
1351 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1352 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1354 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1357 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1359 QStringList modNameList;
1360 app->modules( modNameList, false );
1361 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1363 int id = _prefs_->addPreference( *it );
1364 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1368 app->modules( modList );
1369 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1371 SalomeApp_Module* mod = 0;
1372 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1373 mod = (SalomeApp_Module*)itr.current();
1375 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1377 int modCat = _prefs_->addPreference( mod->moduleName() );
1378 _prefs_->setItemProperty( modCat, "info", QString::null );
1379 mod->createPreferences();
1384 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1385 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1390 /*!Add new module to application.*/
1391 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1393 CAM_Application::moduleAdded( mod );
1395 SalomeApp_Module* salomeMod = 0;
1396 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1397 salomeMod = (SalomeApp_Module*)mod;
1399 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1401 int modCat = myPrefs->addPreference( mod->moduleName() );
1402 myPrefs->setItemProperty( modCat, "info", QString::null );
1403 salomeMod->createPreferences();
1407 /*!Create preferences.*/
1408 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1413 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1415 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1416 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1417 pref->setItemProperty( studyGroup, "columns", 1 );
1419 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1420 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1421 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1422 pref->setItemProperty( undoPref, "min", 1 );
1423 pref->setItemProperty( undoPref, "max", 100 );
1425 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1426 pref->setItemProperty( extgroup, "columns", 1 );
1427 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1428 pref->setItemProperty( apppref, "existing", true );
1429 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1431 pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1433 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1434 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1435 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1439 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1440 int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1441 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1443 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1444 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1446 pref->setItemProperty( defCols, "columns", 1 );
1448 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1449 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1451 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1453 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1455 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1456 pref->setItemProperty( occGroup, "columns", 1 );
1457 pref->setItemProperty( vtkGroup, "columns", 1 );
1459 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1460 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1461 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1462 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1464 pref->setItemProperty( occTS, "min", 1 );
1465 pref->setItemProperty( occTS, "max", 150 );
1467 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1468 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1469 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1470 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1472 pref->setItemProperty( isoU, "min", 0 );
1473 pref->setItemProperty( isoU, "max", 100000 );
1475 pref->setItemProperty( isoV, "min", 0 );
1476 pref->setItemProperty( isoV, "max", 100000 );
1478 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1479 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1480 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1481 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1483 pref->setItemProperty( vtkTS, "min", 1 );
1484 pref->setItemProperty( vtkTS, "max", 150 );
1486 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1487 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1488 pref->setItemProperty( dirGroup, "columns", 1 );
1489 pref->addPreference( tr( "" ), dirGroup,
1490 SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1493 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1495 SUIT_ResourceMgr* resMgr = resourceMgr();
1499 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1501 int sz = resMgr->integerValue( sec, param, -1 );
1502 QPtrList<SUIT_ViewManager> lst;
1503 viewManagers( OCCViewer_Viewer::Type(), lst );
1504 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1506 SUIT_ViewModel* vm = it.current()->getViewModel();
1507 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1510 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1511 occVM->setTrihedronSize( sz );
1512 occVM->getAISContext()->UpdateCurrentViewer();
1516 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1518 int sz = resMgr->integerValue( sec, param, -1 );
1519 QPtrList<SUIT_ViewManager> lst;
1520 viewManagers( SVTK_Viewer::Type(), lst );
1521 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1523 SUIT_ViewModel* vm = it.current()->getViewModel();
1524 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1527 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1528 vtkVM->setTrihedronSize( sz );
1533 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1535 QPtrList<SUIT_ViewManager> lst;
1536 viewManagers( OCCViewer_Viewer::Type(), lst );
1537 int u = resMgr->integerValue( sec, "iso_number_u" );
1538 int v = resMgr->integerValue( sec, "iso_number_v" );
1539 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1540 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1543 if( sec=="ObjectBrowser" )
1545 if( param=="auto_size" )
1547 OB_Browser* ob = objectBrowser();
1551 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1552 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1554 updateObjectBrowser( false );
1558 if( sec=="PyConsole" )
1561 if( pythonConsole() )
1562 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1566 /*!Update desktop title.*/
1567 void SalomeApp_Application::updateDesktopTitle() {
1568 QString aTitle = applicationName();
1569 QString aVer = applicationVersion();
1570 if ( !aVer.isEmpty() )
1571 aTitle += QString( " " ) + aVer;
1573 if ( activeStudy() )
1575 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1576 if ( !sName.isEmpty() ) {
1577 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1578 _PTR(Study) stdDS = study->studyDS();
1580 if ( stdDS->GetProperties()->IsLocked() ) {
1581 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1583 aTitle += QString( " - [%1]" ).arg( sName );
1589 desktop()->setCaption( aTitle );
1592 /*!Update windows after close document.*/
1593 void SalomeApp_Application::afterCloseDoc()
1597 CAM_Application::afterCloseDoc();
1600 /*!Gets CORBA::ORB_var*/
1601 CORBA::ORB_var SalomeApp_Application::orb()
1603 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1604 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1608 /*!Create and return SALOMEDS_StudyManager.*/
1609 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1611 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1615 /*!Create and return SALOME_NamingService.*/
1616 SALOME_NamingService* SalomeApp_Application::namingService()
1618 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1622 /*!Create and return SALOME_LifeCycleCORBA.*/
1623 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1625 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1629 QString SalomeApp_Application::defaultEngineIOR()
1631 /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1632 QString anIOR( "" );
1633 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1634 if ( !CORBA::is_nil( anEngine ) )
1635 anIOR = orb()->object_to_string( anEngine );
1639 /*!Adds icon names for modules.*/
1640 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1644 SUIT_ResourceMgr* resMgr = resourceMgr();
1648 QStringList modList;
1649 modules( modList, false );
1651 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1653 QString modName = *it;
1654 QString modIntr = moduleName( modName );
1655 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1657 if ( modIcon.isEmpty() )
1660 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1661 modIcon += QString( ".png" );
1663 iconMap.insert( modName, modIcon );
1667 /*!Update module action.*/
1668 void SalomeApp_Application::updateModuleActions()
1671 if ( activeModule() )
1672 modName = activeModule()->moduleName();
1674 if ( myActions.contains( modName ) )
1675 myActions[modName]->setOn( true );
1678 /*!Gets current windows.
1679 *\param winMap - output current windows map.
1681 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1684 if ( !activeStudy() )
1687 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1688 ((SalomeApp_Module*)activeModule())->windows( winMap );
1690 defaultWindows( winMap );
1693 /*!Gets current view managers.
1694 *\param lst - output current view managers list.
1696 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1699 if ( !activeStudy() )
1702 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1703 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1705 defaultViewManagers( lst );
1708 /*!Update windows.*/
1709 void SalomeApp_Application::updateWindows()
1711 QMap<int, int> winMap;
1712 currentWindows( winMap );
1714 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1715 getWindow( it.key() );
1717 loadWindowsGeometry();
1719 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1720 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1723 /*!Update view managers.*/
1724 void SalomeApp_Application::updateViewManagers()
1727 currentViewManagers( lst );
1729 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1730 getViewManager( *it, true );
1733 /*!Load windows geometry.*/
1734 void SalomeApp_Application::loadWindowsGeometry()
1736 QtxDockAction* dockMgr = 0;
1738 QAction* a = action( ViewWindowsId );
1739 if ( a && a->inherits( "QtxDockAction" ) )
1740 dockMgr = (QtxDockAction*)a;
1746 if ( activeModule() )
1747 modName = moduleLibrary( activeModule()->moduleName(), false );
1749 QString section = QString( "windows_geometry" );
1750 if ( !modName.isEmpty() )
1751 section += QString( "." ) + modName;
1753 dockMgr->loadGeometry( resourceMgr(), section, false );
1754 dockMgr->restoreGeometry();
1757 /*!Save windows geometry.*/
1758 void SalomeApp_Application::saveWindowsGeometry()
1760 QtxDockAction* dockMgr = 0;
1762 QAction* a = action( ViewWindowsId );
1763 if ( a && a->inherits( "QtxDockAction" ) )
1764 dockMgr = (QtxDockAction*)a;
1770 if ( activeModule() )
1771 modName = moduleLibrary( activeModule()->moduleName(), false );
1773 QString section = QString( "windows_geometry" );
1774 if ( !modName.isEmpty() )
1775 section += QString( "." ) + modName;
1777 dockMgr->storeGeometry();
1778 dockMgr->saveGeometry( resourceMgr(), section, false );
1781 /*!Activate windows.*/
1782 void SalomeApp_Application::activateWindows()
1784 if ( activeStudy() )
1786 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1787 itr.data()->activate( activeStudy()->id() );
1791 /*!Private SLOT. On preferences.*/
1792 void SalomeApp_Application::onProperties()
1794 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1798 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1801 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1802 int res = aDlg.exec();
1803 if( res==QDialog::Accepted && aDlg.isChanged() )
1804 SB->CommitCommand();
1808 //study->updateCaptions();
1809 updateDesktopTitle();
1813 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1814 const QString& caption, QWidget* parent )
1818 QStringList fls = QStringList::split( ";;", filters, false );
1819 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1823 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1827 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1831 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1832 const QString& caption, QWidget* parent )
1836 QStringList fls = QStringList::split( ";;", filters, false );
1837 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1841 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1843 CAM_Application::contextMenuPopup( type, thePopup, title );
1845 OB_Browser* ob = objectBrowser();
1846 if ( !ob || type != ob->popupClientType() )
1849 thePopup->insertSeparator();
1850 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1852 // "Activate module" item should appear only if it's necessary
1853 SALOME_ListIO aList;
1854 SalomeApp_SelectionMgr* mgr = selectionMgr();
1855 mgr->selectedObjects(aList);
1856 if (aList.Extent() != 1)
1858 Handle(SALOME_InteractiveObject) aIObj = aList.First();
1859 QString aModuleName(aIObj->getComponentDataType());
1860 QString aModuleTitle = moduleTitle(aModuleName);
1861 CAM_Module* currentModule = activeModule();
1862 if (currentModule && currentModule->moduleName() == aModuleTitle)
1864 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1867 /*!Update obect browser*/
1868 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1870 // update existing data models (already loaded SComponents)
1873 for ( ModuleListIterator it = modules(); it.current(); ++it )
1875 CAM_DataModel* camDM = it.current()->dataModel();
1876 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1877 ((SalomeApp_DataModel*)camDM)->update();
1880 // update "non-existing" (not loaded yet) data models
1881 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1884 _PTR(Study) stdDS = study->studyDS();
1887 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
1889 _PTR(SComponent) aComponent ( it->Value() );
1891 if ( aComponent->ComponentDataType() == "Interface Applicative" )
1892 continue; // skip the magic "Interface Applicative" component
1894 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
1899 if ( objectBrowser() )
1901 objectBrowser()->updateGeometry();
1902 objectBrowser()->updateTree();
1906 /*!Protected SLOT.On desktop activated.*/
1907 void SalomeApp_Application::onDesktopActivated()
1909 CAM_Application::onDesktopActivated();
1910 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
1912 aModule->studyActivated();
1915 /*!Create empty study.*/
1916 void SalomeApp_Application::createEmptyStudy()
1918 CAM_Application::createEmptyStudy();
1919 if ( objectBrowser() )
1920 objectBrowser()->updateTree();
1923 /*!Activate module \a mod.*/
1924 bool SalomeApp_Application::activateModule( CAM_Module* mod )
1926 bool res = CAM_Application::activateModule( mod );
1927 if ( objectBrowser() )
1928 objectBrowser()->updateTree();
1932 /*!Display Catalog Genenerator dialog */
1933 void SalomeApp_Application::onCatalogGen()
1935 ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
1939 /*!Display Registry Display dialog */
1940 void SalomeApp_Application::onRegDisplay()
1942 CORBA::ORB_var anOrb = orb();
1943 ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
1946 regWnd->setActiveWindow();