--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2010 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+__author__="aribes/gboulant"
+
+from PyQt4.QtGui import *
+from PyQt4.QtCore import *
+
+import SalomePyQt
+sgPyQt = SalomePyQt.SalomePyQt()
+
+################################################
+# GUI context class
+# Used to store actions, menus, toolbars, etc...
+################################################
+# A gui context instance is created for each study. The dictionnary __study2context__
+# keeps the mapping in memory. This context contains graphical objects that have
+# to be created for each study. It contains at least the ui component builder that
+# creates the menu and toolbar items (must be created for every study)
+
+from daGuiImpl import adaoGuiHelper
+from daGuiImpl.adaoGuiManager import AdaoGuiUiComponentBuilder
+from daGuiImpl.adaoGuiManager import AdaoGuiActionImpl
+class GUIcontext:
+ uiComponentBuilder = None
+ actionImpl = None
+ def __init__(self):
+ self.uiComponentBuilder = AdaoGuiUiComponentBuilder()
+ self.actionImpl = AdaoGuiActionImpl()
+
+
+__study2context__ = {}
+__current_context__ = None
+def _setContext( studyID ):
+ global __study2context__, __current_context__
+ if not __study2context__.has_key(studyID):
+ print "create new context"
+ __study2context__[studyID] = GUIcontext()
+ pass
+ __current_context__ = __study2context__[studyID]
+ return __current_context__
+
+# This object does not need to be embedded in a GUI context object. A single
+# instance for all studies is a priori sufficient.
+
+################################################
+# Implementation of SALOME GUI interface
+################################################
+
+# called when module is initialized
+# perform initialization actions
+def initialize():
+ pass
+
+# called when module is initialized
+# return map of popup windows to be used by the module
+def windows():
+ wm = {}
+ wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
+ wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
+ return wm
+
+# called when module is initialized
+# return list of 2d/3d views to be used ny the module
+def views():
+ return []
+
+def createPreferences():
+ """
+ Called when module is initialized. Export module's preferences.
+ """
+ pass
+
+# called when module is activated
+# returns True if activating is successfull and False otherwise
+def activate():
+ print "activate study", sgPyQt.getStudyId()
+ ctx = _setContext( sgPyQt.getStudyId() )
+ ctx.actionImpl.activate()
+ return True
+
+# called when module is deactivated
+def deactivate():
+ pass
+
+# called when active study is changed
+# active study ID is passed as parameter
+def activeStudyChanged( studyID ):
+ ctx = _setContext( sgPyQt.getStudyId() )
+ pass
+
+
+# called when popup menu is invoked
+# popup menu and menu context are passed as parameters
+def createPopupMenu( popup, context ):
+ activeStudyId = sgPyQt.getStudyId()
+ ctx = _setContext(sgPyQt.getStudyId())
+ selcount, selected = adaoGuiHelper.getAllSelected(activeStudyId)
+ if selcount == 1:
+ selectedItem = adaoGuiHelper.getSelectedItem(activeStudyId)
+ popup = ctx.uiComponentBuilder.createPopupMenuOnItem(popup, activeStudyId, selectedItem)
+
+def OnGUIEvent(actionId) :
+ """
+ Called when an event is raised from a graphic item (click on menu item or
+ toolbar button). The actionId value is the ID associated to the item.
+ """
+ pass
+ ctx = _setContext( sgPyQt.getStudyId() )
+ ctx.actionImpl.processAction(actionId)
+
+# called when module's preferences are changed
+# preference's resources section and setting name are passed as parameters
+def preferenceChanged( section, setting ):
+ pass
+
+# called when active view is changed
+# view ID is passed as parameter
+def activeViewChanged( viewID ):
+ pass
+
+# called when active view is cloned
+# cloned view ID is passed as parameter
+def viewCloned( viewID ):
+ pass
+
+# called when active view is viewClosed
+# view ID is passed as parameter
+def viewClosed( viewID ):
+ pass
+
+++ /dev/null
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2010 EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-__author__="aribes/gboulant"
-
-from PyQt4.QtGui import *
-from PyQt4.QtCore import *
-
-import SalomePyQt
-sgPyQt = SalomePyQt.SalomePyQt()
-
-################################################
-# GUI context class
-# Used to store actions, menus, toolbars, etc...
-################################################
-# A gui context instance is created for each study. The dictionnary __study2context__
-# keeps the mapping in memory. This context contains graphical objects that have
-# to be created for each study. It contains at least the ui component builder that
-# creates the menu and toolbar items (must be created for every study)
-
-from daGuiImpl import datassimGuiHelper
-from daGuiImpl.datassimGuiManager import DatassimGuiUiComponentBuilder
-from daGuiImpl.datassimGuiManager import DatassimGuiActionImpl
-class GUIcontext:
- uiComponentBuilder = None
- actionImpl = None
- def __init__(self):
- self.uiComponentBuilder = DatassimGuiUiComponentBuilder()
- self.actionImpl = DatassimGuiActionImpl()
-
-
-__study2context__ = {}
-__current_context__ = None
-def _setContext( studyID ):
- global __study2context__, __current_context__
- if not __study2context__.has_key(studyID):
- print "create new context"
- __study2context__[studyID] = GUIcontext()
- pass
- __current_context__ = __study2context__[studyID]
- return __current_context__
-
-# This object does not need to be embedded in a GUI context object. A single
-# instance for all studies is a priori sufficient.
-
-################################################
-# Implementation of SALOME GUI interface
-################################################
-
-# called when module is initialized
-# perform initialization actions
-def initialize():
- pass
-
-# called when module is initialized
-# return map of popup windows to be used by the module
-def windows():
- wm = {}
- wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
- wm[SalomePyQt.WT_PyConsole] = Qt.BottomDockWidgetArea
- return wm
-
-# called when module is initialized
-# return list of 2d/3d views to be used ny the module
-def views():
- return []
-
-def createPreferences():
- """
- Called when module is initialized. Export module's preferences.
- """
- pass
-
-# called when module is activated
-# returns True if activating is successfull and False otherwise
-def activate():
- print "activate study", sgPyQt.getStudyId()
- ctx = _setContext( sgPyQt.getStudyId() )
- ctx.actionImpl.activate()
- return True
-
-# called when module is deactivated
-def deactivate():
- pass
-
-# called when active study is changed
-# active study ID is passed as parameter
-def activeStudyChanged( studyID ):
- ctx = _setContext( sgPyQt.getStudyId() )
- pass
-
-
-# called when popup menu is invoked
-# popup menu and menu context are passed as parameters
-def createPopupMenu( popup, context ):
- activeStudyId = sgPyQt.getStudyId()
- ctx = _setContext(sgPyQt.getStudyId())
- selcount, selected = datassimGuiHelper.getAllSelected(activeStudyId)
- if selcount == 1:
- selectedItem = datassimGuiHelper.getSelectedItem(activeStudyId)
- popup = ctx.uiComponentBuilder.createPopupMenuOnItem(popup, activeStudyId, selectedItem)
-
-def OnGUIEvent(actionId) :
- """
- Called when an event is raised from a graphic item (click on menu item or
- toolbar button). The actionId value is the ID associated to the item.
- """
- pass
- ctx = _setContext( sgPyQt.getStudyId() )
- ctx.actionImpl.processAction(actionId)
-
-
-# called when module's preferences are changed
-# preference's resources section and setting name are passed as parameters
-def preferenceChanged( section, setting ):
- pass
-
-# called when active view is changed
-# view ID is passed as parameter
-def activeViewChanged( viewID ):
- pass
-
-# called when active view is cloned
-# cloned view ID is passed as parameter
-def viewCloned( viewID ):
- pass
-
-# called when active view is viewClosed
-# view ID is passed as parameter
-def viewClosed( viewID ):
- pass
-
mypkgpython_PYTHON = \
__init__.py \
- DATASSIMGUI_impl.py \
- datassimGuiManager.py \
- datassimGuiHelper.py \
- datassimModuleHelper.py \
- datassimStudyEditor.py \
+ ADAOGUI_impl.py \
+ adaoGuiManager.py \
+ adaoGuiHelper.py \
+ adaoModuleHelper.py \
+ adaoStudyEditor.py \
studyedit.py \
- datassimCase.py \
+ adaoCase.py \
enumerate.py
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2010 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+import os
+import subprocess
+import traceback
+import SalomePyQt
+
+class AdaoCase:
+
+ def __init__(self):
+ self.__name = "new_case"
+ self.__filename = ""
+ self.__yacs_filename = ""
+
+ def get_name(self):
+ return self.__name
+
+ def set_name(self, name):
+ self.__name = str(name)
+
+ def get_filename(self):
+ return self.__filename
+
+ def set_filename(self, name):
+ self.__filename = str(name)
+
+ def createYACSFile(self):
+ rtn = ""
+ if (self.__filename == ""):
+ return "You need to save your case to export it"
+
+ filename = self.__filename[:self.__filename.rfind(".")] + '.py'
+ if not os.path.exists(filename):
+ msg = "Cannot find the py file for YACS generation \n"
+ msg += "Is your case correct ? \n"
+ msg += "(Try to load: " + filename + ")"
+ return msg
+
+ if not os.environ.has_key("ADAO_ROOT_DIR"):
+ return "Please add ADAO_ROOT_DIR to your environnement"
+
+ adao_path = os.environ["ADAO_ROOT_DIR"]
+ adao_exe = adao_path + "/bin/salome/AdaoYacsSchemaCreator.py"
+ self.__yacs_filename = self.__filename[:self.__filename.rfind(".")] + '.xml'
+ args = [adao_exe, filename, self.__yacs_filename]
+ p = subprocess.Popen(args)
+ (stdoutdata, stderrdata) = p.communicate()
+ if not os.path.exists(self.__yacs_filename):
+ msg = "An error occured during the execution of AdaoYacsSchemaCreator.py \n"
+ msg += "See erros details in your terminal \n"
+ return msg
+ return rtn
+
+ def exportCaseToYACS(self):
+ rtn = ""
+ rtn = self.createYACSFile()
+ if rtn != "":
+ return rtn
+
+ try:
+ import libYACS_Swig
+ yacs_swig = libYACS_Swig.YACS_Swig()
+ yacs_swig.loadSchema(self.__yacs_filename)
+ except:
+ msg = "Please install YACS module, error was: \n"
+ msg += traceback.format_exc()
+ return msg
+ return rtn
+
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2010 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+__author__="aribes/gboulant"
+
+import salome
+# Get SALOME PyQt interface
+import SalomePyQt
+__sgPyQt = SalomePyQt.SalomePyQt()
+
+import adaoModuleHelper
+from PyQt4 import QtGui,QtCore
+
+def waitCursor():
+ QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
+
+def restoreCursor():
+ QtGui.QApplication.restoreOverrideCursor()
+
+def gui_warning(parent, msg="An error occurs" ):
+ """
+ This function displays a message dialog box displaying the specified message.
+ """
+ QtGui.QMessageBox.warning( parent, "Alerte", msg)
+
+def getActiveStudyId():
+ """
+ This function returns the id of the active study. The concept of active study
+ makes sens only in the GUI context.
+ """
+ return __sgPyQt.getStudyId()
+
+
+def getActiveStudy():
+ """
+ This function returns the active study reference. The concept of active study
+ makes sens only in the GUI context.
+ """
+ studyId = getActiveStudyId()()
+ study = adaoModuleHelper.getStudyManager().GetStudyByID( studyId )
+ return study
+
+def refreshObjectBrowser():
+ """
+ Refresh the graphical representation of the SALOME study, in case where the
+ GUI is working.
+ """
+ if salome.sg is not None:
+ salome.sg.updateObjBrowser(0)
+
+def getSelectedItem(salomeStudyId=getActiveStudyId()):
+ """
+ Get the current selection. If more than one item are selected, the
+ only first is considered. The object is return (not the id).
+ The item can be of any type, no control is done in this function.
+ """
+ if salome.sg is None:
+ raise Exception("GuiHelper.getSelectedItem can't be used without the GUI context")
+
+ salomeStudy = adaoModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
+
+ item = None
+ listEntries=salome.sg.getAllSelected()
+ if len(listEntries) >= 1:
+ entry = listEntries[0]
+ item = salomeStudy.FindObjectID( entry )
+
+ return item
+
+def getAllSelected(salomeStudyId):
+ """
+ Returns all selected items in the specified study.
+ """
+ if salome.sg is None:
+ raise OmaException("getSelectedItem can't be used without the GUI context", OmaException.TYPES.DEVEL)
+
+ study = adaoModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
+ selcount = salome.sg.SelectedCount()
+ seltypes = {}
+ for i in range( selcount ):
+ __incObjToMap( seltypes, adaoModuleHelper.getObjectID( study, salome.sg.getSelected( i ) ) )
+ pass
+ return selcount, seltypes
+
+def __incObjToMap( m, id ):
+ """
+ Increment object counter in the specified map.
+ Not to be used outside this module.
+ """
+ if id not in m: m[id] = 0
+ m[id] += 1
+ pass
+
+def getDesktop():
+ """
+ Returns the active Desktop. Usefull to set the relative position of a dialog box
+ """
+ return __sgPyQt.getDesktop()
+
+def warning(msg):
+ """
+ This function displays a message dialog box displaying the specified message.
+ """
+ gui_warning(getDesktop(),msg)
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2010 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+"""
+This file centralizes the definitions and implementations of ui components used
+in the GUI part of the module.
+"""
+
+__author__ = "aribes/gboulant"
+
+import traceback
+from PyQt4.QtCore import QObject
+from PyQt4 import QtGui,QtCore
+import SalomePyQt
+sgPyQt = SalomePyQt.SalomePyQt()
+
+from daGuiImpl.enumerate import Enumerate
+from daGuiImpl.adaoCase import AdaoCase
+from daEficasWrapper.adaoEficasWrapper import AdaoEficasWrapper
+from daEficasWrapper.eficasWrapper import EficasObserver
+from daEficasWrapper.eficasWrapper import EficasEvent
+import adaoGuiHelper
+import adaoStudyEditor
+
+__cases__ = {}
+
+#
+# ==============================================================================
+# Classes to manage the building of UI components
+# ==============================================================================
+#
+UI_ELT_IDS = Enumerate([
+ 'ADAO_MENU_ID',
+ 'NEW_ADAOCASE_ID',
+ 'OPEN_ADAOCASE_ID',
+ 'EDIT_ADAOCASE_POP_ID',
+ 'REMOVE_ADAOCASE_POP_ID',
+ 'YACS_EXPORT_POP_ID',
+ ],offset=950)
+
+ACTIONS_MAP={
+ UI_ELT_IDS.NEW_ADAOCASE_ID:"newAdaoCase",
+ UI_ELT_IDS.OPEN_ADAOCASE_ID:"openAdaoCase",
+ UI_ELT_IDS.EDIT_ADAOCASE_POP_ID:"editAdaoCase",
+ UI_ELT_IDS.REMOVE_ADAOCASE_POP_ID:"removeAdaoCase",
+ UI_ELT_IDS.YACS_EXPORT_POP_ID:"exportCaseToYACS",
+}
+
+class AdaoGuiUiComponentBuilder:
+ """
+ The initialisation of this class creates the graphic components involved
+ in the GUI (menu, menu item, toolbar). A ui component builder should be
+ created for each opened study and associated to its context (see usage in OMAGUI.py).
+ """
+ def __init__(self):
+ self.initUiComponents()
+
+ def initUiComponents(self):
+
+ objectTR = QObject()
+
+ # create top-level menu
+ mid = sgPyQt.createMenu( "ADAO", -1, UI_ELT_IDS.ADAO_MENU_ID, sgPyQt.defaultMenuGroup() )
+ # create toolbar
+ tid = sgPyQt.createTool( "ADAO" )
+
+ a = sgPyQt.createAction( UI_ELT_IDS.NEW_ADAOCASE_ID, "New case", "New case", "Create a new adao case", "" )
+ sgPyQt.createMenu(a, mid)
+ sgPyQt.createTool(a, tid)
+ a = sgPyQt.createAction( UI_ELT_IDS.OPEN_ADAOCASE_ID, "Open case", "Open case", "Open a adao case", "" )
+ sgPyQt.createMenu(a, mid)
+ sgPyQt.createTool(a, tid)
+
+ # the following action are used in context popup
+ a = sgPyQt.createAction( UI_ELT_IDS.EDIT_ADAOCASE_POP_ID, "Edit case", "Edit case", "Edit the selected study case", "" )
+ a = sgPyQt.createAction( UI_ELT_IDS.REMOVE_ADAOCASE_POP_ID, "Remove case", "Remove case", "Remove the selected study case", "" )
+ a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_POP_ID, "Export to YACS", "Export to YACS", "Generate a YACS graph executing this case", "" )
+
+ def createPopupMenuOnItem(self,popup,salomeSudyId, item):
+ if adaoStudyEditor.isValidAdaoCaseItem(salomeSudyId, item):
+ popup.addAction( sgPyQt.action( UI_ELT_IDS.EDIT_ADAOCASE_POP_ID ) )
+ popup.addAction( sgPyQt.action( UI_ELT_IDS.REMOVE_ADAOCASE_POP_ID ) )
+ popup.addAction( sgPyQt.action( UI_ELT_IDS.YACS_EXPORT_POP_ID ) )
+
+ return popup
+
+class AdaoGuiActionImpl(EficasObserver):
+ """
+ This class implements the ui actions concerning the management of oma study
+ cases.
+ """
+
+ def __init__(self):
+ pass
+ # This dialog is created once so that it can be recycled for each call
+ # to newOmaCase().
+ #self.__dlgNewStudyCase = DlgNewStudyCase()
+ self.__parent = SalomePyQt.SalomePyQt().getDesktop()
+ self.__dlgEficasWrapper = AdaoEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
+ self.__dlgEficasWrapper.addObserver(self)
+ self.__Eficas_viewId = -1
+
+ # ==========================================================================
+ # Processing of ui actions
+ #
+ def processAction(self,actionId):
+ """
+ Main switch function for ui actions processing
+ """
+ if ACTIONS_MAP.has_key(actionId):
+ try:
+ functionName = ACTIONS_MAP[actionId]
+ getattr(self,functionName)()
+ except:
+ traceback.print_exc()
+ else:
+ msg = "The requested action is not implemented: " + str(actionId)
+ print msg
+
+ def showEficas(self):
+ if self.__Eficas_viewId == -1:
+ print "First showEficas"
+ self.__dlgEficasWrapper.init_gui()
+
+ # Scroll Widget
+ area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
+ area.setWidget( self.__dlgEficasWrapper)
+ area.setWidgetResizable(1)
+ self.__Eficas_viewId = SalomePyQt.SalomePyQt().createViewWithWidget(area)
+ else:
+ print "myViewId =", self.__Eficas_viewId
+ print "activeView =", SalomePyQt.SalomePyQt().getActiveView()
+ if SalomePyQt.SalomePyQt().getActiveView() != self.__Eficas_viewId :
+ result_activate = SalomePyQt.SalomePyQt().activateView(self.__Eficas_viewId)
+ if result_activate == False:
+ print "View was close - create a new eficas widget"
+ self.__dlgEficasWrapper.init_gui()
+
+ # Scroll Widget
+ area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
+ area.setWidget( self.__dlgEficasWrapper)
+ area.setWidgetResizable(1)
+ self.__Eficas_viewId = SalomePyQt.SalomePyQt().createViewWithWidget(area)
+
+ def activate(self):
+ self.showEficas()
+
+ def newAdaoCase(self):
+ self.showEficas()
+ self.__dlgEficasWrapper.fileNew()
+
+ def openAdaoCase(self):
+ self.showEficas()
+ global __cases__
+ fichier = QtGui.QFileDialog.getOpenFileName(SalomePyQt.SalomePyQt().getDesktop(),
+ self.__dlgEficasWrapper.trUtf8('Ouvrir Fichier'),
+ self.__dlgEficasWrapper.CONFIGURATION.savedir,
+ self.__dlgEficasWrapper.trUtf8('JDC Files (*.comm);;''All Files (*)'))
+ if fichier.isNull(): return
+ new_case = AdaoCase()
+ new_case.set_filename(str(fichier))
+ new_case.set_name(str(fichier.split('/')[-1]))
+ salomeStudyId = adaoGuiHelper.getActiveStudyId()
+ salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, new_case)
+ case_key = (salomeStudyId, salomeStudyItem.GetID())
+ __cases__[case_key] = new_case
+
+ # Open file in Eficas
+ self.__dlgEficasWrapper.Openfile(new_case.get_filename())
+ callbackId = [salomeStudyId, salomeStudyItem]
+ self.__dlgEficasWrapper.setCallbackId(callbackId)
+ self.showEficas()
+ adaoGuiHelper.refreshObjectBrowser()
+
+ def editAdaoCase(self):
+ # First we show eficas - all cases are reloaded
+ global __cases__
+
+ # Take study item
+ salomeStudyId = adaoGuiHelper.getActiveStudyId()
+ salomeStudyItem = adaoGuiHelper.getSelectedItem(salomeStudyId)
+ case_key = (salomeStudyId, salomeStudyItem.GetID())
+
+ # ShowEficas, If case is an empty case - case is destroyed by reopen
+ self.showEficas()
+ try:
+ case = __cases__[case_key]
+ # Search if case is in Eficas !
+ callbackId = [salomeStudyId, salomeStudyItem]
+ case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
+
+ # If case is not in eficas Open It !
+ if case_open_in_eficas == False:
+ if case.get_filename() != "":
+ self.__dlgEficasWrapper.Openfile(case.get_filename())
+ callbackId = [salomeStudyId, salomeStudyItem]
+ self.__dlgEficasWrapper.setCallbackId(callbackId)
+ except:
+ print "Oups - cannot edit case !"
+ traceback.print_exc()
+
+ def removeAdaoCase(self):
+ global __cases__
+
+ # First step: selectCase
+ salomeStudyId = adaoGuiHelper.getActiveStudyId()
+ salomeStudyItem = adaoGuiHelper.getSelectedItem(salomeStudyId)
+ callbackId = [salomeStudyId, salomeStudyItem]
+ case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
+ # If case is in eficas close it !
+ if case_open_in_eficas:
+ self.__dlgEficasWrapper.fileClose()
+
+ # Test if case exists
+ case_key = (salomeStudyId, salomeStudyItem.GetID())
+ if __cases__.has_key(case_key):
+ __cases__.pop(case_key)
+ adaoStudyEditor.removeItem(salomeStudyId, salomeStudyItem)
+ adaoGuiHelper.refreshObjectBrowser()
+
+ def exportCaseToYACS(self):
+ global __cases__
+ salomeStudyId = adaoGuiHelper.getActiveStudyId()
+ salomeStudyItem = adaoGuiHelper.getSelectedItem(salomeStudyId)
+ case_key = (salomeStudyId, salomeStudyItem.GetID())
+ case = __cases__[case_key]
+
+ msg = case.exportCaseToYACS()
+
+ if msg != "":
+ adaoGuiHelper.gui_warning(self.__parent, msg)
+
+ # ==========================================================================
+ # Processing notifications from eficas
+ #
+ __processOptions={
+ EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent",
+ EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent",
+ EficasEvent.EVENT_TYPES.NEW : "_processEficasNewEvent",
+ EficasEvent.EVENT_TYPES.DESTROY : "_processEficasDestroyEvent",
+ EficasEvent.EVENT_TYPES.OPEN : "_processEficasOpenEvent",
+ EficasEvent.EVENT_TYPES.REOPEN : "_processEficasReOpenEvent"
+ }
+ def processEficasEvent(self, eficasWrapper, eficasEvent):
+ """
+ Implementation of the interface EficasObserver. The implementation is a
+ switch on the possible types of events defined in EficasEvent.EVENT_TYPES.
+ @overload
+ """
+ functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent")
+ return getattr(self,functionName)(eficasWrapper, eficasEvent)
+
+ def _processEficasCloseEvent(self, eficasWrapper, eficasEvent):
+ pass
+
+ def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
+ global __cases__
+ new_case = AdaoCase()
+ case_name = eficasWrapper.getCaseName()
+ new_case.set_name(case_name)
+ salomeStudyId = adaoGuiHelper.getActiveStudyId()
+ salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, new_case)
+ case_key = (salomeStudyId, salomeStudyItem.GetID())
+ __cases__[case_key] = new_case
+ adaoGuiHelper.refreshObjectBrowser()
+ callbackId = [salomeStudyId, salomeStudyItem]
+ self.__dlgEficasWrapper.setCallbackId(callbackId)
+
+ def _processEficasReOpenEvent(self, eficasWrapper, eficasEvent):
+ global __cases__
+ try:
+ callbackId = eficasEvent.callbackId
+ [salomeStudyId, salomeStudyItem] = callbackId
+ case_key = (salomeStudyId, salomeStudyItem.GetID())
+ case = __cases__[case_key]
+ # Search if case is in Eficas !
+ callbackId = [salomeStudyId, salomeStudyItem]
+ print "selectCase"
+ case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
+ # If case is not in eficas Open It !
+ if case_open_in_eficas == False:
+ print "reopen selectCase"
+ if case.get_filename() != "":
+ self.__dlgEficasWrapper.Openfile(case.get_filename())
+ callbackId = [salomeStudyId, salomeStudyItem]
+ self.__dlgEficasWrapper.setCallbackId(callbackId)
+ else:
+ # Since I am an empty case I destroy myself before reloading
+ adaoStudyEditor.removeItem(salomeStudyId, salomeStudyItem)
+ adaoGuiHelper.refreshObjectBrowser()
+ __cases__.pop(case_key)
+ self.__dlgEficasWrapper.fileNew()
+ except:
+ print "Oups - cannot reopen case !"
+ traceback.print_exc()
+
+ def _processEficasOpenEvent(self, eficasWrapper, eficasEvent):
+ global __cases__
+
+ # Ouverture du fichier
+ self.__dlgEficasWrapper.Openfile(self.__dlgEficasWrapper.getOpenFileName())
+
+ # Creation d'un nouveau cas
+ new_case = AdaoCase()
+ salomeStudyId = adaoGuiHelper.getActiveStudyId()
+ salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, new_case)
+ case_key = (salomeStudyId, salomeStudyItem.GetID())
+ __cases__[case_key] = new_case
+
+ # Connexion du nouveau cas
+ callbackId = [salomeStudyId, salomeStudyItem]
+ self.__dlgEficasWrapper.setCallbackId(callbackId)
+
+ # On sauvegarde le cas
+ self._processEficasSaveEvent(self.__dlgEficasWrapper, None, callbackId)
+
+ def _processEficasSaveEvent(self, eficasWrapper, eficasEvent, callbackId=None):
+ global __cases__
+ if callbackId is None:
+ callbackId = eficasEvent.callbackId
+ if callbackId is None:
+ raise DevelException("the callback data should not be None. Can't guess what are the study and case")
+ [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
+ if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
+ raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
+ else:
+ [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
+
+ # Get Editor All infos we need !
+ case_name = eficasWrapper.getCaseName()
+ file_case_name = eficasWrapper.getFileCaseName()
+ if case_name != "" :
+ # Get case
+ old_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID())
+ case =__cases__[old_case_key]
+
+ # Set new informations
+ case.set_name(case_name)
+ if str(case_name).startswith("Untitled"):
+ pass
+ else:
+ case.set_filename(file_case_name)
+ adaoStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case)
+
+ # Case key changed !
+ #new_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID())
+ # A ne pas inverser !!!
+ #__cases__.pop(old_case_key)
+ #__cases__[new_case_key] = case
+
+ adaoGuiHelper.refreshObjectBrowser()
+
+ def _processEficasDestroyEvent(self, eficasWrapper, eficasEvent):
+ global __cases__
+ callbackId = eficasEvent.callbackId
+ if callbackId is None:
+ raise DevelException("the callback data should not be None. Can't guess what are the study and case")
+ [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
+ if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
+ raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
+
+ case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID())
+ __cases__.pop(case_key)
+ adaoStudyEditor.removeItem(targetSalomeStudyId, targetSalomeStudyItem)
+ adaoGuiHelper.refreshObjectBrowser()
+
+ def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
+ print "Unknown Eficas Event"
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# ---
+# Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
+# ---
+#
+
+__all__ = [
+ "moduleID",
+ "objectID",
+ "unknownID",
+ "componentName",
+ "modulePixmap",
+ "verbose",
+ "getORB",
+ "getNS",
+ "getLCC",
+ "getStudyManager",
+ "getEngine",
+ "getEngineIOR",
+ "findOrCreateComponent",
+ "getObjectID",
+ ]
+
+from omniORB import CORBA
+from SALOME_NamingServicePy import SALOME_NamingServicePy_i
+from LifeCycleCORBA import LifeCycleCORBA
+import SALOMEDS
+import SALOMEDS_Attributes_idl
+
+#import OMA_ORB
+
+###
+# Get OMA module's ID
+###
+def moduleID():
+ MODULE_ID = 1100
+ return MODULE_ID
+
+###
+# Get OMA object's ID
+###
+def objectID():
+ OBJECT_ID = 1110
+ return OBJECT_ID
+
+###
+# Get unknown ID
+###
+def unknownID():
+ FOREIGN_ID = -1
+ return FOREIGN_ID
+
+def componentName():
+ """
+ This provide the name of the module component to be associated to the study.
+ """
+ # Note that this name should be (i) the name used for the class implementing
+ # the component CORBA interface and (ii) the name used to declare the component
+ # in the catalog of the module.
+ return "ADAO"
+
+# _MEM_ we use here the tr() translation methode to manage constant parameters
+# in the application. We could have specified instead constant values directly
+# in the code below. It's a matter of convenience.
+from PyQt4.QtCore import QObject
+QObjectTR=QObject()
+
+def componentUserName():
+ return "ADAO"
+
+def modulePixmap():
+ """
+ Get the reference pixmap for this module.
+ """
+ return "ADAO_small.png"
+
+__verbose__ = None
+def verbose():
+ global __verbose__
+ if __verbose__ is None:
+ try:
+ __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
+ except:
+ __verbose__ = 0
+ pass
+ pass
+ return __verbose__
+
+###
+# Get ORB reference
+###
+__orb__ = None
+def getORB():
+ global __orb__
+ if __orb__ is None:
+ __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
+ pass
+ return __orb__
+
+###
+# Get naming service instance
+###
+__naming_service__ = None
+def getNS():
+ global __naming_service__
+ if __naming_service__ is None:
+ __naming_service__ = SALOME_NamingServicePy_i( getORB() )
+ pass
+ return __naming_service__
+
+##
+# Get life cycle CORBA instance
+##
+__lcc__ = None
+def getLCC():
+ global __lcc__
+ if __lcc__ is None:
+ __lcc__ = LifeCycleCORBA( getORB() )
+ pass
+ return __lcc__
+
+##
+# Get study manager
+###
+__study_manager__ = None
+def getStudyManager():
+ global __study_manager__
+ if __study_manager__ is None:
+ obj = getNS().Resolve( '/myStudyManager' )
+ __study_manager__ = obj._narrow( SALOMEDS.StudyManager )
+ pass
+ return __study_manager__
+
+###
+# Get OMA engine
+###
+__engine__ = None
+def getEngine():
+ global __engine__
+ if __engine__ is None:
+ __engine__ = getLCC().FindOrLoadComponent( "FactoryServer", componentName() )
+ pass
+ return __engine__
+
+###
+# Get OMA engine IOR
+###
+def getEngineIOR():
+ IOR = ""
+ if getORB() and getEngine():
+ IOR = getORB().object_to_string( getEngine() )
+ pass
+ return IOR
+
+###
+# Find or create OMA component object in a study
+###
+def findOrCreateComponent( study ):
+ father = study.FindComponent( componentName() )
+ if father is None:
+ builder = study.NewBuilder()
+ father = builder.NewComponent( componentName() )
+ attr = builder.FindOrCreateAttribute( father, "AttributeName" )
+ attr.SetValue( componentName() )
+ attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
+ attr.SetPixMap( modulePixmap() )
+ attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
+ attr.SetValue( moduleID() )
+ try:
+ builder.DefineComponentInstance( father, getEngine() )
+ pass
+ except:
+ pass
+ pass
+ return father
+
+###
+# Get object's ID
+###
+def getObjectID( study, entry ):
+ ID = unknownID()
+ if study and entry:
+ sobj = study.FindObjectID( entry )
+ if sobj is not None:
+ test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
+ if test: ID = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()
+ pass
+ pass
+ return
+
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2010 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+__author__="aribes/gboulant"
+
+from enumerate import Enumerate
+import studyedit
+import adaoModuleHelper
+from daGuiImpl.adaoCase import AdaoCase
+
+#
+# ==============================================================================
+# Constant parameters and identifiers
+# ==============================================================================
+#
+ADAO_ITEM_TYPES = Enumerate([
+ "ADAO_CASE",
+])
+
+#
+# ==============================================================================
+# Function dedicated to the data management in the salome study
+# ==============================================================================
+#
+# For developpers, note that the data structures used here are:
+# - the SALOME study whose API is defined by SALOMEDS::Study
+# - an item in a study whose API is defined by SALOMEDS:SObject
+# - a study component, whose API is defined by SALOMEDS::SComponent
+# a SComponent is a reference in a study toward a SALOME component
+#
+
+def addInStudy(salomeStudyId, adaoCase):
+ """
+ This function adds in the specified SALOME study a study entry that corresponds
+ to the specified adao case. This study case is put in a folder under
+ the ADAO component and is identified by the case name.
+ """
+
+ studyEditor = studyedit.getStudyEditor(salomeStudyId)
+
+ adaoRootEntry = studyEditor.findOrCreateComponent(
+ engineName = adaoModuleHelper.componentName(),
+ componentName = adaoModuleHelper.componentUserName())
+
+ itemName = adaoCase.get_name()
+ itemValue = str(adaoCase.get_filename())
+ itemType = ADAO_ITEM_TYPES.ADAO_CASE
+
+ salomeStudyItem = studyEditor.createItem(
+ adaoRootEntry, itemName,
+ comment = itemValue,
+ typeId = itemType)
+ # _MEM_ Note that we use the comment attribute to store the serialize
+ # description of the data.
+
+ return salomeStudyItem
+
+def updateItem(salomeStudyId, salomeStudyItem, adaoCase):
+
+ studyEditor = studyedit.getStudyEditor(salomeStudyId)
+
+ if salomeStudyItem.GetName()[:-2] != adaoCase.get_name():
+ itemName = adaoCase.get_name()
+ itemValue = adaoCase.get_filename()
+ else:
+ itemName = salomeStudyItem.GetName()
+ itemValue = adaoCase.get_filename()
+
+ studyEditor.setItem(salomeStudyItem,
+ name = itemName,
+ comment = itemValue)
+
+def removeItem(salomeStudyId, item):
+ """
+ Remove the item from the specified study.
+ """
+ studyEditor = studyedit.getStudyEditor(salomeStudyId)
+ return studyEditor.removeItem(item,True)
+
+
+def isValidAdaoCaseItem(salomeStudyId,item):
+ """
+ Return true if the specified item corresponds to a valid adaoCase
+ """
+ if item is None:
+ return False
+
+ studyEditor = studyedit.getStudyEditor(salomeStudyId)
+ itemType = studyEditor.getTypeId(item)
+ if itemType != ADAO_ITEM_TYPES.ADAO_CASE:
+ return False
+
+ return True
+++ /dev/null
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2010 EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-import os
-import subprocess
-import traceback
-import SalomePyQt
-
-class DatassimCase:
-
-
- def __init__(self):
- self.__name = "new_case"
- self.__filename = ""
- self.__yacs_filename = ""
-
- def get_name(self):
- return self.__name
-
- def set_name(self, name):
- self.__name = str(name)
-
- def get_filename(self):
- return self.__filename
-
- def set_filename(self, name):
- self.__filename = str(name)
-
- def createYACSFile(self):
- rtn = ""
- if (self.__filename == ""):
- return "You need to save your case to export it"
-
- filename = self.__filename[:self.__filename.rfind(".")] + '.py'
- if not os.path.exists(filename):
- msg = "Cannot find the py file for YACS generation \n"
- msg += "Is your case correct ? \n"
- msg += "(Try to load: " + filename + ")"
- return msg
-
- if not os.environ.has_key("DATASSIM_ROOT_DIR"):
- return "Please add DATASSIM_ROOT_DIR to your environnement"
-
- datassim_path = os.environ["DATASSIM_ROOT_DIR"]
- datassim_exe = datassim_path + "/bin/salome/DatassimYacsSchemaCreator.py"
- self.__yacs_filename = self.__filename[:self.__filename.rfind(".")] + '.xml'
- args = [datassim_exe, filename, self.__yacs_filename]
- p = subprocess.Popen(args)
- (stdoutdata, stderrdata) = p.communicate()
- if not os.path.exists(self.__yacs_filename):
- msg = "An error occured during the execution of DatassimYacsSchemaCreator.py \n"
- msg += "See erros details in your terminal \n"
- return msg
- return rtn
-
- def exportCaseToYACS(self):
- rtn = ""
- rtn = self.createYACSFile()
- if rtn != "":
- return rtn
-
- try:
- import libYACS_Swig
- yacs_swig = libYACS_Swig.YACS_Swig()
- yacs_swig.loadSchema(self.__yacs_filename)
- except:
- msg = "Please install YACS module, error was: \n"
- msg += traceback.format_exc()
- return msg
- return rtn
-
+++ /dev/null
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2010 EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-__author__="aribes/gboulant"
-
-import salome
-# Get SALOME PyQt interface
-import SalomePyQt
-__sgPyQt = SalomePyQt.SalomePyQt()
-
-import datassimModuleHelper
-from PyQt4 import QtGui,QtCore
-
-def waitCursor():
- QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
-
-def restoreCursor():
- QtGui.QApplication.restoreOverrideCursor()
-
-def gui_warning(parent, msg="An error occurs" ):
- """
- This function displays a message dialog box displaying the specified message.
- """
- QtGui.QMessageBox.warning( parent, "Alerte", msg)
-
-def getActiveStudyId():
- """
- This function returns the id of the active study. The concept of active study
- makes sens only in the GUI context.
- """
- return __sgPyQt.getStudyId()
-
-
-def getActiveStudy():
- """
- This function returns the active study reference. The concept of active study
- makes sens only in the GUI context.
- """
- studyId = getActiveStudyId()()
- study = datassimModuleHelper.getStudyManager().GetStudyByID( studyId )
- return study
-
-def refreshObjectBrowser():
- """
- Refresh the graphical representation of the SALOME study, in case where the
- GUI is working.
- """
- if salome.sg is not None:
- salome.sg.updateObjBrowser(0)
-
-def getSelectedItem(salomeStudyId=getActiveStudyId()):
- """
- Get the current selection. If more than one item are selected, the
- only first is considered. The object is return (not the id).
- The item can be of any type, no control is done in this function.
- """
- if salome.sg is None:
- raise Exception("GuiHelper.getSelectedItem can't be used without the GUI context")
-
- salomeStudy = datassimModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
-
- item = None
- listEntries=salome.sg.getAllSelected()
- if len(listEntries) >= 1:
- entry = listEntries[0]
- item = salomeStudy.FindObjectID( entry )
-
- return item
-
-def getAllSelected(salomeStudyId):
- """
- Returns all selected items in the specified study.
- """
- if salome.sg is None:
- raise OmaException("getSelectedItem can't be used without the GUI context", OmaException.TYPES.DEVEL)
-
- study = datassimModuleHelper.getStudyManager().GetStudyByID( salomeStudyId )
- selcount = salome.sg.SelectedCount()
- seltypes = {}
- for i in range( selcount ):
- __incObjToMap( seltypes, datassimModuleHelper.getObjectID( study, salome.sg.getSelected( i ) ) )
- pass
- return selcount, seltypes
-
-def __incObjToMap( m, id ):
- """
- Increment object counter in the specified map.
- Not to be used outside this module.
- """
- if id not in m: m[id] = 0
- m[id] += 1
- pass
-
-def getDesktop():
- """
- Returns the active Desktop. Usefull to set the relative position of a dialog box
- """
- return __sgPyQt.getDesktop()
-
-def warning(msg):
- """
- This function displays a message dialog box displaying the specified message.
- """
- gui_warning(getDesktop(),msg)
+++ /dev/null
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2010 EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-"""
-This file centralizes the definitions and implementations of ui components used
-in the GUI part of the module.
-"""
-
-__author__ = "aribes/gboulant"
-
-import traceback
-from PyQt4.QtCore import QObject
-from PyQt4 import QtGui,QtCore
-import SalomePyQt
-sgPyQt = SalomePyQt.SalomePyQt()
-
-from daGuiImpl.enumerate import Enumerate
-from daGuiImpl.datassimCase import DatassimCase
-from daEficasWrapper.datassimEficasWrapper import DatassimEficasWrapper
-from daEficasWrapper.eficasWrapper import EficasObserver
-from daEficasWrapper.eficasWrapper import EficasEvent
-import datassimGuiHelper
-import datassimStudyEditor
-
-__cases__ = {}
-
-#
-# ==============================================================================
-# Classes to manage the building of UI components
-# ==============================================================================
-#
-UI_ELT_IDS = Enumerate([
- 'DATASSIM_MENU_ID',
- 'NEW_DATASSIMCASE_ID',
- 'OPEN_DATASSIMCASE_ID',
- 'EDIT_DATASSIMCASE_POP_ID',
- 'REMOVE_DATASSIMCASE_POP_ID',
- 'YACS_EXPORT_POP_ID',
- ],offset=950)
-
-ACTIONS_MAP={
- UI_ELT_IDS.NEW_DATASSIMCASE_ID:"newDatassimCase",
- UI_ELT_IDS.OPEN_DATASSIMCASE_ID:"openDatassimCase",
- UI_ELT_IDS.EDIT_DATASSIMCASE_POP_ID:"editDatassimCase",
- UI_ELT_IDS.REMOVE_DATASSIMCASE_POP_ID:"removeDatassimCase",
- UI_ELT_IDS.YACS_EXPORT_POP_ID:"exportCaseToYACS",
-}
-
-class DatassimGuiUiComponentBuilder:
- """
- The initialisation of this class creates the graphic components involved
- in the GUI (menu, menu item, toolbar). A ui component builder should be
- created for each opened study and associated to its context (see usage in OMAGUI.py).
- """
- def __init__(self):
- self.initUiComponents()
-
- def initUiComponents(self):
-
- objectTR = QObject()
-
- # create top-level menu
- mid = sgPyQt.createMenu( "DATASSIM", -1, UI_ELT_IDS.DATASSIM_MENU_ID, sgPyQt.defaultMenuGroup() )
- # create toolbar
- tid = sgPyQt.createTool( "DATASSIM" )
-
- a = sgPyQt.createAction( UI_ELT_IDS.NEW_DATASSIMCASE_ID, "New case", "New case", "Create a new datassim case", "" )
- sgPyQt.createMenu(a, mid)
- sgPyQt.createTool(a, tid)
- a = sgPyQt.createAction( UI_ELT_IDS.OPEN_DATASSIMCASE_ID, "Open case", "Open case", "Open a datassim case", "" )
- sgPyQt.createMenu(a, mid)
- sgPyQt.createTool(a, tid)
-
- # the following action are used in context popup
- a = sgPyQt.createAction( UI_ELT_IDS.EDIT_DATASSIMCASE_POP_ID, "Edit case", "Edit case", "Edit the selected study case", "" )
- a = sgPyQt.createAction( UI_ELT_IDS.REMOVE_DATASSIMCASE_POP_ID, "Remove case", "Remove case", "Remove the selected study case", "" )
- a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_POP_ID, "Export to YACS", "Export to YACS", "Generate a YACS graph executing this case", "" )
-
- def createPopupMenuOnItem(self,popup,salomeSudyId, item):
- if datassimStudyEditor.isValidDatassimCaseItem(salomeSudyId, item):
- popup.addAction( sgPyQt.action( UI_ELT_IDS.EDIT_DATASSIMCASE_POP_ID ) )
- popup.addAction( sgPyQt.action( UI_ELT_IDS.REMOVE_DATASSIMCASE_POP_ID ) )
- popup.addAction( sgPyQt.action( UI_ELT_IDS.YACS_EXPORT_POP_ID ) )
-
- return popup
-
-class DatassimGuiActionImpl(EficasObserver):
- """
- This class implements the ui actions concerning the management of oma study
- cases.
- """
-
- def __init__(self):
- pass
- # This dialog is created once so that it can be recycled for each call
- # to newOmaCase().
- #self.__dlgNewStudyCase = DlgNewStudyCase()
- self.__parent = SalomePyQt.SalomePyQt().getDesktop()
- self.__dlgEficasWrapper = DatassimEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
- self.__dlgEficasWrapper.addObserver(self)
- self.__Eficas_viewId = -1
-
- # ==========================================================================
- # Processing of ui actions
- #
- def processAction(self,actionId):
- """
- Main switch function for ui actions processing
- """
- if ACTIONS_MAP.has_key(actionId):
- try:
- functionName = ACTIONS_MAP[actionId]
- getattr(self,functionName)()
- except:
- traceback.print_exc()
- else:
- msg = "The requested action is not implemented: " + str(actionId)
- print msg
-
- def showEficas(self):
- if self.__Eficas_viewId == -1:
- print "First showEficas"
- self.__dlgEficasWrapper.init_gui()
-
- # Scroll Widget
- area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
- area.setWidget( self.__dlgEficasWrapper)
- area.setWidgetResizable(1)
- self.__Eficas_viewId = SalomePyQt.SalomePyQt().createViewWithWidget(area)
- else:
- print "myViewId =", self.__Eficas_viewId
- print "activeView =", SalomePyQt.SalomePyQt().getActiveView()
- if SalomePyQt.SalomePyQt().getActiveView() != self.__Eficas_viewId :
- result_activate = SalomePyQt.SalomePyQt().activateView(self.__Eficas_viewId)
- if result_activate == False:
- print "View was close - create a new eficas widget"
- self.__dlgEficasWrapper.init_gui()
-
- # Scroll Widget
- area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
- area.setWidget( self.__dlgEficasWrapper)
- area.setWidgetResizable(1)
- self.__Eficas_viewId = SalomePyQt.SalomePyQt().createViewWithWidget(area)
-
- def activate(self):
- self.showEficas()
-
- def newDatassimCase(self):
- self.showEficas()
- self.__dlgEficasWrapper.fileNew()
-
- def openDatassimCase(self):
- self.showEficas()
- global __cases__
- fichier = QtGui.QFileDialog.getOpenFileName(SalomePyQt.SalomePyQt().getDesktop(),
- self.__dlgEficasWrapper.trUtf8('Ouvrir Fichier'),
- self.__dlgEficasWrapper.CONFIGURATION.savedir,
- self.__dlgEficasWrapper.trUtf8('JDC Files (*.comm);;''All Files (*)'))
- if fichier.isNull(): return
- new_case = DatassimCase()
- new_case.set_filename(str(fichier))
- new_case.set_name(str(fichier.split('/')[-1]))
- salomeStudyId = datassimGuiHelper.getActiveStudyId()
- salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case)
- case_key = (salomeStudyId, salomeStudyItem.GetID())
- __cases__[case_key] = new_case
-
- # Open file in Eficas
- self.__dlgEficasWrapper.Openfile(new_case.get_filename())
- callbackId = [salomeStudyId, salomeStudyItem]
- self.__dlgEficasWrapper.setCallbackId(callbackId)
- self.showEficas()
- datassimGuiHelper.refreshObjectBrowser()
-
- def editDatassimCase(self):
- # First we show eficas - all cases are reloaded
- global __cases__
-
- # Take study item
- salomeStudyId = datassimGuiHelper.getActiveStudyId()
- salomeStudyItem = datassimGuiHelper.getSelectedItem(salomeStudyId)
- case_key = (salomeStudyId, salomeStudyItem.GetID())
-
- # ShowEficas, If case is an empty case - case is destroyed by reopen
- self.showEficas()
- try:
- case = __cases__[case_key]
- # Search if case is in Eficas !
- callbackId = [salomeStudyId, salomeStudyItem]
- case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
-
- # If case is not in eficas Open It !
- if case_open_in_eficas == False:
- if case.get_filename() != "":
- self.__dlgEficasWrapper.Openfile(case.get_filename())
- callbackId = [salomeStudyId, salomeStudyItem]
- self.__dlgEficasWrapper.setCallbackId(callbackId)
- except:
- print "Oups - cannot edit case !"
- traceback.print_exc()
-
- def removeDatassimCase(self):
- global __cases__
-
- # First step: selectCase
- salomeStudyId = datassimGuiHelper.getActiveStudyId()
- salomeStudyItem = datassimGuiHelper.getSelectedItem(salomeStudyId)
- callbackId = [salomeStudyId, salomeStudyItem]
- case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
- # If case is in eficas close it !
- if case_open_in_eficas:
- self.__dlgEficasWrapper.fileClose()
-
- # Test if case exists
- case_key = (salomeStudyId, salomeStudyItem.GetID())
- if __cases__.has_key(case_key):
- __cases__.pop(case_key)
- datassimStudyEditor.removeItem(salomeStudyId, salomeStudyItem)
- datassimGuiHelper.refreshObjectBrowser()
-
- def exportCaseToYACS(self):
- global __cases__
- salomeStudyId = datassimGuiHelper.getActiveStudyId()
- salomeStudyItem = datassimGuiHelper.getSelectedItem(salomeStudyId)
- case_key = (salomeStudyId, salomeStudyItem.GetID())
- case = __cases__[case_key]
-
- msg = case.exportCaseToYACS()
-
- if msg != "":
- datassimGuiHelper.gui_warning(self.__parent, msg)
-
- # ==========================================================================
- # Processing notifications from eficas
- #
- __processOptions={
- EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent",
- EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent",
- EficasEvent.EVENT_TYPES.NEW : "_processEficasNewEvent",
- EficasEvent.EVENT_TYPES.DESTROY : "_processEficasDestroyEvent",
- EficasEvent.EVENT_TYPES.OPEN : "_processEficasOpenEvent",
- EficasEvent.EVENT_TYPES.REOPEN : "_processEficasReOpenEvent"
- }
- def processEficasEvent(self, eficasWrapper, eficasEvent):
- """
- Implementation of the interface EficasObserver. The implementation is a
- switch on the possible types of events defined in EficasEvent.EVENT_TYPES.
- @overload
- """
- functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent")
- return getattr(self,functionName)(eficasWrapper, eficasEvent)
-
- def _processEficasCloseEvent(self, eficasWrapper, eficasEvent):
- pass
-
- def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
- global __cases__
- new_case = DatassimCase()
- case_name = eficasWrapper.getCaseName()
- new_case.set_name(case_name)
- salomeStudyId = datassimGuiHelper.getActiveStudyId()
- salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case)
- case_key = (salomeStudyId, salomeStudyItem.GetID())
- __cases__[case_key] = new_case
- datassimGuiHelper.refreshObjectBrowser()
- callbackId = [salomeStudyId, salomeStudyItem]
- self.__dlgEficasWrapper.setCallbackId(callbackId)
-
- def _processEficasReOpenEvent(self, eficasWrapper, eficasEvent):
- global __cases__
- try:
- callbackId = eficasEvent.callbackId
- [salomeStudyId, salomeStudyItem] = callbackId
- case_key = (salomeStudyId, salomeStudyItem.GetID())
- case = __cases__[case_key]
- # Search if case is in Eficas !
- callbackId = [salomeStudyId, salomeStudyItem]
- print "selectCase"
- case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId)
- # If case is not in eficas Open It !
- if case_open_in_eficas == False:
- print "reopen selectCase"
- if case.get_filename() != "":
- self.__dlgEficasWrapper.Openfile(case.get_filename())
- callbackId = [salomeStudyId, salomeStudyItem]
- self.__dlgEficasWrapper.setCallbackId(callbackId)
- else:
- # Since I am an empty case I destroy myself before reloading
- datassimStudyEditor.removeItem(salomeStudyId, salomeStudyItem)
- datassimGuiHelper.refreshObjectBrowser()
- __cases__.pop(case_key)
- self.__dlgEficasWrapper.fileNew()
- except:
- print "Oups - cannot reopen case !"
- traceback.print_exc()
-
- def _processEficasOpenEvent(self, eficasWrapper, eficasEvent):
- global __cases__
-
- # Ouverture du fichier
- self.__dlgEficasWrapper.Openfile(self.__dlgEficasWrapper.getOpenFileName())
-
- # Creation d'un nouveau cas
- new_case = DatassimCase()
- salomeStudyId = datassimGuiHelper.getActiveStudyId()
- salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case)
- case_key = (salomeStudyId, salomeStudyItem.GetID())
- __cases__[case_key] = new_case
-
- # Connexion du nouveau cas
- callbackId = [salomeStudyId, salomeStudyItem]
- self.__dlgEficasWrapper.setCallbackId(callbackId)
-
- # On sauvegarde le cas
- self._processEficasSaveEvent(self.__dlgEficasWrapper, None, callbackId)
-
- def _processEficasSaveEvent(self, eficasWrapper, eficasEvent, callbackId=None):
- global __cases__
- if callbackId is None:
- callbackId = eficasEvent.callbackId
- if callbackId is None:
- raise DevelException("the callback data should not be None. Can't guess what are the study and case")
- [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
- if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
- raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
- else:
- [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
-
- # Get Editor All infos we need !
- case_name = eficasWrapper.getCaseName()
- file_case_name = eficasWrapper.getFileCaseName()
- if case_name != "" :
- # Get case
- old_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID())
- case =__cases__[old_case_key]
-
- # Set new informations
- case.set_name(case_name)
- if str(case_name).startswith("Untitled"):
- pass
- else:
- case.set_filename(file_case_name)
- datassimStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case)
-
- # Case key changed !
- #new_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID())
- # A ne pas inverser !!!
- #__cases__.pop(old_case_key)
- #__cases__[new_case_key] = case
-
- datassimGuiHelper.refreshObjectBrowser()
-
- def _processEficasDestroyEvent(self, eficasWrapper, eficasEvent):
- global __cases__
- callbackId = eficasEvent.callbackId
- if callbackId is None:
- raise DevelException("the callback data should not be None. Can't guess what are the study and case")
- [targetSalomeStudyId,targetSalomeStudyItem] = callbackId
- if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ):
- raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None")
-
- case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID())
- __cases__.pop(case_key)
- datassimStudyEditor.removeItem(targetSalomeStudyId, targetSalomeStudyItem)
- datassimGuiHelper.refreshObjectBrowser()
-
- def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
- print "Unknown Eficas Event"
+++ /dev/null
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-#
-# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-# ---
-# Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
-# ---
-#
-
-__all__ = [
- "moduleID",
- "objectID",
- "unknownID",
- "componentName",
- "modulePixmap",
- "verbose",
- "getORB",
- "getNS",
- "getLCC",
- "getStudyManager",
- "getEngine",
- "getEngineIOR",
- "findOrCreateComponent",
- "getObjectID",
- ]
-
-from omniORB import CORBA
-from SALOME_NamingServicePy import SALOME_NamingServicePy_i
-from LifeCycleCORBA import LifeCycleCORBA
-import SALOMEDS
-import SALOMEDS_Attributes_idl
-
-#import OMA_ORB
-
-###
-# Get OMA module's ID
-###
-def moduleID():
- MODULE_ID = 1100
- return MODULE_ID
-
-###
-# Get OMA object's ID
-###
-def objectID():
- OBJECT_ID = 1110
- return OBJECT_ID
-
-###
-# Get unknown ID
-###
-def unknownID():
- FOREIGN_ID = -1
- return FOREIGN_ID
-
-def componentName():
- """
- This provide the name of the module component to be associated to the study.
- """
- # Note that this name should be (i) the name used for the class implementing
- # the component CORBA interface and (ii) the name used to declare the component
- # in the catalog of the module.
- return "DATASSIM"
-
-# _MEM_ we use here the tr() translation methode to manage constant parameters
-# in the application. We could have specified instead constant values directly
-# in the code below. It's a matter of convenience.
-from PyQt4.QtCore import QObject
-QObjectTR=QObject()
-
-def componentUserName():
- return "DATASSIM"
-
-def modulePixmap():
- """
- Get the reference pixmap for this module.
- """
- return "DATASSIM_small.png"
-
-__verbose__ = None
-def verbose():
- global __verbose__
- if __verbose__ is None:
- try:
- __verbose__ = int( os.getenv( 'SALOME_VERBOSE', 0 ) )
- except:
- __verbose__ = 0
- pass
- pass
- return __verbose__
-
-###
-# Get ORB reference
-###
-__orb__ = None
-def getORB():
- global __orb__
- if __orb__ is None:
- __orb__ = CORBA.ORB_init( [''], CORBA.ORB_ID )
- pass
- return __orb__
-
-###
-# Get naming service instance
-###
-__naming_service__ = None
-def getNS():
- global __naming_service__
- if __naming_service__ is None:
- __naming_service__ = SALOME_NamingServicePy_i( getORB() )
- pass
- return __naming_service__
-
-##
-# Get life cycle CORBA instance
-##
-__lcc__ = None
-def getLCC():
- global __lcc__
- if __lcc__ is None:
- __lcc__ = LifeCycleCORBA( getORB() )
- pass
- return __lcc__
-
-##
-# Get study manager
-###
-__study_manager__ = None
-def getStudyManager():
- global __study_manager__
- if __study_manager__ is None:
- obj = getNS().Resolve( '/myStudyManager' )
- __study_manager__ = obj._narrow( SALOMEDS.StudyManager )
- pass
- return __study_manager__
-
-###
-# Get OMA engine
-###
-__engine__ = None
-def getEngine():
- global __engine__
- if __engine__ is None:
- __engine__ = getLCC().FindOrLoadComponent( "FactoryServer", componentName() )
- pass
- return __engine__
-
-###
-# Get OMA engine IOR
-###
-def getEngineIOR():
- IOR = ""
- if getORB() and getEngine():
- IOR = getORB().object_to_string( getEngine() )
- pass
- return IOR
-
-###
-# Find or create OMA component object in a study
-###
-def findOrCreateComponent( study ):
- father = study.FindComponent( componentName() )
- if father is None:
- builder = study.NewBuilder()
- father = builder.NewComponent( componentName() )
- attr = builder.FindOrCreateAttribute( father, "AttributeName" )
- attr.SetValue( componentName() )
- attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
- attr.SetPixMap( modulePixmap() )
- attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
- attr.SetValue( moduleID() )
- try:
- builder.DefineComponentInstance( father, getEngine() )
- pass
- except:
- pass
- pass
- return father
-
-###
-# Get object's ID
-###
-def getObjectID( study, entry ):
- ID = unknownID()
- if study and entry:
- sobj = study.FindObjectID( entry )
- if sobj is not None:
- test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
- if test: ID = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()
- pass
- pass
- return
-
+++ /dev/null
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2010 EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-__author__="aribes/gboulant"
-
-from enumerate import Enumerate
-import studyedit
-import datassimModuleHelper
-from daGuiImpl.datassimCase import DatassimCase
-
-#
-# ==============================================================================
-# Constant parameters and identifiers
-# ==============================================================================
-#
-DATASSIM_ITEM_TYPES = Enumerate([
- "DATASSIM_CASE",
-])
-
-#
-# ==============================================================================
-# Function dedicated to the data management in the salome study
-# ==============================================================================
-#
-# For developpers, note that the data structures used here are:
-# - the SALOME study whose API is defined by SALOMEDS::Study
-# - an item in a study whose API is defined by SALOMEDS:SObject
-# - a study component, whose API is defined by SALOMEDS::SComponent
-# a SComponent is a reference in a study toward a SALOME component
-#
-
-def addInStudy(salomeStudyId, datassimCase):
- """
- This function adds in the specified SALOME study a study entry that corresponds
- to the specified datassim case. This study case is put in a folder under
- the DATASSIM component and is identified by the case name.
- """
-
- studyEditor = studyedit.getStudyEditor(salomeStudyId)
-
- datassimRootEntry = studyEditor.findOrCreateComponent(
- engineName = datassimModuleHelper.componentName(),
- componentName = datassimModuleHelper.componentUserName())
-
- itemName = datassimCase.get_name()
- itemValue = str(datassimCase.get_filename())
- itemType = DATASSIM_ITEM_TYPES.DATASSIM_CASE
-
- salomeStudyItem = studyEditor.createItem(
- datassimRootEntry, itemName,
- comment = itemValue,
- typeId = itemType)
- # _MEM_ Note that we use the comment attribute to store the serialize
- # description of the data.
-
- return salomeStudyItem
-
-def updateItem(salomeStudyId, salomeStudyItem, datassimCase):
-
- studyEditor = studyedit.getStudyEditor(salomeStudyId)
-
- if salomeStudyItem.GetName()[:-2] != datassimCase.get_name():
- itemName = datassimCase.get_name()
- itemValue = datassimCase.get_filename()
- else:
- itemName = salomeStudyItem.GetName()
- itemValue = datassimCase.get_filename()
-
- studyEditor.setItem(salomeStudyItem,
- name = itemName,
- comment = itemValue)
-
-def removeItem(salomeStudyId, item):
- """
- Remove the item from the specified study.
- """
- studyEditor = studyedit.getStudyEditor(salomeStudyId)
- return studyEditor.removeItem(item,True)
-
-
-def isValidDatassimCaseItem(salomeStudyId,item):
- """
- Return true if the specified item corresponds to a valid datassimCase
- """
- if item is None:
- return False
-
- studyEditor = studyedit.getStudyEditor(salomeStudyId)
- itemType = studyEditor.getTypeId(item)
- if itemType != DATASSIM_ITEM_TYPES.DATASSIM_CASE:
- return False
-
- return True