1 // File: SalomeApp_Application.cxx
2 // Created: 10/22/2004 3:23:45 PM
3 // Author: Sergey LITONIN
4 // Copyright (C) CEA 2004
6 #include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
8 #include "SalomeApp_Application.h"
10 #include "SalomeApp_Study.h"
11 #include "SalomeApp_Module.h"
12 #include "SalomeApp_OBFilter.h"
13 #include "SalomeApp_DataModel.h"
14 #include "SalomeApp_DataObject.h"
15 #include "SalomeApp_EventFilter.h"
16 #include "SalomeApp_WidgetContainer.h"
18 #include "SalomeApp_AboutDlg.h"
19 #include "SalomeApp_ModuleDlg.h"
20 #include "SalomeApp_Preferences.h"
21 #include "SalomeApp_PreferencesDlg.h"
22 #include "SalomeApp_StudyPropertiesDlg.h"
23 #include "SalomeApp_CheckFileDlg.h"
25 #include "SalomeApp_GLSelector.h"
26 #include "SalomeApp_OBSelector.h"
27 #include "SalomeApp_OCCSelector.h"
28 #include "SalomeApp_VTKSelector.h"
29 #include "SalomeApp_SelectionMgr.h"
31 #include <LogWindow.h>
33 #include <GLViewer_Viewer.h>
34 #include <GLViewer_ViewManager.h>
36 #include <Plot2d_ViewManager.h>
37 #include <SPlot2d_ViewModel.h>
39 #include <OCCViewer_ViewManager.h>
40 #include <SOCC_ViewModel.h>
42 #include <SVTK_ViewModel.h>
43 #include <SVTK_ViewManager.h>
45 #include <STD_TabDesktop.h>
47 #include "STD_LoadStudiesDlg.h"
49 #include <SUIT_Tools.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_Accel.h>
53 #include <QtxToolBar.h>
54 #include <QtxMRUAction.h>
55 #include <QtxDockAction.h>
56 #include <QtxResourceEdit.h>
58 #include <OB_Browser.h>
60 #include <PythonConsole_PyConsole.h>
62 #include <SUIT_FileDlg.h>
63 #include <SUIT_MessageBox.h>
64 #include <SUIT_ResourceMgr.h>
65 #include <SUIT_ActionOperation.h>
67 #include <Utils_ORB_INIT.hxx>
68 #include <Utils_SINGLETON.hxx>
69 #include <SALOME_ModuleCatalog_impl.hxx>
70 #include <SALOME_LifeCycleCORBA.hxx>
78 #include <qcombobox.h>
79 #include <qmessagebox.h>
80 #include <qapplication.h>
84 #include "SALOMEDS_StudyManager.hxx"
86 #include "SALOME_ListIteratorOfListIO.hxx"
87 #include "SALOME_ListIO.hxx"
89 #include "ToolsGUI_CatalogGeneratorDlg.h"
90 #include "ToolsGUI_RegWidget.h"
92 #define OBJECT_BROWSER_WIDTH 300
94 /*!Image for empty icon.*/
95 static const char* imageEmptyIcon[] = {
98 "....................",
99 "....................",
100 "....................",
101 "....................",
102 "....................",
103 "....................",
104 "....................",
105 "....................",
106 "....................",
107 "....................",
108 "....................",
109 "....................",
110 "....................",
111 "....................",
112 "....................",
113 "....................",
114 "....................",
115 "....................",
116 "....................",
117 "...................."};
119 /*!Create new instance of SalomeApp_Application.*/
120 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
122 return new SalomeApp_Application();
125 SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0;
128 Class : SalomeApp_Application
129 Description : Application containing SalomeApp module
133 SalomeApp_Application::SalomeApp_Application()
134 : CAM_Application( false ),
137 STD_TabDesktop* desk = new STD_TabDesktop();
141 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
142 QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
144 desktop()->setIcon( aLogo );
145 desktop()->setDockableMenuBar( true );
146 desktop()->setDockableStatusBar( false );
148 // base logo (salome itself)
149 desktop()->addLogo( "_app_base", aResMgr->loadPixmap( "SalomeApp", tr( "APP_BASE_LOGO" ), false ) );
150 // extra logo (salome-based application)
151 desktop()->addLogo( "_app_extra", aResMgr->loadPixmap( "SalomeApp", tr( "APP_EXTRA_LOGO" ), false ) );
155 mySelMgr = new SalomeApp_SelectionMgr( this );
157 myAccel = new SUIT_Accel( desktop() );
158 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() );
159 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() );
160 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() );
161 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() );
162 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() );
163 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() );
164 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() );
165 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() );
166 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() );
167 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() );
168 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() );
169 myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, SVTK_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, SVTK_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, SVTK_Viewer::Type() );
172 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, SVTK_Viewer::Type() );
173 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, SVTK_Viewer::Type() );
174 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, SVTK_Viewer::Type() );
175 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, SVTK_Viewer::Type() );
176 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, SVTK_Viewer::Type() );
177 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, SVTK_Viewer::Type() );
178 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, SVTK_Viewer::Type() );
179 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, SVTK_Viewer::Type() );
181 connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ),
182 this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) );
184 connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) );
188 *\li Save window geometry.
189 *\li Save desktop geometry.
190 *\li Save resource maneger.
191 *\li Delete selection manager.
192 *\li Destroy event filter.
194 SalomeApp_Application::~SalomeApp_Application()
196 saveWindowsGeometry();
201 desktop()->saveGeometry( resourceMgr(), "desktop" );
202 resourceMgr()->save();
207 SalomeApp_EventFilter::Destroy();
210 /*!Start application.*/
211 void SalomeApp_Application::start()
214 desktop()->loadGeometry( resourceMgr(), "desktop" );
216 CAM_Application::start();
218 QAction* a = action( ViewWindowsId );
219 if ( a && a->inherits( "QtxDockAction" ) )
220 ((QtxDockAction*)a)->setAutoPlace( true );
222 SalomeApp_EventFilter::Init();
225 updateViewManagers();
230 /*!Gets application name.*/
231 QString SalomeApp_Application::applicationName() const
233 return tr( "APP_NAME" );
236 /*!Gets application version.*/
237 QString SalomeApp_Application::applicationVersion() const
239 static QString _app_version;
241 if ( _app_version.isEmpty() )
243 QString resVersion = tr( "APP_VERSION" );
244 if ( resVersion != "APP_VERSION" )
246 _app_version = resVersion;
250 QString path( ::getenv( "GUI_ROOT_DIR" ) );
251 if ( !path.isEmpty() )
252 path += QDir::separator();
253 path += QString( "bin/salome/VERSION" );
256 if ( vf.open( IO_ReadOnly ) )
259 vf.readLine( line, 1024 );
262 if ( !line.isEmpty() )
264 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
265 line.remove( line.length() - 1, 1 );
267 int idx = line.findRev( ":" );
269 _app_version = line.mid( idx + 1 ).stripWhiteSpace();
277 /*!Load module by \a name.*/
278 CAM_Module* SalomeApp_Application::loadModule( const QString& name )
280 CAM_Module* mod = CAM_Application::loadModule( name );
283 connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) );
284 connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) );
285 connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) );
290 /*!Activate module by \a modName*/
291 bool SalomeApp_Application::activateModule( const QString& modName )
294 CAM_Module* prevMod = activeModule();
297 actName = prevMod->moduleName();
299 if ( actName == modName )
302 putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) );
304 saveWindowsGeometry();
306 bool status = CAM_Application::activateModule( modName );
308 updateModuleActions();
316 updateViewManagers();
321 /*!Gets selection manager.*/
322 SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const
328 void SalomeApp_Application::createActions()
330 STD_Application::createActions();
332 SUIT_Desktop* desk = desktop();
333 SUIT_ResourceMgr* resMgr = resourceMgr();
336 createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
337 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
338 0, desk, false, this, SLOT( onDumpStudy() ) );
341 createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
342 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
343 0, desk, false, this, SLOT( onLoadScript() ) );
346 createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
347 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
348 0, desk, false, this, SLOT( onProperties() ) );
351 createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(),
352 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
353 CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) );
355 //! Catalog Generator
356 createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIconSet(),
357 tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ),
358 0, desk, false, this, SLOT( onCatalogGen() ) );
361 createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIconSet(),
362 tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ),
363 0, desk, false, this, SLOT( onRegDisplay() ) );
366 QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk );
367 connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) );
368 registerAction( MRUId, mru );
370 //! default icon for neutral point ('SALOME' module)
371 QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false );
372 if ( defIcon.isNull() )
373 defIcon = QPixmap( imageEmptyIcon );
375 //! default icon for any module
376 QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false );
377 if ( modIcon.isNull() )
378 modIcon = QPixmap( imageEmptyIcon );
380 QToolBar* modTBar = new QtxToolBar( true, desk );
381 modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) );
383 QActionGroup* modGroup = new QActionGroup( this );
384 modGroup->setExclusive( true );
385 modGroup->setUsesDropDown( true );
387 QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ),
388 tr( "PRP_APP_MODULE" ), 0, desk, true );
390 myActions.insert( QString(), a );
392 QMap<QString, QString> iconMap;
393 moduleIconNames( iconMap );
395 const int iconSize = 20;
397 modGroup->addTo( modTBar );
398 modTBar->addSeparator();
401 modules( modList, false );
403 for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it )
405 if ( (*it).isEmpty() )
409 if ( iconMap.contains( *it ) )
410 iconName = iconMap[*it];
412 QString modName = moduleName( *it );
414 QPixmap icon = resMgr->loadPixmap( modName, iconName, false );
418 icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) );
420 QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true );
424 myActions.insert( *it, a );
427 SUIT_Tools::simplifySeparators( modTBar );
431 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
432 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
433 createMenu( separator(), windowMenu, -1, 1 );
435 QMap<int, int> accelMap;
436 accelMap[NewGLViewId] = ALT+Key_G;
437 accelMap[NewPlot2dId] = ALT+Key_P;
438 accelMap[NewOCCViewId] = ALT+Key_O;
439 accelMap[NewVTKViewId] = ALT+Key_K;
441 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
443 QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(),
444 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
445 tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ),
446 accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) );
447 createMenu( a, newWinMenu, -1 );
449 connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) );
451 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
453 createMenu( DumpStudyId, fileMenu, 10, -1 );
454 createMenu( separator(), fileMenu, -1, 15, -1 );
455 createMenu( LoadScriptId, fileMenu, 10, -1 );
456 createMenu( separator(), fileMenu, -1, 15, -1 );
457 createMenu( PropertiesId, fileMenu, 10, -1 );
458 createMenu( separator(), fileMenu, -1, 15, -1 );
459 createMenu( PreferencesId, fileMenu, 15, -1 );
460 createMenu( separator(), fileMenu, -1, 15, -1 );
462 int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, -1, 50 );
463 createMenu( CatalogGenId, toolsMenu, 10, -1 );
464 createMenu( RegDisplayId, toolsMenu, 10, -1 );
465 createMenu( separator(), toolsMenu, -1, 15, -1 );
468 createMenu( separator(), fileMenu, -1, 100, -1 );
469 createMenu( MRUId, fileMenu, 100, -1 );
470 createMenu( separator(), fileMenu, -1, 100, -1 );
474 /*!On module activation action.*/
475 void SalomeApp_Application::onModuleActivation( QAction* a )
480 QString modName = a->menuText();
481 if ( modName == tr( "APP_NAME" ) )
482 modName = QString::null;
484 // Force user to create/open a study before module activation
485 QMap<QString, QString> iconMap;
486 moduleIconNames( iconMap );
487 QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false );
489 icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module
491 bool cancelled = false;
492 while ( !modName.isEmpty() && !activeStudy() && !cancelled ){
493 SalomeApp_ModuleDlg aDlg( desktop(), modName, icon );
494 int res = aDlg.exec();
508 putInfo( tr("INF_CANCELLED") );
509 myActions[QString()]->setOn( true );
515 activateModule( modName );
518 /*!Default module activation.*/
519 QString SalomeApp_Application::defaultModule() const
521 QStringList aModuleNames;
522 modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration
523 //! If there's the one and only module --> activate it automatically
524 //! TODO: Possible improvement - default module can be taken from preferences
525 return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" );
528 /*!On new window slot.*/
529 void SalomeApp_Application::onNewWindow()
531 const QObject* obj = sender();
532 if ( !obj || !obj->inherits( "QAction" ) )
536 int id = actionId( (QAction*)obj );
540 type = GLViewer_Viewer::Type();
543 type = Plot2d_Viewer::Type();
546 type = OCCViewer_Viewer::Type();
549 type = SVTK_Viewer::Type();
553 if ( !type.isEmpty() )
554 createViewManager( type );
557 //=======================================================================
559 /*! Purpose : SLOT. Create new document*/
560 //=======================================================================
561 void SalomeApp_Application::onNewDoc()
563 SUIT_Study* study = activeStudy();
565 saveWindowsGeometry();
567 CAM_Application::onNewDoc();
569 if ( !study ) // new study will be create in THIS application
572 updateViewManagers();
576 //=======================================================================
578 /*! Purpose : SLOT. Open new document*/
579 //=======================================================================
580 void SalomeApp_Application::onOpenDoc()
582 SUIT_Study* study = activeStudy();
583 saveWindowsGeometry();
585 CAM_Application::onOpenDoc();
587 if ( !study ) // new study will be create in THIS application
590 updateViewManagers();
594 /*! Purpose : SLOT. Open new document with \a aName.*/
595 bool SalomeApp_Application::onOpenDoc( const QString& aName )
597 bool res = CAM_Application::onOpenDoc( aName );
599 QAction* a = action( MRUId );
600 if ( a && a->inherits( "QtxMRUAction" ) )
602 QtxMRUAction* mru = (QtxMRUAction*)a;
604 mru->insert( aName );
606 mru->remove( aName );
611 /*!SLOT. Load document.*/
612 void SalomeApp_Application::onLoadDoc()
614 QString name, studyname, ext;
616 STD_LoadStudiesDlg aDlg( desktop(), TRUE);
618 std::vector<std::string> List = studyMgr()->GetOpenStudies();
620 SUIT_Session* aSession = SUIT_Session::session();
621 QPtrList<SUIT_Application> aAppList = aSession->applications();
622 SUIT_Application* aApp = 0;
624 for (unsigned int ind = 0; ind < List.size(); ind++) {
625 studyname = List[ind].c_str();
626 //Add to list only unloaded studies
627 bool isAlreadyOpen = false;
628 for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
631 if(!aApp || !aApp->activeStudy()) continue;
632 if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
635 if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
638 int retVal = aDlg.exec();
639 studyname = aDlg.ListComponent->currentText();
641 if (retVal == QDialog::Rejected)
644 if ( studyname.isNull() || studyname.isEmpty() )
648 name.replace( QRegExp(":"), "/" );
650 if(onLoadDoc(name)) {
652 updateViewManagers();
653 updateObjectBrowser(true);
658 /*!SLOT. Load document with \a aName.*/
659 bool SalomeApp_Application::onLoadDoc( const QString& aName )
661 bool res = CAM_Application::onLoadDoc( aName );
663 /*jfa tmp:QAction* a = action( MRUId );
664 if ( a && a->inherits( "QtxMRUAction" ) )
666 QtxMRUAction* mru = (QtxMRUAction*)a;
668 mru->insert( aName );
670 mru->remove( aName );
675 /*!Private SLOT. Selection.*/
676 void SalomeApp_Application::onSelection()
678 onSelectionChanged();
680 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
681 ((SalomeApp_Module*)activeModule())->selectionChanged();
684 /*!SLOT. Copy objects to study maneger from selection maneger..*/
685 void SalomeApp_Application::onCopy()
688 SalomeApp_SelectionMgr* mgr = selectionMgr();
689 mgr->selectedObjects(list);
691 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
692 if(study == NULL) return;
694 _PTR(Study) stdDS = study->studyDS();
697 SALOME_ListIteratorOfListIO it( list );
700 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
702 studyMgr()->Copy(so);
703 onSelectionChanged();
710 /*!SLOT. Paste objects to study maneger from selection manager.*/
711 void SalomeApp_Application::onPaste()
714 SalomeApp_SelectionMgr* mgr = selectionMgr();
715 mgr->selectedObjects(list);
717 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
718 if(study == NULL) return;
720 _PTR(Study) stdDS = study->studyDS();
723 SALOME_ListIteratorOfListIO it( list );
726 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
728 studyMgr()->Paste(so);
729 updateObjectBrowser( true );
730 updateActions(); //SRN: BugID IPAL9377, case 3
737 /*!Sets enable or disable some actions on selection changed.*/
738 void SalomeApp_Application::onSelectionChanged()
741 SalomeApp_SelectionMgr* mgr = selectionMgr();
742 mgr->selectedObjects(list);
744 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
745 if(study == NULL) return;
747 _PTR(Study) stdDS = study->studyDS();
752 SALOME_ListIteratorOfListIO it( list );
753 if(it.More() && list.Extent() == 1)
755 _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
757 qaction = action(EditCopyId);
758 if( so && studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
759 else qaction->setEnabled(false);
761 qaction = action(EditPasteId);
762 if( so && studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
763 else qaction->setEnabled(false);
766 qaction = action(EditCopyId);
767 qaction->setEnabled(false);
768 qaction = action(EditPasteId);
769 qaction->setEnabled(false);
773 /*!Update object browser.*/
774 void SalomeApp_Application::onRefresh()
776 updateObjectBrowser( true );
779 /*!Delete references.*/
780 void SalomeApp_Application::onDeleteReferences()
783 SalomeApp_SelectionMgr* mgr = selectionMgr();
784 mgr->selectedObjects(aList);
786 if (aList.Extent() < 1) return;
788 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
789 _PTR(Study) aStudyDS = aStudy->studyDS();
790 _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder();
793 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
795 if ( it.Value()->hasEntry() )
797 _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
798 if ( aSObject->ReferencedObject(anObj) )
799 aStudyBuilder->RemoveReference(aSObject);
803 updateObjectBrowser();
807 void SalomeApp_Application::onOpenWith()
809 QApplication::setOverrideCursor( Qt::waitCursor );
811 SalomeApp_SelectionMgr* mgr = selectionMgr();
812 mgr->selectedObjects(aList);
813 if (aList.Extent() != 1)
815 QApplication::restoreOverrideCursor();
818 Handle(SALOME_InteractiveObject) aIObj = aList.First();
819 QString aModuleName(aIObj->getComponentDataType());
820 QString aModuleTitle = moduleTitle(aModuleName);
821 activateModule(aModuleTitle);
822 QApplication::restoreOverrideCursor();
825 bool SalomeApp_Application::useStudy(const QString& theName)
828 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
831 res = aStudy->loadDocument( theName );
832 updateDesktopTitle();
833 updateCommandsStatus();
838 *\param study - SUIT_Study.
840 void SalomeApp_Application::setActiveStudy( SUIT_Study* study )
842 CAM_Application::setActiveStudy( study );
847 //=======================================================================
848 // name : createNewStudy
849 /*! Purpose : Create new study*/
850 //=======================================================================
851 SUIT_Study* SalomeApp_Application::createNewStudy()
853 SalomeApp_Study* aStudy = new SalomeApp_Study( this );
855 // Set up processing of major study-related events
856 connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
857 connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
858 connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );
859 connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
864 //=======================================================================
865 // name : createNewStudy
866 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
867 //=======================================================================
868 void SalomeApp_Application::updateCommandsStatus()
870 CAM_Application::updateCommandsStatus();
872 for ( int id = NewGLViewId; id <= NewVTKViewId; id++ )
874 QAction* a = action( id );
876 a->setEnabled( activeStudy() );
880 QAction* a = action( DumpStudyId );
882 a->setEnabled( activeStudy() );
885 a = action( LoadScriptId );
887 a->setEnabled( activeStudy() );
889 a = action( PropertiesId );
891 a->setEnabled( activeStudy() );
893 a = action(EditCopyId);
894 a->setEnabled(false);
895 a = action(EditPasteId);
896 a->setEnabled(false);
899 //=======================================================================
900 // name : onHelpAbout
901 /*! Purpose : SLOT. Display "About" message box*/
902 //=======================================================================
903 void SalomeApp_Application::onHelpAbout()
905 SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() );
910 QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const
917 if ( !activeStudy() )
920 sId = activeStudy()->id();
923 if ( myWindows.contains( flag ) )
924 wid = myWindows[flag]->widget( sId );
929 /*!Adds window to application.
930 *\param wid - QWidget
931 *\param flag - key wor window
932 *\param studyId - study id
933 * Flag used how identificator of window in windows list.
935 void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId )
943 if ( !activeStudy() )
946 sId = activeStudy()->id();
949 if ( !myWindows.contains( flag ) )
951 QMap<int, int> winMap;
952 currentWindows( winMap );
954 myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) );
955 if ( winMap.contains( flag ) )
956 desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] );
958 myWindows[flag]->setResizeEnabled( true );
959 myWindows[flag]->setCloseMode( QDockWindow::Always );
960 myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) );
964 if( wid->inherits( "PythonConsole" ) )
965 f = ( ( PythonConsole* )wid )->font();
969 myWindows[flag]->insert( sId, wid );
972 setWindowShown( flag, !myWindows[flag]->isEmpty() );
975 /*!Remove window from application.
976 *\param flag - key wor window
977 *\param studyId - study id
978 * Flag used how identificator of window in windows list.
980 void SalomeApp_Application::removeWindow( const int flag, const int studyId )
982 if ( !myWindows.contains( flag ) )
988 if ( !activeStudy() )
991 sId = activeStudy()->id();
994 QWidget* wid = myWindows[flag]->widget( sId );
995 myWindows[flag]->remove( sId );
998 setWindowShown( flag, !myWindows[flag]->isEmpty() );
1002 *\param flag - key wor window
1003 *\param studyId - study id
1004 * Flag used how identificator of window in windows list.
1006 QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId )
1008 QWidget* wid = window( flag, studyId );
1010 addWindow( wid = createWindow( flag ), flag, studyId );
1015 /*!Check is window visible?(with identificator \a type)*/
1016 bool SalomeApp_Application::isWindowVisible( const int type ) const
1019 if ( myWindows.contains( type ) )
1021 SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop();
1022 res = desk && desk->appropriate( myWindows[type] );
1027 /*!Sets window show or hide.
1028 *\param type - window identificator.
1029 *\param on - true/false (window show/hide)
1031 void SalomeApp_Application::setWindowShown( const int type, const bool on )
1033 if ( !desktop() || !myWindows.contains( type ) )
1036 QDockWindow* dw = myWindows[type];
1037 desktop()->setAppropriate( dw, on );
1038 on ? dw->show() : dw->hide();
1041 OB_Browser* SalomeApp_Application::objectBrowser()
1044 QWidget* wid = getWindow( WT_ObjectBrowser );
1045 if ( wid->inherits( "OB_Browser" ) )
1046 ob = (OB_Browser*)wid;
1050 /*!Gets "LogWindow".*/
1051 LogWindow* SalomeApp_Application::logWindow()
1054 QWidget* wid = getWindow( WT_LogWindow );
1055 if ( wid->inherits( "LogWindow" ) )
1056 lw = (LogWindow*)wid;
1060 /*!Get "PythonConsole"*/
1061 PythonConsole* SalomeApp_Application::pythonConsole()
1063 PythonConsole* console = 0;
1064 QWidget* wid = getWindow( WT_PyConsole );
1065 if ( wid->inherits( "PythonConsole" ) )
1066 console = (PythonConsole*)wid;
1070 /*!Gets preferences.*/
1071 SalomeApp_Preferences* SalomeApp_Application::preferences() const
1073 return preferences( false );
1076 /*!Gets view manager*/
1077 SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create )
1079 SUIT_ViewManager* aVM = viewManager( vmType );
1080 SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
1082 if ( anActiveVM && anActiveVM->getType() == vmType )
1085 if ( aVM && create )
1087 if ( !aVM->getActiveView() )
1090 aVM->getActiveView()->setFocus();
1093 aVM = createViewManager( vmType );
1098 /*!Create view manager.*/
1099 SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType )
1101 SUIT_ResourceMgr* resMgr = resourceMgr();
1103 SUIT_ViewManager* viewMgr = 0;
1104 if ( vmType == GLViewer_Viewer::Type() )
1106 viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() );
1107 new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr );
1109 else if ( vmType == Plot2d_Viewer::Type() )
1111 viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() );
1112 viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface
1114 else if ( vmType == OCCViewer_Viewer::Type() )
1116 viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() );
1117 SOCC_Viewer* vm = new SOCC_Viewer();
1118 vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) );
1119 vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) );
1122 u = resMgr->integerValue( "OCCViewer", "iso_number_u", u );
1123 v = resMgr->integerValue( "OCCViewer", "iso_number_v", v );
1124 vm->setIsos( u, v );
1125 viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface
1126 new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr );
1128 else if ( vmType == SVTK_Viewer::Type() )
1130 viewMgr = new SVTK_ViewManager( activeStudy(), desktop() );
1131 SVTK_Viewer* vm = dynamic_cast<SVTK_Viewer*>( viewMgr->getViewModel() );
1134 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1135 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1136 new SalomeApp_VTKSelector( vm, mySelMgr );
1143 addViewManager( viewMgr );
1144 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1146 if ( viewWin && desktop() )
1147 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1149 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1150 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1155 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1157 removeViewManager( theVM );
1160 /*!Private SLOT. On study created.*/
1161 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1163 SUIT_DataObject* aRoot = 0;
1164 if ( theStudy && theStudy->root() )
1166 aRoot = theStudy->root();
1167 //aRoot->setName( tr( "DATA_MODELS" ) );
1169 if ( objectBrowser() != 0 )
1170 objectBrowser()->setRootObject( aRoot );
1172 activateModule( defaultModule() );
1177 /*!Private SLOT. On study opened.*/
1178 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1180 SUIT_DataObject* aRoot = 0;
1181 if ( theStudy && theStudy->root() )
1183 aRoot = theStudy->root();
1186 if ( objectBrowser() != 0 ) {
1187 objectBrowser()->setRootObject( aRoot );
1190 activateModule( defaultModule() );
1197 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1202 /*!Private SLOT. On study closed.*/
1203 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1207 activateModule( "" );
1209 saveWindowsGeometry();
1212 /*!Private SLOT. On dump study.*/
1213 void SalomeApp_Application::onDumpStudy( )
1215 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1216 if ( !appStudy ) return;
1217 _PTR(Study) aStudy = appStudy->studyDS();
1219 QStringList aFilters;
1220 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1222 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1223 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1224 fd->setFilters( aFilters );
1225 fd->SetChecked(true);
1227 QString aFileName = fd->selectedFile();
1228 bool toPublish = fd->IsChecked();
1231 if(!aFileName.isEmpty()) {
1232 QFileInfo aFileInfo(aFileName);
1233 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1237 /*!Private SLOT. On load script.*/
1238 void SalomeApp_Application::onLoadScript( )
1240 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1241 if ( !appStudy ) return;
1242 _PTR(Study) aStudy = appStudy->studyDS();
1244 if ( aStudy->GetProperties()->IsLocked() ) {
1245 SUIT_MessageBox::warn1 ( desktop(),
1246 QObject::tr("WRN_WARNING"),
1247 QObject::tr("WRN_STUDY_LOCKED"),
1248 QObject::tr("BUT_OK") );
1252 QStringList filtersList;
1253 filtersList.append(tr("PYTHON_FILES_FILTER"));
1254 filtersList.append(tr("ALL_FILES_FILTER"));
1256 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1258 if ( !aFile.isEmpty() )
1260 QString command = QString("execfile(\"%1\")").arg(aFile);
1262 PythonConsole* pyConsole = pythonConsole();
1265 pyConsole->exec( command );
1269 /*!Private SLOT. On preferences.*/
1270 void SalomeApp_Application::onPreferences()
1272 QApplication::setOverrideCursor( Qt::waitCursor );
1274 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1276 QApplication::restoreOverrideCursor();
1286 /*!Private SLOT. On open document with name \a aName.*/
1287 void SalomeApp_Application::onMRUActivated( QString aName )
1292 /*!Private SLOT. On preferences changed.*/
1293 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1295 SalomeApp_Module* sMod = 0;
1296 CAM_Module* mod = module( modName );
1297 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1298 sMod = (SalomeApp_Module*)mod;
1301 sMod->preferencesChanged( section, param );
1303 preferencesChanged( section, param );
1306 /*!Gets file filter.
1307 *\retval QString "(*.hdf)"
1309 QString SalomeApp_Application::getFileFilter() const
1314 /*!Remove all windows from study.*/
1315 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1317 CAM_Application::beforeCloseDoc( s );
1319 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1320 removeWindow( itr.key(), s->id() );
1323 /*!Update actions.*/
1324 void SalomeApp_Application::updateActions()
1326 updateCommandsStatus();
1330 QWidget* SalomeApp_Application::createWindow( const int flag )
1334 SUIT_ResourceMgr* resMgr = resourceMgr();
1336 if ( flag == WT_ObjectBrowser )
1338 OB_Browser* ob = new OB_Browser( desktop() );
1339 ob->setAutoUpdate( true );
1340 ob->setAutoOpenLevel( 1 );
1341 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1342 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1343 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1345 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1347 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1348 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1350 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1351 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1352 QString().sprintf( "visibility_column_%d", i ), true ) );
1354 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1356 // Create OBSelector
1357 new SalomeApp_OBSelector( ob, mySelMgr );
1361 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1363 else if ( flag == WT_PyConsole )
1365 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1366 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1367 pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1370 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1372 else if ( flag == WT_LogWindow )
1374 LogWindow* logWin = new LogWindow( desktop() );
1375 logWin->setCaption( tr( "LOG_WINDOW" ) );
1378 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1384 /*!Default windows(Object Browser, Python Console).
1385 * Adds to map \a aMap.
1387 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1389 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1390 aMap.insert( WT_PyConsole, Qt::DockBottom );
1391 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1394 /*!Default view manager.*/
1395 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1400 /*!Gets preferences.
1401 * Create preferences, if \a crt = true.
1403 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1408 SalomeApp_Application* that = (SalomeApp_Application*)this;
1410 if ( !_prefs_ && crt )
1412 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1413 that->createPreferences( _prefs_ );
1416 that->myPrefs = _prefs_;
1418 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1419 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1421 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1424 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1426 QStringList modNameList;
1427 app->modules( modNameList, false );
1428 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1430 int id = _prefs_->addPreference( *it );
1431 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1435 app->modules( modList );
1436 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1438 SalomeApp_Module* mod = 0;
1439 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1440 mod = (SalomeApp_Module*)itr.current();
1442 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1444 int modCat = _prefs_->addPreference( mod->moduleName() );
1445 _prefs_->setItemProperty( modCat, "info", QString::null );
1446 mod->createPreferences();
1451 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1452 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1457 /*!Add new module to application.*/
1458 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1460 CAM_Application::moduleAdded( mod );
1462 SalomeApp_Module* salomeMod = 0;
1463 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1464 salomeMod = (SalomeApp_Module*)mod;
1466 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1468 int modCat = myPrefs->addPreference( mod->moduleName() );
1469 myPrefs->setItemProperty( modCat, "info", QString::null );
1470 salomeMod->createPreferences();
1474 /*!Create preferences.*/
1475 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1480 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1482 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1483 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1484 pref->setItemProperty( studyGroup, "columns", 1 );
1486 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1487 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1488 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1489 pref->setItemProperty( undoPref, "min", 1 );
1490 pref->setItemProperty( undoPref, "max", 100 );
1492 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1493 pref->setItemProperty( extgroup, "columns", 1 );
1494 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1495 pref->setItemProperty( apppref, "existing", true );
1496 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1498 pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1500 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1501 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1502 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1506 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1507 int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1508 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1510 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1511 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1513 pref->setItemProperty( defCols, "columns", 1 );
1515 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1516 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1518 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1520 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1522 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1524 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1526 pref->setItemProperty( occGroup, "columns", 1 );
1527 pref->setItemProperty( vtkGroup, "columns", 1 );
1528 pref->setItemProperty( plot2dGroup, "columns", 1 );
1530 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1531 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1532 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1533 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1535 pref->setItemProperty( occTS, "min", 1 );
1536 pref->setItemProperty( occTS, "max", 150 );
1538 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1539 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1540 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1541 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1543 pref->setItemProperty( isoU, "min", 0 );
1544 pref->setItemProperty( isoU, "max", 100000 );
1546 pref->setItemProperty( isoV, "min", 0 );
1547 pref->setItemProperty( isoV, "max", 100000 );
1549 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1550 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1551 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1552 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1554 pref->setItemProperty( vtkTS, "min", 1 );
1555 pref->setItemProperty( vtkTS, "max", 150 );
1557 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1558 SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1560 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1561 SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" );
1562 QStringList aLegendPosList;
1563 aLegendPosList.append( tr("PREF_LEFT") );
1564 aLegendPosList.append( tr("PREF_RIGHT") );
1565 aLegendPosList.append( tr("PREF_TOP") );
1566 aLegendPosList.append( tr("PREF_BOTTOM") );
1568 QValueList<QVariant> anIndexesList;
1569 anIndexesList.append(0);
1570 anIndexesList.append(1);
1571 anIndexesList.append(2);
1572 anIndexesList.append(3);
1574 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1575 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1577 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1578 SalomeApp_Preferences::Selector, "Plot2d", "CurveType" );
1579 QStringList aCurveTypesList;
1580 aCurveTypesList.append( tr("PREF_POINTS") );
1581 aCurveTypesList.append( tr("PREF_LINES") );
1582 aCurveTypesList.append( tr("PREF_SPLINE") );
1584 anIndexesList.clear();
1585 anIndexesList.append(0);
1586 anIndexesList.append(1);
1587 anIndexesList.append(2);
1589 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1590 pref->setItemProperty( curveType, "indexes", anIndexesList );
1592 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1593 SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1595 pref->setItemProperty( markerSize, "min", 0 );
1596 pref->setItemProperty( markerSize, "max", 100 );
1598 QStringList aScaleModesList;
1599 aScaleModesList.append( tr("PREF_LINEAR") );
1600 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1602 anIndexesList.clear();
1603 anIndexesList.append(0);
1604 anIndexesList.append(1);
1606 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1607 SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1609 pref->setItemProperty( horScale, "strings", aScaleModesList );
1610 pref->setItemProperty( horScale, "indexes", anIndexesList );
1612 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1613 SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1615 pref->setItemProperty( verScale, "strings", aScaleModesList );
1616 pref->setItemProperty( verScale, "indexes", anIndexesList );
1618 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1619 SalomeApp_Preferences::Color, "Plot2d", "Background" );
1621 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1622 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1623 pref->setItemProperty( dirGroup, "columns", 1 );
1624 pref->addPreference( tr( "" ), dirGroup,
1625 SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1628 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1630 SUIT_ResourceMgr* resMgr = resourceMgr();
1634 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1636 int sz = resMgr->integerValue( sec, param, -1 );
1637 QPtrList<SUIT_ViewManager> lst;
1638 viewManagers( OCCViewer_Viewer::Type(), lst );
1639 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1641 SUIT_ViewModel* vm = it.current()->getViewModel();
1642 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1645 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1646 occVM->setTrihedronSize( sz );
1647 occVM->getAISContext()->UpdateCurrentViewer();
1651 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1653 int sz = resMgr->integerValue( sec, param, -1 );
1654 QPtrList<SUIT_ViewManager> lst;
1655 viewManagers( SVTK_Viewer::Type(), lst );
1656 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1658 SUIT_ViewModel* vm = it.current()->getViewModel();
1659 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1662 SVTK_Viewer* vtkVM = dynamic_cast<SVTK_Viewer*>( vm );
1665 vtkVM->setTrihedronSize( sz );
1671 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1673 QPtrList<SUIT_ViewManager> lst;
1674 viewManagers( OCCViewer_Viewer::Type(), lst );
1675 int u = resMgr->integerValue( sec, "iso_number_u" );
1676 int v = resMgr->integerValue( sec, "iso_number_v" );
1677 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1678 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1681 if( sec=="ObjectBrowser" )
1683 if( param=="auto_size" )
1685 OB_Browser* ob = objectBrowser();
1689 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1690 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1692 updateObjectBrowser( false );
1696 if( sec=="PyConsole" )
1699 if( pythonConsole() )
1700 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1704 /*!Update desktop title.*/
1705 void SalomeApp_Application::updateDesktopTitle() {
1706 QString aTitle = applicationName();
1707 QString aVer = applicationVersion();
1708 if ( !aVer.isEmpty() )
1709 aTitle += QString( " " ) + aVer;
1711 if ( activeStudy() )
1713 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1714 if ( !sName.isEmpty() ) {
1715 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1716 _PTR(Study) stdDS = study->studyDS();
1718 if ( stdDS->GetProperties()->IsLocked() ) {
1719 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1721 aTitle += QString( " - [%1]" ).arg( sName );
1727 desktop()->setCaption( aTitle );
1730 /*!Update windows after close document.*/
1731 void SalomeApp_Application::afterCloseDoc()
1735 CAM_Application::afterCloseDoc();
1738 /*!Gets CORBA::ORB_var*/
1739 CORBA::ORB_var SalomeApp_Application::orb()
1741 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1742 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1746 /*!Create and return SALOMEDS_StudyManager.*/
1747 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1749 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1753 /*!Create and return SALOME_NamingService.*/
1754 SALOME_NamingService* SalomeApp_Application::namingService()
1756 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1760 /*!Create and return SALOME_LifeCycleCORBA.*/
1761 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1763 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1767 QString SalomeApp_Application::defaultEngineIOR()
1769 /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1770 QString anIOR( "" );
1771 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1772 if ( !CORBA::is_nil( anEngine ) )
1773 anIOR = orb()->object_to_string( anEngine );
1777 /*!Adds icon names for modules.*/
1778 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1782 SUIT_ResourceMgr* resMgr = resourceMgr();
1786 QStringList modList;
1787 modules( modList, false );
1789 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1791 QString modName = *it;
1792 QString modIntr = moduleName( modName );
1793 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1795 if ( modIcon.isEmpty() )
1798 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1799 modIcon += QString( ".png" );
1801 iconMap.insert( modName, modIcon );
1805 /*!Update module action.*/
1806 void SalomeApp_Application::updateModuleActions()
1809 if ( activeModule() )
1810 modName = activeModule()->moduleName();
1812 if ( myActions.contains( modName ) )
1813 myActions[modName]->setOn( true );
1816 /*!Gets current windows.
1817 *\param winMap - output current windows map.
1819 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1822 if ( !activeStudy() )
1825 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1826 ((SalomeApp_Module*)activeModule())->windows( winMap );
1828 defaultWindows( winMap );
1831 /*!Gets current view managers.
1832 *\param lst - output current view managers list.
1834 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1837 if ( !activeStudy() )
1840 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1841 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1843 defaultViewManagers( lst );
1846 /*!Update windows.*/
1847 void SalomeApp_Application::updateWindows()
1849 QMap<int, int> winMap;
1850 currentWindows( winMap );
1852 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1853 getWindow( it.key() );
1855 loadWindowsGeometry();
1857 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1858 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1861 /*!Update view managers.*/
1862 void SalomeApp_Application::updateViewManagers()
1865 currentViewManagers( lst );
1867 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1868 getViewManager( *it, true );
1871 /*!Load windows geometry.*/
1872 void SalomeApp_Application::loadWindowsGeometry()
1874 QtxDockAction* dockMgr = 0;
1876 QAction* a = action( ViewWindowsId );
1877 if ( a && a->inherits( "QtxDockAction" ) )
1878 dockMgr = (QtxDockAction*)a;
1884 if ( activeModule() )
1885 modName = activeModule()->name("");
1887 QString section = QString( "windows_geometry" );
1888 if ( !modName.isEmpty() )
1889 section += QString( "." ) + modName;
1891 dockMgr->loadGeometry( resourceMgr(), section, false );
1892 dockMgr->restoreGeometry();
1895 /*!Save windows geometry.*/
1896 void SalomeApp_Application::saveWindowsGeometry()
1898 QtxDockAction* dockMgr = 0;
1900 QAction* a = action( ViewWindowsId );
1901 if ( a && a->inherits( "QtxDockAction" ) )
1902 dockMgr = (QtxDockAction*)a;
1908 if ( activeModule() )
1909 modName = activeModule()->name("");
1911 QString section = QString( "windows_geometry" );
1912 if ( !modName.isEmpty() )
1913 section += QString( "." ) + modName;
1915 dockMgr->storeGeometry();
1916 dockMgr->saveGeometry( resourceMgr(), section, false );
1919 /*!Activate windows.*/
1920 void SalomeApp_Application::activateWindows()
1922 if ( activeStudy() )
1924 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1925 itr.data()->activate( activeStudy()->id() );
1929 /*!Private SLOT. On preferences.*/
1930 void SalomeApp_Application::onProperties()
1932 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1936 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1939 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1940 int res = aDlg.exec();
1941 if( res==QDialog::Accepted && aDlg.isChanged() )
1942 SB->CommitCommand();
1946 //study->updateCaptions();
1947 updateDesktopTitle();
1952 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1953 const QString& caption, QWidget* parent )
1957 QStringList fls = QStringList::split( ";;", filters, false );
1958 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1962 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1966 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1970 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1971 const QString& caption, QWidget* parent )
1975 QStringList fls = QStringList::split( ";;", filters, false );
1976 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1980 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1982 CAM_Application::contextMenuPopup( type, thePopup, title );
1984 OB_Browser* ob = objectBrowser();
1985 if ( !ob || type != ob->popupClientType() )
1988 thePopup->insertSeparator();
1989 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1991 // Get selected objects
1992 SALOME_ListIO aList;
1993 SalomeApp_SelectionMgr* mgr = selectionMgr();
1994 mgr->selectedObjects(aList);
1996 // "Delete reference" item should appear only for invalid references
1998 // Check if selected objects is invalid references
1999 bool isInvalidRefs = true;
2001 if ( aList.Extent() < 1 )
2002 isInvalidRefs = false;
2004 if ( isInvalidRefs )
2006 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
2007 _PTR(Study) aStudyDS = aStudy->studyDS();
2008 _PTR(SObject) anObj;
2010 for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() )
2012 if ( it.Value()->hasEntry() )
2014 _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
2015 if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() )
2016 isInvalidRefs = false;
2021 // Add "Delete refrence" item to popup
2022 if ( isInvalidRefs )
2024 thePopup->insertSeparator();
2025 thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) );
2029 // "Activate module" item should appear only if it's necessary
2030 if (aList.Extent() != 1)
2032 Handle(SALOME_InteractiveObject) aIObj = aList.First();
2033 QString aModuleName(aIObj->getComponentDataType());
2034 QString aModuleTitle = moduleTitle(aModuleName);
2035 CAM_Module* currentModule = activeModule();
2036 if (currentModule && currentModule->moduleName() == aModuleTitle)
2038 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
2042 /*!Update obect browser*/
2043 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
2045 // update existing data models (already loaded SComponents)
2048 for ( ModuleListIterator it = modules(); it.current(); ++it )
2050 CAM_DataModel* camDM = it.current()->dataModel();
2051 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
2052 ((SalomeApp_DataModel*)camDM)->update();
2055 // update "non-existing" (not loaded yet) data models
2056 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
2059 _PTR(Study) stdDS = study->studyDS();
2062 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
2064 _PTR(SComponent) aComponent ( it->Value() );
2066 if ( aComponent->ComponentDataType() == "Interface Applicative" )
2067 continue; // skip the magic "Interface Applicative" component
2069 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
2074 if ( objectBrowser() )
2076 objectBrowser()->updateGeometry();
2077 objectBrowser()->updateTree();
2081 /*!Protected SLOT.On desktop activated.*/
2082 void SalomeApp_Application::onDesktopActivated()
2084 CAM_Application::onDesktopActivated();
2085 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
2087 aModule->studyActivated();
2090 /*!Create empty study.*/
2091 void SalomeApp_Application::createEmptyStudy()
2093 CAM_Application::createEmptyStudy();
2094 if ( objectBrowser() )
2095 objectBrowser()->updateTree();
2098 /*!Activate module \a mod.*/
2099 bool SalomeApp_Application::activateModule( CAM_Module* mod )
2101 bool res = CAM_Application::activateModule( mod );
2102 if ( objectBrowser() )
2103 objectBrowser()->updateTree();
2107 /*!Display Catalog Genenerator dialog */
2108 void SalomeApp_Application::onCatalogGen()
2110 ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
2114 /*!Display Registry Display dialog */
2115 void SalomeApp_Application::onRegDisplay()
2117 CORBA::ORB_var anOrb = orb();
2118 ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
2121 regWnd->setActiveWindow();
2124 /*!return keyborad accelerators manager object */
2125 SUIT_Accel* SalomeApp_Application::accel() const