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, VTKViewer_Viewer::Type() );
170 myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() );
171 myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() );
172 myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() );
173 myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() );
174 myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() );
175 myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() );
176 myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() );
177 myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() );
178 myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() );
179 myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_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 = VTKViewer_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(studyMgr()->CanCopy(so) ) qaction->setEnabled(true);
759 else qaction->setEnabled(false);
761 qaction = action(EditPasteId);
762 if( 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 = (SVTK_Viewer*)viewMgr->getViewModel();
1132 vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) );
1133 vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) );
1134 new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr);
1140 addViewManager( viewMgr );
1141 SUIT_ViewWindow* viewWin = viewMgr->createViewWindow();
1143 if ( viewWin && desktop() )
1144 viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) );
1146 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1147 this, SLOT( onCloseView( SUIT_ViewManager* ) ) );
1152 void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM )
1154 removeViewManager( theVM );
1157 /*!Private SLOT. On study created.*/
1158 void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy )
1160 SUIT_DataObject* aRoot = 0;
1161 if ( theStudy && theStudy->root() )
1163 aRoot = theStudy->root();
1164 //aRoot->setName( tr( "DATA_MODELS" ) );
1166 if ( objectBrowser() != 0 )
1167 objectBrowser()->setRootObject( aRoot );
1169 activateModule( defaultModule() );
1174 /*!Private SLOT. On study opened.*/
1175 void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy )
1177 SUIT_DataObject* aRoot = 0;
1178 if ( theStudy && theStudy->root() )
1180 aRoot = theStudy->root();
1183 if ( objectBrowser() != 0 ) {
1184 objectBrowser()->setRootObject( aRoot );
1187 activateModule( defaultModule() );
1194 void SalomeApp_Application::onStudySaved( SUIT_Study* )
1199 /*!Private SLOT. On study closed.*/
1200 void SalomeApp_Application::onStudyClosed( SUIT_Study* )
1204 activateModule( "" );
1206 saveWindowsGeometry();
1209 /*!Private SLOT. On dump study.*/
1210 void SalomeApp_Application::onDumpStudy( )
1212 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1213 if ( !appStudy ) return;
1214 _PTR(Study) aStudy = appStudy->studyDS();
1216 QStringList aFilters;
1217 aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
1219 SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
1220 fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
1221 fd->setFilters( aFilters );
1222 fd->SetChecked(true);
1224 QString aFileName = fd->selectedFile();
1225 bool toPublish = fd->IsChecked();
1228 if(!aFileName.isEmpty()) {
1229 QFileInfo aFileInfo(aFileName);
1230 aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
1234 /*!Private SLOT. On load script.*/
1235 void SalomeApp_Application::onLoadScript( )
1237 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1238 if ( !appStudy ) return;
1239 _PTR(Study) aStudy = appStudy->studyDS();
1241 if ( aStudy->GetProperties()->IsLocked() ) {
1242 SUIT_MessageBox::warn1 ( desktop(),
1243 QObject::tr("WRN_WARNING"),
1244 QObject::tr("WRN_STUDY_LOCKED"),
1245 QObject::tr("BUT_OK") );
1249 QStringList filtersList;
1250 filtersList.append(tr("PYTHON_FILES_FILTER"));
1251 filtersList.append(tr("ALL_FILES_FILTER"));
1253 QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
1255 if ( !aFile.isEmpty() )
1257 QString command = QString("execfile(\"%1\")").arg(aFile);
1259 PythonConsole* pyConsole = pythonConsole();
1262 pyConsole->exec( command );
1266 /*!Private SLOT. On preferences.*/
1267 void SalomeApp_Application::onPreferences()
1269 QApplication::setOverrideCursor( Qt::waitCursor );
1271 SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop());
1273 QApplication::restoreOverrideCursor();
1283 /*!Private SLOT. On open document with name \a aName.*/
1284 void SalomeApp_Application::onMRUActivated( QString aName )
1289 /*!Private SLOT. On preferences changed.*/
1290 void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param )
1292 SalomeApp_Module* sMod = 0;
1293 CAM_Module* mod = module( modName );
1294 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1295 sMod = (SalomeApp_Module*)mod;
1298 sMod->preferencesChanged( section, param );
1300 preferencesChanged( section, param );
1303 /*!Gets file filter.
1304 *\retval QString "(*.hdf)"
1306 QString SalomeApp_Application::getFileFilter() const
1311 /*!Remove all windows from study.*/
1312 void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s )
1314 CAM_Application::beforeCloseDoc( s );
1316 for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr )
1317 removeWindow( itr.key(), s->id() );
1320 /*!Update actions.*/
1321 void SalomeApp_Application::updateActions()
1323 updateCommandsStatus();
1327 QWidget* SalomeApp_Application::createWindow( const int flag )
1331 SUIT_ResourceMgr* resMgr = resourceMgr();
1333 if ( flag == WT_ObjectBrowser )
1335 OB_Browser* ob = new OB_Browser( desktop() );
1336 ob->setAutoUpdate( true );
1337 ob->setAutoOpenLevel( 1 );
1338 ob->setCaption( tr( "OBJECT_BROWSER" ) );
1339 ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
1340 ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
1342 ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
1344 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1345 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1347 ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
1348 ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
1349 QString().sprintf( "visibility_column_%d", i ), true ) );
1351 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1353 // Create OBSelector
1354 new SalomeApp_OBSelector( ob, mySelMgr );
1358 ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1360 else if ( flag == WT_PyConsole )
1362 PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
1363 pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
1364 pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1367 // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1369 else if ( flag == WT_LogWindow )
1371 LogWindow* logWin = new LogWindow( desktop() );
1372 logWin->setCaption( tr( "LOG_WINDOW" ) );
1375 logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
1381 /*!Default windows(Object Browser, Python Console).
1382 * Adds to map \a aMap.
1384 void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
1386 aMap.insert( WT_ObjectBrowser, Qt::DockLeft );
1387 aMap.insert( WT_PyConsole, Qt::DockBottom );
1388 // aMap.insert( WT_LogWindow, Qt::DockBottom );
1391 /*!Default view manager.*/
1392 void SalomeApp_Application::defaultViewManagers( QStringList& ) const
1397 /*!Gets preferences.
1398 * Create preferences, if \a crt = true.
1400 SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const
1405 SalomeApp_Application* that = (SalomeApp_Application*)this;
1407 if ( !_prefs_ && crt )
1409 _prefs_ = new SalomeApp_Preferences( resourceMgr() );
1410 that->createPreferences( _prefs_ );
1413 that->myPrefs = _prefs_;
1415 QPtrList<SUIT_Application> appList = SUIT_Session::session()->applications();
1416 for ( QPtrListIterator<SUIT_Application> appIt ( appList ); appIt.current(); ++appIt )
1418 if ( !appIt.current()->inherits( "SalomeApp_Application" ) )
1421 SalomeApp_Application* app = (SalomeApp_Application*)appIt.current();
1423 QStringList modNameList;
1424 app->modules( modNameList, false );
1425 for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it )
1427 int id = _prefs_->addPreference( *it );
1428 _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) );
1432 app->modules( modList );
1433 for ( ModuleListIterator itr( modList ); itr.current(); ++itr )
1435 SalomeApp_Module* mod = 0;
1436 if ( itr.current()->inherits( "SalomeApp_Module" ) )
1437 mod = (SalomeApp_Module*)itr.current();
1439 if ( mod && !_prefs_->hasModule( mod->moduleName() ) )
1441 int modCat = _prefs_->addPreference( mod->moduleName() );
1442 _prefs_->setItemProperty( modCat, "info", QString::null );
1443 mod->createPreferences();
1448 connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ),
1449 this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) );
1454 /*!Add new module to application.*/
1455 void SalomeApp_Application::moduleAdded( CAM_Module* mod )
1457 CAM_Application::moduleAdded( mod );
1459 SalomeApp_Module* salomeMod = 0;
1460 if ( mod && mod->inherits( "SalomeApp_Module" ) )
1461 salomeMod = (SalomeApp_Module*)mod;
1463 if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) )
1465 int modCat = myPrefs->addPreference( mod->moduleName() );
1466 myPrefs->setItemProperty( modCat, "info", QString::null );
1467 salomeMod->createPreferences();
1471 /*!Create preferences.*/
1472 void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref )
1477 int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
1479 int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat );
1480 int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab );
1481 pref->setItemProperty( studyGroup, "columns", 1 );
1483 pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" );
1484 pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" );
1485 int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" );
1486 pref->setItemProperty( undoPref, "min", 1 );
1487 pref->setItemProperty( undoPref, "max", 100 );
1489 int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab );
1490 pref->setItemProperty( extgroup, "columns", 1 );
1491 int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" );
1492 pref->setItemProperty( apppref, "existing", true );
1493 pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser );
1495 pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" );
1497 int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab );
1498 pref->setItemProperty( pythonConsoleGroup, "columns", 1 );
1499 pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" );
1503 int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
1504 int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
1505 for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
1507 pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
1508 SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
1510 pref->setItemProperty( defCols, "columns", 1 );
1512 int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
1513 pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
1515 int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat );
1517 int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab );
1519 int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab );
1521 int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab );
1523 pref->setItemProperty( occGroup, "columns", 1 );
1524 pref->setItemProperty( vtkGroup, "columns", 1 );
1525 pref->setItemProperty( plot2dGroup, "columns", 1 );
1527 int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup,
1528 SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" );
1529 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup,
1530 SalomeApp_Preferences::Color, "OCCViewer", "background" );
1532 pref->setItemProperty( occTS, "min", 1 );
1533 pref->setItemProperty( occTS, "max", 150 );
1535 int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup,
1536 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" );
1537 int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup,
1538 SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" );
1540 pref->setItemProperty( isoU, "min", 0 );
1541 pref->setItemProperty( isoU, "max", 100000 );
1543 pref->setItemProperty( isoV, "min", 0 );
1544 pref->setItemProperty( isoV, "max", 100000 );
1546 int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup,
1547 SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" );
1548 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup,
1549 SalomeApp_Preferences::Color, "VTKViewer", "background" );
1551 pref->setItemProperty( vtkTS, "min", 1 );
1552 pref->setItemProperty( vtkTS, "max", 150 );
1554 pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup,
1555 SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" );
1557 int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup,
1558 SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" );
1559 QStringList aLegendPosList;
1560 aLegendPosList.append( tr("PREF_LEFT") );
1561 aLegendPosList.append( tr("PREF_RIGHT") );
1562 aLegendPosList.append( tr("PREF_TOP") );
1563 aLegendPosList.append( tr("PREF_BOTTOM") );
1565 QValueList<QVariant> anIndexesList;
1566 anIndexesList.append(0);
1567 anIndexesList.append(1);
1568 anIndexesList.append(2);
1569 anIndexesList.append(3);
1571 pref->setItemProperty( legendPosition, "strings", aLegendPosList );
1572 pref->setItemProperty( legendPosition, "indexes", anIndexesList );
1574 int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup,
1575 SalomeApp_Preferences::Selector, "Plot2d", "CurveType" );
1576 QStringList aCurveTypesList;
1577 aCurveTypesList.append( tr("PREF_POINTS") );
1578 aCurveTypesList.append( tr("PREF_LINES") );
1579 aCurveTypesList.append( tr("PREF_SPLINE") );
1581 anIndexesList.clear();
1582 anIndexesList.append(0);
1583 anIndexesList.append(1);
1584 anIndexesList.append(2);
1586 pref->setItemProperty( curveType, "strings", aCurveTypesList );
1587 pref->setItemProperty( curveType, "indexes", anIndexesList );
1589 int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup,
1590 SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" );
1592 pref->setItemProperty( markerSize, "min", 0 );
1593 pref->setItemProperty( markerSize, "max", 100 );
1595 QStringList aScaleModesList;
1596 aScaleModesList.append( tr("PREF_LINEAR") );
1597 aScaleModesList.append( tr("PREF_LOGARITHMIC") );
1599 anIndexesList.clear();
1600 anIndexesList.append(0);
1601 anIndexesList.append(1);
1603 int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup,
1604 SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" );
1606 pref->setItemProperty( horScale, "strings", aScaleModesList );
1607 pref->setItemProperty( horScale, "indexes", anIndexesList );
1609 int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup,
1610 SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" );
1612 pref->setItemProperty( verScale, "strings", aScaleModesList );
1613 pref->setItemProperty( verScale, "indexes", anIndexesList );
1615 pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup,
1616 SalomeApp_Preferences::Color, "Plot2d", "Background" );
1618 int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat );
1619 int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab );
1620 pref->setItemProperty( dirGroup, "columns", 1 );
1621 pref->addPreference( tr( "" ), dirGroup,
1622 SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" );
1625 void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param )
1627 SUIT_ResourceMgr* resMgr = resourceMgr();
1631 if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) )
1633 int sz = resMgr->integerValue( sec, param, -1 );
1634 QPtrList<SUIT_ViewManager> lst;
1635 viewManagers( OCCViewer_Viewer::Type(), lst );
1636 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1638 SUIT_ViewModel* vm = it.current()->getViewModel();
1639 if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) )
1642 OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm;
1643 occVM->setTrihedronSize( sz );
1644 occVM->getAISContext()->UpdateCurrentViewer();
1648 if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) )
1650 int sz = resMgr->integerValue( sec, param, -1 );
1651 QPtrList<SUIT_ViewManager> lst;
1652 viewManagers( SVTK_Viewer::Type(), lst );
1653 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current() && sz >= 0; ++it )
1655 SUIT_ViewModel* vm = it.current()->getViewModel();
1656 if ( !vm || !vm->inherits( "SVTK_Viewer" ) )
1659 SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm;
1660 vtkVM->setTrihedronSize( sz );
1665 if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) )
1667 QPtrList<SUIT_ViewManager> lst;
1668 viewManagers( OCCViewer_Viewer::Type(), lst );
1669 int u = resMgr->integerValue( sec, "iso_number_u" );
1670 int v = resMgr->integerValue( sec, "iso_number_v" );
1671 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it )
1672 ((OCCViewer_Viewer*)it.current())->setIsos( u, v );
1675 if( sec=="ObjectBrowser" )
1677 if( param=="auto_size" )
1679 OB_Browser* ob = objectBrowser();
1683 bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
1684 ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
1686 updateObjectBrowser( false );
1690 if( sec=="PyConsole" )
1693 if( pythonConsole() )
1694 pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) );
1698 /*!Update desktop title.*/
1699 void SalomeApp_Application::updateDesktopTitle() {
1700 QString aTitle = applicationName();
1701 QString aVer = applicationVersion();
1702 if ( !aVer.isEmpty() )
1703 aTitle += QString( " " ) + aVer;
1705 if ( activeStudy() )
1707 QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
1708 if ( !sName.isEmpty() ) {
1709 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
1710 _PTR(Study) stdDS = study->studyDS();
1712 if ( stdDS->GetProperties()->IsLocked() ) {
1713 aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
1715 aTitle += QString( " - [%1]" ).arg( sName );
1721 desktop()->setCaption( aTitle );
1724 /*!Update windows after close document.*/
1725 void SalomeApp_Application::afterCloseDoc()
1729 CAM_Application::afterCloseDoc();
1732 /*!Gets CORBA::ORB_var*/
1733 CORBA::ORB_var SalomeApp_Application::orb()
1735 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
1736 static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
1740 /*!Create and return SALOMEDS_StudyManager.*/
1741 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
1743 static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
1747 /*!Create and return SALOME_NamingService.*/
1748 SALOME_NamingService* SalomeApp_Application::namingService()
1750 static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
1754 /*!Create and return SALOME_LifeCycleCORBA.*/
1755 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
1757 static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
1761 QString SalomeApp_Application::defaultEngineIOR()
1763 /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
1764 QString anIOR( "" );
1765 CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
1766 if ( !CORBA::is_nil( anEngine ) )
1767 anIOR = orb()->object_to_string( anEngine );
1771 /*!Adds icon names for modules.*/
1772 void SalomeApp_Application::moduleIconNames( QMap<QString, QString>& iconMap ) const
1776 SUIT_ResourceMgr* resMgr = resourceMgr();
1780 QStringList modList;
1781 modules( modList, false );
1783 for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it )
1785 QString modName = *it;
1786 QString modIntr = moduleName( modName );
1787 QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null );
1789 if ( modIcon.isEmpty() )
1792 if ( SUIT_Tools::extension( modIcon ).isEmpty() )
1793 modIcon += QString( ".png" );
1795 iconMap.insert( modName, modIcon );
1799 /*!Update module action.*/
1800 void SalomeApp_Application::updateModuleActions()
1803 if ( activeModule() )
1804 modName = activeModule()->moduleName();
1806 if ( myActions.contains( modName ) )
1807 myActions[modName]->setOn( true );
1810 /*!Gets current windows.
1811 *\param winMap - output current windows map.
1813 void SalomeApp_Application::currentWindows( QMap<int, int>& winMap ) const
1816 if ( !activeStudy() )
1819 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1820 ((SalomeApp_Module*)activeModule())->windows( winMap );
1822 defaultWindows( winMap );
1825 /*!Gets current view managers.
1826 *\param lst - output current view managers list.
1828 void SalomeApp_Application::currentViewManagers( QStringList& lst ) const
1831 if ( !activeStudy() )
1834 if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) )
1835 ((SalomeApp_Module*)activeModule())->viewManagers( lst );
1837 defaultViewManagers( lst );
1840 /*!Update windows.*/
1841 void SalomeApp_Application::updateWindows()
1843 QMap<int, int> winMap;
1844 currentWindows( winMap );
1846 for ( QMap<int, int>::ConstIterator it = winMap.begin(); it != winMap.end(); ++it )
1847 getWindow( it.key() );
1849 loadWindowsGeometry();
1851 for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1852 setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) );
1855 /*!Update view managers.*/
1856 void SalomeApp_Application::updateViewManagers()
1859 currentViewManagers( lst );
1861 for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
1862 getViewManager( *it, true );
1865 /*!Load windows geometry.*/
1866 void SalomeApp_Application::loadWindowsGeometry()
1868 QtxDockAction* dockMgr = 0;
1870 QAction* a = action( ViewWindowsId );
1871 if ( a && a->inherits( "QtxDockAction" ) )
1872 dockMgr = (QtxDockAction*)a;
1878 if ( activeModule() )
1879 modName = moduleLibrary( activeModule()->moduleName(), false );
1881 QString section = QString( "windows_geometry" );
1882 if ( !modName.isEmpty() )
1883 section += QString( "." ) + modName;
1885 dockMgr->loadGeometry( resourceMgr(), section, false );
1886 dockMgr->restoreGeometry();
1889 /*!Save windows geometry.*/
1890 void SalomeApp_Application::saveWindowsGeometry()
1892 QtxDockAction* dockMgr = 0;
1894 QAction* a = action( ViewWindowsId );
1895 if ( a && a->inherits( "QtxDockAction" ) )
1896 dockMgr = (QtxDockAction*)a;
1902 if ( activeModule() )
1903 modName = moduleLibrary( activeModule()->moduleName(), false );
1905 QString section = QString( "windows_geometry" );
1906 if ( !modName.isEmpty() )
1907 section += QString( "." ) + modName;
1909 dockMgr->storeGeometry();
1910 dockMgr->saveGeometry( resourceMgr(), section, false );
1913 /*!Activate windows.*/
1914 void SalomeApp_Application::activateWindows()
1916 if ( activeStudy() )
1918 for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr )
1919 itr.data()->activate( activeStudy()->id() );
1923 /*!Private SLOT. On preferences.*/
1924 void SalomeApp_Application::onProperties()
1926 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
1930 _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
1933 SalomeApp_StudyPropertiesDlg aDlg( desktop() );
1934 int res = aDlg.exec();
1935 if( res==QDialog::Accepted && aDlg.isChanged() )
1936 SB->CommitCommand();
1940 //study->updateCaptions();
1941 updateDesktopTitle();
1946 QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters,
1947 const QString& caption, QWidget* parent )
1951 QStringList fls = QStringList::split( ";;", filters, false );
1952 return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true );
1956 QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent )
1960 return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true );
1964 QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters,
1965 const QString& caption, QWidget* parent )
1969 QStringList fls = QStringList::split( ";;", filters, false );
1970 return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true );
1974 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
1976 CAM_Application::contextMenuPopup( type, thePopup, title );
1978 OB_Browser* ob = objectBrowser();
1979 if ( !ob || type != ob->popupClientType() )
1982 thePopup->insertSeparator();
1983 thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
1985 // Get selected objects
1986 SALOME_ListIO aList;
1987 SalomeApp_SelectionMgr* mgr = selectionMgr();
1988 mgr->selectedObjects(aList);
1990 // "Delete reference" item should appear only for invalid references
1992 // Check if selected objects is invalid references
1993 bool isInvalidRefs = true;
1995 if ( aList.Extent() < 1 )
1996 isInvalidRefs = false;
1998 if ( isInvalidRefs )
2000 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
2001 _PTR(Study) aStudyDS = aStudy->studyDS();
2002 _PTR(SObject) anObj;
2004 for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() )
2006 if ( it.Value()->hasEntry() )
2008 _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
2009 if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() )
2010 isInvalidRefs = false;
2015 // Add "Delete refrence" item to popup
2016 if ( isInvalidRefs )
2018 thePopup->insertSeparator();
2019 thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) );
2023 // "Activate module" item should appear only if it's necessary
2024 if (aList.Extent() != 1)
2026 Handle(SALOME_InteractiveObject) aIObj = aList.First();
2027 QString aModuleName(aIObj->getComponentDataType());
2028 QString aModuleTitle = moduleTitle(aModuleName);
2029 CAM_Module* currentModule = activeModule();
2030 if (currentModule && currentModule->moduleName() == aModuleTitle)
2032 thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
2036 /*!Update obect browser*/
2037 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
2039 // update existing data models (already loaded SComponents)
2042 for ( ModuleListIterator it = modules(); it.current(); ++it )
2044 CAM_DataModel* camDM = it.current()->dataModel();
2045 if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) )
2046 ((SalomeApp_DataModel*)camDM)->update();
2049 // update "non-existing" (not loaded yet) data models
2050 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
2053 _PTR(Study) stdDS = study->studyDS();
2056 for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )
2058 _PTR(SComponent) aComponent ( it->Value() );
2060 if ( aComponent->ComponentDataType() == "Interface Applicative" )
2061 continue; // skip the magic "Interface Applicative" component
2063 SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
2068 if ( objectBrowser() )
2070 objectBrowser()->updateGeometry();
2071 objectBrowser()->updateTree();
2075 /*!Protected SLOT.On desktop activated.*/
2076 void SalomeApp_Application::onDesktopActivated()
2078 CAM_Application::onDesktopActivated();
2079 SalomeApp_Module* aModule = dynamic_cast<SalomeApp_Module*>(activeModule());
2081 aModule->studyActivated();
2084 /*!Create empty study.*/
2085 void SalomeApp_Application::createEmptyStudy()
2087 CAM_Application::createEmptyStudy();
2088 if ( objectBrowser() )
2089 objectBrowser()->updateTree();
2092 /*!Activate module \a mod.*/
2093 bool SalomeApp_Application::activateModule( CAM_Module* mod )
2095 bool res = CAM_Application::activateModule( mod );
2096 if ( objectBrowser() )
2097 objectBrowser()->updateTree();
2101 /*!Display Catalog Genenerator dialog */
2102 void SalomeApp_Application::onCatalogGen()
2104 ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
2108 /*!Display Registry Display dialog */
2109 void SalomeApp_Application::onRegDisplay()
2111 CORBA::ORB_var anOrb = orb();
2112 ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
2115 regWnd->setActiveWindow();
2118 /*!return keyborad accelerators manager object */
2119 SUIT_Accel* SalomeApp_Application::accel() const