1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2015 EDF R&D
4 # This file is part of SALOME ADAO module
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
29 from Ihm import CONNECTOR
31 import adaoStudyEditor
37 self.name = "not yet defined" # Name of the case
39 self.filename = "not yet defined" # Python filename generated by Eficas
40 self.yacs_filename = "not yet defined" # Yacs schema filename
42 self.salome_study_id = -1 # Study of the case
43 self.salome_study_item = None # Study item object
45 self.eficas_editor = None # Editor object from Eficas
47 def setEditor(self, editor):
48 if editor is not self.eficas_editor:
49 self.eficas_editor = editor
51 CONNECTOR.Connect(self.eficas_editor.jdc, "valid", self.editorValidEvent, ())
53 # Rq on notera que l'on utilise isvalid dans isOk
54 # et que isOk appelle editorValidEvent
55 # il n'y a pas de boucle infini car isvalid n'émet
56 # son signal que si l'état a changé
57 def editorValidEvent(self):
58 adaoStudyEditor.updateItem(self.salome_study_id, self.salome_study_item, self)
59 adaoGuiHelper.refreshObjectBrowser()
62 if self.eficas_editor.jdc:
63 return self.eficas_editor.jdc.isvalid()
66 def createYACSFile(self):
68 if (self.filename == ""):
69 return "You need to save your case to export it."
71 self.yacs_filename = self.filename[:self.filename.rfind(".")] + '.xml'
72 yacs_filename_backup = self.filename[:self.filename.rfind(".")] + '.xml.back'
73 if os.path.exists(self.yacs_filename):
74 os.rename(self.yacs_filename, yacs_filename_backup)
76 self.eficas_editor.modified = True
77 self.eficas_editor.saveFile()
78 filename = self.filename[:self.filename.rfind(".")] + '.py'
79 if not os.path.exists(filename):
80 msg = "Cannot find the COMM associated python file for YACS\n"
81 msg += "generation. Is your case correct?\n"
84 if not os.environ.has_key("ADAO_ROOT_DIR"):
85 return "Please add ADAO_ROOT_DIR to your environnement."
87 adao_path = os.environ["ADAO_ROOT_DIR"]
88 adao_exe = adao_path + "/bin/salome/AdaoYacsSchemaCreator.py"
89 args = ["python", adao_exe, filename, self.yacs_filename]
90 p = subprocess.Popen(args)
91 (stdoutdata, stderrdata) = p.communicate()
92 if not os.path.exists(self.yacs_filename):
93 msg = "An error occured during the execution of the ADAO YACS Schema\n"
94 msg += "Creator. If SALOME is launched by command line, see errors\n"
95 msg += "details in your terminal.\n"
99 def exportCaseToYACS(self):
101 rtn = self.createYACSFile()
107 yacs_swig = libYACS_Swig.YACS_Swig()
108 yacs_swig.loadSchema(self.yacs_filename, 1, 1)
110 msg = "Please install YACS module, error was: \n"
111 msg += traceback.format_exc()