]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daGuiImpl/adaoCase.py
Salome HOME
Ajout des boutons save et close, travaux en cours
[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     self.__name = "new_case"
30     self.__filename = ""
31     self.__yacs_filename = ""
32
33   def get_name(self):
34     return self.__name
35
36   def set_name(self, name):
37     self.__name = str(name)
38
39   def get_filename(self):
40     return self.__filename
41
42   def set_filename(self, name):
43     self.__filename = str(name)
44
45   def createYACSFile(self):
46     rtn = ""
47     if (self.__filename == ""):
48       return "You need to save your case to export it"
49
50     filename = self.__filename[:self.__filename.rfind(".")] + '.py'
51     if not os.path.exists(filename):
52       msg =  "Cannot find the py file for YACS generation \n"
53       msg += "Is your case correct ? \n"
54       msg += "(Try to load: " + filename + ")"
55       return msg
56
57     if not os.environ.has_key("ADAO_ROOT_DIR"):
58       return "Please add ADAO_ROOT_DIR to your environnement"
59
60     adao_path = os.environ["ADAO_ROOT_DIR"]
61     adao_exe = adao_path + "/bin/salome/AdaoYacsSchemaCreator.py"
62     self.__yacs_filename = self.__filename[:self.__filename.rfind(".")] + '.xml'
63     args = ["python", adao_exe, filename, self.__yacs_filename]
64     p = subprocess.Popen(args)
65     (stdoutdata, stderrdata) = p.communicate()
66     if not os.path.exists(self.__yacs_filename):
67       msg  = "An error occured during the execution of AdaoYacsSchemaCreator.py \n"
68       msg += "See erros details in your terminal \n"
69       return msg
70     return rtn
71
72   def exportCaseToYACS(self):
73     rtn = ""
74     rtn = self.createYACSFile()
75     if rtn != "":
76       return rtn
77
78     try:
79       import libYACS_Swig
80       yacs_swig = libYACS_Swig.YACS_Swig()
81       yacs_swig.loadSchema(self.__yacs_filename)
82     except:
83       msg =  "Please install YACS module, error was: \n"
84       msg += traceback.format_exc()
85       return msg
86     return rtn
87