forked from psicofil/SalomeToCalculix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SalometoCalculix.py
167 lines (137 loc) · 5.68 KB
/
SalometoCalculix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# -*- coding: utf-8 -*-
# Mesh with Salome and export to Calculix
# Author: Gomez Lucio
# Version: 0.1 (27/04/2016)
#/****************************************************************************
# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
# IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE
# AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
#
# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
# WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
# LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
#
# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION, INC,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#*****************************************************************************/
# CONFIGURATION - EDIT THE FOLLOWING LINE TO MATCH YOUR UNICAL BINARY
unical_bin = '/home/user/unical/unical' # example for Linux
#unical_bin = "C:\\Daten\\unical\\unical.exe" # example for Windows
# Configuration the optional option to poen results in cgx
cgx_bin = '/home/user/Calculix/cgx_2.9 ' # CGX binary exapmle for Linux
# END CONFIGURATION
import salome
import subprocess
import sys
import tempfile
import SMESH, SALOMEDS
from PyQt4 import QtGui,QtCore
from salome.smesh import smeshBuilder
from platform import system
def findSelectedMeshes():
meshes=list()
smesh = smeshBuilder.New(salome.myStudy)
selected=salome.sg.getSelected(0)
try:
selobjID=salome.myStudy.FindObjectID(selected)
selobj=selobjID.GetObject()
mName=selobjID.GetName().replace(" ","_")
mesh=smesh.Mesh(selobj)
meshes.append(mesh)
except:
QtGui.QMessageBox.critical(None,'Error',"You have to select a mesh object and then run this script.",QtGui.QMessageBox.Abort)
return None
else:
return meshes
def proceed():
meshes=findSelectedMeshes()
try:
if not meshes == None:
for mesh in meshes:
if not mesh == None:
temp_file = tempfile.mkstemp(suffix='.unv')[1]
mesh.ExportUNV(temp_file)
file_inp = le_inp_file.text()
command = unical_bin + ' ' + temp_file + ' ' + file_inp
print command
output = subprocess.check_output([command, '-1'], shell=True, stderr=subprocess.STDOUT,)
QtGui.QMessageBox.information(None,'successful result','The mesh has been exported successfully in ' + file_inp,QtGui.QMessageBox.Ok)
except:
QtGui.QMessageBox.critical(None,'Error',"Unexpected error in Salome to Calculix Script: {}".format(sys.exc_info()[0]),QtGui.QMessageBox.Abort)
if rb_cgx.isChecked():
open_CGX()
if rb_delet_e_f.isChecked():
delete_edges_and_faces_mesh()
#hide()
def hide():
dialog.hide()
def meshFile():
PageName = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.activeWindow(),'Select inp or msh file result ',"Result.inp",filter ="inp (*.inp *.);;msh (*.msh *.)")
le_inp_file.setText(str(PageName))
def open_CGX():
command_cgx = cgx_bin + '-c ' + le_inp_file.text()
try:
process = QtCore.QProcess()
process.startDetached('xterm -e ' + command_cgx)
except:
QtGui.QMessageBox.critical(None,'Error',"Unexpected error in CGX process to open the result",QtGui.QMessageBox.Abort)
def name_mesh():
meshes=findSelectedMeshes()
if not meshes == None:
for mesh in meshes:
if not mesh == None:
mName=mesh.GetName()
le_selectMesh.setText(mName)
def delete_edges_and_faces_mesh():
meshes=findSelectedMeshes()
if not meshes == None:
for mesh in meshes:
if not mesh == None:
Group_1 = mesh.CreateEmptyGroup(SMESH.FACE, 'Group_1' )
nbAdd = Group_1.AddFrom( mesh.GetMesh() )
Group_2 = mesh.CreateEmptyGroup( SMESH.EDGE, 'Group_2' )
nbAdd = Group_2.AddFrom( mesh.GetMesh() )
mesh.RemoveGroupWithContents(Group_1)
mesh.RemoveGroupWithContents(Group_2)
if salome.sg.hasDesktop():
salome.sg.updateObjBrowser(1)
### GUI APLIACTION ###
dialog = QtGui.QDialog()
dialog.resize(600,200)
dialog.setWindowTitle("Salome to Calculix")
layout = QtGui.QGridLayout(dialog)
l_inp_file = QtGui.QLabel("inp file result:")
le_inp_file = QtGui.QLineEdit()
pb_inp_file = QtGui.QPushButton()
pb_inp_file.setText("file result")
l_selectMesh = QtGui.QLabel("Selected Mesh:")
le_selectMesh = QtGui.QLineEdit()
le_selectMesh.setEnabled(False)
pb_sel_mesh = QtGui.QPushButton()
pb_sel_mesh.setText("Select Mesh")
name_mesh()
okbox = QtGui.QDialogButtonBox(dialog)
okbox.setOrientation(QtCore.Qt.Horizontal)
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
l_options = QtGui.QLabel("Aditional options:")
rb_cgx = QtGui.QCheckBox("Open the result with CGX at the end")
rb_delet_e_f = QtGui.QCheckBox("Delete delete edges and faces in selected mesh")
rb_cgx.setChecked(False)
layout.addWidget(l_selectMesh,1,0)
layout.addWidget(le_selectMesh,2,0)
layout.addWidget(pb_sel_mesh,2,1)
layout.addWidget(l_inp_file,3,0)
layout.addWidget(le_inp_file,4,0)
layout.addWidget(pb_inp_file,4,1)
layout.addWidget(l_options,5,0)
layout.addWidget(rb_cgx,6,0)
layout.addWidget(rb_delet_e_f,7,0)
layout.addWidget(okbox,8,0)
pb_sel_mesh.clicked.connect(name_mesh)
pb_inp_file.clicked.connect(meshFile)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), proceed)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), hide)
QtCore.QMetaObject.connectSlotsByName(dialog)
dialog.show()