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):
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_3">
+ <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Input</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
</widget>
</item>
<item row="0" column="1">
- <widget class="QLineEdit" name="le_meshEdges"/>
+ <widget class="QToolButton" name="tb_meshEdges">
+ <property name="toolTip">
+ <string>Select a shape in the HYDRO object browser</string>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
</item>
<item row="0" column="2">
+ <widget class="QLineEdit" name="le_meshEdges"/>
+ </item>
+ <item row="0" column="3">
<widget class="QToolButton" name="pb_meshEdges">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="toolTip">
+ <string>Select a shapefile in the file system</string>
+ </property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="1">
- <widget class="QLineEdit" name="le_shapeToAdjust"/>
+ <widget class="QToolButton" name="tb_shapeToAdjust">
+ <property name="toolTip">
+ <string>Select a shape in the HYDRO object browser</string>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
</item>
<item row="1" column="2">
+ <widget class="QLineEdit" name="le_shapeToAdjust"/>
+ </item>
+ <item row="1" column="3">
<widget class="QToolButton" name="pb_shapeToAdjust">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="toolTip">
+ <string>Select a shapefile in the file system</string>
+ </property>
<property name="text">
<string>...</string>
</property>
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 *
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):
"""
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)
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
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)
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()
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()