34#include "baro_history.h"
44DashboardInstrument_BaroHistory::DashboardInstrument_BaroHistory(
45 wxWindow* parent, wxWindowID
id, wxString title,
48 SetDrawSoloInPane(
true);
51 m_MinPress = (double)1200;
53 m_TotalMinPress = 1200;
60 f = m_Properties->m_DataFont.GetChosenFont();
62 f = g_pFontData->GetChosenFont();
63 dc.GetTextExtent(
"hPa----", &w, &h, 0, 0, &f);
64 m_TopLineHeight = wxMax(30, h);
72 for (
int idx = 0; idx < BARO_RECORD_COUNT; idx++) {
73 m_ArrayPressHistory[idx] = -1;
74 m_ExpSmoothArrayPressure[idx] = -1;
75 m_ArrayRecTime[idx] = wxDateTime::Now().GetTm();
76 m_ArrayRecTime[idx].year = 999;
79 m_WindowRect = GetClientRect();
80 m_DrawAreaRect = GetClientRect();
81 m_DrawAreaRect.SetHeight(m_WindowRect.height - m_TopLineHeight -
85wxSize DashboardInstrument_BaroHistory::GetSize(
int orient, wxSize hint) {
90 f = m_Properties->m_TitleFont.GetChosenFont();
92 f = g_pFontTitle->GetChosenFont();
93 dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, &f);
94 if (orient == wxHORIZONTAL) {
95 return wxSize(DefaultWidth, wxMax(m_TitleHeight + 140, hint.y));
97 return wxSize(wxMax(hint.x, DefaultWidth),
98 wxMax(m_TitleHeight + 140, hint.y));
101void DashboardInstrument_BaroHistory::SetData(DASH_CAP st,
double data,
103 if (st == OCPN_DBP_STC_MDA && data > 700.0 && data < 2000.0) {
104 if (m_SetNewData < 1) {
106 if (m_SpdRecCnt++ <= 5) m_SpdStartVal += data;
108 if (m_SpdRecCnt == 5) {
109 m_Press = m_SpdStartVal / 5;
113 if (m_SpdRecCnt > 5) {
115 m_SampleCount = m_SampleCount < BARO_RECORD_COUNT ? m_SampleCount + 1
120 for (
int idx = 1; idx < BARO_RECORD_COUNT; idx++) {
121 if (BARO_RECORD_COUNT - m_SampleCount <= idx)
122 m_MaxPress = wxMax(m_ArrayPressHistory[idx - 1], m_MaxPress);
123 m_MinPress = wxMin(m_ArrayPressHistory[idx - 1], m_MinPress);
124 m_ArrayPressHistory[idx - 1] = m_ArrayPressHistory[idx];
125 m_ExpSmoothArrayPressure[idx - 1] = m_ExpSmoothArrayPressure[idx];
126 m_ArrayRecTime[idx - 1] = m_ArrayRecTime[idx];
128 m_ArrayPressHistory[BARO_RECORD_COUNT - 1] = m_Press;
129 if (m_SampleCount < 2) {
130 m_ArrayPressHistory[BARO_RECORD_COUNT - 2] = m_Press;
131 m_ExpSmoothArrayPressure[BARO_RECORD_COUNT - 2] = m_Press;
133 m_ExpSmoothArrayPressure[BARO_RECORD_COUNT - 1] =
134 alpha * m_ArrayPressHistory[BARO_RECORD_COUNT - 2] +
135 (1 - alpha) * m_ExpSmoothArrayPressure[BARO_RECORD_COUNT - 2];
136 m_ArrayRecTime[BARO_RECORD_COUNT - 1] = wxDateTime::Now().GetTm();
137 m_MaxPress = wxMax(m_Press, m_MaxPress);
139 m_MinPress = wxMin(m_MinPress, m_Press);
140 if (wxMin(m_Press, m_MinPress) == -1) {
141 m_MinPress = wxMin(m_Press, 1200);
144 m_TotalMaxPress = wxMax(m_Press, m_TotalMaxPress);
145 m_TotalMinPress = wxMin(m_Press, m_TotalMinPress);
153 if (isnan(data)) m_Press = data;
157void DashboardInstrument_BaroHistory::Draw(wxGCDC* dc) {
158 m_WindowRect = GetClientRect();
159 m_DrawAreaRect = GetClientRect();
160 m_DrawAreaRect.SetHeight(m_WindowRect.height - m_TopLineHeight -
162 m_DrawAreaRect.SetX(m_LeftLegend + 3);
170void DashboardInstrument_BaroHistory::DrawWindSpeedScale(wxGCDC* dc) {
171 wxString label1, label2, label3, label4, label5;
174 cl = wxColour(61, 61, 204, 255);
176 dc->SetTextForeground(
177 GetColourSchemeFont(m_Properties->m_SmallFont.GetColour()));
178 dc->SetFont(m_Properties->m_SmallFont.GetChosenFont());
180 dc->SetTextForeground(GetColourSchemeFont(g_pFontSmall->GetColour()));
181 dc->SetFont(g_pFontSmall->GetChosenFont());
184 if (m_MaxPress > 1100) m_MaxPress = 1100;
186 if (m_TotalMinPress < 930) m_TotalMinPress = 930;
188 m_MaxPressScale = (int)((m_MaxPress + 15) - (m_TotalMinPress - 15));
191 label1 = _T(
"-- hPa");
192 label2 = _T(
"-- hPa");
193 label3 = _T(
"-- hPa");
194 label4 = _T(
"-- hPa");
195 label5 = _T(
"-- hPa");
201 label1.Printf(_T(
"%.0f hPa"), m_MaxPressScale + (m_TotalMinPress - 18));
205 label2.Printf(_T(
"%.0f hPa"),
206 m_MaxPressScale * 3. / 4 + (m_TotalMinPress - 18));
210 label3.Printf(_T(
"%.0f hPa"), m_MaxPressScale / 2 + (m_TotalMinPress - 18));
214 label4.Printf(_T(
"%.0f hPa"), m_MaxPressScale / 4 + (m_TotalMinPress - 18));
217 label5.Printf(_T(
"%.0f hPa"), (m_TotalMinPress - 18));
221 f = m_Properties->m_SmallFont.GetChosenFont();
223 f = g_pFontSmall->GetChosenFont();
224 dc->GetTextExtent(label1, &m_LeftLegend, &height, 0, 0, &f);
225 dc->DrawText(label1, 4, (
int)(m_TopLineHeight - height / 2));
227 f = m_Properties->m_SmallFont.GetChosenFont();
229 f = g_pFontSmall->GetChosenFont();
230 dc->GetTextExtent(label2, &width, &height, 0, 0, &f);
231 dc->DrawText(label2, 4,
232 (
int)(m_TopLineHeight + m_DrawAreaRect.height / 4 - height / 2));
233 m_LeftLegend = wxMax(width, m_LeftLegend);
235 f = m_Properties->m_SmallFont.GetChosenFont();
237 f = g_pFontSmall->GetChosenFont();
238 dc->GetTextExtent(label3, &width, &height, 0, 0, &f);
239 dc->DrawText(label3, 4,
240 (
int)(m_TopLineHeight + m_DrawAreaRect.height / 2 - height / 2));
241 m_LeftLegend = wxMax(width, m_LeftLegend);
243 f = m_Properties->m_SmallFont.GetChosenFont();
245 f = g_pFontSmall->GetChosenFont();
246 dc->GetTextExtent(label4, &width, &height, 0, 0, &f);
249 (
int)(m_TopLineHeight + m_DrawAreaRect.height * 0.75 - height / 2));
250 m_LeftLegend = wxMax(width, m_LeftLegend);
252 f = m_Properties->m_SmallFont.GetChosenFont();
254 f = g_pFontSmall->GetChosenFont();
255 dc->GetTextExtent(label5, &width, &height, 0, 0, &f);
256 dc->DrawText(label5, 4,
257 (
int)(m_TopLineHeight + m_DrawAreaRect.height - height / 2));
258 m_LeftLegend = wxMax(width, m_LeftLegend);
265void DashboardInstrument_BaroHistory::DrawBackground(wxGCDC* dc) {
266 wxString label, label1, label2, label3, label4, label5;
273 DrawWindSpeedScale(dc);
278 GetGlobalColor(_T(
"UBLCK"), &cl);
281 dc->DrawLine(m_LeftLegend + 3, m_TopLineHeight,
282 m_WindowRect.width - 3 - m_RightLegend,
284 dc->DrawLine(m_LeftLegend + 3, (
int)(m_TopLineHeight + m_DrawAreaRect.height),
285 m_WindowRect.width - 3 - m_RightLegend,
286 (
int)(m_TopLineHeight + m_DrawAreaRect.height));
287 pen.SetStyle(wxPENSTYLE_DOT);
289 dc->DrawLine(m_LeftLegend + 3,
290 (
int)(m_TopLineHeight + m_DrawAreaRect.height * 0.25),
291 m_WindowRect.width - 3 - m_RightLegend,
292 (
int)(m_TopLineHeight + m_DrawAreaRect.height * 0.25));
293 dc->DrawLine(m_LeftLegend + 3,
294 (
int)(m_TopLineHeight + m_DrawAreaRect.height * 0.75),
295 m_WindowRect.width - 3 - m_RightLegend,
296 (
int)(m_TopLineHeight + m_DrawAreaRect.height * 0.75));
298 pen.SetStyle(wxPENSTYLE_SHORT_DASH);
301 dc->DrawLine(m_LeftLegend + 3,
302 (
int)(m_TopLineHeight + m_DrawAreaRect.height * 0.5),
303 m_WindowRect.width - 3 - m_RightLegend,
304 (
int)(m_TopLineHeight + m_DrawAreaRect.height * 0.5));
310void DashboardInstrument_BaroHistory::DrawForeground(wxGCDC* dc) {
314 int width, height, min, hour;
315 wxString WindAngle, WindSpeed;
325 dc->SetFont(m_Properties->m_DataFont.GetChosenFont());
326 dc->SetTextForeground(
327 GetColourSchemeFont(m_Properties->m_DataFont.GetColour()));
329 dc->SetFont(g_pFontData->GetChosenFont());
330 dc->SetTextForeground(GetColourSchemeFont(g_pFontData->GetColour()));
332 if (!std::isnan(m_Press))
333 WindSpeed = wxString::Format(_T(
"hPa %3.1f "), m_Press);
335 WindSpeed = wxString::Format(_T(
"hPa --- "));
337 f = m_Properties->m_DataFont.GetChosenFont();
339 f = g_pFontData->GetChosenFont();
340 dc->GetTextExtent(WindSpeed, °w, °h, 0, 0, &f);
342 dc->DrawText(WindSpeed, m_LeftLegend + 3, 1);
344 dc->SetFont(m_Properties->m_LabelFont.GetChosenFont());
345 dc->SetTextForeground(
346 GetColourSchemeFont(m_Properties->m_LabelFont.GetColour()));
348 dc->SetFont(g_pFontLabel->GetChosenFont());
349 dc->SetTextForeground(GetColourSchemeFont(g_pFontLabel->GetColour()));
353 f = m_Properties->m_LabelFont.GetChosenFont();
355 f = g_pFontLabel->GetChosenFont();
356 dc->GetTextExtent(WindSpeed, &labelw, &labelh, 0, 0, &f);
359 while (m_ArrayRecTime[i].year == 999 && i < BARO_RECORD_COUNT - 1) i++;
360 if (i == BARO_RECORD_COUNT - 1) {
365 wxDateTime localTime(m_ArrayRecTime[i]);
366 min = localTime.GetMinute();
367 hour = localTime.GetHour();
369 m_DrawAreaRect.SetWidth(m_WindowRect.width - 3 - m_LeftLegend -
371 m_ratioW = double(m_DrawAreaRect.width) / (BARO_RECORD_COUNT - 1);
373 dc->DrawText(wxString::Format(
374 _(
" Max %.1f since %02d:%02d Overall Max %.1f Min %.1f "),
375 m_MaxPress, hour, min, m_TotalMaxPress, m_TotalMinPress),
376 m_LeftLegend + 2 + degw, m_TopLineHeight - 2 - labelh);
377 pen.SetStyle(wxPENSTYLE_SOLID);
378 pen.SetColour(wxColour(61, 61, 204, 255));
381 ratioH = (double)m_DrawAreaRect.height / (
double)m_MaxPressScale;
383 wxPoint pointsSpd[BARO_RECORD_COUNT + 2];
384 wxPoint bdDraw[BARO_RECORD_COUNT + 2];
386 bdDraw[ls].x = 1 * m_ratioW + 3 + m_LeftLegend;
388 m_TopLineHeight + m_DrawAreaRect.height -
389 ((m_ArrayPressHistory[1] - (double)m_TotalMinPress + 18) * ratioH);
395 for (
int idx = 1; idx < BARO_RECORD_COUNT; idx++) {
396 pointsSpd[idx].x = idx * m_ratioW + 3 + m_LeftLegend;
399 m_TopLineHeight + m_DrawAreaRect.height -
400 ((m_ExpSmoothArrayPressure[idx] - m_TotalMinPress + 18.0) * ratioH);
401 if (BARO_RECORD_COUNT - m_SampleCount <= idx &&
402 pointsSpd[idx].y > m_TopLineHeight &&
403 pointsSpd[idx].y <= m_TopLineHeight + m_DrawAreaRect.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_ArrayRecTime[idx].year != 999) {
447 wxDateTime localTime(m_ArrayRecTime[idx]);
448 hour = localTime.GetHour();
449 min = localTime.GetMinute();
450 if ((hour * 100 + min) != done && (min == 0)) {
451 pointTime.x = idx * m_ratioW + 3 + m_LeftLegend;
452 dc->DrawLine(pointTime.x, m_TopLineHeight + 1, pointTime.x,
453 (m_TopLineHeight + m_DrawAreaRect.height + 1));
454 label.Printf(_T(
"%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_WindowRect.height - height);
459 done = hour * 100 + min;