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):
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 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):
# 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)
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)"))
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)
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()