-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
438 lines (373 loc) · 22.2 KB
/
ui.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
import os, sys
import multiprocessing as mp
from visualize_func import *
from read_evac import *
#import matplotlib.pyplot as plt
#from data_func.py import *
try:
import matplotlib.pyplot as plt
except:
print("Warning: matplotlib cannot be imported. Unable to plot figures!")
if sys.version_info[0] == 2:
raw_input("Please check!")
else:
input("please check!")
'''
# Version Check
if sys.version_info[0] == 3: # Python 3
from tkinter import *
from tkinter.ttk import Notebook
import tkinter.filedialog as tkf
else:
# Python 2
from Tkinter import *
from ttk import Notebook
import tkFileDialog as tkf
'''
if sys.version_info[0] == 3: # Python 3
from tkinter import *
#from tkinter import ttk
from tkinter.ttk import Notebook
from tkinter.ttk import Treeview
from tkinter.ttk import Button
import tkinter.filedialog as tkf
import tkinter.messagebox as msg
else:
# Python 2
from Tkinter import *
from ttk import Notebook
from ttk import Treeview
from ttk import Entry
import tkFileDialog as tkf
import tkMessageBox as msg
class GUI(object):
def __init__(self, FN_FDS=None, FN_EVAC=None, FN_EVACtxt=None):
#self.FN_Info = ['FDS', 'EVAC'] #, 'Doors']
#self.FN=[None, None] #, None]
#self.FN[0]=FN_FDS
#self.FN[1]=FN_EVAC
self.fname_FDS=FN_FDS
self.fname_EVAC=FN_EVAC
self.fname_EVACtxt=FN_EVACtxt
self.FNTemp=os.getcwd() +'/log.txt'
self.openfn=None
self.opendir=None
self.window = Tk()
self.window.title('evac prt5 tool')
self.window.geometry('960x390')
self.notebook = Notebook(self.window)
self.notebook.pack(side=TOP, padx=2, pady=2)
# added "self.rootWindow" by Hiroki Sayama 10/09/2018
#self.frameRun = Frame(self.window)
#self.frameSettings = Frame(self.window)
#self.frameParameters = Frame(self.window)
#self.frameInformation = Frame(self.window)
# --------------------------------------------
# frameInformation
# --------------------------------------------
scrollInfo = Scrollbar(self.window)#frameInformation)
self.textInformation = Text(self.window, width=45,height=6,fg='cyan', bg='black',wrap=WORD,font=("Courier",10))
scrollInfo.pack(side=RIGHT, fill=Y)
self.textInformation.pack(side=LEFT,fill=BOTH,expand=YES)
scrollInfo.config(command=self.textInformation.yview)
self.textInformation.config(yscrollcommand=scrollInfo.set)
self.textInformation.insert(END, 'Please select .fds file or prt5 file to read in data or visualize the data!')
#self.notebook.add(self.frameRun,text="Run")
#self.notebook.add(self.frameSettings,text="Settings")
#self.notebook.add(self.frameParameters,text="Parameters")
#self.notebook.add(self.frameInformation,text="Info")
#self.notebook.pack(expand=NO, fill=BOTH, padx=5, pady=5 ,side=TOP)
# self.notebook.grid(row=0, column=0, padx=5, pady=5, sticky='nswe') # commented out by toshi on 2016-06-21(Tue) 18:31:02
self.statusStr = ""
self.statusText = StringVar(self.window, value=self.statusStr) # at this point, statusStr = ""
# added "self.rootWindow" above by Hiroki Sayama 10/09/2018
self.setStatusStr("Simulation not yet started")
self.status = Label(self.window, width=40,height=3, fg='cyan', bg='black', relief=SUNKEN, bd=1, textvariable=self.statusText)
# self.status.grid(row=1,column=0,padx=5,pady=5,sticky='nswe') # commented out by toshi on 2016-06-21(Tue) 18:31:17
self.status.pack(side=TOP, fill=X, padx=5, pady=5, expand=NO)
#self.status = Label(window, width=40,height=3, relief=SUNKEN, bd=1, textvariable=self.statusText)
# self.status.grid(row=1,column=0,padx=5,pady=5,sticky='nswe') # commented out by toshi on 2016-06-21(Tue) 18:31:17
#self.status.pack(side=TOP, fill=X, padx=5, pady=5, expand=NO)
#from Tkinter.tkFileDialog import askopenfilename
#fname = tkFileDialog.askopenfilename(filetypes=(("Template files", "*.tplate"), ("HTML files", "*.html;*.htm"), ("All files", "*.*") ))
#def quit_botton(event):
# --------------------------------------------
# frameRun
# --------------------------------------------
self.lb_guide = Label(self.window, text = "Please select the input files.")
self.lb_guide.pack()
self.lb0 = Label(self.window,text = "Optional: The FDS input file selected: "+str(self.fname_FDS)+"\n")
self.lb0.pack()
self.lb1 = Label(self.window,text = "The EVAC data file selected: "+str(self.fname_EVAC)+"\n")
self.lb1.pack()
#self.lb2 = Label(self.window,,text = "The exit data file selected: "+str(FN[2])+"\n")
#self.lb2.pack()
self.buttonSelectFDS =Button(self.window, text='Optional: choose fds input file', width=38, command=self.selectFDSFile)
self.buttonSelectFDS.pack()
self.showHelp(self.buttonSelectFDS, "Only for FDS+Evac: Select FDS input file!")
self.buttonBinParser =Button(self.window, text='Parser for binary data file', width=38, command=self.parseEvacFile)
self.buttonBinParser.pack()
self.showHelp(self.buttonBinParser, "Indicate if the binary data file is \n for CrowdEgress or FDS+Evac!")
#Button(window, text='choose csv file for door data', command=lambda: selectFile(2)).pack()
#if CheckVar1.get():
# buttonSelectFDS.configure(state=DISABLED)
#TestV=CheckVar1.get()
self.buttonRead = Button(self.window, text='Write binary data into txt file', width=38, command=self.readData)
self.buttonRead.pack()
self.showHelp(self.buttonRead, "Write binary Data into a text file! \n This action may take some time, \n depending on the size of data file!")
self.buttonStart = Button(self.window, text='Visualize binary data in Pygame', width=38, command=self.startSim)
self.buttonStart.pack()
self.showHelp(self.buttonStart, "Visualize a binary data file \n for either CrowdEgress or FDS+Evac!")
#buttonStart.place(x=5,y=220)
#print(self.fname_FDS, self.fname_EVAC)
self.buttonPlotDoorProb = Button(self.window, text='plot exit selection probability data', width=38, command=self.plotExitProb)
self.buttonPlotDoorProb.pack()
self.showHelp(self.buttonPlotDoorProb, "Select an output text file of CrowdEgress \n Plot exit selection probability from data selected!")
#buttonStart.place(x=5,y=220)
#print(self.fname_FDS, self.fname_EVAC)
self.buttonPlotTpre =Button(self.window, text='plot pre-movement time data', width=38, command=self.plotTpre)
self.buttonPlotTpre.pack()
self.showHelp(self.buttonPlotTpre, "Select an output text file of CrowdEgress \n Plot pre-movement time from data selected!")
#Button(window, text='choose csv file for door data', command=lambda: selectFile(2)).pack()
if os.path.exists(self.FNTemp) and self.fname_FDS is None and self.fname_EVAC is None and self.fname_EVACtxt is None:
#if self.FNTemp is not None:
for line in open(self.FNTemp, "r"):
#if re.match('FN_FDS', line):
# temp = line.split('=')
# self.fname_FDS = temp[1].strip()
# self.lb0.config(text = "The FDS data file selected in the last run.\n")
if re.match('FN_EVAC', line):
temp = line.split('=')
self.fname_EVAC = temp[1].strip()
#self.lb1.config(text = "The input prt5 data file selected in the last run\n")
if re.match('FN_EVACtxt', line):
temp = line.split('=')
self.fname_EVACtxt = temp[1].strip()
#self.lb1.config(text = "The input txt data file selected in the last run\n")
self.textInformation.insert(END, '\n'+'FDS Input File Selected in the last run: '+str(self.fname_FDS)+'\n')
self.textInformation.insert(END, '\n'+'EVAC prt5 Data Selected in the last run: '+str(self.fname_EVAC)+'\n')
self.textInformation.insert(END, '\n'+'EVAC txt file Selected in the last run: '+str(self.fname_EVACtxt)+'\n')
def start(self):
self.window.mainloop()
def quitGUI(self):
#pylab.close('all')
self.window.quit()
self.window.destroy()
def setStatusStr(self,newStatus):
self.statusStr = newStatus
self.statusText.set(self.statusStr)
def showHelp(self, widget, text):
def setText(self):
self.statusText.set(text)
self.status.configure(foreground='cyan')
def showHelpLeave(self):
self.statusText.set(self.statusStr)
self.status.configure(foreground='cyan')
widget.bind("<Enter>", lambda e : setText(self))
widget.bind("<Leave>", lambda e : showHelpLeave(self))
def selectFDSFile(self):
self.fname_FDS = tkf.askopenfilename(filetypes=(("All files", "*.*"), ("fds files", "*.fds")), initialdir=self.opendir)
#self.FN[0]=self.fname_FDS
#temp=re.split(r'/', self.fname_FDS)
self.opendir = os.path.dirname(self.fname_FDS)
temp=self.fname_FDS.split('/')
self.lb0.config(text = "If fds is selected, the compartment geometry is created by fds file. \n"+"The FDS data file selected: "+str(temp[-1])+"\n")
self.textInformation.insert(END, '\n'+'FDS Input File Selected: '+self.fname_FDS+'\n'+'Please note that if users plan to visualize prt5 data file, the compartment geometry is created by fds file as selected. \n However, the program will not check if the prt5 data is exactly generated from the fds file as selected. ')
print('fname_FDS:', self.fname_FDS)
self.setStatusStr("Select FDS Input File.")
if os.path.exists(self.FNTemp) and self.fname_FDS is not None and self.fname_FDS is not '':
f = open(self.FNTemp, "a+")
f.write('FN_FDS='+str(self.fname_FDS)+'\n')
f.write('Working path='+os.getcwd()+'\n')
#f.write('TimeDate='+os.gettime()+'\n')
f.close()
print("write FDS filename in log")
msg.showinfo('Info', 'Please note that fds input file is only used in visualization of prt5 data. \n In other words, if users plan to visualize prt5 data file, the compartment geometry is created by fds file as selected. \n However, the program will not check if the prt5 data is exactly generated from the fds file as selected. \n Thus, please ensure the prt5 data file selected for visualization is produced from this fds input file. ')
def parseEvacFile(self):
self.fname_EVAC = tkf.askopenfilename(filetypes=(("All files", "*.*"), ("prt5 files", "*.prt5")), initialdir=self.opendir)
#self.FN[1]=self.fname_EVAC
self.openfn = os.path.basename(self.fname_EVAC)
self.opendir = os.path.dirname(self.fname_EVAC)
self.lb1.config(text = "The input binary data file selected: "+ self.openfn +"\n")
self.textInformation.insert(END, '\n'+'EVAC Binary Data Selected: '+self.fname_EVAC+'\n')
print('fname_EVAC', self.fname_EVAC)
temp = self.openfn.split('.')
print(temp)
suffix = str(temp[-1].strip())
self.setStatusStr("Select Evac Binary Data File.")
if os.path.exists(self.FNTemp) and self.fname_EVAC is not None and self.fname_EVAC is not '':
#self.opendir = os.getcwd()
f = open(self.FNTemp, "a+")
f.write('FN_EVAC='+str(self.fname_EVAC)+'\n')
f.write('Working path='+ self.opendir + '\n') #os.getcwd()+'\n')
f.close()
print("Write EVAC filename in log")
if suffix == 'bin':
msg.showinfo("CrowdEgress data file selected", "CrowdEgress binary data file selected. \n Users may write the binary data into a text file or directly visualize the data file \n" +self.opendir + '\n' + self.openfn)
elif suffix == 'prt5':
msg.showinfo("FDS+Evac data file selected", "FDS+Evac binary data file selected. \n Users may write the binary data into a text file or directly visualize the data file \n" +self.opendir + '\n' + self.openfn)
else:
msg.showinfo("No proper binary data file selected", "No binary data file selected. Please select an binary data file. \n Data file suffix: .bin or .prt5")
else:
msg.showinfo("No file selected", "No file selected. Please select an binary data file.")
def readData(self):
self.fname_EVAC = tkf.askopenfilename(filetypes=(("All files", "*.*"), ("prt5 files", "*.prt5")), initialdir=self.opendir)
#self.FN[1]=self.fname_EVAC
self.openfn = os.path.basename(self.fname_EVAC)
self.opendir = os.path.dirname(self.fname_EVAC)
self.lb1.config(text = "The input binary data file selected: "+ self.openfn +"\n")
self.textInformation.insert(END, '\n'+'EVAC Binary Data Selected: '+self.fname_EVAC+'\n')
print('fname_EVAC', self.fname_EVAC)
temp = self.openfn.split('.')
print(temp)
suffix = str(temp[-1].strip())
self.setStatusStr("Select Evac Binary Data File.")
#self.setStatusStr("Read Prt5 Data! This action may take a few seconds or minutes, depending on the size of data file!")
if os.path.exists(self.fname_EVAC) and self.fname_EVAC is not None and self.fname_EVAC is not '':
print('load binary data file and extract evac-related information', self.fname_EVAC)
#self.textInformation.insert(END, "\nRead Prt5 Data! This action may take a few seconds or minutes, depending on the size of data file!")
readPRTfile(self.fname_EVAC, wrtxt=True)
self.textInformation.insert(END, "\nRead Binary Data Successfully!\n")
msg.showinfo("Write Binary Data File into Text File", "Read Binary Data Successfully!")
return
if os.path.exists(self.fname_FDS):
print ('load .fds file and extract evac-related information', self.fname_FDS)
CHID=readCHID(self.fname_FDS)
print(CHID)
# The following lines are effective only for the latest version of fds as well as fds6_dump205.exe
# If you are using the old version of fds, please modify the code to read evac prt5 file.
#self.textInformation.insert(END, "\nRead Prt5 Data! This action may take a few seconds or minutes, depending on the size of data file!")
temp=os.path.split(self.fname_FDS)
self.fname_EVAC=os.path.join(temp[0],CHID+'_evac_0001.prt5')
readPRTfile(self.fname_EVAC, wrtxt=True)
self.textInformation.insert(END, "\nRead Prt5 Data Successfully!\n")
msg.showinfo("Write Prt5 Data File into Text File", "Read Prt5 Data Successfully!")
return
print('No input files found! Please select the data file or fds input file!')
self.setStatusStr('No input files found! Please select the data file or fds input file!')
return
def startSim(self):
#myTest = simulation()
#myTest.select_file(self.FN[1], None, "non-gui")
#myTest.read_data()
#sunpro1 = mp.Process(target=show_simu(myTest))
#sunpro1.start()
#sunpro1.join()
#show_geom(myTest)
#myTest.show_simulation()
#myTest.quit()
#self.setStatusStr("Visualize Prt5 Data by Pygame!")
#self.textInformation.insert(END, "\nVisualize Prt5 Data by Pygame!\n")
self.fname_EVAC = tkf.askopenfilename(filetypes=(("All files", "*.*"), ("prt5 files", "*.prt5"), ("binary files", "*.bin")), initialdir=self.opendir)
self.openfn = os.path.basename(self.fname_EVAC)
self.opendir = os.path.dirname(self.fname_EVAC)
temp=self.openfn.split('.')
fnsuffix=temp[-1]
self.lb1.config(text = "The input binary data file selected: "+str(temp[-1])+"\n")
self.textInformation.insert(END, '\n'+'EVAC prt5/binary Data Selected: '+self.fname_EVAC+'\n')
print('fname_EVAC', self.fname_EVAC)
self.setStatusStr("Select prt5/binary Data File.")
if os.path.exists(self.FNTemp) and self.fname_EVAC is not None and self.fname_EVAC is not '':
f = open(self.FNTemp, "a+")
f.write('FN_EVAC='+str(self.fname_EVAC)+'\n')
f.write('Working path='+os.getcwd()+'\n')
f.close()
print("Write EVAC filename in log")
'''
if self.fname_FDS is not None and os.path.exists(self.fname_FDS):
print ('load .fds file and extract evac-related information', self.fname_FDS)
CHID=readCHID(self.fname_FDS)
print(CHID)
# The following lines are effective for the latest version of fds as well as previous version of fds.
# If you are using the old version of fds, please select evac prt5 file.
if os.path.exists(self.fname_EVAC):
sunpro1 = mp.Process(target=visualizeFdsEvac(self.fname_EVAC, self.fname_FDS))
sunpro1.start()
sunpro1.join()
else:
temp=os.path.split(self.fname_FDS)
self.fname_EVAC=os.path.join(temp[0],CHID+'_evac_0001.prt5')
sunpro1 = mp.Process(target=visualizeFdsEvac(self.fname_EVAC, self.fname_FDS))
sunpro1.start()
sunpro1.join()
#visualizeFdsEvac(CHID+'_evac_0001.npz', self.FN[0])
else: # No file selected for fds
print("No file selected for fds input file")
'''
#if os.path.exists(self.fname_EVAC):
if fnsuffix=='prt5':
if self.fname_FDS is not None and os.path.exists(self.fname_FDS):
visualizeFdsEvac(self.fname_EVAC, self.fname_FDS)
else:
print("No file selected for fds input file.")
visualizeFdsEvac(self.fname_EVAC, None)
elif fnsuffix=='bin':
visualizeAgent(self.fname_EVAC, None)
#sunpro1 = mp.Process(target=visualizeAgent(self.fname_EVAC, None))
#sunpro1.start()
#sunpro1.join()
else:
print ("Input file %s is neither prt5 data nor binary data!" %self.fname_EVAC)
#exit(-1)
def plotExitProb(self):
#myTest = simulation()
#myTest.select_file(self.FN[1], None, "non-gui")
#myTest.read_data()
#sunpro1 = mp.Process(target=show_simu(myTest))
#sunpro1.start()
#sunpro1.join()
#show_geom(myTest)
#myTest.show_simulation()
#myTest.quit()
#self.setStatusStr("Visualize Prt5 Data by Pygame!")
#self.textInformation.insert(END, "\nVisualize Prt5 Data by Pygame!\n")
self.fname_EVACtxt = tkf.askopenfilename(filetypes=(("All files", "*.*"), ("txt files", "*.txt")), initialdir=self.opendir)
self.opendir = os.path.dirname(self.fname_EVACtxt)
temp=self.fname_EVACtxt.split('/')
self.lb1.config(text = "The output exit probability data file selected: "+str(temp[-1])+"\n")
self.textInformation.insert(END, '\n'+'EVAC exit probability Data Selected: '+self.fname_EVACtxt+'\n')
print('fname_EVACtxt', self.fname_EVACtxt)
self.setStatusStr("Select Evac output txt data File.")
if os.path.exists(self.FNTemp) and self.fname_EVACtxt is not None:
f = open(self.FNTemp, "a+")
f.write('FN_EVACtxt='+str(self.fname_EVACtxt)+'\n')
f.write('Working path='+os.getcwd()+'\n')
f.close()
print("Write EVACtxt filename in log")
if os.path.exists(self.fname_EVACtxt):
plotDoorProb(self.fname_EVACtxt, doorIndex=2)
#sunpro1 = mp.Process(target=plt.plot(doorProb))
#sunpro1.start()
#sunpro1.join()
else:
print ("Input file %s does not exist!" %self.fname_EVACtxt)
#exit(-1)
def plotTpreTemp(self):
self.fname_EVACtxt = tkf.askopenfilename(filetypes=(("All files", "*.*"), ("bin files", "*.bin")), initialdir=self.opendir)
temp=self.fname_EVACtxt.split('/')
self.lb1.config(text = "The output exit probability data file selected: "+str(temp[-1])+"\n")
self.textInformation.insert(END, '\n'+'EVAC exit probability Data Selected: '+self.fname_EVACtxt+'\n')
print('fname_EVACtxt', self.fname_EVACtxt)
self.setStatusStr("Select Evac output txt data File.")
if os.path.exists(self.FNTemp) and self.fname_EVACtxt is not None:
f = open(self.FNTemp, "a+")
f.write('FN_EVACtxt='+str(self.fname_EVACtxt)+'\n')
f.write('Working path='+os.getcwd()+'\n')
f.close()
print("Write EVACtxt filename in log")
def plotTpre(self):
#tempdir=os.path.dirname(self.fname_EVAC)
#print(tempdir)
self.fname_TpreBinFile = tkf.askopenfilename(filetypes=(("bin files", "*.bin"),("All files", "*.*")), initialdir=self.opendir)
self.opendir = os.path.dirname(self.fname_TpreBinFile)
temp=re.split(r'/', self.fname_TpreBinFile)
#temp=self.fname_OutTXT.split('/')
#self.lb_outbin.config(text = "The output bin file selected: "+str(temp[-1])+"\n")
#self.textInformation.insert(END, 'fname_FDS: '+self.fname_FDS)
print('fname_TpreBinFile:', self.fname_TpreBinFile)
self.setStatusStr("Simulation not yet started!")
self.textInformation.insert(END, '\n'+'Output Tpre Binary File Selected (Pre-Evacuation Time): '+self.fname_TpreBinFile+'\n')
visualizeTpre(self.fname_TpreBinFile)
if __name__ == '__main__':
myGUI=GUI()
myGUI.start()