From 3ad5a0ba33c083a1d305bedf5cc46c31cbce6c54 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Thu, 26 Nov 2020 15:13:26 +0100 Subject: [PATCH] automatic load shapes from dialog 'Mesh edges to shapes' --- src/HYDROTools/plugins/meshEdgesToShapes.ui | 16 +++++++++++- .../plugins/meshEdgesToShapesDialog.py | 26 +++++++++++++++++++ src/HYDROTools/shapesGroups.py | 11 +++++--- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/HYDROTools/plugins/meshEdgesToShapes.ui b/src/HYDROTools/plugins/meshEdgesToShapes.ui index 2319c56c..244709d2 100644 --- a/src/HYDROTools/plugins/meshEdgesToShapes.ui +++ b/src/HYDROTools/plugins/meshEdgesToShapes.ui @@ -7,7 +7,7 @@ 0 0 814 - 369 + 389 @@ -212,6 +212,20 @@ + + + + Load free borders shape + + + + + + + Load all other edge shapes + + + diff --git a/src/HYDROTools/plugins/meshEdgesToShapesDialog.py b/src/HYDROTools/plugins/meshEdgesToShapesDialog.py index e17579ca..67b2ed3b 100644 --- a/src/HYDROTools/plugins/meshEdgesToShapesDialog.py +++ b/src/HYDROTools/plugins/meshEdgesToShapesDialog.py @@ -17,13 +17,19 @@ 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 * +import json from salome.hydrotools.shapesGroups import freeBordersGroup, exploreEdgeGroups +from salome.hydrotools.hydroGeoMeshUtils import importPolylines #import sysconfig #pythonVersion = 'python' + sysconfig.get_python_version() @@ -114,6 +120,8 @@ class meshEdgesToShapesDialog(QDialog): offsetX = self.dsb_offsetX.value() offsetY = self.dsb_offsetY.value() isOutMedKept = self.cb_keepOutMed.isChecked() + isLoadFreeBorders = self.cb_loadFreeBorders.isChecked() + isLoadOthers = self.cb_loadOthers.isChecked() self.accept() print(medFile) print(outDir) @@ -127,6 +135,24 @@ class meshEdgesToShapesDialog(QDialog): if not isOutMedKept: print("remove", medFileOut) os.remove(medFileOut) + shapesListFile = os.path.join(outDir, "shapesList.json") + fileShapes = [] + with open(shapesListFile, 'r') as f: + fileShapes = json.load(f) + print(fileShapes) + hydro_doc = HYDROData_Document.Document() + l = [] + if isLoadFreeBorders: + l = l + [ a for a in fileShapes if "FreeBorders.shp" in a] + if isLoadOthers: + l = l + [ a for a in fileShapes if "FreeBorders.shp" not in a] + for fileShape in l: + a = os.path.splitext(os.path.basename(fileShape)) + shapeName = a[0] + shapes = importPolylines(hydro_doc, fileShape, shapeName, 0, 0) + if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() + def on_reject(self): print("reject") diff --git a/src/HYDROTools/shapesGroups.py b/src/HYDROTools/shapesGroups.py index f4673d80..a5ffb497 100644 --- a/src/HYDROTools/shapesGroups.py +++ b/src/HYDROTools/shapesGroups.py @@ -12,7 +12,7 @@ import medcoupling as mc import shapefile import math import os - +import json def freeBordersGroup(meshFileIn, meshFileOut=""): """ @@ -159,6 +159,7 @@ def writeShapeLines(mcMesh, grpName, nodeChains, outputDirectory, offsetX=0., of w.line([chaincoords]) w.record(chainName) w.close() + return shapeFileName + '.shp' def writeShapePoints(mcMesh, grpName, nodeChains, outputDirectory, offsetX=0., offsetY=0.): @@ -216,12 +217,16 @@ def exploreEdgeGroups(meshFile, outputDirectory="", offsetX=0., offsetY=0.): groups = [mcMesh.getGroup(d1, name) for name in grp_names] # list of groups in their name order + filenames = [] for (grp, grpName) in zip(groups, grp_names): fullGrpName = prefix + '_' + grpName nodeChains = explodeGroup(grp, fullGrpName) - writeShapeLines(mcMesh, fullGrpName, nodeChains, outputDirectory, offsetX, offsetY) + filename = writeShapeLines(mcMesh, fullGrpName, nodeChains, outputDirectory, offsetX, offsetY) writeShapePoints(mcMesh, fullGrpName, nodeChains, outputDirectory, offsetX, offsetY) - + filenames.append(filename) + shapesListFile = os.path.join(outputDirectory, "shapesList.json") + with open(shapesListFile, 'w') as f: + json.dump(filenames, f) def fitShapePointsToMesh(freeBorderShapefile, shapefileToAdjust, outputDirectory="", splitFreeBorder=True, splitShapeAdjusted=True): """ -- 2.39.2