Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 import salome_pluginsmanager
00024
00025 def MeshCut(context):
00026
00027 study = context.study
00028 studyId = context.studyId
00029 sg = context.sg
00030
00031 import os
00032 import subprocess
00033 import tempfile
00034 from PyQt4 import QtGui
00035 from PyQt4.QtGui import QFileDialog
00036 from PyQt4.QtGui import QMessageBox
00037 from MeshCutDialog import Ui_Dialog
00038
00039 class CutDialog(QtGui.QDialog):
00040
00041 def __init__(self):
00042 QtGui.QDialog.__init__(self)
00043
00044 self.ui = Ui_Dialog()
00045 self.ui.setupUi(self)
00046
00047 self.connect(self.ui.pb_origMeshFile, QtCore.SIGNAL("clicked()"),
00048 self.setInputFile)
00049 self.connect(self.ui.pb_cutMeshFile, QtCore.SIGNAL("clicked()"),
00050 self.setOutputFile)
00051 self.connect(self.ui.pb_help, QtCore.SIGNAL("clicked()"),
00052 self.helpMessage)
00053 pass
00054
00055 def setInputFile(self):
00056 fd = QFileDialog(self, "select an existing Med file", self.ui.le_origMeshFile.text(), "MED-Files (*.med);;All Files (*)")
00057 if fd.exec_():
00058 infile = fd.selectedFiles()[0]
00059 self.ui.le_origMeshFile.setText(infile)
00060 insplit = os.path.splitext(infile.toLocal8Bit().data())
00061 outfile = insplit[0] + '_cut' + insplit[1]
00062 self.ui.le_cutMeshFile.setText(outfile)
00063 pass
00064
00065 def setOutputFile(self):
00066 fd = QFileDialog(self, "select an output Med file", self.ui.le_cutMeshFile.text(), "MED-Files (*.med);;All Files (*)")
00067 if fd.exec_():
00068 self.ui.le_cutMeshFile.setText(fd.selectedFiles()[0])
00069 pass
00070
00071 def helpMessage(self):
00072 QMessageBox.about(None, "About MeshCut",
00073 """
00074 Cut a tetrahedron mesh by a plane
00075 ---------------------------------
00076
00077 MeshCut allows to cut a mesh constituted of linear
00078 tetrahedrons by a plane. The tetrahedrons intersected
00079 by the plane are cut and replaced by elements of
00080 various types (tetrahedron, pyramid, pentahedron).
00081
00082 MeshCut is a standalone program, reading and
00083 producing med files. The cutting plane is defined
00084 by a vector normal to the plane and a vertex
00085 belonging to the plane.
00086
00087 Vertices of a tetrahedron are considered as belonging to
00088 the cut plane if their distance to the plane is inferior
00089 to L*T where L is the mean edge size of the tetrahedron
00090 and T the tolerance.
00091 """)
00092 pass
00093 pass
00094
00095
00096
00097 window = CutDialog()
00098 window.ui.dsb_tolerance.setValue(0.01)
00099 retry = True
00100 while(retry):
00101 retry = False
00102 window.exec_()
00103 result = window.result()
00104 if result:
00105
00106 args = ['MeshCut']
00107 args += [window.ui.le_origMeshFile.text().toLocal8Bit().data()]
00108 args += [window.ui.le_cutMeshFile.text().toLocal8Bit().data()]
00109 args += [window.ui.le_outMeshName.text().toLocal8Bit().data()]
00110 args += [window.ui.le_groupAbove.text().toLocal8Bit().data()]
00111 args += [window.ui.le_groupBelow.text().toLocal8Bit().data()]
00112 args += [str(window.ui.dsb_normX.value())]
00113 args += [str(window.ui.dsb_normY.value())]
00114 args += [str(window.ui.dsb_normZ.value())]
00115 args += [str(window.ui.dsb_vertX.value())]
00116 args += [str(window.ui.dsb_vertY.value())]
00117 args += [str(window.ui.dsb_vertZ.value())]
00118 args += [str(window.ui.dsb_tolerance.value())]
00119 f= tempfile.NamedTemporaryFile(delete=False)
00120 fname = f.name
00121 p = subprocess.Popen(args, stdout=f, stderr=f)
00122 err = p.wait()
00123 f.close()
00124 if err==0:
00125 os.remove(fname)
00126 else:
00127 f = open(fname, 'r')
00128 m = f.read()
00129 msgBox = QMessageBox()
00130 msgBox.setText("Parameters are not OK")
00131 msgBox.setInformativeText("Do you want to retry ?")
00132 msgBox.setDetailedText(m)
00133 msgBox.setStandardButtons(QMessageBox.Retry | QMessageBox.Cancel)
00134 msgBox.setDefaultButton(QMessageBox.Retry)
00135 ret = msgBox.exec_()
00136 if ret == QMessageBox.Retry:
00137 retry = True
00138 pass
00139 pass
00140 pass
00141 pass
00142
00143
00144 salome_pluginsmanager.AddFunction('MeshCut', 'Cut a tetrahedron mesh by a plane', MeshCut)
00145