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 #define OBJECT_BROWSER_WIDTH 300
90 /*!Image for empty icon.*/
91 static const char* imageEmptyIcon[] = {
94 "....................",
95 "....................",
96 "....................",
97 "....................",
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "....................",
111 "....................",
112 "....................",
113 "...................."};
115 /*!Create new instance of SalomeApp_Application.*/
116 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
118 return new SalomeApp_Application();
121 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
124 Class : SalomeApp_Application
125 Description : Application containing SalomeApp module
129 SalomeApp_Application::SalomeApp_Application()
130 : CAM_Application( false ),
133 STD_TabDesktop* desk = new STD_TabDesktop();
137 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
138 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
140 desktop()->setIcon( aLogo );
141 desktop()->setDockableMenuBar( true );
142 desktop()->setDockableStatusBar( false );
146 mySelMgr = new SalomeApp_SelectionMgr( this );
148 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
149 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
151 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
155 *\li Save window geometry.
156 *\li Save desktop geometry.
157 *\li Save resource maneger.
158 *\li Delete selection manager.
159 *\li Destroy event filter.
161 SalomeApp_Application::~SalomeApp_Application()
163 saveWindowsGeometry();
168 desktop()->saveGeometry( resourceMgr(), "desktop" );
169 resourceMgr()->save();
174 SalomeApp_EventFilter::Destroy();
177 /*!Start application.*/
178 void SalomeApp_Application::start()
181 desktop()->loadGeometry( resourceMgr(), "desktop" );
183 CAM_Application::start();
185 QAction* a = action( ViewWindowsId );
186 if ( a && a->inherits( "QtxDockAction" ) )
187 ((QtxDockAction*)a)->setAutoPlace( true );
189 SalomeApp_EventFilter::Init();
192 updateViewManagers();
197 /*!Gets application name.*/
198 QString SalomeApp_Application::applicationName() const
200 return tr( "APP_NAME" );
203 /*!Gets application version.*/
204 QString SalomeApp_Application::applicationVersion() const
206 static QString _app_version;
208 if ( _app_version.isEmpty() )
210 QString path( ::getenv( "GUI_ROOT_DIR" ) );
211 if ( !path.isEmpty() )
212 path += QDir::separator();
213 path += QString( "bin/salome/VERSION" );
216 if ( vf.open( IO_ReadOnly ) )
219 vf.readLine( line, 1024 );
222 if ( !line.isEmpty() )
224 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
225 line.remove( line.length() - 1, 1 );
227 int idx = line.findRev( ":" );
229 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
237 /*!Load module by \a name.*/
238 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
240 CAM_Module* mod = CAM_Application::loadModule( name );
243 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
244 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
245 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
250 /*!Activate module by \a modName*/
251 bool SalomeApp_Application::activateModule( const QString& modName )
254 CAM_Module* prevMod = activeModule();
257 actName = prevMod->moduleName();
259 if ( actName == modName )
262 saveWindowsGeometry();
264 bool status = CAM_Application::activateModule( modName );
266 updateModuleActions();
272 updateViewManagers();
277 /*!Gets selection manager.*/
278 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
284 void SalomeApp_Application::createActions()
286 STD_Application::createActions();
288 SUIT_Desktop* desk = desktop();
289 SUIT_ResourceMgr* resMgr = resourceMgr();
292 createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
293 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
294 0, desk, false, this, SLOT( onDumpStudy() ) );
297 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
298 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
299 0, desk, false, this, SLOT( onLoadScript() ) );
302 createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
303 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
304 0, desk, false, this, SLOT( onProperties() ) );
307 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
308 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
309 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
312 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
313 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
314 registerAction( MRUId, mru );
316 //! default icon for neutral point ('SALOME' module)
317 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
318 if ( defIcon.isNull() )
319 defIcon = QPixmap( imageEmptyIcon );
321 //! default icon for any module
322 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
323 if ( modIcon.isNull() )
324 modIcon = QPixmap( imageEmptyIcon );
326 QToolBar* modTBar = new QtxToolBar( true, desk );
327 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
329 QActionGroup* modGroup = new QActionGroup( this );
330 modGroup->setExclusive( true );
331 modGroup->setUsesDropDown( true );
333 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
334 tr( "PRP_APP_MODULE" ), 0, desk, true );
336 myActions.insert( QString(), a );
338 QMap<QString, QString> iconMap;
339 moduleIconNames( iconMap );
341 const int iconSize = 20;
343 modGroup->addTo( modTBar );
344 modTBar->addSeparator();
347 modules( modList, false );
349 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
351 if ( (*it).isEmpty() )
355 if ( iconMap.contains( *it ) )
356 iconName = iconMap[*it];
358 QString modName = moduleName( *it );
360 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
364 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
366 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
370 myActions.insert( *it, a );
373 SUIT_Tools::simplifySeparators( modTBar );
377 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
378 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
379 createMenu( separator(), windowMenu, -1, 1 );
381 QMap<int, int> accelMap;
382 accelMap[NewGLViewId] = ALT+Key_G;
383 accelMap[NewPlot2dId] = ALT+Key_P;
384 accelMap[NewOCCViewId] = ALT+Key_O;
385 accelMap[NewVTKViewId] = ALT+Key_K;
387 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
389 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
390 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
391 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
392 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
393 createMenu( a, newWinMenu, -1 );
395 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
397 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
399 createMenu( DumpStudyId, fileMenu, 10, -1 );
400 createMenu( separator(), fileMenu, -1, 15, -1 );
401 createMenu( LoadScriptId, fileMenu, 10, -1 );
402 createMenu( separator(), fileMenu, -1, 15, -1 );
403 createMenu( PropertiesId, fileMenu, 10, -1 );
404 createMenu( separator(), fileMenu, -1, 15, -1 );
405 createMenu( PreferencesId, fileMenu, 15, -1 );
406 createMenu( separator(), fileMenu, -1, 15, -1 );
409 createMenu( separator(), fileMenu, -1, 100, -1 );
410 createMenu( MRUId, fileMenu, 100, -1 );
411 createMenu( separator(), fileMenu, -1, 100, -1 );
415 /*!On module activation action.*/
416 void SalomeApp_Application::onModuleActivation( QAction* a )
421 QString modName = a->menuText();
422 if ( modName == tr( "APP_NAME" ) )
423 modName = QString::null;
425 // Force user to create/open a study before module activation
426 QMap<QString, QString> iconMap;
427 moduleIconNames( iconMap );
428 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
430 icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
432 bool cancelled = false;
433 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
434 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
435 int res = aDlg.exec();
449 putInfo( tr("INF_CANCELLED") );
450 myActions[QString()]->setOn( true );
456 activateModule( modName );
459 /*!Default module activation.*/
460 QString SalomeApp_Application::defaultModule() const
462 QStringList aModuleNames;
463 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
464 //! If there's the one and only module --> activate it automatically
465 //! TODO: Possible improvement - default module can be taken from preferences
466 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
469 /*!On new window slot.*/
470 void SalomeApp_Application::onNewWindow()
472 const QObject* obj = sender();
473 if ( !obj || !obj->inherits( "QAction" ) )
477 int id = actionId( (QAction*)obj );
481 type = GLViewer_Viewer::Type();
484 type = Plot2d_Viewer::Type();
487 type = OCCViewer_Viewer::Type();
490 type = VTKViewer_Viewer::Type();
494 if ( !type.isEmpty() )
495 createViewManager( type );
498 //=======================================================================
500 /*! Purpose : SLOT. Create new document*/
501 //=======================================================================
502 void SalomeApp_Application::onNewDoc()
504 SUIT_Study* study = activeStudy();
506 saveWindowsGeometry();
508 CAM_Application::onNewDoc();
510 if ( !study ) // new study will be create in THIS application
513 updateViewManagers();
517 //=======================================================================
519 /*! Purpose : SLOT. Open new document*/
520 //=======================================================================
521 void SalomeApp_Application::onOpenDoc()
523 SUIT_Study* study = activeStudy();
524 saveWindowsGeometry();
526 CAM_Application::onOpenDoc();
528 if ( !study ) // new study will be create in THIS application
531 updateViewManagers();
535 /*! Purpose : SLOT. Open new document with \a aName.*/
536 bool SalomeApp_Application::onOpenDoc( const QString& aName )
538 bool res = CAM_Application::onOpenDoc( aName );
540 QAction* a = action( MRUId );
541 if ( a && a->inherits( "QtxMRUAction" ) )
543 QtxMRUAction* mru = (QtxMRUAction*)a;
545 mru->insert( aName );
547 mru->remove( aName );
552 /*!SLOT. Load document.*/
553 void SalomeApp_Application::onLoadDoc()
555 QString name, studyname, ext;
557 STD_LoadStudiesDlg aDlg( desktop(), TRUE);
559 std::vector<std::string> List = studyMgr()->GetOpenStudies();
561 SUIT_Session* aSession = SUIT_Session::session();
562 QPtrList<SUIT_Application> aAppList = aSession->applications();
563 SUIT_Application* aApp = 0;
565 for (unsigned int ind = 0; ind < List.size(); ind++) {
566 studyname = List[ind].c_str();
567 //Add to list only unloaded studies
568 bool isAlreadyOpen = false;
569 for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
572 if(!aApp || !aApp->activeStudy()) continue;
573 if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
576 if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
579 int retVal = aDlg.exec();
580 studyname = aDlg.ListComponent->currentText();
582 if (retVal == QDialog::Rejected)
585 if ( studyname.isNull() || studyname.isEmpty() )
589 name.replace( QRegExp(":"), "/" );
591 if(onLoadDoc(name)) {
593 updateViewManagers();
594 updateObjectBrowser(true);
599 /*!SLOT. Load document with \a aName.*/
600 bool SalomeApp_Application::onLoadDoc( const QString& aName )
602 bool res = CAM_Application::onLoadDoc( aName );
604 /*jfa tmp:QAction* a = action( MRUId );
605 if ( a && a->inherits( "QtxMRUAction" ) )
607 QtxMRUAction* mru = (QtxMRUAction*)a;
609 mru->insert( aName );
611 mru->remove( aName );
616 /*!Private SLOT. Selection.*/
617 void SalomeApp_Application::onSelection()
619 onSelectionChanged();
621 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
622 ((SalomeApp_Module*)activeModule())->selectionChanged();
625 /*!SLOT. Copy objects to study maneger from selection maneger..*/
626 void SalomeApp_Application::onCopy()
629 SalomeApp_SelectionMgr* mgr = selectionMgr();
630 mgr->selectedObjects(list);
632 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
633 if(study == NULL) return;
635 _PTR(Study) stdDS = study->studyDS();
638 SALOME_ListIteratorOfListIO it( list );
641 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
643 studyMgr()->Copy(so);
644 onSelectionChanged();
651 /*!SLOT. Paste objects to study maneger from selection manager.*/
652 void SalomeApp_Application::onPaste()
655 SalomeApp_SelectionMgr* mgr = selectionMgr();
656 mgr->selectedObjects(list);
658 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
659 if(study == NULL) return;
661 _PTR(Study) stdDS = study->studyDS();
664 SALOME_ListIteratorOfListIO it( list );
667 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
669 studyMgr()->Paste(so);
670 updateObjectBrowser( true );
671 updateActions(); //SRN: BugID IPAL9377, case 3
678 /*!Sets enable or disable some actions on selection changed.*/
679 void SalomeApp_Application::onSelectionChanged()
682 SalomeApp_SelectionMgr* mgr = selectionMgr();
683 mgr->selectedObjects(list);
685 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
686 if(study == NULL) return;
688 _PTR(Study) stdDS = study->studyDS();
693 SALOME_ListIteratorOfListIO it( list );
694 if(it.More() && list.Extent() == 1)
696 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
698 qaction = action(EditCopyId);
699 if(studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
700 else qaction->setEnabled(false);
702 qaction = action(EditPasteId);
703 if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
704 else qaction->setEnabled(false);
707 qaction = action(EditCopyId);
708 qaction->setEnabled(false);
709 qaction = action(EditPasteId);
710 qaction->setEnabled(false);
714 /*!Update object browser.*/
715 void SalomeApp_Application::onRefresh()
717 updateObjectBrowser( true );
721 void SalomeApp_Application::onOpenWith()
723 QApplication::setOverrideCursor( Qt::waitCursor );
725 SalomeApp_SelectionMgr* mgr = selectionMgr();
726 mgr->selectedObjects(aList);
727 if (aList.Extent() != 1)
729 QApplication::restoreOverrideCursor();
732 Handle(SALOME_InteractiveObject) aIObj = aList.First();
733 QString aModuleName(aIObj->getComponentDataType());
734 QString aModuleTitle = moduleTitle(aModuleName);
735 activateModule(aModuleTitle);
736 QApplication::restoreOverrideCursor();
739 bool SalomeApp_Application::useStudy(const QString& theName)
742 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
745 res = aStudy->loadDocument( theName );
746 updateDesktopTitle();
747 updateCommandsStatus();
752 *\param study - SUIT_Study.
754 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
756 CAM_Application::setActiveStudy( study );
761 //=======================================================================
762 // name : createNewStudy
763 /*! Purpose : Create new study*/
764 //=======================================================================
765 SUIT_Study* SalomeApp_Application::createNewStudy()
767 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
769 // Set up processing of major study-related events
770 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
771 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
772 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
773 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
778 //=======================================================================
779 // name : createNewStudy
780 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
781 //=======================================================================
782 void SalomeApp_Application::updateCommandsStatus()
784 CAM_Application::updateCommandsStatus();
786 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
788 QAction* a = action( id );
790 a->setEnabled( activeStudy() );
794 QAction* a = action( DumpStudyId );
796 a->setEnabled( activeStudy() );
799 a = action( LoadScriptId );
801 a->setEnabled( activeStudy() );
803 a = action( PropertiesId );
805 a->setEnabled( activeStudy() );
807 a = action(EditCopyId);
808 a->setEnabled(false);
809 a = action(EditPasteId);
810 a->setEnabled(false);
813 //=======================================================================
814 // name : onHelpAbout
815 /*! Purpose : SLOT. Display "About" message box*/
816 //=======================================================================
817 void SalomeApp_Application::onHelpAbout()
819 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
824 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
831 if ( !activeStudy() )
834 sId = activeStudy()->id();
837 if ( myWindows.contains( flag ) )
838 wid = myWindows[flag]->widget( sId );
843 /*!Adds window to application.
844 *\param wid - QWidget
845 *\param flag - key wor window
846 *\param studyId - study id
847 * Flag used how identificator of window in windows list.
849 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
857 if ( !activeStudy() )
860 sId = activeStudy()->id();
863 if ( !myWindows.contains( flag ) )
865 QMap<int, int> winMap;
866 currentWindows( winMap );
868 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
869 if ( winMap.contains( flag ) )
870 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
872 myWindows[flag]->setResizeEnabled( true );
873 myWindows[flag]->setCloseMode( QDockWindow::Always );
874 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
878 if( wid->inherits( "PythonConsole" ) )
879 f = ( ( PythonConsole* )wid )->font();
883 myWindows[flag]->insert( sId, wid );
886 setWindowShown( flag, !myWindows[flag]->isEmpty() );
889 /*!Remove window from application.
890 *\param flag - key wor window
891 *\param studyId - study id
892 * Flag used how identificator of window in windows list.
894 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
896 if ( !myWindows.contains( flag ) )
902 if ( !activeStudy() )
905 sId = activeStudy()->id();
908 QWidget* wid = myWindows[flag]->widget( sId );
909 myWindows[flag]->remove( sId );
912 setWindowShown( flag, !myWindows[flag]->isEmpty() );
916 *\param flag - key wor window
917 *\param studyId - study id
918 * Flag used how identificator of window in windows list.
920 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
922 QWidget* wid = window( flag, studyId );
924 addWindow( wid = createWindow( flag ), flag, studyId );
929 /*!Check is window visible?(with identificator \a type)*/
930 bool SalomeApp_Application::isWindowVisible( const int type ) const
933 if ( myWindows.contains( type ) )
935 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
936 res = desk && desk->appropriate( myWindows[type] );
941 /*!Sets window show or hide.
942 *\param type - window identificator.
943 *\param on - true/false (window show/hide)
945 void SalomeApp_Application::setWindowShown( const int type, const bool on )
947 if ( !desktop() || !myWindows.contains( type ) )
950 QDockWindow* dw = myWindows[type];
951 desktop()->setAppropriate( dw, on );
952 on ? dw->show() : dw->hide();
955 OB_Browser* SalomeApp_Application::objectBrowser()
958 QWidget* wid = getWindow( WT_ObjectBrowser );
959 if ( wid->inherits( "OB_Browser" ) )
960 ob = (OB_Browser*)wid;
964 /*!Gets "LogWindow".*/
965 LogWindow* SalomeApp_Application::logWindow()
968 QWidget* wid = getWindow( WT_LogWindow );
969 if ( wid->inherits( "LogWindow" ) )
970 lw = (LogWindow*)wid;
974 /*!Get "PythonConsole"*/
975 PythonConsole* SalomeApp_Application::pythonConsole()
977 PythonConsole* console = 0;
978 QWidget* wid = getWindow( WT_PyConsole );
979 if ( wid->inherits( "PythonConsole" ) )
980 console = (PythonConsole*)wid;
984 /*!Gets preferences.*/
985 SalomeApp_Preferences* SalomeApp_Application::preferences() const
987 return preferences( false );
990 /*!Gets view manager*/
991 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
993 SUIT_ViewManager* aVM = viewManager( vmType );
994 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
996 if ( anActiveVM && anActiveVM->getType() == vmType )
1001 if ( !aVM->getActiveView() )
1004 aVM->getActiveView()->setFocus();
1007 aVM = createViewManager( vmType );
1012 /*!Create view manager.*/
1013 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
1015 SUIT_ResourceMgr* resMgr = resourceMgr();
1017 SUIT_ViewManager* viewMgr = 0;
1018 if ( vmType == GLViewer_Viewer::Type() )
1020 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1021 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1023 else if ( vmType == Plot2d_Viewer::Type() )
1025 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1026 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
1028 else if ( vmType == OCCViewer_Viewer::Type() )
1030 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1031 SOCC_Viewer* vm = new SOCC_Viewer();
1032 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1033 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1036 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1037 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1038 vm->setIsos( u, v );
1039 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1040 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1042 else if ( vmType == SVTK_Viewer::Type() )
1044 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1045 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
1046 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1047 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1048 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
1054 addViewManager( viewMgr );
1055 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1057 if ( viewWin && desktop() )
1058 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1060 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1061 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1066 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1068 removeViewManager( theVM );
1071 /*!Private SLOT. On study created.*/
1072 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1074 SUIT_DataObject* aRoot = 0;
1075 if ( theStudy && theStudy->root() )
1077 aRoot = theStudy->root();
1078 //aRoot->setName( tr( "DATA_MODELS" ) );
1080 if ( objectBrowser() != 0 )
1081 objectBrowser()->setRootObject( aRoot );
1083 activateModule( defaultModule() );
1088 /*!Private SLOT. On study opened.*/
1089 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1091 SUIT_DataObject* aRoot = 0;
1092 if ( theStudy && theStudy->root() )
1094 aRoot = theStudy->root();
1097 if ( objectBrowser() != 0 ) {
1098 objectBrowser()->setRootObject( aRoot );
1101 activateModule( defaultModule() );
1108 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1113 /*!Private SLOT. On study closed.*/
1114 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1118 activateModule( "" );
1120 saveWindowsGeometry();
1123 /*!Private SLOT. On dump study.*/
1124 void SalomeApp_Application::onDumpStudy( )
1126 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1127 if ( !appStudy ) return;
1128 _PTR(Study) aStudy = appStudy->studyDS();
1130 QStringList aFilters;
1131 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1133 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1134 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1135 fd->setFilters( aFilters );
1136 fd->SetChecked(true);
1138 QString aFileName = fd->selectedFile();
1139 bool toPublish = fd->IsChecked();
1142 if(!aFileName.isEmpty()) {
1143 QFileInfo aFileInfo(aFileName);
1144 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1148 /*!Private SLOT. On load script.*/
1149 void SalomeApp_Application::onLoadScript( )
1151 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1152 if ( !appStudy ) return;
1153 _PTR(Study) aStudy = appStudy->studyDS();
1155 if ( aStudy->GetProperties()->IsLocked() ) {
1156 SUIT_MessageBox::warn1 ( desktop(),
1157 QObject::tr("WRN_WARNING"),
1158 QObject::tr("WRN_STUDY_LOCKED"),
1159 QObject::tr("BUT_OK") );
1163 QStringList filtersList;
1164 filtersList.append(tr("PYTHON_FILES_FILTER"));
1165 filtersList.append(tr("ALL_FILES_FILTER"));
1167 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1169 if ( !aFile.isEmpty() )
1171 QString command = QString("execfile(\"%1\")").arg(aFile);
1173 PythonConsole* pyConsole = pythonConsole();
1176 pyConsole->exec( command );
1180 /*!Private SLOT. On preferences.*/
1181 void SalomeApp_Application::onPreferences()
1183 QApplication::setOverrideCursor( Qt::waitCursor );
1185 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1187 QApplication::restoreOverrideCursor();
1197 /*!Private SLOT. On open document with name \a aName.*/
1198 void SalomeApp_Application::onMRUActivated( QString aName )
1203 /*!Private SLOT. On preferences changed.*/
1204 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1206 SalomeApp_Module* sMod = 0;
1207 CAM_Module* mod = module( modName );
1208 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1209 sMod = (SalomeApp_Module*)mod;
1212 sMod->preferencesChanged( section, param );
1214 preferencesChanged( section, param );
1217 /*!Gets file filter.
1218 *\retval QString "(*.hdf)"
1220 QString SalomeApp_Application::getFileFilter() const
1225 /*!Remove all windows from study.*/
1226 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1228 CAM_Application::beforeCloseDoc( s );
1230 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1231 removeWindow( itr.key(), s->id() );
1234 /*!Update actions.*/
1235 void SalomeApp_Application::updateActions()
1237 updateCommandsStatus();
1241 QWidget* SalomeApp_Application::createWindow( const int flag )
1245 SUIT_ResourceMgr* resMgr = resourceMgr();
1247 if ( flag == WT_ObjectBrowser )
1249 OB_Browser* ob = new OB_Browser( desktop() );
1250 ob->setAutoUpdate( true );
1251 ob->setAutoOpenLevel( 1 );
1252 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1253 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1254 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1256 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1258 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1259 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1261 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1262 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1263 QString().sprintf( "visibility_column_%d", i ), true ) );
1265 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1267 // Create OBSelector
1268 new SalomeApp_OBSelector( ob, mySelMgr );
1272 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1274 else if ( flag == WT_PyConsole )
1276 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1277 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1278 pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1281 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1283 else if ( flag == WT_LogWindow )
1285 LogWindow* logWin = new LogWindow( desktop() );
1286 logWin->setCaption( tr( "LOG_WINDOW" ) );
1289 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1295 /*!Default windows(Object Browser, Python Console).
1296 * Adds to map \a aMap.
1298 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1300 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1301 aMap.insert( WT_PyConsole, Qt::DockBottom );
1302 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1305 /*!Default view manager.*/
1306 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1311 /*!Gets preferences.
1312 * Create preferences, if \a crt = true.
1314 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1319 SalomeApp_Application* that = (SalomeApp_Application*)this;
1321 if ( !_prefs_ && crt )
1323 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1324 that->createPreferences( _prefs_ );
1327 that->myPrefs = _prefs_;
1329 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1330 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1332 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1335 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1337 QStringList modNameList;
1338 app->modules( modNameList, false );
1339 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1341 int id = _prefs_->addPreference( *it );
1342 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1346 app->modules( modList );
1347 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1349 SalomeApp_Module* mod = 0;
1350 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1351 mod = (SalomeApp_Module*)itr.current();
1353 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1355 int modCat = _prefs_->addPreference( mod->moduleName() );
1356 _prefs_->setItemProperty( modCat, "info", QString::null );
1357 mod->createPreferences();
1362 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1363 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1368 /*!Add new module to application.*/
1369 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1371 CAM_Application::moduleAdded( mod );
1373 SalomeApp_Module* salomeMod = 0;
1374 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1375 salomeMod = (SalomeApp_Module*)mod;
1377 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1379 int modCat = myPrefs->addPreference( mod->moduleName() );
1380 myPrefs->setItemProperty( modCat, "info", QString::null );
1381 salomeMod->createPreferences();
1385 /*!Create preferences.*/
1386 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1391 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1393 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1394 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1395 pref->setItemProperty( studyGroup, "columns", 1 );
1397 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1398 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1399 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1400 pref->setItemProperty( undoPref, "min", 1 );
1401 pref->setItemProperty( undoPref, "max", 100 );
1403 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1404 pref->setItemProperty( extgroup, "columns", 1 );
1405 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1406 pref->setItemProperty( apppref, "existing", true );
1407 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1409 pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1411 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1412 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1413 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1417 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1418 int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1419 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1421 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1422 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1424 pref->setItemProperty( defCols, "columns", 1 );
1426 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1427 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1429 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1431 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1433 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1434 pref->setItemProperty( occGroup, "columns", 1 );
1435 pref->setItemProperty( vtkGroup, "columns", 1 );
1437 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1438 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1439 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1440 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1442 pref->setItemProperty( occTS, "min", 1 );
1443 pref->setItemProperty( occTS, "max", 150 );
1445 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1446 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1447 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1448 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1450 pref->setItemProperty( isoU, "min", 0 );
1451 pref->setItemProperty( isoU, "max", 100000 );
1453 pref->setItemProperty( isoV, "min", 0 );
1454 pref->setItemProperty( isoV, "max", 100000 );
1456 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1457 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1458 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1459 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1461 pref->setItemProperty( vtkTS, "min", 1 );
1462 pref->setItemProperty( vtkTS, "max", 150 );
1464 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1465 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1466 pref->setItemProperty( dirGroup, "columns", 1 );
1467 pref->addPreference( tr( "" ), dirGroup,
1468 SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1471 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1473 SUIT_ResourceMgr* resMgr = resourceMgr();
1477 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1479 int sz = resMgr->integerValue( sec, param, -1 );
1480 QPtrList<SUIT_ViewManager> lst;
1481 viewManagers( OCCViewer_Viewer::Type(), lst );
1482 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1484 SUIT_ViewModel* vm = it.current()->getViewModel();
1485 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1488 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1489 occVM->setTrihedronSize( sz );
1490 occVM->getAISContext()->UpdateCurrentViewer();
1494 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1496 int sz = resMgr->integerValue( sec, param, -1 );
1497 QPtrList<SUIT_ViewManager> lst;
1498 viewManagers( SVTK_Viewer::Type(), lst );
1499 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1501 SUIT_ViewModel* vm = it.current()->getViewModel();
1502 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1505 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1506 vtkVM->setTrihedronSize( sz );
1511 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1513 QPtrList<SUIT_ViewManager> lst;
1514 viewManagers( OCCViewer_Viewer::Type(), lst );
1515 int u = resMgr->integerValue( sec, "iso_number_u" );
1516 int v = resMgr->integerValue( sec, "iso_number_v" );
1517 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1518 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1521 if( sec=="ObjectBrowser" )
1523 if( param=="auto_size" )
1525 OB_Browser* ob = objectBrowser();
1529 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1530 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1532 updateObjectBrowser( false );
1536 if( sec=="PyConsole" )
1539 if( pythonConsole() )
1540 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1544 /*!Update desktop title.*/
1545 void SalomeApp_Application::updateDesktopTitle() {
1546 QString aTitle = applicationName();
1547 QString aVer = applicationVersion();
1548 if ( !aVer.isEmpty() )
1549 aTitle += QString( " " ) + aVer;
1551 if ( activeStudy() )
1553 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1554 if ( !sName.isEmpty() ) {
1555 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1556 _PTR(Study) stdDS = study->studyDS();
1558 if ( stdDS->GetProperties()->IsLocked() ) {
1559 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1561 aTitle += QString( " - [%1]" ).arg( sName );
1567 desktop()->setCaption( aTitle );
1570 /*!Update windows after close document.*/
1571 void SalomeApp_Application::afterCloseDoc()
1575 CAM_Application::afterCloseDoc();
1578 /*!Gets CORBA::ORB_var*/
1579 CORBA::ORB_var SalomeApp_Application::orb()
1581 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1582 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1586 /*!Create and return SALOMEDS_StudyManager.*/
1587 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1589 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1593 /*!Create and return SALOME_NamingService.*/
1594 SALOME_NamingService* SalomeApp_Application::namingService()
1596 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1600 /*!Create and return SALOME_LifeCycleCORBA.*/
1601 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1603 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1607 QString SalomeApp_Application::defaultEngineIOR()
1609 /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1610 QString anIOR( "" );
1611 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1612 if ( !CORBA::is_nil( anEngine ) )
1613 anIOR = orb()->object_to_string( anEngine );
1617 /*!Adds icon names for modules.*/
1618 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1622 SUIT_ResourceMgr* resMgr = resourceMgr();
1626 QStringList modList;
1627 modules( modList, false );
1629 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1631 QString modName = *it;
1632 QString modIntr = moduleName( modName );
1633 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1635 if ( modIcon.isEmpty() )
1638 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1639 modIcon += QString( ".png" );
1641 iconMap.insert( modName, modIcon );
1645 /*!Update module action.*/
1646 void SalomeApp_Application::updateModuleActions()
1649 if ( activeModule() )
1650 modName = activeModule()->moduleName();
1652 if ( myActions.contains( modName ) )
1653 myActions[modName]->setOn( true );
1656 /*!Gets current windows.
1657 *\param winMap - output current windows map.
1659 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1662 if ( !activeStudy() )
1665 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1666 ((SalomeApp_Module*)activeModule())->windows( winMap );
1668 defaultWindows( winMap );
1671 /*!Gets current view managers.
1672 *\param lst - output current view managers list.
1674 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1677 if ( !activeStudy() )
1680 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1681 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1683 defaultViewManagers( lst );
1686 /*!Update windows.*/
1687 void SalomeApp_Application::updateWindows()
1689 QMap<int, int> winMap;
1690 currentWindows( winMap );
1692 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1693 getWindow( it.key() );
1695 loadWindowsGeometry();
1697 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1698 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1701 /*!Update view managers.*/
1702 void SalomeApp_Application::updateViewManagers()
1705 currentViewManagers( lst );
1707 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1708 getViewManager( *it, true );
1711 /*!Load windows geometry.*/
1712 void SalomeApp_Application::loadWindowsGeometry()
1714 QtxDockAction* dockMgr = 0;
1716 QAction* a = action( ViewWindowsId );
1717 if ( a && a->inherits( "QtxDockAction" ) )
1718 dockMgr = (QtxDockAction*)a;
1724 if ( activeModule() )
1725 modName = moduleLibrary( activeModule()->moduleName(), false );
1727 QString section = QString( "windows_geometry" );
1728 if ( !modName.isEmpty() )
1729 section += QString( "." ) + modName;
1731 dockMgr->loadGeometry( resourceMgr(), section, false );
1732 dockMgr->restoreGeometry();
1735 /*!Save windows geometry.*/
1736 void SalomeApp_Application::saveWindowsGeometry()
1738 QtxDockAction* dockMgr = 0;
1740 QAction* a = action( ViewWindowsId );
1741 if ( a && a->inherits( "QtxDockAction" ) )
1742 dockMgr = (QtxDockAction*)a;
1748 if ( activeModule() )
1749 modName = moduleLibrary( activeModule()->moduleName(), false );
1751 QString section = QString( "windows_geometry" );
1752 if ( !modName.isEmpty() )
1753 section += QString( "." ) + modName;
1755 dockMgr->storeGeometry();
1756 dockMgr->saveGeometry( resourceMgr(), section, false );
1759 /*!Activate windows.*/
1760 void SalomeApp_Application::activateWindows()
1762 if ( activeStudy() )
1764 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1765 itr.data()->activate( activeStudy()->id() );
1769 /*!Private SLOT. On preferences.*/
1770 void SalomeApp_Application::onProperties()
1772 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1776 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1779 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1780 int res = aDlg.exec();
1781 if( res==QDialog::Accepted && aDlg.isChanged() )
1782 SB->CommitCommand();
1786 //study->updateCaptions();
1787 updateDesktopTitle();
1791 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1792 const QString& caption, QWidget* parent )
1796 QStringList fls = QStringList::split( ";;", filters, false );
1797 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1801 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1805 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1809 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1810 const QString& caption, QWidget* parent )
1814 QStringList fls = QStringList::split( ";;", filters, false );
1815 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1819 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1821 CAM_Application::contextMenuPopup( type, thePopup, title );
1823 OB_Browser* ob = objectBrowser();
1824 if ( !ob || type != ob->popupClientType() )
1827 thePopup->insertSeparator();
1828 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1830 // "Activate module" item should appear only if it's necessary
1831 SALOME_ListIO aList;
1832 SalomeApp_SelectionMgr* mgr = selectionMgr();
1833 mgr->selectedObjects(aList);
1834 if (aList.Extent() != 1)
1836 Handle(SALOME_InteractiveObject) aIObj = aList.First();
1837 QString aModuleName(aIObj->getComponentDataType());
1838 QString aModuleTitle = moduleTitle(aModuleName);
1839 CAM_Module* currentModule = activeModule();
1840 if (currentModule && currentModule->moduleName() == aModuleTitle)
1842 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1845 /*!Update obect browser*/
1846 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1848 // update existing data models (already loaded SComponents)
1851 for ( ModuleListIterator it = modules(); it.current(); ++it )
1853 CAM_DataModel* camDM = it.current()->dataModel();
1854 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1855 ((SalomeApp_DataModel*)camDM)->update();
1858 // update "non-existing" (not loaded yet) data models
1859 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1862 _PTR(Study) stdDS = study->studyDS();
1865 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
1867 _PTR(SComponent) aComponent ( it->Value() );
1869 if ( aComponent->ComponentDataType() == "Interface Applicative" )
1870 continue; // skip the magic "Interface Applicative" component
1872 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
1877 if ( objectBrowser() )
1879 objectBrowser()->updateGeometry();
1880 objectBrowser()->updateTree();
1884 /*!Protected SLOT.On desktop activated.*/
1885 void SalomeApp_Application::onDesktopActivated()
1887 CAM_Application::onDesktopActivated();
1888 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
1890 aModule->studyActivated();
1893 /*!Create empty study.*/
1894 void SalomeApp_Application::createEmptyStudy()
1896 CAM_Application::createEmptyStudy();
1897 if ( objectBrowser() )
1898 objectBrowser()->updateTree();
1901 /*!Activate module \a mod.*/
1902 bool SalomeApp_Application::activateModule( CAM_Module* mod )
1904 bool res = CAM_Application::activateModule( mod );
1905 if ( objectBrowser() )
1906 objectBrowser()->updateTree();