38extern int g_iDashDepthUnit;
45int x_alabel, y_alabel, a_plotdown, a_plotup, a_plotheight;
47DashboardInstrument_Altitude::DashboardInstrument_Altitude(
48 wxWindow* parent, wxWindowID
id, wxString title,
51 m_cap_flag.set(OCPN_DBP_STC_TMP);
54 m_AltitudeUnit = getUsrDistanceUnit_Plugin(g_iDashDepthUnit);
56 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT; idx++) {
57 m_ArrayAltitude[idx] = 0.0;
61wxSize DashboardInstrument_Altitude::GetSize(
int orient, wxSize hint) {
66 f = m_Properties->m_TitleFont.GetChosenFont();
67 dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, &f);
68 f = m_Properties->m_DataFont.GetChosenFont();
69 dc.GetTextExtent(
"15.7 Feet", &w, &m_aDataHeight, 0, 0, &f);
70 f = m_Properties->m_LabelFont.GetChosenFont();
71 dc.GetTextExtent(
"20.8 C", &x_alabel, &y_alabel, 0, 0, &f);
73 f = g_pFontTitle->GetChosenFont();
74 dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, &f);
75 f = g_pFontData->GetChosenFont();
76 dc.GetTextExtent(
"15.7 Feet", &w, &m_aDataHeight, 0, 0, &f);
78 f = g_pFontLabel->GetChosenFont();
79 dc.GetTextExtent(
"20.8 C", &x_alabel, &y_alabel, 0, 0, &f);
83 m_TitleHeight + m_aDataHeight + 4 * m_aDataHeight + y_alabel;
84 if (orient == wxHORIZONTAL) {
85 return wxSize(DefaultWidth, wxMax(y_total, hint.y));
87 return wxSize(wxMax(hint.x, DefaultWidth), y_total);
91void DashboardInstrument_Altitude::SetData(DASH_CAP st,
double data,
93 if (st == OCPN_DBP_STC_ALTI) {
94 m_Altitude = std::isnan(data) ? 0.0 : data;
99 m_meanAltitude += (m_Altitude - m_ArrayAltitude[0]) / ALTITUDE_RECORD_COUNT;
101 (m_Altitude * m_Altitude - m_ArrayAltitude[0] * m_ArrayAltitude[0]);
103 for (
int idx = 1; idx < ALTITUDE_RECORD_COUNT; idx++) {
104 m_ArrayAltitude[idx - 1] = m_ArrayAltitude[idx];
106 m_ArrayAltitude[ALTITUDE_RECORD_COUNT - 1] = m_Altitude;
107 m_AltitudeUnit =
unit;
108 }
else if (st == OCPN_DBP_STC_ATMP) {
109 if (!std::isnan(data)) {
110 m_Temp = wxString::Format(_T(
"%.1f"), data) + DEGREE_SIGN +
unit;
117void DashboardInstrument_Altitude::setAttenuation(
int steps) {
122 switch (m_Attenuation) {
137 switch (m_Attenuation) {
156int DashboardInstrument_Altitude::getAttenuation() {
157 return m_Attenuation * m_Decade;
160void DashboardInstrument_Altitude::Draw(wxGCDC* dc) {
165void DashboardInstrument_Altitude::DrawBackground(wxGCDC* dc) {
166 wxSize size = GetClientSize();
169 dc->SetTextForeground(
170 GetColourSchemeFont(m_Properties->m_LabelFont.GetColour()));
172 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
173 GetColourSchemeFont(g_pFontLabel->GetColour())) {
174 GetGlobalColor(_T(
"DASHL"), &cl);
175 dc->SetTextForeground(cl);
177 dc->SetTextForeground(GetColourSchemeFont(g_pFontLabel->GetColour()));
181 pen.SetStyle(wxPENSTYLE_SOLID);
183 cl = GetColourSchemeFont(m_Properties->m_SmallFont.GetColour());
185 cl = GetColourSchemeFont(g_pFontSmall->GetColour());
191 a_plotup = m_TitleHeight + m_aDataHeight;
192 a_plotdown = size.y - y_alabel;
193 a_plotheight = a_plotdown - a_plotup;
196 dc->DrawLine(3, a_plotdown, size.x - 3, a_plotdown);
199 pen.SetStyle(wxPENSTYLE_SHORT_DASH);
201 pen.SetStyle(wxPENSTYLE_DOT);
207 dc->DrawLine(3, a_plotup, size.x - 3, a_plotup);
208 dc->DrawLine(3, a_plotup + a_plotheight / 4, size.x - 3,
209 a_plotup + a_plotheight / 4);
210 dc->DrawLine(3, a_plotup + a_plotheight * 2 / 4, size.x - 3,
211 a_plotup + a_plotheight * 2 / 4);
212 dc->DrawLine(3, a_plotup + a_plotheight * 3 / 4, size.x - 3,
213 a_plotup + a_plotheight * 3 / 4);
215 dc->SetFont(m_Properties->m_SmallFont.GetChosenFont());
216 dc->SetTextForeground(
217 GetColourSchemeFont(m_Properties->m_SmallFont.GetColour()));
219 dc->SetFont(g_pFontSmall->GetChosenFont());
220 dc->SetTextForeground(GetColourSchemeFont(g_pFontSmall->GetColour()));
222 double MaxAltitude = -9999.0;
223 double MinAltitude = 9999999.0;
225 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT; idx++) {
226 if (m_ArrayAltitude[idx] > MaxAltitude)
227 MaxAltitude = m_ArrayAltitude[idx];
228 else if (m_ArrayAltitude[idx] < MinAltitude)
229 MinAltitude = m_ArrayAltitude[idx];
234 m_sum2Altitude / ALTITUDE_RECORD_COUNT;
235 varAltitude -= m_meanAltitude * m_meanAltitude;
238 double range = MaxAltitude - MinAltitude;
239 if (range > 1.1 * m_Range) setAttenuation(+1);
240 if (range < 0.3 * m_Range)
242 double grid = getAttenuation();
243 m_Range = grid * c_GridLines;
249 if ((MaxAltitude - m_MaxAltitude) / grid > 0.25 ||
250 (MaxAltitude - m_MaxAltitude) / grid < -0.75 * c_GridLines) {
251 m_MaxAltitude = (round(MaxAltitude / grid) + 1) * grid;
252 m_MinAltitude = m_MaxAltitude - m_Range;
254 if ((MinAltitude - m_MinAltitude) / grid < -0.25 ||
255 (MinAltitude - m_MinAltitude) / grid > 0.75 * c_GridLines) {
256 m_MinAltitude = (round(MinAltitude / grid) - 1) * grid;
257 m_MaxAltitude = m_MinAltitude + m_Range;
261 label.Printf(_T(
"+/-%.1f %8.0f ") + m_AltitudeUnit, sqrt(varAltitude),
266 f = m_Properties->m_SmallFont.GetChosenFont();
268 f = g_pFontSmall->GetChosenFont();
269 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
270 dc->DrawText(label, size.x - width - 1, a_plotup - height);
272 label.Printf(_T(
"%.1f/ %8.0f ") + m_AltitudeUnit, m_Range / c_GridLines,
275 f = m_Properties->m_SmallFont.GetChosenFont();
277 f = g_pFontSmall->GetChosenFont();
278 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
279 dc->DrawText(label, size.x - width - 1, a_plotdown);
282void DashboardInstrument_Altitude::DrawForeground(wxGCDC* dc) {
283 wxSize size = GetClientSize();
286 cl = GetColourSchemeFont(m_Properties->m_LabelFont.GetColour());
288 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
289 GetColourSchemeFont(g_pFontLabel->GetColour()))
290 GetGlobalColor(_T(
"DASH1"), &cl);
292 cl = GetColourSchemeFont(g_pFontLabel->GetColour());
296 brush.SetStyle(wxBRUSHSTYLE_SOLID);
299 dc->SetPen(*wxTRANSPARENT_PEN);
301 double ratioH = double(a_plotheight) / m_Range;
302 double ratioW = double(size.x - 6) / (ALTITUDE_RECORD_COUNT - 1);
303 wxPoint points[ALTITUDE_RECORD_COUNT + 2];
304#ifdef __OCPN__ANDROID__
307 points[0].y = a_plotdown;
309 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT - 1; idx++) {
310 points[1].x = points[0].x;
311 if (m_ArrayAltitude[idx])
313 a_plotdown - (m_ArrayAltitude[idx] - m_MinAltitude) * ratioH;
315 points[1].y = a_plotdown;
317 points[2].x = points[1].x + ratioW;
318 if (m_ArrayAltitude[idx + 1])
320 a_plotdown - (m_ArrayAltitude[idx + 1] - m_MinAltitude) * ratioH;
322 points[2].y = a_plotdown;
324 points[3].x = points[2].x;
325 points[3].y = a_plotdown;
326 dc->DrawPolygon(4, points);
328 points[0].x = points[2].x;
329 points[0].y = a_plotdown;
333 for (
int idx = 0; idx < ALTITUDE_RECORD_COUNT; idx++) {
334 points[idx].x = idx * ratioW + 3;
336 a_plotdown - (m_ArrayAltitude[idx] - m_MinAltitude) * ratioH;
338 points[ALTITUDE_RECORD_COUNT].x = size.x - 3;
339 points[ALTITUDE_RECORD_COUNT].y = a_plotdown;
340 points[ALTITUDE_RECORD_COUNT + 1].x = 3;
341 points[ALTITUDE_RECORD_COUNT + 1].y = a_plotdown;
342 dc->DrawPolygon(ALTITUDE_RECORD_COUNT + 2, points);
345 dc->SetFont(m_Properties->m_DataFont.GetChosenFont());
346 dc->SetTextForeground(
347 GetColourSchemeFont(m_Properties->m_DataFont.GetColour()));
350 dc->SetTextForeground(GetColourSchemeFont(g_pFontData->GetColour()));
351 dc->SetFont(g_pFontData->GetChosenFont());
353 if (m_AltitudeUnit != _T(
"-")) {
354 wxString s_alti = wxString::Format(_T(
"%.1f"), m_meanAltitude);
355 dc->DrawText(s_alti + _T(
" ") + m_AltitudeUnit, 10, m_TitleHeight);
357 dc->DrawText(_T(
"---"), 10, m_TitleHeight);
361 dc->SetFont(m_Properties->m_LabelFont.GetChosenFont());
363 dc->SetFont(g_pFontLabel->GetChosenFont());
367 f = m_Properties->m_LabelFont.GetChosenFont();
368 dc->GetTextExtent(m_Temp, &width, &height, 0, 0, &f);
370 f = g_pFontLabel->GetChosenFont();
371 dc->GetTextExtent(m_Temp, &width, &height, 0, 0, &f);
373 dc->DrawText(m_Temp, 3, a_plotdown);