Salome HOME
8d4fe2cf32800847ba40700bc55229273e4576a1
[modules/hydrosolver.git] / src / salome_hydro / checkBoundariesDialog.py
1 #  Copyright (C) 2012-2013 EDF
2 #
3 #  This file is part of SALOME HYDRO module.
4 #
5 #  SALOME HYDRO module is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #
10 #  SALOME HYDRO module is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #
15 #  You should have received a copy of the GNU General Public License
16 #  along with SALOME HYDRO module.  If not, see <http://www.gnu.org/licenses/>.
17
18 import os
19 import sys
20
21 from PyQt5.QtCore import *
22 from PyQt5.QtGui import *
23 from PyQt5.QtWidgets import *
24 from PyQt5 import uic
25
26 import subprocess
27 import time
28
29 import sysconfig
30 pythonVersion = 'python' + sysconfig.get_python_version()
31 hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', pythonVersion, 'site-packages', 'salome', 'salome', 'hydro')
32
33 class checkBoundariesDialog(QDialog):
34     """
35     """
36
37     def __init__(self, parent = None, modal = 0):
38         QDialog.__init__(self, parent)
39         uic.loadUi(os.path.join(hydro_solver_root, 'checkBoundaries.ui'), self )
40
41         # Connections
42         self.pb_medFile.clicked.connect(self.on_med_file_browse)
43         self.pb_bcdFile.clicked.connect(self.on_bcd_file_browse)
44         self.rb_liqbcd.toggled.connect(self.on_liqbcd)
45         self.pb_help.clicked.connect(self.on_help)
46         self.pb_ok.accepted.connect(self.on_accept)
47         self.pb_ok.rejected.connect(self.on_reject)
48         self.medFile = None
49         self.bcdFile = None
50         self.rb_liqbcd.setChecked(True)
51         self.rb_allbcd.setChecked(False)
52         self.liqbcd = True
53
54     def on_med_file_browse(self):
55         """
56         Select MED file
57         """
58         print("on_med_file_browse")
59         self.medFile, _filt = QFileDialog.getOpenFileName(self, self.tr("MED file"), "", self.tr("MED files (*.med)"))
60         print(self.medFile)
61         if not self.medFile:
62             return
63         self.le_medFile.setText(self.medFile)
64
65     def on_bcd_file_browse(self):
66         """
67         Select bcd file
68         """
69         print("on_bcd_file_browse")
70         self.bcdFile, _filt = QFileDialog.getOpenFileName(self, self.tr("Boundary Condition file"), "", self.tr("Boundary Condition files (*.bcd)"))
71         print(self.bcdFile)
72         if not self.bcdFile:
73             return
74         self.le_bcdFile.setText(self.bcdFile)
75
76     def on_liqbcd(self):
77         """
78         switch type of display
79         """
80         print("on_liqbcd")
81         if self.rb_liqbcd.isChecked():
82             self.liqbcd = True
83         else:
84             self.liqbcd = False
85
86     def on_help(self):
87         """
88         display a help message
89         """
90         msg = """
91         <h2>Display boundarycondition dialog</h2>
92
93         This dialog is used to draw the mesh with colored boundary conditions on nodes.
94         <br><br>
95         The boundary condition file (bcd) associates a type of boundary condition to each concerned group in the mesh.
96         <br>
97         The option "Liquid /solid boundaries" allows to distinguish all the differents boundary condition groups
98         <br>
99         The option "All boundaries by Telemac type" allows to distinguish all the types of boundary conditions.
100         <br><br>
101         The drawing computation Is launch in a separate process, without waiting.
102         It may be long, for a big mesh...
103         """
104         QMessageBox.about(self, self.tr("About change coordinates dialog"), msg);
105
106
107     def on_accept(self):
108         print("accept")
109         #TODO check medfile in and out not empty
110         #TODO preset for bcdFile
111         medFile = self.le_medFile.text()
112         bcdFile = self.le_bcdFile.text()
113         if not os.path.isfile(medFile):
114             msgBox = QMessageBox()
115             msgBox.setText( "MED file does not exist" )
116             msgBox.exec_()
117             return
118         if not os.path.isfile(bcdFile):
119             msgBox = QMessageBox()
120             msgBox.setText( "Boundary condition file does not exist" )
121             msgBox.exec_()
122             return
123         option = "--bnd"
124         if self.liqbcd:
125             option = "--liq-bnd"
126         cmd = ["plot.py", "mesh2d", medFile, "-b", bcdFile, option]
127         try:
128             proc = subprocess.Popen(cmd)
129         except OSError:
130             print("invalid command")
131             QMessageBox.critical(self, "command error", "%s is not found" % cmd[0])
132         self.accept()
133
134     def on_reject(self):
135         print("reject")
136         self.reject()
137
138
139 def execDialog(context):
140     print("execDialog")
141     # get context study, salomeGui
142     study = context.study
143     sg = context.sg
144     dlg = checkBoundariesDialog()
145     dlg.exec_()