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 fitShapePointsToMesh
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 fitShapePointsToMeshEdgesDialog(QDialog):
36 def __init__(self, parent = None, modal = 0):
37 QDialog.__init__(self, parent)
38 uic.loadUi(os.path.join(hydro_root, 'fitShapePointsToMeshEdges.ui'), self )
41 self.pb_meshEdges.clicked.connect(self.on_meshEdges_browse)
42 self.pb_shapeToAdjust.clicked.connect(self.on_shapeToAdjust_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)
47 self.shapeToAdjust = None
49 def on_meshEdges_browse(self):
51 Select Shapefile of mesh edges
53 print("on_meshEdges_browse")
54 self.meshEdges, filt = QFileDialog.getOpenFileName(self, self.tr("shapefile of mesh border edges"), "", self.tr("shapefiles (*.shp)"))
56 if not self.meshEdges:
58 self.le_meshEdges.setText(self.meshEdges)
60 def on_shapeToAdjust_browse(self):
62 Select shapefile to adjust
64 print("on_shapeToAdjust_browse")
65 self.shapeToAdjust, filt = QFileDialog.getOpenFileName(self, self.tr("shapefile to adjust"), "", self.tr("shapefiles (*.shp)"))
66 print(self.shapeToAdjust)
67 if not self.shapeToAdjust:
69 self.le_shapeToAdjust.setText(self.shapeToAdjust)
73 display a help message
76 <h2>Fit shape points to mesh edges dialog</h2>
78 This dialog is used to adjust a shapefile crossing another shapefile corresponding to edges of a mesh, for instance the free borders.
79 the shapeFile to adjust must be a closed line or polygon crossing the free border shapefile in 2 points.
81 The algorithm find in the shapefile to adjust and in the free border shapefile the two closest pairs of corresponding points
82 and move the points in the shapefile to adjust to correspond to the points found in the free border shapefile.
84 If requested, it splits the free border shapefile and/or the shapefile adjusted in two parts, at their intersection.
86 The shapefile adusted is written in the directory of the shapefile to adjust, with a suffix '_adj'.
88 The split free border shapefile is written in the directory of the free border shapefile, with a suffix '_split'.
90 Below is the description of the dialog controls.
92 <h3>Mesh edges shapefile</h3>
93 This field allows selection of a shapefile (via the standard file open dialog).
94 <h3>Shapefile to adjust</h3>
95 This field allows selection of a shapefile (via the standard file open dialog).
96 <h3>Split mesh edges shapefile</h3>
97 If this checkbox is checked, the mesh edges shapefile is split at the intersection with the other shapefile.
98 <h3>Split shapefile to adjust</h3>
99 If this checkbox is checked, the shapefile to adjust is split at the intersection with the other shapefile.
101 QMessageBox.about(self, self.tr("About fit shape points to mesh edges dialog"), msg);
106 meshEdges = self.le_meshEdges.text()
107 shapeToAdjust = self.le_shapeToAdjust.text()
108 isMeshEdgesSplit = self.cb_splitMeshEdges.isChecked()
109 isShapeToAdjustSplit = self.cb_splitShapeToAdjust.isChecked()
113 print(isMeshEdgesSplit)
114 print(isShapeToAdjustSplit)
115 fitShapePointsToMesh(meshEdges, shapeToAdjust, "", isMeshEdgesSplit, isShapeToAdjustSplit)
122 def execDialog(context):
124 # get context study, salomeGui
125 study = context.study
127 dlg = fitShapePointsToMeshEdgesDialog()