43extern int g_iDashDepthUnit;
50int x_alabel, y_alabel, a_plotdown, a_plotup, a_plotheight;
52DashboardInstrument_Altitude::DashboardInstrument_Altitude(
53 wxWindow* parent, wxWindowID
id, wxString title,
56 m_cap_flag.set(OCPN_DBP_STC_TMP);
61 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT; idx++) {
62 m_ArrayAltitude[idx] = 0.0;
66wxSize DashboardInstrument_Altitude::GetSize(
int orient, wxSize hint) {
71 f = m_Properties->m_TitleFont.GetChosenFont();
72 dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, &f);
73 f = m_Properties->m_DataFont.GetChosenFont();
74 dc.GetTextExtent(
"15.7 Feet", &w, &m_aDataHeight, 0, 0, &f);
75 f = m_Properties->m_LabelFont.GetChosenFont();
76 dc.GetTextExtent(
"20.8 C", &x_alabel, &y_alabel, 0, 0, &f);
78 f = g_pFontTitle->GetChosenFont();
79 dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, &f);
80 f = g_pFontData->GetChosenFont();
81 dc.GetTextExtent(
"15.7 Feet", &w, &m_aDataHeight, 0, 0, &f);
83 f = g_pFontLabel->GetChosenFont();
84 dc.GetTextExtent(
"20.8 C", &x_alabel, &y_alabel, 0, 0, &f);
88 m_TitleHeight + m_aDataHeight + 4 * m_aDataHeight + y_alabel;
89 if (orient == wxHORIZONTAL) {
90 return wxSize(DefaultWidth, wxMax(y_total, hint.y));
92 return wxSize(wxMax(hint.x, DefaultWidth), y_total);
96void DashboardInstrument_Altitude::SetData(DASH_CAP st,
double data,
98 if (st == OCPN_DBP_STC_ALTI) {
99 if (std::isnan(data)) {
105 if (m_cntValid < ALTITUDE_RECORD_COUNT && data != 0.0) m_cntValid++;
109 if (m_cntValid == 1) {
110 for (
int idx = 1; idx < ALTITUDE_RECORD_COUNT; idx++) {
111 m_ArrayAltitude[idx - 1] = m_Altitude;
114 for (
int idx = 1; idx < ALTITUDE_RECORD_COUNT; idx++) {
115 m_ArrayAltitude[idx - 1] = m_ArrayAltitude[idx];
118 m_ArrayAltitude[ALTITUDE_RECORD_COUNT - 1] = m_Altitude;
119 m_AltitudeUnit =
unit;
120 }
else if (st == OCPN_DBP_STC_ATMP) {
121 if (!std::isnan(data)) {
122 m_Temp = wxString::Format(_T(
"%.1f"), data) + DEGREE_SIGN +
unit;
129void DashboardInstrument_Altitude::setAttenuation(
int steps) {
134 switch (m_Attenuation) {
149 switch (m_Attenuation) {
168int DashboardInstrument_Altitude::getAttenuation() {
169 return m_Attenuation * m_Decade;
172void DashboardInstrument_Altitude::Draw(wxGCDC* dc) {
177void DashboardInstrument_Altitude::DrawBackground(wxGCDC* dc) {
178 wxSize size = GetClientSize();
181 dc->SetTextForeground(
182 GetColourSchemeFont(m_Properties->m_LabelFont.GetColour()));
184 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
185 GetColourSchemeFont(g_pFontLabel->GetColour())) {
186 GetGlobalColor(_T(
"DASHL"), &cl);
187 dc->SetTextForeground(cl);
189 dc->SetTextForeground(GetColourSchemeFont(g_pFontLabel->GetColour()));
193 pen.SetStyle(wxPENSTYLE_SOLID);
195 cl = GetColourSchemeFont(m_Properties->m_SmallFont.GetColour());
197 cl = GetColourSchemeFont(g_pFontSmall->GetColour());
203 a_plotup = m_TitleHeight + m_aDataHeight;
204 a_plotdown = size.y - y_alabel;
205 a_plotheight = a_plotdown - a_plotup;
208 dc->DrawLine(3, a_plotdown, size.x - 3, a_plotdown);
211 pen.SetStyle(wxPENSTYLE_SHORT_DASH);
213 pen.SetStyle(wxPENSTYLE_DOT);
219 dc->DrawLine(3, a_plotup, size.x - 3, a_plotup);
220 dc->DrawLine(3, a_plotup + a_plotheight / 4, size.x - 3,
221 a_plotup + a_plotheight / 4);
222 dc->DrawLine(3, a_plotup + a_plotheight * 2 / 4, size.x - 3,
223 a_plotup + a_plotheight * 2 / 4);
224 dc->DrawLine(3, a_plotup + a_plotheight * 3 / 4, size.x - 3,
225 a_plotup + a_plotheight * 3 / 4);
227 dc->SetFont(m_Properties->m_SmallFont.GetChosenFont());
228 dc->SetTextForeground(
229 GetColourSchemeFont(m_Properties->m_SmallFont.GetColour()));
231 dc->SetFont(g_pFontSmall->GetChosenFont());
232 dc->SetTextForeground(GetColourSchemeFont(g_pFontSmall->GetColour()));
236 m_meanAltitude = m_ArrayAltitude[0];
237 double MaxAltitude = m_ArrayAltitude[0];
238 double MinAltitude = m_ArrayAltitude[0];
239 double sum2Altitude = m_ArrayAltitude[0] * m_ArrayAltitude[0];
240 for (
int idx = 1; idx < ALTITUDE_RECORD_COUNT; idx++) {
241 MaxAltitude = std::max(MaxAltitude, m_ArrayAltitude[idx]);
242 MinAltitude = std::min(MinAltitude, m_ArrayAltitude[idx]);
243 m_meanAltitude += m_ArrayAltitude[idx];
244 sum2Altitude += m_ArrayAltitude[idx] * m_ArrayAltitude[idx];
246 m_meanAltitude /= ALTITUDE_RECORD_COUNT;
249 double varAltitude = sum2Altitude / ALTITUDE_RECORD_COUNT;
250 varAltitude -= m_meanAltitude * m_meanAltitude;
252 varAltitude *= (ALTITUDE_RECORD_COUNT / (ALTITUDE_RECORD_COUNT - 1.0));
254 if (varAltitude < 0.0) varAltitude = 0.0;
257 double range = MaxAltitude - MinAltitude;
258 if (range > 1.1 * m_Range) setAttenuation(+1);
259 if (range < 0.3 * m_Range) setAttenuation(-1);
260 double grid = getAttenuation();
261 m_Range = grid * c_GridLines;
264 if ((MaxAltitude - m_MaxAltitude) / grid > 0.25 ||
265 (MaxAltitude - m_MaxAltitude) / grid < -0.75 * c_GridLines) {
266 m_MaxAltitude = (round(MaxAltitude / grid) + 1) * grid;
267 m_MinAltitude = m_MaxAltitude - m_Range;
269 if ((MinAltitude - m_MinAltitude) / grid < -0.25 ||
270 (MinAltitude - m_MinAltitude) / grid > 0.75 * c_GridLines) {
271 m_MinAltitude = (round(MinAltitude / grid) - 1) * grid;
272 m_MaxAltitude = m_MinAltitude + m_Range;
281 label.Printf(_T(
"+/-%.1f %8.0f ") + m_AltitudeUnit, sqrt(varAltitude),
286 f = m_Properties->m_SmallFont.GetChosenFont();
288 f = g_pFontSmall->GetChosenFont();
289 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
290 dc->DrawText(label, size.x - width - 1, a_plotup - height);
292 label.Printf(_T(
"%.1f/ %8.0f ") + m_AltitudeUnit, m_Range / c_GridLines,
295 f = m_Properties->m_SmallFont.GetChosenFont();
297 f = g_pFontSmall->GetChosenFont();
298 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
299 dc->DrawText(label, size.x - width - 1, a_plotdown);
302void DashboardInstrument_Altitude::DrawForeground(wxGCDC* dc) {
303 wxSize size = GetClientSize();
306 cl = GetColourSchemeFont(m_Properties->m_LabelFont.GetColour());
308 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
309 GetColourSchemeFont(g_pFontLabel->GetColour()))
310 GetGlobalColor(_T(
"DASH1"), &cl);
312 cl = GetColourSchemeFont(g_pFontLabel->GetColour());
316 brush.SetStyle(wxBRUSHSTYLE_SOLID);
319 dc->SetPen(*wxTRANSPARENT_PEN);
321 double ratioH = double(a_plotheight) / m_Range;
322 double ratioW = double(size.x - 6) / (ALTITUDE_RECORD_COUNT - 1);
323 wxPoint points[ALTITUDE_RECORD_COUNT + 2];
324#ifdef __OCPN__ANDROID__
327 points[0].y = a_plotdown;
329 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT - 1; idx++) {
330 points[1].x = points[0].x;
331 if (m_ArrayAltitude[idx])
333 a_plotdown - (m_ArrayAltitude[idx] - m_MinAltitude) * ratioH;
335 points[1].y = a_plotdown;
337 points[2].x = points[1].x + ratioW;
338 if (m_ArrayAltitude[idx + 1])
340 a_plotdown - (m_ArrayAltitude[idx + 1] - m_MinAltitude) * ratioH;
342 points[2].y = a_plotdown;
344 points[3].x = points[2].x;
345 points[3].y = a_plotdown;
346 dc->DrawPolygon(4, points);
348 points[0].x = points[2].x;
349 points[0].y = a_plotdown;
353 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT; idx++) {
354 points[idx].x = idx * ratioW + 3;
356 a_plotdown - (m_ArrayAltitude[idx] - m_MinAltitude) * ratioH;
358 points[ALTITUDE_RECORD_COUNT].x = size.x - 3;
359 points[ALTITUDE_RECORD_COUNT].y = a_plotdown;
360 points[ALTITUDE_RECORD_COUNT + 1].x = 3;
361 points[ALTITUDE_RECORD_COUNT + 1].y = a_plotdown;
362 dc->DrawPolygon(ALTITUDE_RECORD_COUNT + 2, points);
365 dc->SetFont(m_Properties->m_DataFont.GetChosenFont());
366 dc->SetTextForeground(
367 GetColourSchemeFont(m_Properties->m_DataFont.GetColour()));
370 dc->SetTextForeground(GetColourSchemeFont(g_pFontData->GetColour()));
371 dc->SetFont(g_pFontData->GetChosenFont());
373 if (m_AltitudeUnit != _T(
"-")) {
374 wxString s_alti = wxString::Format(_T(
"%.1f"), m_meanAltitude);
375 dc->DrawText(s_alti + _T(
" ") + m_AltitudeUnit, 10, m_TitleHeight);
377 dc->DrawText(_T(
"---"), 10, m_TitleHeight);
381 dc->SetFont(m_Properties->m_LabelFont.GetChosenFont());
383 dc->SetFont(g_pFontLabel->GetChosenFont());
387 f = m_Properties->m_LabelFont.GetChosenFont();
388 dc->GetTextExtent(m_Temp, &width, &height, 0, 0, &f);
390 f = g_pFontLabel->GetChosenFont();
391 dc->GetTextExtent(m_Temp, &width, &height, 0, 0, &f);
393 dc->DrawText(m_Temp, 3, a_plotdown);
wxString getUsrDistanceUnit_Plugin(int unit)
Gets display string for user's preferred distance unit.