From: Paul RASCLE Date: Wed, 25 Nov 2020 17:56:27 +0000 (+0100) Subject: selection on object browser for shapes in fitShapesPointsToMesheEdges dialog X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=201b9b864e41d0537a69b1fa8caf277338de57e6;p=modules%2Fhydro.git selection on object browser for shapes in fitShapesPointsToMesheEdges dialog --- diff --git a/src/HYDROGUI/resources/icon_select.png b/src/HYDROGUI/resources/icon_select.png index cd126ad0..4af5214e 100644 Binary files a/src/HYDROGUI/resources/icon_select.png and b/src/HYDROGUI/resources/icon_select.png differ 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()