OpenCPN Partial API docs
Loading...
Searching...
No Matches
OCPNListCtrl.cpp
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 *
5 ***************************************************************************
6 * Copyright (C) 2010 by David S. Register *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22 ***************************************************************************
23 */
24
25#include "OCPNListCtrl.h"
26#include "ais_target_data.h"
27#include "navutil_base.h"
28
29extern wxString g_AisTargetList_column_spec;
30extern wxString g_AisTargetList_column_order;
31extern bool bGPSValid;
32
33OCPNListCtrl::OCPNListCtrl(AISTargetListDialog* parent, wxWindowID id,
34 const wxPoint& pos, const wxSize& size, long style)
35 : wxListCtrl(parent, id, pos, size, style) {
36 m_parent = parent;
37}
38
39OCPNListCtrl::~OCPNListCtrl() {
40 g_AisTargetList_column_spec.Clear();
41 for (int i = 0; i < tlSOG + 1; i++) {
42 wxListItem item;
43 GetColumn(i, item);
44 wxString sitem;
45 sitem.Printf(_T("%d;"), item.m_width);
46 g_AisTargetList_column_spec += sitem;
47 }
48
49#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
50 int i_columns = GetColumnCount();
51 wxArrayInt a_order(i_columns);
52 a_order = GetColumnsOrder();
53 g_AisTargetList_column_order.Clear();
54 for (int i = 0; i < i_columns; i++) {
55 wxString sitem;
56 sitem.Printf(_T("%d;"), a_order[i]);
57 g_AisTargetList_column_order += sitem;
58 }
59#endif
60}
61
62wxString OCPNListCtrl::OnGetItemText(long item, long column) const {
63 wxString ret;
64
65 if (m_parent->m_pListCtrlAISTargets) {
66 auto pAISTarget = m_parent->GetpTarget(item);
67 if (pAISTarget) ret = GetTargetColumnData(pAISTarget.get(), column);
68 }
69
70 return ret;
71}
72
73int OCPNListCtrl::OnGetItemColumnImage(long item, long column) const {
74 return -1;
75}
76
77wxString OCPNListCtrl::GetTargetColumnData(AisTargetData* pAISTarget,
78 long column) const {
79 wxString ret;
80
81 if (pAISTarget) {
82 switch (column) {
83 case tlTRK:
84 if ((pAISTarget->Class == AIS_ATON) || (pAISTarget->Class == AIS_BASE))
85 ret = _("-");
86 else if (pAISTarget->b_show_track && !pAISTarget->b_NoTrack)
87 ret = _("Yes");
88 else
89 ret = _("No");
90 break;
91
92 case tlNAME:
93 if ((!pAISTarget->b_nameValid && (pAISTarget->Class == AIS_BASE)) ||
94 (pAISTarget->Class == AIS_SART))
95 ret = _("-");
96 else {
97 wxString uret = trimAISField(pAISTarget->ShipName);
98 if (uret == _T("Unknown"))
99 ret = wxGetTranslation(uret);
100 else
101 ret = uret;
102
103 if (strlen(pAISTarget->ShipNameExtension))
104 ret.Append(wxString(pAISTarget->ShipNameExtension, wxConvUTF8));
105 }
106 break;
107
108 case tlCALL:
109 ret = trimAISField(pAISTarget->CallSign);
110 break;
111
112 case tlMMSI:
113 if (pAISTarget->Class != AIS_GPSG_BUDDY)
114 ret.Printf(_T("%09d"), abs(pAISTarget->MMSI));
115 else
116 ret.Printf(_T(" nil "));
117 break;
118
119 case tlCLASS:
120 if (pAISTarget->b_SarAircraftPosnReport) {
121 int airtype = (pAISTarget->MMSI % 1000) / 100;
122 ret = airtype == 5 ? _("SAR Helicopter") : _("SAR Aircraft");
123 } else
124 ret = wxGetTranslation(pAISTarget->Get_class_string(true));
125 break;
126
127 case tlTYPE:
128 if ((pAISTarget->Class == AIS_BASE) ||
129 (pAISTarget->Class == AIS_SART) ||
130 pAISTarget->b_SarAircraftPosnReport)
131 ret = _("-");
132 else
133 ret = wxGetTranslation(pAISTarget->Get_vessel_type_string(false));
134 break;
135
136 case tlNAVSTATUS: {
137 if (pAISTarget->Class == AIS_SART) {
138 if (pAISTarget->NavStatus == RESERVED_14)
139 ret = _("Active");
140 else if (pAISTarget->NavStatus == UNDEFINED)
141 ret = _("Testing");
142 } else {
143 if ((pAISTarget->NavStatus <= 20) && (pAISTarget->NavStatus >= 0))
144 ret = wxGetTranslation(ais_get_status(pAISTarget->NavStatus));
145 else
146 ret = _("-");
147 }
148
149 if ((pAISTarget->Class == AIS_ATON) ||
150 (pAISTarget->Class == AIS_BASE) ||
151 (pAISTarget->Class == AIS_CLASS_B) ||
152 pAISTarget->b_SarAircraftPosnReport)
153 ret = _("-");
154 break;
155 }
156
157 case tlBRG: {
158 if (pAISTarget->b_positionOnceValid && bGPSValid &&
159 (pAISTarget->Brg >= 0.) && (fabs(pAISTarget->Lat) < 85.)) {
160 int brg = (int)wxRound(pAISTarget->Brg);
161 if (pAISTarget->Brg > 359.5) brg = 0;
162
163 ret.Printf(_T("%03d"), brg);
164 } else
165 ret = _("-");
166 break;
167 }
168
169 case tlCOG: {
170 if ((pAISTarget->COG >= 360.0) || (pAISTarget->Class == AIS_ATON) ||
171 (pAISTarget->Class == AIS_BASE))
172 ret = _("-");
173 else {
174 int crs = wxRound(pAISTarget->COG);
175 if (crs == 360)
176 ret.Printf(_T(" 000"));
177 else
178 ret.Printf(_T(" %03d"), crs);
179 }
180 break;
181 }
182
183 case tlSOG: {
184 if (((pAISTarget->SOG > 100.) &&
185 !pAISTarget->b_SarAircraftPosnReport) ||
186 (pAISTarget->Class == AIS_ATON) || (pAISTarget->Class == AIS_BASE))
187 ret = _("-");
188 else
189 ret.Printf(_T("%5.1f"), toUsrSpeed(pAISTarget->SOG));
190 break;
191 }
192 case tlCPA: {
193 if ((!pAISTarget->bCPA_Valid) || (pAISTarget->Class == AIS_ATON) ||
194 (pAISTarget->Class == AIS_BASE))
195 ret = _("-");
196 else
197 ret.Printf(_T("%5.2f"), toUsrDistance(pAISTarget->CPA));
198 break;
199 }
200 case tlTCPA: {
201 if ((!pAISTarget->bCPA_Valid) || (pAISTarget->Class == AIS_ATON) ||
202 (pAISTarget->Class == AIS_BASE))
203 ret = _("-");
204 else
205 ret.Printf(_T("%5.0f"), pAISTarget->TCPA);
206 break;
207 }
208 case tlRNG: {
209 if (pAISTarget->b_positionOnceValid && bGPSValid &&
210 (pAISTarget->Range_NM >= 0.))
211 ret.Printf(_T("%5.2f"), toUsrDistance(pAISTarget->Range_NM));
212 else
213 ret = _("-");
214 break;
215 }
216
217 default:
218 break;
219 }
220 }
221
222 return ret;
223}