Salome HOME
Adding generation of YACS scheme
authorYoann AUDOUIN <B61570@dsp0761867.postes.calibre.edf.fr>
Mon, 12 Jun 2017 06:37:55 +0000 (08:37 +0200)
committerYoann AUDOUIN <B61570@dsp0761867.postes.calibre.edf.fr>
Mon, 12 Jun 2017 06:37:55 +0000 (08:37 +0200)
src/HYDROGUI/HYDROSOLVERGUI.py
src/salome_hydro/study.py

index 0b41bd0cc85eb9bb7bc2b36e260e5951dbd58268..b799e17519e82ae862867ccdb69817929721f050 100755 (executable)
@@ -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,
index 68b410b6b0626949d32704d3508945d26c2ed46a..bc5f4d39b92c1bdee149f010225b525c30e0470b 100644 (file)
@@ -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()