Repository navigation
Expand file tree
/
Copy pathgui_navigation.cpp
More file actions
237 lines (224 loc) · 8.11 KB
/
Copy pathgui_navigation.cpp
File metadata and controls
237 lines (224 loc) · 8.11 KB
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
// Navigation: native viewer implementation.
#include "gui_navigation.hpp"
#include "gui_frf.hpp"
#include "gui_frf_render.hpp"
#include "gui_menu.hpp"
#include "gui_render.hpp"
#include "gui_render_data.hpp"
#include "gui_spectrum.hpp"
#include "gui_state.hpp"
#include "gui_status.hpp"
#include "gui_time_axis.hpp"
namespace gui {
void clamp_range(double& lo, double& hi, double minb, double maxb, double minw) {
double w = hi - lo;
const double full = maxb - minb;
if (w < minw) w = minw;
if (w > full) w = full;
if (lo < minb) lo = minb;
hi = lo + w;
if (hi > maxb) { hi = maxb; lo = hi - w; if (lo < minb) lo = minb; }
}
bool active_axis(double*& lo, double*& hi, double& minb, double& maxb, double& minw) {
if (g.mode == AnalysisMode::FRF) {
if (!g.frf.result.ok || g.frf.pending) return false;
if (g.frf.logarithmic_frequency_axis) {
lo = &g.frf.log_start; hi = &g.frf.log_end;
minb = std::log10(g.frf.result.common().frequencies[1]);
maxb = std::log10(g.frf.result.common().frequencies.back());
} else {
lo=&g.frf.frequency_start; hi=&g.frf.frequency_end;
minb=g.frf.result.common().frequencies[1]; maxb=g.frf.result.common().frequencies.back();
}
minw = std::min(1e-6, (maxb-minb)*.01);
return true;
}
if ((g.mode == AnalysisMode::FFT)) {
if (!ensure_current_spectrum() || g.spec.bin_count() < 2) return false;
lo = &g.freq_start; hi = &g.freq_end;
minb = 0.0; maxb = g.spec.nyquist;
minw = (g.spec.frequency(1) - g.spec.frequency(0)) * 0.5;
return true;
}
if (!has_data()) return false;
lo = &g.win_start; hi = &g.win_end;
minb = g.data_t0; maxb = g.data_t1;
minw = std::max(g.approx_dt * 0.5, (g.data_t1 - g.data_t0) * 1e-6);
return true;
}
void zoom_at(double center_frac, double factor) {
double *lo, *hi, minb, maxb, minw;
if (!active_axis(lo, hi, minb, maxb, minw)) return;
const bool stitched=g.mode==AnalysisMode::Time && g.stitch_time_gaps;
const double initial_lo=stitched ? stitched_time_from_raw(*lo) : *lo;
const double initial_hi=stitched ? stitched_time_from_raw(*hi) : *hi;
if(stitched){minb=stitched_time_from_raw(minb);maxb=stitched_time_from_raw(maxb);}
const double w = initial_hi - initial_lo;
const double c = initial_lo + w * center_frac;
double nw = w * factor;
if (nw < minw) nw = minw;
const double full = maxb - minb;
if (nw > full) nw = full;
double nlo = c - nw * center_frac;
double nhi = nlo + nw;
if (nlo < minb) { nlo = minb; nhi = nlo + nw; }
if (nhi > maxb) { nhi = maxb; nlo = nhi - nw; if (nlo < minb) nlo = minb; }
*lo = stitched ? raw_time_from_stitched(nlo) : nlo;
*hi = stitched ? raw_time_from_stitched(nhi) : nhi;
if (g.mode==AnalysisMode::FRF) sync_frf_frequency_limits();
set_status();
invalidate_plot();
}
void zoom_y_at(double center_frac, double factor) {
if (g.mode == AnalysisMode::FRF) {
double lo, hi; frf_y_range(lo, hi);
(void)center_frac;
const double width = std::clamp(hi*factor, 1e-6, 1e6);
g.frf.y_min = 0.0; g.frf.y_max = width;
g.frf.auto_y = false; set_status(); invalidate_plot(); return;
}
if (!has_data()) return;
double ymin, ymax;
current_time_yrange(ymin, ymax);
if (!g.auto_y) { ymin = g.y_lock_min; ymax = g.y_lock_max; }
const double w = ymax - ymin;
if (w <= 0) return;
const double c = ymin + w * center_frac;
double nw = w * factor;
const double minw = std::max(1e-12, w * 1e-6);
if (nw < minw) nw = minw;
double nlo = c - nw * center_frac;
double nhi = nlo + nw;
g.y_lock_min = nlo;
g.y_lock_max = nhi;
g.auto_y = false;
if (g.autoy) { SendMessageW(g.autoy, BM_SETCHECK, BST_UNCHECKED, 0); InvalidateRect(g.autoy, nullptr, FALSE); }
sync_menu();
set_status();
invalidate_plot();
}
void zoom_y_amp_at(double center_frac, double factor) {
(void)center_frac;
double ymax = visible_spectrum_ymax();
if (ymax <= 0) ymax = 1.0;
double ytop = ymax * 1.08;
if (!g.auto_y_amp) ytop = g.y_amp_max;
const double w = ytop;
if (w <= 0) return;
double nw = w * factor;
const double minw = std::max(1e-12, w * 1e-6);
if (nw < minw) nw = minw;
g.y_amp_max = nw;
g.auto_y_amp = false;
set_status();
invalidate_plot();
}
void pan_by(double frac) {
double *lo, *hi, minb, maxb, minw;
if (!active_axis(lo, hi, minb, maxb, minw)) return;
const bool stitched=g.mode==AnalysisMode::Time && g.stitch_time_gaps;
double a=stitched ? stitched_time_from_raw(*lo) : *lo,b=stitched ? stitched_time_from_raw(*hi) : *hi;
if(stitched){minb=stitched_time_from_raw(minb);maxb=stitched_time_from_raw(maxb);}
const double w=b-a;a+=w*frac;b+=w*frac;clamp_range(a,b,minb,maxb,minw);
*lo=stitched ? raw_time_from_stitched(a) : a;
*hi=stitched ? raw_time_from_stitched(b) : b;
if (g.mode==AnalysisMode::FRF) sync_frf_frequency_limits();
set_status();
invalidate_plot();
}
bool prepare_plot_drag(int mx, int my) {
double *lo, *hi, minb, maxb, minw;
if (!active_axis(lo, hi, minb, maxb, minw)) return false;
g.drag_x = mx;
g.drag_y = my;
g.drag_lo = *lo;
g.drag_hi = *hi;
if(g.mode==AnalysisMode::Time && g.stitch_time_gaps){g.drag_lo=stitched_time_from_raw(g.drag_lo);g.drag_hi=stitched_time_from_raw(g.drag_hi);}
if (g.mode == AnalysisMode::FRF) { frf_y_range(g.drag_y_lo, g.drag_y_hi); return true; }
if ((g.mode == AnalysisMode::FFT)) {
if (g.auto_y_amp) {
double ymax = visible_spectrum_ymax();
if (ymax <= 0) ymax = 1.0;
g.drag_y_hi = ymax * 1.08;
} else {
g.drag_y_hi = g.y_amp_max;
}
g.drag_y_lo = 0.0;
} else {
if (g.auto_y) {
current_time_yrange(g.drag_y_lo, g.drag_y_hi);
} else {
g.drag_y_lo = g.y_lock_min;
g.drag_y_hi = g.y_lock_max;
}
}
return true;
}
void pan_y_by(double frac) {
if (g.mode == AnalysisMode::FRF) {
double lo, hi; frf_y_range(lo, hi);
const double shift = hi*frac;
g.frf.y_min = 0.0; g.frf.y_max = std::max(1e-6,hi+shift); g.frf.auto_y = false;
set_status(); invalidate_plot(); return;
}
if ((g.mode == AnalysisMode::FFT)) {
double ymax = visible_spectrum_ymax();
if (ymax <= 0) ymax = 1.0;
double ytop = ymax * 1.08;
if (!g.auto_y_amp) ytop = g.y_amp_max;
const double w = ytop;
const double shift = w * frac;
g.y_amp_max = ytop + shift;
if (g.y_amp_max < 1e-12) g.y_amp_max = 1e-12;
g.auto_y_amp = false;
set_status();
invalidate_plot();
return;
}
if (!has_data()) return;
double ymin, ymax;
current_time_yrange(ymin, ymax);
if (g.auto_y) {
g.y_lock_min = ymin;
g.y_lock_max = ymax;
g.auto_y = false;
if (g.autoy) { SendMessageW(g.autoy, BM_SETCHECK, BST_UNCHECKED, 0); InvalidateRect(g.autoy, nullptr, FALSE); }
sync_menu();
}
const double w = g.y_lock_max - g.y_lock_min;
const double shift = w * frac;
g.y_lock_min += shift;
g.y_lock_max += shift;
set_status();
invalidate_plot();
}
void goto_start() {
double *lo, *hi, minb, maxb, minw;
if (!active_axis(lo, hi, minb, maxb, minw)) return;
const double w = *hi - *lo;
*lo = minb;
*hi = minb + w;
if (*hi > maxb) { *hi = maxb; *lo = maxb - w; if (*lo < minb) *lo = minb; }
set_status();
invalidate_plot();
}
void goto_end() {
double *lo, *hi, minb, maxb, minw;
if (!active_axis(lo, hi, minb, maxb, minw)) return;
const double w = *hi - *lo;
*hi = maxb;
*lo = maxb - w;
if (*lo < minb) { *lo = minb; *hi = minb + w; if (*hi > maxb) *hi = maxb; }
set_status();
invalidate_plot();
}
void reset_view() {
if (g.mode == AnalysisMode::FRF) { reset_frf_view(); return; }
g.win_start = g.data_t0;
g.win_end = g.data_t1;
g.freq_start = 0.0;
g.freq_end = g.spec_valid ? g.spec.nyquist : 1.0;
set_status();
invalidate_plot();
}
} // namespace gui