From: Yoann AUDOUIN Date: Mon, 12 Jun 2017 06:37:55 +0000 (+0200) Subject: Adding generation of YACS scheme X-Git-Tag: Salome_8_3_Hydro_2_0rc1~14^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=99fb0a095cfaa3c5c774438e0e160d33b77e0db7;p=modules%2Fhydrosolver.git Adding generation of YACS scheme --- diff --git a/src/HYDROGUI/HYDROSOLVERGUI.py b/src/HYDROGUI/HYDROSOLVERGUI.py index 0b41bd0..b799e17 100755 --- a/src/HYDROGUI/HYDROSOLVERGUI.py +++ b/src/HYDROGUI/HYDROSOLVERGUI.py @@ -72,6 +72,7 @@ class GUIcontext: EDIT_BOUNDARY_CONDITIONS_FILE_ID = 956 GENERATE_INTERPOLZ_PY_ID = 957 GEN_TELEMAC2D_PYTHON_ID = 958 + GEN_TELEMAC2D_YACS_ID = 959 def __init__( self ): # create top-level menu @@ -149,7 +150,10 @@ class GUIcontext: sgPyQt.createAction( GUIcontext.GEN_TELEMAC2D_PYTHON_ID, "Generate Python script", "Generate Python script", - "Run Telemac2D solver to compute the case" ) + "Generate a Python script from the eficas date" ) + sgPyQt.createAction( GUIcontext.GEN_TELEMAC2D_YACS_ID, "Generate YACS script", + "Generate YACS script", + "Generate a YACS script from the eficas date" ) sgPyQt.createAction( GUIcontext.RUN_TELEMAC2D_ID, "Compute case", "Compute case", "Run Telemac2D solver to compute the case" ) sgPyQt.createAction( GUIcontext.EDIT_TELEMAC2D_CASE_ID, "Edit case", "Edit case", @@ -279,6 +283,7 @@ def createPopupMenu(popup, context): popup.addAction(sgPyQt.action(GUIcontext.EDIT_TELEMAC2D_CASE_ID)) popup.addAction(sgPyQt.action(GUIcontext.RUN_TELEMAC2D_ID)) popup.addAction(sgPyQt.action(GUIcontext.GEN_TELEMAC2D_PYTHON_ID)) + popup.addAction(sgPyQt.action(GUIcontext.GEN_TELEMAC2D_YACS_ID)) elif selectedType == hydro_study.COUPLING1D2D_CASE_TYPE_ID: popup.addAction(sgPyQt.action(GUIcontext.EDIT_COUPLING1D2D_CASE_ID)) popup.addAction(sgPyQt.action(GUIcontext.OPEN_SCHEMA_IN_YACS_ID)) @@ -430,8 +435,7 @@ def generate_telemac2d_python(): with wait_cursor: ed = hydro_study.HydroStudyEditor() sobj = get_and_check_selected_file_path() - print sobj - ed.find_or_create_telemac2d_case(sobj) + ed.generate_study_script(sobj) except SALOME.SALOME_Exception, exc: salome.sg.updateObjBrowser( 0 ) msg = unicode(QApplication.translate("generate_telemac2d_python", @@ -439,6 +443,21 @@ def generate_telemac2d_python(): msg += "\n" + exc.details.text raise HSGUIException(msg) +### +# Generate a python script from the eficas file +### +def generate_telemac2d_yacs(): + try: + with wait_cursor: + ed = hydro_study.HydroStudyEditor() + sobj = get_and_check_selected_file_path() + ed.generate_study_yacs(sobj) + except SALOME.SALOME_Exception, exc: + salome.sg.updateObjBrowser( 0 ) + msg = unicode(QApplication.translate("generate_telemac2d_yacs", + "An error happened while trying to generate telemac2d Python script:")) + msg += "\n" + exc.details.text + raise HSGUIException(msg) ### # Open Eficas for 1D / 2D Coupling to create a new coupling case @@ -502,6 +521,7 @@ dict_command = { GUIcontext.CREATE_TELEMAC2D_CASE_ID: create_telemac2d_case, GUIcontext.RUN_TELEMAC2D_ID: run_telemac2d, GUIcontext.GEN_TELEMAC2D_PYTHON_ID: generate_telemac2d_python, + GUIcontext.GEN_TELEMAC2D_YACS_ID: generate_telemac2d_yacs, GUIcontext.EDIT_TELEMAC2D_CASE_ID: edit_telemac2d_case, GUIcontext.CREATE_COUPLING1D2D_CASE_ID: create_coupling1d2d_case, GUIcontext.EDIT_COUPLING1D2D_CASE_ID: edit_coupling1d2d_case, diff --git a/src/salome_hydro/study.py b/src/salome_hydro/study.py index 68b410b..bc5f4d3 100644 --- a/src/salome_hydro/study.py +++ b/src/salome_hydro/study.py @@ -170,16 +170,38 @@ class HydroStudyEditor: icon = TELEMAC2D_ICON, comment = str(filePath), typeId = TELEMAC2D_CASE_TYPE_ID) - # Create "Variables" item - from TelApy.api.generate_study import generate_yacs + + def generate_study_script(self, filePath) + """ + Generating a python script from the eficas info + """ + # Create "Python script" item + from TelApy.api.generate_study import generate_study_script + with open(filePath) as jdcfile: + jdc = jdcfile.read() + params = jdc_to_dict(jdc, ["TELEMAC2D", "_F"]) + + python_script = generate_study_script(params) + print python_script + + def generate_study_yacs(self, filePath) + """ + Generating a yacs file from the eficas info + """ + # Create "Python script" item + from TelApy.api.generate_study import generate_yacs_study with open(filePath) as jdcfile: jdc = jdcfile.read() params = jdc_to_dict(jdc, ["TELEMAC2D", "_F"]) - yacs_scheme = generate_yacs(params) + yacs_scheme = generate_yacs_study(params) + file_dir = os.path.basename(filePath) + root, sfx = filePath.splitext() + yacs_file = os.path.join(file_dir,root+".xml") + + print yacs_file print yacs_scheme - # TODO: Replace that by adding yacs scheme and python script ? def find_or_create_coupling1d2d_case(self, filePath): self.find_or_create_hydro_component()