OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_list_ctrl.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#include "gl_headers.h" // Must come before anythng using GL stuff
25
26#include "ocpn_list_ctrl.h"
27
30#include "model/navutil_base.h"
31#include "model/own_ship.h"
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("%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("%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) ||
85 (pAISTarget->Class == AIS_BASE) || (pAISTarget->Class == AIS_METEO))
86 ret = _("-");
87 else if (pAISTarget->b_show_track && !pAISTarget->b_NoTrack)
88 ret = _("Yes");
89 else
90 ret = _("No");
91 break;
92
93 case tlNAME:
94 if ((!pAISTarget->b_nameValid && (pAISTarget->Class == AIS_BASE)) ||
95 (pAISTarget->Class == AIS_SART))
96 ret = _("-");
97 else {
98 wxString uret = trimAISField(pAISTarget->ShipName);
99 if (uret == "Unknown")
100 ret = wxGetTranslation(uret);
101 else
102 ret = uret;
103
104 if (strlen(pAISTarget->ShipNameExtension))
105 ret.Append(wxString(pAISTarget->ShipNameExtension, wxConvUTF8));
106 }
107 break;
108
109 case tlCALL:
110 ret = trimAISField(pAISTarget->CallSign);
111 break;
112
113 case tlMMSI:
114 if (pAISTarget->Class != AIS_GPSG_BUDDY)
115 ret.Printf("%09d", abs(pAISTarget->MMSI));
116 else
117 ret.Printf(" nil ");
118 break;
119
120 case tlCLASS:
121 if (pAISTarget->b_SarAircraftPosnReport) {
122 int airtype = (pAISTarget->MMSI % 1000) / 100;
123 ret = airtype == 5 ? _("SAR Helicopter") : _("SAR Aircraft");
124 } else
125 ret = wxGetTranslation(pAISTarget->Get_class_string(true));
126 break;
127
128 case tlTYPE:
129 if ((pAISTarget->Class == AIS_BASE) ||
130 (pAISTarget->Class == AIS_SART) ||
131 (pAISTarget->Class == AIS_METEO) ||
132 pAISTarget->b_SarAircraftPosnReport)
133 ret = _("-");
134 else
135 ret = wxGetTranslation(pAISTarget->Get_vessel_type_string(false));
136 break;
137
138 case tlNAVSTATUS: {
139 if (pAISTarget->Class == AIS_SART) {
140 if (pAISTarget->NavStatus == RESERVED_14)
141 ret = _("Active");
142 else if (pAISTarget->NavStatus == UNDEFINED)
143 ret = _("Testing");
144 } else {
145 if ((pAISTarget->NavStatus <= 20) && (pAISTarget->NavStatus >= 0))
146 ret = wxGetTranslation(ais_get_status(pAISTarget->NavStatus));
147 else
148 ret = _("-");
149 }
150
151 if ((pAISTarget->Class == AIS_ATON) ||
152 (pAISTarget->Class == AIS_BASE) ||
153 (pAISTarget->Class == AIS_CLASS_B) ||
154 (pAISTarget->Class == AIS_METEO) ||
155 pAISTarget->b_SarAircraftPosnReport)
156 ret = _("-");
157 break;
158 }
159
160 case tlBRG: {
161 if (pAISTarget->b_positionOnceValid && bGPSValid &&
162 (pAISTarget->Brg >= 0.) && (fabs(pAISTarget->Lat) < 85.)) {
163 int brg = (int)wxRound(pAISTarget->Brg);
164 if (pAISTarget->Brg > 359.5) brg = 0;
165
166 ret.Printf("%03d", brg);
167 } else
168 ret = _("-");
169 break;
170 }
171
172 case tlCOG: {
173 if ((pAISTarget->COG >= 360.0) || (pAISTarget->Class == AIS_ATON) ||
174 (pAISTarget->Class == AIS_BASE) || (pAISTarget->Class == AIS_METEO))
175 ret = _("-");
176 else {
177 int crs = wxRound(pAISTarget->COG);
178 if (crs == 360)
179 ret.Printf(" 000");
180 else
181 ret.Printf(" %03d", crs);
182 }
183 break;
184 }
185
186 case tlSOG: {
187 if (((pAISTarget->SOG > 100.) &&
188 !pAISTarget->b_SarAircraftPosnReport) ||
189 (pAISTarget->Class == AIS_ATON) ||
190 (pAISTarget->Class == AIS_BASE) || (pAISTarget->Class == AIS_METEO))
191 ret = _("-");
192 else
193 ret.Printf("%5.1f", toUsrSpeed(pAISTarget->SOG));
194 break;
195 }
196 case tlCPA: {
197 if ((!pAISTarget->bCPA_Valid) || (pAISTarget->Class == AIS_ATON) ||
198 (pAISTarget->Class == AIS_BASE) || (pAISTarget->Class == AIS_METEO))
199 ret = _("-");
200 else
201 ret.Printf("%5.2f", toUsrDistance(pAISTarget->CPA));
202 break;
203 }
204 case tlTCPA: {
205 if ((!pAISTarget->bCPA_Valid) || (pAISTarget->Class == AIS_ATON) ||
206 (pAISTarget->Class == AIS_BASE) || (pAISTarget->Class == AIS_METEO))
207 ret = _("-");
208 else
209 ret.Printf("%5.0f", pAISTarget->TCPA);
210 break;
211 }
212 case tlRNG: {
213 if (pAISTarget->b_positionOnceValid && bGPSValid &&
214 (pAISTarget->Range_NM >= 0.))
215 ret.Printf("%5.2f", toUsrDistance(pAISTarget->Range_NM));
216 else
217 ret = _("-");
218 break;
219 }
220 case tlFLAG: {
221 ret = wxGetTranslation(pAISTarget->GetCountryCode(true));
222
223 if (ret.IsEmpty()) {
224 ret = _("-");
225 }
226 break;
227 }
228
229 default:
230 break;
231 }
232 }
233
234 return ret;
235}
Global state for AIS decoder.
AIS target definitions.
Dialog for displaying a list of AIS targets.
Platform independent GL includes.
double toUsrDistance(double nm_distance, int unit)
Convert a distance from nautical miles (NMi) to user display units.
Navigation Utility Functions without GUI dependencies.
AIS info display component.
bool bGPSValid
Indicate whether the Global Navigation Satellite System (GNSS) has a valid position.
Definition own_ship.cpp:34
Position, course, speed, etc.