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