]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Export in YACS
authorAndré <andre.ribes@edf.fr>
Thu, 29 Apr 2010 15:18:53 +0000 (17:18 +0200)
committerAndré <andre.ribes@edf.fr>
Thu, 29 Apr 2010 15:18:53 +0000 (17:18 +0200)
src/daSalome/daGUI/daGuiImpl/datassimCase.py
src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py

index 7814e7b2351b6375b94f3427abb59042da361f60..e6ea93122a4752091f10312fd1dd715d0216dd69 100644 (file)
 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
+import os
+import subprocess
+import traceback
+import SalomePyQt
+
 class DatassimCase:
 
-  __name = "new_case"
-  __filename = ""
 
   def __init__(self):
-    pass
+    self.__name = "new_case"
+    self.__filename = ""
+    self.__yacs_filename = ""
 
   def get_name(self):
     return self.__name
@@ -37,3 +42,47 @@ class DatassimCase:
 
   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
+
index ed1b3fbe9f6d9857e0960b01b96ca9b0abde80b9..a973b190d541f242b4630c262e9ba6d690cb5051 100644 (file)
@@ -60,6 +60,7 @@ ACTIONS_MAP={
     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:
@@ -111,6 +112,7 @@ class DatassimGuiActionImpl(EficasObserver):
         # 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
@@ -223,6 +225,18 @@ class DatassimGuiActionImpl(EficasObserver):
         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
     #