25#include "OCPNListCtrl.h"
26#include "ais_target_data.h"
27#include "navutil_base.h"
29extern wxString g_AisTargetList_column_spec;
30extern wxString g_AisTargetList_column_order;
34 const wxPoint& pos,
const wxSize& size,
long style)
35 : wxListCtrl(parent, id, pos, size, style) {
39OCPNListCtrl::~OCPNListCtrl() {
40 g_AisTargetList_column_spec.Clear();
41 for (
int i = 0; i < tlSOG + 1; i++) {
45 sitem.Printf(_T(
"%d;"), item.m_width);
46 g_AisTargetList_column_spec += sitem;
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++) {
56 sitem.Printf(_T(
"%d;"), a_order[i]);
57 g_AisTargetList_column_order += sitem;
62wxString OCPNListCtrl::OnGetItemText(
long item,
long column)
const {
65 if (m_parent->m_pListCtrlAISTargets) {
66 auto pAISTarget = m_parent->GetpTarget(item);
67 if (pAISTarget) ret = GetTargetColumnData(pAISTarget.get(), column);
73int OCPNListCtrl::OnGetItemColumnImage(
long item,
long column)
const {
77wxString OCPNListCtrl::GetTargetColumnData(
AisTargetData* pAISTarget,
84 if ((pAISTarget->Class == AIS_ATON) || (pAISTarget->Class == AIS_BASE))
86 else if (pAISTarget->b_show_track && !pAISTarget->b_NoTrack)
93 if ((!pAISTarget->b_nameValid && (pAISTarget->Class == AIS_BASE)) ||
94 (pAISTarget->Class == AIS_SART))
97 wxString uret = trimAISField(pAISTarget->ShipName);
98 if (uret == _T(
"Unknown"))
99 ret = wxGetTranslation(uret);
103 if (strlen(pAISTarget->ShipNameExtension))
104 ret.Append(wxString(pAISTarget->ShipNameExtension, wxConvUTF8));
109 ret = trimAISField(pAISTarget->CallSign);
113 if (pAISTarget->Class != AIS_GPSG_BUDDY)
114 ret.Printf(_T(
"%09d"), abs(pAISTarget->MMSI));
116 ret.Printf(_T(
" nil "));
120 if (pAISTarget->b_SarAircraftPosnReport) {
121 int airtype = (pAISTarget->MMSI % 1000) / 100;
122 ret = airtype == 5 ? _(
"SAR Helicopter") : _(
"SAR Aircraft");
124 ret = wxGetTranslation(pAISTarget->Get_class_string(
true));
128 if ((pAISTarget->Class == AIS_BASE) ||
129 (pAISTarget->Class == AIS_SART) ||
130 pAISTarget->b_SarAircraftPosnReport)
133 ret = wxGetTranslation(pAISTarget->Get_vessel_type_string(
false));
137 if (pAISTarget->Class == AIS_SART) {
138 if (pAISTarget->NavStatus == RESERVED_14)
140 else if (pAISTarget->NavStatus == UNDEFINED)
143 if ((pAISTarget->NavStatus <= 20) && (pAISTarget->NavStatus >= 0))
144 ret = wxGetTranslation(ais_get_status(pAISTarget->NavStatus));
149 if ((pAISTarget->Class == AIS_ATON) ||
150 (pAISTarget->Class == AIS_BASE) ||
151 (pAISTarget->Class == AIS_CLASS_B) ||
152 pAISTarget->b_SarAircraftPosnReport)
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;
163 ret.Printf(_T(
"%03d"), brg);
170 if ((pAISTarget->COG >= 360.0) || (pAISTarget->Class == AIS_ATON) ||
171 (pAISTarget->Class == AIS_BASE))
174 int crs = wxRound(pAISTarget->COG);
176 ret.Printf(_T(
" 000"));
178 ret.Printf(_T(
" %03d"), crs);
184 if (((pAISTarget->SOG > 100.) &&
185 !pAISTarget->b_SarAircraftPosnReport) ||
186 (pAISTarget->Class == AIS_ATON) || (pAISTarget->Class == AIS_BASE))
189 ret.Printf(_T(
"%5.1f"), toUsrSpeed(pAISTarget->SOG));
193 if ((!pAISTarget->bCPA_Valid) || (pAISTarget->Class == AIS_ATON) ||
194 (pAISTarget->Class == AIS_BASE))
197 ret.Printf(_T(
"%5.2f"), toUsrDistance(pAISTarget->CPA));
201 if ((!pAISTarget->bCPA_Valid) || (pAISTarget->Class == AIS_ATON) ||
202 (pAISTarget->Class == AIS_BASE))
205 ret.Printf(_T(
"%5.0f"), pAISTarget->TCPA);
209 if (pAISTarget->b_positionOnceValid && bGPSValid &&
210 (pAISTarget->Range_NM >= 0.))
211 ret.Printf(_T(
"%5.2f"), toUsrDistance(pAISTarget->Range_NM));