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