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