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 );
768 void SalomeApp_Application::onOpenWith()
770 QApplication::setOverrideCursor( Qt::waitCursor );
772 SalomeApp_SelectionMgr* mgr = selectionMgr();
773 mgr->selectedObjects(aList);
774 if (aList.Extent() != 1)
776 QApplication::restoreOverrideCursor();
779 Handle(SALOME_InteractiveObject) aIObj = aList.First();
780 QString aModuleName(aIObj->getComponentDataType());
781 QString aModuleTitle = moduleTitle(aModuleName);
782 activateModule(aModuleTitle);
783 QApplication::restoreOverrideCursor();
786 bool SalomeApp_Application::useStudy(const QString& theName)
789 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
792 res = aStudy->loadDocument( theName );
793 updateDesktopTitle();
794 updateCommandsStatus();
799 *\param study - SUIT_Study.
801 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
803 CAM_Application::setActiveStudy( study );
808 //=======================================================================
809 // name : createNewStudy
810 /*! Purpose : Create new study*/
811 //=======================================================================
812 SUIT_Study* SalomeApp_Application::createNewStudy()
814 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
816 // Set up processing of major study-related events
817 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
818 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
819 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
820 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
825 //=======================================================================
826 // name : createNewStudy
827 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
828 //=======================================================================
829 void SalomeApp_Application::updateCommandsStatus()
831 CAM_Application::updateCommandsStatus();
833 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
835 QAction* a = action( id );
837 a->setEnabled( activeStudy() );
841 QAction* a = action( DumpStudyId );
843 a->setEnabled( activeStudy() );
846 a = action( LoadScriptId );
848 a->setEnabled( activeStudy() );
850 a = action( PropertiesId );
852 a->setEnabled( activeStudy() );
854 a = action(EditCopyId);
855 a->setEnabled(false);
856 a = action(EditPasteId);
857 a->setEnabled(false);
860 //=======================================================================
861 // name : onHelpAbout
862 /*! Purpose : SLOT. Display "About" message box*/
863 //=======================================================================
864 void SalomeApp_Application::onHelpAbout()
866 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
871 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
878 if ( !activeStudy() )
881 sId = activeStudy()->id();
884 if ( myWindows.contains( flag ) )
885 wid = myWindows[flag]->widget( sId );
890 /*!Adds window to application.
891 *\param wid - QWidget
892 *\param flag - key wor window
893 *\param studyId - study id
894 * Flag used how identificator of window in windows list.
896 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
904 if ( !activeStudy() )
907 sId = activeStudy()->id();
910 if ( !myWindows.contains( flag ) )
912 QMap<int, int> winMap;
913 currentWindows( winMap );
915 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
916 if ( winMap.contains( flag ) )
917 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
919 myWindows[flag]->setResizeEnabled( true );
920 myWindows[flag]->setCloseMode( QDockWindow::Always );
921 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
925 if( wid->inherits( "PythonConsole" ) )
926 f = ( ( PythonConsole* )wid )->font();
930 myWindows[flag]->insert( sId, wid );
933 setWindowShown( flag, !myWindows[flag]->isEmpty() );
936 /*!Remove window from application.
937 *\param flag - key wor window
938 *\param studyId - study id
939 * Flag used how identificator of window in windows list.
941 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
943 if ( !myWindows.contains( flag ) )
949 if ( !activeStudy() )
952 sId = activeStudy()->id();
955 QWidget* wid = myWindows[flag]->widget( sId );
956 myWindows[flag]->remove( sId );
959 setWindowShown( flag, !myWindows[flag]->isEmpty() );
963 *\param flag - key wor window
964 *\param studyId - study id
965 * Flag used how identificator of window in windows list.
967 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
969 QWidget* wid = window( flag, studyId );
971 addWindow( wid = createWindow( flag ), flag, studyId );
976 /*!Check is window visible?(with identificator \a type)*/
977 bool SalomeApp_Application::isWindowVisible( const int type ) const
980 if ( myWindows.contains( type ) )
982 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
983 res = desk && desk->appropriate( myWindows[type] );
988 /*!Sets window show or hide.
989 *\param type - window identificator.
990 *\param on - true/false (window show/hide)
992 void SalomeApp_Application::setWindowShown( const int type, const bool on )
994 if ( !desktop() || !myWindows.contains( type ) )
997 QDockWindow* dw = myWindows[type];
998 desktop()->setAppropriate( dw, on );
999 on ? dw->show() : dw->hide();
1002 OB_Browser* SalomeApp_Application::objectBrowser()
1005 QWidget* wid = getWindow( WT_ObjectBrowser );
1006 if ( wid->inherits( "OB_Browser" ) )
1007 ob = (OB_Browser*)wid;
1011 /*!Gets "LogWindow".*/
1012 LogWindow* SalomeApp_Application::logWindow()
1015 QWidget* wid = getWindow( WT_LogWindow );
1016 if ( wid->inherits( "LogWindow" ) )
1017 lw = (LogWindow*)wid;
1021 /*!Get "PythonConsole"*/
1022 PythonConsole* SalomeApp_Application::pythonConsole()
1024 PythonConsole* console = 0;
1025 QWidget* wid = getWindow( WT_PyConsole );
1026 if ( wid->inherits( "PythonConsole" ) )
1027 console = (PythonConsole*)wid;
1031 /*!Gets preferences.*/
1032 SalomeApp_Preferences* SalomeApp_Application::preferences() const
1034 return preferences( false );
1037 /*!Gets view manager*/
1038 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
1040 SUIT_ViewManager* aVM = viewManager( vmType );
1041 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1043 if ( anActiveVM && anActiveVM->getType() == vmType )
1046 if ( aVM && create )
1048 if ( !aVM->getActiveView() )
1051 aVM->getActiveView()->setFocus();
1054 aVM = createViewManager( vmType );
1059 /*!Create view manager.*/
1060 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
1062 SUIT_ResourceMgr* resMgr = resourceMgr();
1064 SUIT_ViewManager* viewMgr = 0;
1065 if ( vmType == GLViewer_Viewer::Type() )
1067 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1068 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1070 else if ( vmType == Plot2d_Viewer::Type() )
1072 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1073 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
1075 else if ( vmType == OCCViewer_Viewer::Type() )
1077 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1078 SOCC_Viewer* vm = new SOCC_Viewer();
1079 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1080 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1083 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1084 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1085 vm->setIsos( u, v );
1086 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1087 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1089 else if ( vmType == SVTK_Viewer::Type() )
1091 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1092 SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel();
1093 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1094 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1095 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
1101 addViewManager( viewMgr );
1102 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1104 if ( viewWin && desktop() )
1105 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1107 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1108 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1113 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1115 removeViewManager( theVM );
1118 /*!Private SLOT. On study created.*/
1119 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1121 SUIT_DataObject* aRoot = 0;
1122 if ( theStudy && theStudy->root() )
1124 aRoot = theStudy->root();
1125 //aRoot->setName( tr( "DATA_MODELS" ) );
1127 if ( objectBrowser() != 0 )
1128 objectBrowser()->setRootObject( aRoot );
1130 activateModule( defaultModule() );
1135 /*!Private SLOT. On study opened.*/
1136 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1138 SUIT_DataObject* aRoot = 0;
1139 if ( theStudy && theStudy->root() )
1141 aRoot = theStudy->root();
1144 if ( objectBrowser() != 0 ) {
1145 objectBrowser()->setRootObject( aRoot );
1148 activateModule( defaultModule() );
1155 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1160 /*!Private SLOT. On study closed.*/
1161 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1165 activateModule( "" );
1167 saveWindowsGeometry();
1170 /*!Private SLOT. On dump study.*/
1171 void SalomeApp_Application::onDumpStudy( )
1173 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1174 if ( !appStudy ) return;
1175 _PTR(Study) aStudy = appStudy->studyDS();
1177 QStringList aFilters;
1178 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1180 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1181 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1182 fd->setFilters( aFilters );
1183 fd->SetChecked(true);
1185 QString aFileName = fd->selectedFile();
1186 bool toPublish = fd->IsChecked();
1189 if(!aFileName.isEmpty()) {
1190 QFileInfo aFileInfo(aFileName);
1191 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1195 /*!Private SLOT. On load script.*/
1196 void SalomeApp_Application::onLoadScript( )
1198 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1199 if ( !appStudy ) return;
1200 _PTR(Study) aStudy = appStudy->studyDS();
1202 if ( aStudy->GetProperties()->IsLocked() ) {
1203 SUIT_MessageBox::warn1 ( desktop(),
1204 QObject::tr("WRN_WARNING"),
1205 QObject::tr("WRN_STUDY_LOCKED"),
1206 QObject::tr("BUT_OK") );
1210 QStringList filtersList;
1211 filtersList.append(tr("PYTHON_FILES_FILTER"));
1212 filtersList.append(tr("ALL_FILES_FILTER"));
1214 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1216 if ( !aFile.isEmpty() )
1218 QString command = QString("execfile(\"%1\")").arg(aFile);
1220 PythonConsole* pyConsole = pythonConsole();
1223 pyConsole->exec( command );
1227 /*!Private SLOT. On preferences.*/
1228 void SalomeApp_Application::onPreferences()
1230 QApplication::setOverrideCursor( Qt::waitCursor );
1232 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1234 QApplication::restoreOverrideCursor();
1244 /*!Private SLOT. On open document with name \a aName.*/
1245 void SalomeApp_Application::onMRUActivated( QString aName )
1250 /*!Private SLOT. On preferences changed.*/
1251 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1253 SalomeApp_Module* sMod = 0;
1254 CAM_Module* mod = module( modName );
1255 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1256 sMod = (SalomeApp_Module*)mod;
1259 sMod->preferencesChanged( section, param );
1261 preferencesChanged( section, param );
1264 /*!Gets file filter.
1265 *\retval QString "(*.hdf)"
1267 QString SalomeApp_Application::getFileFilter() const
1272 /*!Remove all windows from study.*/
1273 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1275 CAM_Application::beforeCloseDoc( s );
1277 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1278 removeWindow( itr.key(), s->id() );
1281 /*!Update actions.*/
1282 void SalomeApp_Application::updateActions()
1284 updateCommandsStatus();
1288 QWidget* SalomeApp_Application::createWindow( const int flag )
1292 SUIT_ResourceMgr* resMgr = resourceMgr();
1294 if ( flag == WT_ObjectBrowser )
1296 OB_Browser* ob = new OB_Browser( desktop() );
1297 ob->setAutoUpdate( true );
1298 ob->setAutoOpenLevel( 1 );
1299 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1300 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1301 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1303 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1305 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1306 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1308 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1309 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1310 QString().sprintf( "visibility_column_%d", i ), true ) );
1312 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1314 // Create OBSelector
1315 new SalomeApp_OBSelector( ob, mySelMgr );
1319 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1321 else if ( flag == WT_PyConsole )
1323 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1324 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1325 pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1328 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1330 else if ( flag == WT_LogWindow )
1332 LogWindow* logWin = new LogWindow( desktop() );
1333 logWin->setCaption( tr( "LOG_WINDOW" ) );
1336 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1342 /*!Default windows(Object Browser, Python Console).
1343 * Adds to map \a aMap.
1345 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1347 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1348 aMap.insert( WT_PyConsole, Qt::DockBottom );
1349 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1352 /*!Default view manager.*/
1353 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1358 /*!Gets preferences.
1359 * Create preferences, if \a crt = true.
1361 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1366 SalomeApp_Application* that = (SalomeApp_Application*)this;
1368 if ( !_prefs_ && crt )
1370 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1371 that->createPreferences( _prefs_ );
1374 that->myPrefs = _prefs_;
1376 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1377 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1379 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1382 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1384 QStringList modNameList;
1385 app->modules( modNameList, false );
1386 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1388 int id = _prefs_->addPreference( *it );
1389 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1393 app->modules( modList );
1394 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1396 SalomeApp_Module* mod = 0;
1397 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1398 mod = (SalomeApp_Module*)itr.current();
1400 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1402 int modCat = _prefs_->addPreference( mod->moduleName() );
1403 _prefs_->setItemProperty( modCat, "info", QString::null );
1404 mod->createPreferences();
1409 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1410 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1415 /*!Add new module to application.*/
1416 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1418 CAM_Application::moduleAdded( mod );
1420 SalomeApp_Module* salomeMod = 0;
1421 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1422 salomeMod = (SalomeApp_Module*)mod;
1424 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1426 int modCat = myPrefs->addPreference( mod->moduleName() );
1427 myPrefs->setItemProperty( modCat, "info", QString::null );
1428 salomeMod->createPreferences();
1432 /*!Create preferences.*/
1433 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1438 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1440 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1441 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1442 pref->setItemProperty( studyGroup, "columns", 1 );
1444 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1445 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1446 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1447 pref->setItemProperty( undoPref, "min", 1 );
1448 pref->setItemProperty( undoPref, "max", 100 );
1450 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1451 pref->setItemProperty( extgroup, "columns", 1 );
1452 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1453 pref->setItemProperty( apppref, "existing", true );
1454 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1456 pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1458 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1459 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1460 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1464 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1465 int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1466 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1468 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1469 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1471 pref->setItemProperty( defCols, "columns", 1 );
1473 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1474 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1476 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1478 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1480 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1481 pref->setItemProperty( occGroup, "columns", 1 );
1482 pref->setItemProperty( vtkGroup, "columns", 1 );
1484 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1485 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1486 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1487 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1489 pref->setItemProperty( occTS, "min", 1 );
1490 pref->setItemProperty( occTS, "max", 150 );
1492 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1493 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1494 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1495 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1497 pref->setItemProperty( isoU, "min", 0 );
1498 pref->setItemProperty( isoU, "max", 100000 );
1500 pref->setItemProperty( isoV, "min", 0 );
1501 pref->setItemProperty( isoV, "max", 100000 );
1503 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1504 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1505 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1506 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1508 pref->setItemProperty( vtkTS, "min", 1 );
1509 pref->setItemProperty( vtkTS, "max", 150 );
1511 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1512 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1513 pref->setItemProperty( dirGroup, "columns", 1 );
1514 pref->addPreference( tr( "" ), dirGroup,
1515 SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1518 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1520 SUIT_ResourceMgr* resMgr = resourceMgr();
1524 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1526 int sz = resMgr->integerValue( sec, param, -1 );
1527 QPtrList<SUIT_ViewManager> lst;
1528 viewManagers( OCCViewer_Viewer::Type(), lst );
1529 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1531 SUIT_ViewModel* vm = it.current()->getViewModel();
1532 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1535 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1536 occVM->setTrihedronSize( sz );
1537 occVM->getAISContext()->UpdateCurrentViewer();
1541 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1543 int sz = resMgr->integerValue( sec, param, -1 );
1544 QPtrList<SUIT_ViewManager> lst;
1545 viewManagers( SVTK_Viewer::Type(), lst );
1546 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1548 SUIT_ViewModel* vm = it.current()->getViewModel();
1549 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1552 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1553 vtkVM->setTrihedronSize( sz );
1558 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1560 QPtrList<SUIT_ViewManager> lst;
1561 viewManagers( OCCViewer_Viewer::Type(), lst );
1562 int u = resMgr->integerValue( sec, "iso_number_u" );
1563 int v = resMgr->integerValue( sec, "iso_number_v" );
1564 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1565 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1568 if( sec=="ObjectBrowser" )
1570 if( param=="auto_size" )
1572 OB_Browser* ob = objectBrowser();
1576 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1577 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1579 updateObjectBrowser( false );
1583 if( sec=="PyConsole" )
1586 if( pythonConsole() )
1587 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1591 /*!Update desktop title.*/
1592 void SalomeApp_Application::updateDesktopTitle() {
1593 QString aTitle = applicationName();
1594 QString aVer = applicationVersion();
1595 if ( !aVer.isEmpty() )
1596 aTitle += QString( " " ) + aVer;
1598 if ( activeStudy() )
1600 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1601 if ( !sName.isEmpty() ) {
1602 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1603 _PTR(Study) stdDS = study->studyDS();
1605 if ( stdDS->GetProperties()->IsLocked() ) {
1606 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1608 aTitle += QString( " - [%1]" ).arg( sName );
1614 desktop()->setCaption( aTitle );
1617 /*!Update windows after close document.*/
1618 void SalomeApp_Application::afterCloseDoc()
1622 CAM_Application::afterCloseDoc();
1625 /*!Gets CORBA::ORB_var*/
1626 CORBA::ORB_var SalomeApp_Application::orb()
1628 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1629 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1633 /*!Create and return SALOMEDS_StudyManager.*/
1634 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1636 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1640 /*!Create and return SALOME_NamingService.*/
1641 SALOME_NamingService* SalomeApp_Application::namingService()
1643 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1647 /*!Create and return SALOME_LifeCycleCORBA.*/
1648 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1650 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1654 QString SalomeApp_Application::defaultEngineIOR()
1656 /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1657 QString anIOR( "" );
1658 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1659 if ( !CORBA::is_nil( anEngine ) )
1660 anIOR = orb()->object_to_string( anEngine );
1664 /*!Adds icon names for modules.*/
1665 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1669 SUIT_ResourceMgr* resMgr = resourceMgr();
1673 QStringList modList;
1674 modules( modList, false );
1676 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1678 QString modName = *it;
1679 QString modIntr = moduleName( modName );
1680 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1682 if ( modIcon.isEmpty() )
1685 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1686 modIcon += QString( ".png" );
1688 iconMap.insert( modName, modIcon );
1692 /*!Update module action.*/
1693 void SalomeApp_Application::updateModuleActions()
1696 if ( activeModule() )
1697 modName = activeModule()->moduleName();
1699 if ( myActions.contains( modName ) )
1700 myActions[modName]->setOn( true );
1703 /*!Gets current windows.
1704 *\param winMap - output current windows map.
1706 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1709 if ( !activeStudy() )
1712 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1713 ((SalomeApp_Module*)activeModule())->windows( winMap );
1715 defaultWindows( winMap );
1718 /*!Gets current view managers.
1719 *\param lst - output current view managers list.
1721 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1724 if ( !activeStudy() )
1727 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1728 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1730 defaultViewManagers( lst );
1733 /*!Update windows.*/
1734 void SalomeApp_Application::updateWindows()
1736 QMap<int, int> winMap;
1737 currentWindows( winMap );
1739 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1740 getWindow( it.key() );
1742 loadWindowsGeometry();
1744 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1745 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1748 /*!Update view managers.*/
1749 void SalomeApp_Application::updateViewManagers()
1752 currentViewManagers( lst );
1754 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1755 getViewManager( *it, true );
1758 /*!Load windows geometry.*/
1759 void SalomeApp_Application::loadWindowsGeometry()
1761 QtxDockAction* dockMgr = 0;
1763 QAction* a = action( ViewWindowsId );
1764 if ( a && a->inherits( "QtxDockAction" ) )
1765 dockMgr = (QtxDockAction*)a;
1771 if ( activeModule() )
1772 modName = moduleLibrary( activeModule()->moduleName(), false );
1774 QString section = QString( "windows_geometry" );
1775 if ( !modName.isEmpty() )
1776 section += QString( "." ) + modName;
1778 dockMgr->loadGeometry( resourceMgr(), section, false );
1779 dockMgr->restoreGeometry();
1782 /*!Save windows geometry.*/
1783 void SalomeApp_Application::saveWindowsGeometry()
1785 QtxDockAction* dockMgr = 0;
1787 QAction* a = action( ViewWindowsId );
1788 if ( a && a->inherits( "QtxDockAction" ) )
1789 dockMgr = (QtxDockAction*)a;
1795 if ( activeModule() )
1796 modName = moduleLibrary( activeModule()->moduleName(), false );
1798 QString section = QString( "windows_geometry" );
1799 if ( !modName.isEmpty() )
1800 section += QString( "." ) + modName;
1802 dockMgr->storeGeometry();
1803 dockMgr->saveGeometry( resourceMgr(), section, false );
1806 /*!Activate windows.*/
1807 void SalomeApp_Application::activateWindows()
1809 if ( activeStudy() )
1811 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1812 itr.data()->activate( activeStudy()->id() );
1816 /*!Private SLOT. On preferences.*/
1817 void SalomeApp_Application::onProperties()
1819 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1823 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1826 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1827 int res = aDlg.exec();
1828 if( res==QDialog::Accepted && aDlg.isChanged() )
1829 SB->CommitCommand();
1833 //study->updateCaptions();
1834 updateDesktopTitle();
1838 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1839 const QString& caption, QWidget* parent )
1843 QStringList fls = QStringList::split( ";;", filters, false );
1844 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1848 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1852 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1856 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1857 const QString& caption, QWidget* parent )
1861 QStringList fls = QStringList::split( ";;", filters, false );
1862 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1866 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1868 CAM_Application::contextMenuPopup( type, thePopup, title );
1870 OB_Browser* ob = objectBrowser();
1871 if ( !ob || type != ob->popupClientType() )
1874 thePopup->insertSeparator();
1875 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1877 // "Activate module" item should appear only if it's necessary
1878 SALOME_ListIO aList;
1879 SalomeApp_SelectionMgr* mgr = selectionMgr();
1880 mgr->selectedObjects(aList);
1881 if (aList.Extent() != 1)
1883 Handle(SALOME_InteractiveObject) aIObj = aList.First();
1884 QString aModuleName(aIObj->getComponentDataType());
1885 QString aModuleTitle = moduleTitle(aModuleName);
1886 CAM_Module* currentModule = activeModule();
1887 if (currentModule && currentModule->moduleName() == aModuleTitle)
1889 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
1892 /*!Update obect browser*/
1893 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
1895 // update existing data models (already loaded SComponents)
1898 for ( ModuleListIterator it = modules(); it.current(); ++it )
1900 CAM_DataModel* camDM = it.current()->dataModel();
1901 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
1902 ((SalomeApp_DataModel*)camDM)->update();
1905 // update "non-existing" (not loaded yet) data models
1906 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1909 _PTR(Study) stdDS = study->studyDS();
1912 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
1914 _PTR(SComponent) aComponent ( it->Value() );
1916 if ( aComponent->ComponentDataType() == "Interface Applicative" )
1917 continue; // skip the magic "Interface Applicative" component
1919 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
1924 if ( objectBrowser() )
1926 objectBrowser()->updateGeometry();
1927 objectBrowser()->updateTree();
1931 /*!Protected SLOT.On desktop activated.*/
1932 void SalomeApp_Application::onDesktopActivated()
1934 CAM_Application::onDesktopActivated();
1935 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
1937 aModule->studyActivated();
1940 /*!Create empty study.*/
1941 void SalomeApp_Application::createEmptyStudy()
1943 CAM_Application::createEmptyStudy();
1944 if ( objectBrowser() )
1945 objectBrowser()->updateTree();
1948 /*!Activate module \a mod.*/
1949 bool SalomeApp_Application::activateModule( CAM_Module* mod )
1951 bool res = CAM_Application::activateModule( mod );
1952 if ( objectBrowser() )
1953 objectBrowser()->updateTree();
1957 /*!Display Catalog Genenerator dialog */
1958 void SalomeApp_Application::onCatalogGen()
1960 ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
1964 /*!Display Registry Display dialog */
1965 void SalomeApp_Application::onRegDisplay()
1967 CORBA::ORB_var anOrb = orb();
1968 ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
1971 regWnd->setActiveWindow();
1974 /*!return keyborad accelerators manager object */
1975 SUIT_Accel* SalomeApp_Application::accel() const