Subversion Repositories Projects

Rev

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