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 );
150 mySelMgr = new SalomeApp_SelectionMgr( this );
152 myAccel = new SUIT_Accel( desktop() );
153 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
154 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
155 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
156 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
157 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
158 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
159 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
160 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
161 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
162 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
163 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
172 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
173 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
174 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() );
176 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
177 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
179 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
183 *\li Save window geometry.
184 *\li Save desktop geometry.
185 *\li Save resource maneger.
186 *\li Delete selection manager.
187 *\li Destroy event filter.
189 SalomeApp_Application::~SalomeApp_Application()
191 saveWindowsGeometry();
196 desktop()->saveGeometry( resourceMgr(), "desktop" );
197 resourceMgr()->save();
202 SalomeApp_EventFilter::Destroy();
205 /*!Start application.*/
206 void SalomeApp_Application::start()
209 desktop()->loadGeometry( resourceMgr(), "desktop" );
211 CAM_Application::start();
213 QAction* a = action( ViewWindowsId );
214 if ( a && a->inherits( "QtxDockAction" ) )
215 ((QtxDockAction*)a)->setAutoPlace( true );
217 SalomeApp_EventFilter::Init();
220 updateViewManagers();
225 /*!Gets application name.*/
226 QString SalomeApp_Application::applicationName() const
228 return tr( "APP_NAME" );
231 /*!Gets application version.*/
232 QString SalomeApp_Application::applicationVersion() const
234 static QString _app_version;
236 if ( _app_version.isEmpty() )
238 QString path( ::getenv( "GUI_ROOT_DIR" ) );
239 if ( !path.isEmpty() )
240 path += QDir::separator();
241 path += QString( "bin/salome/VERSION" );
244 if ( vf.open( IO_ReadOnly ) )
247 vf.readLine( line, 1024 );
250 if ( !line.isEmpty() )
252 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
253 line.remove( line.length() - 1, 1 );
255 int idx = line.findRev( ":" );
257 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
265 /*!Load module by \a name.*/
266 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
268 CAM_Module* mod = CAM_Application::loadModule( name );
271 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
272 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
273 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
278 /*!Activate module by \a modName*/
279 bool SalomeApp_Application::activateModule( const QString& modName )
282 CAM_Module* prevMod = activeModule();
285 actName = prevMod->moduleName();
287 if ( actName == modName )
290 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
292 saveWindowsGeometry();
294 bool status = CAM_Application::activateModule( modName );
296 updateModuleActions();
304 updateViewManagers();
309 /*!Gets selection manager.*/
310 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
316 void SalomeApp_Application::createActions()
318 STD_Application::createActions();
320 SUIT_Desktop* desk = desktop();
321 SUIT_ResourceMgr* resMgr = resourceMgr();
324 createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
325 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
326 0, desk, false, this, SLOT( onDumpStudy() ) );
329 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
330 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
331 0, desk, false, this, SLOT( onLoadScript() ) );
334 createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
335 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
336 0, desk, false, this, SLOT( onProperties() ) );
339 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
340 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
341 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
343 //! Catalog Generator
344 createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIconSet(),
345 tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ),
346 0, desk, false, this, SLOT( onCatalogGen() ) );
349 createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIconSet(),
350 tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ),
351 0, desk, false, this, SLOT( onRegDisplay() ) );
354 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
355 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
356 registerAction( MRUId, mru );
358 //! default icon for neutral point ('SALOME' module)
359 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
360 if ( defIcon.isNull() )
361 defIcon = QPixmap( imageEmptyIcon );
363 //! default icon for any module
364 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
365 if ( modIcon.isNull() )
366 modIcon = QPixmap( imageEmptyIcon );
368 QToolBar* modTBar = new QtxToolBar( true, desk );
369 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
371 QActionGroup* modGroup = new QActionGroup( this );
372 modGroup->setExclusive( true );
373 modGroup->setUsesDropDown( true );
375 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
376 tr( "PRP_APP_MODULE" ), 0, desk, true );
378 myActions.insert( QString(), a );
380 QMap<QString, QString> iconMap;
381 moduleIconNames( iconMap );
383 const int iconSize = 20;
385 modGroup->addTo( modTBar );
386 modTBar->addSeparator();
389 modules( modList, false );
391 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
393 if ( (*it).isEmpty() )
397 if ( iconMap.contains( *it ) )
398 iconName = iconMap[*it];
400 QString modName = moduleName( *it );
402 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
406 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
408 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
412 myActions.insert( *it, a );
415 SUIT_Tools::simplifySeparators( modTBar );
419 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
420 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
421 createMenu( separator(), windowMenu, -1, 1 );
423 QMap<int, int> accelMap;
424 accelMap[NewGLViewId] = ALT+Key_G;
425 accelMap[NewPlot2dId] = ALT+Key_P;
426 accelMap[NewOCCViewId] = ALT+Key_O;
427 accelMap[NewVTKViewId] = ALT+Key_K;
429 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
431 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
432 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
433 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
434 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
435 createMenu( a, newWinMenu, -1 );
437 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
439 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
441 createMenu( DumpStudyId, fileMenu, 10, -1 );
442 createMenu( separator(), fileMenu, -1, 15, -1 );
443 createMenu( LoadScriptId, fileMenu, 10, -1 );
444 createMenu( separator(), fileMenu, -1, 15, -1 );
445 createMenu( PropertiesId, fileMenu, 10, -1 );
446 createMenu( separator(), fileMenu, -1, 15, -1 );
447 createMenu( PreferencesId, fileMenu, 15, -1 );
448 createMenu( separator(), fileMenu, -1, 15, -1 );
450 int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, -1, 50 );
451 createMenu( CatalogGenId, toolsMenu, 10, -1 );
452 createMenu( RegDisplayId, toolsMenu, 10, -1 );
453 createMenu( separator(), toolsMenu, -1, 15, -1 );
456 createMenu( separator(), fileMenu, -1, 100, -1 );
457 createMenu( MRUId, fileMenu, 100, -1 );
458 createMenu( separator(), fileMenu, -1, 100, -1 );
462 /*!On module activation action.*/
463 void SalomeApp_Application::onModuleActivation( QAction* a )
468 QString modName = a->menuText();
469 if ( modName == tr( "APP_NAME" ) )
470 modName = QString::null;
472 // Force user to create/open a study before module activation
473 QMap<QString, QString> iconMap;
474 moduleIconNames( iconMap );
475 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
477 icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
479 bool cancelled = false;
480 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
481 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
482 int res = aDlg.exec();
496 putInfo( tr("INF_CANCELLED") );
497 myActions[QString()]->setOn( true );
503 activateModule( modName );
506 /*!Default module activation.*/
507 QString SalomeApp_Application::defaultModule() const
509 QStringList aModuleNames;
510 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
511 //! If there's the one and only module --> activate it automatically
512 //! TODO: Possible improvement - default module can be taken from preferences
513 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
516 /*!On new window slot.*/
517 void SalomeApp_Application::onNewWindow()
519 const QObject* obj = sender();
520 if ( !obj || !obj->inherits( "QAction" ) )
524 int id = actionId( (QAction*)obj );
528 type = GLViewer_Viewer::Type();
531 type = Plot2d_Viewer::Type();
534 type = OCCViewer_Viewer::Type();
537 type = VTKViewer_Viewer::Type();
541 if ( !type.isEmpty() )
542 createViewManager( type );
545 //=======================================================================
547 /*! Purpose : SLOT. Create new document*/
548 //=======================================================================
549 void SalomeApp_Application::onNewDoc()
551 SUIT_Study* study = activeStudy();
553 saveWindowsGeometry();
555 CAM_Application::onNewDoc();
557 if ( !study ) // new study will be create in THIS application
560 updateViewManagers();
564 //=======================================================================
566 /*! Purpose : SLOT. Open new document*/
567 //=======================================================================
568 void SalomeApp_Application::onOpenDoc()
570 SUIT_Study* study = activeStudy();
571 saveWindowsGeometry();
573 CAM_Application::onOpenDoc();
575 if ( !study ) // new study will be create in THIS application
578 updateViewManagers();
582 /*! Purpose : SLOT. Open new document with \a aName.*/
583 bool SalomeApp_Application::onOpenDoc( const QString& aName )
585 bool res = CAM_Application::onOpenDoc( aName );
587 QAction* a = action( MRUId );
588 if ( a && a->inherits( "QtxMRUAction" ) )
590 QtxMRUAction* mru = (QtxMRUAction*)a;
592 mru->insert( aName );
594 mru->remove( aName );
599 /*!SLOT. Load document.*/
600 void SalomeApp_Application::onLoadDoc()
602 QString name, studyname, ext;
604 STD_LoadStudiesDlg aDlg( desktop(), TRUE);
606 std::vector<std::string> List = studyMgr()->GetOpenStudies();
608 SUIT_Session* aSession = SUIT_Session::session();
609 QPtrList<SUIT_Application> aAppList = aSession->applications();
610 SUIT_Application* aApp = 0;
612 for (unsigned int ind = 0; ind < List.size(); ind++) {
613 studyname = List[ind].c_str();
614 //Add to list only unloaded studies
615 bool isAlreadyOpen = false;
616 for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
619 if(!aApp || !aApp->activeStudy()) continue;
620 if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
623 if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
626 int retVal = aDlg.exec();
627 studyname = aDlg.ListComponent->currentText();
629 if (retVal == QDialog::Rejected)
632 if ( studyname.isNull() || studyname.isEmpty() )
636 name.replace( QRegExp(":"), "/" );
638 if(onLoadDoc(name)) {
640 updateViewManagers();
641 updateObjectBrowser(true);
646 /*!SLOT. Load document with \a aName.*/
647 bool SalomeApp_Application::onLoadDoc( const QString& aName )
649 bool res = CAM_Application::onLoadDoc( aName );
651 /*jfa tmp:QAction* a = action( MRUId );
652 if ( a && a->inherits( "QtxMRUAction" ) )
654 QtxMRUAction* mru = (QtxMRUAction*)a;
656 mru->insert( aName );
658 mru->remove( aName );
663 /*!Private SLOT. Selection.*/
664 void SalomeApp_Application::onSelection()
666 onSelectionChanged();
668 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
669 ((SalomeApp_Module*)activeModule())->selectionChanged();
672 /*!SLOT. Copy objects to study maneger from selection maneger..*/
673 void SalomeApp_Application::onCopy()
676 SalomeApp_SelectionMgr* mgr = selectionMgr();
677 mgr->selectedObjects(list);
679 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
680 if(study == NULL) return;
682 _PTR(Study) stdDS = study->studyDS();
685 SALOME_ListIteratorOfListIO it( list );
688 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
690 studyMgr()->Copy(so);
691 onSelectionChanged();
698 /*!SLOT. Paste objects to study maneger from selection manager.*/
699 void SalomeApp_Application::onPaste()
702 SalomeApp_SelectionMgr* mgr = selectionMgr();
703 mgr->selectedObjects(list);
705 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
706 if(study == NULL) return;
708 _PTR(Study) stdDS = study->studyDS();
711 SALOME_ListIteratorOfListIO it( list );
714 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
716 studyMgr()->Paste(so);
717 updateObjectBrowser( true );
718 updateActions(); //SRN: BugID IPAL9377, case 3
725 /*!Sets enable or disable some actions on selection changed.*/
726 void SalomeApp_Application::onSelectionChanged()
729 SalomeApp_SelectionMgr* mgr = selectionMgr();
730 mgr->selectedObjects(list);
732 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
733 if(study == NULL) return;
735 _PTR(Study) stdDS = study->studyDS();
740 SALOME_ListIteratorOfListIO it( list );
741 if(it.More() && list.Extent() == 1)
743 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
745 qaction = action(EditCopyId);
746 if(studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
747 else qaction->setEnabled(false);
749 qaction = action(EditPasteId);
750 if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
751 else qaction->setEnabled(false);
754 qaction = action(EditCopyId);
755 qaction->setEnabled(false);
756 qaction = action(EditPasteId);
757 qaction->setEnabled(false);
761 /*!Update object browser.*/
762 void SalomeApp_Application::onRefresh()
764 updateObjectBrowser( true );
767 /*!Delete references.*/
768 void SalomeApp_Application::onDeleteReferences()
771 SalomeApp_SelectionMgr* mgr = selectionMgr();
772 mgr->selectedObjects(aList);
774 if (aList.Extent() < 1) return;
776 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
777 _PTR(Study) aStudyDS = aStudy->studyDS();
778 _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder();
781 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
783 if ( it.Value()->hasEntry() )
785 _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
786 if ( aSObject->ReferencedObject(anObj) )
787 aStudyBuilder->RemoveReference(aSObject);
791 updateObjectBrowser();
795 void SalomeApp_Application::onOpenWith()
797 QApplication::setOverrideCursor( Qt::waitCursor );
799 SalomeApp_SelectionMgr* mgr = selectionMgr();
800 mgr->selectedObjects(aList);
801 if (aList.Extent() != 1)
803 QApplication::restoreOverrideCursor();
806 Handle(SALOME_InteractiveObject) aIObj = aList.First();
807 QString aModuleName(aIObj->getComponentDataType());
808 QString aModuleTitle = moduleTitle(aModuleName);
809 activateModule(aModuleTitle);
810 QApplication::restoreOverrideCursor();
813 bool SalomeApp_Application::useStudy(const QString& theName)
816 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
819 res = aStudy->loadDocument( theName );
820 updateDesktopTitle();
821 updateCommandsStatus();
826 *\param study - SUIT_Study.
828 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
830 CAM_Application::setActiveStudy( study );
835 //=======================================================================
836 // name : createNewStudy
837 /*! Purpose : Create new study*/
838 //=======================================================================
839 SUIT_Study* SalomeApp_Application::createNewStudy()
841 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
843 // Set up processing of major study-related events
844 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
845 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
846 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
847 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
852 //=======================================================================
853 // name : createNewStudy
854 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
855 //=======================================================================
856 void SalomeApp_Application::updateCommandsStatus()
858 CAM_Application::updateCommandsStatus();
860 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
862 QAction* a = action( id );
864 a->setEnabled( activeStudy() );
868 QAction* a = action( DumpStudyId );
870 a->setEnabled( activeStudy() );
873 a = action( LoadScriptId );
875 a->setEnabled( activeStudy() );
877 a = action( PropertiesId );
879 a->setEnabled( activeStudy() );
881 a = action(EditCopyId);
882 a->setEnabled(false);
883 a = action(EditPasteId);
884 a->setEnabled(false);
887 //=======================================================================
888 // name : onHelpAbout
889 /*! Purpose : SLOT. Display "About" message box*/
890 //=======================================================================
891 void SalomeApp_Application::onHelpAbout()
893 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
898 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
905 if ( !activeStudy() )
908 sId = activeStudy()->id();
911 if ( myWindows.contains( flag ) )
912 wid = myWindows[flag]->widget( sId );
917 /*!Adds window to application.
918 *\param wid - QWidget
919 *\param flag - key wor window
920 *\param studyId - study id
921 * Flag used how identificator of window in windows list.
923 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
931 if ( !activeStudy() )
934 sId = activeStudy()->id();
937 if ( !myWindows.contains( flag ) )
939 QMap<int, int> winMap;
940 currentWindows( winMap );
942 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
943 if ( winMap.contains( flag ) )
944 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
946 myWindows[flag]->setResizeEnabled( true );
947 myWindows[flag]->setCloseMode( QDockWindow::Always );
948 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
952 if( wid->inherits( "PythonConsole" ) )
953 f = ( ( PythonConsole* )wid )->font();
957 myWindows[flag]->insert( sId, wid );
960 setWindowShown( flag, !myWindows[flag]->isEmpty() );
963 /*!Remove window from application.
964 *\param flag - key wor window
965 *\param studyId - study id
966 * Flag used how identificator of window in windows list.
968 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
970 if ( !myWindows.contains( flag ) )
976 if ( !activeStudy() )
979 sId = activeStudy()->id();
982 QWidget* wid = myWindows[flag]->widget( sId );
983 myWindows[flag]->remove( sId );
986 setWindowShown( flag, !myWindows[flag]->isEmpty() );
990 *\param flag - key wor window
991 *\param studyId - study id
992 * Flag used how identificator of window in windows list.
994 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
996 QWidget* wid = window( flag, studyId );
998 addWindow( wid = createWindow( flag ), flag, studyId );
1003 /*!Check is window visible?(with identificator \a type)*/
1004 bool SalomeApp_Application::isWindowVisible( const int type ) const
1007 if ( myWindows.contains( type ) )
1009 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
1010 res = desk && desk->appropriate( myWindows[type] );
1015 /*!Sets window show or hide.
1016 *\param type - window identificator.
1017 *\param on - true/false (window show/hide)
1019 void SalomeApp_Application::setWindowShown( const int type, const bool on )
1021 if ( !desktop() || !myWindows.contains( type ) )
1024 QDockWindow* dw = myWindows[type];
1025 desktop()->setAppropriate( dw, on );
1026 on ? dw->show() : dw->hide();
1029 OB_Browser* SalomeApp_Application::objectBrowser()
1032 QWidget* wid = getWindow( WT_ObjectBrowser );
1033 if ( wid->inherits( "OB_Browser" ) )
1034 ob = (OB_Browser*)wid;
1038 /*!Gets "LogWindow".*/
1039 LogWindow* SalomeApp_Application::logWindow()
1042 QWidget* wid = getWindow( WT_LogWindow );
1043 if ( wid->inherits( "LogWindow" ) )
1044 lw = (LogWindow*)wid;
1048 /*!Get "PythonConsole"*/
1049 PythonConsole* SalomeApp_Application::pythonConsole()
1051 PythonConsole* console = 0;
1052 QWidget* wid = getWindow( WT_PyConsole );
1053 if ( wid->inherits( "PythonConsole" ) )
1054 console = (PythonConsole*)wid;
1058 /*!Gets preferences.*/
1059 SalomeApp_Preferences* SalomeApp_Application::preferences() const
1061 return preferences( false );
1064 /*!Gets view manager*/
1065 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
1067 SUIT_ViewManager* aVM = viewManager( vmType );
1068 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1070 if ( anActiveVM && anActiveVM->getType() == vmType )
1073 if ( aVM && create )
1075 if ( !aVM->getActiveView() )
1078 aVM->getActiveView()->setFocus();
1081 aVM = createViewManager( vmType );
1086 /*!Create view manager.*/
1087 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
1089 SUIT_ResourceMgr* resMgr = resourceMgr();
1091 SUIT_ViewManager* viewMgr = 0;
1092 if ( vmType == GLViewer_Viewer::Type() )
1094 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1095 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1097 else if ( vmType == Plot2d_Viewer::Type() )
1099 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1100 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
1102 else if ( vmType == OCCViewer_Viewer::Type() )
1104 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1105 SOCC_Viewer* vm = new SOCC_Viewer();
1106 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1107 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1110 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1111 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1112 vm->setIsos( u, v );
1113 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1114 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1116 else if ( vmType == SVTK_Viewer::Type() )
1118 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1119 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
1120 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1121 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1122 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
1128 addViewManager( viewMgr );
1129 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1131 if ( viewWin && desktop() )
1132 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1134 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1135 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1140 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1142 removeViewManager( theVM );
1145 /*!Private SLOT. On study created.*/
1146 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1148 SUIT_DataObject* aRoot = 0;
1149 if ( theStudy && theStudy->root() )
1151 aRoot = theStudy->root();
1152 //aRoot->setName( tr( "DATA_MODELS" ) );
1154 if ( objectBrowser() != 0 )
1155 objectBrowser()->setRootObject( aRoot );
1157 activateModule( defaultModule() );
1162 /*!Private SLOT. On study opened.*/
1163 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1165 SUIT_DataObject* aRoot = 0;
1166 if ( theStudy && theStudy->root() )
1168 aRoot = theStudy->root();
1171 if ( objectBrowser() != 0 ) {
1172 objectBrowser()->setRootObject( aRoot );
1175 activateModule( defaultModule() );
1182 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1187 /*!Private SLOT. On study closed.*/
1188 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1192 activateModule( "" );
1194 saveWindowsGeometry();
1197 /*!Private SLOT. On dump study.*/
1198 void SalomeApp_Application::onDumpStudy( )
1200 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1201 if ( !appStudy ) return;
1202 _PTR(Study) aStudy = appStudy->studyDS();
1204 QStringList aFilters;
1205 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1207 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1208 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1209 fd->setFilters( aFilters );
1210 fd->SetChecked(true);
1212 QString aFileName = fd->selectedFile();
1213 bool toPublish = fd->IsChecked();
1216 if(!aFileName.isEmpty()) {
1217 QFileInfo aFileInfo(aFileName);
1218 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1222 /*!Private SLOT. On load script.*/
1223 void SalomeApp_Application::onLoadScript( )
1225 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1226 if ( !appStudy ) return;
1227 _PTR(Study) aStudy = appStudy->studyDS();
1229 if ( aStudy->GetProperties()->IsLocked() ) {
1230 SUIT_MessageBox::warn1 ( desktop(),
1231 QObject::tr("WRN_WARNING"),
1232 QObject::tr("WRN_STUDY_LOCKED"),
1233 QObject::tr("BUT_OK") );
1237 QStringList filtersList;
1238 filtersList.append(tr("PYTHON_FILES_FILTER"));
1239 filtersList.append(tr("ALL_FILES_FILTER"));
1241 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1243 if ( !aFile.isEmpty() )
1245 QString command = QString("execfile(\"%1\")").arg(aFile);
1247 PythonConsole* pyConsole = pythonConsole();
1250 pyConsole->exec( command );
1254 /*!Private SLOT. On preferences.*/
1255 void SalomeApp_Application::onPreferences()
1257 QApplication::setOverrideCursor( Qt::waitCursor );
1259 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1261 QApplication::restoreOverrideCursor();
1271 /*!Private SLOT. On open document with name \a aName.*/
1272 void SalomeApp_Application::onMRUActivated( QString aName )
1277 /*!Private SLOT. On preferences changed.*/
1278 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1280 SalomeApp_Module* sMod = 0;
1281 CAM_Module* mod = module( modName );
1282 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1283 sMod = (SalomeApp_Module*)mod;
1286 sMod->preferencesChanged( section, param );
1288 preferencesChanged( section, param );
1291 /*!Gets file filter.
1292 *\retval QString "(*.hdf)"
1294 QString SalomeApp_Application::getFileFilter() const
1299 /*!Remove all windows from study.*/
1300 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1302 CAM_Application::beforeCloseDoc( s );
1304 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1305 removeWindow( itr.key(), s->id() );
1308 /*!Update actions.*/
1309 void SalomeApp_Application::updateActions()
1311 updateCommandsStatus();
1315 QWidget* SalomeApp_Application::createWindow( const int flag )
1319 SUIT_ResourceMgr* resMgr = resourceMgr();
1321 if ( flag == WT_ObjectBrowser )
1323 OB_Browser* ob = new OB_Browser( desktop() );
1324 ob->setAutoUpdate( true );
1325 ob->setAutoOpenLevel( 1 );
1326 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1327 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1328 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1330 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1332 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1333 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1335 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1336 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1337 QString().sprintf( "visibility_column_%d", i ), true ) );
1339 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1341 // Create OBSelector
1342 new SalomeApp_OBSelector( ob, mySelMgr );
1346 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1348 else if ( flag == WT_PyConsole )
1350 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1351 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1352 pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1355 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1357 else if ( flag == WT_LogWindow )
1359 LogWindow* logWin = new LogWindow( desktop() );
1360 logWin->setCaption( tr( "LOG_WINDOW" ) );
1363 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1369 /*!Default windows(Object Browser, Python Console).
1370 * Adds to map \a aMap.
1372 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1374 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1375 aMap.insert( WT_PyConsole, Qt::DockBottom );
1376 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1379 /*!Default view manager.*/
1380 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1385 /*!Gets preferences.
1386 * Create preferences, if \a crt = true.
1388 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1393 SalomeApp_Application* that = (SalomeApp_Application*)this;
1395 if ( !_prefs_ && crt )
1397 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1398 that->createPreferences( _prefs_ );
1401 that->myPrefs = _prefs_;
1403 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1404 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1406 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1409 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1411 QStringList modNameList;
1412 app->modules( modNameList, false );
1413 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1415 int id = _prefs_->addPreference( *it );
1416 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1420 app->modules( modList );
1421 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1423 SalomeApp_Module* mod = 0;
1424 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1425 mod = (SalomeApp_Module*)itr.current();
1427 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1429 int modCat = _prefs_->addPreference( mod->moduleName() );
1430 _prefs_->setItemProperty( modCat, "info", QString::null );
1431 mod->createPreferences();
1436 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1437 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1442 /*!Add new module to application.*/
1443 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1445 CAM_Application::moduleAdded( mod );
1447 SalomeApp_Module* salomeMod = 0;
1448 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1449 salomeMod = (SalomeApp_Module*)mod;
1451 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1453 int modCat = myPrefs->addPreference( mod->moduleName() );
1454 myPrefs->setItemProperty( modCat, "info", QString::null );
1455 salomeMod->createPreferences();
1459 /*!Create preferences.*/
1460 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1465 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1467 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1468 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1469 pref->setItemProperty( studyGroup, "columns", 1 );
1471 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1472 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1473 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1474 pref->setItemProperty( undoPref, "min", 1 );
1475 pref->setItemProperty( undoPref, "max", 100 );
1477 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1478 pref->setItemProperty( extgroup, "columns", 1 );
1479 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1480 pref->setItemProperty( apppref, "existing", true );
1481 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1483 pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1485 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1486 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1487 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1491 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1492 int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1493 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1495 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1496 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1498 pref->setItemProperty( defCols, "columns", 1 );
1500 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1501 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1503 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1505 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1507 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1509 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1511 pref->setItemProperty( occGroup, "columns", 1 );
1512 pref->setItemProperty( vtkGroup, "columns", 1 );
1513 pref->setItemProperty( plot2dGroup, "columns", 1 );
1515 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1516 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1517 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1518 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1520 pref->setItemProperty( occTS, "min", 1 );
1521 pref->setItemProperty( occTS, "max", 150 );
1523 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1524 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1525 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1526 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1528 pref->setItemProperty( isoU, "min", 0 );
1529 pref->setItemProperty( isoU, "max", 100000 );
1531 pref->setItemProperty( isoV, "min", 0 );
1532 pref->setItemProperty( isoV, "max", 100000 );
1534 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1535 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1536 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1537 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1539 pref->setItemProperty( vtkTS, "min", 1 );
1540 pref->setItemProperty( vtkTS, "max", 150 );
1542 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1543 SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1545 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1546 SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" );
1547 QStringList aLegendPosList;
1548 aLegendPosList.append( tr("PREF_LEFT") );
1549 aLegendPosList.append( tr("PREF_RIGHT") );
1550 aLegendPosList.append( tr("PREF_TOP") );
1551 aLegendPosList.append( tr("PREF_BOTTOM") );
1553 QValueList<QVariant> anIndexesList;
1554 anIndexesList.append(0);
1555 anIndexesList.append(1);
1556 anIndexesList.append(2);
1557 anIndexesList.append(3);
1559 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1560 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1562 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1563 SalomeApp_Preferences::Selector, "Plot2d", "CurveType" );
1564 QStringList aCurveTypesList;
1565 aCurveTypesList.append( tr("PREF_POINTS") );
1566 aCurveTypesList.append( tr("PREF_LINES") );
1567 aCurveTypesList.append( tr("PREF_SPLINE") );
1569 anIndexesList.clear();
1570 anIndexesList.append(0);
1571 anIndexesList.append(1);
1572 anIndexesList.append(2);
1574 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1575 pref->setItemProperty( curveType, "indexes", anIndexesList );
1577 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1578 SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1580 pref->setItemProperty( markerSize, "min", 0 );
1581 pref->setItemProperty( markerSize, "max", 100 );
1583 QStringList aScaleModesList;
1584 aScaleModesList.append( tr("PREF_LINEAR") );
1585 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1587 anIndexesList.clear();
1588 anIndexesList.append(0);
1589 anIndexesList.append(1);
1591 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1592 SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1594 pref->setItemProperty( horScale, "strings", aScaleModesList );
1595 pref->setItemProperty( horScale, "indexes", anIndexesList );
1597 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1598 SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1600 pref->setItemProperty( verScale, "strings", aScaleModesList );
1601 pref->setItemProperty( verScale, "indexes", anIndexesList );
1603 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1604 SalomeApp_Preferences::Color, "Plot2d", "Background" );
1606 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1607 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1608 pref->setItemProperty( dirGroup, "columns", 1 );
1609 pref->addPreference( tr( "" ), dirGroup,
1610 SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1613 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1615 SUIT_ResourceMgr* resMgr = resourceMgr();
1619 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1621 int sz = resMgr->integerValue( sec, param, -1 );
1622 QPtrList<SUIT_ViewManager> lst;
1623 viewManagers( OCCViewer_Viewer::Type(), lst );
1624 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1626 SUIT_ViewModel* vm = it.current()->getViewModel();
1627 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1630 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1631 occVM->setTrihedronSize( sz );
1632 occVM->getAISContext()->UpdateCurrentViewer();
1636 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1638 int sz = resMgr->integerValue( sec, param, -1 );
1639 QPtrList<SUIT_ViewManager> lst;
1640 viewManagers( SVTK_Viewer::Type(), lst );
1641 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1643 SUIT_ViewModel* vm = it.current()->getViewModel();
1644 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1647 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1648 vtkVM->setTrihedronSize( sz );
1653 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1655 QPtrList<SUIT_ViewManager> lst;
1656 viewManagers( OCCViewer_Viewer::Type(), lst );
1657 int u = resMgr->integerValue( sec, "iso_number_u" );
1658 int v = resMgr->integerValue( sec, "iso_number_v" );
1659 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1660 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1663 if( sec=="ObjectBrowser" )
1665 if( param=="auto_size" )
1667 OB_Browser* ob = objectBrowser();
1671 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1672 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1674 updateObjectBrowser( false );
1678 if( sec=="PyConsole" )
1681 if( pythonConsole() )
1682 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1686 /*!Update desktop title.*/
1687 void SalomeApp_Application::updateDesktopTitle() {
1688 QString aTitle = applicationName();
1689 QString aVer = applicationVersion();
1690 if ( !aVer.isEmpty() )
1691 aTitle += QString( " " ) + aVer;
1693 if ( activeStudy() )
1695 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1696 if ( !sName.isEmpty() ) {
1697 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1698 _PTR(Study) stdDS = study->studyDS();
1700 if ( stdDS->GetProperties()->IsLocked() ) {
1701 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1703 aTitle += QString( " - [%1]" ).arg( sName );
1709 desktop()->setCaption( aTitle );
1712 /*!Update windows after close document.*/
1713 void SalomeApp_Application::afterCloseDoc()
1717 CAM_Application::afterCloseDoc();
1720 /*!Gets CORBA::ORB_var*/
1721 CORBA::ORB_var SalomeApp_Application::orb()
1723 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1724 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1728 /*!Create and return SALOMEDS_StudyManager.*/
1729 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1731 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1735 /*!Create and return SALOME_NamingService.*/
1736 SALOME_NamingService* SalomeApp_Application::namingService()
1738 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1742 /*!Create and return SALOME_LifeCycleCORBA.*/
1743 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1745 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1749 QString SalomeApp_Application::defaultEngineIOR()
1751 /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1752 QString anIOR( "" );
1753 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1754 if ( !CORBA::is_nil( anEngine ) )
1755 anIOR = orb()->object_to_string( anEngine );
1759 /*!Adds icon names for modules.*/
1760 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1764 SUIT_ResourceMgr* resMgr = resourceMgr();
1768 QStringList modList;
1769 modules( modList, false );
1771 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1773 QString modName = *it;
1774 QString modIntr = moduleName( modName );
1775 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1777 if ( modIcon.isEmpty() )
1780 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1781 modIcon += QString( ".png" );
1783 iconMap.insert( modName, modIcon );
1787 /*!Update module action.*/
1788 void SalomeApp_Application::updateModuleActions()
1791 if ( activeModule() )
1792 modName = activeModule()->moduleName();
1794 if ( myActions.contains( modName ) )
1795 myActions[modName]->setOn( true );
1798 /*!Gets current windows.
1799 *\param winMap - output current windows map.
1801 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1804 if ( !activeStudy() )
1807 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1808 ((SalomeApp_Module*)activeModule())->windows( winMap );
1810 defaultWindows( winMap );
1813 /*!Gets current view managers.
1814 *\param lst - output current view managers list.
1816 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1819 if ( !activeStudy() )
1822 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1823 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1825 defaultViewManagers( lst );
1828 /*!Update windows.*/
1829 void SalomeApp_Application::updateWindows()
1831 QMap<int, int> winMap;
1832 currentWindows( winMap );
1834 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1835 getWindow( it.key() );
1837 loadWindowsGeometry();
1839 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1840 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1843 /*!Update view managers.*/
1844 void SalomeApp_Application::updateViewManagers()
1847 currentViewManagers( lst );
1849 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1850 getViewManager( *it, true );
1853 /*!Load windows geometry.*/
1854 void SalomeApp_Application::loadWindowsGeometry()
1856 QtxDockAction* dockMgr = 0;
1858 QAction* a = action( ViewWindowsId );
1859 if ( a && a->inherits( "QtxDockAction" ) )
1860 dockMgr = (QtxDockAction*)a;
1866 if ( activeModule() )
1867 modName = moduleLibrary( activeModule()->moduleName(), false );
1869 QString section = QString( "windows_geometry" );
1870 if ( !modName.isEmpty() )
1871 section += QString( "." ) + modName;
1873 dockMgr->loadGeometry( resourceMgr(), section, false );
1874 dockMgr->restoreGeometry();
1877 /*!Save windows geometry.*/
1878 void SalomeApp_Application::saveWindowsGeometry()
1880 QtxDockAction* dockMgr = 0;
1882 QAction* a = action( ViewWindowsId );
1883 if ( a && a->inherits( "QtxDockAction" ) )
1884 dockMgr = (QtxDockAction*)a;
1890 if ( activeModule() )
1891 modName = moduleLibrary( activeModule()->moduleName(), false );
1893 QString section = QString( "windows_geometry" );
1894 if ( !modName.isEmpty() )
1895 section += QString( "." ) + modName;
1897 dockMgr->storeGeometry();
1898 dockMgr->saveGeometry( resourceMgr(), section, false );
1901 /*!Activate windows.*/
1902 void SalomeApp_Application::activateWindows()
1904 if ( activeStudy() )
1906 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1907 itr.data()->activate( activeStudy()->id() );
1911 /*!Private SLOT. On preferences.*/
1912 void SalomeApp_Application::onProperties()
1914 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1918 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1921 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1922 int res = aDlg.exec();
1923 if( res==QDialog::Accepted && aDlg.isChanged() )
1924 SB->CommitCommand();
1928 //study->updateCaptions();
1929 updateDesktopTitle();
1933 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1934 const QString& caption, QWidget* parent )
1938 QStringList fls = QStringList::split( ";;", filters, false );
1939 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1943 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1947 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1951 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1952 const QString& caption, QWidget* parent )
1956 QStringList fls = QStringList::split( ";;", filters, false );
1957 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1961 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1963 CAM_Application::contextMenuPopup( type, thePopup, title );
1965 OB_Browser* ob = objectBrowser();
1966 if ( !ob || type != ob->popupClientType() )
1969 thePopup->insertSeparator();
1970 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1972 // Get selected objects
1973 SALOME_ListIO aList;
1974 SalomeApp_SelectionMgr* mgr = selectionMgr();
1975 mgr->selectedObjects(aList);
1977 // "Delete reference" item should appear only for invalid references
1979 // Check if selected objects is invalid references
1980 bool isInvalidRefs = true;
1982 if ( aList.Extent() < 1 )
1983 isInvalidRefs = false;
1985 if ( isInvalidRefs )
1987 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
1988 _PTR(Study) aStudyDS = aStudy->studyDS();
1989 _PTR(SObject) anObj;
1991 for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() )
1993 if ( it.Value()->hasEntry() )
1995 _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
1996 if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() )
1997 isInvalidRefs = false;
2002 // Add "Delete refrence" item to popup
2003 if ( isInvalidRefs )
2005 thePopup->insertSeparator();
2006 thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) );
2010 // "Activate module" item should appear only if it's necessary
2011 if (aList.Extent() != 1)
2013 Handle(SALOME_InteractiveObject) aIObj = aList.First();
2014 QString aModuleName(aIObj->getComponentDataType());
2015 QString aModuleTitle = moduleTitle(aModuleName);
2016 CAM_Module* currentModule = activeModule();
2017 if (currentModule && currentModule->moduleName() == aModuleTitle)
2019 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
2023 /*!Update obect browser*/
2024 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
2026 // update existing data models (already loaded SComponents)
2029 for ( ModuleListIterator it = modules(); it.current(); ++it )
2031 CAM_DataModel* camDM = it.current()->dataModel();
2032 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
2033 ((SalomeApp_DataModel*)camDM)->update();
2036 // update "non-existing" (not loaded yet) data models
2037 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
2040 _PTR(Study) stdDS = study->studyDS();
2043 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
2045 _PTR(SComponent) aComponent ( it->Value() );
2047 if ( aComponent->ComponentDataType() == "Interface Applicative" )
2048 continue; // skip the magic "Interface Applicative" component
2050 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
2055 if ( objectBrowser() )
2057 objectBrowser()->updateGeometry();
2058 objectBrowser()->updateTree();
2062 /*!Protected SLOT.On desktop activated.*/
2063 void SalomeApp_Application::onDesktopActivated()
2065 CAM_Application::onDesktopActivated();
2066 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
2068 aModule->studyActivated();
2071 /*!Create empty study.*/
2072 void SalomeApp_Application::createEmptyStudy()
2074 CAM_Application::createEmptyStudy();
2075 if ( objectBrowser() )
2076 objectBrowser()->updateTree();
2079 /*!Activate module \a mod.*/
2080 bool SalomeApp_Application::activateModule( CAM_Module* mod )
2082 bool res = CAM_Application::activateModule( mod );
2083 if ( objectBrowser() )
2084 objectBrowser()->updateTree();
2088 /*!Display Catalog Genenerator dialog */
2089 void SalomeApp_Application::onCatalogGen()
2091 ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
2095 /*!Display Registry Display dialog */
2096 void SalomeApp_Application::onRegDisplay()
2098 CORBA::ORB_var anOrb = orb();
2099 ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
2102 regWnd->setActiveWindow();
2105 /*!return keyborad accelerators manager object */
2106 SUIT_Accel* SalomeApp_Application::accel() const