Salome HOME
ed5e4e4b613da93b260363c3a96745910cd84ded
[modules/hydrosolver.git] / src / salome_hydro / mascaret / 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.mascaret.eficas.appli",
34                 color = termcolor.GREEN_FG)
35
36 import eficasSalome
37
38 from salome.hydro.study import HydroStudyEditor
39
40 class EficasForMascaretAppli(eficasSalome.MyEficas):
41     """
42     This class launches Eficas and adds entries for the created files in
43     MASCARET component in the study tree. The messages in this class are in
44     french because they are displayed in Eficas interface.
45
46     :type  fichier: string
47     :param fichier: path of an Eficas file to open
48
49     """
50     def __init__(self, fichier = None, version = None):
51         self.ed = HydroStudyEditor()
52         self.codedir = os.path.dirname(__file__)
53         sys.path[:0] = [self.codedir]
54         area = QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
55         eficasSalome.MyEficas.__init__(self, area,
56                                        "mascaret",
57                                        fichier, version = version)
58         gridLayout = QGridLayout(area)
59         gridLayout.addWidget(self)
60         area.setWidgetResizable(1)
61         sgPyQt.createView("Eficas Mascaret", self)
62
63     def addJdcInSalome(self, jdcPath):
64         """
65         Add the newly created file in Salome study
66         """
67         try:
68             self.ed.find_or_create_mascaret_case(jdcPath)
69         except Exception, exc:
70             msgError = "Can't add file to Salome study tree"
71             logger.exception(msgError)
72             QMessageBox.warning(self, self.tr("Warning"),
73                                 self.tr("%s. Reason:\n%s\n\nSee logs for "
74                                         "more details." % (msgError, exc)))
75         salome.sg.updateObjBrowser(0)
76
77     def closeEvent(self, event):
78         while self.codedir in sys.path:
79             sys.path.remove(self.codedir)
80         eficasSalome.MyEficas.closeEvent(self, event)