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 *
26 from salome.hydrotools.shapesGroups import freeBordersGroup, exploreEdgeGroups
29 #pythonVersion = 'python' + sysconfig.get_python_version()
30 hydro_root = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'plugins', 'hydro', 'plugins')
32 class meshEdgesToShapesDialog(QDialog):
36 def __init__(self, parent = None, modal = 0):
37 QDialog.__init__(self, parent)
38 uic.loadUi(os.path.join(hydro_root, 'meshEdgesToShapes.ui'), self )
41 self.pb_medFile.clicked.connect(self.on_med_file_browse)
42 self.pb_outDir.clicked.connect(self.on_outputDir_browse)
43 self.pb_help.clicked.connect(self.on_help)
44 self.pb_ok.accepted.connect(self.on_accept)
45 self.pb_ok.rejected.connect(self.on_reject)
46 self.cb_keepOutMed.setChecked(True)
50 def on_med_file_browse(self):
54 print("on_med_file_browse")
55 self.medFile, filt = QFileDialog.getOpenFileName(self, self.tr("Input MED file"), "", self.tr("MED files (*.med)"))
59 self.le_medFile.setText(self.medFile)
61 def on_outputDir_browse(self):
63 Select OutputDirectory
65 print("on_ouptutDir_browse")
66 self.outDir = QFileDialog.getExistingDirectory(self, self.tr("Output Directory"), "")
70 self.le_outDir.setText(self.outDir)
74 display a help message
77 <h2>Mesh Edges to Shapes Dialog</h2>
79 This dialog is used to extract all groups of edges from a mesh, plus all the border (free) edges,
80 and write the groups as shapefiles.
82 The free edges regroup the external border of the mesh, and all the internal borders (isles).
83 A group containing the free edges is added to the mesh.
85 The mesh is saved in a new file, in an ouput directory used also to store the shapefiles.
87 A shapefile of edges and a shapefile of points are generated for each group of edges.
88 The shapefiles are intended to be loaded in a SIG tool (Qgis) and should preferaby be set in a correct coordinates system.
90 If the mesh uses a local coordinate system with an origin offset, the coordinates of this origin should be set in the dialog.
92 Below is the description of the dialog controls.
95 This field allows selection of a med file (via the standard file open dialog).
96 The filling of this field is mandatory.
98 <h3>offsetX, offsetY</h3>
99 These fields are used to set the Origin of the local coordinates system of the mesh, if any.
101 <h3>Output directory</h3>
102 This field allows selection of a directory to store the shapes and the outputMesh.
104 <h3>Keep output MED file</h3>
105 If this checkbox is unchecked, the output mesh will be removed after calculation of the shapes.
107 QMessageBox.about(self, self.tr("About mesh edges to shapes dialog"), msg);
112 medFile = self.le_medFile.text()
113 outDir = self.le_outDir.text()
114 offsetX = self.dsb_offsetX.value()
115 offsetY = self.dsb_offsetY.value()
116 isOutMedKept = self.cb_keepOutMed.isChecked()
121 print(offsetX, offsetY)
122 a = os.path.splitext(medFile)
123 medFileOut = os.path.join(outDir, os.path.basename(a[0]) + '_brd' + a[1])
125 medFileOut = freeBordersGroup(medFile, medFileOut)
126 exploreEdgeGroups(medFileOut, outDir, offsetX, offsetY)
128 print("remove", medFileOut)
129 os.remove(medFileOut)
136 def execDialog(context):
138 # get context study, salomeGui
139 study = context.study
141 dlg = meshEdgesToShapesDialog()