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>
51 #include <SUIT_Accel.h>
53 #include <QtxToolBar.h>
54 #include <QtxMRUAction.h>
55 #include <QtxDockAction.h>
56 #include <QtxResourceEdit.h>
58 #include <OB_Browser.h>
59 #include <OB_ListItem.h>
61 #include <PythonConsole_PyConsole.h>
63 #include <SUIT_FileDlg.h>
64 #include <SUIT_MessageBox.h>
65 #include <SUIT_ResourceMgr.h>
66 #include <SUIT_ActionOperation.h>
68 #include <Utils_ORB_INIT.hxx>
69 #include <Utils_SINGLETON.hxx>
70 #include <SALOME_ModuleCatalog_impl.hxx>
71 #include <SALOME_LifeCycleCORBA.hxx>
79 #include <qcombobox.h>
80 #include <qmessagebox.h>
81 #include <qapplication.h>
85 #include <qstatusbar.h>
87 #include "SALOMEDS_StudyManager.hxx"
89 #include "SALOME_ListIteratorOfListIO.hxx"
90 #include "SALOME_ListIO.hxx"
92 #include "ToolsGUI_CatalogGeneratorDlg.h"
93 #include "ToolsGUI_RegWidget.h"
95 #define OBJECT_BROWSER_WIDTH 300
96 #define OBJECT_COLUMN_WIDTH 150
97 #define DEFAULT_BROWSER "mozilla"
99 /*!Image for empty icon.*/
100 static const char* imageEmptyIcon[] = {
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "....................",
111 "....................",
112 "....................",
113 "....................",
114 "....................",
115 "....................",
116 "....................",
117 "....................",
118 "....................",
119 "....................",
120 "....................",
121 "....................",
122 "...................."};
124 /*!Create new instance of SalomeApp_Application.*/
125 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
127 return new SalomeApp_Application();
130 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
133 Class : SalomeApp_Application
134 Description : Application containing SalomeApp module
138 SalomeApp_Application::SalomeApp_Application()
139 : CAM_Application( false ),
142 STD_TabDesktop* desk = new STD_TabDesktop();
146 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
147 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
149 desktop()->setIcon( aLogo );
150 desktop()->setDockableMenuBar( true );
151 desktop()->setDockableStatusBar( false );
153 // base logo (salome itself)
154 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "SalomeApp", tr( "APP_BASE_LOGO" ), false ) );
155 // extra logo (salome-based application)
156 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "SalomeApp", tr( "APP_EXTRA_LOGO" ), false ) );
160 mySelMgr = new SalomeApp_SelectionMgr( this );
162 myAccel = new SUIT_Accel( desktop() );
163 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
172 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
173 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
174 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, SVTK_Viewer::Type() );
175 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, SVTK_Viewer::Type() );
176 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, SVTK_Viewer::Type() );
177 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, SVTK_Viewer::Type() );
178 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, SVTK_Viewer::Type() );
179 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, SVTK_Viewer::Type() );
180 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, SVTK_Viewer::Type() );
181 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, SVTK_Viewer::Type() );
182 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, SVTK_Viewer::Type() );
183 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, SVTK_Viewer::Type() );
184 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, SVTK_Viewer::Type() );
186 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
190 *\li Save window geometry.
191 *\li Save desktop geometry.
192 *\li Save resource maneger.
193 *\li Delete selection manager.
194 *\li Destroy event filter.
196 SalomeApp_Application::~SalomeApp_Application()
198 saveWindowsGeometry();
203 desktop()->saveGeometry( resourceMgr(), "desktop" );
204 resourceMgr()->save();
209 SalomeApp_EventFilter::Destroy();
212 /*!Start application.*/
213 void SalomeApp_Application::start()
216 desktop()->loadGeometry( resourceMgr(), "desktop" );
218 CAM_Application::start();
220 QAction* a = action( ViewWindowsId );
221 if ( a && a->inherits( "QtxDockAction" ) )
222 ((QtxDockAction*)a)->setAutoPlace( true );
224 SalomeApp_EventFilter::Init();
227 updateViewManagers();
230 desktop()->statusBar()->message( "" );
233 /*!Gets application name.*/
234 QString SalomeApp_Application::applicationName() const
236 return tr( "APP_NAME" );
239 /*!Gets application version.*/
240 QString SalomeApp_Application::applicationVersion() const
242 static QString _app_version;
244 if ( _app_version.isEmpty() )
246 QString resVersion = tr( "APP_VERSION" );
247 if ( resVersion != "APP_VERSION" )
249 _app_version = resVersion;
253 QString path( ::getenv( "GUI_ROOT_DIR" ) );
254 if ( !path.isEmpty() )
255 path += QDir::separator();
256 path += QString( "bin/salome/VERSION" );
259 if ( vf.open( IO_ReadOnly ) )
262 vf.readLine( line, 1024 );
265 if ( !line.isEmpty() )
267 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
268 line.remove( line.length() - 1, 1 );
270 int idx = line.findRev( ":" );
272 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
280 /*!Load module by \a name.*/
281 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
283 CAM_Module* mod = CAM_Application::loadModule( name );
286 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
287 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
288 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
293 /*!Activate module by \a modName*/
294 bool SalomeApp_Application::activateModule( const QString& modName )
297 CAM_Module* prevMod = activeModule();
300 actName = prevMod->moduleName();
302 if ( actName == modName )
305 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
307 saveWindowsGeometry();
309 bool status = CAM_Application::activateModule( modName );
311 updateModuleActions();
319 updateViewManagers();
324 /*!Gets selection manager.*/
325 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
331 void SalomeApp_Application::createActions()
333 STD_Application::createActions();
335 SUIT_Desktop* desk = desktop();
336 SUIT_ResourceMgr* resMgr = resourceMgr();
339 createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
340 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
341 0, desk, false, this, SLOT( onDumpStudy() ) );
344 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
345 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
346 0, desk, false, this, SLOT( onLoadScript() ) );
349 createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
350 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
351 0, desk, false, this, SLOT( onProperties() ) );
354 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
355 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
356 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
358 //! Catalog Generator
359 createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIconSet(),
360 tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ),
361 0, desk, false, this, SLOT( onCatalogGen() ) );
364 createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIconSet(),
365 tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ),
366 0, desk, false, this, SLOT( onRegDisplay() ) );
369 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
370 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
371 registerAction( MRUId, mru );
373 //! default icon for neutral point ('SALOME' module)
374 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
375 if ( defIcon.isNull() )
376 defIcon = QPixmap( imageEmptyIcon );
378 //! default icon for any module
379 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
380 if ( modIcon.isNull() )
381 modIcon = QPixmap( imageEmptyIcon );
383 QToolBar* modTBar = new QtxToolBar( true, desk );
384 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
386 QActionGroup* modGroup = new QActionGroup( this );
387 modGroup->setExclusive( true );
388 modGroup->setUsesDropDown( true );
390 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
391 tr( "PRP_APP_MODULE" ), 0, desk, true );
393 myActions.insert( QString(), a );
395 QMap<QString, QString> iconMap;
396 moduleIconNames( iconMap );
398 const int iconSize = 20;
400 modGroup->addTo( modTBar );
401 modTBar->addSeparator();
404 modules( modList, false );
406 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
408 if ( (*it).isEmpty() )
412 if ( iconMap.contains( *it ) )
413 iconName = iconMap[*it];
415 QString modName = moduleName( *it );
417 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
421 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
423 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
427 myActions.insert( *it, a );
430 SUIT_Tools::simplifySeparators( modTBar );
434 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
435 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
436 createMenu( separator(), windowMenu, -1, 1 );
438 QMap<int, int> accelMap;
439 accelMap[NewGLViewId] = ALT+Key_G;
440 accelMap[NewPlot2dId] = ALT+Key_P;
441 accelMap[NewOCCViewId] = ALT+Key_O;
442 accelMap[NewVTKViewId] = ALT+Key_K;
444 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
446 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
447 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
448 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
449 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
450 createMenu( a, newWinMenu, -1 );
452 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
455 int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
456 int helpModuleMenu = createMenu( tr( "MEN_DESK_MODULE_HELP" ), helpMenu, -1, 0 );
457 createMenu( separator(), helpMenu, -1, 1 );
459 QStringList aModuleList;
460 modules( aModuleList, false );
462 int id = SalomeApp_Application::UserID;
463 // help for KERNEL and GUI
465 if (dir = getenv("GUI_ROOT_DIR")) {
466 a = createAction( id, tr( QString("Kernel & GUI Help") ), QIconSet(),
467 tr( QString("Kernel && GUI Help") ),
468 tr( QString("Kernel & GUI Help") ),
469 0, desk, false, this, SLOT( onHelpContentsModule() ) );
470 a->setName( QString("GUI") );
471 createMenu( a, helpModuleMenu, -1 );
474 // help for other existing modules
475 for ( QStringList::Iterator it = aModuleList.begin(); it != aModuleList.end(); ++it )
477 if ( (*it).isEmpty() )
480 QString modName = moduleName( *it );
481 if ( modName.compare("GEOM") == 0 ) { // to be removed when documentation for other modules will be done
482 QAction* a = createAction( id, tr( moduleTitle(modName) + QString(" Help") ), QIconSet(),
483 tr( moduleTitle(modName) + QString(" Help") ),
484 tr( moduleTitle(modName) + QString(" Help") ),
485 0, desk, false, this, SLOT( onHelpContentsModule() ) );
486 a->setName( modName );
487 createMenu( a, helpModuleMenu, -1 );
492 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
494 createMenu( DumpStudyId, fileMenu, 10, -1 );
495 createMenu( separator(), fileMenu, -1, 15, -1 );
496 createMenu( LoadScriptId, fileMenu, 10, -1 );
497 createMenu( separator(), fileMenu, -1, 15, -1 );
498 createMenu( PropertiesId, fileMenu, 10, -1 );
499 createMenu( separator(), fileMenu, -1, 15, -1 );
500 createMenu( PreferencesId, fileMenu, 15, -1 );
501 createMenu( separator(), fileMenu, -1, 15, -1 );
503 int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, -1, 50 );
504 createMenu( CatalogGenId, toolsMenu, 10, -1 );
505 createMenu( RegDisplayId, toolsMenu, 10, -1 );
506 createMenu( separator(), toolsMenu, -1, 15, -1 );
510 createMenu( separator(), fileMenu, -1, 100, -1 );
511 createMenu( MRUId, fileMenu, 100, -1 );
512 createMenu( separator(), fileMenu, -1, 100, -1 );
516 /*!On module activation action.*/
517 void SalomeApp_Application::onModuleActivation( QAction* a )
522 QString modName = a->menuText();
523 if ( modName == tr( "APP_NAME" ) )
524 modName = QString::null;
526 // Force user to create/open a study before module activation
527 QMap<QString, QString> iconMap;
528 moduleIconNames( iconMap );
529 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
531 icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
533 bool cancelled = false;
534 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
535 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
536 int res = aDlg.exec();
550 putInfo( tr("INF_CANCELLED") );
551 myActions[QString()]->setOn( true );
557 activateModule( modName );
560 /*!Default module activation.*/
561 QString SalomeApp_Application::defaultModule() const
563 QStringList aModuleNames;
564 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
565 //! If there's the one and only module --> activate it automatically
566 //! TODO: Possible improvement - default module can be taken from preferences
567 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
570 /*!On new window slot.*/
571 void SalomeApp_Application::onNewWindow()
573 const QObject* obj = sender();
574 if ( !obj || !obj->inherits( "QAction" ) )
578 int id = actionId( (QAction*)obj );
582 type = GLViewer_Viewer::Type();
585 type = Plot2d_Viewer::Type();
588 type = OCCViewer_Viewer::Type();
591 type = SVTK_Viewer::Type();
595 if ( !type.isEmpty() )
596 createViewManager( type );
599 //=======================================================================
601 /*! Purpose : SLOT. Create new document*/
602 //=======================================================================
603 void SalomeApp_Application::onNewDoc()
605 SUIT_Study* study = activeStudy();
607 saveWindowsGeometry();
609 CAM_Application::onNewDoc();
611 if ( !study ) // new study will be create in THIS application
614 updateViewManagers();
618 //=======================================================================
620 /*! Purpose : SLOT. Open new document*/
621 //=======================================================================
622 void SalomeApp_Application::onOpenDoc()
624 SUIT_Study* study = activeStudy();
625 saveWindowsGeometry();
627 CAM_Application::onOpenDoc();
629 if ( !study ) // new study will be create in THIS application
632 updateViewManagers();
636 /*! Purpose : SLOT. Open new document with \a aName.*/
637 bool SalomeApp_Application::onOpenDoc( const QString& aName )
639 bool res = false, toOpen = true, isAlreadyOpen = false;
641 // Look among opened studies
642 if (activeStudy()) { // at least one study is opened
643 SUIT_Session* aSession = SUIT_Session::session();
644 QPtrList<SUIT_Application> aAppList = aSession->applications();
645 QPtrListIterator<SUIT_Application> it (aAppList);
646 SUIT_Application* aApp = 0;
647 // iterate on all applications
648 for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
649 if (aApp->activeStudy()->studyName() == aName) {
650 isAlreadyOpen = true; // Already opened, ask user what to do
652 // The document ... is already open.
653 // Do you want to reload it?
654 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
655 tr("QUE_DOC_ALREADYOPEN").arg(aName),
656 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
657 if (aAnswer == 1) { // reload
658 if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
659 // Opened in THIS (active) application.
660 STD_Application* app1 = (STD_Application*)aAppList.at(0);
661 STD_Application* app2 = (STD_Application*)aAppList.at(1);
662 if (!app1 || !app2) {
666 if (app1->activeStudy()->studyName() == aName) {
667 // app1 is this application, we need another one
670 // Close document of this application. This application will be destroyed.
671 onCloseDoc(/*ask = */false);
672 // Open the file with another application, as this one will be destroyed.
673 return app1->onOpenDoc(aName);
675 // Opened in another application.
676 STD_Application* app = (STD_Application*)aApp;
678 app->onCloseDoc(/*ask = */false);
680 } else { // do not reload
681 // OK, the study will not be reloaded, but we call
682 // CAM_Application::onOpenDoc( aName ) all the same.
683 // It will activate a desktop of the study <aName>.
689 // Look among unloaded studies
690 if (!isAlreadyOpen) {
691 std::vector<std::string> List = studyMgr()->GetOpenStudies();
694 for (unsigned int ind = 0; ind < List.size() && !isAlreadyOpen; ind++) {
695 studyName = List[ind].c_str();
696 if (aName == studyName) {
697 // Already exists unloaded, ask user what to do
698 isAlreadyOpen = true;
700 // The document ... already exists in the study manager.
701 // Do you want to reload it?
702 int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
703 tr("QUE_DOC_ALREADYEXIST").arg(aName),
704 tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
706 _PTR(Study) aStudy = studyMgr()->GetStudyByName(aName.latin1());
708 studyMgr()->Close(aStudy);
717 res = CAM_Application::onOpenDoc( aName );
719 QAction* a = action( MRUId );
720 if ( a && a->inherits( "QtxMRUAction" ) )
722 QtxMRUAction* mru = (QtxMRUAction*)a;
724 mru->insert( aName );
726 mru->remove( aName );
731 /*!SLOT. Load document.*/
732 void SalomeApp_Application::onLoadDoc()
734 QString name, studyname, ext;
736 STD_LoadStudiesDlg aDlg( desktop(), TRUE);
738 std::vector<std::string> List = studyMgr()->GetOpenStudies();
740 SUIT_Session* aSession = SUIT_Session::session();
741 QPtrList<SUIT_Application> aAppList = aSession->applications();
742 SUIT_Application* aApp = 0;
744 for (unsigned int ind = 0; ind < List.size(); ind++) {
745 studyname = List[ind].c_str();
746 //Add to list only unloaded studies
747 bool isAlreadyOpen = false;
748 for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
751 if(!aApp || !aApp->activeStudy()) continue;
752 if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
755 if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
758 int retVal = aDlg.exec();
759 studyname = aDlg.ListComponent->currentText();
761 if (retVal == QDialog::Rejected)
764 if ( studyname.isNull() || studyname.isEmpty() )
768 name.replace( QRegExp(":"), "/" );
770 if(onLoadDoc(name)) {
772 updateViewManagers();
773 updateObjectBrowser(true);
778 /*!SLOT. Load document with \a aName.*/
779 bool SalomeApp_Application::onLoadDoc( const QString& aName )
781 bool res = CAM_Application::onLoadDoc( aName );
783 /*jfa tmp:QAction* a = action( MRUId );
784 if ( a && a->inherits( "QtxMRUAction" ) )
786 QtxMRUAction* mru = (QtxMRUAction*)a;
788 mru->insert( aName );
790 mru->remove( aName );
795 /*!Private SLOT. Selection.*/
796 void SalomeApp_Application::onSelection()
798 onSelectionChanged();
800 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
801 ((SalomeApp_Module*)activeModule())->selectionChanged();
804 /*!SLOT. Copy objects to study maneger from selection maneger..*/
805 void SalomeApp_Application::onCopy()
808 SalomeApp_SelectionMgr* mgr = selectionMgr();
809 mgr->selectedObjects(list);
811 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
812 if(study == NULL) return;
814 _PTR(Study) stdDS = study->studyDS();
817 SALOME_ListIteratorOfListIO it( list );
820 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
822 studyMgr()->Copy(so);
823 onSelectionChanged();
830 /*!SLOT. Paste objects to study maneger from selection manager.*/
831 void SalomeApp_Application::onPaste()
834 SalomeApp_SelectionMgr* mgr = selectionMgr();
835 mgr->selectedObjects(list);
837 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
838 if(study == NULL) return;
840 _PTR(Study) stdDS = study->studyDS();
843 SALOME_ListIteratorOfListIO it( list );
846 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
848 studyMgr()->Paste(so);
849 updateObjectBrowser( true );
850 updateActions(); //SRN: BugID IPAL9377, case 3
857 /*!Sets enable or disable some actions on selection changed.*/
858 void SalomeApp_Application::onSelectionChanged()
861 SalomeApp_SelectionMgr* mgr = selectionMgr();
862 mgr->selectedObjects(list);
864 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
865 if(study == NULL) return;
867 _PTR(Study) stdDS = study->studyDS();
872 SALOME_ListIteratorOfListIO it( list );
873 if(it.More() && list.Extent() == 1)
875 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
877 qaction = action(EditCopyId);
878 if( so && studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
879 else qaction->setEnabled(false);
881 qaction = action(EditPasteId);
882 if( so && studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
883 else qaction->setEnabled(false);
886 qaction = action(EditCopyId);
887 qaction->setEnabled(false);
888 qaction = action(EditPasteId);
889 qaction->setEnabled(false);
893 /*!Update object browser.*/
894 void SalomeApp_Application::onRefresh()
896 updateObjectBrowser( true );
899 /*!Delete references.*/
900 void SalomeApp_Application::onDeleteReferences()
903 SalomeApp_SelectionMgr* mgr = selectionMgr();
904 mgr->selectedObjects(aList);
906 if (aList.Extent() < 1) return;
908 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
909 _PTR(Study) aStudyDS = aStudy->studyDS();
910 _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder();
913 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
915 if ( it.Value()->hasEntry() )
917 _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
918 if ( aSObject->ReferencedObject(anObj) )
919 aStudyBuilder->RemoveReference(aSObject);
923 updateObjectBrowser();
927 void SalomeApp_Application::onOpenWith()
929 QApplication::setOverrideCursor( Qt::waitCursor );
931 SalomeApp_SelectionMgr* mgr = selectionMgr();
932 mgr->selectedObjects(aList);
933 if (aList.Extent() != 1)
935 QApplication::restoreOverrideCursor();
938 Handle(SALOME_InteractiveObject) aIObj = aList.First();
939 QString aModuleName(aIObj->getComponentDataType());
940 QString aModuleTitle = moduleTitle(aModuleName);
941 activateModule(aModuleTitle);
942 QApplication::restoreOverrideCursor();
945 bool SalomeApp_Application::useStudy(const QString& theName)
948 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
951 res = aStudy->loadDocument( theName );
952 updateDesktopTitle();
953 updateCommandsStatus();
958 *\param study - SUIT_Study.
960 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
962 CAM_Application::setActiveStudy( study );
967 //=======================================================================
968 // name : createNewStudy
969 /*! Purpose : Create new study*/
970 //=======================================================================
971 SUIT_Study* SalomeApp_Application::createNewStudy()
973 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
975 // Set up processing of major study-related events
976 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
977 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
978 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
979 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
984 //=======================================================================
985 // name : createNewStudy
986 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
987 //=======================================================================
988 void SalomeApp_Application::updateCommandsStatus()
990 CAM_Application::updateCommandsStatus();
992 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
994 QAction* a = action( id );
996 a->setEnabled( activeStudy() );
1000 QAction* a = action( DumpStudyId );
1002 a->setEnabled( activeStudy() );
1005 a = action( LoadScriptId );
1007 a->setEnabled( activeStudy() );
1009 a = action( PropertiesId );
1011 a->setEnabled( activeStudy() );
1013 a = action(EditCopyId);
1014 a->setEnabled(false);
1015 a = action(EditPasteId);
1016 a->setEnabled(false);
1019 //=======================================================================
1020 // name : onHelpAbout
1021 /*! Purpose : SLOT. Display "About" message box*/
1022 //=======================================================================
1023 void SalomeApp_Application::onHelpAbout()
1025 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
1030 // Helps to execute command
1031 class RunBrowser: public QThread {
1034 RunBrowser(QString theApp, QString theParams, QString theHelpFile, QString theContext=NULL):
1035 myApp(theApp), myParams(theParams), myHelpFile("file:" + theHelpFile + theContext), myStatus(0) {};
1041 if ( !myApp.isEmpty())
1043 aCommand.sprintf("%s %s %s",myApp.latin1(),myParams.latin1(),myHelpFile.latin1());
1044 myStatus = system(aCommand);
1047 QCustomEvent* ce2000 = new QCustomEvent (2000);
1048 postEvent (qApp, ce2000);
1052 if( myStatus != 0 || myApp.isEmpty())
1055 aCommand.sprintf("%s %s %s", QString(DEFAULT_BROWSER).latin1(),myParams.latin1(), myHelpFile.latin1());
1056 myStatus = system(aCommand);
1059 QCustomEvent* ce2001 = new QCustomEvent (2001);
1060 postEvent (qApp, ce2001);
1073 //=======================================================================
1074 // name : onHelpContentsModule
1075 /*! Purpose : SLOT. Display help contents for choosen module*/
1076 //=======================================================================
1077 void SalomeApp_Application::onHelpContentsModule()
1079 const QAction* obj = (QAction*) sender();
1081 QString aComponentName = obj->name();
1082 QString aFileName = aComponentName.lower() + ".htm";
1087 if (dir = getenv( aComponentName + "_ROOT_DIR")) {
1088 root = Qtx::addSlash( Qtx::addSlash(dir) + Qtx::addSlash("doc") + Qtx::addSlash("salome") + Qtx::addSlash(aComponentName));
1089 if ( QFileInfo( root + aFileName ).exists() ) {
1092 SUIT_MessageBox::warn1( desktop(), tr("WRN_WARNING"),
1093 QString( "%1"+ aFileName + " doesn't exist." ).arg(root), tr ("BUT_OK") );
1098 QString helpFile = QFileInfo( homeDir + aFileName ).absFilePath();
1099 SUIT_ResourceMgr* resMgr = resourceMgr();
1100 QString anApp = resMgr->stringValue("ExternalBrowser", "application");
1101 QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
1103 RunBrowser* rs = new RunBrowser(anApp, aParams, helpFile);
1107 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
1114 if ( !activeStudy() )
1117 sId = activeStudy()->id();
1120 if ( myWindows.contains( flag ) )
1121 wid = myWindows[flag]->widget( sId );
1126 /*!Adds window to application.
1127 *\param wid - QWidget
1128 *\param flag - key wor window
1129 *\param studyId - study id
1130 * Flag used how identificator of window in windows list.
1132 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
1140 if ( !activeStudy() )
1143 sId = activeStudy()->id();
1146 if ( !myWindows.contains( flag ) )
1148 QMap<int, int> winMap;
1149 currentWindows( winMap );
1151 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
1152 if ( winMap.contains( flag ) )
1153 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
1155 myWindows[flag]->setResizeEnabled( true );
1156 myWindows[flag]->setCloseMode( QDockWindow::Always );
1157 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
1161 if( wid->inherits( "PythonConsole" ) )
1162 f = ( ( PythonConsole* )wid )->font();
1166 myWindows[flag]->insert( sId, wid );
1169 setWindowShown( flag, !myWindows[flag]->isEmpty() );
1172 /*!Remove window from application.
1173 *\param flag - key wor window
1174 *\param studyId - study id
1175 * Flag used how identificator of window in windows list.
1177 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
1179 if ( !myWindows.contains( flag ) )
1185 if ( !activeStudy() )
1188 sId = activeStudy()->id();
1191 QWidget* wid = myWindows[flag]->widget( sId );
1192 myWindows[flag]->remove( sId );
1195 setWindowShown( flag, !myWindows[flag]->isEmpty() );
1199 *\param flag - key wor window
1200 *\param studyId - study id
1201 * Flag used how identificator of window in windows list.
1203 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
1205 QWidget* wid = window( flag, studyId );
1207 addWindow( wid = createWindow( flag ), flag, studyId );
1212 /*!Check is window visible?(with identificator \a type)*/
1213 bool SalomeApp_Application::isWindowVisible( const int type ) const
1216 if ( myWindows.contains( type ) )
1218 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
1219 res = desk && desk->appropriate( myWindows[type] );
1224 /*!Sets window show or hide.
1225 *\param type - window identificator.
1226 *\param on - true/false (window show/hide)
1228 void SalomeApp_Application::setWindowShown( const int type, const bool on )
1230 if ( !desktop() || !myWindows.contains( type ) )
1233 QDockWindow* dw = myWindows[type];
1234 desktop()->setAppropriate( dw, on );
1235 on ? dw->show() : dw->hide();
1238 OB_Browser* SalomeApp_Application::objectBrowser()
1241 QWidget* wid = getWindow( WT_ObjectBrowser );
1242 if ( wid->inherits( "OB_Browser" ) )
1243 ob = (OB_Browser*)wid;
1247 /*!Gets "LogWindow".*/
1248 LogWindow* SalomeApp_Application::logWindow()
1251 QWidget* wid = getWindow( WT_LogWindow );
1252 if ( wid->inherits( "LogWindow" ) )
1253 lw = (LogWindow*)wid;
1257 /*!Get "PythonConsole"*/
1258 PythonConsole* SalomeApp_Application::pythonConsole()
1260 PythonConsole* console = 0;
1261 QWidget* wid = getWindow( WT_PyConsole );
1262 if ( wid->inherits( "PythonConsole" ) )
1263 console = (PythonConsole*)wid;
1267 /*!Gets preferences.*/
1268 SalomeApp_Preferences* SalomeApp_Application::preferences() const
1270 return preferences( false );
1273 /*!Gets view manager*/
1274 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
1276 SUIT_ViewManager* aVM = viewManager( vmType );
1277 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1279 if ( anActiveVM && anActiveVM->getType() == vmType )
1282 if ( aVM && create )
1284 if ( !aVM->getActiveView() )
1287 aVM->getActiveView()->setFocus();
1290 aVM = createViewManager( vmType );
1295 /*!Create view manager.*/
1296 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
1298 SUIT_ResourceMgr* resMgr = resourceMgr();
1300 SUIT_ViewManager* viewMgr = 0;
1301 if ( vmType == GLViewer_Viewer::Type() )
1303 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1304 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1306 else if ( vmType == Plot2d_Viewer::Type() )
1308 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1309 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
1311 else if ( vmType == OCCViewer_Viewer::Type() )
1313 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1314 SOCC_Viewer* vm = new SOCC_Viewer();
1315 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1316 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1319 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1320 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1321 vm->setIsos( u, v );
1322 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1323 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1325 else if ( vmType == SVTK_Viewer::Type() )
1327 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1328 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1331 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1332 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1333 new SalomeApp_VTKSelector( vm, mySelMgr );
1340 addViewManager( viewMgr );
1341 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1343 if ( viewWin && desktop() )
1344 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1346 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1347 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1352 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1354 removeViewManager( theVM );
1357 /*!Private SLOT. On study created.*/
1358 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1360 SUIT_DataObject* aRoot = 0;
1361 if ( theStudy && theStudy->root() )
1363 aRoot = theStudy->root();
1364 //aRoot->setName( tr( "DATA_MODELS" ) );
1366 if ( objectBrowser() != 0 )
1367 objectBrowser()->setRootObject( aRoot );
1369 activateModule( defaultModule() );
1374 /*!Private SLOT. On study opened.*/
1375 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1377 SUIT_DataObject* aRoot = 0;
1378 if ( theStudy && theStudy->root() )
1380 aRoot = theStudy->root();
1383 if ( objectBrowser() != 0 ) {
1384 objectBrowser()->setRootObject( aRoot );
1387 activateModule( defaultModule() );
1394 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1399 /*!Private SLOT. On study closed.*/
1400 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1404 activateModule( "" );
1406 // Bug 10396: remove all selectors
1408 mySelMgr = new SalomeApp_SelectionMgr( this );
1410 saveWindowsGeometry();
1413 /*!Private SLOT. On dump study.*/
1414 void SalomeApp_Application::onDumpStudy( )
1416 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1417 if ( !appStudy ) return;
1418 _PTR(Study) aStudy = appStudy->studyDS();
1420 QStringList aFilters;
1421 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1423 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1424 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1425 fd->setFilters( aFilters );
1426 fd->SetChecked(true);
1428 QString aFileName = fd->selectedFile();
1429 bool toPublish = fd->IsChecked();
1432 if(!aFileName.isEmpty()) {
1433 QFileInfo aFileInfo(aFileName);
1434 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1438 /*!Private SLOT. On load script.*/
1439 void SalomeApp_Application::onLoadScript( )
1441 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1442 if ( !appStudy ) return;
1443 _PTR(Study) aStudy = appStudy->studyDS();
1445 if ( aStudy->GetProperties()->IsLocked() ) {
1446 SUIT_MessageBox::warn1 ( desktop(),
1447 QObject::tr("WRN_WARNING"),
1448 QObject::tr("WRN_STUDY_LOCKED"),
1449 QObject::tr("BUT_OK") );
1453 QStringList filtersList;
1454 filtersList.append(tr("PYTHON_FILES_FILTER"));
1455 filtersList.append(tr("ALL_FILES_FILTER"));
1457 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1459 if ( !aFile.isEmpty() )
1461 QString command = QString("execfile(\"%1\")").arg(aFile);
1463 PythonConsole* pyConsole = pythonConsole();
1466 pyConsole->exec( command );
1470 /*!Private SLOT. On preferences.*/
1471 void SalomeApp_Application::onPreferences()
1473 QApplication::setOverrideCursor( Qt::waitCursor );
1475 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1477 QApplication::restoreOverrideCursor();
1487 /*!Private SLOT. On open document with name \a aName.*/
1488 void SalomeApp_Application::onMRUActivated( QString aName )
1493 /*!Private SLOT. On preferences changed.*/
1494 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1496 SalomeApp_Module* sMod = 0;
1497 CAM_Module* mod = module( modName );
1498 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1499 sMod = (SalomeApp_Module*)mod;
1502 sMod->preferencesChanged( section, param );
1504 preferencesChanged( section, param );
1507 /*!Gets file filter.
1508 *\retval QString "(*.hdf)"
1510 QString SalomeApp_Application::getFileFilter() const
1515 /*!Remove all windows from study.*/
1516 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1518 CAM_Application::beforeCloseDoc( s );
1520 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1521 removeWindow( itr.key(), s->id() );
1524 /*!Update actions.*/
1525 void SalomeApp_Application::updateActions()
1527 updateCommandsStatus();
1531 QWidget* SalomeApp_Application::createWindow( const int flag )
1535 SUIT_ResourceMgr* resMgr = resourceMgr();
1537 if ( flag == WT_ObjectBrowser )
1539 OB_Browser* ob = new OB_Browser( desktop() );
1540 ob->setAutoUpdate( true );
1541 ob->setAutoOpenLevel( 1 );
1542 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1543 ob->listView()->setColumnWidth( 0, OBJECT_COLUMN_WIDTH );
1544 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1545 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1547 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1548 connect( ob->listView(), SIGNAL( doubleClicked( QListViewItem* ) ), this, SLOT( onDblClick( QListViewItem* ) ) );
1550 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1551 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1553 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1554 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1555 QString().sprintf( "visibility_column_%d", i ), true ) );
1557 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1559 // Create OBSelector
1560 new SalomeApp_OBSelector( ob, mySelMgr );
1564 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1566 else if ( flag == WT_PyConsole )
1568 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1569 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1570 pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1573 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1575 else if ( flag == WT_LogWindow )
1577 LogWindow* logWin = new LogWindow( desktop() );
1578 logWin->setCaption( tr( "LOG_WINDOW" ) );
1581 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1587 /*!Default windows(Object Browser, Python Console).
1588 * Adds to map \a aMap.
1590 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1592 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1593 aMap.insert( WT_PyConsole, Qt::DockBottom );
1594 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1597 /*!Default view manager.*/
1598 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1603 /*!Gets preferences.
1604 * Create preferences, if \a crt = true.
1606 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1611 SalomeApp_Application* that = (SalomeApp_Application*)this;
1613 if ( !_prefs_ && crt )
1615 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1616 that->createPreferences( _prefs_ );
1619 that->myPrefs = _prefs_;
1621 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1622 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1624 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1627 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1629 QStringList modNameList;
1630 app->modules( modNameList, false );
1631 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1633 int id = _prefs_->addPreference( *it );
1634 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1638 app->modules( modList );
1639 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1641 SalomeApp_Module* mod = 0;
1642 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1643 mod = (SalomeApp_Module*)itr.current();
1645 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1647 int modCat = _prefs_->addPreference( mod->moduleName() );
1648 _prefs_->setItemProperty( modCat, "info", QString::null );
1649 mod->createPreferences();
1654 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1655 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1660 /*!Add new module to application.*/
1661 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1663 CAM_Application::moduleAdded( mod );
1665 SalomeApp_Module* salomeMod = 0;
1666 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1667 salomeMod = (SalomeApp_Module*)mod;
1669 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1671 int modCat = myPrefs->addPreference( mod->moduleName() );
1672 myPrefs->setItemProperty( modCat, "info", QString::null );
1673 salomeMod->createPreferences();
1677 /*!Create preferences.*/
1678 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1683 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1685 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1686 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1687 pref->setItemProperty( studyGroup, "columns", 1 );
1689 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1690 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1691 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1692 pref->setItemProperty( undoPref, "min", 1 );
1693 pref->setItemProperty( undoPref, "max", 100 );
1695 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1696 pref->setItemProperty( extgroup, "columns", 1 );
1697 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1698 pref->setItemProperty( apppref, "existing", true );
1699 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1701 pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1703 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1704 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1705 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1709 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1710 int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1711 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1713 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1714 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1716 pref->setItemProperty( defCols, "columns", 1 );
1718 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1719 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1721 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1723 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1725 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1727 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1729 pref->setItemProperty( occGroup, "columns", 1 );
1730 pref->setItemProperty( vtkGroup, "columns", 1 );
1731 pref->setItemProperty( plot2dGroup, "columns", 1 );
1733 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1734 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1735 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1736 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1738 pref->setItemProperty( occTS, "min", 1 );
1739 pref->setItemProperty( occTS, "max", 150 );
1741 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1742 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1743 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1744 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1746 pref->setItemProperty( isoU, "min", 0 );
1747 pref->setItemProperty( isoU, "max", 100000 );
1749 pref->setItemProperty( isoV, "min", 0 );
1750 pref->setItemProperty( isoV, "max", 100000 );
1752 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1753 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1754 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1755 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1757 pref->setItemProperty( vtkTS, "min", 1 );
1758 pref->setItemProperty( vtkTS, "max", 150 );
1760 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1761 SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1763 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1764 SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" );
1765 QStringList aLegendPosList;
1766 aLegendPosList.append( tr("PREF_LEFT") );
1767 aLegendPosList.append( tr("PREF_RIGHT") );
1768 aLegendPosList.append( tr("PREF_TOP") );
1769 aLegendPosList.append( tr("PREF_BOTTOM") );
1771 QValueList<QVariant> anIndexesList;
1772 anIndexesList.append(0);
1773 anIndexesList.append(1);
1774 anIndexesList.append(2);
1775 anIndexesList.append(3);
1777 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1778 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1780 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1781 SalomeApp_Preferences::Selector, "Plot2d", "CurveType" );
1782 QStringList aCurveTypesList;
1783 aCurveTypesList.append( tr("PREF_POINTS") );
1784 aCurveTypesList.append( tr("PREF_LINES") );
1785 aCurveTypesList.append( tr("PREF_SPLINE") );
1787 anIndexesList.clear();
1788 anIndexesList.append(0);
1789 anIndexesList.append(1);
1790 anIndexesList.append(2);
1792 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1793 pref->setItemProperty( curveType, "indexes", anIndexesList );
1795 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1796 SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1798 pref->setItemProperty( markerSize, "min", 0 );
1799 pref->setItemProperty( markerSize, "max", 100 );
1801 QStringList aScaleModesList;
1802 aScaleModesList.append( tr("PREF_LINEAR") );
1803 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1805 anIndexesList.clear();
1806 anIndexesList.append(0);
1807 anIndexesList.append(1);
1809 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1810 SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1812 pref->setItemProperty( horScale, "strings", aScaleModesList );
1813 pref->setItemProperty( horScale, "indexes", anIndexesList );
1815 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1816 SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1818 pref->setItemProperty( verScale, "strings", aScaleModesList );
1819 pref->setItemProperty( verScale, "indexes", anIndexesList );
1821 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1822 SalomeApp_Preferences::Color, "Plot2d", "Background" );
1824 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1825 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1826 pref->setItemProperty( dirGroup, "columns", 1 );
1827 pref->addPreference( tr( "" ), dirGroup,
1828 SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1831 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1833 SUIT_ResourceMgr* resMgr = resourceMgr();
1837 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1839 int sz = resMgr->integerValue( sec, param, -1 );
1840 QPtrList<SUIT_ViewManager> lst;
1841 viewManagers( OCCViewer_Viewer::Type(), lst );
1842 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1844 SUIT_ViewModel* vm = it.current()->getViewModel();
1845 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1848 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1849 occVM->setTrihedronSize( sz );
1850 occVM->getAISContext()->UpdateCurrentViewer();
1854 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1856 int sz = resMgr->integerValue( sec, param, -1 );
1857 QPtrList<SUIT_ViewManager> lst;
1858 viewManagers( SVTK_Viewer::Type(), lst );
1859 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1861 SUIT_ViewModel* vm = it.current()->getViewModel();
1862 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1865 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1868 vtkVM->setTrihedronSize( sz );
1874 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1876 QPtrList<SUIT_ViewManager> lst;
1877 viewManagers( OCCViewer_Viewer::Type(), lst );
1878 int u = resMgr->integerValue( sec, "iso_number_u" );
1879 int v = resMgr->integerValue( sec, "iso_number_v" );
1880 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1881 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1884 if( sec=="ObjectBrowser" )
1886 if( param=="auto_size" )
1888 OB_Browser* ob = objectBrowser();
1892 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1893 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1895 updateObjectBrowser( false );
1899 if( sec=="PyConsole" )
1902 if( pythonConsole() )
1903 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1907 /*!Update desktop title.*/
1908 void SalomeApp_Application::updateDesktopTitle() {
1909 QString aTitle = applicationName();
1910 QString aVer = applicationVersion();
1911 if ( !aVer.isEmpty() )
1912 aTitle += QString( " " ) + aVer;
1914 if ( activeStudy() )
1916 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1917 if ( !sName.isEmpty() ) {
1918 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1919 _PTR(Study) stdDS = study->studyDS();
1921 if ( stdDS->GetProperties()->IsLocked() ) {
1922 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1924 aTitle += QString( " - [%1]" ).arg( sName );
1930 desktop()->setCaption( aTitle );
1933 /*!Update windows after close document.*/
1934 void SalomeApp_Application::afterCloseDoc()
1938 CAM_Application::afterCloseDoc();
1941 /*!Gets CORBA::ORB_var*/
1942 CORBA::ORB_var SalomeApp_Application::orb()
1944 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1945 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1949 /*!Create and return SALOMEDS_StudyManager.*/
1950 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1952 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1956 /*!Create and return SALOME_NamingService.*/
1957 SALOME_NamingService* SalomeApp_Application::namingService()
1959 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1963 /*!Create and return SALOME_LifeCycleCORBA.*/
1964 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1966 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1970 QString SalomeApp_Application::defaultEngineIOR()
1972 /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1973 QString anIOR( "" );
1974 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1975 if ( !CORBA::is_nil( anEngine ) )
1976 anIOR = orb()->object_to_string( anEngine );
1980 /*!Adds icon names for modules.*/
1981 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1985 SUIT_ResourceMgr* resMgr = resourceMgr();
1989 QStringList modList;
1990 modules( modList, false );
1992 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1994 QString modName = *it;
1995 QString modIntr = moduleName( modName );
1996 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1998 if ( modIcon.isEmpty() )
2001 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
2002 modIcon += QString( ".png" );
2004 iconMap.insert( modName, modIcon );
2008 /*!Update module action.*/
2009 void SalomeApp_Application::updateModuleActions()
2012 if ( activeModule() )
2013 modName = activeModule()->moduleName();
2015 if ( myActions.contains( modName ) )
2016 myActions[modName]->setOn( true );
2019 /*!Gets current windows.
2020 *\param winMap - output current windows map.
2022 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
2025 if ( !activeStudy() )
2028 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
2029 ((SalomeApp_Module*)activeModule())->windows( winMap );
2031 defaultWindows( winMap );
2034 /*!Gets current view managers.
2035 *\param lst - output current view managers list.
2037 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
2040 if ( !activeStudy() )
2043 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
2044 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
2046 defaultViewManagers( lst );
2049 /*!Update windows.*/
2050 void SalomeApp_Application::updateWindows()
2052 QMap<int, int> winMap;
2053 currentWindows( winMap );
2055 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
2056 getWindow( it.key() );
2058 loadWindowsGeometry();
2060 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2061 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
2064 /*!Update view managers.*/
2065 void SalomeApp_Application::updateViewManagers()
2068 currentViewManagers( lst );
2070 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
2071 getViewManager( *it, true );
2074 /*!Load windows geometry.*/
2075 void SalomeApp_Application::loadWindowsGeometry()
2077 QtxDockAction* dockMgr = 0;
2079 QAction* a = action( ViewWindowsId );
2080 if ( a && a->inherits( "QtxDockAction" ) )
2081 dockMgr = (QtxDockAction*)a;
2087 if ( activeModule() )
2088 modName = activeModule()->name("");
2090 QString section = QString( "windows_geometry" );
2091 if ( !modName.isEmpty() )
2092 section += QString( "." ) + modName;
2094 dockMgr->loadGeometry( resourceMgr(), section, false );
2095 dockMgr->restoreGeometry();
2098 /*!Save windows geometry.*/
2099 void SalomeApp_Application::saveWindowsGeometry()
2101 QtxDockAction* dockMgr = 0;
2103 QAction* a = action( ViewWindowsId );
2104 if ( a && a->inherits( "QtxDockAction" ) )
2105 dockMgr = (QtxDockAction*)a;
2111 if ( activeModule() )
2112 modName = activeModule()->name("");
2114 QString section = QString( "windows_geometry" );
2115 if ( !modName.isEmpty() )
2116 section += QString( "." ) + modName;
2118 dockMgr->storeGeometry();
2119 dockMgr->saveGeometry( resourceMgr(), section, false );
2122 /*!Activate windows.*/
2123 void SalomeApp_Application::activateWindows()
2125 if ( activeStudy() )
2127 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
2128 itr.data()->activate( activeStudy()->id() );
2132 /*!Private SLOT. On preferences.*/
2133 void SalomeApp_Application::onProperties()
2135 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
2139 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
2142 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
2143 int res = aDlg.exec();
2144 if( res==QDialog::Accepted && aDlg.isChanged() )
2145 SB->CommitCommand();
2149 //study->updateCaptions();
2150 updateDesktopTitle();
2155 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
2156 const QString& caption, QWidget* parent )
2160 QStringList fls = QStringList::split( ";;", filters, false );
2161 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
2165 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
2169 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
2173 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
2174 const QString& caption, QWidget* parent )
2178 QStringList fls = QStringList::split( ";;", filters, false );
2179 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
2183 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
2185 CAM_Application::contextMenuPopup( type, thePopup, title );
2187 OB_Browser* ob = objectBrowser();
2188 if ( !ob || type != ob->popupClientType() )
2191 thePopup->insertSeparator();
2192 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
2194 // Get selected objects
2195 SALOME_ListIO aList;
2196 SalomeApp_SelectionMgr* mgr = selectionMgr();
2197 mgr->selectedObjects(aList);
2199 // "Delete reference" item should appear only for invalid references
2201 // Check if selected objects is invalid references
2202 bool isInvalidRefs = true;
2204 if ( aList.Extent() < 1 )
2205 isInvalidRefs = false;
2207 if ( isInvalidRefs )
2209 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
2210 _PTR(Study) aStudyDS = aStudy->studyDS();
2211 _PTR(SObject) anObj;
2213 for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() )
2215 if ( it.Value()->hasEntry() )
2217 _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
2218 if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() )
2219 isInvalidRefs = false;
2224 // Add "Delete refrence" item to popup
2225 if ( isInvalidRefs )
2227 thePopup->insertSeparator();
2228 thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) );
2232 // "Activate module" item should appear only if it's necessary
2233 if (aList.Extent() != 1)
2235 Handle(SALOME_InteractiveObject) aIObj = aList.First();
2236 QString aModuleName(aIObj->getComponentDataType());
2237 QString aModuleTitle = moduleTitle(aModuleName);
2238 CAM_Module* currentModule = activeModule();
2239 if (currentModule && currentModule->moduleName() == aModuleTitle)
2241 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
2245 /*!Update obect browser*/
2246 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
2248 // update existing data models (already loaded SComponents)
2251 for ( ModuleListIterator it = modules(); it.current(); ++it )
2253 CAM_DataModel* camDM = it.current()->dataModel();
2254 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
2255 ((SalomeApp_DataModel*)camDM)->update();
2258 // update "non-existing" (not loaded yet) data models
2259 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
2262 _PTR(Study) stdDS = study->studyDS();
2265 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
2267 _PTR(SComponent) aComponent ( it->Value() );
2269 if ( aComponent->ComponentDataType() == "Interface Applicative" )
2270 continue; // skip the magic "Interface Applicative" component
2272 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
2277 if ( objectBrowser() )
2279 objectBrowser()->updateGeometry();
2280 objectBrowser()->updateTree();
2284 /*!Protected SLOT.On desktop activated.*/
2285 void SalomeApp_Application::onDesktopActivated()
2287 CAM_Application::onDesktopActivated();
2288 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
2290 aModule->studyActivated();
2293 /*!Create empty study.*/
2294 void SalomeApp_Application::createEmptyStudy()
2296 CAM_Application::createEmptyStudy();
2297 if ( objectBrowser() )
2298 objectBrowser()->updateTree();
2301 /*!Activate module \a mod.*/
2302 bool SalomeApp_Application::activateModule( CAM_Module* mod )
2304 bool res = CAM_Application::activateModule( mod );
2305 if ( objectBrowser() )
2306 objectBrowser()->updateTree();
2310 /*!Display Catalog Genenerator dialog */
2311 void SalomeApp_Application::onCatalogGen()
2313 ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
2317 /*!Display Registry Display dialog */
2318 void SalomeApp_Application::onRegDisplay()
2320 CORBA::ORB_var anOrb = orb();
2321 ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
2324 regWnd->setActiveWindow();
2327 /*!return keyborad accelerators manager object */
2328 SUIT_Accel* SalomeApp_Application::accel() const
2333 /*!find original object by double click on item */
2334 void SalomeApp_Application::onDblClick( QListViewItem* it )
2336 OB_ListItem* item = dynamic_cast<OB_ListItem*>( it );
2337 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
2341 SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>( item->dataObject() );
2345 QString entry = obj->entry();
2346 _PTR(SObject) sobj = study->studyDS()->FindObjectID( entry.latin1() ), ref;
2348 if( sobj && sobj->ReferencedObject( ref ) )
2350 entry = ref->GetID();
2351 QListViewItemIterator anIt( item->listView() );
2352 for( ; anIt.current(); anIt++ )
2354 OB_ListItem* item = dynamic_cast<OB_ListItem*>( anIt.current() );
2358 SalomeApp_DataObject* original = dynamic_cast<SalomeApp_DataObject*>( item->dataObject() );
2359 if( original->entry()!=entry )
2362 OB_Browser* br = objectBrowser();
2363 br->setSelected( original );
2364 SUIT_DataObject* p = original->parent();