Salome HOME
Updating copyright date information and version
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoCase.py
index ca2e2c00068a094fde008999e078f59cdb826877..5a2c9b94a944a5cb0feb4cb35943e7feb97f69f9 100644 (file)
@@ -1,21 +1,23 @@
 # -*- coding: utf-8 -*-
-#  Copyright (C) 2010 EDF R&D
+# Copyright (C) 2008-2015 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 file is part of SALOME ADAO module
 #
-#  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.
+# 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.
 #
-#  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
+# 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.
 #
-#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+# 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
@@ -23,6 +25,11 @@ import subprocess
 import traceback
 import SalomePyQt
 
+import eficasSalome
+from Ihm import CONNECTOR
+import adaoGuiHelper
+import adaoStudyEditor
+
 class AdaoCase:
 
   def __init__(self):
@@ -37,6 +44,20 @@ class AdaoCase:
 
     self.eficas_editor = None               # Editor object from Eficas
 
+  def setEditor(self, editor):
+    if editor is not self.eficas_editor:
+      self.eficas_editor = editor
+      # Connect to the jdc
+      CONNECTOR.Connect(self.eficas_editor.jdc, "valid", self.editorValidEvent, ())
+
+  # Rq on notera que l'on utilise isvalid dans isOk
+  #    et que isOk appelle editorValidEvent
+  #    il n'y a pas de boucle infini car isvalid n'émet
+  #    son signal que si l'état a changé
+  def editorValidEvent(self):
+    adaoStudyEditor.updateItem(self.salome_study_id, self.salome_study_item, self)
+    adaoGuiHelper.refreshObjectBrowser()
+
   def isOk(self):
     if self.eficas_editor.jdc:
       return self.eficas_editor.jdc.isvalid()
@@ -45,27 +66,33 @@ class AdaoCase:
   def createYACSFile(self):
     rtn = ""
     if (self.filename == ""):
-      return "You need to save your case to export it"
+      return "You need to save your case to export it."
 
+    self.yacs_filename = self.filename[:self.filename.rfind(".")] + '.xml'
+    yacs_filename_backup = self.filename[:self.filename.rfind(".")] + '.xml.back'
+    if os.path.exists(self.yacs_filename):
+      os.rename(self.yacs_filename, yacs_filename_backup)
+
+    self.eficas_editor.modified = True
+    self.eficas_editor.saveFile()
     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 + ")"
+      msg =  "Cannot find the COMM associated python file for YACS\n"
+      msg += "generation. Is your case correct?\n"
       return msg
 
     if not os.environ.has_key("ADAO_ROOT_DIR"):
-      return "Please add ADAO_ROOT_DIR to your environnement"
+      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 = ["python", 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"
+      msg  = "An error occured during the execution of the ADAO YACS Schema\n"
+      msg += "Creator. If SALOME is launched by command line, see errors\n"
+      msg += "details in your terminal.\n"
       return msg
     return rtn
 
@@ -78,7 +105,7 @@ class AdaoCase:
     try:
       import libYACS_Swig
       yacs_swig = libYACS_Swig.YACS_Swig()
-      yacs_swig.loadSchema(self.yacs_filename)
+      yacs_swig.loadSchema(self.yacs_filename, 1, 1)
     except:
       msg =  "Please install YACS module, error was: \n"
       msg += traceback.format_exc()