From 9208044cdbddf9e45fb9147c7aa4bf491eb0c72d Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Thu, 26 Nov 2020 19:25:27 +0100 Subject: [PATCH] selection on object browser for med in 'Mesh edges to shapes' dialog --- .../fitShapePointsToMeshEdgesDialog.py | 4 +- src/HYDROTools/plugins/meshEdgesToShapes.ui | 10 ++++ .../plugins/meshEdgesToShapesDialog.py | 59 ++++++++++++++++--- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py b/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py index e9485336..e15e0e69 100644 --- a/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py +++ b/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py @@ -37,13 +37,13 @@ from salome.hydrotools.hydroGeoMeshUtils import importPolylines import tempfile -#import sysconfig -#pythonVersion = 'python' + sysconfig.get_python_version() hydro_root = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'plugins', 'hydro', 'plugins') hydro_resources = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'resources', 'hydro') class fitShapePointsToMeshEdgesDialog(QDialog): """ + 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. """ def __init__(self, parent = None, modal = 0): diff --git a/src/HYDROTools/plugins/meshEdgesToShapes.ui b/src/HYDROTools/plugins/meshEdgesToShapes.ui index 244709d2..cd75f235 100644 --- a/src/HYDROTools/plugins/meshEdgesToShapes.ui +++ b/src/HYDROTools/plugins/meshEdgesToShapes.ui @@ -38,6 +38,16 @@ + + + + Select a shape in the HYDRO object browser + + + ... + + + diff --git a/src/HYDROTools/plugins/meshEdgesToShapesDialog.py b/src/HYDROTools/plugins/meshEdgesToShapesDialog.py index 67b2ed3b..1cf70c87 100644 --- a/src/HYDROTools/plugins/meshEdgesToShapesDialog.py +++ b/src/HYDROTools/plugins/meshEdgesToShapesDialog.py @@ -21,6 +21,11 @@ import salome salome.salome_init() +import SalomePyQt +sgPyQt = SalomePyQt.SalomePyQt() +import libSALOME_Swig +salome_gui = libSALOME_Swig.SALOMEGUI_Swig() + from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * @@ -31,12 +36,16 @@ import json from salome.hydrotools.shapesGroups import freeBordersGroup, exploreEdgeGroups from salome.hydrotools.hydroGeoMeshUtils import importPolylines -#import sysconfig -#pythonVersion = 'python' + sysconfig.get_python_version() +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + hydro_root = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'plugins', 'hydro', 'plugins') +hydro_resources = os.path.join(os.environ['HYDRO_ROOT_DIR'], 'share', 'salome', 'resources', 'hydro') class meshEdgesToShapesDialog(QDialog): """ + This dialog is used to extract all groups of edges from a mesh, plus all the border (free) edges, + and write the groups as shapefiles. """ def __init__(self, parent = None, modal = 0): @@ -45,6 +54,8 @@ class meshEdgesToShapesDialog(QDialog): # Connections self.pb_medFile.clicked.connect(self.on_med_file_browse) + self.tb_medFile.setIcon(QIcon(QPixmap(os.path.join(hydro_resources, "icon_select.png")))) + self.tb_medFile.clicked.connect(self.on_select_med_file) 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) @@ -53,9 +64,40 @@ class meshEdgesToShapesDialog(QDialog): self.medFile = None self.outDir = None + def get_selected_mesh(self): + """ + Select a mesh in the object browser and return associated filename + """ + nbsel = salome.sg.SelectedCount() + if nbsel != 1: + return "" + sel=salome.sg.getSelected(0) + so=salome.myStudy.FindObjectID(sel) + if so is None: + return "" + obj=so.GetObject() + smesh = smeshBuilder.New() + smesh.SetEnablePublish( False ) + mesh1 = smesh.Mesh() + smesh.SetEnablePublish( True ) + if not isinstance(obj, type(mesh1.GetMesh())): + return "" + filename = obj.GetMesh().GetMEDFileInfo().fileName + return filename + + def on_select_med_file(self): + """ + set selected mesh filename on dialog + """ + filename = self.get_selected_mesh() + print("selected mesh: %s"%filename) + if filename != "": + self.medFile = filename + self.le_medFile.setText(self.medFile) + def on_med_file_browse(self): """ - Select MED file + Select MED file in file system """ print("on_med_file_browse") self.medFile, filt = QFileDialog.getOpenFileName(self, self.tr("Input MED file"), "", self.tr("MED files (*.med)")) @@ -130,8 +172,11 @@ class meshEdgesToShapesDialog(QDialog): a = os.path.splitext(medFile) medFileOut = os.path.join(outDir, os.path.basename(a[0]) + '_brd' + a[1]) print(medFileOut) + smesh = smeshBuilder.New() + smesh.SetEnablePublish( False ) medFileOut = freeBordersGroup(medFile, medFileOut) exploreEdgeGroups(medFileOut, outDir, offsetX, offsetY) + smesh.SetEnablePublish( True ) if not isOutMedKept: print("remove", medFileOut) os.remove(medFileOut) @@ -161,8 +206,6 @@ class meshEdgesToShapesDialog(QDialog): def execDialog(context): print("execDialog") - # get context study, salomeGui - study = context.study - sg = context.sg - dlg = meshEdgesToShapesDialog() - dlg.exec_() + desktop = sgPyQt.getDesktop() + dlg = meshEdgesToShapesDialog(desktop) + dlg.show() -- 2.39.2