39extern int g_iDashDepthUnit;
46int x_alabel, y_alabel, a_plotdown, a_plotup, a_plotheight;
48DashboardInstrument_Altitude::DashboardInstrument_Altitude(
49 wxWindow* parent, wxWindowID
id, wxString title,
52 m_cap_flag.set(OCPN_DBP_STC_TMP);
57 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT; idx++) {
58 m_ArrayAltitude[idx] = 0.0;
62wxSize DashboardInstrument_Altitude::GetSize(
int orient, wxSize hint) {
67 f = m_Properties->m_TitleFont.GetChosenFont();
68 dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, &f);
69 f = m_Properties->m_DataFont.GetChosenFont();
70 dc.GetTextExtent(
"15.7 Feet", &w, &m_aDataHeight, 0, 0, &f);
71 f = m_Properties->m_LabelFont.GetChosenFont();
72 dc.GetTextExtent(
"20.8 C", &x_alabel, &y_alabel, 0, 0, &f);
74 f = g_pFontTitle->GetChosenFont();
75 dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, &f);
76 f = g_pFontData->GetChosenFont();
77 dc.GetTextExtent(
"15.7 Feet", &w, &m_aDataHeight, 0, 0, &f);
79 f = g_pFontLabel->GetChosenFont();
80 dc.GetTextExtent(
"20.8 C", &x_alabel, &y_alabel, 0, 0, &f);
84 m_TitleHeight + m_aDataHeight + 4 * m_aDataHeight + y_alabel;
85 if (orient == wxHORIZONTAL) {
86 return wxSize(DefaultWidth, wxMax(y_total, hint.y));
88 return wxSize(wxMax(hint.x, DefaultWidth), y_total);
92void DashboardInstrument_Altitude::SetData(DASH_CAP st,
double data,
94 if (st == OCPN_DBP_STC_ALTI) {
95 m_Altitude = std::isnan(data) ? 0.0 : data;
100 m_meanAltitude += (m_Altitude - m_ArrayAltitude[0]) / ALTITUDE_RECORD_COUNT;
102 (m_Altitude * m_Altitude - m_ArrayAltitude[0] * m_ArrayAltitude[0]);
104 for (
int idx = 1; idx < ALTITUDE_RECORD_COUNT; idx++) {
105 m_ArrayAltitude[idx - 1] = m_ArrayAltitude[idx];
107 m_ArrayAltitude[ALTITUDE_RECORD_COUNT - 1] = m_Altitude;
108 m_AltitudeUnit =
unit;
109 }
else if (st == OCPN_DBP_STC_ATMP) {
110 if (!std::isnan(data)) {
111 m_Temp = wxString::Format(_T(
"%.1f"), data) + DEGREE_SIGN +
unit;
118void DashboardInstrument_Altitude::setAttenuation(
int steps) {
123 switch (m_Attenuation) {
138 switch (m_Attenuation) {
157int DashboardInstrument_Altitude::getAttenuation() {
158 return m_Attenuation * m_Decade;
161void DashboardInstrument_Altitude::Draw(wxGCDC* dc) {
166void DashboardInstrument_Altitude::DrawBackground(wxGCDC* dc) {
167 wxSize size = GetClientSize();
170 dc->SetTextForeground(
171 GetColourSchemeFont(m_Properties->m_LabelFont.GetColour()));
173 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
174 GetColourSchemeFont(g_pFontLabel->GetColour())) {
175 GetGlobalColor(_T(
"DASHL"), &cl);
176 dc->SetTextForeground(cl);
178 dc->SetTextForeground(GetColourSchemeFont(g_pFontLabel->GetColour()));
182 pen.SetStyle(wxPENSTYLE_SOLID);
184 cl = GetColourSchemeFont(m_Properties->m_SmallFont.GetColour());
186 cl = GetColourSchemeFont(g_pFontSmall->GetColour());
192 a_plotup = m_TitleHeight + m_aDataHeight;
193 a_plotdown = size.y - y_alabel;
194 a_plotheight = a_plotdown - a_plotup;
197 dc->DrawLine(3, a_plotdown, size.x - 3, a_plotdown);
200 pen.SetStyle(wxPENSTYLE_SHORT_DASH);
202 pen.SetStyle(wxPENSTYLE_DOT);
208 dc->DrawLine(3, a_plotup, size.x - 3, a_plotup);
209 dc->DrawLine(3, a_plotup + a_plotheight / 4, size.x - 3,
210 a_plotup + a_plotheight / 4);
211 dc->DrawLine(3, a_plotup + a_plotheight * 2 / 4, size.x - 3,
212 a_plotup + a_plotheight * 2 / 4);
213 dc->DrawLine(3, a_plotup + a_plotheight * 3 / 4, size.x - 3,
214 a_plotup + a_plotheight * 3 / 4);
216 dc->SetFont(m_Properties->m_SmallFont.GetChosenFont());
217 dc->SetTextForeground(
218 GetColourSchemeFont(m_Properties->m_SmallFont.GetColour()));
220 dc->SetFont(g_pFontSmall->GetChosenFont());
221 dc->SetTextForeground(GetColourSchemeFont(g_pFontSmall->GetColour()));
225 double MaxAltitude = m_ArrayAltitude[0];
226 double MinAltitude = m_ArrayAltitude[0];
227 for (
int idx = 1; idx < ALTITUDE_RECORD_COUNT; idx++) {
228 MaxAltitude = std::max(MaxAltitude, m_ArrayAltitude[idx]);
229 MinAltitude = std::min(MinAltitude, m_ArrayAltitude[idx]);
234 m_sum2Altitude / (ALTITUDE_RECORD_COUNT - 1);
235 varAltitude -= m_meanAltitude * m_meanAltitude;
236 if (varAltitude < 0.0) varAltitude = 0.0;
239 double range = MaxAltitude - MinAltitude;
240 if (range > 1.1 * m_Range) setAttenuation(+1);
241 if (range < 0.3 * m_Range) setAttenuation(-1);
242 double grid = getAttenuation();
243 m_Range = grid * c_GridLines;
246 if ((MaxAltitude - m_MaxAltitude) / grid > 0.25 ||
247 (MaxAltitude - m_MaxAltitude) / grid < -0.75 * c_GridLines) {
248 m_MaxAltitude = (round(MaxAltitude / grid) + 1) * grid;
249 m_MinAltitude = m_MaxAltitude - m_Range;
251 if ((MinAltitude - m_MinAltitude) / grid < -0.25 ||
252 (MinAltitude - m_MinAltitude) / grid > 0.75 * c_GridLines) {
253 m_MinAltitude = (round(MinAltitude / grid) - 1) * grid;
254 m_MaxAltitude = m_MinAltitude + m_Range;
263 label.Printf(_T(
"+/-%.1f %8.0f ") + m_AltitudeUnit, sqrt(varAltitude),
268 f = m_Properties->m_SmallFont.GetChosenFont();
270 f = g_pFontSmall->GetChosenFont();
271 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
272 dc->DrawText(label, size.x - width - 1, a_plotup - height);
274 label.Printf(_T(
"%.1f/ %8.0f ") + m_AltitudeUnit, m_Range / c_GridLines,
277 f = m_Properties->m_SmallFont.GetChosenFont();
279 f = g_pFontSmall->GetChosenFont();
280 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
281 dc->DrawText(label, size.x - width - 1, a_plotdown);
284void DashboardInstrument_Altitude::DrawForeground(wxGCDC* dc) {
285 wxSize size = GetClientSize();
288 cl = GetColourSchemeFont(m_Properties->m_LabelFont.GetColour());
290 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
291 GetColourSchemeFont(g_pFontLabel->GetColour()))
292 GetGlobalColor(_T(
"DASH1"), &cl);
294 cl = GetColourSchemeFont(g_pFontLabel->GetColour());
298 brush.SetStyle(wxBRUSHSTYLE_SOLID);
301 dc->SetPen(*wxTRANSPARENT_PEN);
303 double ratioH = double(a_plotheight) / m_Range;
304 double ratioW = double(size.x - 6) / (ALTITUDE_RECORD_COUNT - 1);
305 wxPoint points[ALTITUDE_RECORD_COUNT + 2];
306#ifdef __OCPN__ANDROID__
309 points[0].y = a_plotdown;
311 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT - 1; idx++) {
312 points[1].x = points[0].x;
313 if (m_ArrayAltitude[idx])
315 a_plotdown - (m_ArrayAltitude[idx] - m_MinAltitude) * ratioH;
317 points[1].y = a_plotdown;
319 points[2].x = points[1].x + ratioW;
320 if (m_ArrayAltitude[idx + 1])
322 a_plotdown - (m_ArrayAltitude[idx + 1] - m_MinAltitude) * ratioH;
324 points[2].y = a_plotdown;
326 points[3].x = points[2].x;
327 points[3].y = a_plotdown;
328 dc->DrawPolygon(4, points);
330 points[0].x = points[2].x;
331 points[0].y = a_plotdown;
335 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT; idx++) {
336 points[idx].x = idx * ratioW + 3;
338 a_plotdown - (m_ArrayAltitude[idx] - m_MinAltitude) * ratioH;
340 points[ALTITUDE_RECORD_COUNT].x = size.x - 3;
341 points[ALTITUDE_RECORD_COUNT].y = a_plotdown;
342 points[ALTITUDE_RECORD_COUNT + 1].x = 3;
343 points[ALTITUDE_RECORD_COUNT + 1].y = a_plotdown;
344 dc->DrawPolygon(ALTITUDE_RECORD_COUNT + 2, points);
347 dc->SetFont(m_Properties->m_DataFont.GetChosenFont());
348 dc->SetTextForeground(
349 GetColourSchemeFont(m_Properties->m_DataFont.GetColour()));
352 dc->SetTextForeground(GetColourSchemeFont(g_pFontData->GetColour()));
353 dc->SetFont(g_pFontData->GetChosenFont());
355 if (m_AltitudeUnit != _T(
"-")) {
356 wxString s_alti = wxString::Format(_T(
"%.1f"), m_meanAltitude);
357 dc->DrawText(s_alti + _T(
" ") + m_AltitudeUnit, 10, m_TitleHeight);
359 dc->DrawText(_T(
"---"), 10, m_TitleHeight);
363 dc->SetFont(m_Properties->m_LabelFont.GetChosenFont());
365 dc->SetFont(g_pFontLabel->GetChosenFont());
369 f = m_Properties->m_LabelFont.GetChosenFont();
370 dc->GetTextExtent(m_Temp, &width, &height, 0, 0, &f);
372 f = g_pFontLabel->GetChosenFont();
373 dc->GetTextExtent(m_Temp, &width, &height, 0, 0, &f);
375 dc->DrawText(m_Temp, 3, a_plotdown);
wxString getUsrDistanceUnit_Plugin(int unit)
Gets display string for user's preferred distance unit.