Salome HOME
ca24c63bbf557e9f8676ecd2377fb225015ddc58
[modules/hydrosolver.git] / src / salome_hydro / telma / eficas / appli.py
1 # -*- coding: utf-8 -*-
2 #
3 #  Copyright (C) 2012-2013 EDF
4 #
5 #  This file is part of SALOME HYDRO module.
6 #
7 #  SALOME HYDRO module is free software: you can redistribute it and/or modify
8 #  it under the terms of the GNU General Public License as published by
9 #  the Free Software Foundation, either version 3 of the License, or
10 #  (at your option) any later version.
11 #
12 #  SALOME HYDRO module is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #  GNU General Public License for more details.
16 #
17 #  You should have received a copy of the GNU General Public License
18 #  along with SALOME HYDRO module.  If not, see <http://www.gnu.org/licenses/>.
19
20 import os
21 import sys
22 import re
23
24 from PyQt5.QtWidgets import QMessageBox, QScrollArea, QGridLayout
25
26
27 import salome
28 import SalomePyQt
29 sgPyQt = SalomePyQt.SalomePyQt()
30
31 from salome.kernel.logger import Logger
32 from salome.kernel import termcolor
33 logger = Logger("salome.hydro.telma.eficas.appli",
34                 color = termcolor.GREEN_FG)
35
36 import eficasSalome
37
38 from salome.hydro.study import HydroStudyEditor
39
40 def importFirst():
41     """
42     Horrible hack to allow a correct load of a Telemac case file when done after
43     some other edition, such as create case for Pytel execution.
44     """
45     eficasTelemacPath = os.path.join(eficasSalome.eficasConfig.eficasPath,'Telemac')
46     sys.path.insert(0, eficasTelemacPath)
47     from telemac2d_enum_auto import TelemacdicoEn
48     sys.path.pop(0)
49
50 importFirst()
51
52 class EficasForTelmaAppli(eficasSalome.MyEficas):
53     """
54     This class launches Eficas and adds entries for the created files in
55     HYDRO component in the study tree. The messages in this class are in
56     french because they are displayed in Eficas interface.
57
58     :type  fichier: string
59     :param fichier: path of an Eficas file to open
60
61     """
62     def __init__(self, code="telemac", fichier=None, version=None, lang=None):
63         self.ed = HydroStudyEditor()
64         self.codedir = os.path.dirname(__file__)
65         sys.path[:0] = [self.codedir]
66         area = QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
67         eficasSalome.MyEficas.__init__(self, area,
68                                        code=code, fichier=fichier,
69                                        version=version, lang=lang)
70         gridLayout = QGridLayout(area)
71         gridLayout.addWidget(self)
72         area.setWidgetResizable(1)
73         sgPyQt.createView("Eficas Telemac", self)
74
75
76
77
78     def addJdcInSalome(self, jdcPath):
79         """
80         Add the newly created file in Salome study
81         """
82         try:
83             self.ed.find_or_create_telma(jdcPath)
84         except Exception as exc:
85             msgError = "Can't add file to Salome study tree"
86             logger.exception(msgError)
87             QMessageBox.warning(self, self.tr("Warning"),
88                                 self.tr("%s. Reason:\n%s\n\nSee logs for "
89                                         "more details." % (msgError, exc)))
90         salome.sg.updateObjBrowser(0)
91
92     def closeEvent(self, event):
93         while self.codedir in sys.path:
94             sys.path.remove(self.codedir)
95         eficasSalome.MyEficas.closeEvent(self, event)