1 # Copyright (C) 2012-2013 EDF
3 # This file is part of SALOME HYDRO module.
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.
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.
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/>.
21 from PyQt5.QtCore import *
22 from PyQt5.QtGui import *
23 from PyQt5.QtWidgets import *
27 from pyproj import CRS
29 from salome.hydrotools.changeCoords import changeCoords
32 pythonVersion = 'python' + sysconfig.get_python_version()
33 hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', pythonVersion, 'site-packages', 'salome', 'salome', 'hydro')
35 class changeCoordsDialog(QDialog):
39 def __init__(self, parent = None, modal = 0):
40 QDialog.__init__(self, parent)
41 uic.loadUi(os.path.join(hydro_solver_root, 'changeCoords.ui'), self )
44 self.pb_medFileIn.clicked.connect(self.on_med_file_in_browse)
45 self.pb_medFileOut.clicked.connect(self.on_med_file_out_browse)
46 self.pb_help.clicked.connect(self.on_help)
47 self.pb_ok.accepted.connect(self.on_accept)
48 self.pb_ok.rejected.connect(self.on_reject)
50 self.medFileOut = None
51 EPSG_list = (2154, 27561, 27562, 27563, 27564, 27571, 27572, 27573, 27574 )
52 for epsg in EPSG_list:
53 crs_code = CRS.from_epsg(epsg)
54 codeName = str(epsg) + ' ' + crs_code.name
55 self.cmb_systemIn.addItem(codeName)
56 self.cmb_systemOut.addItem(codeName)
57 self.cb_changeCoordSystem.setChecked(True)
58 self.cb_changeCoordSystem.setChecked(False)
60 def on_med_file_in_browse(self):
64 print("on_med_file_in_browse")
65 self.medFileIn, filt = QFileDialog.getOpenFileName(self, self.tr("Input MED file"), "", self.tr("MED files (*.med)"))
67 if not self.medFileIn:
69 self.le_medFileIn.setText(self.medFileIn)
70 a = os.path.splitext(self.medFileIn)
71 self.medFileOut = a[0] + '_coo' + a[1]
72 self.le_medFileOut.setText(self.medFileOut)
74 def on_med_file_out_browse(self):
76 Select output MED file
78 print("on_med_file_out_browse")
79 self.medFileOut, filt = QFileDialog.getSaveFileName(self, self.tr("Output MED file"), "", self.tr("MED files (*.med)"))
80 print(self.medFileOut)
81 if not self.medFileOut:
83 self.le_medFileOut.setText(self.medFileOut)
87 display a help message
90 <h2>Change mesh coordinates dialog</h2>
92 This dialog is used to change the nodes coordinates in a mesh. It is used either for a simple translation, a change of coordinates system
93 (for instance from Lambert II to Lambert-93), or a combination.
95 The modified mesh is saved in a new file.
97 If there is a change of coordinates system, the input mesh is first translated, when it uses a local origin.
98 After the change of coordinates system, the output mesh can be translated (new local origin).
100 When there is only a simple translation, the operation is: Xout = Xin + offsetXin -offsetXout, Yout = Yin + offsetYin -offsetYout.
102 Below is the description of the dialog controls.
104 <h3>Change coordinates system</h3>
105 If this checkbox is checked, the output mesh will be removed after calculation of the shapes.
107 <h3>Input MED file</h3>
108 This field allows the selection of a med file (via the standard file open dialog).
109 The filling of this field is mandatory.
111 <h3>Input offsetX, offsetY</h3>
112 These fields are used to set the Origin of the local coordinates system of the input mesh, if any.
114 <h3>Input Coord System</h3>
115 This combo box is use to select the coordinate system of the input mesh.
117 <h3>Output MED file</h3>
118 This field allows the definition of a med file (via the standard file save dialog).
119 The filling of this field is mandatory.
121 <h3>Output offsetX, offsetY</h3>
122 These fields are used to set the Origin of the local coordinates system of the output mesh, if any.
124 <h3>Output Coord System</h3>
125 This combo box is use to select the coordinate system of the output mesh.
127 QMessageBox.about(self, self.tr("About mesh edges to shapes dialog"), msg);
132 #TODO check medfile in and out not empty
133 #TODO preset for medFileOut
134 medFileIn = self.le_medFileIn.text()
135 medFileOut = self.le_medFileOut.text()
136 offsetXin = self.dsb_offsetXin.value()
137 offsetYin = self.dsb_offsetYin.value()
138 offsetXout = self.dsb_offsetXout.value()
139 offsetYout = self.dsb_offsetYout.value()
140 isChangeCoordSystem = self.cb_changeCoordSystem.isChecked()
143 if isChangeCoordSystem:
144 epsgIn = int(self.cmb_systemIn.currentText().split()[0])
145 epsgOut = int(self.cmb_systemOut.currentText().split()[0])
148 print(isChangeCoordSystem)
149 print(offsetXin, offsetYin)
150 print(offsetXout, offsetYout)
151 print(epsgIn, epsgOut)
152 if not os.path.isfile(medFileIn):
153 msgBox = QMessageBox()
154 msgBox.setText( "Input MED file does not exist" )
157 dir = os.path.dirname(medFileOut)
158 base = os.path.basename(medFileOut)
159 ext = os.path.splitext(medFileOut)[1]
160 if not os.path.isdir(dir) or (base == "") or (ext.lower() != ".med"):
161 msgBox = QMessageBox()
162 msgBox.setText( "Output MED file is not a valid path" )
166 changeCoords(medFileIn, medFileOut, epsgIn, epsgOut, offsetXin, offsetYin, offsetXout, offsetYout)
173 def execDialog(context):
175 # get context study, salomeGui
176 study = context.study
178 dlg = changeCoordsDialog()