From 1c7c17682ebfb369350c229ae36d68d83073fa4b Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Thu, 13 Aug 2020 21:17:23 +0200 Subject: [PATCH] dialog adjust shape point to mesh edges --- src/HYDROTools/hydro_plugins.py | 9 + src/HYDROTools/plugins/CMakeLists.txt | 2 + .../plugins/fitShapePointsToMeshEdges.ui | 231 ++++++++++++++++++ .../fitShapePointsToMeshEdgesDialog.py | 128 ++++++++++ 4 files changed, 370 insertions(+) create mode 100644 src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui create mode 100644 src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py diff --git a/src/HYDROTools/hydro_plugins.py b/src/HYDROTools/hydro_plugins.py index 11eb9f49..c86b138a 100644 --- a/src/HYDROTools/hydro_plugins.py +++ b/src/HYDROTools/hydro_plugins.py @@ -32,6 +32,15 @@ except Exception as e: salome_pluginsmanager.logger.info('ERROR: meshEdgesToShapes plug-in is unavailable: {}'.format(e)) pass +try: + from plugins import fitShapePointsToMeshEdgesDialog + salome_pluginsmanager.AddFunction('Adjust shapefile', + 'Adjust shapefile points to mesh edges', + fitShapePointsToMeshEdgesDialog.execDialog) +except Exception as e: + salome_pluginsmanager.logger.info('ERROR: fitShapePointsToMeshEdges plug-in is unavailable: {}'.format(e)) + pass + try: from testPlugin import testDialog salome_pluginsmanager.AddFunction('test Dialog', diff --git a/src/HYDROTools/plugins/CMakeLists.txt b/src/HYDROTools/plugins/CMakeLists.txt index 2509e46b..e01a3d4b 100644 --- a/src/HYDROTools/plugins/CMakeLists.txt +++ b/src/HYDROTools/plugins/CMakeLists.txt @@ -20,10 +20,12 @@ SET(PLUGIN_SCRIPTS __init__.py meshEdgesToShapesDialog.py + fitShapePointsToMeshEdgesDialog.py ) SET(UIFILES meshEdgesToShapes.ui + fitShapePointsToMeshEdges.ui ) # --- rules --- diff --git a/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui b/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui new file mode 100644 index 00000000..f8feb325 --- /dev/null +++ b/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui @@ -0,0 +1,231 @@ + + + Dialog + + + + 0 + 0 + 817 + 265 + + + + Mesh Edges to Shapes + + + Qt::LeftToRight + + + + + + Input + + + + + + + + + 0 + 0 + + + + Mesh edges shapefile + + + + + + + + + + + 0 + 0 + + + + ... + + + + + + + + 0 + 0 + + + + Shapefile to adjust + + + + + + + + + + + 0 + 0 + + + + ... + + + + + + + + + + + Split mesh edges shapefile + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Split shapefile to adjust + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 66 + + + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Help + + + + + + + + + + + pb_ok + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + pb_ok + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + diff --git a/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py b/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py new file mode 100644 index 00000000..c27a8891 --- /dev/null +++ b/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py @@ -0,0 +1,128 @@ +# Copyright (C) 2012-2013 EDF +# +# This file is part of SALOME HYDRO module. +# +# SALOME HYDRO module is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# SALOME HYDRO module is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with SALOME HYDRO module. If not, see . + +import os +import sys + +from PyQt5.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * +from PyQt5 import uic + +from salome.hydrotools.shapesGroups import fitShapePointsToMesh + +#import sysconfig +#pythonVersion = 'python' + sysconfig.get_python_version() +hydro_root = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'plugins', 'hydro', 'plugins') + +class fitShapePointsToMeshEdgesDialog(QDialog): + """ + """ + + def __init__(self, parent = None, modal = 0): + QDialog.__init__(self, parent) + uic.loadUi(os.path.join(hydro_root, 'fitShapePointsToMeshEdges.ui'), self ) + + # Connections + self.pb_meshEdges.clicked.connect(self.on_meshEdges_browse) + self.pb_shapeToAdjust.clicked.connect(self.on_shapeToAdjust_browse) + self.pb_help.clicked.connect(self.on_help) + self.pb_ok.accepted.connect(self.on_accept) + self.pb_ok.rejected.connect(self.on_reject) + self.meshEdges = None + self.shapeToAdjust = None + + def on_meshEdges_browse(self): + """ + Select Shapefile of mesh edges + """ + print("on_meshEdges_browse") + self.meshEdges, filt = QFileDialog.getOpenFileName(self, self.tr("shapefile of mesh border edges"), "", self.tr("shapefiles (*.shp)")) + print(self.meshEdges) + if not self.meshEdges: + return + self.le_meshEdges.setText(self.meshEdges) + + def on_shapeToAdjust_browse(self): + """ + Select shapefile to adjust + """ + print("on_shapeToAdjust_browse") + self.shapeToAdjust, filt = QFileDialog.getOpenFileName(self, self.tr("shapefile to adjust"), "", self.tr("shapefiles (*.shp)")) + print(self.shapeToAdjust) + if not self.shapeToAdjust: + return + self.le_shapeToAdjust.setText(self.shapeToAdjust) + + def on_help(self): + """ + display a help message + """ + msg = """ +

Fit shape points to mesh edges dialog

+ + This dialog is used to adjust a shapefile crossing another shapefile corresponding to edges of a mesh, for instance the free borders. + the shapeFile to adjust must be a closed line or polygon crossing the free border shapefile in 2 points. +

+ The algorithm find in the shapefile to adjust and in the free border shapefile the two closest pairs of corresponding points + and move the points in the shapefile to adjust to correspond to the points found in the free border shapefile. +
+ If requested, it splits the free border shapefile and/or the shapefile adjusted in two parts, at their intersection. +
+ The shapefile adusted is written in the directory of the shapefile to adjust, with a suffix '_adj'. +
+ The split free border shapefile is written in the directory of the free border shapefile, with a suffix '_split'. +

+ Below is the description of the dialog controls. + +

Mesh edges shapefile

+ This field allows selection of a shapefile (via the standard file open dialog). +

Shapefile to adjust

+ This field allows selection of a shapefile (via the standard file open dialog). +

Split mesh edges shapefile

+ If this checkbox is checked, the mesh edges shapefile is split at the intersection with the other shapefile. +

Split shapefile to adjust

+ If this checkbox is checked, the shapefile to adjust is split at the intersection with the other shapefile. + """ + QMessageBox.about(self, self.tr("About fit shape points to mesh edges dialog"), msg); + + + def on_accept(self): + print("accept") + meshEdges = self.le_meshEdges.text() + shapeToAdjust = self.le_shapeToAdjust.text() + isMeshEdgesSplit = self.cb_splitMeshEdges.isChecked() + isShapeToAdjustSplit = self.cb_splitShapeToAdjust.isChecked() + self.accept() + print(meshEdges) + print(shapeToAdjust) + print(isMeshEdgesSplit) + print(isShapeToAdjustSplit) + fitShapePointsToMesh(meshEdges, shapeToAdjust, isMeshEdgesSplit, isShapeToAdjustSplit) + + def on_reject(self): + print("reject") + self.reject() + + +def execDialog(context): + print("execDialog") + # get context study, salomeGui + study = context.study + sg = context.sg + dlg = fitShapePointsToMeshEdgesDialog() + dlg.exec_() -- 2.30.2