forked from OpenRadioss/Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenRadioss_gui.py
242 lines (205 loc) · 10.1 KB
/
OpenRadioss_gui.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# Copyright 1986-2025 Altair Engineering Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import os
import json
import platform
import tkinter as tk
if platform.system() == 'Windows':
import ctypes
myappid = 'openradioss.jobgui.1.6.0'
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('openradioss.jobgui.1.6.0')
#import time
import subprocess
from tkinter import filedialog
from tkinter import messagebox
from job_holder import JobHolder
try:
from vortex_radioss.animtod3plot.Anim_to_D3plot import readAndConvert
vd3penabled = True
except ImportError:
# If VortexRadioss Module not present disable d3plot options
vd3penabled = False
import gui_def
class openradioss_gui:
def __init__(self,debug,FullName):
# Global Variables
self.debug=debug
self.current_platform=platform.system()
self.job_holder = JobHolder(self.debug)
self.Window = gui_def.window(vd3penabled)
if FullName=='':
self.job_file_entry=self.Window.file('Job file (.rad, .key, or .k, or .inp)', self.select_file, self.Window.icon_folder)
else:
self.job_file_entry=self.Window.file(FullName, self.select_file, self.Window.icon_folder)
# Create checkboxes
self.nt_entry = self.Window.thread_mpi('-nt', 5,0,2)
self.np_entry = self.Window.thread_mpi('-np', 5,5,2)
self.single_status = self.Window.checkbox1('Single Precision ',5,5)
self.vtk_status = self.Window.checkbox1('Anim - vtk',5,2)
self.starter_status = self.Window.checkbox2('Run Starter Only',5,2)
if vd3penabled:
self.d3plot_status = self.Window.checkbox2('Anim - d3plot',5,2)
self.csv_status = self.Window.checkbox3('TH - csv',0,0)
else:
self.csv_status = self.Window.checkbox2('TH - csv ',5,2)
# Create buttons
self.Window.button('Add Job', self.add_job, (0, 5))
self.Window.button('Show Queue', self.show_queue, 6)
self.Window.button('Clear Queue', self.clear_queue, 6)
self.Window.button('Close', self.close_window, (5, 0))
# Create a menu bar
self.Window.menubar('Info')
self.load_config()
self.Window.root.protocol("WM_DELETE_WINDOW", self.close_window)
self.Window.root.after(1000, self.run_job)
self.Window.root.mainloop()
#-------------------------------- Functions #--------------------------------
# Close the app when the close button is clicked or the window is closed
# no job is running or the user confirms the close action
#----------------------------------------------------------------------------
def close_window(self):
if self.job_holder.is_empty() or messagebox.askokcancel('Close Window', 'Job is running. Close?'):
self.Window.close()
quit()
#-------------------------------- Functions #--------------------------------
# Queues the job when the add job button is clicked
#----------------------------------------------------------------------------
def add_job(self):
self.check_install()
if self.job_file_entry.is_placeholder_active() or not os.path.exists(self.job_file_entry.get_user_input()):
messagebox.showerror('', 'Select job.')
return
# Get Values based on Checkbox Statuses
file = self.job_file_entry.get_user_input()
nt = self.nt_entry.get_user_input('1')
np = self.np_entry.get_user_input('1')
precision = 'sp' if self.single_status.get() else 'dp'
anim_to_vtk = 'yes' if self.vtk_status.get() else 'no'
th_to_csv = 'yes' if self.csv_status.get() else 'no'
starter_only = 'yes' if self.starter_status.get() else 'no'
if vd3penabled:
d3plot = 'yes' if self.d3plot_status.get() else 'no'
else:
d3plot = 'no'
allcommand = [os.path.normpath(file), nt, np, precision, anim_to_vtk, th_to_csv, starter_only, d3plot]
# Add Job in Queue
if messagebox.askokcancel('Add job', 'Add job?'):
self.save_config()
if self.debug==1:print("Allcommand: ",allcommand)
self.job_holder.push_job(allcommand)
def show_queue(self):
self.job_holder.show_queue()
def clear_queue(self):
self.job_holder.clear_queue()
def run_job(self):
self.job_holder.run_job()
self.Window.root.after(1000, self.run_job)
return
def select_file(self):
file_path = filedialog.askopenfilename(
title='Select input file',
filetypes=[('Radioss file', '*.rad *.key *.k *.inp' )]
)
self.job_file_entry.on_focus_gain()
self.job_file_entry.delete(0, tk.END)
self.job_file_entry.insert(0, file_path)
def check_mpi_path(self):
mpi_path_file = "path_to_intel-mpi.txt"
if self.np_entry.get_user_input() > '1' and not os.path.exists(mpi_path_file):
messagebox.showinfo('', 'Running MPI requires intel mpi installation. Please browse to an intel-mpi location. Or select np = 1')
directory_path = filedialog.askdirectory(
title='Select intel-mpi directory'
)
if directory_path:
with open(mpi_path_file, 'w') as file:
file.write('"' + directory_path + '"')
else:
# MPI path file exists or np <= 1, continue with the script
pass
def check_sp_exes(self):
if platform.system() == 'Windows':
sp_executable = "../exec/starter_win64_sp.exe"
elif platform.system() == 'Linux':
sp_executable = "../exec/starter_linux64_gf_sp"
if self.single_status.get() and not os.path.exists(sp_executable):
messagebox.showinfo('WARNING', 'Single Precision Executables not Installed\n Please Install or submit without sp option checked')
else:
# single precision executables exist continue with script
pass
def check_install(self):
is_installed = "../hm_cfg_files"
if not os.path.exists(is_installed):
messagebox.showinfo('INCORRECT INSTALL LOCATION', 'The guiscripts folder needs to be saved inside\n your OpenRadioss Folder\n (Same Folder Level as exec and hm_cfg_files)')
else:
# installation location correct continue with script
pass
# Create Json Config File & write on disk
def save_config(self):
config={}
config['starter_only'] = self.starter_status.get()
config['vtk'] = self.vtk_status.get()
config['sp'] = self.single_status.get()
config['csv'] = self.csv_status.get()
if vd3penabled:
config['d3plot'] = self.d3plot_status.get()
config['np'] = self.np_entry.get_user_input()
config['nt'] = self.nt_entry.get_user_input()
# Open File & Write Json file
if self.current_platform == 'Windows':
username = os.environ.get('USERNAME')
directory = os.path.join('C:\\Users', username, 'AppData','Local','OpenRadioss_GUI')
else:
home=os.environ.get('HOME')
directory = os.path.join(home,'.OpenRadioss_GUI')
if not os.path.exists(directory):
os.makedirs(directory)
json_file=os.path.join(directory, 'config.json')
with open(json_file, mode='w') as file:
json.dump(config, file, indent=4)
file.close()
def load_config(self):
if self.current_platform == 'Windows':
username = os.environ.get('USERNAME')
directory = os.path.join('C:\\Users', username, 'AppData','Local','OpenRadioss_GUI')
else:
home=os.environ.get('HOME')
directory = os.path.join(home,'.OpenRadioss_GUI')
if not os.path.exists(directory):
os.makedirs(directory)
json_file=os.path.join(directory, 'config.json')
print('Json File:',json_file)
try:
with open(json_file, mode='r') as file:
config_file=json.load(file)
file.close()
self.starter_status.set(config_file['starter_only'])
self.vtk_status.set(config_file['vtk'])
self.single_status.set(config_file['sp'])
self.csv_status.set(config_file['csv'])
if vd3penabled:
self.d3plot_status.set(config_file['d3plot'])
except:
config_file={}
# ===========================================
# Main entry point
# ===========================================
if __name__ == "__main__":
#----------------------------- GUI Elements #--------------------------------
# File Menu
gui= openradioss_gui(0)