OpenCPN Partial API docs
Loading...
Searching...
No Matches
ais_target_list_dlg.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 <wx/textctrl.h>
26#include <wx/sizer.h>
27#include <wx/tokenzr.h>
28#include <wx/clipbrd.h>
29
30#ifdef __ANDROID__
31#include "androidUTIL.h"
32#endif
33
34#include "model/ais_decoder.h"
36#include "model/ais_target_data.h"
37#include "model/route_point.h"
38#include "model/select.h"
39
40#include "ais.h"
41#include "ais_target_list_dlg.h"
42#include "chcanv.h"
43#include "ocpn_frame.h"
44#include "OCPNListCtrl.h"
45#include "OCPNPlatform.h"
46#include "routemanagerdialog.h"
47#include "styles.h"
48#include "model/navobj_db.h"
49
50extern int g_AisTargetList_count;
51extern bool g_bAisTargetList_autosort;
52extern ocpnStyle::StyleManager *g_StyleManager;
53extern MyConfig *pConfig;
54extern AISTargetListDialog *g_pAISTargetList;
55extern MyFrame *gFrame;
56extern wxString g_default_wp_icon;
57extern RouteManagerDialog *pRouteManagerDialog;
58
59AISTargetListDialog *g_pAISTargetList;
60
61static AisDecoder *s_p_sort_decoder;
62
63IMPLEMENT_CLASS(AISTargetListDialog, wxPanel)
64
65BEGIN_EVENT_TABLE(AISTargetListDialog, wxPanel)
66EVT_CLOSE(AISTargetListDialog::OnClose)
67END_EVENT_TABLE()
68
69static bool g_bsort_once;
70
71static int ItemCompare(AisTargetData *pAISTarget1, AisTargetData *pAISTarget2) {
72 wxString s1, s2;
73 double n1 = 0.;
74 double n2 = 0.;
75 bool b_cmptype_num = false;
76
77 // Don't sort unless requested
78 if (!g_bAisTargetList_autosort && !g_bsort_once) return 0;
79
80 AisTargetData *t1 = pAISTarget1;
81 AisTargetData *t2 = pAISTarget2;
82
83 if (t1->Class == AIS_SART) {
84 if (t2->Class == AIS_DSC)
85 return 0;
86 else
87 return -1;
88 }
89
90 if (t2->Class == AIS_SART) {
91 if (t1->Class == AIS_DSC)
92 return 0;
93 else
94 return 1;
95 }
96
97 switch (g_AisTargetList_sortColumn) {
98 case tlTRK:
99 n1 = t1->b_show_track;
100 n2 = t2->b_show_track;
101 b_cmptype_num = true;
102 break;
103
104 case tlNAME:
105 s1 = trimAISField(t1->ShipName);
106 if ((!t1->b_nameValid && (t1->Class == AIS_BASE)) ||
107 (t1->Class == AIS_SART))
108 s1 = "-";
109
110 s2 = trimAISField(t2->ShipName);
111 if ((!t2->b_nameValid && (t2->Class == AIS_BASE)) ||
112 (t2->Class == AIS_SART))
113 s2 = "-";
114 break;
115
116 case tlCALL:
117 s1 = trimAISField(t1->CallSign);
118 s2 = trimAISField(t2->CallSign);
119 break;
120
121 case tlMMSI:
122 n1 = t1->MMSI;
123 n2 = t2->MMSI;
124 b_cmptype_num = true;
125 break;
126
127 case tlCLASS:
128 s1 = t1->Get_class_string(true);
129 s2 = t2->Get_class_string(true);
130 break;
131
132 case tlTYPE:
133 s1 = t1->Get_vessel_type_string(false);
134 if ((t1->Class == AIS_BASE) ||
135 (t1->Class == AIS_SART || (t1->Class == AIS_METEO)))
136 s1 = "-";
137
138 s2 = t2->Get_vessel_type_string(false);
139 if ((t1->Class == AIS_BASE) || (t1->Class == AIS_SART) ||
140 (t1->Class == AIS_METEO))
141 s2 = "-";
142 break;
143
144 case tlFLAG:
145 s1 = t1->GetCountryCode(true);
146 s2 = t2->GetCountryCode(true);
147 break;
148 case tlNAVSTATUS: {
149 if ((t1->NavStatus <= 15) && (t1->NavStatus >= 0)) {
150 if (t1->Class == AIS_SART) {
151 if (t1->NavStatus == RESERVED_14)
152 s1 = _("Active");
153 else if (t1->NavStatus == UNDEFINED)
154 s1 = _("Testing");
155 } else
156 s1 = ais_get_status(t1->NavStatus);
157 } else
158 s1 = _("-");
159
160 if ((t1->Class == AIS_ATON) || (t1->Class == AIS_BASE) ||
161 (t1->Class == AIS_CLASS_B) || (t1->Class == AIS_METEO))
162 s1 = "-";
163
164 if ((t2->NavStatus <= 15) && (t2->NavStatus >= 0)) {
165 if (t2->Class == AIS_SART) {
166 if (t2->NavStatus == RESERVED_14)
167 s2 = _("Active");
168 else if (t2->NavStatus == UNDEFINED)
169 s2 = _("Testing");
170 } else
171 s2 = ais_get_status(t2->NavStatus);
172 } else
173 s2 = _("-");
174
175 if ((t2->Class == AIS_ATON) || (t2->Class == AIS_BASE) ||
176 (t2->Class == AIS_CLASS_B) || (t2->Class == AIS_METEO))
177 s2 = "-";
178
179 break;
180 }
181
182 case tlBRG: {
183 int brg1 = wxRound(t1->Brg);
184 if (brg1 == 360)
185 n1 = 0.;
186 else
187 n1 = brg1;
188
189 int brg2 = wxRound(t2->Brg);
190 if (brg2 == 360)
191 n2 = 0.;
192 else
193 n2 = brg2;
194
195 b_cmptype_num = true;
196 break;
197 }
198
199 case tlCOG: {
200 if ((t1->COG >= 360.0) || (t1->Class == AIS_ATON) ||
201 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
202 n1 = -1.0;
203 else {
204 int crs = wxRound(t1->COG);
205 if (crs == 360)
206 n1 = 0.;
207 else
208 n1 = crs;
209 }
210
211 if ((t2->COG >= 360.0) || (t2->Class == AIS_ATON) ||
212 (t2->Class == AIS_BASE) || (t2->Class == AIS_METEO))
213 n2 = -1.0;
214 else {
215 int crs = wxRound(t2->COG);
216 if (crs == 360)
217 n2 = 0.;
218 else
219 n2 = crs;
220 }
221
222 b_cmptype_num = true;
223 break;
224 }
225
226 case tlSOG: {
227 if ((t1->SOG > 100.) || (t1->Class == AIS_ATON) ||
228 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
229 n1 = -1.0;
230 else
231 n1 = t1->SOG;
232
233 if ((t2->SOG > 100.) || (t2->Class == AIS_ATON) ||
234 (t2->Class == AIS_BASE) || (t2->Class == AIS_METEO))
235 n2 = -1.0;
236 else
237 n2 = t2->SOG;
238
239 b_cmptype_num = true;
240 break;
241 }
242 case tlCPA: {
243 if ((!t1->bCPA_Valid) || (t1->Class == AIS_ATON) ||
244 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
245 n1 = 99999.0;
246 else
247 n1 = t1->CPA;
248
249 if ((!t2->bCPA_Valid) || (t2->Class == AIS_ATON) ||
250 (t2->Class == AIS_BASE))
251 n2 = 99999.0;
252 else
253 n2 = t2->CPA;
254
255 b_cmptype_num = true;
256 break;
257 }
258 case tlTCPA: {
259 if ((!t1->bCPA_Valid) || (t1->Class == AIS_ATON) ||
260 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
261 n1 = 99999.0;
262 else
263 n1 = t1->TCPA;
264
265 if ((!t2->bCPA_Valid) || (t2->Class == AIS_ATON) ||
266 (t2->Class == AIS_BASE) || (t2->Class == AIS_METEO))
267 n2 = 99999.0;
268 else
269 n2 = t2->TCPA;
270
271 b_cmptype_num = true;
272 break;
273 }
274 case tlRNG: {
275 n1 = t1->Range_NM;
276 n2 = t2->Range_NM;
277 b_cmptype_num = true;
278 break;
279 }
280
281 default:
282 break;
283 }
284
285 if (!b_cmptype_num) {
286 if (g_bAisTargetList_sortReverse) return s2.Cmp(s1);
287 return s1.Cmp(s2);
288 } else {
289 // If numeric sort values are equal, secondary sort is on Range_NM
290 if (g_bAisTargetList_sortReverse) {
291 if (n2 > n1)
292 return 1;
293 else if (n2 < n1)
294 return -1;
295 else
296 return (t1->Range_NM > t2->Range_NM); // 0;
297 } else {
298 if (n2 > n1)
299 return -1;
300 else if (n2 < n1)
301 return 1;
302 else
303 return (t1->Range_NM > t2->Range_NM); // 0;
304 }
305 }
306}
307
308static int ArrayItemCompareMMSI(int MMSI1, int MMSI2) {
309 if (s_p_sort_decoder) {
310 std::shared_ptr<AisTargetData> pAISTarget1 =
311 s_p_sort_decoder->Get_Target_Data_From_MMSI(MMSI1);
312 std::shared_ptr<AisTargetData> pAISTarget2 =
313 s_p_sort_decoder->Get_Target_Data_From_MMSI(MMSI2);
314
315 if (pAISTarget1 && pAISTarget2)
316 return ItemCompare(pAISTarget1.get(), pAISTarget2.get());
317 else
318 return 0;
319 } else
320 return 0;
321}
322
323AISTargetListDialog::AISTargetListDialog(wxWindow *parent, wxAuiManager *auimgr,
324 AisDecoder *pdecoder)
325 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(-1, -1 /*780, 250*/),
326 wxBORDER_NONE) {
327 m_pparent = parent;
328 m_pAuiManager = auimgr;
329 m_pdecoder = pdecoder;
330 g_bsort_once = false;
331 m_bautosort_force = false;
332
333 wxFont *qFont = GetOCPNScaledFont(_("Dialog"));
334 SetFont(*qFont);
335
336 s_p_sort_decoder = pdecoder;
337 m_pMMSI_array = new ArrayOfMMSI(ArrayItemCompareMMSI);
338
339 CreateControls();
340
341 // Set default color for panel, respecting Dark mode if enabled
342 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
343 SetColorScheme();
344
345 UpdateButtons();
346
347 if (m_pAuiManager) {
348 wxAuiPaneInfo paneproto = wxAuiPaneInfo()
349 .Name("AISTargetList")
350 .CaptionVisible(true)
351 .Float()
352 .FloatingPosition(50, 50)
353 .FloatingSize(400, 200)
354 .BestSize(700, GetCharHeight() * 10);
355
356 // Force and/or override any perspective information that is not
357 // applicable
358 paneproto.Caption(wxGetTranslation(_("AIS target list")));
359 paneproto.Name("AISTargetList");
360 paneproto.DestroyOnClose(true);
361 paneproto.TopDockable(false)
362 .BottomDockable(true)
363 .LeftDockable(false)
364 .RightDockable(false);
365 paneproto.Show(true);
366
367 m_pAuiManager->AddPane(this, paneproto);
368
369 wxAuiPaneInfo &pane = m_pAuiManager->GetPane("AISTargetList");
370
371 if (g_AisTargetList_perspective.IsEmpty()) {
372 if (!g_btouch) RecalculateSize();
373 } else {
374 m_pAuiManager->LoadPaneInfo(g_AisTargetList_perspective, pane);
375 m_pAuiManager->Update();
376 }
377
378 pane = m_pAuiManager->GetPane("AISTargetList"); // Refresh the reference
379
380 // Some special setup for touch screens
381 if (g_btouch) {
382 pane.Float();
383 pane.Dockable(false);
384
385 wxSize screen_size = gFrame->GetClientSize();
386 pane.FloatingSize(screen_size.x * 8 / 10, screen_size.y * 8 / 10);
387 pane.FloatingPosition(screen_size.x * 1 / 10, screen_size.y * 1 / 10);
388 m_pAuiManager->Update();
389 }
390
391 bool b_reset_pos = false;
392 if ((pane.floating_size.x != -1) && (pane.floating_size.y != -1)) {
393#ifdef __WXMSW__
394 // Support MultiMonitor setups which an allow negative window positions.
395 // If the requested window title bar does not intersect any installed
396 // monitor, then default to simple primary monitor positioning.
397 RECT frame_title_rect;
398 frame_title_rect.left = pane.floating_pos.x;
399 frame_title_rect.top = pane.floating_pos.y;
400 frame_title_rect.right = pane.floating_pos.x + pane.floating_size.x;
401 frame_title_rect.bottom = pane.floating_pos.y + 30;
402
403 if (NULL == MonitorFromRect(&frame_title_rect, MONITOR_DEFAULTTONULL))
404 b_reset_pos = true;
405#else
406
407 // Make sure drag bar (title bar) of window intersects wxClient Area of
408 // screen, with a little slop...
409 wxRect window_title_rect; // conservative estimate
410 window_title_rect.x = pane.floating_pos.x;
411 window_title_rect.y = pane.floating_pos.y;
412 window_title_rect.width = pane.floating_size.x;
413 window_title_rect.height = 30;
414
415 wxRect ClientRect = wxGetClientDisplayRect();
416 ClientRect.Deflate(
417 60, 60); // Prevent the new window from being too close to the edge
418 if (!ClientRect.Intersects(window_title_rect)) b_reset_pos = true;
419
420#endif
421
422 if (b_reset_pos) {
423 pane.FloatingPosition(50, 50);
424 m_pAuiManager->Update();
425 }
426 }
427
428 // If the list got accidentally dropped on top of the chart bar, move it
429 // away....
430 if (pane.IsDocked() && (pane.dock_row == 0)) {
431 pane.Float();
432 pane.Row(1);
433 pane.Position(0);
434 m_pAuiManager->Update();
435 }
436
437 pane.Show(true);
438 m_pAuiManager->Update();
439
440 g_AisTargetList_perspective = m_pAuiManager->SavePaneInfo(pane);
441 pConfig->UpdateSettings();
442
443 m_pAuiManager->Connect(
444 wxEVT_AUI_PANE_CLOSE,
445 wxAuiManagerEventHandler(AISTargetListDialog::OnPaneClose), NULL, this);
446
447 } else {
448 // Make an estimate of the default dialog size
449 // for the case when the AUI Perspective for this dialog is undefined
450 wxSize esize;
451 esize.x = 700;
452 esize.y = GetCharHeight() * 10; // 18;
453 SetSize(esize);
454 }
455
456 // Connect Events
457 Connect(wxEVT_CONTEXT_MENU,
458 wxCommandEventHandler(AISTargetListDialog::OnRightClickContext), NULL,
459 this);
460}
461
462AISTargetListDialog::~AISTargetListDialog() {
463 Disconnect_decoder();
464 g_pAISTargetList = NULL;
465}
466
467void AISTargetListDialog::RecalculateSize() {
468 // Make an estimate of the dialog size
469
470 wxSize esize;
471 esize.x = GetCharWidth() * 110;
472 esize.y = GetCharHeight() * 40;
473
474 wxSize dsize = gFrame->GetClientSize();
475 esize.y = wxMin(esize.y, dsize.y - (4 * GetCharHeight()));
476 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
477 SetClientSize(esize);
478
479 wxSize fsize = GetSize();
480 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
481 fsize.x = wxMin(fsize.x, dsize.x - (2 * GetCharHeight()));
482 SetSize(fsize);
483
484 if (m_pAuiManager) {
485 wxAuiPaneInfo &pane = m_pAuiManager->GetPane("AISTargetList");
486
487 if (pane.IsOk()) {
488 pane.FloatingSize(fsize.x, fsize.y);
489 wxPoint pos = gFrame->GetScreenPosition();
490 pane.FloatingPosition(pos.x + (dsize.x - fsize.x) / 2,
491 pos.y + (dsize.y - fsize.y) / 2);
492 }
493
494 m_pAuiManager->Update();
495 }
496}
497
498void AISTargetListDialog::CreateControls() {
499 wxBoxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL);
500 SetSizer(topSizer);
501#ifdef __ANDROID__
502 this->GetHandle()->setStyleSheet(getQtStyleSheet());
503#endif
504
505 // Parse the global column width string as read from config file
506 wxStringTokenizer tkz(g_AisTargetList_column_spec, ";");
507 wxString s_width = tkz.GetNextToken();
508 int width;
509 long lwidth;
510
511 long flags = wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_HRULES | wxLC_VRULES |
512 wxBORDER_SUNKEN;
513#ifndef __WXQT__
514 flags |= wxLC_VIRTUAL;
515#endif
516
517 m_pListCtrlAISTargets = new OCPNListCtrl(
518 this, ID_AIS_TARGET_LIST, wxDefaultPosition, wxDefaultSize, flags);
519
520 wxImageList *imglist = new wxImageList(16, 16, true, 2);
521
522 ocpnStyle::Style *style = g_StyleManager->GetCurrentStyle();
523 imglist->Add(style->GetIcon("sort_asc"));
524 imglist->Add(style->GetIcon("sort_desc"));
525
526 m_pListCtrlAISTargets->AssignImageList(imglist, wxIMAGE_LIST_SMALL);
527 m_pListCtrlAISTargets->Connect(
528 wxEVT_COMMAND_LIST_ITEM_SELECTED,
529 wxListEventHandler(AISTargetListDialog::OnTargetSelected), NULL, this);
530 m_pListCtrlAISTargets->Connect(
531 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
532 wxListEventHandler(AISTargetListDialog::OnTargetSelected), NULL, this);
533 m_pListCtrlAISTargets->Connect(
534 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
535 wxListEventHandler(AISTargetListDialog::OnTargetDefaultAction), NULL,
536 this);
537 m_pListCtrlAISTargets->Connect(
538 wxEVT_COMMAND_LIST_COL_CLICK,
539 wxListEventHandler(AISTargetListDialog::OnTargetListColumnClicked), NULL,
540 this);
541
542 int dx = GetCharWidth();
543
544 width = dx * 4;
545 if (s_width.ToLong(&lwidth)) {
546 width = wxMax(dx * 2, lwidth);
547 width = wxMin(width, dx * 30);
548 }
549 m_pListCtrlAISTargets->InsertColumn(tlTRK, _("Trk"), wxLIST_FORMAT_LEFT,
550 width);
551 s_width = tkz.GetNextToken();
552
553 width = dx * 12;
554 if (s_width.ToLong(&lwidth)) {
555 width = wxMax(dx * 2, lwidth);
556 width = wxMin(width, dx * 30);
557 }
558 m_pListCtrlAISTargets->InsertColumn(tlNAME, _("Name"), wxLIST_FORMAT_LEFT,
559 width);
560 s_width = tkz.GetNextToken();
561
562 width = dx * 7;
563 if (s_width.ToLong(&lwidth)) {
564 width = wxMax(dx * 2, lwidth);
565 width = wxMin(width, dx * 30);
566 }
567 m_pListCtrlAISTargets->InsertColumn(tlCALL, _("Call"), wxLIST_FORMAT_LEFT,
568 width);
569 s_width = tkz.GetNextToken();
570
571 width = dx * 10;
572 if (s_width.ToLong(&lwidth)) {
573 width = wxMax(dx * 2, lwidth);
574 width = wxMin(width, dx * 30);
575 }
576 m_pListCtrlAISTargets->InsertColumn(tlMMSI, _("MMSI"), wxLIST_FORMAT_LEFT,
577 width);
578 s_width = tkz.GetNextToken();
579
580 width = dx * 7;
581 if (s_width.ToLong(&lwidth)) {
582 width = wxMax(dx * 2, lwidth);
583 width = wxMin(width, dx * 30);
584 }
585 m_pListCtrlAISTargets->InsertColumn(tlCLASS, _("Class"), wxLIST_FORMAT_CENTER,
586 width);
587 s_width = tkz.GetNextToken();
588
589 width = dx * 10;
590 if (s_width.ToLong(&lwidth)) {
591 width = wxMax(dx * 2, lwidth);
592 width = wxMin(width, dx * 30);
593 }
594 m_pListCtrlAISTargets->InsertColumn(tlTYPE, _("Type"), wxLIST_FORMAT_LEFT,
595 width);
596 s_width = tkz.GetNextToken();
597
598 width = dx * 12;
599 if (s_width.ToLong(&lwidth)) {
600 width = wxMax(dx * 2, lwidth);
601 width = wxMin(width, dx * 30);
602 }
603 m_pListCtrlAISTargets->InsertColumn(tlNAVSTATUS, _("Flag"),
604 wxLIST_FORMAT_LEFT, width);
605 s_width = tkz.GetNextToken();
606
607 width = dx * 12;
608 if (s_width.ToLong(&lwidth)) {
609 width = wxMax(dx * 2, lwidth);
610 width = wxMin(width, dx * 30);
611 }
612 m_pListCtrlAISTargets->InsertColumn(tlNAVSTATUS, _("Nav Status"),
613 wxLIST_FORMAT_LEFT, width);
614 s_width = tkz.GetNextToken();
615
616 width = dx * 6;
617 if (s_width.ToLong(&lwidth)) {
618 width = wxMax(dx * 2, lwidth);
619 width = wxMin(width, dx * 30);
620 }
621 m_pListCtrlAISTargets->InsertColumn(tlBRG, _("Brg"), wxLIST_FORMAT_RIGHT,
622 width);
623 s_width = tkz.GetNextToken();
624
625 width = dx * 8;
626 if (s_width.ToLong(&lwidth)) {
627 width = wxMax(dx * 2, lwidth);
628 width = wxMin(width, dx * 30);
629 }
630 m_pListCtrlAISTargets->InsertColumn(tlRNG, _("Range"), wxLIST_FORMAT_RIGHT,
631 width);
632 s_width = tkz.GetNextToken();
633
634 width = dx * 6;
635 if (s_width.ToLong(&lwidth)) {
636 width = wxMax(dx * 2, lwidth);
637 width = wxMin(width, dx * 30);
638 }
639 m_pListCtrlAISTargets->InsertColumn(tlCOG, _("CoG"), wxLIST_FORMAT_RIGHT,
640 width);
641 s_width = tkz.GetNextToken();
642
643 width = dx * 6;
644 if (s_width.ToLong(&lwidth)) {
645 width = wxMax(dx * 2, lwidth);
646 width = wxMin(width, dx * 30);
647 }
648 m_pListCtrlAISTargets->InsertColumn(tlSOG, _("SoG"), wxLIST_FORMAT_RIGHT,
649 width);
650
651 width = dx * 7;
652 if (s_width.ToLong(&lwidth)) {
653 width = wxMax(dx * 2, lwidth);
654 width = wxMin(width, dx * 30);
655 }
656 m_pListCtrlAISTargets->InsertColumn(tlCPA, _("CPA"), wxLIST_FORMAT_RIGHT,
657 width);
658
659 width = dx * 8;
660 if (s_width.ToLong(&lwidth)) {
661 width = wxMax(dx * 2, lwidth);
662 width = wxMin(width, dx * 30);
663 }
664 m_pListCtrlAISTargets->InsertColumn(tlTCPA, _("TCPA"), wxLIST_FORMAT_RIGHT,
665 width);
666 wxListItem item;
667 item.SetMask(wxLIST_MASK_IMAGE);
668 item.SetImage(g_bAisTargetList_sortReverse ? 1 : 0);
669 g_AisTargetList_sortColumn = wxMax(g_AisTargetList_sortColumn, 0);
670 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
671
672#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
673 wxStringTokenizer tkz_order(g_AisTargetList_column_order, ";");
674 wxString s_order = tkz_order.GetNextToken();
675 int i_columns = m_pListCtrlAISTargets->GetColumnCount();
676 wxArrayInt a_order(i_columns);
677 for (int i = 0; i < i_columns; i++) {
678 long l_order = (long)i;
679 s_order.ToLong(&l_order);
680 if (l_order < 0 || l_order > i_columns) {
681 l_order = i;
682 }
683 a_order[i] = l_order;
684 s_order = tkz_order.GetNextToken();
685 }
686
687 m_pListCtrlAISTargets->SetColumnsOrder(a_order);
688#endif
689
690 topSizer->Add(m_pListCtrlAISTargets, 1, wxEXPAND | wxALL, 0);
691
692 wxBoxSizer *boxSizer02 = new wxBoxSizer(wxVERTICAL);
693 boxSizer02->AddSpacer(22);
694 topSizer->Add(boxSizer02, 0, wxEXPAND | wxALL, 2);
695
696 wxScrolledWindow *winr =
697 new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
698 wxNO_BORDER | wxTAB_TRAVERSAL | wxVSCROLL);
699 winr->SetScrollRate(0, 5);
700
701 boxSizer02->Add(winr, 1, wxALL | wxEXPAND, 3);
702
703 wxBoxSizer *bsRouteButtonsInner = new wxBoxSizer(wxVERTICAL);
704 winr->SetSizer(bsRouteButtonsInner);
705
706 m_pButtonInfo = new wxButton(winr, wxID_ANY, _("Target info"),
707 wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW);
708 m_pButtonInfo->Connect(
709 wxEVT_COMMAND_BUTTON_CLICKED,
710 wxCommandEventHandler(AISTargetListDialog::OnTargetQuery), NULL, this);
711 bsRouteButtonsInner->Add(m_pButtonInfo, 0, wxEXPAND | wxALL, 2);
712 bsRouteButtonsInner->AddSpacer(5);
713
714 m_pButtonJumpTo =
715 new wxButton(winr, wxID_ANY, _("Center view"), wxDefaultPosition,
716 wxDefaultSize, wxBU_AUTODRAW);
717 m_pButtonJumpTo->Connect(
718 wxEVT_COMMAND_BUTTON_CLICKED,
719 wxCommandEventHandler(AISTargetListDialog::OnTargetScrollTo), NULL, this);
720 bsRouteButtonsInner->Add(m_pButtonJumpTo, 0, wxEXPAND | wxALL, 2);
721
722 m_pButtonJumpTo_Close =
723 new wxButton(winr, wxID_ANY, _("Center-Info-Close"), wxDefaultPosition,
724 wxDefaultSize, wxBU_AUTODRAW);
725 m_pButtonJumpTo_Close->Connect(
726 wxEVT_COMMAND_BUTTON_CLICKED,
727 wxCommandEventHandler(AISTargetListDialog::OnTargetScrollToClose), NULL,
728 this);
729 bsRouteButtonsInner->Add(m_pButtonJumpTo_Close, 0, wxEXPAND | wxALL, 2);
730
731 m_pButtonCreateWpt =
732 new wxButton(winr, wxID_ANY, _("Create WPT"), wxDefaultPosition,
733 wxDefaultSize, wxBU_AUTODRAW);
734 m_pButtonCreateWpt->Connect(
735 wxEVT_COMMAND_BUTTON_CLICKED,
736 wxCommandEventHandler(AISTargetListDialog::OnTargetCreateWpt), NULL,
737 this);
738 bsRouteButtonsInner->Add(m_pButtonCreateWpt, 0, wxEXPAND | wxALL, 0);
739
740 m_pButtonHideAllTracks =
741 new wxButton(winr, wxID_ANY, _("Hide All Tracks"), wxDefaultPosition,
742 wxDefaultSize, wxBU_AUTODRAW);
743 m_pButtonHideAllTracks->Connect(
744 wxEVT_COMMAND_BUTTON_CLICKED,
745 wxCommandEventHandler(AISTargetListDialog::OnHideAllTracks), NULL, this);
746 bsRouteButtonsInner->Add(m_pButtonHideAllTracks, 0, wxEXPAND | wxALL, 2);
747
748 m_pButtonShowAllTracks =
749 new wxButton(winr, wxID_ANY, _("Show All Tracks"), wxDefaultPosition,
750 wxDefaultSize, wxBU_AUTODRAW);
751 m_pButtonShowAllTracks->Connect(
752 wxEVT_COMMAND_BUTTON_CLICKED,
753 wxCommandEventHandler(AISTargetListDialog::OnShowAllTracks), NULL, this);
754 bsRouteButtonsInner->Add(m_pButtonShowAllTracks, 0, wxEXPAND | wxALL, 2);
755
756 m_pButtonToggleTrack =
757 new wxButton(winr, wxID_ANY, _("Toggle track"), wxDefaultPosition,
758 wxDefaultSize, wxBU_AUTODRAW);
759 m_pButtonToggleTrack->Connect(
760 wxEVT_COMMAND_BUTTON_CLICKED,
761 wxCommandEventHandler(AISTargetListDialog::OnToggleTrack), NULL, this);
762 bsRouteButtonsInner->Add(m_pButtonToggleTrack, 0, wxEXPAND | wxALL, 2);
763
764 m_pButtonCopyMMSI =
765 new wxButton(winr, wxID_ANY, _("Copy MMSI"), wxDefaultPosition,
766 wxDefaultSize, wxBU_AUTODRAW);
767 m_pButtonCopyMMSI->Connect(
768 wxEVT_COMMAND_BUTTON_CLICKED,
769 wxCommandEventHandler(AISTargetListDialog::OnCopyMMSI), NULL, this);
770 bsRouteButtonsInner->Add(m_pButtonCopyMMSI, 0, wxEXPAND | wxALL, 2);
771
772 m_pCBAutosort =
773 new wxCheckBox(winr, wxID_ANY, _("AutoSort"), wxDefaultPosition,
774 wxDefaultSize, wxBU_AUTODRAW);
775 m_pCBAutosort->Connect(
776 wxEVT_COMMAND_CHECKBOX_CLICKED,
777 wxCommandEventHandler(AISTargetListDialog::OnAutosortCB), NULL, this);
778 bsRouteButtonsInner->Add(m_pCBAutosort, 0, wxEXPAND | wxALL, 2);
779 g_bAisTargetList_autosort = true;
780 m_pCBAutosort->SetValue(g_bAisTargetList_autosort);
781
782 bsRouteButtonsInner->AddSpacer(10);
783
784 m_pStaticTextRange = new wxStaticText(winr, wxID_ANY, _("Limit range: NM"),
785 wxDefaultPosition, wxDefaultSize, 0);
786 bsRouteButtonsInner->Add(m_pStaticTextRange, 0, wxALL, 2);
787 bsRouteButtonsInner->AddSpacer(2);
788 m_pSpinCtrlRange = new wxSpinCtrl(
789 winr, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(50, -1),
790 wxSP_ARROW_KEYS, 1, 20000, g_AisTargetList_range);
791 m_pSpinCtrlRange->Connect(
792 wxEVT_COMMAND_SPINCTRL_UPDATED,
793 wxCommandEventHandler(AISTargetListDialog::OnLimitRange), NULL, this);
794 m_pSpinCtrlRange->Connect(
795 wxEVT_COMMAND_TEXT_UPDATED,
796 wxCommandEventHandler(AISTargetListDialog::OnLimitRange), NULL, this);
797 bsRouteButtonsInner->Add(m_pSpinCtrlRange, 0, wxEXPAND | wxALL, 0);
798
799 bsRouteButtonsInner->AddSpacer(10);
800 m_pStaticTextCount = new wxStaticText(winr, wxID_ANY, _("Target Count"),
801 wxDefaultPosition, wxDefaultSize, 0);
802 bsRouteButtonsInner->Add(m_pStaticTextCount, 0, wxALL, 2);
803
804 bsRouteButtonsInner->AddSpacer(2);
805 m_pTextTargetCount = new wxTextCtrl(winr, wxID_ANY, "", wxDefaultPosition,
806 wxDefaultSize, wxTE_READONLY);
807 m_pTextTargetCount->SetMinSize(wxSize(6 * GetCharWidth(), -1));
808 bsRouteButtonsInner->Add(m_pTextTargetCount, 0, wxALL, 2);
809
810 bsRouteButtonsInner->AddSpacer(10);
811 m_pButtonOK = new wxButton(winr, wxID_ANY, _("Close"), wxDefaultPosition,
812 wxDefaultSize, wxBU_AUTODRAW);
813 m_pButtonOK->Connect(
814 wxEVT_COMMAND_BUTTON_CLICKED,
815 wxCommandEventHandler(AISTargetListDialog::OnCloseButton), NULL, this);
816 bsRouteButtonsInner->Add(m_pButtonOK, 0, wxEXPAND | wxALL, 0);
817
818 topSizer->Layout();
819
820 // This is silly, but seems to be required for __WXMSW__ build
821 // If not done, the SECOND invocation of AISTargetList fails to expand the
822 // list to the full wxSizer size....
823 SetSize(GetSize().x, GetSize().y - 1);
824}
825
826void AISTargetListDialog::OnClose(wxCloseEvent &event) {
827 Disconnect_decoder();
828 Hide();
829 g_pAISTargetList = NULL;
830}
831
832void AISTargetListDialog::Disconnect_decoder() { m_pdecoder = NULL; }
833
834void AISTargetListDialog::SetColorScheme() { DimeControl(this); }
835
836void AISTargetListDialog::OnPaneClose(wxAuiManagerEvent &event) {
837 if (event.pane->name == "AISTargetList") {
838 g_AisTargetList_perspective = m_pAuiManager->SavePaneInfo(*event.pane);
839 }
840 event.Skip();
841}
842
843void AISTargetListDialog::OnCloseButton(wxCommandEvent &event) { Shutdown(); }
844
845void AISTargetListDialog::Shutdown(void) {
846 if (m_pAuiManager) {
847 wxAuiPaneInfo pane = m_pAuiManager->GetPane(this);
848 g_AisTargetList_perspective = m_pAuiManager->SavePaneInfo(pane);
849 m_pAuiManager->DetachPane(this);
850 Disconnect_decoder();
851 pane.Show(false);
852 m_pAuiManager->Update();
853#ifdef __ANDROID__
854 GetParent()->Refresh(true);
855#endif
856 Destroy();
857 }
858}
859
860void AISTargetListDialog::UpdateButtons() {
861 long item = -1;
862 item = m_pListCtrlAISTargets->GetNextItem(item, wxLIST_NEXT_ALL,
863 wxLIST_STATE_SELECTED);
864 bool enable = (item != -1);
865
866 m_pButtonInfo->Enable(enable);
867
868 if (m_pdecoder && item != -1) {
869 auto pAISTargetSel =
870 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(item));
871 if (pAISTargetSel && (!pAISTargetSel->b_positionOnceValid)) enable = false;
872 }
873 m_pButtonJumpTo->Enable(enable);
874 m_pButtonJumpTo_Close->Enable(enable);
875 m_pButtonCreateWpt->Enable(enable);
876 m_pButtonToggleTrack->Enable(enable);
877 m_pButtonCopyMMSI->Enable(enable);
878}
879
880void AISTargetListDialog::OnTargetSelected(wxListEvent &event) {
881 UpdateButtons();
882}
883
884void AISTargetListDialog::DoTargetQuery(int mmsi) {
885 ShowAISTargetQueryDialog(m_pparent, mmsi);
886}
887
888/*
889 ** When an item is activated in AIS TArget List then opens the AIS Target Query
890 *Dialog
891 */
892void AISTargetListDialog::OnTargetDefaultAction(wxListEvent &event) {
893 long mmsi_no;
894 if ((mmsi_no = event.GetData())) DoTargetQuery(mmsi_no);
895}
896
897void AISTargetListDialog::OnTargetQuery(wxCommandEvent &event) {
898 long selItemID = -1;
899 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
900 wxLIST_STATE_SELECTED);
901 if (selItemID == -1) return;
902
903 if (m_pdecoder) {
904 auto pAISTarget =
905 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
906 if (pAISTarget) DoTargetQuery(pAISTarget->MMSI);
907 }
908}
909
910void AISTargetListDialog::OnAutosortCB(wxCommandEvent &event) {
911 g_bAisTargetList_autosort = m_pCBAutosort->GetValue();
912
913 m_bautosort_force = g_bAisTargetList_autosort;
914
915 if (!g_bAisTargetList_autosort) {
916 wxListItem item;
917 item.SetMask(wxLIST_MASK_IMAGE);
918 item.SetImage(-1);
919 g_AisTargetList_sortColumn = wxMax(g_AisTargetList_sortColumn, 0);
920 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
921 } else {
922 wxListItem item;
923 item.SetMask(wxLIST_MASK_IMAGE);
924 item.SetImage(g_bAisTargetList_sortReverse ? 1 : 0);
925
926 if (g_AisTargetList_sortColumn >= 0) {
927 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
928 UpdateAISTargetList();
929 }
930 }
931}
932
933void AISTargetListDialog::OnTargetListColumnClicked(wxListEvent &event) {
934 int key = event.GetColumn();
935 wxListItem item;
936 item.SetMask(wxLIST_MASK_IMAGE);
937 if (key == g_AisTargetList_sortColumn)
938 g_bAisTargetList_sortReverse = !g_bAisTargetList_sortReverse;
939 else {
940 item.SetImage(-1);
941 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
942 g_bAisTargetList_sortReverse = false;
943 g_AisTargetList_sortColumn = key;
944 }
945 item.SetImage(g_bAisTargetList_sortReverse ? 1 : 0);
946
947 if (!g_bAisTargetList_autosort) g_bsort_once = true;
948
949 if (g_AisTargetList_sortColumn >= 0) {
950 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
951 UpdateAISTargetList();
952 }
953}
954
955void AISTargetListDialog::OnTargetScrollTo(wxCommandEvent &event) {
956 CenterToTarget(false);
957}
958
959void AISTargetListDialog::OnTargetScrollToClose(wxCommandEvent &event) {
960 CenterToTarget(true);
961}
962
963void AISTargetListDialog::OnTargetCreateWpt(wxCommandEvent &event) {
964 long selItemID = -1;
965 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
966 wxLIST_STATE_SELECTED);
967 if (selItemID == -1) return;
968
969 std::shared_ptr<AisTargetData> pAISTarget = NULL;
970 if (m_pdecoder)
971 pAISTarget =
972 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
973
974 if (pAISTarget) {
975 RoutePoint *pWP =
976 new RoutePoint(pAISTarget->Lat, pAISTarget->Lon, g_default_wp_icon,
977 wxEmptyString, wxEmptyString);
978 pWP->m_bIsolatedMark = true; // This is an isolated mark
979 pSelect->AddSelectableRoutePoint(pAISTarget->Lat, pAISTarget->Lon, pWP);
980 // pConfig->AddNewWayPoint(pWP, -1); // use auto next num
981 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
982
983 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
984 pRouteManagerDialog->UpdateWptListCtrl();
985 gFrame->GetPrimaryCanvas()->undo->BeforeUndoableAction(
986 Undo_CreateWaypoint, pWP, Undo_HasParent, NULL);
987 gFrame->GetPrimaryCanvas()->undo->AfterUndoableAction(NULL);
988 Refresh(false);
989 }
990}
991
992void AISTargetListDialog::OnShowAllTracks(wxCommandEvent &event) {
993 if (m_pdecoder) {
994 for (const auto &it : m_pdecoder->GetTargetList()) {
995 auto pAISTarget = it.second;
996 if (NULL != pAISTarget) {
997 pAISTarget->b_show_track = true;
998
999 // Check for any persistently tracked target, force b_show_track_old ON
1000 std::map<int, Track *>::iterator it;
1001 it = g_pAIS->m_persistent_tracks.find(pAISTarget->MMSI);
1002 if (it != g_pAIS->m_persistent_tracks.end()) {
1003 pAISTarget->b_show_track_old = true;
1004 }
1005 }
1006 }
1007 UpdateAISTargetList();
1008 }
1009}
1010
1011void AISTargetListDialog::OnHideAllTracks(wxCommandEvent &event) {
1012 if (m_pdecoder) {
1013 for (const auto &it : m_pdecoder->GetTargetList()) {
1014 auto pAISTarget = it.second;
1015 if (NULL != pAISTarget) {
1016 pAISTarget->b_show_track = false;
1017
1018 // Check for any persistently tracked target, force b_show_track ON
1019 std::map<int, Track *>::iterator it;
1020 it = g_pAIS->m_persistent_tracks.find(pAISTarget->MMSI);
1021 if (it != g_pAIS->m_persistent_tracks.end()) {
1022 pAISTarget->b_show_track = true;
1023 pAISTarget->b_show_track_old = false;
1024 }
1025 }
1026 }
1027 UpdateAISTargetList();
1028 }
1029}
1030
1031void AISTargetListDialog::OnToggleTrack(wxCommandEvent &event) {
1032 long selItemID = -1;
1033 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1034 wxLIST_STATE_SELECTED);
1035 if (selItemID == -1) return;
1036
1037 std::shared_ptr<AisTargetData> pAISTarget = NULL;
1038 if (m_pdecoder)
1039 pAISTarget =
1040 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
1041
1042 if (pAISTarget) {
1043 pAISTarget->b_show_track_old =
1044 pAISTarget->b_show_track; // Store current state before toggling
1045 pAISTarget->b_show_track = !pAISTarget->b_show_track; // Toggle visibility
1046 UpdateAISTargetList();
1047 }
1048}
1049
1050void AISTargetListDialog::OnCopyMMSI(wxCommandEvent &event) {
1051 long selItemID = -1;
1052 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1053 wxLIST_STATE_SELECTED);
1054 if (selItemID == -1) return;
1055 CopyMMSItoClipBoard((int)m_pMMSI_array->Item(selItemID));
1056}
1057
1058void AISTargetListDialog::CenterToTarget(bool close) {
1059 long selItemID = -1;
1060 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1061 wxLIST_STATE_SELECTED);
1062 if (selItemID == -1) return;
1063
1064 std::shared_ptr<AisTargetData> pAISTarget = NULL;
1065 if (m_pdecoder)
1066 pAISTarget =
1067 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
1068
1069 if (pAISTarget) {
1070 double scale = gFrame->GetFocusCanvas()->GetVPScale();
1071 if (!close) {
1072 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), pAISTarget->Lat,
1073 pAISTarget->Lon, scale);
1074 } else {
1075 // Set a resonable (1:5000) chart scale to see the target.
1076 if (scale < 0.7) { // Don't zoom if already close.
1077 ChartCanvas *cc = gFrame->GetFocusCanvas();
1078 double factor = cc->GetScaleValue() / 5000.0;
1079 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), pAISTarget->Lat,
1080 pAISTarget->Lon, scale * factor);
1081 }
1082 DoTargetQuery(pAISTarget->MMSI);
1083 // Close AIS target list
1084 Shutdown();
1085 }
1086 }
1087}
1088
1089void AISTargetListDialog::CopyMMSItoClipBoard(int mmsi) {
1090 // Write MMSI # as text to the clipboard
1091 if (wxTheClipboard->Open()) {
1092 wxTheClipboard->SetData(
1093 new wxTextDataObject(wxString::Format("%09d", mmsi)));
1094 wxTheClipboard->Close();
1095 }
1096}
1097void AISTargetListDialog::OnLimitRange(wxCommandEvent &event) {
1098 g_AisTargetList_range = m_pSpinCtrlRange->GetValue();
1099 UpdateAISTargetList();
1100}
1101
1102std::shared_ptr<AisTargetData> AISTargetListDialog::GetpTarget(
1103 unsigned int list_item) {
1104 if (m_pdecoder)
1105 return m_pdecoder->Get_Target_Data_From_MMSI(
1106 m_pMMSI_array->Item(list_item));
1107 else
1108 return NULL;
1109}
1110
1111void AISTargetListDialog::UpdateAISTargetList(void) {
1112 if (m_pListCtrlAISTargets && !m_pListCtrlAISTargets->IsVirtual())
1113 return UpdateNVAISTargetList();
1114
1115 if (m_pdecoder && m_pListCtrlAISTargets) {
1116 // Capture the MMSI of the curently selected list item
1117 long selItemID = -1;
1118 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1119 wxLIST_STATE_SELECTED);
1120
1121 int selMMSI = -1;
1122 if (selItemID != -1) selMMSI = m_pMMSI_array->Item(selItemID);
1123
1124 const auto &current_targets = m_pdecoder->GetTargetList();
1125 wxListItem item;
1126
1127 int index = 0;
1128 m_pMMSI_array->Clear();
1129
1130 for (auto it = current_targets.begin(); it != current_targets.end();
1131 ++it, ++index) {
1132 auto pAISTarget = it->second;
1133 item.SetId(index);
1134
1135 if (NULL != pAISTarget) {
1136 bool b_add = false;
1137 if ((pAISTarget->b_positionOnceValid) &&
1138 (pAISTarget->Range_NM <= g_AisTargetList_range))
1139 b_add = true;
1140 else if (!pAISTarget->b_positionOnceValid)
1141 b_add = true;
1142
1143 // Do not show any "lost" targets in the list.
1144 if (pAISTarget->b_lost) b_add = false;
1145
1146 if (b_add) {
1147 m_pMMSI_array->Add(pAISTarget->MMSI);
1148 }
1149 }
1150 }
1151
1152 g_bsort_once = false;
1153
1154 m_pListCtrlAISTargets->SetItemCount(m_pMMSI_array->GetCount());
1155
1156 g_AisTargetList_count = m_pMMSI_array->GetCount();
1157
1158 if ((g_AisTargetList_count > 1000) && !m_bautosort_force)
1159 g_bAisTargetList_autosort = false;
1160
1161 m_pCBAutosort->SetValue(g_bAisTargetList_autosort);
1162
1163 // Restore selected item
1164 long item_sel = 0;
1165 if ((selItemID != -1) && (selMMSI != -1)) {
1166 for (unsigned int i = 0; i < m_pMMSI_array->GetCount(); i++) {
1167 if (m_pMMSI_array->Item(i) == selMMSI) {
1168 item_sel = i;
1169 break;
1170 }
1171 }
1172 }
1173
1174 if (m_pMMSI_array->GetCount())
1175 m_pListCtrlAISTargets->SetItemState(
1176 item_sel, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
1177 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1178 else
1179 m_pListCtrlAISTargets->DeleteAllItems();
1180
1181 wxString count;
1182 count.Printf("%lu", (unsigned long)m_pMMSI_array->GetCount());
1183 m_pTextTargetCount->ChangeValue(count);
1184
1185#ifdef __WXMSW__
1186 m_pListCtrlAISTargets->Refresh(false);
1187#endif
1188 }
1189}
1190
1191void AISTargetListDialog::UpdateNVAISTargetList(void) {
1192 if (m_pdecoder) {
1193 // Capture the MMSI of the curently selected list item
1194 long selItemID = -1;
1195 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1196 wxLIST_STATE_SELECTED);
1197
1198 int selMMSI = -1;
1199 if (selItemID != -1) selMMSI = m_pMMSI_array->Item(selItemID);
1200
1201 const auto &current_targets = m_pdecoder->GetTargetList();
1202 wxListItem item;
1203
1204 int index = 0;
1205 m_pMMSI_array->Clear();
1206
1207 for (auto it = current_targets.begin(); it != current_targets.end();
1208 ++it, ++index) {
1209 auto pAISTarget = it->second;
1210 item.SetId(index);
1211
1212 if (NULL != pAISTarget) {
1213 bool b_add = false;
1214 if ((pAISTarget->b_positionOnceValid) &&
1215 (pAISTarget->Range_NM <= g_AisTargetList_range))
1216 b_add = true;
1217 else if (!pAISTarget->b_positionOnceValid)
1218 b_add = true;
1219
1220 if (b_add) {
1221 m_pMMSI_array->Add(pAISTarget->MMSI);
1222 }
1223 }
1224 }
1225
1226 g_bsort_once = false;
1227
1228 g_AisTargetList_count = m_pMMSI_array->GetCount();
1229
1230 m_pListCtrlAISTargets->DeleteAllItems();
1231
1232 for (int i = 0; i < g_AisTargetList_count; i++) {
1233 wxListItem item;
1234 item.SetId(i);
1235 m_pListCtrlAISTargets->InsertItem(item);
1236 for (int j = 0; j < tlTCPA + 1; j++) {
1237 item.SetColumn(j);
1238 item.SetText(m_pListCtrlAISTargets->OnGetItemText(i, j));
1239 m_pListCtrlAISTargets->SetItem(item);
1240 }
1241 }
1242
1243 if ((g_AisTargetList_count > 1000) && !m_bautosort_force)
1244 g_bAisTargetList_autosort = false;
1245
1246 m_pCBAutosort->SetValue(g_bAisTargetList_autosort);
1247
1248 // Restore selected item
1249 long item_sel = 0;
1250 if ((selItemID != -1) && (selMMSI != -1)) {
1251 for (unsigned int i = 0; i < m_pMMSI_array->GetCount(); i++) {
1252 if (m_pMMSI_array->Item(i) == selMMSI) {
1253 item_sel = i;
1254 break;
1255 }
1256 }
1257 }
1258
1259 if (m_pMMSI_array->GetCount())
1260 m_pListCtrlAISTargets->SetItemState(
1261 item_sel, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
1262 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1263 else
1264 m_pListCtrlAISTargets->DeleteAllItems();
1265
1266 wxString count;
1267 count.Printf("%lu", (unsigned long)m_pMMSI_array->GetCount());
1268 m_pTextTargetCount->ChangeValue(count);
1269
1270#ifdef __WXMSW__
1271 m_pListCtrlAISTargets->Refresh(false);
1272#endif
1273 }
1274}
1275
1276void AISTargetListDialog::OnRightClickContext(wxCommandEvent &event) {
1277 wxAuiPaneInfo &pane = m_pAuiManager->GetPane("AISTargetList");
1278 if (pane.IsDocked()) {
1279 wxMenu *popup = new wxMenu();
1280 popup->Append(ID_RCLK_UNDOCK, _("Undock Target List"));
1281 popup->Connect(wxEVT_COMMAND_MENU_SELECTED,
1282 wxCommandEventHandler(AISTargetListDialog::OnContextUndock),
1283 NULL, this);
1284
1285 PopupMenu(popup);
1286 delete popup;
1287 }
1288}
1289
1290void AISTargetListDialog::OnContextUndock(wxCommandEvent &event) {
1291 wxAuiPaneInfo &pane = m_pAuiManager->GetPane("AISTargetList");
1292 pane.Float();
1293 m_pAuiManager->Update();
1294}
Class AisDecoder and helpers.
Global state for AIS decoder.
Class AISTargetListDialog.
AISTargetListDialog * g_pAISTargetList
Global instance.
Generic Chart canvas base.
Dialog for displaying a list of AIS targets.
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:151
Main application frame.
Definition ocpn_frame.h:138
A custom list control for displaying AIS target information.
Represents a waypoint or mark within the navigation system.
Definition route_point.h:70
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:56
Class NavObj_dB.