1 | from enthought.traits.api import Int, String |
---|
2 | from Scientific.IO.NetCDF import NetCDFFile |
---|
3 | from Tkinter import Label, Scale, W, E, HORIZONTAL |
---|
4 | from visualiser import Visualiser |
---|
5 | |
---|
6 | class SWWVisualiser(Visualiser): |
---|
7 | '''A Visualiser that views SWW files. The source for this |
---|
8 | visualiser is a string containing the sww file name. |
---|
9 | ''' |
---|
10 | source = String |
---|
11 | frameDelay = Int(100) |
---|
12 | frameStep = Int(1) |
---|
13 | |
---|
14 | def __init__(self, *args, **kwargs): |
---|
15 | Visualiser.__init__(self, *args, **kwargs) |
---|
16 | |
---|
17 | fin = NetCDFFile(self.source, 'r') |
---|
18 | self.frame = 0 |
---|
19 | self.maxFrame = fin.variables['time'].shape[0] - 1 |
---|
20 | self.paused = False |
---|
21 | self.heightFeatureCache = [] |
---|
22 | for i in range(self.maxFrame + 1): # Zero indexed |
---|
23 | self.heightFeatureCache.append({}) |
---|
24 | |
---|
25 | def setup_grid(self): |
---|
26 | fin = NetCDFFile(self.source, 'r') |
---|
27 | N_tri = fin.variables['volumes'].shape[0] |
---|
28 | for v in range(N_tri): |
---|
29 | self.vtk_cells.InsertNextCell(3) |
---|
30 | for i in range(3): |
---|
31 | self.vtk_cells.InsertCellPoint(fin.variables['volumes'][v][i]) |
---|
32 | fin.close() |
---|
33 | |
---|
34 | def setup_gui(self): |
---|
35 | Visualiser.setup_gui(self) |
---|
36 | |
---|
37 | Label(self.tk_customControlFrame, text='Frame').grid(row=0, column=0, sticky=W+E) |
---|
38 | self.tk_frame = Scale(self.tk_customControlFrame, from_=0, to=self.maxFrame, orient=HORIZONTAL) |
---|
39 | self.tk_frame.grid(row=0, column=1, sticky=W+E) |
---|
40 | Label(self.tk_customControlFrame, text='Step').grid(row=0, column=2, sticky=W+E) |
---|
41 | self.tk_frameStep = Scale(self.tk_customControlFrame, from_=0, to=self.maxFrame, orient=HORIZONTAL) |
---|
42 | self.tk_frameStep.grid(row=0, column=3, sticky=W+E) |
---|
43 | |
---|