Salome HOME
Cleanup
[modules/hydrosolver.git] / src / salome_hydro / study.py
index 13237fd81884e72022e40252b1cdaa62c08c0c70..f045f9b77d0a6d93d4b37bc5a0806cfc50280939 100644 (file)
@@ -170,15 +170,49 @@ 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"])
+
+        # Generation script string
+        python_script = generate_study_script(params)
+
+        # Computing name of the file (same as filePath)
+        file_dir, filename = os.path.split(filePath)
+        root, sfx = os.path.splitext(filename)
+        python_file = os.path.join(file_dir,root+".py")
+
+        # Writting to file
+        with open(python_file,'w') as pfile:
+            pfile.write(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_study_yacs
         with open(filePath) as jdcfile:
             jdc = jdcfile.read()
         params = jdc_to_dict(jdc, ["TELEMAC2D", "_F"])
 
-        yacs_scheme = generate_yacs(params)
+        # Generation YACS scheme
+        yacs_scheme = generate_study_yacs(params)
+
+        # Computing name of the file (same as filePath)
+        file_dir, filename = os.path.split(filePath)
+        root, sfx = os.path.splitext(filename)
+        yacs_file = os.path.join(file_dir,root+".xml")
 
-        # TODO: Replace that by adding yacs scheme and python script ?
+        # Writting to file
+        yacs_scheme.saveSchema(yacs_file)
 
     def find_or_create_coupling1d2d_case(self, filePath):
         self.find_or_create_hydro_component()