41extern int g_iDashDepthUnit;
44int x_alabel, y_alabel, a_plotdown, a_plotup, a_plotheight;
46DashboardInstrument_Altitude::DashboardInstrument_Altitude(
47 wxWindow* parent, wxWindowID
id, wxString title,
55 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT; idx++) {
56 m_array_altitude[idx] = 0.0;
60wxSize DashboardInstrument_Altitude::GetSize(
int orient, wxSize hint) {
65 f = m_Properties->m_TitleFont.GetChosenFont();
66 dc.GetTextExtent(m_title, &w, &m_TitleHeight,
nullptr,
nullptr, &f);
67 f = m_Properties->m_DataFont.GetChosenFont();
68 dc.GetTextExtent(
"15.7 Feet", &w, &m_aDataHeight,
nullptr,
nullptr, &f);
69 f = m_Properties->m_LabelFont.GetChosenFont();
70 dc.GetTextExtent(
"20.8 C", &x_alabel, &y_alabel,
nullptr,
nullptr, &f);
72 f = g_pFontTitle->GetChosenFont();
73 dc.GetTextExtent(m_title, &w, &m_TitleHeight,
nullptr,
nullptr, &f);
74 f = g_pFontData->GetChosenFont();
75 dc.GetTextExtent(
"15.7 Feet", &w, &m_aDataHeight,
nullptr,
nullptr, &f);
77 f = g_pFontLabel->GetChosenFont();
78 dc.GetTextExtent(
"20.8 C", &x_alabel, &y_alabel,
nullptr,
nullptr, &f);
82 m_TitleHeight + m_aDataHeight + 4 * m_aDataHeight + y_alabel;
83 if (orient == wxHORIZONTAL) {
84 return {DefaultWidth, wxMax(y_total, hint.y)};
86 return {wxMax(hint.x, DefaultWidth), y_total};
90void DashboardInstrument_Altitude::SetData(
DASH_CAP st,
double data,
93 if (std::isnan(data)) {
99 if (m_cnt_valid < ALTITUDE_RECORD_COUNT && data != 0.0) m_cnt_valid++;
103 if (m_cnt_valid == 1) {
104 for (
int idx = 1; idx < ALTITUDE_RECORD_COUNT; idx++) {
105 m_array_altitude[idx - 1] =
109 for (
int idx = 1; idx < ALTITUDE_RECORD_COUNT; idx++) {
110 m_array_altitude[idx - 1] = m_array_altitude[idx];
113 m_array_altitude[ALTITUDE_RECORD_COUNT - 1] = m_altitude;
114 m_altitude_unit =
unit;
116 if (!std::isnan(data)) {
117 m_temp = wxString::Format(
"%.1f", data) + DEGREE_SIGN +
unit;
124void DashboardInstrument_Altitude::SetAttenuation(
int steps) {
129 switch (m_attenuation) {
144 switch (m_attenuation) {
163int DashboardInstrument_Altitude::GetAttenuation()
const {
164 return m_attenuation * m_decade;
167void DashboardInstrument_Altitude::Draw(wxGCDC* dc) {
172void DashboardInstrument_Altitude::DrawBackground(wxGCDC* dc) {
173 wxSize size = GetClientSize();
176 dc->SetTextForeground(
177 GetColourSchemeFont(m_Properties->m_LabelFont.GetColour()));
179 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
180 GetColourSchemeFont(g_pFontLabel->GetColour())) {
181 GetGlobalColor(
"DASHL", &cl);
182 dc->SetTextForeground(cl);
184 dc->SetTextForeground(GetColourSchemeFont(g_pFontLabel->GetColour()));
188 pen.SetStyle(wxPENSTYLE_SOLID);
190 cl = GetColourSchemeFont(m_Properties->m_SmallFont.GetColour());
192 cl = GetColourSchemeFont(g_pFontSmall->GetColour());
198 a_plotup = m_TitleHeight + m_aDataHeight;
199 a_plotdown = size.y - y_alabel;
200 a_plotheight = a_plotdown - a_plotup;
203 dc->DrawLine(3, a_plotdown, size.x - 3, a_plotdown);
206 pen.SetStyle(wxPENSTYLE_SHORT_DASH);
208 pen.SetStyle(wxPENSTYLE_DOT);
214 dc->DrawLine(3, a_plotup, size.x - 3, a_plotup);
215 dc->DrawLine(3, a_plotup + a_plotheight / 4, size.x - 3,
216 a_plotup + a_plotheight / 4);
217 dc->DrawLine(3, a_plotup + a_plotheight * 2 / 4, size.x - 3,
218 a_plotup + a_plotheight * 2 / 4);
219 dc->DrawLine(3, a_plotup + a_plotheight * 3 / 4, size.x - 3,
220 a_plotup + a_plotheight * 3 / 4);
222 dc->SetFont(m_Properties->m_SmallFont.GetChosenFont());
223 dc->SetTextForeground(
224 GetColourSchemeFont(m_Properties->m_SmallFont.GetColour()));
226 dc->SetFont(g_pFontSmall->GetChosenFont());
227 dc->SetTextForeground(GetColourSchemeFont(g_pFontSmall->GetColour()));
231 m_mean_altitude = m_array_altitude[0];
232 double MaxAltitude = m_array_altitude[0];
233 double MinAltitude = m_array_altitude[0];
234 double sum2Altitude = m_array_altitude[0] * m_array_altitude[0];
235 for (
int idx = 1; idx < ALTITUDE_RECORD_COUNT; idx++) {
236 MaxAltitude = std::max(MaxAltitude, m_array_altitude[idx]);
237 MinAltitude = std::min(MinAltitude, m_array_altitude[idx]);
238 m_mean_altitude += m_array_altitude[idx];
239 sum2Altitude += m_array_altitude[idx] * m_array_altitude[idx];
241 m_mean_altitude /= ALTITUDE_RECORD_COUNT;
244 double varAltitude = sum2Altitude / ALTITUDE_RECORD_COUNT;
245 varAltitude -= m_mean_altitude * m_mean_altitude;
247 varAltitude *= (ALTITUDE_RECORD_COUNT / (ALTITUDE_RECORD_COUNT - 1.0));
249 if (varAltitude < 0.0) varAltitude = 0.0;
252 double range = MaxAltitude - MinAltitude;
253 if (range > 1.1 * m_range) SetAttenuation(+1);
254 if (range < 0.3 * m_range) SetAttenuation(-1);
255 double grid = GetAttenuation();
256 m_range = grid * c_grid_lines;
259 if ((MaxAltitude - m_max_altitude) / grid > 0.25 ||
260 (MaxAltitude - m_max_altitude) / grid < -0.75 * c_grid_lines) {
261 m_max_altitude = (round(MaxAltitude / grid) + 1) * grid;
262 m_min_altitude = m_max_altitude - m_range;
264 if ((MinAltitude - m_min_altitude) / grid < -0.25 ||
265 (MinAltitude - m_min_altitude) / grid > 0.75 * c_grid_lines) {
266 m_min_altitude = (round(MinAltitude / grid) - 1) * grid;
267 m_max_altitude = m_min_altitude + m_range;
276 label.Printf(
"+/-%.1f %8.0f " + m_altitude_unit, sqrt(varAltitude),
281 f = m_Properties->m_SmallFont.GetChosenFont();
283 f = g_pFontSmall->GetChosenFont();
284 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
285 dc->DrawText(label, size.x - width - 1, a_plotup - height);
287 label.Printf(
"%.1f/ %8.0f " + m_altitude_unit, m_range / c_grid_lines,
290 f = m_Properties->m_SmallFont.GetChosenFont();
292 f = g_pFontSmall->GetChosenFont();
293 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
294 dc->DrawText(label, size.x - width - 1, a_plotdown);
297void DashboardInstrument_Altitude::DrawForeground(wxGCDC* dc) {
298 wxSize size = GetClientSize();
301 cl = GetColourSchemeFont(m_Properties->m_LabelFont.GetColour());
303 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
304 GetColourSchemeFont(g_pFontLabel->GetColour()))
305 GetGlobalColor(
"DASH1", &cl);
307 cl = GetColourSchemeFont(g_pFontLabel->GetColour());
311 brush.SetStyle(wxBRUSHSTYLE_SOLID);
314 dc->SetPen(*wxTRANSPARENT_PEN);
316 double ratioH = double(a_plotheight) / m_range;
317 double ratioW = double(size.x - 6) / (ALTITUDE_RECORD_COUNT - 1);
318 wxPoint points[ALTITUDE_RECORD_COUNT + 2];
322 points[0].y = a_plotdown;
324 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT - 1; idx++) {
325 points[1].x = points[0].x;
326 if (m_array_altitude[idx])
328 a_plotdown - (m_array_altitude[idx] - m_min_altitude) * ratioH;
330 points[1].y = a_plotdown;
332 points[2].x = points[1].x + ratioW;
333 if (m_array_altitude[idx + 1])
335 a_plotdown - (m_array_altitude[idx + 1] - m_min_altitude) * ratioH;
337 points[2].y = a_plotdown;
339 points[3].x = points[2].x;
340 points[3].y = a_plotdown;
341 dc->DrawPolygon(4, points);
343 points[0].x = points[2].x;
344 points[0].y = a_plotdown;
348 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT; idx++) {
349 points[idx].x = idx * ratioW + 3;
351 a_plotdown - (m_array_altitude[idx] - m_min_altitude) * ratioH;
353 points[ALTITUDE_RECORD_COUNT].x = size.x - 3;
354 points[ALTITUDE_RECORD_COUNT].y = a_plotdown;
355 points[ALTITUDE_RECORD_COUNT + 1].x = 3;
356 points[ALTITUDE_RECORD_COUNT + 1].y = a_plotdown;
357 dc->DrawPolygon(ALTITUDE_RECORD_COUNT + 2, points);
360 dc->SetFont(m_Properties->m_DataFont.GetChosenFont());
361 dc->SetTextForeground(
362 GetColourSchemeFont(m_Properties->m_DataFont.GetColour()));
365 dc->SetTextForeground(GetColourSchemeFont(g_pFontData->GetColour()));
366 dc->SetFont(g_pFontData->GetChosenFont());
368 if (m_altitude_unit !=
"-") {
369 wxString s_alti = wxString::Format(
"%.1f", m_mean_altitude);
370 dc->DrawText(s_alti +
" " + m_altitude_unit, 10, m_TitleHeight);
372 dc->DrawText(
"---", 10, m_TitleHeight);
376 dc->SetFont(m_Properties->m_LabelFont.GetChosenFont());
378 dc->SetFont(g_pFontLabel->GetChosenFont());
382 f = m_Properties->m_LabelFont.GetChosenFont();
383 dc->GetTextExtent(m_temp, &width, &height, 0, 0, &f);
385 f = g_pFontLabel->GetChosenFont();
386 dc->GetTextExtent(m_temp, &width, &height, 0, 0, &f);
388 dc->DrawText(m_temp, 3, a_plotdown);
Dashboard altitude instrument.
@ OCPN_DBP_STC_ALTI
Altitude.
@ OCPN_DBP_STC_ATMP
Air Temperature.
@ OCPN_DBP_STC_TMP
Water temperature.
wxString getUsrDistanceUnit_Plugin(int unit)
Gets display string for user's preferred distance unit.