From 201b9b864e41d0537a69b1fa8caf277338de57e6 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Wed, 25 Nov 2020 18:56:27 +0100 Subject: [PATCH] selection on object browser for shapes in fitShapesPointsToMesheEdges dialog --- src/HYDROGUI/resources/icon_select.png | Bin 167 -> 1007 bytes src/HYDROTools/hydroGeoMeshUtils.py | 24 +++--- .../plugins/fitShapePointsToMeshEdges.ui | 34 +++++++- .../fitShapePointsToMeshEdgesDialog.py | 79 ++++++++++++++++-- 4 files changed, 116 insertions(+), 21 deletions(-) diff --git a/src/HYDROGUI/resources/icon_select.png b/src/HYDROGUI/resources/icon_select.png index cd126ad011ec15a1e57f0975bfec3862e667fdec..4af5214ebf8dfd3245c9cbe7a2aeabb963af42ce 100644 GIT binary patch literal 1007 zcmVz@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ7U=fFnoP+QyZxE zIuQQ{2p~cR{`&L#*GhYz$Z$KaD2DI985rJuWng&xfq~)vyZ;Pt-hXDeu_6y-U>Hzs zFUYk30mMW^uv}X@sg~ixx4#T8KQl1gefyu`()0fePwrk}czJd;!}C+i7@)3`0Af~v z0K(@&Zy?Upv-0o`EttgcG1`IZ!d2#e0zPH;q%kW&w*+W z1Mw#){sRy|=mz=$BVl83dIN(^ND;&9?`#Zb9{*=}eD4Os``d@W2LAc_j^WRbPhf+A z;4~0_1mZ_P{03woKmZ{d$jrpVyfL?X1A~f*2g6gKvdh4*dU4}0!`o|nz~S}v)olh| zX>G9LKi@vw22v-0805-_K>QUX4iG@d28J6tg)_(*crZK%I{wDX{|qm09%XpAcM`*! zE87_U{r+(rr19IUyAh1cY{;&A48-q1c7Ox{0tneae??PYhSxxQo_+ey@buP6hRgHf z8NR>0e-S8m2I{Tve}8>@z`*d056XWA#7}_u8_W=Z075p9&x3f zhMfnBZ-i=i3pD`b5-}hKCToWKP}lv183GVM$m#IovOK@Ix^btxPG1Q4=;_rAY-wC4WKE(TBu#LB_XAZZcHz$}11^_ovS%uB^G5Y`j002ovPDHLkV1f(qwt4^n literal 167 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|&H|6fVg?4j!ywFfJby(BP%zTd z#WBR9ckQL!f(!~A%mHf2|JQDC`zhh%xO7jqrK?X$>M!o2FL^d)2b^fs*)mDPi^=(B z@q$gO{q`+fccUPkxpIN#BL%jTiUOSr8HGxhoKj2L_(lF=XIn9Ysbc0l%SR6FKuZ`r MUHx3vIVCg!0Hzo>_W%F@ diff --git a/src/HYDROTools/hydroGeoMeshUtils.py b/src/HYDROTools/hydroGeoMeshUtils.py index 5089394a..6da1a4ef 100644 --- a/src/HYDROTools/hydroGeoMeshUtils.py +++ b/src/HYDROTools/hydroGeoMeshUtils.py @@ -63,28 +63,32 @@ def importPolylines(document, shapeFile, shapeName, iSpline, displayLevel): shapeType = 1 # polyline shapes = [] isShapeFound = True - shape = document.FindObjectByName(shapeName) # single shape - if shape is not None: - for i in range(shape.NbSections()): - shape.SetSectionType(i, shapeType) - shape.Update() - shape.SetZLevel(displayLevel) - shapes.append(shape) + print("importPolylines %s %s"%(shapeName, shapeType)) index = 0 # for multiple shapes while isShapeFound: shapeNameIndex = shapeName + "_%d" % index index = index + 1 - print(shapeNameIndex) + print("try name %s"%shapeNameIndex) shape = document.FindObjectByName(shapeNameIndex) - print(shape) if shape is None: isShapeFound = False else: + print("found %s"%shapeNameIndex) for i in range(shape.NbSections()): shape.SetSectionType(i, shapeType) shape.Update() shape.SetZLevel(displayLevel) - shapes.append(shape) + shapes.append(shape) + if index <= 1: # no multiple shapes, try single shape + print("try name %s"%shapeName) + shape = document.FindObjectByName(shapeName) # single shape + if shape is not None: + print("found %s"%shapeName) + for i in range(shape.NbSections()): + shape.SetSectionType(i, shapeType) + shape.Update() + shape.SetZLevel(displayLevel) + shapes.append(shape) return shapes def importBathymetry(document, bathyName, bathyPath): diff --git a/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui b/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui index b3f617d3..de18cd81 100644 --- a/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui +++ b/src/HYDROTools/plugins/fitShapePointsToMeshEdges.ui @@ -16,13 +16,13 @@ Qt::LeftToRight - + Input - + @@ -39,9 +39,19 @@ - + + + Select a shape in the HYDRO object browser + + + ... + + + + + @@ -49,6 +59,9 @@ 0 + + Select a shapefile in the file system + ... @@ -68,9 +81,19 @@ - + + + Select a shape in the HYDRO object browser + + + ... + + + + + @@ -78,6 +101,9 @@ 0 + + Select a shapefile in the file system + ... diff --git a/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py b/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py index 937562c7..dc9e646f 100644 --- a/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.py +++ b/src/HYDROTools/plugins/fitShapePointsToMeshEdgesDialog.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 * @@ -30,9 +35,12 @@ from HYDROPy import * from salome.hydrotools.shapesGroups import fitShapePointsToMesh 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): """ @@ -43,6 +51,10 @@ class fitShapePointsToMeshEdgesDialog(QDialog): uic.loadUi(os.path.join(hydro_root, 'fitShapePointsToMeshEdges.ui'), self ) # Connections + self.tb_meshEdges.clicked.connect(self.on_select_meshEdges) + self.tb_shapeToAdjust.clicked.connect(self.on_select_shapeToAdjust) + self.tb_meshEdges.setIcon(QIcon(QPixmap(os.path.join(hydro_resources, "icon_select.png")))) + self.tb_shapeToAdjust.setIcon(QIcon(QPixmap(os.path.join(hydro_resources, "icon_select.png")))) 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) @@ -51,7 +63,55 @@ class fitShapePointsToMeshEdgesDialog(QDialog): self.pb_ok.rejected.connect(self.on_reject) self.meshEdges = None self.shapeToAdjust = None + self.tmpdir = tempfile.mkdtemp() + print("tmpdir=",self.tmpdir) + + + def get_selected_polyline(self): + """ + Select a polyline2D in the HYDRO object browser + """ + ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes() + doc = HYDROData_Document.Document() + for i in ind: + if i.column()==0: + name = str(i.data()) + case = doc.FindObjectByName( name ) + if isinstance(case, HYDROData_PolylineXY): + print("selected %s"%name) + return name + return None + + def on_select_meshEdges(self): + """ + Get selected Polyline in the HYDRO object browser + """ + name = self.get_selected_polyline() + if name is None: + return + doc = HYDROData_Document.Document() + polyXY = doc.FindObjectByName(name) + if polyXY is None: + return + self.meshEdges = os.path.join(self.tmpdir, name + ".shp") + res = HYDROData_PolylineXY.ExportShapeXY(doc, self.meshEdges, [polyXY]) + self.le_meshEdges.setText(self.meshEdges) + def on_select_shapeToAdjust(self): + """ + Get selected Polyline in the HYDRO object browser + """ + name = self.get_selected_polyline() + if name is None: + return + doc = HYDROData_Document.Document() + polyXY = doc.FindObjectByName(name) + if polyXY is None: + return + self.shapeToAdjust = os.path.join(self.tmpdir, name + ".shp") + res = HYDROData_PolylineXY.ExportShapeXY(doc, self.shapeToAdjust, [polyXY]) + self.le_shapeToAdjust.setText(self.shapeToAdjust) + def on_meshEdges_browse(self): """ Select Shapefile of mesh edges @@ -130,6 +190,11 @@ class fitShapePointsToMeshEdgesDialog(QDialog): isSplineMeshEdges = self.cb_splineMeshEdges.isChecked() isSplineShapeToAdjust = self.cb_splineShapeToAdjust.isChecked() outdir = self.le_outDir.text() + if not os.path.isdir(outdir): + msgBox = QMessageBox() + msgBox.setText( "Output directory is not set, please select" ) + msgBox.exec_() + return self.accept() print(meshEdges) print(shapeToAdjust) @@ -143,13 +208,15 @@ class fitShapePointsToMeshEdgesDialog(QDialog): if isMeshEdgesSplit: ext = "_split" meshEdgesShapefile = os.path.join(outdir, a[0] + ext + a[1]) - shapeName = a[0] + ext + shapeName = a[0] #+ ext + "_PolyXY" + print("isSplineMeshEdges %s"%isSplineMeshEdges) 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 + shapeName = a[0] #+ ext + "_PolyXY" + print("isSplineShapeToAdjust %s"%isSplineShapeToAdjust) adjustedShapes = importPolylines(hydro_doc, adjustedShapefile, shapeName, isSplineShapeToAdjust, 0) if salome.sg.hasDesktop(): salome.sg.updateObjBrowser() @@ -162,8 +229,6 @@ class fitShapePointsToMeshEdgesDialog(QDialog): def execDialog(context): print("execDialog") - # get context study, salomeGui - study = context.study - sg = context.sg - dlg = fitShapePointsToMeshEdgesDialog() - dlg.exec_() + desktop = sgPyQt.getDesktop() + dlg = fitShapePointsToMeshEdgesDialog(desktop) + dlg.show() -- 2.39.2