comparison Plot.c @ 135:77539f2597b1

Code cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 22 Jan 2014 12:29:38 +0100
parents bd28161e5ac2
children be87c8e78266
comparison
equal deleted inserted replaced
134:bd28161e5ac2 135:77539f2597b1
1
2 #include <ansi_c.h> 1 #include <ansi_c.h>
3 #include <userint.h> 2 #include <userint.h>
4 3
5 #include "YLCStuff.h" 4 #include "YLCStuff.h"
6 #include "FXAnalyse.h" 5 #include "FXPlot.h"
7 6 #include "Plot.h"
8 #include "FXPlot.h" // Auto generated panel definitions and protypes 7
9 #include "Plot.h" // My own .h file, containing prototypes and definitions for the class Plot... 8 void Plot_InitPanel(Plot_Data *Instance, const char *title, double ymin, double ymax, int parent, int control)
10 9 {
11 // ******************* Member functions : constructor and destructor **********************
12
13 int Plot_InitPanel(Plot_Data * Instance, const char * title, double PlotMin, double PlotMax, int parent, int control) {
14
15 if ((Instance->PlotPanel = LoadPanel (0, "FXPlot.uir", PLOTPANEL)) < 0) 10 if ((Instance->PlotPanel = LoadPanel (0, "FXPlot.uir", PLOTPANEL)) < 0)
16 return -1; 11 return;
17 SetPanelAttribute(Instance->PlotPanel, ATTR_TITLE, title) ; 12
18 SetPanelAttribute (Instance->PlotPanel, ATTR_CALLBACK_DATA, (void *)Instance); // the panel callback therefore knows which data structure it is associated to 13 SetPanelAttribute(Instance->PlotPanel, ATTR_TITLE, title);
14 SetPanelAttribute(Instance->PlotPanel, ATTR_CALLBACK_DATA, (void *)Instance);
19 Instance->active = TRUE; 15 Instance->active = TRUE;
20 Instance->parent = parent; 16 Instance->parent = parent;
21 Instance->control = control; 17 Instance->control = control;
22 Instance->IndexPoint = 0 ; 18 Instance->IndexPoint = 0;
23 Instance->Mean = 0 ; 19 Instance->Mean = 0;
24 Instance->Slope = 0; 20 Instance->Slope = 0;
25 Instance->ADev = 0 ; 21 Instance->ADev = 0;
26 Instance->Frequencies = calloc(MAXPOINTSNUMBER, sizeof(double)) ; 22 Instance->Frequencies = calloc(MAXPOINTSNUMBER, sizeof(double));
27 DisplayPanel (Instance->PlotPanel); 23 DisplayPanel(Instance->PlotPanel);
28 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, PlotMin) ; 24
29 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, PlotMax) ; 25 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, ymin);
30 SetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, PlotMin, PlotMax) ; 26 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, ymax);
31 return 0 ; 27
32 } 28 if ((ymin != 0.0) && (ymax != 0.0)) {
33 29 /* manual scaling */
34 30 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, ymin);
35 31 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, ymax);
36 int Plot_ClosePanel(Plot_Data * Instance) { 32 SetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, ymin, ymax);
33 } else {
34 /* auto scaling */
35 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_AUTOSCALE, TRUE);
36 SetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_AUTOSCALE, 0, 0);
37 }
38 }
39
40
41 void Plot_ClosePanel(Plot_Data * Instance)
42 {
37 Instance->active = FALSE; 43 Instance->active = FALSE;
38 free(Instance->Frequencies); 44 free(Instance->Frequencies);
39 SetCtrlVal(Instance->parent, Instance->control, FALSE); 45 SetCtrlVal(Instance->parent, Instance->control, FALSE);
40 DiscardPanel (Instance->PlotPanel); 46 DiscardPanel(Instance->PlotPanel);
41 return 0; 47 }
42 } 48
43 49
44 50 void Plot_AddFrequency(Plot_Data * Instance, double Freq)
45 51 {
46 // ******************** Member functions, callbacks (private) ******************************* 52 double Drift = 0;
47 53 int DeDrift;
48 int CVICALLBACK CB_PlotEvent(int panel, int event, void *callbackData, int eventData1, int eventData2) { 54 int N = 0;
49 55
50 int VirtualKeyCode; 56 double Mean = Instance->Mean;
51 int StepIndex; 57 double Slope = Instance->Slope;
52 double Step; 58 double ADev = Instance->ADev;
53 59
54 Plot_Data * Instance = NULL; 60 /* Correct Freq with drift (feed forward) if dedrift is on */
55 61 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_DEDRIFT, &DeDrift);
56 switch (event) 62 if (DeDrift) {
57 { 63 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_DEDRIFT, &Drift);
58 case EVENT_CLOSE: 64 Freq -= ((double) Instance->IndexPoint)*Drift;
59 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance); 65 }
60 Plot_ClosePanel(Instance) ; 66
61 break; 67 /* Add Freq to graph plot */
62 68 Instance->Frequencies[Instance->IndexPoint++] = Freq;
63 case EVENT_KEYPRESS: 69 N = Instance->IndexPoint;
64 VirtualKeyCode = GetKeyPressEventVirtualKey(eventData2); 70
65 switch (VirtualKeyCode) 71 if (N > 1) {
66 { 72 /* adev and slope computation need at least 2 data points */
67 case 2304: //ie right arrow 73 Instance->Slope = (Slope*(N-2) + 6*(Freq-Mean)/N)/(N+1);
68 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &StepIndex); 74 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_SLOPE, Instance->Slope);
69 if (StepIndex<10){ 75 Instance->ADev = sqrt( ( ADev*ADev*(N-2) + 0.5*pow(Freq-Instance->Frequencies[N-2],2) ) / (N-1));
70 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, ++StepIndex) ; 76 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_ADEV, Instance->ADev);
71 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &Step); 77 }
72 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, Step) ; 78 Instance->Mean = (Mean*(N-1)+Freq)/N;
73 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, Step) ;
74 };
75 break;
76 case 2048: //ie left arrow
77 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &StepIndex);
78 if (StepIndex>0){
79 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, --StepIndex) ;
80 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &Step);
81 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, Step) ;
82 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, Step) ;
83 };
84 break;
85 };
86 break;
87 }
88 return 0;
89 }
90
91 int CVICALLBACK Plot_CB_ChangeMax (int panel, int control, int event,
92 void *callbackData, int eventData1, int eventData2)
93 {
94 double YMin, YMax ;
95
96 switch (event)
97 {
98 case EVENT_COMMIT:
99 GetCtrlVal(panel, PLOTPANEL_MIN, &YMin) ;
100 GetCtrlVal(panel, PLOTPANEL_MAX, &YMax) ;
101 if (YMin<YMax) {
102 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, YMin, YMax) ;
103 SetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, FALSE) ;
104 } ;
105 break;
106 case EVENT_RIGHT_CLICK:
107
108 break;
109 }
110 return 0;
111 }
112
113 int CVICALLBACK Plot_CB_ChangeMin (int panel, int control, int event,
114 void *callbackData, int eventData1, int eventData2)
115 {
116 double YMin, YMax ;
117
118 switch (event)
119 {
120 case EVENT_COMMIT:
121 GetCtrlVal(panel, PLOTPANEL_MIN, &YMin) ;
122 GetCtrlVal(panel, PLOTPANEL_MAX, &YMax) ;
123 if (YMin<YMax ) {
124 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, YMin, YMax) ;
125 SetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, FALSE) ;
126 } ;
127 break;
128 case EVENT_RIGHT_CLICK:
129
130 break;
131 }
132 return 0;
133 }
134
135
136 int CVICALLBACK Plot_CB_ChangeAutoScale (int panel, int control, int event,
137 void *callbackData, int eventData1, int eventData2)
138 {
139 bool AutoScale = FALSE;
140 int NotCare = 20000000 ;
141 double YMin = 10000000 , YMax = 64000000 ;
142
143 switch (event)
144 {
145 case EVENT_COMMIT:
146 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, &AutoScale) ;
147 if (AutoScale) {
148 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_AUTOSCALE, YMin, YMax) ;
149 GetAxisScalingMode(panel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, &NotCare, &YMin, &YMax ) ;
150 SetCtrlVal(panel, PLOTPANEL_MIN, YMin);
151 SetCtrlVal(panel, PLOTPANEL_MAX, YMax);
152 }
153 else {
154 GetCtrlVal(panel, PLOTPANEL_MIN, &YMin);
155 GetCtrlVal(panel, PLOTPANEL_MAX, &YMax);
156 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, YMin, YMax) ;
157 } ;
158 break;
159 case EVENT_RIGHT_CLICK:
160
161 break;
162 }
163 return 0;
164 }
165
166 int CVICALLBACK Plot_CB_ChangeScalingStep(int panel, int control, int event,
167 void *callbackData, int eventData1, int eventData2)
168 {
169 double ScalingStep ;
170
171 switch (event)
172 {
173 case EVENT_COMMIT:
174 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &ScalingStep) ;
175 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, ScalingStep) ;
176 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, ScalingStep) ;
177 break;
178 case EVENT_RIGHT_CLICK:
179 break;
180 }
181 return 0;
182 }
183
184
185 // ******************** Member functions, public *******************************************
186
187 int Plot_AddFrequency(Plot_Data * Instance, double Freq) {
188
189 double YMin = 10000000, YMax = 64000000, Mean = 0, ADev = 0 , Slope = 0 , Drift = 0 ;
190 bool AutoScale, DeDrift ;
191 int N = 0, NotCare ;
192
193 // Retrieve previous values for mean, adev and slope
194 Mean = Instance->Mean ;
195 Slope = Instance->Slope;
196 ADev = Instance->ADev;
197
198 // Correct Freq with drift (feed forward) if dedrift is on
199 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_DEDRIFT, &DeDrift) ;
200 if(DeDrift) {
201 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_DEDRIFT, &Drift) ;
202 Freq -= ((double) Instance->IndexPoint)*Drift ;
203 } ;
204
205 // Add Freq to graph plot
206 Instance->Frequencies[Instance->IndexPoint++] = Freq ;
207 N = Instance->IndexPoint ; // N is now the new number of points in the graph
208
209
210 if (N > 1) { // ADEV and SLOPE need at least 2 values !
211 Instance->Slope = (Slope*(N-2) + 6*(Freq-Mean)/N)/(N+1) ;
212 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_SLOPE, Instance->Slope ) ;
213 Instance->ADev = sqrt( ( ADev*ADev*(N-2) + 0.5*pow(Freq-Instance->Frequencies[N-2],2) ) / (N-1) ) ;
214 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_ADEV, Instance->ADev ) ;
215 } ;
216 Instance->Mean = (Mean*(N-1)+Freq)/N ;
217 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MEAN, Instance->Mean); 79 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MEAN, Instance->Mean);
218 80
219 if (N > MAXPOINTSNUMBER - 2) { // If too many points recorded, restart new plot with new values of Mean, Slope and Adev 81 /* if too many points recorded restart */
82 if (N > MAXPOINTSNUMBER - 2) {
220 Instance->IndexPoint = 0; 83 Instance->IndexPoint = 0;
221 Instance->Mean = 0; 84 Instance->Mean = 0;
222 Instance->Slope = 0; 85 Instance->Slope = 0;
223 Instance->ADev = 0; 86 Instance->ADev = 0;
224 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_MEAN, 0.) ; 87 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_MEAN, 0.0);
225 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_SLOPE, 0.) ; 88 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_SLOPE, 0.0);
226 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_ADEV, 0.) ; 89 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_ADEV, 0.0);
227 } ; 90 }
228 91
229 DeleteGraphPlot(Instance->PlotPanel, PLOTPANEL_FREQPLOT, -1,VAL_IMMEDIATE_DRAW) ; 92 DeleteGraphPlot(Instance->PlotPanel, PLOTPANEL_FREQPLOT, -1, VAL_IMMEDIATE_DRAW);
230 PlotY(Instance->PlotPanel, PLOTPANEL_FREQPLOT, Instance->Frequencies, Instance->IndexPoint, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE) ; 93 PlotY(Instance->PlotPanel, PLOTPANEL_FREQPLOT, Instance->Frequencies, Instance->IndexPoint,
231 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_AUTOSCALE, &AutoScale) ; 94 VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE);
232 if (AutoScale) { 95
233 GetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, &NotCare, &YMin, &YMax ) ; 96 int autoscale;
234 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, YMin); 97 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_AUTOSCALE, &autoscale);
235 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, YMax); 98 if (autoscale) {
236 } ; 99 /* update plot limits */
237 return 0 ; 100 double ymin, ymax;
238 } 101 GetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, NULL, &ymin, &ymax);
239 102 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, ymin);
240 103 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, ymax);
104 /* adjust control limits */
105 SetCtrlAttribute(Instance->PlotPanel, PLOTPANEL_MIN, ATTR_MAX_VALUE, ymax);
106 SetCtrlAttribute(Instance->PlotPanel, PLOTPANEL_MAX, ATTR_MIN_VALUE, ymin);
107 }
108 }
109
110
111 /* callbacks */
112
113 int CVICALLBACK CB_PlotEvent(int panel, int event,
114 void *callbackData, int eventData1, int eventData2)
115 {
116 switch (event)
117 {
118 case EVENT_CLOSE:
119 Plot_Data *data;
120 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &data);
121 Plot_ClosePanel(data);
122 break;
123
124 case EVENT_KEYPRESS:
125 int keycode = GetKeyPressEventVirtualKey(eventData2);
126 int index;
127 double step;
128 switch (keycode)
129 {
130 case 2304: /* right arrow */
131 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &index);
132 if (index < 10) {
133 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, ++index);
134 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &step);
135 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, step);
136 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, step);
137 }
138 break;
139 case 2048: /* left arrow */
140 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &index);
141 if (index > 0) {
142 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, --index);
143 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &step);
144 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, step);
145 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, step);
146 }
147 break;
148 }
149 break;
150 }
151 return 0;
152 }
153
154
155 int CVICALLBACK Plot_CB_ChangeYLim (int panel, int control, int event,
156 void *callbackData, int eventData1, int eventData2)
157 {
158 double ymin, ymax;
159
160 switch (event)
161 {
162 case EVENT_COMMIT:
163 GetCtrlVal(panel, PLOTPANEL_MIN, &ymin);
164 GetCtrlVal(panel, PLOTPANEL_MAX, &ymax);
165 /* adjust control limits */
166 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_MAX_VALUE, ymax);
167 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_MIN_VALUE, ymin);
168 /* disable autoscaling */
169 SetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, FALSE);
170 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, ymin, ymax);
171 break;
172 }
173 return 0;
174 }
175
176
177 int CVICALLBACK Plot_CB_ChangeAutoScale (int panel, int control, int event,
178 void *callbackData, int eventData1, int eventData2)
179 {
180 int autoscale = FALSE;
181 double ymin, ymax;
182
183 switch (event)
184 {
185 case EVENT_COMMIT:
186 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, &autoscale);
187 if (autoscale) {
188 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_AUTOSCALE, 0, 0);
189 GetAxisScalingMode(panel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, NULL, &ymin, &ymax);
190 SetCtrlVal(panel, PLOTPANEL_MIN, ymin);
191 SetCtrlVal(panel, PLOTPANEL_MAX, ymax);
192 /* adjust control limits */
193 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_MAX_VALUE, ymax);
194 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_MIN_VALUE, ymin);
195 } else {
196 GetCtrlVal(panel, PLOTPANEL_MIN, &ymin);
197 GetCtrlVal(panel, PLOTPANEL_MAX, &ymax);
198 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, ymin, ymax);
199 }
200 break;
201 }
202 return 0;
203 }
204
205
206 int CVICALLBACK Plot_CB_ChangeScalingStep(int panel, int control, int event,
207 void *callbackData, int eventData1, int eventData2)
208 {
209 double step;
210
211 switch (event)
212 {
213 case EVENT_COMMIT:
214 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &step);
215 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, step);
216 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, step);
217 break;
218 }
219 return 0;
220 }
241 221
242 222
243 int CVICALLBACK Plot_CB_Reset (int panel, int control, int event, 223 int CVICALLBACK Plot_CB_Reset (int panel, int control, int event,
244 void *callbackData, int eventData1, int eventData2) 224 void *callbackData, int eventData1, int eventData2)
245 { 225 {
246 Plot_Data * Instance = NULL; 226 Plot_Data *data;
247 227 switch (event)
248 switch (event) 228 {
249 { 229 case EVENT_COMMIT:
250 case EVENT_COMMIT: 230 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &data);
251 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance); 231 data->IndexPoint = 0;
252 Instance->IndexPoint = 0 ; 232 data->Mean = 0;
253 Instance->Mean = 0 ; 233 data->Slope = 0;
254 Instance->Slope = 0; 234 data->ADev = 0;
255 Instance->ADev = 0 ; 235 break;
256 236 }
257 break;
258 }
259 return 0; 237 return 0;
260 } 238 }
261 239
262 240
263 int CVICALLBACK Plot_CB_GetDrift (int panel, int control, int event, 241 int CVICALLBACK Plot_CB_GetDrift (int panel, int control, int event,
264 void *callbackData, int eventData1, int eventData2) 242 void *callbackData, int eventData1, int eventData2)
265 { 243 {
266 Plot_Data * Instance = NULL; 244 Plot_Data *data;
267 bool DeDrift ; 245 int dedrift;
268 double Drift ; 246 double drift;
269 247
270 switch (event) 248 switch (event)
271 { 249 {
272 case EVENT_COMMIT: 250 case EVENT_COMMIT:
273 251 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &data);
274 //Instance = ThisPlot(panel) ; 252 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &dedrift);
275 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance); 253 if (dedrift) {
276 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &DeDrift) ; 254 GetCtrlVal(panel, PLOTPANEL_DEDRIFT, &drift);
277 255 drift += data->Slope;
278 if (!DeDrift) { 256 SetCtrlVal(panel, PLOTPANEL_DEDRIFT, drift);
279 SetCtrlVal(panel,PLOTPANEL_DEDRIFT,Instance->Slope) ; 257 data->IndexPoint = 0;
280 } 258 data->Mean = 0;
281 else { 259 data->Slope = 0;
282 GetCtrlVal(panel, PLOTPANEL_DEDRIFT, &Drift) ; 260 data->ADev = 0;
283 Drift += Instance->Slope ; 261 } else
284 SetCtrlVal(panel, PLOTPANEL_DEDRIFT, Drift) ; 262 SetCtrlVal(panel,PLOTPANEL_DEDRIFT, data->Slope);
285 263 break;
286 Instance->IndexPoint = 0 ; 264 }
287 Instance->Mean = 0 ; 265 return 0;
288 Instance->Slope = 0 ; 266 }
289 Instance->ADev = 0 ; 267
290
291 } ;
292
293
294 break;
295 }
296 return 0;
297 }
298 268
299 int CVICALLBACK Plot_CB_ChangeDrift (int panel, int control, int event, 269 int CVICALLBACK Plot_CB_ChangeDrift (int panel, int control, int event,
300 void *callbackData, int eventData1, int eventData2) 270 void *callbackData, int eventData1, int eventData2)
301 { 271 {
302 bool DeDrift ; 272 int dedrift;
303 Plot_Data * Instance = NULL; 273 Plot_Data *data;
304 274
305 switch (event) 275 switch (event)
306 { 276 {
307 case EVENT_COMMIT: 277 case EVENT_COMMIT:
308 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &DeDrift) ; 278 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &dedrift);
309 if(DeDrift) { 279 if (dedrift) {
310 280 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &data);
311 //Instance = ThisPlot(panel) ; 281 data->IndexPoint = 0;
312 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance); 282 data->Mean = 0;
313 283 data->Slope = 0;
314 Instance->IndexPoint = 0 ; 284 data->ADev = 0;
315 Instance->Mean = 0 ; 285 }
316 Instance->Slope = 0 ; 286 break;
317 Instance->ADev = 0 ; 287 }
318 288 return 0;
319 } ; 289 }
320 290
321 break;
322 }
323 return 0;
324 }
325