OpenCPN Partial API docs
Loading...
Searching...
No Matches
from_ownship.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 by Pavel Kalian *
3 * Copyright (C) 2010 by David S. Register *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#include "from_ownship.h"
26
27extern int g_iDashDistanceUnit;
28
29//----------------------------------------------------------------
30//
31// DashboardInstrument_FromOwnship Implementation
32//
33//----------------------------------------------------------------
34DashboardInstrument_FromOwnship::DashboardInstrument_FromOwnship(
35 wxWindow* pparent, wxWindowID id, wxString title,
36 InstrumentProperties* Properties, DASH_CAP cap_flag1, DASH_CAP cap_flag2,
37 DASH_CAP cap_flag3, DASH_CAP cap_flag4)
38 : DashboardInstrument(pparent, id, title, cap_flag1, Properties) {
39 m_cap_flag.set(cap_flag2);
40 m_cap_flag.set(cap_flag3);
41 m_cap_flag.set(cap_flag4);
42 m_data1 = "---";
43 m_data2 = "---";
44 m_cap_flag1 = cap_flag1;
45 m_cap_flag2 = cap_flag2;
46 m_cap_flag3 = cap_flag3;
47 m_cap_flag4 = cap_flag4;
48 s_lat = 99999999;
49 s_lon = 99999999;
50 c_lat = 0;
51 c_lon = 0;
52}
53
54void DashboardInstrument_FromOwnship::Draw(wxGCDC* dc) {
55 SetDataFont(dc);
56
57 int x1, x2;
58 x1 = x2 = m_DataMargin;
59
60 if (m_DataRightAlign) {
61 int w, h;
62 dc->GetTextExtent(m_data1, &w, &h, nullptr, nullptr);
63 x1 = GetClientSize().GetWidth() - w - m_DataMargin;
64 dc->GetTextExtent(m_data2, &w, &h, nullptr, nullptr);
65 x2 = GetClientSize().GetWidth() - w - m_DataMargin;
66 }
67
68 dc->DrawText(m_data1, x1, m_DataTop);
69 dc->DrawText(m_data2, x2, m_DataTop + m_DataTextHeight);
70}
71
72void DashboardInstrument_FromOwnship::SetData(DASH_CAP st, double data,
73 wxString unit) {
74 if (st == m_cap_flag1) {
75 c_lat = data;
76 } else if (st == m_cap_flag2) {
77 c_lon = data;
78 } else if (st == m_cap_flag3) {
79 s_lat = data;
80 } else if (st == m_cap_flag4) {
81 s_lon = data;
82 } else
83 return;
84 if (s_lat < 99999999 && s_lon < 99999999) {
85 double brg, dist;
86 bool showUnit =
87 (m_Properties ? (m_Properties->m_ShowUnit == 1) : g_bShowUnit);
88 DistanceBearingMercator_Plugin(c_lat, c_lon, s_lat, s_lon, &brg, &dist);
89 if (showUnit) {
90 m_data1.Printf("%03d " + DEGREE_SIGN, (int)brg);
91 m_data2.Printf("%3.2f %s",
92 toUsrDistance_Plugin(dist, g_iDashDistanceUnit),
93 getUsrDistanceUnit_Plugin(g_iDashDistanceUnit).c_str());
94 } else {
95 m_data1.Printf("%03d", (int)brg);
96 m_data2.Printf("%3.2f", toUsrDistance_Plugin(dist, g_iDashDistanceUnit));
97 }
98 }
99
100 Refresh(false);
101}
102
103wxSize DashboardInstrument_FromOwnship::GetSize(int orient, wxSize hint) {
104 InitTitleSize();
105 int w;
106
107 wxString sampleText;
108
109 if (m_Properties ? (m_Properties->m_ShowUnit == 1) : g_bShowUnit) {
110 sampleText = "000.00 NMi";
111 } else {
112 sampleText = "000.00";
113 }
114 InitDataTextHeight(sampleText, w);
115
116 int drawHeight = static_cast<int>(m_DataTextHeight * 2 +
117 m_DataTextHeight * g_TitleVerticalOffset);
118 InitTitleAndDataPosition(drawHeight);
119 int h = GetFullHeight(drawHeight);
120
121 if (orient == wxHORIZONTAL) {
122 return wxSize(wxMax(w + m_DataMargin, DefaultWidth), wxMax(hint.y, h));
123 } else {
124 return wxSize(wxMax(hint.x, wxMax(w + m_DataMargin, DefaultWidth)), h);
125 }
126}
Dashboard own ship data instrument.
DASH_CAP
Definition instrument.h:77
wxString getUsrDistanceUnit_Plugin(int unit)
Gets display string for user's preferred distance unit.
double toUsrDistance_Plugin(double nm_distance, int unit)
Converts nautical miles to user's preferred distance unit.
void DistanceBearingMercator_Plugin(double lat0, double lon0, double lat1, double lon1, double *brg, double *dist)
Calculates bearing and distance between two points using Mercator projection.