]> SALOME platform Git repositories - modules/hydrosolver.git/blob - src/salome_hydro/telemac2d/eficas/appli.py
Salome HOME
yamm adaptation and lot 6
[modules/hydrosolver.git] / src / salome_hydro / telemac2d / 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 PyQt4.QtGui import QMessageBox
25
26 import salome
27 import SalomePyQt
28 sgPyQt = SalomePyQt.SalomePyQt()
29
30 from salome.kernel.logger import Logger
31 from salome.kernel import termcolor
32 logger = Logger("salome.hydro.telemac2d.eficas.appli",
33                 color = termcolor.GREEN_FG)
34
35 import eficasSalome
36
37 from salome.hydro.study import HydroStudyEditor
38
39 class EficasForTelemac2DAppli(eficasSalome.MyEficas):
40     """
41     This class launches Eficas and adds entries for the created files in
42     HYDRO component in the study tree. The messages in this class are in
43     french because they are displayed in Eficas interface.
44
45     :type  fichier: string
46     :param fichier: path of an Eficas file to open
47
48     """
49     def __init__(self, fichier = None, version = None):
50         self.ed = HydroStudyEditor()
51         self.codedir = os.path.dirname(__file__)
52         sys.path[:0] = [self.codedir]
53         eficasSalome.MyEficas.__init__(self, sgPyQt.getDesktop(),
54                                        "telemac2d",
55                                        fichier, version = version)
56         sgPyQt.createView("Eficas Telemac2D", self)
57
58     def addJdcInSalome(self, jdcPath):
59         """
60         Add the newly created file in Salome study
61         """
62         try:
63             self.ed.find_or_create_telemac2d_case(jdcPath)
64         except Exception, exc:
65             msgError = "Can't add file to Salome study tree"
66             logger.exception(msgError)
67             QMessageBox.warning(self, self.tr("Warning"),
68                                 self.tr("%s. Reason:\n%s\n\nSee logs for "
69                                         "more details." % (msgError, exc)))
70         salome.sg.updateObjBrowser(0)
71
72     def closeEvent(self, event):
73         while self.codedir in sys.path:
74             sys.path.remove(self.codedir)
75         eficasSalome.MyEficas.closeEvent(self, event)