1 # if you already have plugins defined in a salome_plugins.py file, add this file at the end.
2 # if not, copy this file as ${HOME}/Plugins/salome_plugins.py or ${APPLI}/Plugins/salome_plugins.py
4 import salome_pluginsmanager
7 # get context study, studyId, salomeGui
9 studyId = context.studyId
15 from PyQt4 import QtGui
16 from PyQt4.QtGui import QFileDialog
17 from PyQt4.QtGui import QMessageBox
18 from MeshCutDialog import Ui_Dialog
20 class CutDialog(QtGui.QDialog):
23 QtGui.QDialog.__init__(self)
24 # Set up the user interface from Designer.
27 # Connect up the buttons.
28 self.connect(self.ui.pb_origMeshFile, QtCore.SIGNAL("clicked()"),
30 self.connect(self.ui.pb_cutMeshFile, QtCore.SIGNAL("clicked()"),
32 self.connect(self.ui.pb_help, QtCore.SIGNAL("clicked()"),
36 def setInputFile(self):
37 fd = QFileDialog(self, "select an existing Med file", self.ui.le_origMeshFile.text(), "MED-Files (*.med);;All Files (*)")
39 infile = fd.selectedFiles()[0]
40 self.ui.le_origMeshFile.setText(infile)
41 insplit = os.path.splitext(infile.toLocal8Bit().data())
42 outfile = insplit[0] + '_cut' + insplit[1]
43 self.ui.le_cutMeshFile.setText(outfile)
46 def setOutputFile(self):
47 fd = QFileDialog(self, "select an output Med file", self.ui.le_cutMeshFile.text(), "MED-Files (*.med);;All Files (*)")
49 self.ui.le_cutMeshFile.setText(fd.selectedFiles()[0])
52 def helpMessage(self):
53 QMessageBox.about(None, "About MeshCut",
55 Cut a tetrahedron mesh by a plane
56 ---------------------------------
58 MeshCut allows to cut a mesh constituted of linear
59 tetrahedrons by a plane. The tetrahedrons intersected
60 by the plane are cut and replaced by elements of
61 various types (tetrahedron, pyramid, pentahedron).
63 MeshCut is a standalone program, reading and
64 producing med files. The cutting plane is defined
65 by a vector normal to the plane and a vertex
66 belonging to the plane.
68 Vertices of a tetrahedron are considered as belonging to
69 the cut plane if their distance to the plane is inferior
70 to L*T where L is the mean edge size of the tetrahedron
79 window.ui.dsb_tolerance.setValue(0.01)
84 result = window.result()
88 args += [window.ui.le_origMeshFile.text().toLocal8Bit().data()]
89 args += [window.ui.le_cutMeshFile.text().toLocal8Bit().data()]
90 args += [window.ui.le_outMeshName.text().toLocal8Bit().data()]
91 args += [window.ui.le_groupAbove.text().toLocal8Bit().data()]
92 args += [window.ui.le_groupBelow.text().toLocal8Bit().data()]
93 args += [str(window.ui.dsb_normX.value())]
94 args += [str(window.ui.dsb_normY.value())]
95 args += [str(window.ui.dsb_normZ.value())]
96 args += [str(window.ui.dsb_vertX.value())]
97 args += [str(window.ui.dsb_vertY.value())]
98 args += [str(window.ui.dsb_vertZ.value())]
99 args += [str(window.ui.dsb_tolerance.value())]
100 f= tempfile.NamedTemporaryFile(delete=False)
102 p = subprocess.Popen(args, stdout=f, stderr=f)
110 msgBox = QMessageBox()
111 msgBox.setText("Parameters are not OK")
112 msgBox.setInformativeText("Do you want to retry ?")
113 msgBox.setDetailedText(m)
114 msgBox.setStandardButtons(QMessageBox.Retry | QMessageBox.Cancel)
115 msgBox.setDefaultButton(QMessageBox.Retry)
117 if ret == QMessageBox.Retry:
124 # register the function in the plugin manager
125 salome_pluginsmanager.AddFunction('MeshCut', 'Cut a tetrahedron mesh by a plane', MeshCut)