annotate Plot.c @ 18:721d817f171e

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