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>
60 #include <PythonConsole_PyConsole.h>
62 #include <SUIT_FileDlg.h>
63 #include <SUIT_MessageBox.h>
64 #include <SUIT_ResourceMgr.h>
65 #include <SUIT_ActionOperation.h>
67 #include <Utils_ORB_INIT.hxx>
68 #include <Utils_SINGLETON.hxx>
69 #include <SALOME_ModuleCatalog_impl.hxx>
70 #include <SALOME_LifeCycleCORBA.hxx>
78 #include <qcombobox.h>
79 #include <qmessagebox.h>
80 #include <qapplication.h>
84 #include "SALOMEDS_StudyManager.hxx"
86 #include "SALOME_ListIteratorOfListIO.hxx"
87 #include "SALOME_ListIO.hxx"
89 #include "ToolsGUI_CatalogGeneratorDlg.h"
90 #include "ToolsGUI_RegWidget.h"
92 #define OBJECT_BROWSER_WIDTH 300
94 /*!Image for empty icon.*/
95 static const char* imageEmptyIcon[] = {
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "....................",
111 "....................",
112 "....................",
113 "....................",
114 "....................",
115 "....................",
116 "....................",
117 "...................."};
119 /*!Create new instance of SalomeApp_Application.*/
120 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
122 return new SalomeApp_Application();
125 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
128 Class : SalomeApp_Application
129 Description : Application containing SalomeApp module
133 SalomeApp_Application::SalomeApp_Application()
134 : CAM_Application( false ),
137 STD_TabDesktop* desk = new STD_TabDesktop();
141 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
142 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
144 desktop()->setIcon( aLogo );
145 desktop()->setDockableMenuBar( true );
146 desktop()->setDockableStatusBar( false );
148 // base logo (salome itself)
149 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "SalomeApp", tr( "APP_BASE_LOGO" ), false ) );
150 // extra logo (salome-based application)
151 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "SalomeApp", tr( "APP_EXTRA_LOGO" ), false ) );
155 mySelMgr = new SalomeApp_SelectionMgr( this );
157 myAccel = new SUIT_Accel( desktop() );
158 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
159 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
160 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
161 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
162 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
163 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, SVTK_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, SVTK_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, SVTK_Viewer::Type() );
172 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, SVTK_Viewer::Type() );
173 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, SVTK_Viewer::Type() );
174 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, SVTK_Viewer::Type() );
175 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, SVTK_Viewer::Type() );
176 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, SVTK_Viewer::Type() );
177 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, SVTK_Viewer::Type() );
178 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, SVTK_Viewer::Type() );
179 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, SVTK_Viewer::Type() );
181 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
185 *\li Save window geometry.
186 *\li Save desktop geometry.
187 *\li Save resource maneger.
188 *\li Delete selection manager.
189 *\li Destroy event filter.
191 SalomeApp_Application::~SalomeApp_Application()
193 saveWindowsGeometry();
198 desktop()->saveGeometry( resourceMgr(), "desktop" );
199 resourceMgr()->save();
204 SalomeApp_EventFilter::Destroy();
207 /*!Start application.*/
208 void SalomeApp_Application::start()
211 desktop()->loadGeometry( resourceMgr(), "desktop" );
213 CAM_Application::start();
215 QAction* a = action( ViewWindowsId );
216 if ( a && a->inherits( "QtxDockAction" ) )
217 ((QtxDockAction*)a)->setAutoPlace( true );
219 SalomeApp_EventFilter::Init();
222 updateViewManagers();
227 /*!Gets application name.*/
228 QString SalomeApp_Application::applicationName() const
230 return tr( "APP_NAME" );
233 /*!Gets application version.*/
234 QString SalomeApp_Application::applicationVersion() const
236 static QString _app_version;
238 if ( _app_version.isEmpty() )
240 QString resVersion = tr( "APP_VERSION" );
241 if ( resVersion != "APP_VERSION" )
243 _app_version = resVersion;
247 QString path( ::getenv( "GUI_ROOT_DIR" ) );
248 if ( !path.isEmpty() )
249 path += QDir::separator();
250 path += QString( "bin/salome/VERSION" );
253 if ( vf.open( IO_ReadOnly ) )
256 vf.readLine( line, 1024 );
259 if ( !line.isEmpty() )
261 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
262 line.remove( line.length() - 1, 1 );
264 int idx = line.findRev( ":" );
266 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
274 /*!Load module by \a name.*/
275 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
277 CAM_Module* mod = CAM_Application::loadModule( name );
280 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
281 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
282 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
287 /*!Activate module by \a modName*/
288 bool SalomeApp_Application::activateModule( const QString& modName )
291 CAM_Module* prevMod = activeModule();
294 actName = prevMod->moduleName();
296 if ( actName == modName )
299 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
301 saveWindowsGeometry();
303 bool status = CAM_Application::activateModule( modName );
305 updateModuleActions();
313 updateViewManagers();
318 /*!Gets selection manager.*/
319 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
325 void SalomeApp_Application::createActions()
327 STD_Application::createActions();
329 SUIT_Desktop* desk = desktop();
330 SUIT_ResourceMgr* resMgr = resourceMgr();
333 createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
334 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
335 0, desk, false, this, SLOT( onDumpStudy() ) );
338 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
339 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
340 0, desk, false, this, SLOT( onLoadScript() ) );
343 createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
344 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
345 0, desk, false, this, SLOT( onProperties() ) );
348 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
349 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
350 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
352 //! Catalog Generator
353 createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIconSet(),
354 tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ),
355 0, desk, false, this, SLOT( onCatalogGen() ) );
358 createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIconSet(),
359 tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ),
360 0, desk, false, this, SLOT( onRegDisplay() ) );
363 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
364 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
365 registerAction( MRUId, mru );
367 //! default icon for neutral point ('SALOME' module)
368 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
369 if ( defIcon.isNull() )
370 defIcon = QPixmap( imageEmptyIcon );
372 //! default icon for any module
373 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
374 if ( modIcon.isNull() )
375 modIcon = QPixmap( imageEmptyIcon );
377 QToolBar* modTBar = new QtxToolBar( true, desk );
378 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
380 QActionGroup* modGroup = new QActionGroup( this );
381 modGroup->setExclusive( true );
382 modGroup->setUsesDropDown( true );
384 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
385 tr( "PRP_APP_MODULE" ), 0, desk, true );
387 myActions.insert( QString(), a );
389 QMap<QString, QString> iconMap;
390 moduleIconNames( iconMap );
392 const int iconSize = 20;
394 modGroup->addTo( modTBar );
395 modTBar->addSeparator();
398 modules( modList, false );
400 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
402 if ( (*it).isEmpty() )
406 if ( iconMap.contains( *it ) )
407 iconName = iconMap[*it];
409 QString modName = moduleName( *it );
411 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
415 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
417 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
421 myActions.insert( *it, a );
424 SUIT_Tools::simplifySeparators( modTBar );
428 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
429 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
430 createMenu( separator(), windowMenu, -1, 1 );
432 QMap<int, int> accelMap;
433 accelMap[NewGLViewId] = ALT+Key_G;
434 accelMap[NewPlot2dId] = ALT+Key_P;
435 accelMap[NewOCCViewId] = ALT+Key_O;
436 accelMap[NewVTKViewId] = ALT+Key_K;
438 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
440 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
441 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
442 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
443 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
444 createMenu( a, newWinMenu, -1 );
446 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
448 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
450 createMenu( DumpStudyId, fileMenu, 10, -1 );
451 createMenu( separator(), fileMenu, -1, 15, -1 );
452 createMenu( LoadScriptId, fileMenu, 10, -1 );
453 createMenu( separator(), fileMenu, -1, 15, -1 );
454 createMenu( PropertiesId, fileMenu, 10, -1 );
455 createMenu( separator(), fileMenu, -1, 15, -1 );
456 createMenu( PreferencesId, fileMenu, 15, -1 );
457 createMenu( separator(), fileMenu, -1, 15, -1 );
459 int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, -1, 50 );
460 createMenu( CatalogGenId, toolsMenu, 10, -1 );
461 createMenu( RegDisplayId, toolsMenu, 10, -1 );
462 createMenu( separator(), toolsMenu, -1, 15, -1 );
465 createMenu( separator(), fileMenu, -1, 100, -1 );
466 createMenu( MRUId, fileMenu, 100, -1 );
467 createMenu( separator(), fileMenu, -1, 100, -1 );
471 /*!On module activation action.*/
472 void SalomeApp_Application::onModuleActivation( QAction* a )
477 QString modName = a->menuText();
478 if ( modName == tr( "APP_NAME" ) )
479 modName = QString::null;
481 // Force user to create/open a study before module activation
482 QMap<QString, QString> iconMap;
483 moduleIconNames( iconMap );
484 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
486 icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
488 bool cancelled = false;
489 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
490 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
491 int res = aDlg.exec();
505 putInfo( tr("INF_CANCELLED") );
506 myActions[QString()]->setOn( true );
512 activateModule( modName );
515 /*!Default module activation.*/
516 QString SalomeApp_Application::defaultModule() const
518 QStringList aModuleNames;
519 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
520 //! If there's the one and only module --> activate it automatically
521 //! TODO: Possible improvement - default module can be taken from preferences
522 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
525 /*!On new window slot.*/
526 void SalomeApp_Application::onNewWindow()
528 const QObject* obj = sender();
529 if ( !obj || !obj->inherits( "QAction" ) )
533 int id = actionId( (QAction*)obj );
537 type = GLViewer_Viewer::Type();
540 type = Plot2d_Viewer::Type();
543 type = OCCViewer_Viewer::Type();
546 type = SVTK_Viewer::Type();
550 if ( !type.isEmpty() )
551 createViewManager( type );
554 //=======================================================================
556 /*! Purpose : SLOT. Create new document*/
557 //=======================================================================
558 void SalomeApp_Application::onNewDoc()
560 SUIT_Study* study = activeStudy();
562 saveWindowsGeometry();
564 CAM_Application::onNewDoc();
566 if ( !study ) // new study will be create in THIS application
569 updateViewManagers();
573 //=======================================================================
575 /*! Purpose : SLOT. Open new document*/
576 //=======================================================================
577 void SalomeApp_Application::onOpenDoc()
579 SUIT_Study* study = activeStudy();
580 saveWindowsGeometry();
582 CAM_Application::onOpenDoc();
584 if ( !study ) // new study will be create in THIS application
587 updateViewManagers();
591 /*! Purpose : SLOT. Open new document with \a aName.*/
592 bool SalomeApp_Application::onOpenDoc( const QString& aName )
594 bool res = CAM_Application::onOpenDoc( aName );
596 QAction* a = action( MRUId );
597 if ( a && a->inherits( "QtxMRUAction" ) )
599 QtxMRUAction* mru = (QtxMRUAction*)a;
601 mru->insert( aName );
603 mru->remove( aName );
608 /*!SLOT. Load document.*/
609 void SalomeApp_Application::onLoadDoc()
611 QString name, studyname, ext;
613 STD_LoadStudiesDlg aDlg( desktop(), TRUE);
615 std::vector<std::string> List = studyMgr()->GetOpenStudies();
617 SUIT_Session* aSession = SUIT_Session::session();
618 QPtrList<SUIT_Application> aAppList = aSession->applications();
619 SUIT_Application* aApp = 0;
621 for (unsigned int ind = 0; ind < List.size(); ind++) {
622 studyname = List[ind].c_str();
623 //Add to list only unloaded studies
624 bool isAlreadyOpen = false;
625 for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
628 if(!aApp || !aApp->activeStudy()) continue;
629 if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
632 if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
635 int retVal = aDlg.exec();
636 studyname = aDlg.ListComponent->currentText();
638 if (retVal == QDialog::Rejected)
641 if ( studyname.isNull() || studyname.isEmpty() )
645 name.replace( QRegExp(":"), "/" );
647 if(onLoadDoc(name)) {
649 updateViewManagers();
650 updateObjectBrowser(true);
655 /*!SLOT. Load document with \a aName.*/
656 bool SalomeApp_Application::onLoadDoc( const QString& aName )
658 bool res = CAM_Application::onLoadDoc( aName );
660 /*jfa tmp:QAction* a = action( MRUId );
661 if ( a && a->inherits( "QtxMRUAction" ) )
663 QtxMRUAction* mru = (QtxMRUAction*)a;
665 mru->insert( aName );
667 mru->remove( aName );
672 /*!Private SLOT. Selection.*/
673 void SalomeApp_Application::onSelection()
675 onSelectionChanged();
677 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
678 ((SalomeApp_Module*)activeModule())->selectionChanged();
681 /*!SLOT. Copy objects to study maneger from selection maneger..*/
682 void SalomeApp_Application::onCopy()
685 SalomeApp_SelectionMgr* mgr = selectionMgr();
686 mgr->selectedObjects(list);
688 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
689 if(study == NULL) return;
691 _PTR(Study) stdDS = study->studyDS();
694 SALOME_ListIteratorOfListIO it( list );
697 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
699 studyMgr()->Copy(so);
700 onSelectionChanged();
707 /*!SLOT. Paste objects to study maneger from selection manager.*/
708 void SalomeApp_Application::onPaste()
711 SalomeApp_SelectionMgr* mgr = selectionMgr();
712 mgr->selectedObjects(list);
714 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
715 if(study == NULL) return;
717 _PTR(Study) stdDS = study->studyDS();
720 SALOME_ListIteratorOfListIO it( list );
723 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
725 studyMgr()->Paste(so);
726 updateObjectBrowser( true );
727 updateActions(); //SRN: BugID IPAL9377, case 3
734 /*!Sets enable or disable some actions on selection changed.*/
735 void SalomeApp_Application::onSelectionChanged()
738 SalomeApp_SelectionMgr* mgr = selectionMgr();
739 mgr->selectedObjects(list);
741 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
742 if(study == NULL) return;
744 _PTR(Study) stdDS = study->studyDS();
749 SALOME_ListIteratorOfListIO it( list );
750 if(it.More() && list.Extent() == 1)
752 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
754 qaction = action(EditCopyId);
755 if( so && studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
756 else qaction->setEnabled(false);
758 qaction = action(EditPasteId);
759 if( so && studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
760 else qaction->setEnabled(false);
763 qaction = action(EditCopyId);
764 qaction->setEnabled(false);
765 qaction = action(EditPasteId);
766 qaction->setEnabled(false);
770 /*!Update object browser.*/
771 void SalomeApp_Application::onRefresh()
773 updateObjectBrowser( true );
776 /*!Delete references.*/
777 void SalomeApp_Application::onDeleteReferences()
780 SalomeApp_SelectionMgr* mgr = selectionMgr();
781 mgr->selectedObjects(aList);
783 if (aList.Extent() < 1) return;
785 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
786 _PTR(Study) aStudyDS = aStudy->studyDS();
787 _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder();
790 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
792 if ( it.Value()->hasEntry() )
794 _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
795 if ( aSObject->ReferencedObject(anObj) )
796 aStudyBuilder->RemoveReference(aSObject);
800 updateObjectBrowser();
804 void SalomeApp_Application::onOpenWith()
806 QApplication::setOverrideCursor( Qt::waitCursor );
808 SalomeApp_SelectionMgr* mgr = selectionMgr();
809 mgr->selectedObjects(aList);
810 if (aList.Extent() != 1)
812 QApplication::restoreOverrideCursor();
815 Handle(SALOME_InteractiveObject) aIObj = aList.First();
816 QString aModuleName(aIObj->getComponentDataType());
817 QString aModuleTitle = moduleTitle(aModuleName);
818 activateModule(aModuleTitle);
819 QApplication::restoreOverrideCursor();
822 bool SalomeApp_Application::useStudy(const QString& theName)
825 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
828 res = aStudy->loadDocument( theName );
829 updateDesktopTitle();
830 updateCommandsStatus();
835 *\param study - SUIT_Study.
837 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
839 CAM_Application::setActiveStudy( study );
844 //=======================================================================
845 // name : createNewStudy
846 /*! Purpose : Create new study*/
847 //=======================================================================
848 SUIT_Study* SalomeApp_Application::createNewStudy()
850 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
852 // Set up processing of major study-related events
853 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
854 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
855 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
856 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
861 //=======================================================================
862 // name : createNewStudy
863 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
864 //=======================================================================
865 void SalomeApp_Application::updateCommandsStatus()
867 CAM_Application::updateCommandsStatus();
869 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
871 QAction* a = action( id );
873 a->setEnabled( activeStudy() );
877 QAction* a = action( DumpStudyId );
879 a->setEnabled( activeStudy() );
882 a = action( LoadScriptId );
884 a->setEnabled( activeStudy() );
886 a = action( PropertiesId );
888 a->setEnabled( activeStudy() );
890 a = action(EditCopyId);
891 a->setEnabled(false);
892 a = action(EditPasteId);
893 a->setEnabled(false);
896 //=======================================================================
897 // name : onHelpAbout
898 /*! Purpose : SLOT. Display "About" message box*/
899 //=======================================================================
900 void SalomeApp_Application::onHelpAbout()
902 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
907 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
914 if ( !activeStudy() )
917 sId = activeStudy()->id();
920 if ( myWindows.contains( flag ) )
921 wid = myWindows[flag]->widget( sId );
926 /*!Adds window to application.
927 *\param wid - QWidget
928 *\param flag - key wor window
929 *\param studyId - study id
930 * Flag used how identificator of window in windows list.
932 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
940 if ( !activeStudy() )
943 sId = activeStudy()->id();
946 if ( !myWindows.contains( flag ) )
948 QMap<int, int> winMap;
949 currentWindows( winMap );
951 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
952 if ( winMap.contains( flag ) )
953 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
955 myWindows[flag]->setResizeEnabled( true );
956 myWindows[flag]->setCloseMode( QDockWindow::Always );
957 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
961 if( wid->inherits( "PythonConsole" ) )
962 f = ( ( PythonConsole* )wid )->font();
966 myWindows[flag]->insert( sId, wid );
969 setWindowShown( flag, !myWindows[flag]->isEmpty() );
972 /*!Remove window from application.
973 *\param flag - key wor window
974 *\param studyId - study id
975 * Flag used how identificator of window in windows list.
977 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
979 if ( !myWindows.contains( flag ) )
985 if ( !activeStudy() )
988 sId = activeStudy()->id();
991 QWidget* wid = myWindows[flag]->widget( sId );
992 myWindows[flag]->remove( sId );
995 setWindowShown( flag, !myWindows[flag]->isEmpty() );
999 *\param flag - key wor window
1000 *\param studyId - study id
1001 * Flag used how identificator of window in windows list.
1003 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
1005 QWidget* wid = window( flag, studyId );
1007 addWindow( wid = createWindow( flag ), flag, studyId );
1012 /*!Check is window visible?(with identificator \a type)*/
1013 bool SalomeApp_Application::isWindowVisible( const int type ) const
1016 if ( myWindows.contains( type ) )
1018 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
1019 res = desk && desk->appropriate( myWindows[type] );
1024 /*!Sets window show or hide.
1025 *\param type - window identificator.
1026 *\param on - true/false (window show/hide)
1028 void SalomeApp_Application::setWindowShown( const int type, const bool on )
1030 if ( !desktop() || !myWindows.contains( type ) )
1033 QDockWindow* dw = myWindows[type];
1034 desktop()->setAppropriate( dw, on );
1035 on ? dw->show() : dw->hide();
1038 OB_Browser* SalomeApp_Application::objectBrowser()
1041 QWidget* wid = getWindow( WT_ObjectBrowser );
1042 if ( wid->inherits( "OB_Browser" ) )
1043 ob = (OB_Browser*)wid;
1047 /*!Gets "LogWindow".*/
1048 LogWindow* SalomeApp_Application::logWindow()
1051 QWidget* wid = getWindow( WT_LogWindow );
1052 if ( wid->inherits( "LogWindow" ) )
1053 lw = (LogWindow*)wid;
1057 /*!Get "PythonConsole"*/
1058 PythonConsole* SalomeApp_Application::pythonConsole()
1060 PythonConsole* console = 0;
1061 QWidget* wid = getWindow( WT_PyConsole );
1062 if ( wid->inherits( "PythonConsole" ) )
1063 console = (PythonConsole*)wid;
1067 /*!Gets preferences.*/
1068 SalomeApp_Preferences* SalomeApp_Application::preferences() const
1070 return preferences( false );
1073 /*!Gets view manager*/
1074 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
1076 SUIT_ViewManager* aVM = viewManager( vmType );
1077 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1079 if ( anActiveVM && anActiveVM->getType() == vmType )
1082 if ( aVM && create )
1084 if ( !aVM->getActiveView() )
1087 aVM->getActiveView()->setFocus();
1090 aVM = createViewManager( vmType );
1095 /*!Create view manager.*/
1096 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
1098 SUIT_ResourceMgr* resMgr = resourceMgr();
1100 SUIT_ViewManager* viewMgr = 0;
1101 if ( vmType == GLViewer_Viewer::Type() )
1103 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1104 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1106 else if ( vmType == Plot2d_Viewer::Type() )
1108 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1109 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
1111 else if ( vmType == OCCViewer_Viewer::Type() )
1113 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1114 SOCC_Viewer* vm = new SOCC_Viewer();
1115 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1116 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1119 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1120 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1121 vm->setIsos( u, v );
1122 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1123 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1125 else if ( vmType == SVTK_Viewer::Type() )
1127 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1128 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1131 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1132 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1133 new SalomeApp_VTKSelector( vm, mySelMgr );
1140 addViewManager( viewMgr );
1141 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1143 if ( viewWin && desktop() )
1144 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1146 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1147 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1152 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1154 removeViewManager( theVM );
1157 /*!Private SLOT. On study created.*/
1158 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1160 SUIT_DataObject* aRoot = 0;
1161 if ( theStudy && theStudy->root() )
1163 aRoot = theStudy->root();
1164 //aRoot->setName( tr( "DATA_MODELS" ) );
1166 if ( objectBrowser() != 0 )
1167 objectBrowser()->setRootObject( aRoot );
1169 activateModule( defaultModule() );
1174 /*!Private SLOT. On study opened.*/
1175 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1177 SUIT_DataObject* aRoot = 0;
1178 if ( theStudy && theStudy->root() )
1180 aRoot = theStudy->root();
1183 if ( objectBrowser() != 0 ) {
1184 objectBrowser()->setRootObject( aRoot );
1187 activateModule( defaultModule() );
1194 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1199 /*!Private SLOT. On study closed.*/
1200 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1204 activateModule( "" );
1206 saveWindowsGeometry();
1209 /*!Private SLOT. On dump study.*/
1210 void SalomeApp_Application::onDumpStudy( )
1212 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1213 if ( !appStudy ) return;
1214 _PTR(Study) aStudy = appStudy->studyDS();
1216 QStringList aFilters;
1217 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1219 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1220 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1221 fd->setFilters( aFilters );
1222 fd->SetChecked(true);
1224 QString aFileName = fd->selectedFile();
1225 bool toPublish = fd->IsChecked();
1228 if(!aFileName.isEmpty()) {
1229 QFileInfo aFileInfo(aFileName);
1230 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1234 /*!Private SLOT. On load script.*/
1235 void SalomeApp_Application::onLoadScript( )
1237 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1238 if ( !appStudy ) return;
1239 _PTR(Study) aStudy = appStudy->studyDS();
1241 if ( aStudy->GetProperties()->IsLocked() ) {
1242 SUIT_MessageBox::warn1 ( desktop(),
1243 QObject::tr("WRN_WARNING"),
1244 QObject::tr("WRN_STUDY_LOCKED"),
1245 QObject::tr("BUT_OK") );
1249 QStringList filtersList;
1250 filtersList.append(tr("PYTHON_FILES_FILTER"));
1251 filtersList.append(tr("ALL_FILES_FILTER"));
1253 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1255 if ( !aFile.isEmpty() )
1257 QString command = QString("execfile(\"%1\")").arg(aFile);
1259 PythonConsole* pyConsole = pythonConsole();
1262 pyConsole->exec( command );
1266 /*!Private SLOT. On preferences.*/
1267 void SalomeApp_Application::onPreferences()
1269 QApplication::setOverrideCursor( Qt::waitCursor );
1271 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1273 QApplication::restoreOverrideCursor();
1283 /*!Private SLOT. On open document with name \a aName.*/
1284 void SalomeApp_Application::onMRUActivated( QString aName )
1289 /*!Private SLOT. On preferences changed.*/
1290 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1292 SalomeApp_Module* sMod = 0;
1293 CAM_Module* mod = module( modName );
1294 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1295 sMod = (SalomeApp_Module*)mod;
1298 sMod->preferencesChanged( section, param );
1300 preferencesChanged( section, param );
1303 /*!Gets file filter.
1304 *\retval QString "(*.hdf)"
1306 QString SalomeApp_Application::getFileFilter() const
1311 /*!Remove all windows from study.*/
1312 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1314 CAM_Application::beforeCloseDoc( s );
1316 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1317 removeWindow( itr.key(), s->id() );
1320 /*!Update actions.*/
1321 void SalomeApp_Application::updateActions()
1323 updateCommandsStatus();
1327 QWidget* SalomeApp_Application::createWindow( const int flag )
1331 SUIT_ResourceMgr* resMgr = resourceMgr();
1333 if ( flag == WT_ObjectBrowser )
1335 OB_Browser* ob = new OB_Browser( desktop() );
1336 ob->setAutoUpdate( true );
1337 ob->setAutoOpenLevel( 1 );
1338 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1339 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1340 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1342 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1344 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1345 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1347 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1348 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1349 QString().sprintf( "visibility_column_%d", i ), true ) );
1351 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1353 // Create OBSelector
1354 new SalomeApp_OBSelector( ob, mySelMgr );
1358 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1360 else if ( flag == WT_PyConsole )
1362 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1363 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1364 pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1367 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1369 else if ( flag == WT_LogWindow )
1371 LogWindow* logWin = new LogWindow( desktop() );
1372 logWin->setCaption( tr( "LOG_WINDOW" ) );
1375 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1381 /*!Default windows(Object Browser, Python Console).
1382 * Adds to map \a aMap.
1384 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1386 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1387 aMap.insert( WT_PyConsole, Qt::DockBottom );
1388 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1391 /*!Default view manager.*/
1392 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1397 /*!Gets preferences.
1398 * Create preferences, if \a crt = true.
1400 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1405 SalomeApp_Application* that = (SalomeApp_Application*)this;
1407 if ( !_prefs_ && crt )
1409 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1410 that->createPreferences( _prefs_ );
1413 that->myPrefs = _prefs_;
1415 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1416 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1418 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1421 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1423 QStringList modNameList;
1424 app->modules( modNameList, false );
1425 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1427 int id = _prefs_->addPreference( *it );
1428 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1432 app->modules( modList );
1433 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1435 SalomeApp_Module* mod = 0;
1436 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1437 mod = (SalomeApp_Module*)itr.current();
1439 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1441 int modCat = _prefs_->addPreference( mod->moduleName() );
1442 _prefs_->setItemProperty( modCat, "info", QString::null );
1443 mod->createPreferences();
1448 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1449 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1454 /*!Add new module to application.*/
1455 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1457 CAM_Application::moduleAdded( mod );
1459 SalomeApp_Module* salomeMod = 0;
1460 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1461 salomeMod = (SalomeApp_Module*)mod;
1463 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1465 int modCat = myPrefs->addPreference( mod->moduleName() );
1466 myPrefs->setItemProperty( modCat, "info", QString::null );
1467 salomeMod->createPreferences();
1471 /*!Create preferences.*/
1472 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1477 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1479 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1480 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1481 pref->setItemProperty( studyGroup, "columns", 1 );
1483 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1484 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1485 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1486 pref->setItemProperty( undoPref, "min", 1 );
1487 pref->setItemProperty( undoPref, "max", 100 );
1489 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1490 pref->setItemProperty( extgroup, "columns", 1 );
1491 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1492 pref->setItemProperty( apppref, "existing", true );
1493 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1495 pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1497 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1498 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1499 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1503 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1504 int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1505 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1507 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1508 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1510 pref->setItemProperty( defCols, "columns", 1 );
1512 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1513 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1515 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1517 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1519 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1521 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1523 pref->setItemProperty( occGroup, "columns", 1 );
1524 pref->setItemProperty( vtkGroup, "columns", 1 );
1525 pref->setItemProperty( plot2dGroup, "columns", 1 );
1527 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1528 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1529 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1530 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1532 pref->setItemProperty( occTS, "min", 1 );
1533 pref->setItemProperty( occTS, "max", 150 );
1535 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1536 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1537 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1538 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1540 pref->setItemProperty( isoU, "min", 0 );
1541 pref->setItemProperty( isoU, "max", 100000 );
1543 pref->setItemProperty( isoV, "min", 0 );
1544 pref->setItemProperty( isoV, "max", 100000 );
1546 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1547 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1548 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1549 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1551 pref->setItemProperty( vtkTS, "min", 1 );
1552 pref->setItemProperty( vtkTS, "max", 150 );
1554 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1555 SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1557 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1558 SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" );
1559 QStringList aLegendPosList;
1560 aLegendPosList.append( tr("PREF_LEFT") );
1561 aLegendPosList.append( tr("PREF_RIGHT") );
1562 aLegendPosList.append( tr("PREF_TOP") );
1563 aLegendPosList.append( tr("PREF_BOTTOM") );
1565 QValueList<QVariant> anIndexesList;
1566 anIndexesList.append(0);
1567 anIndexesList.append(1);
1568 anIndexesList.append(2);
1569 anIndexesList.append(3);
1571 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1572 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1574 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1575 SalomeApp_Preferences::Selector, "Plot2d", "CurveType" );
1576 QStringList aCurveTypesList;
1577 aCurveTypesList.append( tr("PREF_POINTS") );
1578 aCurveTypesList.append( tr("PREF_LINES") );
1579 aCurveTypesList.append( tr("PREF_SPLINE") );
1581 anIndexesList.clear();
1582 anIndexesList.append(0);
1583 anIndexesList.append(1);
1584 anIndexesList.append(2);
1586 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1587 pref->setItemProperty( curveType, "indexes", anIndexesList );
1589 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1590 SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1592 pref->setItemProperty( markerSize, "min", 0 );
1593 pref->setItemProperty( markerSize, "max", 100 );
1595 QStringList aScaleModesList;
1596 aScaleModesList.append( tr("PREF_LINEAR") );
1597 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1599 anIndexesList.clear();
1600 anIndexesList.append(0);
1601 anIndexesList.append(1);
1603 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1604 SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1606 pref->setItemProperty( horScale, "strings", aScaleModesList );
1607 pref->setItemProperty( horScale, "indexes", anIndexesList );
1609 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1610 SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1612 pref->setItemProperty( verScale, "strings", aScaleModesList );
1613 pref->setItemProperty( verScale, "indexes", anIndexesList );
1615 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1616 SalomeApp_Preferences::Color, "Plot2d", "Background" );
1618 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1619 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1620 pref->setItemProperty( dirGroup, "columns", 1 );
1621 pref->addPreference( tr( "" ), dirGroup,
1622 SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1625 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1627 SUIT_ResourceMgr* resMgr = resourceMgr();
1631 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1633 int sz = resMgr->integerValue( sec, param, -1 );
1634 QPtrList<SUIT_ViewManager> lst;
1635 viewManagers( OCCViewer_Viewer::Type(), lst );
1636 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1638 SUIT_ViewModel* vm = it.current()->getViewModel();
1639 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1642 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1643 occVM->setTrihedronSize( sz );
1644 occVM->getAISContext()->UpdateCurrentViewer();
1648 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1650 int sz = resMgr->integerValue( sec, param, -1 );
1651 QPtrList<SUIT_ViewManager> lst;
1652 viewManagers( SVTK_Viewer::Type(), lst );
1653 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1655 SUIT_ViewModel* vm = it.current()->getViewModel();
1656 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1659 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1662 vtkVM->setTrihedronSize( sz );
1668 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1670 QPtrList<SUIT_ViewManager> lst;
1671 viewManagers( OCCViewer_Viewer::Type(), lst );
1672 int u = resMgr->integerValue( sec, "iso_number_u" );
1673 int v = resMgr->integerValue( sec, "iso_number_v" );
1674 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1675 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1678 if( sec=="ObjectBrowser" )
1680 if( param=="auto_size" )
1682 OB_Browser* ob = objectBrowser();
1686 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1687 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1689 updateObjectBrowser( false );
1693 if( sec=="PyConsole" )
1696 if( pythonConsole() )
1697 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1701 /*!Update desktop title.*/
1702 void SalomeApp_Application::updateDesktopTitle() {
1703 QString aTitle = applicationName();
1704 QString aVer = applicationVersion();
1705 if ( !aVer.isEmpty() )
1706 aTitle += QString( " " ) + aVer;
1708 if ( activeStudy() )
1710 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1711 if ( !sName.isEmpty() ) {
1712 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1713 _PTR(Study) stdDS = study->studyDS();
1715 if ( stdDS->GetProperties()->IsLocked() ) {
1716 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1718 aTitle += QString( " - [%1]" ).arg( sName );
1724 desktop()->setCaption( aTitle );
1727 /*!Update windows after close document.*/
1728 void SalomeApp_Application::afterCloseDoc()
1732 CAM_Application::afterCloseDoc();
1735 /*!Gets CORBA::ORB_var*/
1736 CORBA::ORB_var SalomeApp_Application::orb()
1738 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1739 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1743 /*!Create and return SALOMEDS_StudyManager.*/
1744 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1746 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1750 /*!Create and return SALOME_NamingService.*/
1751 SALOME_NamingService* SalomeApp_Application::namingService()
1753 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1757 /*!Create and return SALOME_LifeCycleCORBA.*/
1758 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1760 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1764 QString SalomeApp_Application::defaultEngineIOR()
1766 /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1767 QString anIOR( "" );
1768 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1769 if ( !CORBA::is_nil( anEngine ) )
1770 anIOR = orb()->object_to_string( anEngine );
1774 /*!Adds icon names for modules.*/
1775 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1779 SUIT_ResourceMgr* resMgr = resourceMgr();
1783 QStringList modList;
1784 modules( modList, false );
1786 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1788 QString modName = *it;
1789 QString modIntr = moduleName( modName );
1790 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1792 if ( modIcon.isEmpty() )
1795 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1796 modIcon += QString( ".png" );
1798 iconMap.insert( modName, modIcon );
1802 /*!Update module action.*/
1803 void SalomeApp_Application::updateModuleActions()
1806 if ( activeModule() )
1807 modName = activeModule()->moduleName();
1809 if ( myActions.contains( modName ) )
1810 myActions[modName]->setOn( true );
1813 /*!Gets current windows.
1814 *\param winMap - output current windows map.
1816 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1819 if ( !activeStudy() )
1822 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1823 ((SalomeApp_Module*)activeModule())->windows( winMap );
1825 defaultWindows( winMap );
1828 /*!Gets current view managers.
1829 *\param lst - output current view managers list.
1831 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1834 if ( !activeStudy() )
1837 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1838 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1840 defaultViewManagers( lst );
1843 /*!Update windows.*/
1844 void SalomeApp_Application::updateWindows()
1846 QMap<int, int> winMap;
1847 currentWindows( winMap );
1849 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1850 getWindow( it.key() );
1852 loadWindowsGeometry();
1854 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1855 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1858 /*!Update view managers.*/
1859 void SalomeApp_Application::updateViewManagers()
1862 currentViewManagers( lst );
1864 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1865 getViewManager( *it, true );
1868 /*!Load windows geometry.*/
1869 void SalomeApp_Application::loadWindowsGeometry()
1871 QtxDockAction* dockMgr = 0;
1873 QAction* a = action( ViewWindowsId );
1874 if ( a && a->inherits( "QtxDockAction" ) )
1875 dockMgr = (QtxDockAction*)a;
1881 if ( activeModule() )
1882 modName = activeModule()->name("");
1884 QString section = QString( "windows_geometry" );
1885 if ( !modName.isEmpty() )
1886 section += QString( "." ) + modName;
1888 dockMgr->loadGeometry( resourceMgr(), section, false );
1889 dockMgr->restoreGeometry();
1892 /*!Save windows geometry.*/
1893 void SalomeApp_Application::saveWindowsGeometry()
1895 QtxDockAction* dockMgr = 0;
1897 QAction* a = action( ViewWindowsId );
1898 if ( a && a->inherits( "QtxDockAction" ) )
1899 dockMgr = (QtxDockAction*)a;
1905 if ( activeModule() )
1906 modName = activeModule()->name("");
1908 QString section = QString( "windows_geometry" );
1909 if ( !modName.isEmpty() )
1910 section += QString( "." ) + modName;
1912 dockMgr->storeGeometry();
1913 dockMgr->saveGeometry( resourceMgr(), section, false );
1916 /*!Activate windows.*/
1917 void SalomeApp_Application::activateWindows()
1919 if ( activeStudy() )
1921 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1922 itr.data()->activate( activeStudy()->id() );
1926 /*!Private SLOT. On preferences.*/
1927 void SalomeApp_Application::onProperties()
1929 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1933 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1936 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1937 int res = aDlg.exec();
1938 if( res==QDialog::Accepted && aDlg.isChanged() )
1939 SB->CommitCommand();
1943 //study->updateCaptions();
1944 updateDesktopTitle();
1949 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1950 const QString& caption, QWidget* parent )
1954 QStringList fls = QStringList::split( ";;", filters, false );
1955 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1959 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1963 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1967 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1968 const QString& caption, QWidget* parent )
1972 QStringList fls = QStringList::split( ";;", filters, false );
1973 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1977 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1979 CAM_Application::contextMenuPopup( type, thePopup, title );
1981 OB_Browser* ob = objectBrowser();
1982 if ( !ob || type != ob->popupClientType() )
1985 thePopup->insertSeparator();
1986 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1988 // Get selected objects
1989 SALOME_ListIO aList;
1990 SalomeApp_SelectionMgr* mgr = selectionMgr();
1991 mgr->selectedObjects(aList);
1993 // "Delete reference" item should appear only for invalid references
1995 // Check if selected objects is invalid references
1996 bool isInvalidRefs = true;
1998 if ( aList.Extent() < 1 )
1999 isInvalidRefs = false;
2001 if ( isInvalidRefs )
2003 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
2004 _PTR(Study) aStudyDS = aStudy->studyDS();
2005 _PTR(SObject) anObj;
2007 for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() )
2009 if ( it.Value()->hasEntry() )
2011 _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
2012 if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() )
2013 isInvalidRefs = false;
2018 // Add "Delete refrence" item to popup
2019 if ( isInvalidRefs )
2021 thePopup->insertSeparator();
2022 thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) );
2026 // "Activate module" item should appear only if it's necessary
2027 if (aList.Extent() != 1)
2029 Handle(SALOME_InteractiveObject) aIObj = aList.First();
2030 QString aModuleName(aIObj->getComponentDataType());
2031 QString aModuleTitle = moduleTitle(aModuleName);
2032 CAM_Module* currentModule = activeModule();
2033 if (currentModule && currentModule->moduleName() == aModuleTitle)
2035 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
2039 /*!Update obect browser*/
2040 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
2042 // update existing data models (already loaded SComponents)
2045 for ( ModuleListIterator it = modules(); it.current(); ++it )
2047 CAM_DataModel* camDM = it.current()->dataModel();
2048 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
2049 ((SalomeApp_DataModel*)camDM)->update();
2052 // update "non-existing" (not loaded yet) data models
2053 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
2056 _PTR(Study) stdDS = study->studyDS();
2059 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
2061 _PTR(SComponent) aComponent ( it->Value() );
2063 if ( aComponent->ComponentDataType() == "Interface Applicative" )
2064 continue; // skip the magic "Interface Applicative" component
2066 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
2071 if ( objectBrowser() )
2073 objectBrowser()->updateGeometry();
2074 objectBrowser()->updateTree();
2078 /*!Protected SLOT.On desktop activated.*/
2079 void SalomeApp_Application::onDesktopActivated()
2081 CAM_Application::onDesktopActivated();
2082 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
2084 aModule->studyActivated();
2087 /*!Create empty study.*/
2088 void SalomeApp_Application::createEmptyStudy()
2090 CAM_Application::createEmptyStudy();
2091 if ( objectBrowser() )
2092 objectBrowser()->updateTree();
2095 /*!Activate module \a mod.*/
2096 bool SalomeApp_Application::activateModule( CAM_Module* mod )
2098 bool res = CAM_Application::activateModule( mod );
2099 if ( objectBrowser() )
2100 objectBrowser()->updateTree();
2104 /*!Display Catalog Genenerator dialog */
2105 void SalomeApp_Application::onCatalogGen()
2107 ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
2111 /*!Display Registry Display dialog */
2112 void SalomeApp_Application::onRegDisplay()
2114 CORBA::ORB_var anOrb = orb();
2115 ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
2118 regWnd->setActiveWindow();
2121 /*!return keyborad accelerators manager object */
2122 SUIT_Accel* SalomeApp_Application::accel() const