OpenCPN Partial API docs
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 "model/ais_state_vars.h"
27 #include "model/ais_target_data.h"
28 #include "model/navutil_base.h"
29 #include "model/own_ship.h"
30 
31 OCPNListCtrl::OCPNListCtrl(AISTargetListDialog* parent, wxWindowID id,
32  const wxPoint& pos, const wxSize& size, long style)
33  : wxListCtrl(parent, id, pos, size, style) {
34  m_parent = parent;
35 }
36 
37 OCPNListCtrl::~OCPNListCtrl() {
38  g_AisTargetList_column_spec.Clear();
39  for (int i = 0; i < tlSOG + 1; i++) {
40  wxListItem item;
41  GetColumn(i, item);
42  wxString sitem;
43  sitem.Printf(_T("%d;"), item.m_width);
44  g_AisTargetList_column_spec += sitem;
45  }
46 
47 #ifdef wxHAS_LISTCTRL_COLUMN_ORDER
48  int i_columns = GetColumnCount();
49  wxArrayInt a_order(i_columns);
50  a_order = GetColumnsOrder();
51  g_AisTargetList_column_order.Clear();
52  for (int i = 0; i < i_columns; i++) {
53  wxString sitem;
54  sitem.Printf(_T("%d;"), a_order[i]);
55  g_AisTargetList_column_order += sitem;
56  }
57 #endif
58 }
59 
60 wxString OCPNListCtrl::OnGetItemText(long item, long column) const {
61  wxString ret;
62 
63  if (m_parent->m_pListCtrlAISTargets) {
64  auto pAISTarget = m_parent->GetpTarget(item);
65  if (pAISTarget) ret = GetTargetColumnData(pAISTarget.get(), column);
66  }
67 
68  return ret;
69 }
70 
71 int OCPNListCtrl::OnGetItemColumnImage(long item, long column) const {
72  return -1;
73 }
74 
75 wxString OCPNListCtrl::GetTargetColumnData(AisTargetData* pAISTarget,
76  long column) const {
77  wxString ret;
78 
79  if (pAISTarget) {
80  switch (column) {
81  case tlTRK:
82  if ((pAISTarget->Class == AIS_ATON) ||
83  (pAISTarget->Class == AIS_BASE) || (pAISTarget->Class == AIS_METEO))
84  ret = _("-");
85  else if (pAISTarget->b_show_track && !pAISTarget->b_NoTrack)
86  ret = _("Yes");
87  else
88  ret = _("No");
89  break;
90 
91  case tlNAME:
92  if ((!pAISTarget->b_nameValid && (pAISTarget->Class == AIS_BASE)) ||
93  (pAISTarget->Class == AIS_SART))
94  ret = _("-");
95  else {
96  wxString uret = trimAISField(pAISTarget->ShipName);
97  if (uret == _T("Unknown"))
98  ret = wxGetTranslation(uret);
99  else
100  ret = uret;
101 
102  if (strlen(pAISTarget->ShipNameExtension))
103  ret.Append(wxString(pAISTarget->ShipNameExtension, wxConvUTF8));
104  }
105  break;
106 
107  case tlCALL:
108  ret = trimAISField(pAISTarget->CallSign);
109  break;
110 
111  case tlMMSI:
112  if (pAISTarget->Class != AIS_GPSG_BUDDY)
113  ret.Printf(_T("%09d"), abs(pAISTarget->MMSI));
114  else
115  ret.Printf(_T(" nil "));
116  break;
117 
118  case tlCLASS:
119  if (pAISTarget->b_SarAircraftPosnReport) {
120  int airtype = (pAISTarget->MMSI % 1000) / 100;
121  ret = airtype == 5 ? _("SAR Helicopter") : _("SAR Aircraft");
122  } else
123  ret = wxGetTranslation(pAISTarget->Get_class_string(true));
124  break;
125 
126  case tlTYPE:
127  if ((pAISTarget->Class == AIS_BASE) ||
128  (pAISTarget->Class == AIS_SART) ||
129  (pAISTarget->Class == AIS_METEO) ||
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->Class == AIS_METEO) ||
153  pAISTarget->b_SarAircraftPosnReport)
154  ret = _("-");
155  break;
156  }
157 
158  case tlBRG: {
159  if (pAISTarget->b_positionOnceValid && bGPSValid &&
160  (pAISTarget->Brg >= 0.) && (fabs(pAISTarget->Lat) < 85.)) {
161  int brg = (int)wxRound(pAISTarget->Brg);
162  if (pAISTarget->Brg > 359.5) brg = 0;
163 
164  ret.Printf(_T("%03d"), brg);
165  } else
166  ret = _("-");
167  break;
168  }
169 
170  case tlCOG: {
171  if ((pAISTarget->COG >= 360.0) || (pAISTarget->Class == AIS_ATON) ||
172  (pAISTarget->Class == AIS_BASE) || (pAISTarget->Class == AIS_METEO))
173  ret = _("-");
174  else {
175  int crs = wxRound(pAISTarget->COG);
176  if (crs == 360)
177  ret.Printf(_T(" 000"));
178  else
179  ret.Printf(_T(" %03d"), crs);
180  }
181  break;
182  }
183 
184  case tlSOG: {
185  if (((pAISTarget->SOG > 100.) && !pAISTarget->b_SarAircraftPosnReport) ||
186  (pAISTarget->Class == AIS_ATON) || (pAISTarget->Class == AIS_BASE) ||
187  (pAISTarget->Class == AIS_METEO))
188  ret = _("-");
189  else
190  ret.Printf(_T("%5.1f"), toUsrSpeed(pAISTarget->SOG));
191  break;
192  }
193  case tlCPA: {
194  if ((!pAISTarget->bCPA_Valid) || (pAISTarget->Class == AIS_ATON) ||
195  (pAISTarget->Class == AIS_BASE) || (pAISTarget->Class == AIS_METEO))
196  ret = _("-");
197  else
198  ret.Printf(_T("%5.2f"), toUsrDistance(pAISTarget->CPA));
199  break;
200  }
201  case tlTCPA: {
202  if ((!pAISTarget->bCPA_Valid) || (pAISTarget->Class == AIS_ATON) ||
203  (pAISTarget->Class == AIS_BASE) || (pAISTarget->Class == AIS_METEO))
204  ret = _("-");
205  else
206  ret.Printf(_T("%5.0f"), pAISTarget->TCPA);
207  break;
208  }
209  case tlRNG: {
210  if (pAISTarget->b_positionOnceValid && bGPSValid &&
211  (pAISTarget->Range_NM >= 0.))
212  ret.Printf(_T("%5.2f"), toUsrDistance(pAISTarget->Range_NM));
213  else
214  ret = _("-");
215  break;
216  }
217 
218  default:
219  break;
220  }
221  }
222 
223  return ret;
224 }
Global state for AIS decoder.