/
Experiment_display.cpp
378 lines (274 loc) · 8.62 KB
/
Experiment_display.cpp
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
// Experiment_display.cpp : implementation file
//
#include "stdafx.h"
#include "slcontrol.h"
#include "Experiment_display.h"
#include "SLControlDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Experiment_display dialog
extern int FL_OR_SL_CHANNEL_MODE;
Experiment_display::Experiment_display(CWnd* pParent,
Data_record* set_p_Experiment_display_record)
: CDialog(Experiment_display::IDD, pParent)
{
////////////////////////////
// Ken's code starts here //
////////////////////////////
m_pParent=pParent;
m_nID=Experiment_display::IDD;
// Pointer for data record
p_Experiment_display_record=set_p_Experiment_display_record;
// Window location and dimensions
window_x_pos=(float)0.02;
window_y_pos=(float)0.51;
window_x_size=(float)0.63;
window_y_size=(float)0.49;
// Pointers for data plots
if (FL_OR_SL_CHANNEL_MODE==SL_CHANNEL_MODE)
{
no_of_plots=6;
p_FOR_plot =& FOR_plot;
p_SL_plot =& SL_plot;
p_FL_plot =& FL_plot;
p_FOR_SL_plot =& FOR_SL_plot;
p_FOR_FL_plot =& FOR_FL_plot;
p_SL_FL_plot =& SL_FL_plot;
pointers_array[0]=p_FOR_plot;
pointers_array[1]=p_SL_plot;
pointers_array[2]=p_FL_plot;
pointers_array[3]=p_FOR_SL_plot;
pointers_array[4]=p_FOR_FL_plot;
pointers_array[5]=p_SL_FL_plot;
}
else
{
no_of_plots=2;
p_FOR_plot =& FOR_plot;
p_FL_plot =& FL_plot;
pointers_array[0]=p_FOR_plot;
pointers_array[1]=p_FL_plot;
}
////////////////////////////
// Ken's code ends here //
////////////////////////////
//{{AFX_DATA_INIT(Experiment_display)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
Experiment_display::~Experiment_display(void)
{
// Destructor
}
BOOL Experiment_display::Create(void)
{
return CDialog::Create(m_nID, m_pParent);
}
void Experiment_display::PostNcDestroy()
{
delete this;
}
void Experiment_display::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Experiment_display)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Experiment_display, CDialog)
//{{AFX_MSG_MAP(Experiment_display)
ON_WM_KEYDOWN()
ON_WM_CHAR()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Experiment_display message handlers
void Experiment_display::close_experiment_display_window(void)
{
// Code is called by parent to close the window
DestroyWindow();
}
BOOL Experiment_display::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
////////////////////////////
// Ken's code starts here //
////////////////////////////
// Variables
int i;
int width=1022; // screen width and height
int height=740; // in pixels
// Set window
SetWindowPos(NULL,(int)(window_x_pos*width),(int)(window_y_pos*height),
(int)(window_x_size*width),(int)(window_y_size*height),SWP_SHOWWINDOW);
// Create display dc
CClientDC dc(this);
p_display_dc =& dc;
// Calculate window dimensions and pass to plot
CRect current_window;
GetWindowRect(current_window);
current_window.NormalizeRect();
if (FL_OR_SL_CHANNEL_MODE==SL_CHANNEL_MODE)
{
p_FOR_plot->initialise_plot(p_Experiment_display_record,TIME,FORCE,AUTO_SCALE_ON,
CURSOR_DISPLAY_ON,TEXT_DISPLAY_ON,
current_window.Width(),current_window.Height(),(float)0.1,(float)0.24,(float)0.3,(float)0.22,
"Time (s)","FOR (V)","Force v Time");
p_SL_plot->initialise_plot(p_Experiment_display_record,TIME,SL,AUTO_SCALE_ON,
CURSOR_DISPLAY_ON,TEXT_DISPLAY_ON,
current_window.Width(),current_window.Height(),(float)0.1,(float)0.56,(float)0.3,(float)0.22,
"Time (s)","SL (V)","SL v Time");
p_FL_plot->initialise_plot(p_Experiment_display_record,TIME,FL,AUTO_SCALE_ON,
CURSOR_DISPLAY_ON,TEXT_DISPLAY_ON,
current_window.Width(),current_window.Height(),(float)0.1,(float)0.87,(float)0.3,(float)0.22,
"Time (s)","FL (V)","FL v Time");
p_FOR_SL_plot->initialise_plot(p_Experiment_display_record,SL,FORCE,AUTO_SCALE_ON,
CURSOR_DISPLAY_ON,TEXT_DISPLAY_ON,
current_window.Width(),current_window.Height(),(float)0.67,(float)0.24,(float)0.15,(float)0.22,
"SL (V)","FOR (V)","Force v SL");
p_FOR_FL_plot->initialise_plot(p_Experiment_display_record,FL,FORCE,AUTO_SCALE_ON,
CURSOR_DISPLAY_ON,TEXT_DISPLAY_ON,
current_window.Width(),current_window.Height(),(float)0.67,(float)0.56,(float)0.15,(float)0.22,
"FL (V)","FOR (V)","Force v FL");
p_SL_FL_plot->initialise_plot(p_Experiment_display_record,FL,SL,AUTO_SCALE_ON,
CURSOR_DISPLAY_ON,TEXT_DISPLAY_ON,
current_window.Width(),current_window.Height(),(float)0.67,(float)0.87,(float)0.15,(float)0.22,
"FL (V)","SL (V)","SL v FL");
}
else
{
p_FOR_plot->initialise_plot(p_Experiment_display_record,TIME,FORCE,AUTO_SCALE_ON,
CURSOR_DISPLAY_ON,TEXT_DISPLAY_ON,
current_window.Width(),current_window.Height(),(float)0.15,(float)0.4,(float)0.6,(float)0.3,
"Time (s)","FOR (V)","Force v Time");
p_FL_plot->initialise_plot(p_Experiment_display_record,TIME,FL,AUTO_SCALE_ON,
CURSOR_DISPLAY_ON,TEXT_DISPLAY_ON,
current_window.Width(),current_window.Height(),(float)0.15,(float)0.87,(float)0.6,(float)0.3,
"Time (s)","FL (V)","FL v Time");
}
// Draw default plots
for (i=0;i<=(no_of_plots-1);i++)
{
pointers_array[i]->draw_plot(p_display_dc,1,p_Experiment_display_record->no_of_points);
}
////////////////////////////
// Ken's code ends here //
////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void Experiment_display::update_plots()
{
// Code updates plots
// Variables
int i;
// Create display dc
CClientDC dc(this);
p_display_dc =& dc;
// Cycle through plots
for (i=0;i<=(no_of_plots-1);i++)
{
pointers_array[i]->draw_plot(p_display_dc,1,p_Experiment_display_record->no_of_points);
}
}
void Experiment_display::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
////////////////////////////
// Ken's code starts here //
////////////////////////////
// Handles user input
// Variables
int i;
int key_code=nChar;
int control_key;
// Code
// Create display dc
CClientDC dc(this);
p_display_dc =& dc;
// Reacts to user input
// Extract Ctrl Key status
if (GetKeyState(VK_CONTROL)<0) // Ctrl Key pressed
{
control_key=1;
}
else // Ctrl Key not pressed
{
control_key=0;
}
// Clear window
clear_window();
// Cycle through plots processing input
for (i=0;i<=(no_of_plots-1);i++)
{
pointers_array[i]->respond_to_key_press(p_display_dc,key_code,control_key);
}
//////////////////////////
// Ken's code ends here //
//////////////////////////
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
void Experiment_display::clear_window(void)
{
// Code clears window by drawing over it in background colour
// Create display dc
CClientDC dc(this);
CClientDC* p_dc =& dc;
// Pen
CPen* pOriginalPen;
CPen BackgroundPen;
BackgroundPen.CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNFACE));
pOriginalPen = p_dc->SelectObject(&BackgroundPen);
// Background brush
CBrush* pOriginalBrush;
CBrush BackgroundBrush;
BackgroundBrush.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
pOriginalBrush = p_dc->SelectObject(&BackgroundBrush);
// Overdraw screen
// Calculate window dimensions and pass to plot
CRect current_window;
GetWindowRect(current_window);
current_window.NormalizeRect();
p_dc->Rectangle(1,1,current_window.Width(),current_window.Height());
// Return brush and pen
p_dc->SelectObject(pOriginalBrush);
p_dc->SelectObject(pOriginalPen);
}
void Experiment_display::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
// Code redraws screen
// Variables
int i;
// Create display_dc
CClientDC dc_window(this);
CClientDC* p_display_dc =& dc_window;
// Redraw screen
for (i=0;i<=(no_of_plots-1);i++)
{
pointers_array[i]->draw_plot(p_display_dc,
pointers_array[i]->first_drawn_point,
pointers_array[i]->last_drawn_point);
}
}
BOOL Experiment_display::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// Traps Enter and Escape key presses to prevent dialog box closing
if (pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
{
return TRUE;
}
if (pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_ESCAPE)
{
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}