From ebc0069658730aeec33581972051d80539c06bab Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Mon, 23 Nov 2020 19:11:33 +0100 Subject: [PATCH] automatic load of shapes from dialog 'adjust shapefile to mesh' --- .../plugins/fitShapePointsToMeshEdges.ui | 82 ++++++++++++++++++- .../fitShapePointsToMeshEdgesDialog.py | 45 +++++++++- 2 files changed, 121 insertions(+), 6 deletions(-) diff --git a/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui b/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui index 98c9796e..b3f617d3 100644 --- a/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui +++ b/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui @@ -7,7 +7,7 @@ 0 0 817 - 265 + 344 @@ -16,7 +16,7 @@ Qt::LeftToRight - + @@ -85,6 +85,52 @@ + + + + + + + Output + + + + + + + + + 0 + 0 + + + + Output dir: + + + + + + + directory to store shapefiles and output mesh file if kept + + + + + + + + 0 + 0 + + + + ... + + + + + @@ -95,13 +141,27 @@ + + + load result + + + + + + + load as spline + + + + Qt::Horizontal - 40 + 333 20 @@ -115,13 +175,27 @@ + + + load result + + + + + + + load as spline + + + + Qt::Horizontal - 40 + 333 20 diff --git a/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py b/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py index dc7d3a63..937562c7 100644 --- a/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py +++ b/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py @@ -17,13 +17,18 @@ import os import sys +import salome + +salome.salome_init() from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5 import uic +from HYDROPy import * from salome.hydrotools.shapesGroups import fitShapePointsToMesh +from salome.hydrotools.hydroGeoMeshUtils import importPolylines #import sysconfig #pythonVersion = 'python' + sysconfig.get_python_version() @@ -40,6 +45,7 @@ class fitShapePointsToMeshEdgesDialog(QDialog): # Connections self.pb_meshEdges.clicked.connect(self.on_meshEdges_browse) self.pb_shapeToAdjust.clicked.connect(self.on_shapeToAdjust_browse) + self.pb_outDir.clicked.connect(self.on_outputDir_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) @@ -67,6 +73,18 @@ class fitShapePointsToMeshEdgesDialog(QDialog): if not self.shapeToAdjust: return self.le_shapeToAdjust.setText(self.shapeToAdjust) + self.le_outDir.setText(os.path.dirname(self.shapeToAdjust)) + + def on_outputDir_browse(self): + """ + Select OutputDirectory + """ + print("on_ouptutDir_browse") + self.outDir = QFileDialog.getExistingDirectory(self, self.tr("Output Directory"), "") + print(self.outDir) + if not self.outDir: + return + self.le_outDir.setText(self.outDir) def on_help(self): """ @@ -83,7 +101,7 @@ class fitShapePointsToMeshEdgesDialog(QDialog):
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 shapefile adusted is written by default 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'.

@@ -107,12 +125,35 @@ class fitShapePointsToMeshEdgesDialog(QDialog): shapeToAdjust = self.le_shapeToAdjust.text() isMeshEdgesSplit = self.cb_splitMeshEdges.isChecked() isShapeToAdjustSplit = self.cb_splitShapeToAdjust.isChecked() + isLoadMeshEdges = self.cb_loadMeshEdges.isChecked() + isLoadShapeToAdjust = self.cb_loadShapeToAdjust.isChecked() + isSplineMeshEdges = self.cb_splineMeshEdges.isChecked() + isSplineShapeToAdjust = self.cb_splineShapeToAdjust.isChecked() + outdir = self.le_outDir.text() self.accept() print(meshEdges) print(shapeToAdjust) print(isMeshEdgesSplit) print(isShapeToAdjustSplit) - fitShapePointsToMesh(meshEdges, shapeToAdjust, "", isMeshEdgesSplit, isShapeToAdjustSplit) + fitShapePointsToMesh(meshEdges, shapeToAdjust, outdir, isMeshEdgesSplit, isShapeToAdjustSplit) + hydro_doc = HYDROData_Document.Document() + if isLoadMeshEdges: + a = os.path.splitext(os.path.basename(meshEdges)) + ext = "" + if isMeshEdgesSplit: + ext = "_split" + meshEdgesShapefile = os.path.join(outdir, a[0] + ext + a[1]) + shapeName = a[0] + ext + meshEdgesShapes = importPolylines(hydro_doc, meshEdgesShapefile, shapeName, isSplineMeshEdges, 0) + if isLoadShapeToAdjust: + a = os.path.splitext(os.path.basename(shapeToAdjust)) + ext = "_adj" + adjustedShapefile = os.path.join(outdir, a[0] + ext + a[1]) + shapeName = a[0] + ext + adjustedShapes = importPolylines(hydro_doc, adjustedShapefile, shapeName, isSplineShapeToAdjust, 0) + if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() + def on_reject(self): print("reject") -- 2.39.2