]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daGuiImpl/adaoCase.py
Salome HOME
Changement d'architecture pour la gestion du GUI
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoCase.py
1 # -*- coding: utf-8 -*-
2 #  Copyright (C) 2010 EDF R&D
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import os
22 import subprocess
23 import traceback
24 import SalomePyQt
25
26 class AdaoCase:
27
28   def __init__(self):
29
30     self.name = "not yet defined"           # Name of the case
31
32     self.filename = "not yet defined"       # Python filename generated by Eficas
33     self.yacs_filename = "not yet defined"  # Yacs schema filename
34
35     self.salome_study_id = -1               # Study of the case
36     self.salome_study_item = None           # Study item object
37
38     self.eficas_editor = None               # Editor object from Eficas
39
40   def createYACSFile(self):
41     rtn = ""
42     if (self.filename == ""):
43       return "You need to save your case to export it"
44
45     filename = self.filename[:self.filename.rfind(".")] + '.py'
46     if not os.path.exists(filename):
47       msg =  "Cannot find the py file for YACS generation \n"
48       msg += "Is your case correct ? \n"
49       msg += "(Try to load: " + filename + ")"
50       return msg
51
52     if not os.environ.has_key("ADAO_ROOT_DIR"):
53       return "Please add ADAO_ROOT_DIR to your environnement"
54
55     adao_path = os.environ["ADAO_ROOT_DIR"]
56     adao_exe = adao_path + "/bin/salome/AdaoYacsSchemaCreator.py"
57     self.yacs_filename = self.filename[:self.filename.rfind(".")] + '.xml'
58     args = ["python", adao_exe, filename, self.yacs_filename]
59     p = subprocess.Popen(args)
60     (stdoutdata, stderrdata) = p.communicate()
61     if not os.path.exists(self.yacs_filename):
62       msg  = "An error occured during the execution of AdaoYacsSchemaCreator.py \n"
63       msg += "See erros details in your terminal \n"
64       return msg
65     return rtn
66
67   def exportCaseToYACS(self):
68     rtn = ""
69     rtn = self.createYACSFile()
70     if rtn != "":
71       return rtn
72
73     try:
74       import libYACS_Swig
75       yacs_swig = libYACS_Swig.YACS_Swig()
76       yacs_swig.loadSchema(self.yacs_filename)
77     except:
78       msg =  "Please install YACS module, error was: \n"
79       msg += traceback.format_exc()
80       return msg
81     return rtn