38DashboardInstrument_BaroHistory::DashboardInstrument_BaroHistory(
39 wxWindow* parent, wxWindowID
id, wxString title,
42 SetDrawSoloInPane(
true);
45 m_min_press = (double)1200;
46 m_total_max_press = 0;
47 m_total_min_press = 1200;
54 f = m_Properties->m_DataFont.GetChosenFont();
56 f = g_pFontData->GetChosenFont();
57 dc.GetTextExtent(
"hPa----", &w, &h, 0, 0, &f);
58 m_top_line_height = wxMax(30, h);
66 for (
int idx = 0; idx < BARO_RECORD_COUNT; idx++) {
67 m_array_press_history[idx] = -1;
68 m_exp_smooth_array_pressure[idx] = -1;
69 m_array_rec_time[idx] = wxDateTime::Now().GetTm();
70 m_array_rec_time[idx].year = 999;
73 m_window_rect = GetClientRect();
74 m_draw_area_rect = GetClientRect();
75 m_draw_area_rect.SetHeight(m_window_rect.height - m_top_line_height -
79wxSize DashboardInstrument_BaroHistory::GetSize(
int orient, wxSize hint) {
84 f = m_Properties->m_TitleFont.GetChosenFont();
86 f = g_pFontTitle->GetChosenFont();
87 dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, &f);
88 if (orient == wxHORIZONTAL) {
89 return wxSize(DefaultWidth, wxMax(m_TitleHeight + 140, hint.y));
91 return wxSize(wxMax(hint.x, DefaultWidth),
92 wxMax(m_TitleHeight + 140, hint.y));
95void DashboardInstrument_BaroHistory::SetData(
DASH_CAP st,
double data,
98 if (m_set_new_data < 1) {
100 if (m_spd_rec_cnt++ <= 5) m_spd_start_val += data;
102 if (m_spd_rec_cnt == 5) {
103 m_press = m_spd_start_val / 5;
107 if (m_spd_rec_cnt > 5) {
109 m_sample_count = m_sample_count < BARO_RECORD_COUNT ? m_sample_count + 1
114 for (
int idx = 1; idx < BARO_RECORD_COUNT; idx++) {
115 if (BARO_RECORD_COUNT - m_sample_count <= idx)
116 m_max_press = wxMax(m_array_press_history[idx - 1], m_max_press);
117 m_min_press = wxMin(m_array_press_history[idx - 1], m_min_press);
118 m_array_press_history[idx - 1] = m_array_press_history[idx];
119 m_exp_smooth_array_pressure[idx - 1] =
120 m_exp_smooth_array_pressure[idx];
121 m_array_rec_time[idx - 1] = m_array_rec_time[idx];
123 m_array_press_history[BARO_RECORD_COUNT - 1] = m_press;
124 if (m_sample_count < 2) {
125 m_array_press_history[BARO_RECORD_COUNT - 2] = m_press;
126 m_exp_smooth_array_pressure[BARO_RECORD_COUNT - 2] = m_press;
128 m_exp_smooth_array_pressure[BARO_RECORD_COUNT - 1] =
129 alpha * m_array_press_history[BARO_RECORD_COUNT - 2] +
130 (1 - alpha) * m_exp_smooth_array_pressure[BARO_RECORD_COUNT - 2];
131 m_array_rec_time[BARO_RECORD_COUNT - 1] = wxDateTime::Now().GetTm();
132 m_max_press = wxMax(m_press, m_max_press);
134 m_min_press = wxMin(m_min_press, m_press);
135 if (wxMin(m_press, m_min_press) == -1) {
136 m_min_press = wxMin(m_press, 1200);
139 m_total_max_press = wxMax(m_press, m_total_max_press);
140 m_total_min_press = wxMin(m_press, m_total_min_press);
148 if (isnan(data)) m_press = data;
152void DashboardInstrument_BaroHistory::Draw(wxGCDC* dc) {
153 m_window_rect = GetClientRect();
154 m_draw_area_rect = GetClientRect();
155 m_draw_area_rect.SetHeight(m_window_rect.height - m_top_line_height -
157 m_draw_area_rect.SetX(m_left_legend + 3);
165void DashboardInstrument_BaroHistory::DrawWindSpeedScale(wxGCDC* dc) {
166 wxString label1, label2, label3, label4, label5;
169 cl = wxColour(61, 61, 204, 255);
171 dc->SetTextForeground(
172 GetColourSchemeFont(m_Properties->m_SmallFont.GetColour()));
173 dc->SetFont(m_Properties->m_SmallFont.GetChosenFont());
175 dc->SetTextForeground(GetColourSchemeFont(g_pFontSmall->GetColour()));
176 dc->SetFont(g_pFontSmall->GetChosenFont());
179 if (m_max_press > 1100) m_max_press = 1100;
181 if (m_total_min_press < 930) m_total_min_press = 930;
183 m_max_press_scale = (int)((m_max_press + 15) - (m_total_min_press - 15));
196 label1.Printf(
"%.0f hPa", m_max_press_scale + (m_total_min_press - 18));
200 label2.Printf(
"%.0f hPa",
201 m_max_press_scale * 3. / 4 + (m_total_min_press - 18));
205 label3.Printf(
"%.0f hPa", m_max_press_scale / 2 + (m_total_min_press - 18));
209 label4.Printf(
"%.0f hPa", m_max_press_scale / 4 + (m_total_min_press - 18));
212 label5.Printf(
"%.0f hPa", (m_total_min_press - 18));
216 f = m_Properties->m_SmallFont.GetChosenFont();
218 f = g_pFontSmall->GetChosenFont();
219 dc->GetTextExtent(label1, &m_left_legend, &height, 0, 0, &f);
220 dc->DrawText(label1, 4, (
int)(m_top_line_height - height / 2));
222 f = m_Properties->m_SmallFont.GetChosenFont();
224 f = g_pFontSmall->GetChosenFont();
225 dc->GetTextExtent(label2, &width, &height, 0, 0, &f);
228 (
int)(m_top_line_height + m_draw_area_rect.height / 4 - height / 2));
229 m_left_legend = wxMax(width, m_left_legend);
231 f = m_Properties->m_SmallFont.GetChosenFont();
233 f = g_pFontSmall->GetChosenFont();
234 dc->GetTextExtent(label3, &width, &height, 0, 0, &f);
237 (
int)(m_top_line_height + m_draw_area_rect.height / 2 - height / 2));
238 m_left_legend = wxMax(width, m_left_legend);
240 f = m_Properties->m_SmallFont.GetChosenFont();
242 f = g_pFontSmall->GetChosenFont();
243 dc->GetTextExtent(label4, &width, &height, 0, 0, &f);
246 (
int)(m_top_line_height + m_draw_area_rect.height * 0.75 - height / 2));
247 m_left_legend = wxMax(width, m_left_legend);
249 f = m_Properties->m_SmallFont.GetChosenFont();
251 f = g_pFontSmall->GetChosenFont();
252 dc->GetTextExtent(label5, &width, &height, 0, 0, &f);
253 dc->DrawText(label5, 4,
254 (
int)(m_top_line_height + m_draw_area_rect.height - height / 2));
255 m_left_legend = wxMax(width, m_left_legend);
262void DashboardInstrument_BaroHistory::DrawBackground(wxGCDC* dc) {
263 wxString label, label1, label2, label3, label4, label5;
270 DrawWindSpeedScale(dc);
275 GetGlobalColor(
"UBLCK", &cl);
278 dc->DrawLine(m_left_legend + 3, m_top_line_height,
279 m_window_rect.width - 3 - m_right_legend,
281 dc->DrawLine(m_left_legend + 3,
282 (
int)(m_top_line_height + m_draw_area_rect.height),
283 m_window_rect.width - 3 - m_right_legend,
284 (
int)(m_top_line_height + m_draw_area_rect.height));
285 pen.SetStyle(wxPENSTYLE_DOT);
287 dc->DrawLine(m_left_legend + 3,
288 (
int)(m_top_line_height + m_draw_area_rect.height * 0.25),
289 m_window_rect.width - 3 - m_right_legend,
290 (
int)(m_top_line_height + m_draw_area_rect.height * 0.25));
291 dc->DrawLine(m_left_legend + 3,
292 (
int)(m_top_line_height + m_draw_area_rect.height * 0.75),
293 m_window_rect.width - 3 - m_right_legend,
294 (
int)(m_top_line_height + m_draw_area_rect.height * 0.75));
296 pen.SetStyle(wxPENSTYLE_SHORT_DASH);
299 dc->DrawLine(m_left_legend + 3,
300 (
int)(m_top_line_height + m_draw_area_rect.height * 0.5),
301 m_window_rect.width - 3 - m_right_legend,
302 (
int)(m_top_line_height + m_draw_area_rect.height * 0.5));
308void DashboardInstrument_BaroHistory::DrawForeground(wxGCDC* dc) {
312 int width, height, min, hour;
313 wxString WindAngle, WindSpeed;
323 dc->SetFont(m_Properties->m_DataFont.GetChosenFont());
324 dc->SetTextForeground(
325 GetColourSchemeFont(m_Properties->m_DataFont.GetColour()));
327 dc->SetFont(g_pFontData->GetChosenFont());
328 dc->SetTextForeground(GetColourSchemeFont(g_pFontData->GetColour()));
330 if (!std::isnan(m_press))
331 WindSpeed = wxString::Format(
"hPa %3.1f ", m_press);
333 WindSpeed = wxString::Format(
"hPa --- ");
335 f = m_Properties->m_DataFont.GetChosenFont();
337 f = g_pFontData->GetChosenFont();
338 dc->GetTextExtent(WindSpeed, °w, °h, 0, 0, &f);
340 dc->DrawText(WindSpeed, m_left_legend + 3, 1);
342 dc->SetFont(m_Properties->m_LabelFont.GetChosenFont());
343 dc->SetTextForeground(
344 GetColourSchemeFont(m_Properties->m_LabelFont.GetColour()));
346 dc->SetFont(g_pFontLabel->GetChosenFont());
347 dc->SetTextForeground(GetColourSchemeFont(g_pFontLabel->GetColour()));
351 f = m_Properties->m_LabelFont.GetChosenFont();
353 f = g_pFontLabel->GetChosenFont();
354 dc->GetTextExtent(WindSpeed, &labelw, &labelh, 0, 0, &f);
357 while (m_array_rec_time[i].year == 999 && i < BARO_RECORD_COUNT - 1) i++;
358 if (i == BARO_RECORD_COUNT - 1) {
363 wxDateTime localTime(m_array_rec_time[i]);
364 min = localTime.GetMinute();
365 hour = localTime.GetHour();
367 m_draw_area_rect.SetWidth(m_window_rect.width - 3 - m_left_legend -
369 m_ratio_w = double(m_draw_area_rect.width) / (BARO_RECORD_COUNT - 1);
373 _(
" Max %.1f since %02d:%02d Overall Max %.1f Min %.1f "),
374 m_max_press, hour, min, m_total_max_press, m_total_min_press),
375 m_left_legend + 2 + degw, m_top_line_height - 2 - labelh);
376 pen.SetStyle(wxPENSTYLE_SOLID);
377 pen.SetColour(wxColour(61, 61, 204, 255));
380 ratioH = (double)m_draw_area_rect.height / (
double)m_max_press_scale;
382 wxPoint pointsSpd[BARO_RECORD_COUNT + 2];
383 wxPoint bdDraw[BARO_RECORD_COUNT + 2];
385 bdDraw[ls].x = 1 * m_ratio_w + 3 + m_left_legend;
387 m_top_line_height + m_draw_area_rect.height -
388 ((m_array_press_history[1] - (double)m_total_min_press + 18) * ratioH);
394 for (
int idx = 1; idx < BARO_RECORD_COUNT; idx++) {
395 pointsSpd[idx].x = idx * m_ratio_w + 3 + m_left_legend;
398 m_top_line_height + m_draw_area_rect.height -
399 ((m_exp_smooth_array_pressure[idx] - m_total_min_press + 18.0) *
401 if (BARO_RECORD_COUNT - m_sample_count <= idx &&
402 pointsSpd[idx].y > m_top_line_height &&
403 pointsSpd[idx].y <= m_top_line_height + m_draw_area_rect.height) {
404 bdDraw[ls] = pointsSpd[idx];
408 if (ls > 1) dc->DrawLines(ls, bdDraw);
437 GetGlobalColor(
"DASHL", &col);
439 pen.SetStyle(wxPENSTYLE_DOT);
441 dc->SetTextForeground(col);
442 dc->SetFont((g_pFontSmall->GetChosenFont()));
445 for (
int idx = 0; idx < BARO_RECORD_COUNT; idx++) {
446 if (m_array_rec_time[idx].year != 999) {
447 wxDateTime localTime(m_array_rec_time[idx]);
448 hour = localTime.GetHour();
449 min = localTime.GetMinute();
450 if ((hour * 100 + min) != done && (min == 0)) {
451 pointTime.x = idx * m_ratio_w + 3 + m_left_legend;
452 dc->DrawLine(pointTime.x, m_top_line_height + 1, pointTime.x,
453 (m_top_line_height + m_draw_area_rect.height + 1));
454 label.Printf(
"%02d:%02d", hour, min);
455 f = g_pFontSmall->GetChosenFont();
456 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
457 dc->DrawText(label, pointTime.x - width / 2,
458 m_window_rect.height - height);
459 done = hour * 100 + min;
Dashboard barometer history instrument.
@ OCPN_DBP_STC_MDA
Barometic pressure.