Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
584 FredericG 1
#!/usr/bin/env python
2
# -*- coding: iso-8859-15 -*-
3
# generated by wxGlade 0.6.3 on Thu Sep 24 15:46:36 2009
4
 
586 FredericG 5
import sys
606 FredericG 6
import os
584 FredericG 7
import wx
585 FredericG 8
import wx.lib
9
import wx.lib.plot
607 FredericG 10
import ConfigParser
584 FredericG 11
 
585 FredericG 12
# Needs Numeric or numarray or NumPy
13
try:
14
    import numpy.oldnumeric as _Numeric
15
except:
16
    try:
17
        import numarray as _Numeric  #if numarray is used it is renamed Numeric
18
    except:
19
        try:
20
            import Numeric as _Numeric
21
        except:
22
            msg= """
23
            This module requires the Numeric/numarray or NumPy module,
24
            which could not be imported.  It probably is not installed
25
            (it's not part of the standard Python distribution). See the
26
            Numeric Python site (http://numpy.scipy.org) for information on
27
            downloading source or binaries."""
28
            raise ImportError, "Numeric,numarray or NumPy not found. \n" + msg
29
 
584 FredericG 30
# begin wxGlade: extracode
31
# end wxGlade
32
 
33
 
34
 
607 FredericG 35
class SettingsDialog(wx.Dialog):
601 FredericG 36
    def __init__(self, *args, **kwds):
607 FredericG 37
        # begin wxGlade: SettingsDialog.__init__
38
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
39
        wx.Dialog.__init__(self, *args, **kwds)
608 FredericG 40
        self.button_5 = wx.Button(self, wx.ID_CANCEL, "")
41
        self.button_6 = wx.Button(self, wx.ID_OK, "")
601 FredericG 42
 
43
        self.__set_properties()
44
        self.__do_layout()
45
        # end wxGlade
46
 
608 FredericG 47
        # The first argument that is passed to the constructor is the parent
48
        settings = args[0].app.settings
49
        # Add text-boxes for all settings
50
        self.grid_sizer_2.SetRows(len(settings))
51
        for setting in settings.iteritems():
52
            lb = wx.StaticText(self, -1, setting[1].descr, style=wx.ALIGN_RIGHT)
53
            tb = wx.TextCtrl(self, -1, str(setting[1].value))
54
            self.grid_sizer_2.Add(lb, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
55
            self.grid_sizer_2.Add(tb, 0, 0, 0)
56
        self.sizer_5.Fit(self)
57
        self.Layout()
58
 
601 FredericG 59
    def __set_properties(self):
607 FredericG 60
        # begin wxGlade: SettingsDialog.__set_properties
601 FredericG 61
        self.SetTitle("Settings")
62
        # end wxGlade
63
 
64
    def __do_layout(self):
607 FredericG 65
        # begin wxGlade: SettingsDialog.__do_layout
608 FredericG 66
        sizer_5 = wx.BoxSizer(wx.VERTICAL)
67
        grid_sizer_3 = wx.GridSizer(1, 2, 0, 0)
68
        sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
69
        grid_sizer_2 = wx.GridSizer(1, 2, 4, 4)
70
        sizer_5.Add((20, 20), 0, 0, 0)
71
        sizer_6.Add((20, 20), 0, 0, 0)
72
        sizer_6.Add(grid_sizer_2, 0, 0, 0)
73
        sizer_6.Add((20, 20), 0, 0, 0)
74
        sizer_5.Add(sizer_6, 1, wx.EXPAND, 0)
75
        sizer_5.Add((20, 20), 0, 0, 0)
76
        grid_sizer_3.Add(self.button_5, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
77
        grid_sizer_3.Add(self.button_6, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
78
        sizer_5.Add(grid_sizer_3, 0, wx.EXPAND, 0)
79
        sizer_5.Add((20, 20), 0, 0, 0)
80
        self.SetSizer(sizer_5)
81
        sizer_5.Fit(self)
601 FredericG 82
        self.Layout()
83
        # end wxGlade
84
 
608 FredericG 85
        # Store some of the items, we will need them later
86
        self.grid_sizer_2 = grid_sizer_2  
87
        self.sizer_5 = sizer_5
88
 
89
 
90
 
607 FredericG 91
# end of class SettingsDialog
92
 
93
 
94
class SettingsFrame(wx.Frame):
95
    def __init__(self, *args, **kwds):
96
        # content of this block not found: did you rename this class?
97
        pass
98
 
99
    def __set_properties(self):
100
        # content of this block not found: did you rename this class?
101
        pass
102
 
103
    def __do_layout(self):
104
        # content of this block not found: did you rename this class?
105
        pass
106
 
601 FredericG 107
# end of class SettingsFrame
108
 
109
 
587 FredericG 110
class MenuBar(wx.MenuBar):
111
    def __init__(self, *args, **kwds):
112
        # content of this block not found: did you rename this class?
113
        pass
114
 
115
    def __set_properties(self):
116
        # content of this block not found: did you rename this class?
117
        pass
118
 
119
    def __do_layout(self):
120
        # content of this block not found: did you rename this class?
121
        pass
122
 
123
# end of class MenuBar
124
 
125
 
585 FredericG 126
class wxFrame(wx.Panel):
127
    def __init__(self, *args, **kwds):
586 FredericG 128
        # content of this block not found: did you rename this class?
129
        pass
585 FredericG 130
 
131
    def __set_properties(self):
586 FredericG 132
        # content of this block not found: did you rename this class?
585 FredericG 133
        pass
134
 
135
    def __do_layout(self):
586 FredericG 136
        # content of this block not found: did you rename this class?
585 FredericG 137
        pass
138
 
139
# end of class wxFrame
140
 
141
 
142
class MyFrame(wx.Frame):
143
    def __init__(self, *args, **kwds):
144
        # content of this block not found: did you rename this class?
145
        pass
146
 
147
    def __set_properties(self):
148
        # content of this block not found: did you rename this class?
149
        pass
150
 
151
    def __do_layout(self):
152
        # content of this block not found: did you rename this class?
153
        pass
154
 
155
# end of class MyFrame
156
 
157
 
584 FredericG 158
class MainFrame(wx.Frame):
159
    def __init__(self, *args, **kwds):
160
        # begin wxGlade: MainFrame.__init__
161
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
162
        wx.Frame.__init__(self, *args, **kwds)
587 FredericG 163
 
164
        # Menu Bar
165
        self.frame_1_menubar = wx.MenuBar()
166
        wxglade_tmp_menu = wx.Menu()
607 FredericG 167
        wxglade_tmp_menu.Append(101, "Settings", "", wx.ITEM_NORMAL)
168
        wxglade_tmp_menu.Append(150, "Exit", "", wx.ITEM_NORMAL)
587 FredericG 169
        self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
170
        wxglade_tmp_menu = wx.Menu()
607 FredericG 171
        wxglade_tmp_menu.Append(301, "Clear", "", wx.ITEM_NORMAL)
172
        wxglade_tmp_menu.Append(302, "Import", "", wx.ITEM_NORMAL)
587 FredericG 173
        self.frame_1_menubar.Append(wxglade_tmp_menu, "TestSet")
174
        wxglade_tmp_menu = wx.Menu()
175
        self.frame_1_menubar.Append(wxglade_tmp_menu, "MK")
176
        wxglade_tmp_menu = wx.Menu()
177
        self.frame_1_menubar.Append(wxglade_tmp_menu, "Help")
178
        self.SetMenuBar(self.frame_1_menubar)
179
        # Menu Bar end
600 FredericG 180
        self.Description = wx.StaticText(self, -1, "Description")
181
        self.text_ctrl_6 = wx.TextCtrl(self, -1, "Test")
182
        self.label_37 = wx.StaticText(self, -1, "Speed(s)")
183
        self.text_ctrl_9 = wx.TextCtrl(self, -1, "100-200:10")
184
        self.label_35 = wx.StaticText(self, -1, "Motor(s)")
185
        self.text_ctrl_7 = wx.TextCtrl(self, -1, "1")
186
        self.label_38 = wx.StaticText(self, -1, "")
187
        self.text_ctrl_10 = wx.TextCtrl(self, -1, "")
188
        self.label_36 = wx.StaticText(self, -1, "Channel")
189
        self.text_ctrl_8 = wx.TextCtrl(self, -1, "6")
190
        self.label_39 = wx.StaticText(self, -1, "")
191
        self.text_ctrl_11 = wx.TextCtrl(self, -1, "")
192
        self.button_4 = wx.Button(self, -1, "Start")
193
        self.GraphPanel = wx.Panel(self, -1)
194
        self.label_40 = wx.StaticText(self, -1, "Graph Type ")
195
        self.graphTypeChoice = wx.Choice(self, -1, choices=["Raw Signal", "Filtered Signal", "Spectrum"])
196
        self.label_41 = wx.StaticText(self, -1, "Y Axis Range ")
197
        self.yAxisChoice = wx.Choice(self, -1, choices=["25", "50", "100", "200"])
586 FredericG 198
        self.TestListCtrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
584 FredericG 199
 
200
        self.__set_properties()
201
        self.__do_layout()
587 FredericG 202
 
607 FredericG 203
        self.Bind(wx.EVT_MENU, self.OnSettings, id=101)
204
        self.Bind(wx.EVT_MENU, self.onClear, id=301)
205
        self.Bind(wx.EVT_MENU, self.OnImport, id=302)
600 FredericG 206
        self.Bind(wx.EVT_CHOICE, self.onGraphTypeChange, self.graphTypeChoice)
207
        self.Bind(wx.EVT_CHOICE, self.onYAxisChange, self.yAxisChoice)
584 FredericG 208
        # end wxGlade
209
 
587 FredericG 210
    def setApp(self, app):
211
        self.app = app
585 FredericG 212
 
584 FredericG 213
    def __set_properties(self):
214
        # begin wxGlade: MainFrame.__set_properties
587 FredericG 215
        self.SetTitle("VibrationTest")
600 FredericG 216
        self.SetSize((850, 700))
217
        self.Description.SetMinSize((53, 13))
601 FredericG 218
        self.button_4.SetMinSize((80, 80))
600 FredericG 219
        self.GraphPanel.SetMinSize((800,300))
220
        self.graphTypeChoice.SetSelection(0)
221
        self.yAxisChoice.SetSelection(1)
222
        self.TestListCtrl.SetMinSize((800,300))
584 FredericG 223
        # end wxGlade
224
 
225
    def __do_layout(self):
226
        # begin wxGlade: MainFrame.__do_layout
600 FredericG 227
        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
228
        sizer_8 = wx.BoxSizer(wx.VERTICAL)
229
        sizer_11 = wx.BoxSizer(wx.VERTICAL)
230
        sizer_12 = wx.BoxSizer(wx.HORIZONTAL)
231
        sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
232
        sizer_10 = wx.BoxSizer(wx.HORIZONTAL)
233
        grid_sizer_1 = wx.GridSizer(3, 4, 4, 5)
234
        sizer_3.Add((20, 20), 0, 0, 0)
235
        sizer_8.Add((20, 20), 0, 0, 0)
236
        grid_sizer_1.Add(self.Description, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
584 FredericG 237
        grid_sizer_1.Add(self.text_ctrl_6, 0, 0, 0)
600 FredericG 238
        grid_sizer_1.Add(self.label_37, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
239
        grid_sizer_1.Add(self.text_ctrl_9, 0, 0, 0)
240
        grid_sizer_1.Add(self.label_35, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
584 FredericG 241
        grid_sizer_1.Add(self.text_ctrl_7, 0, 0, 0)
600 FredericG 242
        grid_sizer_1.Add(self.label_38, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
243
        grid_sizer_1.Add(self.text_ctrl_10, 0, 0, 0)
244
        grid_sizer_1.Add(self.label_36, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
584 FredericG 245
        grid_sizer_1.Add(self.text_ctrl_8, 0, 0, 0)
600 FredericG 246
        grid_sizer_1.Add(self.label_39, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
247
        grid_sizer_1.Add(self.text_ctrl_11, 0, 0, 0)
248
        sizer_9.Add(grid_sizer_1, 0, 0, 0)
249
        sizer_10.Add((50, 20), 0, 0, 0)
250
        sizer_10.Add(self.button_4, 0, wx.ALIGN_CENTER_VERTICAL, 0)
251
        sizer_9.Add(sizer_10, 1, wx.EXPAND, 0)
252
        sizer_8.Add(sizer_9, 0, 0, 0)
253
        sizer_8.Add((20, 30), 0, 0, 0)
254
        sizer_11.Add(self.GraphPanel, 1, wx.EXPAND, 0)
255
        sizer_11.Add((20, 5), 0, 0, 0)
256
        sizer_12.Add(self.label_40, 0, wx.ALIGN_CENTER_VERTICAL, 0)
257
        sizer_12.Add(self.graphTypeChoice, 0, 0, 0)
258
        sizer_12.Add((40, 20), 0, 0, 0)
259
        sizer_12.Add(self.label_41, 0, wx.ALIGN_CENTER_VERTICAL, 0)
260
        sizer_12.Add(self.yAxisChoice, 0, 0, 0)
261
        sizer_11.Add(sizer_12, 0, 0, 0)
262
        sizer_8.Add(sizer_11, 0, 0, 0)
263
        sizer_8.Add((20, 30), 0, 0, 0)
264
        sizer_8.Add(self.TestListCtrl, 1, 0, 0)
265
        sizer_8.Add((20, 20), 0, 0, 0)
266
        sizer_3.Add(sizer_8, 1, wx.EXPAND, 0)
267
        self.SetSizer(sizer_3)
584 FredericG 268
        self.Layout()
600 FredericG 269
        self.SetSize((850, 700))
584 FredericG 270
        # end wxGlade
271
 
590 FredericG 272
        # List events
273
        self.TestListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnTestSelected, self.TestListCtrl)
274
 
586 FredericG 275
        # Configure Graph
593 FredericG 276
        self.client = wx.lib.plot.PlotCanvas(self.GraphPanel, size=(800,300))
277
 
585 FredericG 278
        self.client.SetPointLabelFunc(self.DrawPointLabel)
279
 
280
        self.client.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
281
        self.client.SetFontSizeAxis(10)
282
        self.client.SetFontSizeLegend(7)
283
        self.client.setLogScale((False,False))
284
 
586 FredericG 285
 
286
        # Configure TestListCtrl
594 FredericG 287
        self.TestListCtrl.InsertColumn(0, "Description")
288
        self.TestListCtrl.InsertColumn(1, "Speed")
289
        self.TestListCtrl.InsertColumn(2, "Channel")
607 FredericG 290
        self.TestListCtrl.InsertColumn(3, "Vibration Value")
291
        self.TestListCtrl.SetColumnWidth(3, 500)
586 FredericG 292
 
585 FredericG 293
    def DrawPointLabel(self, dc, mDataDict):
294
        """This is the fuction that defines how the pointLabels are plotted
295
            dc - DC that will be passed
296
            mDataDict - Dictionary of data that you want to use for the pointLabel
297
 
298
            As an example I have decided I want a box at the curve point
299
            with some text information about the curve plotted below.
300
            Any wxDC method can be used.
301
        """
302
        # ----------
303
        dc.SetPen(wx.Pen(wx.BLACK))
304
        dc.SetBrush(wx.Brush( wx.BLACK, wx.SOLID ) )
305
 
306
        sx, sy = mDataDict["scaledXY"] #scaled x,y of closest point
307
        dc.DrawRectangle( sx-5,sy-5, 10, 10)  #10by10 square centered on point
308
        px,py = mDataDict["pointXY"]
309
        cNum = mDataDict["curveNum"]
310
        pntIn = mDataDict["pIndex"]
311
        legend = mDataDict["legend"]
312
        #make a string to display
313
        s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" %(cNum, legend, px, py, pntIn)
314
        dc.DrawText(s, sx , sy+1)
315
        # -----------
316
 
596 FredericG 317
 
318
    def onNewTest(self, test):
319
        index = self.TestListCtrl.InsertStringItem(sys.maxint, test.descr)
320
        self.TestListCtrl.SetStringItem(index, 1, str(test.speed))
321
        self.TestListCtrl.SetStringItem(index, 2, test.channel)
607 FredericG 322
 
323
        vv = int(test.getVibValue())
324
        vvs = "|%s| (%d)" % ("----------------------------------------------------------------------------------------------------"[0:min(vv,100)], vv)
325
        self.TestListCtrl.SetStringItem(index, 3, vvs)
606 FredericG 326
        if (index == 0):
327
            self.TestListCtrl.Select(index)
596 FredericG 328
 
329
 
590 FredericG 330
    def OnTestSelected(self, event):
331
         testId = event.m_itemIndex
332
         print "Test Selected id=%d" % (testId)
592 FredericG 333
         self.activeTestId = testId
334
         self.drawGraph()
590 FredericG 335
 
592 FredericG 336
    def drawGraph(self):
607 FredericG 337
 
600 FredericG 338
         y = int(self.yAxisChoice.GetStringSelection())
590 FredericG 339
 
607 FredericG 340
         nbSelected = self.TestListCtrl.SelectedItemCount
596 FredericG 341
 
607 FredericG 342
         if nbSelected > 1:
343
             self.graphTypeChoice.Disable()
344
             x = 1
345
             data = []
346
             idx = self.TestListCtrl.GetFirstSelected()
347
             while idx != -1:
348
                 data.append([x,self.app.getTest(idx).getVibValue()])
349
                 x += 1
350
                 idx = self.TestListCtrl.GetNextSelected(idx)
351
             line = wx.lib.plot.PolyLine(data, legend= 'Vibrations', colour='red', width=2)
352
             markers = wx.lib.plot.PolyMarker(data, legend= '', colour='red', marker='circle',size=2)
353
             title = "Comparing tests"
354
             self.client.Draw(wx.lib.plot.PlotGraphics([line, markers], title, "Test", "Vibration Value"), xAxis=(1,max(x,10)), yAxis=(0,y))
600 FredericG 355
             self.client.SetEnableGrid('Horizontal')
356
 
607 FredericG 357
         else:
358
             self.graphTypeChoice.Enable()
359
             vibTest = self.app.getTest(self.activeTestId)
360
             nb = vibTest.getDataLen()
590 FredericG 361
 
607 FredericG 362
             if self.graphTypeChoice.GetSelection() == 0:
363
                 xydata = _Numeric.linspace(0,0.09*nb,2*nb)
364
                 xydata.shape = (nb, 2)
365
                 xydata[:,1] = vibTest.getRawData()
366
                 line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
367
 
368
                 title = "Raw Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
369
                 self.client.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
370
                 self.client.SetEnableGrid('Horizontal')
599 FredericG 371
 
607 FredericG 372
             if self.graphTypeChoice.GetSelection() == 1:
373
                 xydata = _Numeric.linspace(0,0.09*nb,2*nb)
374
                 xydata.shape = (nb, 2)
375
                 xydata[:,1] = vibTest.getFilteredData()
376
                 line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
377
 
378
                 title = "Filtered Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
379
                 self.client.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
380
                 self.client.SetEnableGrid('Horizontal')
381
 
382
             elif self.graphTypeChoice.GetSelection() == 2:
383
                 xydata = _Numeric.linspace(0,5555,nb)
384
                 xydata.shape = (nb/2, 2)
385
 
386
                 xydata[:,1] = vibTest.getSpectrum()
387
 
388
                 line = wx.lib.plot.PolyLine(xydata, legend= 'Spectrum', colour='red')
389
                 markers = wx.lib.plot.PolyMarker(xydata, legend= '', colour='red', marker='circle',size=2)
390
 
391
                 title = "Spectrum: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
392
                 self.client.Draw(wx.lib.plot.PlotGraphics([line,markers], title, "Freq (Hz)", "Acc"), xAxis=(0,200), yAxis= (-0,y))
393
                 self.client.SetEnableGrid(True)
590 FredericG 394
 
599 FredericG 395
 
587 FredericG 396
    def OnImport(self, event): # wxGlade: MainFrame.<event_handler>
606 FredericG 397
        dlg = wx.FileDialog(
398
            self, message="Choose a file",
399
            defaultDir=os.getcwd(),
400
            defaultFile="*.txt",
401
            wildcard="",
402
            style=wx.OPEN | wx.CHANGE_DIR
403
            )
404
        if dlg.ShowModal() == wx.ID_OK:
405
            paths = dlg.GetPaths();
406
            self.app.Import(paths[0])
407
        dlg.Destroy()
587 FredericG 408
 
599 FredericG 409
    def onYAxisChange(self, event): # wxGlade: MainFrame.<event_handler>
592 FredericG 410
        self.drawGraph()
411
 
600 FredericG 412
    def onGraphTypeChange(self, event): # wxGlade: MainFrame.<event_handler>
599 FredericG 413
        self.drawGraph()
414
 
601 FredericG 415
    def onClear(self, event): # wxGlade: MainFrame.<event_handler>
416
        print "Event handler `onClear' not implemented"
417
        event.Skip()
418
 
607 FredericG 419
    def OnSettings(self, event): # wxGlade: MainFrame.<event_handler>
420
        dlg = SettingsDialog(self, -1, "Sample Dialog", size=(350, 200),
421
                         #style=wx.CAPTION | wx.SYSTEM_MENU | wx.THICK_FRAME,
422
                         style=wx.DEFAULT_DIALOG_STYLE, # & ~wx.CLOSE_BOX
423
                         )
424
        dlg.CenterOnScreen()
425
 
426
        # this does not return until the dialog is closed.
427
        val = dlg.ShowModal()
428
 
429
        dlg.Destroy()
430
 
584 FredericG 431
# end of class MainFrame
432
 
607 FredericG 433
class Setting:
434
    def __init__(self, descr, defaultValue):
435
        self.descr = descr
436
        self.value = defaultValue
584 FredericG 437
 
586 FredericG 438
class VibTest:
596 FredericG 439
    def __init__(self, descr, motor, speed, channel, rawData):
594 FredericG 440
        self.descr = descr
441
        self.motor = motor
442
        self.speed = speed
596 FredericG 443
        self.channel = channel
599 FredericG 444
 
445
        self.dataLen = len(rawData)
446
 
590 FredericG 447
        self.rawData = _Numeric.array(rawData)
448
        self.dc = self.rawData.mean()
449
        self.rawData -= self.dc
586 FredericG 450
 
600 FredericG 451
        self.fft = _Numeric.fft.rfft(self.rawData)
452
 
453
        self.spectrum = None
454
        self.filteredData = None
599 FredericG 455
 
602 FredericG 456
        self.vibValue = None
457
 
594 FredericG 458
    def getDescr(self):
459
        return self.Descr
587 FredericG 460
 
590 FredericG 461
    def getRawData(self):
462
        return self.rawData
463
 
464
    def getDataLen(self):
465
        return self.dataLen
466
 
599 FredericG 467
    def getSpectrum(self):
600 FredericG 468
        if self.spectrum == None:
469
            self.spectrum = _Numeric.absolute(self.fft[1:self.dataLen/2+1]) / (self.dataLen/2)
470
        return self.spectrum
590 FredericG 471
 
600 FredericG 472
    def getFilteredData(self):
473
        if self.filteredData == None:
474
            tmpfft = self.fft.copy()
602 FredericG 475
            for i in range(0,5):
600 FredericG 476
                tmpfft[i] = 0
477
            for i in range(30, len(tmpfft)):
478
                tmpfft[i] = 0
479
            self.filteredData = _Numeric.fft.irfft(tmpfft)
480
        return self.filteredData
602 FredericG 481
 
482
    def getVibValue(self):
483
      if self.vibValue == None:
484
        fd = self.getFilteredData();
485
        self.vibValue = max(fd)-min(fd)
486
      return self.vibValue
599 FredericG 487
 
607 FredericG 488
 
489
 
584 FredericG 490
class App(wx.App):
607 FredericG 491
 
492
    SETTINGSFILE = "settings.cfg"
493
 
586 FredericG 494
    def __init__(self, par):
495
        self.VibTests = []
496
        wx.App.__init__(self, par)
497
 
607 FredericG 498
        # Init settings
499
        self.settings={}
500
        self.settings["serialPort"] = Setting("SerialPort", "COM1")
501
        self.settings["hpf"] = Setting("HP Filter cutoff (Hz)", 50)
502
        self.settings["lpf"] = Setting("LP Filter cutoff (Hz)", 400)
503
 
504
        self.readSettings()
505
 
606 FredericG 506
        if len(sys.argv)>1:
507
            self.Import(sys.argv[1])
586 FredericG 508
 
606 FredericG 509
 
607 FredericG 510
    def readSettings(self):
511
        print "Reading settings"
512
        cp = ConfigParser.ConfigParser()
513
 
514
        try:
515
            cp.read(App.SETTINGSFILE)
516
            for setting in cp.items("DEFAULT"):
517
                print " ",setting
518
                try:
519
                    self.settings[setting[0]].value = setting[1]
520
                except:
521
                    print "WARNING, unknown setting"
522
        except:
523
            print "ERROR reading settingsfile"
524
 
525
 
526
    def storeSettings(self):
527
        print "Storing settings"
528
 
529
        cp = ConfigParser.ConfigParser()
530
        for setting in self.settings.iteritems():
531
            cp.set("", setting[0], setting[1].value)
532
 
533
        file = open(App.SETTINGSFILE, "w")
534
        cp.write(file)
535
        file.close()
536
 
596 FredericG 537
    def AddTest(self, descr, motor, speed, channel, rawData):
538
        test = VibTest(descr, motor, speed, channel, rawData)
586 FredericG 539
        self.VibTests.append(test)
596 FredericG 540
        self.frame_1.onNewTest(test)
586 FredericG 541
 
590 FredericG 542
    def getTest(self, testId):
543
        return self.VibTests[testId]
544
 
584 FredericG 545
    def OnInit(self):
546
        wx.InitAllImageHandlers()
586 FredericG 547
        self.frame_1 = MainFrame(None, -1, "")
587 FredericG 548
        self.frame_1.setApp(self);
586 FredericG 549
        self.SetTopWindow(self.frame_1)
550
 
607 FredericG 551
        self.frame_1.CenterOnScreen()
587 FredericG 552
        self.frame_1.Show()
553
        return 1
554
 
606 FredericG 555
    def Import(self, filePath):
596 FredericG 556
 
606 FredericG 557
        print "Importing file \"%s\"" % filePath
596 FredericG 558
 
559
        logfile = open(filePath, "r")
590 FredericG 560
        data = None
596 FredericG 561
 
562
        headers = (logfile.readline()).split(',')
563
        nbCols = len(headers)
564
        print "NbCols =", nbCols
565
 
566
        data = []
567
        descr = []
568
        speed = []
569
        channel = []
570
        for c in range(nbCols):
571
            data.append([])
572
            h = headers[c].split(' ')
573
            descr.append(h[0]);
574
            speed.append(h[1]);
575
            channel.append(h[2]);
576
 
590 FredericG 577
        for line in logfile:
578
            values = line.split(',')
596 FredericG 579
            for i in range(nbCols):
580
                data[i].append(int(values[i]))
590 FredericG 581
        logfile.close()
596 FredericG 582
 
583
        for c in range(nbCols):
599 FredericG 584
            if (len(data[c]) % 2) != 0:
585
                data[c].append(data[c][-1])
596 FredericG 586
            self.AddTest(descr[c], 0, int(speed[c]), channel[c], data[c])
590 FredericG 587
 
588
 
589
 
586 FredericG 590
 
590 FredericG 591
 
584 FredericG 592
# end of class App
593
 
594
if __name__ == "__main__":
595
    VibrationTestGui = App(0)
596
    VibrationTestGui.MainLoop()