]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daGuiImpl/adaoCase.py
Salome HOME
Updating copyright date information and version
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoCase.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2015 EDF R&D
3 #
4 # This file is part of SALOME ADAO module
5 #
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.
10 #
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.
15 #
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
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 import os
24 import subprocess
25 import traceback
26 import SalomePyQt
27
28 import eficasSalome
29 from Ihm import CONNECTOR
30 import adaoGuiHelper
31 import adaoStudyEditor
32
33 class AdaoCase:
34
35   def __init__(self):
36
37     self.name = "not yet defined"           # Name of the case
38
39     self.filename = "not yet defined"       # Python filename generated by Eficas
40     self.yacs_filename = "not yet defined"  # Yacs schema filename
41
42     self.salome_study_id = -1               # Study of the case
43     self.salome_study_item = None           # Study item object
44
45     self.eficas_editor = None               # Editor object from Eficas
46
47   def setEditor(self, editor):
48     if editor is not self.eficas_editor:
49       self.eficas_editor = editor
50       # Connect to the jdc
51       CONNECTOR.Connect(self.eficas_editor.jdc, "valid", self.editorValidEvent, ())
52
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()
60
61   def isOk(self):
62     if self.eficas_editor.jdc:
63       return self.eficas_editor.jdc.isvalid()
64     return False
65
66   def createYACSFile(self):
67     rtn = ""
68     if (self.filename == ""):
69       return "You need to save your case to export it."
70
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)
75
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"
82       return msg
83
84     if not os.environ.has_key("ADAO_ROOT_DIR"):
85       return "Please add ADAO_ROOT_DIR to your environnement."
86
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"
96       return msg
97     return rtn
98
99   def exportCaseToYACS(self):
100     rtn = ""
101     rtn = self.createYACSFile()
102     if rtn != "":
103       return rtn
104
105     try:
106       import libYACS_Swig
107       yacs_swig = libYACS_Swig.YACS_Swig()
108       yacs_swig.loadSchema(self.yacs_filename, 1, 1)
109     except:
110       msg =  "Please install YACS module, error was: \n"
111       msg += traceback.format_exc()
112       return msg
113     return rtn