From: prascle Date: Tue, 3 May 2011 15:37:17 +0000 (+0000) Subject: PR: plugin for MeshCut X-Git-Tag: V6_3_0b1~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=07a37cb49f47b0f745249b0b889ccefc1068c4eb;p=modules%2Fsmesh.git PR: plugin for MeshCut --- diff --git a/src/Tools/MeshCut/Makefile.am b/src/Tools/MeshCut/Makefile.am index 38adf9195..a32f4454c 100644 --- a/src/Tools/MeshCut/Makefile.am +++ b/src/Tools/MeshCut/Makefile.am @@ -43,3 +43,14 @@ MeshCut_CPPFLAGS = $(MED2_INCLUDES) MeshCut_LDFLAGS = $(MED2_LIBS) $(HDF5_LIBS) + + +UIPY_FILES = MeshCutDialog.py +BUILT_SOURCES = $(UIPY_FILES) +bin_SCRIPTS = $(UIPY_FILES) meshcut_plugin.py +clean-local: + rm -f $(UIPY_FILES) +EXTRA_DIST += MeshCutDialog.ui meshcut_plugin.py + +%.py : %.ui + pyuic4 $< -o $@ diff --git a/src/Tools/MeshCut/MeshCutDialog.ui b/src/Tools/MeshCut/MeshCutDialog.ui new file mode 100644 index 000000000..1ec542285 --- /dev/null +++ b/src/Tools/MeshCut/MeshCutDialog.ui @@ -0,0 +1,270 @@ + + + Dialog + + + + 0 + 0 + 416 + 431 + + + + cut a mesh by a plane + + + + + + + + original mesh file + + + + + + + + + + + + output mesh name + + + + + + + meshCut + + + + + + + name of group above cut + + + + + + + above + + + + + + + name of group below cut + + + + + + + below + + + + + + + + + cut plane + + + + + + + + normal vector + + + + + + + vertex in plane + + + + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 1.000000000000000 + + + + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + + + + + + Qt::Horizontal + + + + Tolerance 0 < T <= 1 + + + + + 1.000000000000000 + + + 0.010000000000000 + + + 0.010000000000000 + + + + + + + + Qt::Vertical + + + + 396 + 90 + + + + + + + + Qt::Horizontal + + + + Help + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + cut mesh file + + + + + + + + + + + pb_okCancel + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + pb_okCancel + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/Tools/MeshCut/README b/src/Tools/MeshCut/README index 6dbff87f2..599806b18 100644 --- a/src/Tools/MeshCut/README +++ b/src/Tools/MeshCut/README @@ -21,6 +21,6 @@ where: belowGroups = name of the group of volumes below the cut plane nx ny nz = vector normal to the cut plane px py pz = a point of the cut plane - T = 0 < T < 1 : vertices of a tetrahedron are considered as belonging + T = 0 < T < 1 : vertices of a tetrahedron are considered as belonging to the cut plane if their distance to the plane is inferior to L*T where L is the mean edge size of the tetrahedron diff --git a/src/Tools/MeshCut/meshcut_plugin.py b/src/Tools/MeshCut/meshcut_plugin.py new file mode 100644 index 000000000..578d3fae1 --- /dev/null +++ b/src/Tools/MeshCut/meshcut_plugin.py @@ -0,0 +1,126 @@ +# if you already have plugins defined in a salome_plugins.py file, add this file at the end. +# if not, copy this file as ${HOME}/Plugins/salome_plugins.py or ${APPLI}/Plugins/salome_plugins.py + +import salome_pluginsmanager + +def MeshCut(context): + # get context study, studyId, salomeGui + study = context.study + studyId = context.studyId + sg = context.sg + + import os + import subprocess + import tempfile + from PyQt4 import QtGui + from PyQt4.QtGui import QFileDialog + from PyQt4.QtGui import QMessageBox + from MeshCutDialog import Ui_Dialog + + class CutDialog(QtGui.QDialog): + + def __init__(self): + QtGui.QDialog.__init__(self) + # Set up the user interface from Designer. + self.ui = Ui_Dialog() + self.ui.setupUi(self) + # Connect up the buttons. + self.connect(self.ui.pb_origMeshFile, QtCore.SIGNAL("clicked()"), + self.setInputFile) + self.connect(self.ui.pb_cutMeshFile, QtCore.SIGNAL("clicked()"), + self.setOutputFile) + self.connect(self.ui.pb_help, QtCore.SIGNAL("clicked()"), + self.helpMessage) + pass + + def setInputFile(self): + fd = QFileDialog(self, "select an existing Med file", self.ui.le_origMeshFile.text(), "MED-Files (*.med);;All Files (*)") + if fd.exec_(): + infile = fd.selectedFiles()[0] + self.ui.le_origMeshFile.setText(infile) + insplit = os.path.splitext(infile.toLocal8Bit().data()) + outfile = insplit[0] + '_cut' + insplit[1] + self.ui.le_cutMeshFile.setText(outfile) + pass + + def setOutputFile(self): + fd = QFileDialog(self, "select an output Med file", self.ui.le_cutMeshFile.text(), "MED-Files (*.med);;All Files (*)") + if fd.exec_(): + self.ui.le_cutMeshFile.setText(fd.selectedFiles()[0]) + pass + + def helpMessage(self): + QMessageBox.about(None, "About MeshCut", + """ + Cut a tetrahedron mesh by a plane + --------------------------------- + +MeshCut allows to cut a mesh constituted of linear +tetrahedrons by a plane. The tetrahedrons intersected +by the plane are cut and replaced by elements of +various types (tetrahedron, pyramid, pentahedron). + +MeshCut is a standalone program, reading and +producing med files. The cutting plane is defined +by a vector normal to the plane and a vertex +belonging to the plane. + +Vertices of a tetrahedron are considered as belonging to +the cut plane if their distance to the plane is inferior +to L*T where L is the mean edge size of the tetrahedron +and T the tolerance. + """) + pass + pass + + + + window = CutDialog() + window.ui.dsb_tolerance.setValue(0.01) + retry = True + while(retry): + retry = False + window.exec_() + result = window.result() + if result: + # dialog accepted + args = ['MeshCut'] + args += [window.ui.le_origMeshFile.text().toLocal8Bit().data()] + args += [window.ui.le_cutMeshFile.text().toLocal8Bit().data()] + args += [window.ui.le_outMeshName.text().toLocal8Bit().data()] + args += [window.ui.le_groupAbove.text().toLocal8Bit().data()] + args += [window.ui.le_groupBelow.text().toLocal8Bit().data()] + args += [str(window.ui.dsb_normX.value())] + args += [str(window.ui.dsb_normY.value())] + args += [str(window.ui.dsb_normZ.value())] + args += [str(window.ui.dsb_vertX.value())] + args += [str(window.ui.dsb_vertY.value())] + args += [str(window.ui.dsb_vertZ.value())] + args += [str(window.ui.dsb_tolerance.value())] + f= tempfile.NamedTemporaryFile(delete=False) + fname = f.name + p = subprocess.Popen(args, stdout=f, stderr=f) + err = p.wait() + f.close() + if err==0: + os.remove(fname) + else: + f = open(fname, 'r') + m = f.read() + msgBox = QMessageBox() + msgBox.setText("Parameters are not OK") + msgBox.setInformativeText("Do you want to retry ?") + msgBox.setDetailedText(m) + msgBox.setStandardButtons(QMessageBox.Retry | QMessageBox.Cancel) + msgBox.setDefaultButton(QMessageBox.Retry) + ret = msgBox.exec_() + if ret == QMessageBox.Retry: + retry = True + pass + pass + pass + pass + +# register the function in the plugin manager +salome_pluginsmanager.AddFunction('MeshCut', 'Cut a tetrahedron mesh by a plane', MeshCut) +