From 1559a651a19d4529d4079141ce0b5c7710f4cf01 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 15 Sep 2005 14:01:30 +0000 Subject: [PATCH] *** empty log message *** --- src/SalomeApp/Makefile.in | 65 +- src/SalomeApp/SalomeApp_Application.cxx | 1702 ++--------------------- src/SalomeApp/SalomeApp_Application.h | 142 +- src/SalomeApp/SalomeApp_DataModel.cxx | 234 +--- src/SalomeApp/SalomeApp_DataModel.h | 39 +- src/SalomeApp/SalomeApp_DataObject.cxx | 79 +- src/SalomeApp/SalomeApp_DataObject.h | 7 +- src/SalomeApp/SalomeApp_Module.cxx | 316 +---- src/SalomeApp/SalomeApp_Module.h | 89 +- src/SalomeApp/SalomeApp_PyInterp.cxx | 32 +- src/SalomeApp/SalomeApp_PyInterp.h | 2 + src/SalomeApp/SalomeApp_Study.cxx | 271 ++-- src/SalomeApp/SalomeApp_Study.h | 17 +- src/SalomeApp/SalomeApp_TypeFilter.cxx | 4 +- 14 files changed, 414 insertions(+), 2585 deletions(-) diff --git a/src/SalomeApp/Makefile.in b/src/SalomeApp/Makefile.in index fb914ced0..3c95964be 100755 --- a/src/SalomeApp/Makefile.in +++ b/src/SalomeApp/Makefile.in @@ -13,38 +13,19 @@ VPATH=.:@srcdir@:@srcdir@/resources # header files EXPORT_HEADERS= SalomeApp.h \ - SalomeApp_AboutDlg.h \ SalomeApp_Application.h \ SalomeApp_DataModel.h \ SalomeApp_DataObject.h \ - SalomeApp_DataOwner.h \ - SalomeApp_OCCSelector.h \ - SalomeApp_VTKSelector.h \ - SalomeApp_OBSelector.h \ - SalomeApp_GLSelector.h \ SalomeApp_Module.h \ SalomeApp_Study.h \ - SalomeApp_WidgetContainer.h \ SalomeApp_ExceptionHandler.h \ - SalomeApp_RootObject.h \ - SalomeApp_SelectionMgr.h \ SalomeApp_EventFilter.h \ - SalomeApp_Preferences.h \ - SalomeApp_PreferencesDlg.h \ SalomeApp_Tools.h \ - SalomeApp_NameDlg.h \ SalomeApp_ImportOperation.h \ - SalomeApp_DataSubOwner.h \ - SalomeApp_Selection.h \ SalomeApp_Filter.h \ SalomeApp_TypeFilter.h \ - SalomeApp_OBFilter.h \ SalomeApp_StudyPropertiesDlg.h \ - SalomeApp_CheckFileDlg.h \ - SalomeApp_Operation.h \ - SalomeApp_Dialog.h \ - SalomeApp_UpdateFlags.h \ - SalomeApp_SwitchOp.cxx + SalomeApp_CheckFileDlg.h # .po files to transform in .qm PO_FILES = SalomeApp_images.po \ @@ -54,78 +35,40 @@ PO_FILES = SalomeApp_images.po \ LIB = libSalomeApp.la LIB_SRC= SalomeApp_Module.cxx \ - SalomeApp_AboutDlg.cxx \ SalomeApp_Application.cxx \ SalomeApp_DataModel.cxx \ SalomeApp_DataObject.cxx \ - SalomeApp_DataOwner.cxx \ - SalomeApp_OCCSelector.cxx \ - SalomeApp_VTKSelector.cxx \ - SalomeApp_OBSelector.cxx \ - SalomeApp_GLSelector.cxx \ SalomeApp_Study.cxx \ - SalomeApp_WidgetContainer.cxx \ SalomeApp_ExceptionHandler.cxx \ - SalomeApp_SelectionMgr.cxx \ SalomeApp_EventFilter.cxx \ - SalomeApp_Preferences.cxx \ - SalomeApp_PreferencesDlg.cxx \ SalomeApp_PyInterp.cxx \ SalomeApp_Tools.cxx \ - SalomeApp_NameDlg.cxx \ SalomeApp_ImportOperation.cxx \ - SalomeApp_DataSubOwner.cxx \ - SalomeApp_ModuleDlg.cxx \ - SalomeApp_Selection.cxx \ SalomeApp_Filter.cxx \ SalomeApp_TypeFilter.cxx \ - SalomeApp_OBFilter.cxx \ SalomeApp_StudyPropertiesDlg.cxx \ SalomeApp_ListView.cxx \ SalomeApp_CheckFileDlg.cxx \ - SalomeApp_Operation.cxx \ - SalomeApp_Dialog.cxx \ - SalomeApp_SwitchOp.cxx -LIB_MOC = SalomeApp_AboutDlg.h \ - SalomeApp_Application.h \ +LIB_MOC = SalomeApp_Application.h \ SalomeApp_DataModel.h \ - SalomeApp_OBSelector.h \ - SalomeApp_OCCSelector.h \ - SalomeApp_VTKSelector.h \ - SalomeApp_GLSelector.h \ SalomeApp_Module.h \ SalomeApp_Study.h \ - SalomeApp_SelectionMgr.h \ - SalomeApp_WidgetContainer.h \ - SalomeApp_Preferences.h \ - SalomeApp_PreferencesDlg.h \ - SalomeApp_NameDlg.h \ - SalomeApp_ModuleDlg.h \ SalomeApp_StudyPropertiesDlg.h \ SalomeApp_ListView.h \ SalomeApp_CheckFileDlg.h \ - SalomeApp_Operation.h \ - SalomeApp_Dialog.h \ - SalomeApp_SwitchOp.h LIB_CLIENT_IDL = SALOMEDS.idl \ SALOME_Exception.idl \ SALOME_GenericObj.idl -RESOURCES_FILES = icon_about.png \ - icon_applogo.png \ - icon_default.png \ - icon_module.png \ - icon_module_big.png \ - icon_select.png \ - SalomeApp.ini \ +RESOURCES_FILES = SalomeApp.ini \ SalomeApp.xml CPPFLAGS+=$(PYTHON_INCLUDES) $(QT_INCLUDES) $(QWT_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(BOOST_CPPFLAGS) -I${KERNEL_ROOT_DIR}/include/salome LDFLAGS+=$(PYTHON_LIBS) $(QT_MT_LIBS) -LIBS+= -lsuit -lstd -lCAM -lObjBrowser -L$(KERNEL_ROOT_DIR)/lib/salome -lOpUtil -lSALOMELocalTrace $(CAS_KERNEL) -lSPlot2d -lGLViewer -lOCCViewer -lVTKViewer -lSalomeObject -lSVTK -lSOCC -lPyInterp -lPythonConsole -lLogWindow -lSalomeContainer -lToolsGUI +LIBS+= -lsuit -lstd -lCAM -lObjBrowser -L$(KERNEL_ROOT_DIR)/lib/salome -lOpUtil -lSALOMELocalTrace $(CAS_KERNEL) -lSPlot2d -lGLViewer -lOCCViewer -lVTKViewer -lSalomeObject -lSVTK -lSOCC -lPyInterp -lPythonConsole -lLogWindow -lLightApp -lSalomeContainer -lToolsGUI @CONCLUDE@ diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 742ecab76..ceb036777 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -9,51 +9,23 @@ #include "SalomeApp_Study.h" #include "SalomeApp_Module.h" -#include "SalomeApp_OBFilter.h" #include "SalomeApp_DataModel.h" #include "SalomeApp_DataObject.h" #include "SalomeApp_EventFilter.h" -#include "SalomeApp_WidgetContainer.h" -#include "SalomeApp_AboutDlg.h" -#include "SalomeApp_ModuleDlg.h" -#include "SalomeApp_Preferences.h" -#include "SalomeApp_PreferencesDlg.h" #include "SalomeApp_StudyPropertiesDlg.h" -#include "SalomeApp_CheckFileDlg.h" - -#include "SalomeApp_GLSelector.h" -#include "SalomeApp_OBSelector.h" -#include "SalomeApp_OCCSelector.h" -#include "SalomeApp_VTKSelector.h" -#include "SalomeApp_SelectionMgr.h" - -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include +#include "SalomeApp_CheckFileDlg.h" -#include +#include "LightApp_Application.h" +#include "LightApp_Preferences.h" +#include "LightApp_WidgetContainer.h" +#include "LightApp_SelectionMgr.h" #include "STD_LoadStudiesDlg.h" #include #include -#include - -#include -#include -#include -#include #include @@ -70,18 +42,13 @@ #include #include -#include -#include -#include #include -#include #include -#include -#include #include #include #include "SALOMEDS_StudyManager.hxx" +#include "SALOMEDS_SObject.hxx" #include "SALOME_ListIteratorOfListIO.hxx" #include "SALOME_ListIO.hxx" @@ -91,240 +58,50 @@ #define OBJECT_BROWSER_WIDTH 300 -/*!Image for empty icon.*/ -static const char* imageEmptyIcon[] = { -"20 20 1 1", -". c None", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"...................."}; - /*!Create new instance of SalomeApp_Application.*/ extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication() { return new SalomeApp_Application(); } -SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0; - /* Class : SalomeApp_Application Description : Application containing SalomeApp module */ -/*!Constructor.*/ SalomeApp_Application::SalomeApp_Application() -: CAM_Application( false ), -myPrefs( 0 ) +: LightApp_Application() { - STD_TabDesktop* desk = new STD_TabDesktop(); - - setDesktop( desk ); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false ); - - desktop()->setIcon( aLogo ); - desktop()->setDockableMenuBar( true ); - desktop()->setDockableStatusBar( false ); - - clearViewManagers(); - - mySelMgr = new SalomeApp_SelectionMgr( this ); - - myAccel = new SUIT_Accel( desktop() ); - myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() ); - myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() ); - - connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ), - this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) ); - - connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) ); } /*!Destructor. - *\li Save window geometry. - *\li Save desktop geometry. - *\li Save resource maneger. - *\li Delete selection manager. *\li Destroy event filter. */ SalomeApp_Application::~SalomeApp_Application() { - saveWindowsGeometry(); - - if ( resourceMgr() ) - { - if ( desktop() ) - desktop()->saveGeometry( resourceMgr(), "desktop" ); - resourceMgr()->save(); - } - - delete mySelMgr; - SalomeApp_EventFilter::Destroy(); } /*!Start application.*/ void SalomeApp_Application::start() { - if ( desktop() ) - desktop()->loadGeometry( resourceMgr(), "desktop" ); - - CAM_Application::start(); - - QAction* a = action( ViewWindowsId ); - if ( a && a->inherits( "QtxDockAction" ) ) - ((QtxDockAction*)a)->setAutoPlace( true ); + LightApp_Application::start(); SalomeApp_EventFilter::Init(); - - updateWindows(); - updateViewManagers(); - - putInfo( "" ); -} - -/*!Gets application name.*/ -QString SalomeApp_Application::applicationName() const -{ - return tr( "APP_NAME" ); -} - -/*!Gets application version.*/ -QString SalomeApp_Application::applicationVersion() const -{ - static QString _app_version; - - if ( _app_version.isEmpty() ) - { - QString path( ::getenv( "GUI_ROOT_DIR" ) ); - if ( !path.isEmpty() ) - path += QDir::separator(); - path += QString( "bin/salome/VERSION" ); - - QFile vf( path ); - if ( vf.open( IO_ReadOnly ) ) - { - QString line; - vf.readLine( line, 1024 ); - vf.close(); - - if ( !line.isEmpty() ) - { - while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) ) - line.remove( line.length() - 1, 1 ); - - int idx = line.findRev( ":" ); - if ( idx != -1 ) - _app_version = line.mid( idx + 1 ).stripWhiteSpace(); - } - } - } - - return _app_version; -} - -/*!Load module by \a name.*/ -CAM_Module* SalomeApp_Application::loadModule( const QString& name ) -{ - CAM_Module* mod = CAM_Application::loadModule( name ); - if ( mod ) - { - connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) ); - connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) ); - connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) ); - } - return mod; -} - -/*!Activate module by \a modName*/ -bool SalomeApp_Application::activateModule( const QString& modName ) -{ - QString actName; - CAM_Module* prevMod = activeModule(); - - if ( prevMod ) - actName = prevMod->moduleName(); - - if ( actName == modName ) - return true; - - putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) ); - - saveWindowsGeometry(); - - bool status = CAM_Application::activateModule( modName ); - - updateModuleActions(); - - putInfo( "" ); - - if ( !status ) - return false; - - updateWindows(); - updateViewManagers(); - - return true; -} - -/*!Gets selection manager.*/ -SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const -{ - return mySelMgr; } /*!Create actions:*/ void SalomeApp_Application::createActions() { - STD_Application::createActions(); + LightApp_Application::createActions(); SUIT_Desktop* desk = desktop(); - SUIT_ResourceMgr* resMgr = resourceMgr(); - + //! Dump study createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(), tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ), 0, desk, false, this, SLOT( onDumpStudy() ) ); - + //! Load script createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(), tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ), @@ -335,11 +112,6 @@ void SalomeApp_Application::createActions() tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ), 0, desk, false, this, SLOT( onProperties() ) ); - //! Preferences - createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(), - tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ), - CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) ); - //! Catalog Generator createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIconSet(), tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ), @@ -350,93 +122,7 @@ void SalomeApp_Application::createActions() tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ), 0, desk, false, this, SLOT( onRegDisplay() ) ); - //! MRU - QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk ); - connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) ); - registerAction( MRUId, mru ); - - //! default icon for neutral point ('SALOME' module) - QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false ); - if ( defIcon.isNull() ) - defIcon = QPixmap( imageEmptyIcon ); - - //! default icon for any module - QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false ); - if ( modIcon.isNull() ) - modIcon = QPixmap( imageEmptyIcon ); - - QToolBar* modTBar = new QtxToolBar( true, desk ); - modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) ); - - QActionGroup* modGroup = new QActionGroup( this ); - modGroup->setExclusive( true ); - modGroup->setUsesDropDown( true ); - - QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ), - tr( "PRP_APP_MODULE" ), 0, desk, true ); - modGroup->add( a ); - myActions.insert( QString(), a ); - - QMap iconMap; - moduleIconNames( iconMap ); - - const int iconSize = 20; - - modGroup->addTo( modTBar ); - modTBar->addSeparator(); - - QStringList modList; - modules( modList, false ); - - for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it ) - { - if ( (*it).isEmpty() ) - continue; - - QString iconName; - if ( iconMap.contains( *it ) ) - iconName = iconMap[*it]; - - QString modName = moduleName( *it ); - - QPixmap icon = resMgr->loadPixmap( modName, iconName, false ); - if ( icon.isNull() ) - icon = modIcon; - - icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) ); - - QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true ); - a->addTo( modTBar ); - modGroup->add( a ); - - myActions.insert( *it, a ); - } - - SUIT_Tools::simplifySeparators( modTBar ); - - //! New window - - int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 ); - int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 ); - createMenu( separator(), windowMenu, -1, 1 ); - - QMap accelMap; - accelMap[NewGLViewId] = ALT+Key_G; - accelMap[NewPlot2dId] = ALT+Key_P; - accelMap[NewOCCViewId] = ALT+Key_O; - accelMap[NewVTKViewId] = ALT+Key_K; - - for ( int id = NewGLViewId; id <= NewVTKViewId; id++ ) - { - QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(), - tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), - tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), - accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) ); - createMenu( a, newWinMenu, -1 ); - } - connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) ); - - int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 ); + int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 ); createMenu( DumpStudyId, fileMenu, 10, -1 ); createMenu( separator(), fileMenu, -1, 15, -1 ); @@ -444,156 +130,11 @@ void SalomeApp_Application::createActions() createMenu( separator(), fileMenu, -1, 15, -1 ); createMenu( PropertiesId, fileMenu, 10, -1 ); createMenu( separator(), fileMenu, -1, 15, -1 ); - createMenu( PreferencesId, fileMenu, 15, -1 ); - createMenu( separator(), fileMenu, -1, 15, -1 ); int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, -1, 50 ); createMenu( CatalogGenId, toolsMenu, 10, -1 ); createMenu( RegDisplayId, toolsMenu, 10, -1 ); createMenu( separator(), toolsMenu, -1, 15, -1 ); - - /* - createMenu( separator(), fileMenu, -1, 100, -1 ); - createMenu( MRUId, fileMenu, 100, -1 ); - createMenu( separator(), fileMenu, -1, 100, -1 ); - */ -} - -/*!On module activation action.*/ -void SalomeApp_Application::onModuleActivation( QAction* a ) -{ - if ( !a ) - return; - - QString modName = a->menuText(); - if ( modName == tr( "APP_NAME" ) ) - modName = QString::null; - - // Force user to create/open a study before module activation - QMap iconMap; - moduleIconNames( iconMap ); - QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false ); - if ( icon.isNull() ) - icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module - - bool cancelled = false; - while ( !modName.isEmpty() && !activeStudy() && !cancelled ){ - SalomeApp_ModuleDlg aDlg( desktop(), modName, icon ); - int res = aDlg.exec(); - - switch ( res ){ - case 1: - onNewDoc(); - break; - case 2: - onOpenDoc(); - break; - case 3: - //onLoadStudy(); - //break; - case 0: - default: - putInfo( tr("INF_CANCELLED") ); - myActions[QString()]->setOn( true ); - cancelled = true; - } - } - - if ( !cancelled ) - activateModule( modName ); -} - -/*!Default module activation.*/ -QString SalomeApp_Application::defaultModule() const -{ - QStringList aModuleNames; - modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration - //! If there's the one and only module --> activate it automatically - //! TODO: Possible improvement - default module can be taken from preferences - return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" ); -} - -/*!On new window slot.*/ -void SalomeApp_Application::onNewWindow() -{ - const QObject* obj = sender(); - if ( !obj || !obj->inherits( "QAction" ) ) - return; - - QString type; - int id = actionId( (QAction*)obj ); - switch ( id ) - { - case NewGLViewId: - type = GLViewer_Viewer::Type(); - break; - case NewPlot2dId: - type = Plot2d_Viewer::Type(); - break; - case NewOCCViewId: - type = OCCViewer_Viewer::Type(); - break; - case NewVTKViewId: - type = VTKViewer_Viewer::Type(); - break; - } - - if ( !type.isEmpty() ) - createViewManager( type ); -} - -//======================================================================= -// name : onNewDoc -/*! Purpose : SLOT. Create new document*/ -//======================================================================= -void SalomeApp_Application::onNewDoc() -{ - SUIT_Study* study = activeStudy(); - - saveWindowsGeometry(); - - CAM_Application::onNewDoc(); - - if ( !study ) // new study will be create in THIS application - { - updateWindows(); - updateViewManagers(); - } -} - -//======================================================================= -// name : onOpenDoc -/*! Purpose : SLOT. Open new document*/ -//======================================================================= -void SalomeApp_Application::onOpenDoc() -{ - SUIT_Study* study = activeStudy(); - saveWindowsGeometry(); - - CAM_Application::onOpenDoc(); - - if ( !study ) // new study will be create in THIS application - { - updateWindows(); - updateViewManagers(); - } -} - -/*! Purpose : SLOT. Open new document with \a aName.*/ -bool SalomeApp_Application::onOpenDoc( const QString& aName ) -{ - bool res = CAM_Application::onOpenDoc( aName ); - - QAction* a = action( MRUId ); - if ( a && a->inherits( "QtxMRUAction" ) ) - { - QtxMRUAction* mru = (QtxMRUAction*)a; - if ( res ) - mru->insert( aName ); - else - mru->remove( aName ); - } - return res; } /*!SLOT. Load document.*/ @@ -635,54 +176,28 @@ void SalomeApp_Application::onLoadDoc() name = studyname; name.replace( QRegExp(":"), "/" ); - if(onLoadDoc(name)) { + if (LightApp_Application::onLoadDoc(name)) + { updateWindows(); updateViewManagers(); updateObjectBrowser(true); } } - -/*!SLOT. Load document with \a aName.*/ -bool SalomeApp_Application::onLoadDoc( const QString& aName ) -{ - bool res = CAM_Application::onLoadDoc( aName ); - - /*jfa tmp:QAction* a = action( MRUId ); - if ( a && a->inherits( "QtxMRUAction" ) ) - { - QtxMRUAction* mru = (QtxMRUAction*)a; - if ( res ) - mru->insert( aName ); - else - mru->remove( aName ); - }*/ - return res; -} - -/*!Private SLOT. Selection.*/ -void SalomeApp_Application::onSelection() -{ - onSelectionChanged(); - - if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) ) - ((SalomeApp_Module*)activeModule())->selectionChanged(); -} - /*!SLOT. Copy objects to study maneger from selection maneger..*/ -void SalomeApp_Application::onCopy() +void SalomeApp_Application::onCopy() { SALOME_ListIO list; - SalomeApp_SelectionMgr* mgr = selectionMgr(); + LightApp_SelectionMgr* mgr = selectionMgr(); mgr->selectedObjects(list); - + SalomeApp_Study* study = dynamic_cast(activeStudy()); - if(study == NULL) return; - + if(study == NULL) return; + _PTR(Study) stdDS = study->studyDS(); if(!stdDS) return; - SALOME_ListIteratorOfListIO it( list ); + SALOME_ListIteratorOfListIO it( list ); if(it.More()) { _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); @@ -699,15 +214,15 @@ void SalomeApp_Application::onCopy() void SalomeApp_Application::onPaste() { SALOME_ListIO list; - SalomeApp_SelectionMgr* mgr = selectionMgr(); + LightApp_SelectionMgr* mgr = selectionMgr(); mgr->selectedObjects(list); - + SalomeApp_Study* study = dynamic_cast(activeStudy()); if(study == NULL) return; - + _PTR(Study) stdDS = study->studyDS(); if(!stdDS) return; - + SALOME_ListIteratorOfListIO it( list ); if(it.More()) { @@ -715,7 +230,7 @@ void SalomeApp_Application::onPaste() try { studyMgr()->Paste(so); updateObjectBrowser( true ); - updateActions(); //SRN: BugID IPAL9377, case 3 + updateActions(); //SRN: BugID IPAL9377, case 3 } catch(...) { } @@ -726,49 +241,43 @@ void SalomeApp_Application::onPaste() void SalomeApp_Application::onSelectionChanged() { SALOME_ListIO list; - SalomeApp_SelectionMgr* mgr = selectionMgr(); + LightApp_SelectionMgr* mgr = selectionMgr(); mgr->selectedObjects(list); - + SalomeApp_Study* study = dynamic_cast(activeStudy()); if(study == NULL) return; - + _PTR(Study) stdDS = study->studyDS(); if(!stdDS) return; + + QAction* qaction; - QAction* qaction; - - SALOME_ListIteratorOfListIO it( list ); + SALOME_ListIteratorOfListIO it( list ); if(it.More() && list.Extent() == 1) { _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); - qaction = action(EditCopyId); - if(studyMgr()->CanCopy(so) ) qaction->setEnabled(true); - else qaction->setEnabled(false); - + SALOMEDS_SObject* aSO = dynamic_cast(so.get()); + if(aSO && studyMgr()->CanCopy(so) ) qaction->setEnabled(true); + else qaction->setEnabled(false); + qaction = action(EditPasteId); - if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true); + if( aSO && studyMgr()->CanPaste(so) ) qaction->setEnabled(true); else qaction->setEnabled(false); } else { - qaction = action(EditCopyId); - qaction->setEnabled(false); + qaction = action(EditCopyId); + qaction->setEnabled(false); qaction = action(EditPasteId); qaction->setEnabled(false); } } -/*!Update object browser.*/ -void SalomeApp_Application::onRefresh() -{ - updateObjectBrowser( true ); -} - /*!Delete references.*/ void SalomeApp_Application::onDeleteReferences() { SALOME_ListIO aList; - SalomeApp_SelectionMgr* mgr = selectionMgr(); + LightApp_SelectionMgr* mgr = selectionMgr(); mgr->selectedObjects(aList); if (aList.Extent() < 1) return; @@ -796,7 +305,7 @@ void SalomeApp_Application::onOpenWith() { QApplication::setOverrideCursor( Qt::waitCursor ); SALOME_ListIO aList; - SalomeApp_SelectionMgr* mgr = selectionMgr(); + LightApp_SelectionMgr* mgr = selectionMgr(); mgr->selectedObjects(aList); if (aList.Extent() != 1) { @@ -810,28 +319,6 @@ void SalomeApp_Application::onOpenWith() QApplication::restoreOverrideCursor(); } -bool SalomeApp_Application::useStudy(const QString& theName) -{ - createEmptyStudy(); - SalomeApp_Study* aStudy = dynamic_cast(activeStudy()); - bool res = false; - if (aStudy) - res = aStudy->loadDocument( theName ); - updateDesktopTitle(); - updateCommandsStatus(); - return res; -} - -/*!Set active study. - *\param study - SUIT_Study. - */ -void SalomeApp_Application::setActiveStudy( SUIT_Study* study ) -{ - CAM_Application::setActiveStudy( study ); - - activateWindows(); -} - //======================================================================= // name : createNewStudy /*! Purpose : Create new study*/ @@ -850,19 +337,12 @@ SUIT_Study* SalomeApp_Application::createNewStudy() } //======================================================================= -// name : createNewStudy +// name : updateCommandsStatus /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/ //======================================================================= void SalomeApp_Application::updateCommandsStatus() { - CAM_Application::updateCommandsStatus(); - - for ( int id = NewGLViewId; id <= NewVTKViewId; id++ ) - { - QAction* a = action( id ); - if ( a ) - a->setEnabled( activeStudy() ); - } + LightApp_Application::updateCommandsStatus(); // Dump study menu QAction* a = action( DumpStudyId ); @@ -877,810 +357,122 @@ void SalomeApp_Application::updateCommandsStatus() a = action( PropertiesId ); if( a ) a->setEnabled( activeStudy() ); - + a = action(EditCopyId); a->setEnabled(false); a = action(EditPasteId); a->setEnabled(false); } -//======================================================================= -// name : onHelpAbout -/*! Purpose : SLOT. Display "About" message box*/ -//======================================================================= -void SalomeApp_Application::onHelpAbout() -{ - SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() ); - dlg->exec(); - delete dlg; -} - -QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const +/*!Private SLOT. On dump study.*/ +void SalomeApp_Application::onDumpStudy( ) { - QWidget* wid = 0; + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + if ( !appStudy ) return; + _PTR(Study) aStudy = appStudy->studyDS(); - int sId = studyId; - if ( sId < 0 ) - { - if ( !activeStudy() ) - return 0; - else - sId = activeStudy()->id(); - } + QStringList aFilters; + aFilters.append( tr( "PYTHON_FILES_FILTER" ) ); - if ( myWindows.contains( flag ) ) - wid = myWindows[flag]->widget( sId ); + SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true); + fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) ); + fd->setFilters( aFilters ); + fd->SetChecked(true); + fd->exec(); + QString aFileName = fd->selectedFile(); + bool toPublish = fd->IsChecked(); + delete fd; - return wid; + if(!aFileName.isEmpty()) { + QFileInfo aFileInfo(aFileName); + aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish ); + } } -/*!Adds window to application. - *\param wid - QWidget - *\param flag - key wor window - *\param studyId - study id - * Flag used how identificator of window in windows list. - */ -void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId ) +/*!Private SLOT. On load script.*/ +void SalomeApp_Application::onLoadScript( ) { - if ( !wid ) - return; + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + if ( !appStudy ) return; + _PTR(Study) aStudy = appStudy->studyDS(); - int sId = studyId; - if ( sId < 0 ) - { - if ( !activeStudy() ) - return; - else - sId = activeStudy()->id(); + if ( aStudy->GetProperties()->IsLocked() ) { + SUIT_MessageBox::warn1 ( desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED"), + QObject::tr("BUT_OK") ); + return; } - if ( !myWindows.contains( flag ) ) - { - QMap winMap; - currentWindows( winMap ); - - myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) ); - if ( winMap.contains( flag ) ) - desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] ); + QStringList filtersList; + filtersList.append(tr("PYTHON_FILES_FILTER")); + filtersList.append(tr("ALL_FILES_FILTER")); - myWindows[flag]->setResizeEnabled( true ); - myWindows[flag]->setCloseMode( QDockWindow::Always ); - myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) ); - } + QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true ); - QFont f; - if( wid->inherits( "PythonConsole" ) ) - f = ( ( PythonConsole* )wid )->font(); - else - f = wid->font(); + if ( !aFile.isEmpty() ) + { + QString command = QString("execfile(\"%1\")").arg(aFile); - myWindows[flag]->insert( sId, wid ); - wid->setFont( f ); + PythonConsole* pyConsole = pythonConsole(); - setWindowShown( flag, !myWindows[flag]->isEmpty() ); + if ( pyConsole ) + pyConsole->exec( command ); + } } -/*!Remove window from application. - *\param flag - key wor window - *\param studyId - study id - * Flag used how identificator of window in windows list. - */ -void SalomeApp_Application::removeWindow( const int flag, const int studyId ) +/*!Create window.*/ +QWidget* SalomeApp_Application::createWindow( const int flag ) { - if ( !myWindows.contains( flag ) ) - return; + QWidget* wid = LightApp_Application::createWindow(flag); + SUIT_ResourceMgr* resMgr = resourceMgr(); - int sId = studyId; - if ( sId < 0 ) + if ( flag == WT_ObjectBrowser ) { - if ( !activeStudy() ) - return; - else - sId = activeStudy()->id(); - } - - QWidget* wid = myWindows[flag]->widget( sId ); - myWindows[flag]->remove( sId ); - delete wid; - - setWindowShown( flag, !myWindows[flag]->isEmpty() ); -} - -/*!Gets window. - *\param flag - key wor window - *\param studyId - study id - * Flag used how identificator of window in windows list. - */ -QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId ) -{ - QWidget* wid = window( flag, studyId ); - if ( !wid ) - addWindow( wid = createWindow( flag ), flag, studyId ); - - return wid; -} - -/*!Check is window visible?(with identificator \a type)*/ -bool SalomeApp_Application::isWindowVisible( const int type ) const -{ - bool res = false; - if ( myWindows.contains( type ) ) - { - SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop(); - res = desk && desk->appropriate( myWindows[type] ); - } - return res; -} - -/*!Sets window show or hide. - *\param type - window identificator. - *\param on - true/false (window show/hide) - */ -void SalomeApp_Application::setWindowShown( const int type, const bool on ) -{ - if ( !desktop() || !myWindows.contains( type ) ) - return; - - QDockWindow* dw = myWindows[type]; - desktop()->setAppropriate( dw, on ); - on ? dw->show() : dw->hide(); -} - -OB_Browser* SalomeApp_Application::objectBrowser() -{ - OB_Browser* ob = 0; - QWidget* wid = getWindow( WT_ObjectBrowser ); - if ( wid->inherits( "OB_Browser" ) ) - ob = (OB_Browser*)wid; - return ob; -} - -/*!Gets "LogWindow".*/ -LogWindow* SalomeApp_Application::logWindow() -{ - LogWindow* lw = 0; - QWidget* wid = getWindow( WT_LogWindow ); - if ( wid->inherits( "LogWindow" ) ) - lw = (LogWindow*)wid; - return lw; -} - -/*!Get "PythonConsole"*/ -PythonConsole* SalomeApp_Application::pythonConsole() -{ - PythonConsole* console = 0; - QWidget* wid = getWindow( WT_PyConsole ); - if ( wid->inherits( "PythonConsole" ) ) - console = (PythonConsole*)wid; - return console; -} - -/*!Gets preferences.*/ -SalomeApp_Preferences* SalomeApp_Application::preferences() const -{ - return preferences( false ); -} - -/*!Gets view manager*/ -SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create ) -{ - SUIT_ViewManager* aVM = viewManager( vmType ); - SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager(); - - if ( anActiveVM && anActiveVM->getType() == vmType ) - aVM = anActiveVM; - - if ( aVM && create ) - { - if ( !aVM->getActiveView() ) - aVM->createView(); - else - aVM->getActiveView()->setFocus(); - } - else if ( create ) - aVM = createViewManager( vmType ); - - return aVM; -} - -/*!Create view manager.*/ -SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType ) -{ - SUIT_ResourceMgr* resMgr = resourceMgr(); - - SUIT_ViewManager* viewMgr = 0; - if ( vmType == GLViewer_Viewer::Type() ) - { - viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() ); - new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr ); - } - else if ( vmType == Plot2d_Viewer::Type() ) - { - viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() ); - viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface - } - else if ( vmType == OCCViewer_Viewer::Type() ) - { - viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() ); - SOCC_Viewer* vm = new SOCC_Viewer(); - vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) ); - vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) ); - int u( 1 ), v( 1 ); - vm->isos( u, v ); - u = resMgr->integerValue( "OCCViewer", "iso_number_u", u ); - v = resMgr->integerValue( "OCCViewer", "iso_number_v", v ); - vm->setIsos( u, v ); - viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface - new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr ); - } - else if ( vmType == SVTK_Viewer::Type() ) - { - viewMgr = new SVTK_ViewManager( activeStudy(), desktop() ); - SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel(); - vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) ); - vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) ); - new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr); - } - - if ( !viewMgr ) - return 0; - - addViewManager( viewMgr ); - SUIT_ViewWindow* viewWin = viewMgr->createViewWindow(); - - if ( viewWin && desktop() ) - viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) ); - - connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), - this, SLOT( onCloseView( SUIT_ViewManager* ) ) ); - - return viewMgr; -} - -void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM ) -{ - removeViewManager( theVM ); -} - -/*!Private SLOT. On study created.*/ -void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy ) -{ - SUIT_DataObject* aRoot = 0; - if ( theStudy && theStudy->root() ) - { - aRoot = theStudy->root(); - //aRoot->setName( tr( "DATA_MODELS" ) ); - } - if ( objectBrowser() != 0 ) - objectBrowser()->setRootObject( aRoot ); - - activateModule( defaultModule() ); - - activateWindows(); -} - -/*!Private SLOT. On study opened.*/ -void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy ) -{ - SUIT_DataObject* aRoot = 0; - if ( theStudy && theStudy->root() ) - { - aRoot = theStudy->root(); - //aRoot->dump(); - } - if ( objectBrowser() != 0 ) { - objectBrowser()->setRootObject( aRoot ); - } - - activateModule( defaultModule() ); - - activateWindows(); - - emit studyOpened(); -} - -void SalomeApp_Application::onStudySaved( SUIT_Study* ) -{ - emit studySaved(); -} - -/*!Private SLOT. On study closed.*/ -void SalomeApp_Application::onStudyClosed( SUIT_Study* ) -{ - emit studyClosed(); - - activateModule( "" ); - - saveWindowsGeometry(); -} - -/*!Private SLOT. On dump study.*/ -void SalomeApp_Application::onDumpStudy( ) -{ - SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); - if ( !appStudy ) return; - _PTR(Study) aStudy = appStudy->studyDS(); - - QStringList aFilters; - aFilters.append( tr( "PYTHON_FILES_FILTER" ) ); - - SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true); - fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) ); - fd->setFilters( aFilters ); - fd->SetChecked(true); - fd->exec(); - QString aFileName = fd->selectedFile(); - bool toPublish = fd->IsChecked(); - delete fd; - - if(!aFileName.isEmpty()) { - QFileInfo aFileInfo(aFileName); - aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish ); - } -} - -/*!Private SLOT. On load script.*/ -void SalomeApp_Application::onLoadScript( ) -{ - SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); - if ( !appStudy ) return; - _PTR(Study) aStudy = appStudy->studyDS(); - - if ( aStudy->GetProperties()->IsLocked() ) { - SUIT_MessageBox::warn1 ( desktop(), - QObject::tr("WRN_WARNING"), - QObject::tr("WRN_STUDY_LOCKED"), - QObject::tr("BUT_OK") ); - return; - } - - QStringList filtersList; - filtersList.append(tr("PYTHON_FILES_FILTER")); - filtersList.append(tr("ALL_FILES_FILTER")); - - QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true ); - - if ( !aFile.isEmpty() ) - { - QString command = QString("execfile(\"%1\")").arg(aFile); - - PythonConsole* pyConsole = pythonConsole(); - - if ( pyConsole ) - pyConsole->exec( command ); - } -} - -/*!Private SLOT. On preferences.*/ -void SalomeApp_Application::onPreferences() -{ - QApplication::setOverrideCursor( Qt::waitCursor ); - - SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop()); - - QApplication::restoreOverrideCursor(); - - if ( !prefDlg ) - return; - - prefDlg->exec(); - - delete prefDlg; -} - -/*!Private SLOT. On open document with name \a aName.*/ -void SalomeApp_Application::onMRUActivated( QString aName ) -{ - onOpenDoc( aName ); -} - -/*!Private SLOT. On preferences changed.*/ -void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param ) -{ - SalomeApp_Module* sMod = 0; - CAM_Module* mod = module( modName ); - if ( mod && mod->inherits( "SalomeApp_Module" ) ) - sMod = (SalomeApp_Module*)mod; - - if ( sMod ) - sMod->preferencesChanged( section, param ); - else - preferencesChanged( section, param ); -} - -/*!Gets file filter. - *\retval QString "(*.hdf)" - */ -QString SalomeApp_Application::getFileFilter() const -{ - return "(*.hdf)"; -} - -/*!Remove all windows from study.*/ -void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s ) -{ - CAM_Application::beforeCloseDoc( s ); - - for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr ) - removeWindow( itr.key(), s->id() ); -} - -/*!Update actions.*/ -void SalomeApp_Application::updateActions() -{ - updateCommandsStatus(); -} - -/*!Create window.*/ -QWidget* SalomeApp_Application::createWindow( const int flag ) -{ - QWidget* wid = 0; - - SUIT_ResourceMgr* resMgr = resourceMgr(); - - if ( flag == WT_ObjectBrowser ) - { - OB_Browser* ob = new OB_Browser( desktop() ); - ob->setAutoUpdate( true ); - ob->setAutoOpenLevel( 1 ); - ob->setCaption( tr( "OBJECT_BROWSER" ) ); - ob->resize( OBJECT_BROWSER_WIDTH, ob->height() ); - ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) ); - - ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) ); - - bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); - for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ ) - { - ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i ); - ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser", - QString().sprintf( "visibility_column_%d", i ), true ) ); - } - ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual ); - - // Create OBSelector - new SalomeApp_OBSelector( ob, mySelMgr ); - - wid = ob; - - ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); + OB_Browser* ob = (OB_Browser*)wid; + bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); + if ( ob != 0 ) { + for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ ) + { + ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i ); + ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser", + QString().sprintf( "visibility_column_%d", i ), true ) ); + } + } + ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual ); } else if ( flag == WT_PyConsole ) { + delete wid; + wid = 0; PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() ); pyCons->setCaption( tr( "PYTHON_CONSOLE" ) ); - pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) ); wid = pyCons; - // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); } - else if ( flag == WT_LogWindow ) - { - LogWindow* logWin = new LogWindow( desktop() ); - logWin->setCaption( tr( "LOG_WINDOW" ) ); - wid = logWin; - - logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); - } - return wid; } -/*!Default windows(Object Browser, Python Console). - * Adds to map \a aMap. - */ -void SalomeApp_Application::defaultWindows( QMap& aMap ) const -{ - aMap.insert( WT_ObjectBrowser, Qt::DockLeft ); - aMap.insert( WT_PyConsole, Qt::DockBottom ); - // aMap.insert( WT_LogWindow, Qt::DockBottom ); -} - -/*!Default view manager.*/ -void SalomeApp_Application::defaultViewManagers( QStringList& ) const -{ - /*!Do nothing.*/ -} - -/*!Gets preferences. - * Create preferences, if \a crt = true. - */ -SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const -{ - if ( myPrefs ) - return myPrefs; - - SalomeApp_Application* that = (SalomeApp_Application*)this; - - if ( !_prefs_ && crt ) - { - _prefs_ = new SalomeApp_Preferences( resourceMgr() ); - that->createPreferences( _prefs_ ); - } - - that->myPrefs = _prefs_; - - QPtrList appList = SUIT_Session::session()->applications(); - for ( QPtrListIterator appIt ( appList ); appIt.current(); ++appIt ) - { - if ( !appIt.current()->inherits( "SalomeApp_Application" ) ) - continue; - - SalomeApp_Application* app = (SalomeApp_Application*)appIt.current(); - - QStringList modNameList; - app->modules( modNameList, false ); - for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it ) - { - int id = _prefs_->addPreference( *it ); - _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) ); - } - - ModuleList modList; - app->modules( modList ); - for ( ModuleListIterator itr( modList ); itr.current(); ++itr ) - { - SalomeApp_Module* mod = 0; - if ( itr.current()->inherits( "SalomeApp_Module" ) ) - mod = (SalomeApp_Module*)itr.current(); - - if ( mod && !_prefs_->hasModule( mod->moduleName() ) ) - { - int modCat = _prefs_->addPreference( mod->moduleName() ); - _prefs_->setItemProperty( modCat, "info", QString::null ); - mod->createPreferences(); - } - } - } - - connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ), - this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) ); - - return myPrefs; -} - -/*!Add new module to application.*/ -void SalomeApp_Application::moduleAdded( CAM_Module* mod ) -{ - CAM_Application::moduleAdded( mod ); - - SalomeApp_Module* salomeMod = 0; - if ( mod && mod->inherits( "SalomeApp_Module" ) ) - salomeMod = (SalomeApp_Module*)mod; - - if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) ) - { - int modCat = myPrefs->addPreference( mod->moduleName() ); - myPrefs->setItemProperty( modCat, "info", QString::null ); - salomeMod->createPreferences(); - } -} - /*!Create preferences.*/ -void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref ) +void SalomeApp_Application::createPreferences( LightApp_Preferences* pref ) { + LightApp_Application::createPreferences(pref); + if ( !pref ) return; int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) ); - - int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat ); - int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab ); - pref->setItemProperty( studyGroup, "columns", 1 ); - - pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" ); - pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" ); - int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" ); - pref->setItemProperty( undoPref, "min", 1 ); - pref->setItemProperty( undoPref, "max", 100 ); - - int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab ); - pref->setItemProperty( extgroup, "columns", 1 ); - int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" ); - pref->setItemProperty( apppref, "existing", true ); - pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser ); - - pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" ); - - int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab ); - pref->setItemProperty( pythonConsoleGroup, "columns", 1 ); - pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" ); - - - int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat ); int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab ); for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ ) { pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols, - SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) ); + LightApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) ); } pref->setItemProperty( defCols, "columns", 1 ); int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab ); - pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" ); - - int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat ); - - int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab ); - - int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab ); - - int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab ); - - pref->setItemProperty( occGroup, "columns", 1 ); - pref->setItemProperty( vtkGroup, "columns", 1 ); - pref->setItemProperty( plot2dGroup, "columns", 1 ); - - int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup, - SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" ); - pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup, - SalomeApp_Preferences::Color, "OCCViewer", "background" ); - - pref->setItemProperty( occTS, "min", 1 ); - pref->setItemProperty( occTS, "max", 150 ); - - int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup, - SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" ); - int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup, - SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" ); - - pref->setItemProperty( isoU, "min", 0 ); - pref->setItemProperty( isoU, "max", 100000 ); - - pref->setItemProperty( isoV, "min", 0 ); - pref->setItemProperty( isoV, "max", 100000 ); - - int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup, - SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" ); - pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup, - SalomeApp_Preferences::Color, "VTKViewer", "background" ); - - pref->setItemProperty( vtkTS, "min", 1 ); - pref->setItemProperty( vtkTS, "max", 150 ); - - pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup, - SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" ); - - int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup, - SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" ); - QStringList aLegendPosList; - aLegendPosList.append( tr("PREF_LEFT") ); - aLegendPosList.append( tr("PREF_RIGHT") ); - aLegendPosList.append( tr("PREF_TOP") ); - aLegendPosList.append( tr("PREF_BOTTOM") ); - - QValueList anIndexesList; - anIndexesList.append(0); - anIndexesList.append(1); - anIndexesList.append(2); - anIndexesList.append(3); - - pref->setItemProperty( legendPosition, "strings", aLegendPosList ); - pref->setItemProperty( legendPosition, "indexes", anIndexesList ); - - int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup, - SalomeApp_Preferences::Selector, "Plot2d", "CurveType" ); - QStringList aCurveTypesList; - aCurveTypesList.append( tr("PREF_POINTS") ); - aCurveTypesList.append( tr("PREF_LINES") ); - aCurveTypesList.append( tr("PREF_SPLINE") ); - - anIndexesList.clear(); - anIndexesList.append(0); - anIndexesList.append(1); - anIndexesList.append(2); - - pref->setItemProperty( curveType, "strings", aCurveTypesList ); - pref->setItemProperty( curveType, "indexes", anIndexesList ); - - int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup, - SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" ); - - pref->setItemProperty( markerSize, "min", 0 ); - pref->setItemProperty( markerSize, "max", 100 ); - - QStringList aScaleModesList; - aScaleModesList.append( tr("PREF_LINEAR") ); - aScaleModesList.append( tr("PREF_LOGARITHMIC") ); - - anIndexesList.clear(); - anIndexesList.append(0); - anIndexesList.append(1); - - int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup, - SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" ); - - pref->setItemProperty( horScale, "strings", aScaleModesList ); - pref->setItemProperty( horScale, "indexes", anIndexesList ); - - int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup, - SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" ); - - pref->setItemProperty( verScale, "strings", aScaleModesList ); - pref->setItemProperty( verScale, "indexes", anIndexesList ); - - pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup, - SalomeApp_Preferences::Color, "Plot2d", "Background" ); - - int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat ); - int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab ); - pref->setItemProperty( dirGroup, "columns", 1 ); - pref->addPreference( tr( "" ), dirGroup, - SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" ); -} - -void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param ) -{ - SUIT_ResourceMgr* resMgr = resourceMgr(); - if ( !resMgr ) - return; - - if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) ) - { - int sz = resMgr->integerValue( sec, param, -1 ); - QPtrList lst; - viewManagers( OCCViewer_Viewer::Type(), lst ); - for ( QPtrListIterator it( lst ); it.current() && sz >= 0; ++it ) - { - SUIT_ViewModel* vm = it.current()->getViewModel(); - if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) ) - continue; - - OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm; - occVM->setTrihedronSize( sz ); - occVM->getAISContext()->UpdateCurrentViewer(); - } - } - - if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) ) - { - int sz = resMgr->integerValue( sec, param, -1 ); - QPtrList lst; - viewManagers( SVTK_Viewer::Type(), lst ); - for ( QPtrListIterator it( lst ); it.current() && sz >= 0; ++it ) - { - SUIT_ViewModel* vm = it.current()->getViewModel(); - if ( !vm || !vm->inherits( "SVTK_Viewer" ) ) - continue; - - SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm; - vtkVM->setTrihedronSize( sz ); - vtkVM->Repaint(); - } - } - - if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) ) - { - QPtrList lst; - viewManagers( OCCViewer_Viewer::Type(), lst ); - int u = resMgr->integerValue( sec, "iso_number_u" ); - int v = resMgr->integerValue( sec, "iso_number_v" ); - for ( QPtrListIterator it( lst ); it.current(); ++it ) - ((OCCViewer_Viewer*)it.current())->setIsos( u, v ); - } - - if( sec=="ObjectBrowser" ) - { - if( param=="auto_size" ) - { - OB_Browser* ob = objectBrowser(); - if( !ob ) - return; - - bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); - ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual ); - - updateObjectBrowser( false ); - } - } - - if( sec=="PyConsole" ) - { - if( param=="font" ) - if( pythonConsole() ) - pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) ); - } + pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool, "ObjectBrowser", "auto_size" ); } /*!Update desktop title.*/ @@ -1695,13 +487,15 @@ void SalomeApp_Application::updateDesktopTitle() { QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false ); if ( !sName.isEmpty() ) { SalomeApp_Study* study = dynamic_cast(activeStudy()); - _PTR(Study) stdDS = study->studyDS(); - if(stdDS) { - if ( stdDS->GetProperties()->IsLocked() ) { - aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) ); - } else { - aTitle += QString( " - [%1]" ).arg( sName ); - } + if ( study ) { + _PTR(Study) stdDS = study->studyDS(); + if(stdDS) { + if ( stdDS->GetProperties()->IsLocked() ) { + aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) ); + } else { + aTitle += QString( " - [%1]" ).arg( sName ); + } + } } } } @@ -1709,14 +503,6 @@ void SalomeApp_Application::updateDesktopTitle() { desktop()->setCaption( aTitle ); } -/*!Update windows after close document.*/ -void SalomeApp_Application::afterCloseDoc() -{ - updateWindows(); - - CAM_Application::afterCloseDoc(); -} - /*!Gets CORBA::ORB_var*/ CORBA::ORB_var SalomeApp_Application::orb() { @@ -1756,158 +542,6 @@ QString SalomeApp_Application::defaultEngineIOR() return anIOR; } -/*!Adds icon names for modules.*/ -void SalomeApp_Application::moduleIconNames( QMap& iconMap ) const -{ - iconMap.clear(); - - SUIT_ResourceMgr* resMgr = resourceMgr(); - if ( !resMgr ) - return; - - QStringList modList; - modules( modList, false ); - - for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it ) - { - QString modName = *it; - QString modIntr = moduleName( modName ); - QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null ); - - if ( modIcon.isEmpty() ) - continue; - - if ( SUIT_Tools::extension( modIcon ).isEmpty() ) - modIcon += QString( ".png" ); - - iconMap.insert( modName, modIcon ); - } -} - -/*!Update module action.*/ -void SalomeApp_Application::updateModuleActions() -{ - QString modName; - if ( activeModule() ) - modName = activeModule()->moduleName(); - - if ( myActions.contains( modName ) ) - myActions[modName]->setOn( true ); -} - -/*!Gets current windows. - *\param winMap - output current windows map. - */ -void SalomeApp_Application::currentWindows( QMap& winMap ) const -{ - winMap.clear(); - if ( !activeStudy() ) - return; - - if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) ) - ((SalomeApp_Module*)activeModule())->windows( winMap ); - else - defaultWindows( winMap ); -} - -/*!Gets current view managers. - *\param lst - output current view managers list. - */ -void SalomeApp_Application::currentViewManagers( QStringList& lst ) const -{ - lst.clear(); - if ( !activeStudy() ) - return; - - if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) ) - ((SalomeApp_Module*)activeModule())->viewManagers( lst ); - else - defaultViewManagers( lst ); -} - -/*!Update windows.*/ -void SalomeApp_Application::updateWindows() -{ - QMap winMap; - currentWindows( winMap ); - - for ( QMap::ConstIterator it = winMap.begin(); it != winMap.end(); ++it ) - getWindow( it.key() ); - - loadWindowsGeometry(); - - for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) - setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) ); -} - -/*!Update view managers.*/ -void SalomeApp_Application::updateViewManagers() -{ - QStringList lst; - currentViewManagers( lst ); - - for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it ) - getViewManager( *it, true ); -} - -/*!Load windows geometry.*/ -void SalomeApp_Application::loadWindowsGeometry() -{ - QtxDockAction* dockMgr = 0; - - QAction* a = action( ViewWindowsId ); - if ( a && a->inherits( "QtxDockAction" ) ) - dockMgr = (QtxDockAction*)a; - - if ( !dockMgr ) - return; - - QString modName; - if ( activeModule() ) - modName = moduleLibrary( activeModule()->moduleName(), false ); - - QString section = QString( "windows_geometry" ); - if ( !modName.isEmpty() ) - section += QString( "." ) + modName; - - dockMgr->loadGeometry( resourceMgr(), section, false ); - dockMgr->restoreGeometry(); -} - -/*!Save windows geometry.*/ -void SalomeApp_Application::saveWindowsGeometry() -{ - QtxDockAction* dockMgr = 0; - - QAction* a = action( ViewWindowsId ); - if ( a && a->inherits( "QtxDockAction" ) ) - dockMgr = (QtxDockAction*)a; - - if ( !dockMgr ) - return; - - QString modName; - if ( activeModule() ) - modName = moduleLibrary( activeModule()->moduleName(), false ); - - QString section = QString( "windows_geometry" ); - if ( !modName.isEmpty() ) - section += QString( "." ) + modName; - - dockMgr->storeGeometry(); - dockMgr->saveGeometry( resourceMgr(), section, false ); -} - -/*!Activate windows.*/ -void SalomeApp_Application::activateWindows() -{ - if ( activeStudy() ) - { - for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) - itr.data()->activate( activeStudy()->id() ); - } -} - /*!Private SLOT. On preferences.*/ void SalomeApp_Application::onProperties() { @@ -1929,49 +563,18 @@ void SalomeApp_Application::onProperties() updateDesktopTitle(); } -/*!*/ -QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters, - const QString& caption, QWidget* parent ) -{ - if ( !parent ) - parent = desktop(); - QStringList fls = QStringList::split( ";;", filters, false ); - return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true ); -} - -/*!*/ -QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent ) -{ - if ( !parent ) - parent = desktop(); - return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true ); -} - -/*!*/ -QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters, - const QString& caption, QWidget* parent ) -{ - if ( !parent ) - parent = desktop(); - QStringList fls = QStringList::split( ";;", filters, false ); - return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true ); -} - /*!*/ void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title ) { - CAM_Application::contextMenuPopup( type, thePopup, title ); + LightApp_Application::contextMenuPopup( type, thePopup, title ); OB_Browser* ob = objectBrowser(); if ( !ob || type != ob->popupClientType() ) return; - thePopup->insertSeparator(); - thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) ); - // Get selected objects SALOME_ListIO aList; - SalomeApp_SelectionMgr* mgr = selectionMgr(); + LightApp_SelectionMgr* mgr = selectionMgr(); mgr->selectedObjects(aList); // "Delete reference" item should appear only for invalid references @@ -1986,15 +589,16 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* t { SalomeApp_Study* aStudy = dynamic_cast(activeStudy()); _PTR(Study) aStudyDS = aStudy->studyDS(); - _PTR(SObject) anObj; - + _PTR(SObject) anObj; for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() ) { if ( it.Value()->hasEntry() ) { _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() ); - if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() ) - isInvalidRefs = false; + SALOMEDS_SObject* aSO = dynamic_cast(aSObject.get()); + if( aSO ) + if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() ) + isInvalidRefs = false; } } } @@ -2017,72 +621,30 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* t if (currentModule && currentModule->moduleName() == aModuleTitle) return; thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) ); - } /*!Update obect browser*/ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) { - // update existing data models (already loaded SComponents) - if ( updateModels ) - { - for ( ModuleListIterator it = modules(); it.current(); ++it ) - { - CAM_DataModel* camDM = it.current()->dataModel(); - if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) ) - ((SalomeApp_DataModel*)camDM)->update(); - } - } // update "non-existing" (not loaded yet) data models SalomeApp_Study* study = dynamic_cast(activeStudy()); - if ( study ) + if ( study ) { _PTR(Study) stdDS = study->studyDS(); - if( stdDS ) + if( stdDS ) { - for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() ) + for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() ) { - _PTR(SComponent) aComponent ( it->Value() ); + _PTR(SComponent) aComponent ( it->Value() ); if ( aComponent->ComponentDataType() == "Interface Applicative" ) continue; // skip the magic "Interface Applicative" component - + SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true ); } } } - - if ( objectBrowser() ) - { - objectBrowser()->updateGeometry(); - objectBrowser()->updateTree(); - } -} - -/*!Protected SLOT.On desktop activated.*/ -void SalomeApp_Application::onDesktopActivated() -{ - CAM_Application::onDesktopActivated(); - SalomeApp_Module* aModule = dynamic_cast(activeModule()); - if(aModule) - aModule->studyActivated(); -} - -/*!Create empty study.*/ -void SalomeApp_Application::createEmptyStudy() -{ - CAM_Application::createEmptyStudy(); - if ( objectBrowser() ) - objectBrowser()->updateTree(); -} - -/*!Activate module \a mod.*/ -bool SalomeApp_Application::activateModule( CAM_Module* mod ) -{ - bool res = CAM_Application::activateModule( mod ); - if ( objectBrowser() ) - objectBrowser()->updateTree(); - return res; + LightApp_Application::updateObjectBrowser(updateModels); } /*!Display Catalog Genenerator dialog */ @@ -2101,9 +663,3 @@ void SalomeApp_Application::onRegDisplay() regWnd->raise(); regWnd->setActiveWindow(); } - -/*!return keyborad accelerators manager object */ -SUIT_Accel* SalomeApp_Application::accel() const -{ - return myAccel; -} diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 969d54890..567b59668 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -11,7 +11,7 @@ #endif // _MSC_VER > 1000 #include "SalomeApp.h" -#include +#include #include @@ -25,14 +25,8 @@ class QAction; class QComboBox; class QDockWindow; -class LogWindow; -class OB_Browser; -class PythonConsole; +class LightApp_Preferences; class SalomeApp_Module; -class SalomeApp_Preferences; -class SalomeApp_SelectionMgr; -class SalomeApp_WidgetContainer; -class SUIT_Accel; class SALOME_LifeCycleCORBA; @@ -44,176 +38,56 @@ class SALOME_LifeCycleCORBA; Description : Application containing SalomeApp module */ -class SALOMEAPP_EXPORT SalomeApp_Application : public CAM_Application +class SALOMEAPP_EXPORT SalomeApp_Application : public LightApp_Application { Q_OBJECT public: - typedef enum { WT_ObjectBrowser, WT_PyConsole, WT_LogWindow, WT_User } WindowTypes; - - enum { ModulesListId = STD_Application::UserID, NewGLViewId, - NewPlot2dId, NewOCCViewId, NewVTKViewId, DumpStudyId, - LoadScriptId, PropertiesId, PreferencesId, MRUId, - CatalogGenId, RegDisplayId, UserID }; + enum { DumpStudyId = LightApp_Application::UserID, LoadScriptId, PropertiesId, + CatalogGenId, RegDisplayId, UserID }; public: SalomeApp_Application(); virtual ~SalomeApp_Application(); - - virtual QString applicationName() const; - virtual QString applicationVersion() const; - - virtual CAM_Module* loadModule( const QString& ); - virtual bool activateModule( const QString& ); - - virtual bool useStudy( const QString& ); - - SalomeApp_SelectionMgr* selectionMgr() const; - - LogWindow* logWindow(); - OB_Browser* objectBrowser(); - PythonConsole* pythonConsole(); + virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& ); virtual void updateObjectBrowser( const bool = true ); - SalomeApp_Preferences* preferences() const; - - virtual QString getFileFilter() const; - virtual QString getFileName( bool open, const QString& initial, const QString& filters, - const QString& caption, QWidget* parent ); - virtual QString getDirectory( const QString& initial, const QString& caption, QWidget* parent ); - virtual QStringList getOpenFileNames( const QString& initial, const QString& filters, - const QString& caption, QWidget* parent ); - SUIT_ViewManager* getViewManager( const QString&, const bool ); - void updateActions(); - - QWidget* getWindow( const int, const int = -1 ); - - QWidget* window( const int, const int = -1 ) const; - void addWindow( QWidget*, const int, const int = -1 ); - void removeWindow( const int, const int = -1 ); - - bool isWindowVisible( const int ) const; - void setWindowShown( const int, const bool ); - virtual void start(); - virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& ); - - virtual void createEmptyStudy(); - - SUIT_Accel* accel() const; - static CORBA::ORB_var orb(); static SALOMEDSClient_StudyManager* studyMgr(); static SALOME_NamingService* namingService(); static SALOME_LifeCycleCORBA* lcc(); static QString defaultEngineIOR(); -signals: - void studyOpened(); - void studySaved(); - void studyClosed(); - public slots: - virtual void onNewDoc(); - virtual void onOpenDoc(); - virtual void onHelpAbout(); - virtual bool onOpenDoc( const QString& ); virtual void onLoadDoc(); - virtual bool onLoadDoc( const QString& ); virtual void onCopy(); virtual void onPaste(); -private slots: - void onSelection(); - void onRefresh(); - void onDeleteReferences(); - protected: virtual void createActions(); virtual SUIT_Study* createNewStudy(); virtual QWidget* createWindow( const int ); - virtual void defaultWindows( QMap& ) const; - virtual void defaultViewManagers( QStringList& ) const; - - virtual void setActiveStudy( SUIT_Study* ); virtual void updateCommandsStatus(); - virtual void onSelectionChanged(); - virtual void beforeCloseDoc( SUIT_Study* ); - virtual void afterCloseDoc(); - - virtual void moduleAdded( CAM_Module* ); - virtual bool activateModule( CAM_Module* = 0 ); - - SalomeApp_Preferences* preferences( const bool ) const; - - virtual void createPreferences( SalomeApp_Preferences* ); - virtual void preferencesChanged( const QString&, const QString& ); + virtual void createPreferences( LightApp_Preferences* ); virtual void updateDesktopTitle(); -protected slots: - virtual void onDesktopActivated(); - private slots: - void onNewWindow(); - void onModuleActivation( QAction* ); - void onCloseView( SUIT_ViewManager* ); - - void onStudyCreated( SUIT_Study* ); - void onStudyOpened( SUIT_Study* ); - void onStudySaved( SUIT_Study* ); - void onStudyClosed( SUIT_Study* ); - + void onDeleteReferences(); void onProperties(); void onDumpStudy(); void onLoadScript(); - void onPreferences(); - void onMRUActivated( QString ); - void onCatalogGen(); void onRegDisplay(); - - void onPreferenceChanged( QString&, QString&, QString& ); void onOpenWith(); - -private: - void updateWindows(); - void updateViewManagers(); - void updateModuleActions(); - - void loadWindowsGeometry(); - void saveWindowsGeometry(); - - void updatePreference( const QString&, const QString&, const QString& ); - - QString defaultModule() const; - void currentWindows( QMap& ) const; - void currentViewManagers( QStringList& ) const; - SUIT_ViewManager* createViewManager( const QString& vmType ); - void moduleIconNames( QMap& ) const; - - void activateWindows(); - -private: - typedef QMap ActionMap; - typedef QMap WindowMap; - -private: - SalomeApp_Preferences* myPrefs; - SalomeApp_SelectionMgr* mySelMgr; - ActionMap myActions; - WindowMap myWindows; - - SUIT_Accel* myAccel; - - static SalomeApp_Preferences* _prefs_; }; #ifdef WIN32 diff --git a/src/SalomeApp/SalomeApp_DataModel.cxx b/src/SalomeApp/SalomeApp_DataModel.cxx index 4a39c9943..3c63e644b 100644 --- a/src/SalomeApp/SalomeApp_DataModel.cxx +++ b/src/SalomeApp/SalomeApp_DataModel.cxx @@ -5,13 +5,13 @@ #include "SalomeApp_DataModel.h" #include "SalomeApp_Study.h" -#include "SalomeApp_RootObject.h" #include "SalomeApp_DataObject.h" #include "SalomeApp_Module.h" #include "SalomeApp_Application.h" -#include "SalomeApp_SelectionMgr.h" #include "SalomeApp_Engine_i.hxx" +#include "LightApp_RootObject.h" + #include #include @@ -51,12 +51,11 @@ SUIT_DataObject* SalomeApp_DataModel::BuildTree( const _PTR(SObject)& obj, for ( DataObjectListIterator it( allComponents ); it.current(); ++it ) { SUIT_DataObject* componentObj = it.current(); if ( componentObj->name() == aSName ) { - // mkr : modifications for update of already published in - // object browser, but not loaded yet components - CAM_Application* anApp = dynamic_cast - (SUIT_Session::session()->activeApplication()); - - // asv : corresponding DataObjects are DELETED before update (so they are re-built). + //mkr : modifications for update already published in + //object browser, but not loaded yet component + LightApp_Application* anApp = dynamic_cast + ( SUIT_Session::session()->activeApplication() ); + // asv : corresponding DataObjects are DELETED before update (so they are re-built). if (anApp && !anApp->module(aSName)) { // if module is not loaded, delete it's DataObject // jfa: remove children before DataObject deletion DataObjectList chilren = componentObj->children(/*recursive=*/true); @@ -93,7 +92,7 @@ SUIT_DataObject* SalomeApp_DataModel::BuildTree( const _PTR(SObject)& obj, /*!Purpose : Constructor*/ //======================================================================= SalomeApp_DataModel::SalomeApp_DataModel( CAM_Module* theModule ) -: CAM_DataModel( theModule ) +: LightApp_DataModel( theModule ) { } @@ -109,7 +108,7 @@ SalomeApp_DataModel::~SalomeApp_DataModel() // Function : open /*! Purpose : Open data model*/ //================================================================ -bool SalomeApp_DataModel::open( const QString&, CAM_Study* study ) +bool SalomeApp_DataModel::open( const QString& name, CAM_Study* study ) { SalomeApp_Study* aDoc = dynamic_cast( study ); if ( !aDoc ) @@ -119,72 +118,12 @@ bool SalomeApp_DataModel::open( const QString&, CAM_Study* study ) if ( anId.isEmpty() ) return true; // Probably nothing to load - QString anEngine = getModule()->engineIOR(); - if ( anEngine == "-1" ) { - // Module doesn't have a CORBA engine and doesn't use - // a default one -> SALOMEDS persistence cannot be used - return false; - } - - if ( anEngine.isEmpty() ) { - // Module use a default engine - //TODO: deside, if the below code has to be copyed in a light data model to avoid bulding of data tree twice - anEngine = SalomeApp_Application::defaultEngineIOR(); - } - _PTR(Study) aStudy ( aDoc->studyDS() ); // shared_ptr cannot be used here _PTR(SComponent) aSComp ( aStudy->FindComponentID( std::string( anId.latin1() ) ) ); + if ( aSComp ) + buildTree( aSComp, 0, aDoc ); - if ( aSComp ) { - _PTR(StudyBuilder) aBuilder( aStudy->NewBuilder() ); - if ( aBuilder ) { - try { - aBuilder->LoadWith( aSComp, std::string( anEngine.latin1() ) ); - } - catch( const SALOME::SALOME_Exception& ) { - // Oops, something went wrong while loading -> return an error - return false; - } - - // Something has been read -> create data model tree - buildTree( aSComp, 0, aDoc ); - } - } else { - // Don't return false here, for there might be no data - // for a given component in the study yet - } - - emit opened(); //TODO: is it really needed? to be removed maybe... - return true; -} - -//================================================================ -// Function : save -/*! Purpose : Emit saved()*/ -//================================================================ -bool SalomeApp_DataModel::save() -{ - emit saved(); - return true; -} - -//================================================================ -// Function : saveAs -/*! Purpose : Emit saved() */ -//================================================================ -bool SalomeApp_DataModel::saveAs( const QString&, CAM_Study* ) -{ - emit saved(); - return true; -} - -//================================================================ -// Function : close -/*! Purpose : Emit closed()*/ -//================================================================ -bool SalomeApp_DataModel::close() -{ - emit closed(); + LightApp_DataModel::open(name, study); return true; } @@ -192,33 +131,42 @@ bool SalomeApp_DataModel::close() // Function : update /*! Purpose : Update application.*/ //================================================================ -void SalomeApp_DataModel::update( SalomeApp_DataObject*, SalomeApp_Study* study ) +void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study ) { - SalomeApp_RootObject* studyRoot = 0; + SalomeApp_Study* aSStudy = 0; + LightApp_RootObject* studyRoot = 0; _PTR(SObject) sobj; SalomeApp_DataObject* modelRoot = dynamic_cast( root() ); if ( !modelRoot ){ // not yet connected to a study -> try using argument - if ( !study ) - study = dynamic_cast( getModule()->getApp()->activeStudy() ); - - if ( study ){ - studyRoot = dynamic_cast( study->root() ); - QString anId = getRootEntry( study ); - if ( !anId.isEmpty() ){ // if nothing is published in the study for this module -> do nothing - _PTR(Study) aStudy ( study->studyDS() ); - sobj = aStudy->FindComponentID( std::string( anId.latin1() ) ); + aSStudy = dynamic_cast( study ); + if ( !aSStudy ) + aSStudy = dynamic_cast( getModule()->getApp()->activeStudy() ); + if ( aSStudy ){ + studyRoot = dynamic_cast( aSStudy->root() ); + if ( studyRoot ) { + QString anId = getRootEntry( aSStudy ); + if ( !anId.isEmpty() ){ // if nothing is published in the study for this module -> do nothing + _PTR(Study) aStudy ( aSStudy->studyDS() ); + sobj = aStudy->FindComponentID( std::string( anId.latin1() ) ); + } } } } else{ - studyRoot = dynamic_cast( modelRoot->root() ); - study = studyRoot->study(); // value should not change here theoretically, but just to make sure - _PTR(Study) aStudy ( study->studyDS() ); - - // modelRoot->object() cannot be reused here: it is about to be deleted by buildTree() soon - sobj = aStudy->FindComponentID( std::string( modelRoot->entry().latin1() ) ); + studyRoot = dynamic_cast( modelRoot->root() ); + if ( studyRoot ) { + aSStudy = dynamic_cast( study ); + if ( aSStudy ) { + aSStudy = dynamic_cast( studyRoot->study() ); // value should not change here theoretically, but just to make sure + if ( aSStudy ) { + _PTR(Study) aStudy ( aSStudy->studyDS() ); + // modelRoot->object() cannot be reused here: it is about to be deleted by buildTree() soon + sobj = aStudy->FindComponentID( std::string( modelRoot->entry().latin1() ) ); + } + } + } } - buildTree( sobj, studyRoot, study ); + buildTree( sobj, studyRoot, aSStudy ); } //================================================================ @@ -256,10 +204,14 @@ SalomeApp_Module* SalomeApp_DataModel::getModule() const //================================================================ SalomeApp_Study* SalomeApp_DataModel::getStudy() const { - SalomeApp_RootObject* aRoot = dynamic_cast( root()->root() ); + if(!root()) return 0; + LightApp_RootObject* aRoot = dynamic_cast( root()->root() ); if ( !aRoot ) return 0; - return aRoot->study(); + SalomeApp_Study* aStudy = dynamic_cast( aRoot->study() ); + if ( !aStudy ) + return 0; + return aStudy; } //================================================================ @@ -281,99 +233,3 @@ QString SalomeApp_DataModel::getRootEntry( SalomeApp_Study* study ) const } return anEntry; } - -//================================================================ -// Function : isModified -/*! Purpose : default implementation, always returns false so as not to mask study's isModified()*/ -//================================================================ -bool SalomeApp_DataModel::isModified() const -{ - return false; -} - -//================================================================ -// Function : isSaved -/*! Purpose : default implementation, always returns true so as not to mask study's isSaved()*/ -//================================================================ -bool SalomeApp_DataModel::isSaved() const -{ - return true; -} - -// BEGIN: methods to be used by CORBAless modules - -//================================================================ -// Function : GetListOfFiles -/*! Purpose : to be used by CORBAless modules*/ -//================================================================ -std::vector SalomeApp_DataModel::GetListOfFiles() const - //(const int theStudyId, const char* theComponentName) const -{ - SUIT_Study* anActiveStudy = getModule()->getApp()->activeStudy(); - if (anActiveStudy) { - int aStudyId = anActiveStudy->id(); - SalomeApp_Engine_i* aDefaultEngine = SalomeApp_Engine_i::GetInstance(); - if (aDefaultEngine) { - return aDefaultEngine->GetListOfFiles(aStudyId, module()->name()); - } - } - - std::vector aListOfFiles; - return aListOfFiles; -} - -//================================================================ -// Function : SetListOfFiles -/*! Purpose : to be used by CORBAless modules*/ -//================================================================ -void SalomeApp_DataModel::SetListOfFiles (const std::vector theListOfFiles) - //(const std::vector theListOfFiles, - // const int theStudyId, - // const char* theComponentName) -{ - SUIT_Study* anActiveStudy = getModule()->getApp()->activeStudy(); - if (anActiveStudy) { - int aStudyId = anActiveStudy->id(); - SalomeApp_Engine_i* aDefaultEngine = SalomeApp_Engine_i::GetInstance(); - if (aDefaultEngine) { - aDefaultEngine->SetListOfFiles(theListOfFiles, aStudyId, module()->name()); - } - } -} - -//================================================================ -// Function : GetTmpDir -/*! Purpose : Static method. To be used by CORBAless modules*/ -//================================================================ -std::string SalomeApp_DataModel::GetTmpDir (const char* theURL, - const bool isMultiFile) -{ - std::string anURLDir = SALOMEDS_Tool::GetDirFromPath(theURL); - std::string aTmpDir = isMultiFile ? anURLDir : SALOMEDS_Tool::GetTmpDir(); - return aTmpDir; -} - -//================================================================ -// Function : RemoveTemporaryFiles -/*! Purpose : to be used by CORBAless modules*/ -//================================================================ -void SalomeApp_DataModel::RemoveTemporaryFiles (const bool isMultiFile) const -{ - if (isMultiFile) - return; - - std::vector aListOfFiles = GetListOfFiles(); - if (aListOfFiles.size() > 0) { - std::string aTmpDir = aListOfFiles[0]; - - const int n = aListOfFiles.size() - 1; - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - aSeq->length(n); - for (int i = 0; i < n; i++) - aSeq[i] = CORBA::string_dup(aListOfFiles[i + 1].c_str()); - - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); - } -} - -// END: methods to be used by CORBAless modules diff --git a/src/SalomeApp/SalomeApp_DataModel.h b/src/SalomeApp/SalomeApp_DataModel.h index 3f7d5f664..7ef34b088 100644 --- a/src/SalomeApp/SalomeApp_DataModel.h +++ b/src/SalomeApp/SalomeApp_DataModel.h @@ -11,18 +11,17 @@ #endif // _MSC_VER > 1000 #include "SalomeApp.h" -#include "CAM_DataModel.h" +#include "LightApp_DataModel.h" #include "SALOMEDSClient.hxx" class SalomeApp_Module; class SalomeApp_Study; class SalomeApp_DataObject; -class SalomeApp_SelectionMgr; // Class : SalomeApp_DataModel /// Description : Base class of data model -class SALOMEAPP_EXPORT SalomeApp_DataModel : public CAM_DataModel +class SALOMEAPP_EXPORT SalomeApp_DataModel : public LightApp_DataModel { Q_OBJECT @@ -35,44 +34,16 @@ public: SalomeApp_DataModel ( CAM_Module* theModule ); virtual ~SalomeApp_DataModel(); - /** @name These methods should be redefined in successors.*/ - //@{ virtual bool open( const QString&, CAM_Study* ); - virtual bool save(); - virtual bool saveAs( const QString&, CAM_Study* ); - virtual bool close(); + virtual void update( LightApp_DataObject* = 0, LightApp_Study* = 0 ); - virtual void update( SalomeApp_DataObject* = 0, SalomeApp_Study* = 0 ); - - virtual bool isModified() const; - virtual bool isSaved() const; - //@} - -signals: - void opened(); - void saved(); - void closed(); + QString getRootEntry( SalomeApp_Study* ) const; + SalomeApp_Module* getModule() const; protected: - SalomeApp_Module* getModule() const; SalomeApp_Study* getStudy() const; virtual void buildTree(const _PTR(SObject)&, SUIT_DataObject*, SalomeApp_Study* ); - - /** @name methods to be used by CORBAless modules*/ - //@{ - std::vector GetListOfFiles () const; - void SetListOfFiles (const std::vector theListOfFiles); - - static std::string GetTmpDir (const char* theURL, - const bool isMultiFile); - - void RemoveTemporaryFiles (const bool isMultiFile) const; - //@} - // END: methods to be used by CORBAless modules - -private: - QString getRootEntry( SalomeApp_Study* ) const; }; #endif diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index 0e9866fa9..62cb0add7 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -1,7 +1,7 @@ #include "SalomeApp_DataObject.h" #include "SalomeApp_Study.h" -#include "SalomeApp_RootObject.h" +#include "LightApp_RootObject.h" #include #include @@ -15,62 +15,21 @@ #include #include -/*! - Class: SalomeApp_DataObject::Key - Level: Internal -*/ -class SalomeApp_DataObject::Key : public SUIT_DataObjectKey -{ -public: - Key( const QString& ); - virtual ~Key(); - - virtual bool isLess( const SUIT_DataObjectKey* ) const; - virtual bool isEqual( const SUIT_DataObjectKey* ) const; - -private: - QString myEntry; -}; - -/*!Constructor. Initialize by \a entry.*/ -SalomeApp_DataObject::Key::Key( const QString& entry ) -: SUIT_DataObjectKey(), - myEntry( entry ) -{ -} - -/*!Destructor. Do nothing.*/ -SalomeApp_DataObject::Key::~Key() -{ -} - -/*!Checks: Is current key less than \a other.*/ -bool SalomeApp_DataObject::Key::isLess( const SUIT_DataObjectKey* other ) const -{ - Key* that = (Key*)other; - return myEntry < that->myEntry; -} - -/*!Checks: Is current key equal with \a other.*/ -bool SalomeApp_DataObject::Key::isEqual( const SUIT_DataObjectKey* other ) const -{ - Key* that = (Key*)other; - return myEntry == that->myEntry; -} - /* Class: SalomeApp_DataObject Level: Public */ /*!Constructor. Initialize by \a parent*/ SalomeApp_DataObject::SalomeApp_DataObject( SUIT_DataObject* parent ) -: CAM_DataObject( parent ) +: LightApp_DataObject( parent ), + CAM_DataObject( parent ) { } /*!Constructor. Initialize by \a parent and SObject*/ SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj, SUIT_DataObject* parent ) -: CAM_DataObject( parent ) +: LightApp_DataObject( parent ), + CAM_DataObject( parent ) { myObject = sobj; } @@ -90,13 +49,6 @@ QString SalomeApp_DataObject::entry() const return QString::null; } -/*!Create and return new key object.*/ -SUIT_DataObjectKey* SalomeApp_DataObject::key() const -{ - QString str = entry(); - return new Key( str ); -} - /*!Gets name of object.*/ QString SalomeApp_DataObject::name() const { @@ -131,7 +83,7 @@ QPixmap SalomeApp_DataObject::icon() const _PTR(AttributePixMap) aPixAttr ( anAttr ); if ( aPixAttr->HasPixMap() ){ QString pixmapName = QObject::tr( aPixAttr->GetPixMap().c_str() ); - SalomeApp_RootObject* aRoot = dynamic_cast( root() ); + LightApp_RootObject* aRoot = dynamic_cast( root() ); if ( aRoot && aRoot->study() ) { QPixmap pixmap = aRoot->study()->application()->resourceMgr()->loadPixmap( componentDataType(), pixmapName, false ); return pixmap; @@ -226,25 +178,6 @@ QString SalomeApp_DataObject::toolTip() const return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() ); } -/*!Gets component object. - *\retval SUIT_DataObject. - */ -SUIT_DataObject* SalomeApp_DataObject::componentObject() const -{ - SUIT_DataObject* compObj = 0; // for root object (invisible SALOME_ROOT_OBJECT) - - if ( parent() && parent() == root() ) - compObj = (SUIT_DataObject*)this; // for component-level objects - else - { - compObj = parent(); // for lower level objects - while ( compObj && compObj->parent() != root() ) - compObj = compObj->parent(); - } - - return compObj; -} - /*!Get component type.*/ QString SalomeApp_DataObject::componentDataType() const { diff --git a/src/SalomeApp/SalomeApp_DataObject.h b/src/SalomeApp/SalomeApp_DataObject.h index 434f96baa..34042162d 100644 --- a/src/SalomeApp/SalomeApp_DataObject.h +++ b/src/SalomeApp/SalomeApp_DataObject.h @@ -3,16 +3,15 @@ #include "SalomeApp.h" -#include "CAM_DataObject.h" +#include "LightApp_DataObject.h" #include "CAM_RootObject.h" #include "SALOMEDSClient.hxx" class SalomeApp_Study; -class SALOMEAPP_EXPORT SalomeApp_DataObject : public virtual CAM_DataObject +class SALOMEAPP_EXPORT SalomeApp_DataObject : public LightApp_DataObject { - class Key; public: enum { CT_Value, CT_Entry, CT_IOR, CT_RefEntry }; @@ -29,7 +28,6 @@ public: virtual QString text( const int ) const; virtual QColor color( const ColorRole ) const; - virtual SUIT_DataObjectKey* key() const; virtual QString entry() const; /*! location of corresponding SALOMEDS::SObject */ @@ -38,7 +36,6 @@ public: bool isReference() const; _PTR(SObject) referencedObject() const; - SUIT_DataObject* componentObject() const; /*! GEOM, SMESH, VISU, etc.*/ QString componentDataType() const; diff --git a/src/SalomeApp/SalomeApp_Module.cxx b/src/SalomeApp/SalomeApp_Module.cxx index f62a3eca4..e37e51d64 100644 --- a/src/SalomeApp/SalomeApp_Module.cxx +++ b/src/SalomeApp/SalomeApp_Module.cxx @@ -8,102 +8,24 @@ #include "SalomeApp_Study.h" #include "SalomeApp_DataModel.h" #include "SalomeApp_Application.h" -#include "SalomeApp_Preferences.h" -#include "SalomeApp_UpdateFlags.h" -#include "SalomeApp_Operation.h" -#include "SalomeApp_SwitchOp.h" -#include +#include "LightApp_Preferences.h" -#include +#include "CAM_DataModel.h" -#include -#include +#include "OB_Browser.h" -#include - -#include -#include -#include -#include -#include -#include +#include +#include /*!Constructor.*/ SalomeApp_Module::SalomeApp_Module( const QString& name ) -: CAM_Module( name ), -myPopupMgr( 0 ), -mySwitchOp( 0 ) +: LightApp_Module( name ) { } /*!Destructor.*/ SalomeApp_Module::~SalomeApp_Module() -{ - if ( mySwitchOp ) - delete mySwitchOp; -} - -/*!Initialize module.*/ -void SalomeApp_Module::initialize( CAM_Application* app ) -{ - CAM_Module::initialize( app ); - - SUIT_ResourceMgr* resMgr = app ? app->resourceMgr() : 0; - if ( resMgr ) - resMgr->raiseTranslators( name() ); -} - -/*!Activate module.*/ -bool SalomeApp_Module::activateModule( SUIT_Study* study ) -{ - bool res = CAM_Module::activateModule( study ); - - if ( res && application() && application()->resourceMgr() ) - application()->resourceMgr()->raiseTranslators( name() ); - - if ( mySwitchOp == 0 ) - mySwitchOp = new SalomeApp_SwitchOp( this ); - - return res; -} - -/*!Deactivate module.*/ -bool SalomeApp_Module::deactivateModule( SUIT_Study* ) -{ - delete mySwitchOp; - mySwitchOp = 0; - - return true; -} - -/*!NOT IMPLEMENTED*/ -void SalomeApp_Module::selectionChanged() -{ -} - -/*!NOT IMPLEMENTED*/ -void SalomeApp_Module::MenuItem() -{ -} - -/*!NOT IMPLEMENTED*/ -void SalomeApp_Module::windows( QMap& ) const -{ -} - -/*!NOT IMPLEMENTED*/ -void SalomeApp_Module::viewManagers( QStringList& ) const -{ -} - -/*!NOT IMPLEMENTED*/ -void SalomeApp_Module::createPreferences() -{ -} - -/*!NOT IMPLEMENTED*/ -void SalomeApp_Module::preferencesChanged( const QString&, const QString& ) { } @@ -113,235 +35,9 @@ SalomeApp_Application* SalomeApp_Module::getApp() const return (SalomeApp_Application*)application(); } -/*!NOT IMPLEMENTED*/ -void SalomeApp_Module::onModelOpened() -{ -} - -/*!NOT IMPLEMENTED*/ -void SalomeApp_Module::onModelSaved() -{ -} - -/*!NOT IMPLEMENTED*/ -void SalomeApp_Module::onModelClosed() -{ -} - -/*!Gets popup manager.(create if not exist)*/ -QtxPopupMgr* SalomeApp_Module::popupMgr() -{ - if ( !myPopupMgr ) - myPopupMgr = new QtxPopupMgr( 0, this ); - return myPopupMgr; -} - -/*!Gets preferences.*/ -SalomeApp_Preferences* SalomeApp_Module::preferences() const -{ - SalomeApp_Preferences* pref = 0; - if ( getApp() ) - pref = getApp()->preferences(); - return pref; -} - /*!Create new instance of data model and return it.*/ CAM_DataModel* SalomeApp_Module::createDataModel() { return new SalomeApp_DataModel(this); } -/*!Update object browser.*/ -void SalomeApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root ) -{ - if( updateDataModel ) - if( CAM_DataModel* aDataModel = dataModel() ) - if( SalomeApp_DataModel* aModel = dynamic_cast( aDataModel ) ) - aModel->update( 0, dynamic_cast( getApp()->activeStudy() ) ); - getApp()->objectBrowser()->updateTree( root ); -} - -/*!Context menu popup.*/ -void SalomeApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ ) -{ - SalomeApp_Selection* sel = createSelection(); - sel->init( client, getApp()->selectionMgr() ); - popupMgr()->updatePopup( menu, sel ); - delete sel; -} - -/*!Create and return instance of SalomeApp_Selection.*/ -SalomeApp_Selection* SalomeApp_Module::createSelection() const -{ - return new SalomeApp_Selection(); -} - -/*!Add preference to preferences.*/ -int SalomeApp_Module::addPreference( const QString& label ) -{ - SalomeApp_Preferences* pref = preferences(); - if ( !pref ) - return -1; - - int catId = pref->addPreference( moduleName(), -1 ); - if ( catId == -1 ) - return -1; - - return pref->addPreference( label, catId ); -} - -/*!Add preference to preferences.*/ -int SalomeApp_Module::addPreference( const QString& label, const int pId, const int type, - const QString& section, const QString& param ) -{ - SalomeApp_Preferences* pref = preferences(); - if ( !pref ) - return -1; - - return pref->addPreference( moduleName(), label, pId, type, section, param ); -} - -/*!Gets property of preferences.*/ -QVariant SalomeApp_Module::preferenceProperty( const int id, const QString& prop ) const -{ - QVariant var; - SalomeApp_Preferences* pref = preferences(); - if ( pref ) - var = pref->itemProperty( id, prop ); - return var; -} - - -/*!Set property of preferences.*/ -void SalomeApp_Module::setPreferenceProperty( const int id, const QString& prop, const QVariant& var ) -{ - SalomeApp_Preferences* pref = preferences(); - if ( pref ) - pref->setItemProperty( id, prop, var ); -} - -/*! - * \brief Update something in accordance with update flags - * \param theFlags - update flags -* -* Update viewer or/and object browser etc. in accordance with update flags ( see -* SalomeApp_UpdateFlags enumeration ). Derived modules can redefine this method for their -* own purposes -*/ -void SalomeApp_Module::update( const int theFlags ) -{ - if ( theFlags & UF_Model ) - { - if( CAM_DataModel* aDataModel = dataModel() ) - if( SalomeApp_DataModel* aModel = dynamic_cast( aDataModel ) ) - aModel->update( 0, dynamic_cast( getApp()->activeStudy() ) ); - } - if ( theFlags & UF_ObjBrowser ) - getApp()->objectBrowser()->updateTree( 0 ); - if ( theFlags & UF_Controls ) - updateControls(); - if ( theFlags & UF_Viewer ) - { - if ( SUIT_ViewManager* viewMgr = getApp()->activeViewManager() ) - if ( SUIT_ViewWindow* viewWnd = viewMgr->getActiveView() ) - { - if ( viewWnd->inherits( "SVTK_ViewWindow" ) ) - ( (SVTK_ViewWindow*)viewWnd )->Repaint(); - else if ( viewWnd->inherits( "OCCViewer_ViewWindow" ) ) - ( (OCCViewer_ViewWindow*)viewWnd )->getViewPort()->onUpdate(); - else if ( viewWnd->inherits( "Plot2d_ViewWindow" ) ) - ( (Plot2d_ViewWindow*)viewWnd )->getViewFrame()->Repaint(); - else if ( viewWnd->inherits( "GLViewer_ViewFrame" ) ) - ( (GLViewer_ViewFrame*)viewWnd )->getViewPort()->onUpdate(); - } - } -} - -/*! - * \brief Updates controls -* -* Updates (i.e. disable/enable) controls states (menus, tool bars etc.). This method is -* called from update( UF_Controls ). You may redefine it in concrete module. -*/ -void SalomeApp_Module::updateControls() -{ -} - -/*! - * \brief Starts operation with given identifier - * \param id - identifier of operation to be started -* -* Module stores operations in map. This method starts operation by id. -* If operation isn't in map, then it will be created by createOperation method -* and will be inserted to map -*/ -void SalomeApp_Module::startOperation( const int id ) -{ - SalomeApp_Operation* op = 0; - if( myOperations.contains( id ) ) - op = myOperations[ id ]; - else - { - op = createOperation( id ); - if( op ) - { - myOperations.insert( id, op ); - op->setModule( this ); - connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) ); - connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) ); - } - } - - if( op ) - op->start(); -} - -/*! - * \brief Creates operation with given identifier - * \param id - identifier of operation to be started - * \return Pointer on created operation or NULL if operation is not created -* -* Creates operation with given id. You should not call this method, it will be called -* automatically from startOperation. You may redefine this method in concrete module to -* create operations. -*/ -SalomeApp_Operation* SalomeApp_Module::createOperation( const int /*id*/ ) const -{ - return 0; -} - -/*! - * \brief Virtual protected slot called when operation stopped - * \param theOp - stopped operation -* -* Virtual protected slot called when operation stopped. Redefine this slot if you want to -* perform actions after stopping operation -*/ -void SalomeApp_Module::onOperationStopped( SUIT_Operation* /*theOp*/ ) -{ -} - -/*! - * \brief Virtual protected slot called when operation destroyed - * \param theOp - destroyed operation -* -* Virtual protected slot called when operation destroyed. Redefine this slot if you want to -* perform actions after destroying operation. Base implementation removes pointer on -* destroyed operation from the map of operations -*/ -void SalomeApp_Module::onOperationDestroyed() -{ - const QObject* s = sender(); - if( s && s->inherits( "SalomeApp_Operation" ) ) - { - const SalomeApp_Operation* op = ( SalomeApp_Operation* )s; - MapOfOperation::const_iterator anIt = myOperations.begin(), - aLast = myOperations.end(); - for( ; anIt!=aLast; anIt++ ) - if( anIt.data()==op ) - { - myOperations.remove( anIt.key() ); - break; - } - } -} diff --git a/src/SalomeApp/SalomeApp_Module.h b/src/SalomeApp/SalomeApp_Module.h index 644608c5d..67bc25ed0 100644 --- a/src/SalomeApp/SalomeApp_Module.h +++ b/src/SalomeApp/SalomeApp_Module.h @@ -7,34 +7,19 @@ #define SALOMEAPP_MODULE_H #include "SalomeApp.h" -#include "SalomeApp_Selection.h" -#include +#include #include -class QDockWindow; - -class CAM_Study; - -class QtxPopupMgr; - -class SUIT_Operation; -class SUIT_Convertor; -class SUIT_ViewModel; +class CAM_DataModel; class SUIT_DataObject; - -class SalomeApp_DataModel; class SalomeApp_Application; -class SalomeApp_Preferences; -class SalomeApp_SelectionManager; -class SalomeApp_Operation; -class SalomeApp_SwitchOp; /*! * \brief Base class for all salome modules */ -class SALOMEAPP_EXPORT SalomeApp_Module : public CAM_Module +class SALOMEAPP_EXPORT SalomeApp_Module : public LightApp_Module { Q_OBJECT @@ -42,10 +27,6 @@ public: SalomeApp_Module( const QString& ); virtual ~SalomeApp_Module(); - virtual void initialize( CAM_Application* ); - virtual void windows( QMap& ) const; - virtual void viewManagers( QStringList& ) const; - /*! engineIOR() should be a pure virtual method, to avoid logical errors!\n * Implementation in derived classes can return the following values:\n * module`s engine IOR - means that this is a standard SALOME module with a CORBA engine @@ -53,75 +34,13 @@ public: * \li "-1" - means that this is a light module, SALOMEDS persistence is not used at all\n */ virtual QString engineIOR() const = 0; - - virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& ); - - virtual void createPreferences(); /*! Convenient shortcuts*/ SalomeApp_Application* getApp() const; - virtual void update( const int ); - // Update viewer or/and object browser etc. in accordance with update flags - // ( see SalomeApp_UpdateFlags enumeration ). Derived modules can redefine this method - // for their own purposes - - void updateObjBrowser( bool = true, SUIT_DataObject* = 0 ); - // Update object bropwser ( for updating model or whole object browser use update() method - // can be used ) - - virtual void selectionChanged(); - virtual void preferencesChanged( const QString&, const QString& ); - - virtual void studyActivated() {}; - -public slots: - virtual bool activateModule( SUIT_Study* ); - virtual bool deactivateModule( SUIT_Study* ); - - void MenuItem(); - -protected slots: - virtual void onModelSaved(); - virtual void onModelOpened(); - virtual void onModelClosed(); - virtual void onOperationStopped( SUIT_Operation* ); - virtual void onOperationDestroyed(); - -protected: - QtxPopupMgr* popupMgr(); - SalomeApp_Preferences* preferences() const; - + protected: virtual CAM_DataModel* createDataModel(); - virtual SalomeApp_Selection* createSelection() const; - virtual void updateControls(); - - /*! Module stores operations in map. This method starts operation by id. - * If operation isn't in map, then it will be created by createOperation method - * and will be inserted to map - */ - void startOperation( const int ); - - /*! Create operation by its id. You must not call this method, it will be called automatically - * by startOperation. Please redefine this method in current module - */ - virtual SalomeApp_Operation* createOperation( const int ) const; - - int addPreference( const QString& label ); - int addPreference( const QString& label, const int pId, const int = -1, - const QString& section = QString::null, - const QString& param = QString::null ); - QVariant preferenceProperty( const int, const QString& ) const; - void setPreferenceProperty( const int, const QString&, const QVariant& ); - -private: - typedef QMap MapOfOperation; - -private: - QtxPopupMgr* myPopupMgr; - MapOfOperation myOperations; - SalomeApp_SwitchOp* mySwitchOp; }; #endif diff --git a/src/SalomeApp/SalomeApp_PyInterp.cxx b/src/SalomeApp/SalomeApp_PyInterp.cxx index 7cf6ce66d..a6549f646 100755 --- a/src/SalomeApp/SalomeApp_PyInterp.cxx +++ b/src/SalomeApp/SalomeApp_PyInterp.cxx @@ -30,11 +30,13 @@ #include #include -#ifdef _DEBUG_ -static int MYDEBUG = 0; -#else -static int MYDEBUG = 0; -#endif + +#include +#include + +#include "PyInterp_base.h" // this include must be first (see PyInterp_base.h)! + +#include /*! * constructor : multi Python interpreter, one per SALOME study. @@ -107,3 +109,23 @@ bool SalomeApp_PyInterp::initContext() return true; } + +void SalomeApp_PyInterp::init_python() +{ + /* + * Initialize the main state (_gtstate) if not already done + * The lock is released on init_python output + * It is the caller responsability to acquire it if needed + */ + MESSAGE("PyInterp_base::init_python"); + ASSERT(KERNEL_PYTHON::_gtstate); // initialisation in main + SCRUTE(KERNEL_PYTHON::_gtstate); +// if(!_gtstate){ +// PyReleaseLock aReleaseLock; +// Py_Initialize(); // Initialize the interpreter +// PyEval_InitThreads(); // Initialize and acquire the global interpreter lock +// PySys_SetArgv(_argc,_argv); // initialize sys.argv +// _gtstate = PyThreadState_Get(); +// } +} + diff --git a/src/SalomeApp/SalomeApp_PyInterp.h b/src/SalomeApp/SalomeApp_PyInterp.h index 065f8efd0..a15b3767f 100755 --- a/src/SalomeApp/SalomeApp_PyInterp.h +++ b/src/SalomeApp/SalomeApp_PyInterp.h @@ -37,6 +37,8 @@ public: SalomeApp_PyInterp(); virtual ~SalomeApp_PyInterp(); + virtual void init_python(); + protected: virtual bool initContext(); }; diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index e1065c9fe..97be8db88 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -2,21 +2,31 @@ #include "SalomeApp_Module.h" #include "SalomeApp_DataModel.h" -#include "SalomeApp_RootObject.h" +#include "LightApp_RootObject.h" #include "SalomeApp_DataObject.h" #include "SalomeApp_Application.h" +#include "SalomeApp_Engine_i.hxx" #include #include +#include + #include "utilities.h" +#include "string.h" +#include "vector.h" + +#include "SALOMEDS_Tool.hxx" + +#include +#include CORBA_SERVER_HEADER(SALOME_Exception) /*! Constructor. */ SalomeApp_Study::SalomeApp_Study( SUIT_Application* app ) -: CAM_Study( app ) +: LightApp_Study( app ) { } @@ -62,12 +72,7 @@ void SalomeApp_Study::createDocument() setStudyDS( study ); setStudyName( aName ); - // create myRoot - setRoot( new SalomeApp_RootObject( this ) ); - - CAM_Study::createDocument(); - - emit created( this ); + LightApp_Study::createDocument(); } //======================================================================= @@ -85,22 +90,8 @@ bool SalomeApp_Study::openDocument( const QString& theFileName ) setStudyDS( study ); - setRoot( new SalomeApp_RootObject( this ) ); // create myRoot - - // update loaded data models: call open() and update() on them. - ModelList dm_s; - dataModels( dm_s ); - for ( ModelListIterator it( dm_s ); it.current(); ++it ) - openDataModel( studyName(), it.current() ); - - // this will build a SUIT_DataObject-s tree under myRoot member field - // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step - // but tree that corresponds to not-loaded data models will be updated any way. - ((SalomeApp_Application*)application())->updateObjectBrowser( false ); - - bool res = CAM_Study::openDocument( theFileName ); - emit opened( this ); - + bool res = LightApp_Study::openDocument( theFileName ); + return res; } @@ -119,95 +110,56 @@ bool SalomeApp_Study::loadDocument( const QString& theStudyName ) setStudyDS( study ); - setRoot( new SalomeApp_RootObject( this ) ); // create myRoot - - //SRN: BugID IPAL9021, put there the same code as in a method openDocument - - // update loaded data models: call open() and update() on them. - ModelList dm_s; - dataModels( dm_s ); - for ( ModelListIterator it( dm_s ); it.current(); ++it ) - openDataModel( studyName(), it.current() ); - - // this will build a SUIT_DataObject-s tree under myRoot member field - // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step - // but tree that corresponds to not-loaded data models will be updated any way. - ((SalomeApp_Application*)application())->updateObjectBrowser( false ); - - bool res = CAM_Study::openDocument( theStudyName ); - emit opened( this ); - - //SRN: BugID IPAL9021: End + bool res = LightApp_Study::loadDocument( theStudyName ); return res; } //======================================================================= // name : saveDocumentAs -/*! Purpose : Save document */ +/*! Purpose : Save document*/ //======================================================================= bool SalomeApp_Study::saveDocumentAs( const QString& theFileName ) { - ModelList list; dataModels( list ); - - SalomeApp_DataModel* aModel = (SalomeApp_DataModel*)list.first(); - for ( ; aModel; aModel = (SalomeApp_DataModel*)list.next() ) - aModel->saveAs( theFileName, this ); - // save SALOMEDS document SUIT_ResourceMgr* resMgr = application()->resourceMgr(); if( !resMgr ) return false; + bool res = LightApp_Study::saveDocumentAs( theFileName ); //SRN: BugID IPAL9377, removed usage of uninitialized variable bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ), isAscii = resMgr->booleanValue( "Study", "ascii_file", true ); isAscii ? SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.latin1(), studyDS(), isMultiFile ) : SalomeApp_Application::studyMgr()->SaveAs ( theFileName.latin1(), studyDS(), isMultiFile ); - bool res = CAM_Study::saveDocumentAs( theFileName ); //SRN: BugID IPAL9377, removed usage of uninitialized variable - - if ( res ) - emit saved( this ); - return res; } //======================================================================= // name : saveDocument -/*! Purpose : Save document */ +/*! Purpose : Save document*/ //======================================================================= void SalomeApp_Study::saveDocument() { - ModelList list; dataModels( list ); - - SalomeApp_DataModel* aModel = (SalomeApp_DataModel*)list.first(); - for ( ; aModel; aModel = (SalomeApp_DataModel*)list.next() ) - aModel->save(); - - CAM_Study::saveDocument(); - // save SALOMEDS document SUIT_ResourceMgr* resMgr = application()->resourceMgr(); if( !resMgr ) return; + LightApp_Study::saveDocument(); bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ), isAscii = resMgr->booleanValue( "Study", "ascii_file", true ); isAscii ? SalomeApp_Application::studyMgr()->SaveASCII( studyDS(), isMultiFile ) : SalomeApp_Application::studyMgr()->Save ( studyDS(), isMultiFile ); - - emit saved( this ); } //================================================================ // Function : closeDocument -/*! Purpose : Close document */ +/*! Purpose : Close document*/ //================================================================ void SalomeApp_Study::closeDocument(bool permanently) { - // Inform everybody that this study is going to close when it's most safe to, - // i.e. in the very beginning - emit closed( this ); + LightApp_Study::closeDocument(permanently); // close SALOMEDS document _PTR(Study) studyPtr = studyDS(); @@ -217,25 +169,18 @@ void SalomeApp_Study::closeDocument(bool permanently) SALOMEDSClient_Study* aStudy = 0; setStudyDS( _PTR(Study)(aStudy) ); } - - CAM_Study::closeDocument(permanently); } //================================================================ // Function : isModified -/*! Purpose : Check data model on modifications.*/ +// Purpose : //================================================================ bool SalomeApp_Study::isModified() const { bool isAnyChanged = studyDS() && studyDS()->IsModified(); - ModelList list; dataModels( list ); + if (!isAnyChanged) + isAnyChanged = LightApp_Study::isModified(); - SalomeApp_DataModel* aModel = 0; - for ( QPtrListIterator it( list ); it.current() && !isAnyChanged; ++it ){ - aModel = dynamic_cast( it.current() ); - if ( aModel ) - isAnyChanged = aModel->isModified(); - } return isAnyChanged; } @@ -246,14 +191,9 @@ bool SalomeApp_Study::isModified() const bool SalomeApp_Study::isSaved() const { bool isAllSaved = studyDS() && studyDS()->GetPersistentReference().size(); - ModelList list; dataModels( list ); + if (!isAllSaved) + isAllSaved = LightApp_Study::isModified(); - SalomeApp_DataModel* aModel = 0; - for ( QPtrListIterator it( list ); it.current() && isAllSaved; ++it ){ - aModel = dynamic_cast( it.current() ); - if ( aModel ) - isAllSaved = aModel->isSaved(); - } return isAllSaved; } @@ -275,20 +215,23 @@ void SalomeApp_Study::dataModelInserted (const CAM_DataModel* dm) CAM_Study::dataModelInserted(dm); // Create SComponent for module, using default engine (CORBAless) - SalomeApp_Module* aModule = (SalomeApp_Module*)(dm->module()); - if (aModule) { - QString anEngineIOR = aModule->engineIOR(); - if (anEngineIOR.isEmpty()) { // CORBAless module - // Check SComponent existance - _PTR(SComponent) aComp = studyDS()->FindComponent(dm->module()->name()); - if (!aComp) { - // Create SComponent - _PTR(StudyBuilder) aBuilder = studyDS()->NewBuilder(); - aComp = aBuilder->NewComponent(dm->module()->name()); - - // Set default engine IOR - aBuilder->DefineComponentInstance(aComp, SalomeApp_Application::defaultEngineIOR().latin1()); - } + // SalomeApp_Module* aModule = (SalomeApp_Module*)(dm->module()); + SalomeApp_Module* aModule = dynamic_cast( dm->module() ); + // 1. aModule == 0 means that this is a light module (no CORBA enigine) + // 2. engineIOR == "" means this is a full module but without CORBA engine + if (!aModule || aModule->engineIOR().isEmpty()) { + // Check SComponent existance + _PTR(Study) aStudy = studyDS(); + if (!aStudy) + return; + _PTR(SComponent) aComp = aStudy->FindComponent(dm->module()->name()); + if (!aComp) { + // Create SComponent + _PTR(StudyBuilder) aBuilder = studyDS()->NewBuilder(); + aComp = aBuilder->NewComponent(dm->module()->name()); + + // Set default engine IOR + aBuilder->DefineComponentInstance(aComp, SalomeApp_Application::defaultEngineIOR().latin1()); } } } @@ -301,13 +244,64 @@ bool SalomeApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm if (!dm) return false; - SalomeApp_DataModel* aDM = (SalomeApp_DataModel*)(dm); - if (aDM && aDM->open(studyName, this)) { + // SalomeApp_DataModel* aDM = (SalomeApp_DataModel*)(dm); + SalomeApp_Module* aModule = dynamic_cast( dm->module() ); + _PTR(Study) aStudy = studyDS(); // shared_ptr cannot be used here + _PTR(SComponent) aSComp; + QString anEngine; + // 1. aModule == 0 means that this is a light module (no CORBA enigine) + // 2. engineIOR == "" means this is a full module but without CORBA engine + if (!aModule || aModule->engineIOR().isEmpty()) { + anEngine = SalomeApp_Application::defaultEngineIOR(); + aSComp = aStudy->FindComponent(dm->module()->name()); + } + else { + SalomeApp_DataModel* aDM = dynamic_cast( dm ); + if ( aDM ) { + QString anId = aDM->getRootEntry( this ); + if ( anId.isEmpty() ) + return true; // Probably nothing to load + + if ( aDM ) { + anEngine = aDM->getModule()->engineIOR(); + if ( anEngine == "-1" ) { + // Module doesn't have a CORBA engine and doesn't use + // a default one -> SALOMEDS persistence cannot be used + return false; + } + } + if ( anEngine.isEmpty() ) { + // Module use a default engine + //TODO: deside, if the below code has to be copyed in a light data model to avoid bulding of data tree twice + anEngine = SalomeApp_Application::defaultEngineIOR(); + } + aSComp = aStudy->FindComponentID( std::string( anId.latin1() ) ); + } + } + if ( aSComp ) { + _PTR(StudyBuilder) aBuilder( aStudy->NewBuilder() ); + if ( aBuilder ) { + try { + aBuilder->LoadWith( aSComp, std::string( anEngine.latin1() ) ); + } + catch( const SALOME::SALOME_Exception& ) { + // Oops, something went wrong while loading -> return an error + return false; + } + // Something has been read -> create data model tree + // aDM->buildTree( aSComp, 0, this ); + } + } else { + // Don't return false here, for there might be no data + // for a given component in the study yet + } + if (dm && dm->open(studyName, this)) { // Something has been read -> create data model tree - aDM->update(NULL, this); + LightApp_DataModel* aDM = dynamic_cast( dm ); + if ( aDM ) + aDM->update(NULL, this); return true; } - return false; } @@ -333,6 +327,72 @@ QString SalomeApp_Study::newStudyName() const return newName; } +//================================================================ +// Function : GetListOfFiles +/*! Purpose : to be used by CORBAless modules*/ +//================================================================ +std::vector SalomeApp_Study::GetListOfFiles() const +{ + SalomeApp_Engine_i* aDefaultEngine = SalomeApp_Engine_i::GetInstance(); + if (aDefaultEngine) { + const char* aName = ((CAM_Application*)application())->activeModule()->name(); + return aDefaultEngine->GetListOfFiles(id(), aName); + } + + std::vector aListOfFiles; + return aListOfFiles; +} + +//================================================================ +// Function : SetListOfFiles +/*! Purpose : to be used by CORBAless modules*/ +//================================================================ +void SalomeApp_Study::SetListOfFiles (const std::vector theListOfFiles) +{ + SalomeApp_Engine_i* aDefaultEngine = SalomeApp_Engine_i::GetInstance(); + if (aDefaultEngine) { + const char* aName = ((CAM_Application*)application())->activeModule()->name(); + aDefaultEngine->SetListOfFiles(theListOfFiles, id(), aName); + } +} + +//================================================================ +// Function : GetTmpDir +/*! Purpose : to be used by CORBAless modules*/ +//================================================================ +std::string SalomeApp_Study::GetTmpDir (const char* theURL, + const bool isMultiFile) +{ + std::string anURLDir = SALOMEDS_Tool::GetDirFromPath(theURL); + std::string aTmpDir = isMultiFile ? anURLDir : SALOMEDS_Tool::GetTmpDir(); + return aTmpDir; +} + +//================================================================ +// Function : RemoveTemporaryFiles +/*! Purpose : to be used by CORBAless modules*/ +//================================================================ +void SalomeApp_Study::RemoveTemporaryFiles (const bool isMultiFile) const +{ + if (isMultiFile) + return; + + std::vector aListOfFiles = GetListOfFiles(); + if (aListOfFiles.size() > 0) { + std::string aTmpDir = aListOfFiles[0]; + + const int n = aListOfFiles.size() - 1; + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + aSeq->length(n); + for (int i = 0; i < n; i++) + aSeq[i] = CORBA::string_dup(aListOfFiles[i + 1].c_str()); + + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); + } +} + +// END: methods to be used by CORBAless modules + void SalomeApp_Study::deleteReferencesTo( _PTR( SObject ) obj ) { _PTR(StudyBuilder) sb = studyDS()->NewBuilder(); @@ -347,3 +407,4 @@ void SalomeApp_Study::deleteReferencesTo( _PTR( SObject ) obj ) } } } + diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index 1404446f4..b75dd4f08 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -3,7 +3,7 @@ #include "SalomeApp.h" -#include +#include #ifdef WIN32 #pragma warning( disable:4251 ) @@ -11,7 +11,7 @@ #include "SALOMEDSClient.hxx" -class SALOMEAPP_EXPORT SalomeApp_Study : public CAM_Study +class SALOMEAPP_EXPORT SalomeApp_Study : public LightApp_Study { Q_OBJECT @@ -35,15 +35,15 @@ public: _PTR(Study) studyDS() const; + virtual std::vector GetListOfFiles () const; + virtual void SetListOfFiles (const std::vector theListOfFiles); + virtual std::string GetTmpDir (const char* theURL, + const bool isMultiFile); + virtual void RemoveTemporaryFiles (const bool isMultiFile) const; + // to delete all references to object, whose have the same component void deleteReferencesTo( _PTR( SObject ) ); -signals: - void saved( SUIT_Study* ); - void opened( SUIT_Study* ); - void closed( SUIT_Study* ); - void created( SUIT_Study* ); - protected: virtual void dataModelInserted( const CAM_DataModel* ); virtual bool openDataModel( const QString&, CAM_DataModel* ); @@ -56,7 +56,6 @@ private: _PTR(Study) myStudyDS; }; - #ifdef WIN32 #pragma warning( default:4251 ) #endif diff --git a/src/SalomeApp/SalomeApp_TypeFilter.cxx b/src/SalomeApp/SalomeApp_TypeFilter.cxx index 92216b667..445ec3f9d 100644 --- a/src/SalomeApp/SalomeApp_TypeFilter.cxx +++ b/src/SalomeApp/SalomeApp_TypeFilter.cxx @@ -1,6 +1,6 @@ #include "SalomeApp_TypeFilter.h" -#include "SalomeApp_DataOwner.h" +#include "LightApp_DataOwner.h" #include "SalomeApp_Study.h" #include @@ -26,7 +26,7 @@ SalomeApp_TypeFilter::~SalomeApp_TypeFilter() */ bool SalomeApp_TypeFilter::isOk( const SUIT_DataOwner* sOwner ) const { - const SalomeApp_DataOwner* owner = dynamic_cast ( sOwner ); + const LightApp_DataOwner* owner = dynamic_cast ( sOwner ); SalomeApp_Study* aDoc = getStudy(); if (owner && aDoc && aDoc->studyDS()) -- 2.39.2