25#include <wx/textctrl.h>
27#include <wx/tokenzr.h>
28#include <wx/clipbrd.h>
31#include "androidUTIL.h"
34#include "model/ais_decoder.h"
36#include "model/ais_target_data.h"
37#include "model/route_point.h"
38#include "model/select.h"
41#include "AISTargetListDialog.h"
43#include "ocpn_frame.h"
44#include "OCPNListCtrl.h"
45#include "OCPNPlatform.h"
46#include "routemanagerdialog.h"
51extern int g_AisTargetList_count;
52extern bool g_bAisTargetList_autosort;
57extern wxString g_default_wp_icon;
63EVT_CLOSE(AISTargetListDialog::OnClose)
66static
bool g_bsort_once;
72 bool b_cmptype_num =
false;
75 if (!g_bAisTargetList_autosort && !g_bsort_once)
return 0;
80 if (t1->Class == AIS_SART) {
81 if (t2->Class == AIS_DSC)
87 if (t2->Class == AIS_SART) {
88 if (t1->Class == AIS_DSC)
94 switch (g_AisTargetList_sortColumn) {
96 n1 = t1->b_show_track;
97 n2 = t2->b_show_track;
102 s1 = trimAISField(t1->ShipName);
103 if ((!t1->b_nameValid && (t1->Class == AIS_BASE)) ||
104 (t1->Class == AIS_SART))
107 s2 = trimAISField(t2->ShipName);
108 if ((!t2->b_nameValid && (t2->Class == AIS_BASE)) ||
109 (t2->Class == AIS_SART))
114 s1 = trimAISField(t1->CallSign);
115 s2 = trimAISField(t2->CallSign);
121 b_cmptype_num =
true;
125 s1 = t1->Get_class_string(
true);
126 s2 = t2->Get_class_string(
true);
130 s1 = t1->Get_vessel_type_string(
false);
131 if ((t1->Class == AIS_BASE) ||
132 (t1->Class == AIS_SART || (t1->Class == AIS_METEO)))
135 s2 = t2->Get_vessel_type_string(
false);
136 if ((t1->Class == AIS_BASE) || (t1->Class == AIS_SART) ||
137 (t1->Class == AIS_METEO))
142 if ((t1->NavStatus <= 15) && (t1->NavStatus >= 0)) {
143 if (t1->Class == AIS_SART) {
144 if (t1->NavStatus == RESERVED_14)
146 else if (t1->NavStatus == UNDEFINED)
149 s1 = ais_get_status(t1->NavStatus);
153 if ((t1->Class == AIS_ATON) || (t1->Class == AIS_BASE) ||
154 (t1->Class == AIS_CLASS_B) || (t1->Class == AIS_METEO))
157 if ((t2->NavStatus <= 15) && (t2->NavStatus >= 0)) {
158 if (t2->Class == AIS_SART) {
159 if (t2->NavStatus == RESERVED_14)
161 else if (t2->NavStatus == UNDEFINED)
164 s2 = ais_get_status(t2->NavStatus);
168 if ((t2->Class == AIS_ATON) || (t2->Class == AIS_BASE) ||
169 (t2->Class == AIS_CLASS_B) || (t2->Class == AIS_METEO))
176 int brg1 = wxRound(t1->Brg);
182 int brg2 = wxRound(t2->Brg);
188 b_cmptype_num =
true;
193 if ((t1->COG >= 360.0) || (t1->Class == AIS_ATON) ||
194 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
197 int crs = wxRound(t1->COG);
204 if ((t2->COG >= 360.0) || (t2->Class == AIS_ATON) ||
205 (t2->Class == AIS_BASE) || (t2->Class == AIS_METEO))
208 int crs = wxRound(t2->COG);
215 b_cmptype_num =
true;
220 if ((t1->SOG > 100.) || (t1->Class == AIS_ATON) ||
221 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
226 if ((t2->SOG > 100.) || (t2->Class == AIS_ATON) ||
227 (t2->Class == AIS_BASE) || (t2->Class == AIS_METEO))
232 b_cmptype_num =
true;
236 if ((!t1->bCPA_Valid) || (t1->Class == AIS_ATON) ||
237 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
242 if ((!t2->bCPA_Valid) || (t2->Class == AIS_ATON) ||
243 (t2->Class == AIS_BASE))
248 b_cmptype_num =
true;
252 if ((!t1->bCPA_Valid) || (t1->Class == AIS_ATON) ||
253 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
258 if ((!t2->bCPA_Valid) || (t2->Class == AIS_ATON) ||
259 (t2->Class == AIS_BASE) || (t2->Class == AIS_METEO))
264 b_cmptype_num =
true;
270 b_cmptype_num =
true;
278 if (!b_cmptype_num) {
279 if (g_bAisTargetList_sortReverse)
return s2.Cmp(s1);
283 if (g_bAisTargetList_sortReverse) {
289 return (t1->Range_NM > t2->Range_NM);
296 return (t1->Range_NM > t2->Range_NM);
301static int ArrayItemCompareMMSI(
int MMSI1,
int MMSI2) {
302 if (s_p_sort_decoder) {
303 std::shared_ptr<AisTargetData> pAISTarget1 =
304 s_p_sort_decoder->Get_Target_Data_From_MMSI(MMSI1);
305 std::shared_ptr<AisTargetData> pAISTarget2 =
306 s_p_sort_decoder->Get_Target_Data_From_MMSI(MMSI2);
308 if (pAISTarget1 && pAISTarget2)
309 return ItemCompare(pAISTarget1.get(), pAISTarget2.get());
316AISTargetListDialog::AISTargetListDialog(wxWindow *parent, wxAuiManager *auimgr,
318 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(-1, -1 ),
321 m_pAuiManager = auimgr;
322 m_pdecoder = pdecoder;
323 g_bsort_once =
false;
324 m_bautosort_force =
false;
329 s_p_sort_decoder = pdecoder;
330 m_pMMSI_array =
new ArrayOfMMSI(ArrayItemCompareMMSI);
335 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
341 wxAuiPaneInfo paneproto = wxAuiPaneInfo()
342 .Name(_T(
"AISTargetList"))
343 .CaptionVisible(
true)
345 .FloatingPosition(50, 50)
346 .FloatingSize(400, 200)
347 .BestSize(700, GetCharHeight() * 10);
351 paneproto.Caption(wxGetTranslation(_(
"AIS target list")));
352 paneproto.Name(_T(
"AISTargetList"));
353 paneproto.DestroyOnClose(
true);
354 paneproto.TopDockable(
false)
355 .BottomDockable(
true)
357 .RightDockable(
false);
358 paneproto.Show(
true);
360 m_pAuiManager->AddPane(
this, paneproto);
362 wxAuiPaneInfo &pane = m_pAuiManager->GetPane(_T(
"AISTargetList"));
364 if (g_AisTargetList_perspective.IsEmpty()) {
365 if (!g_btouch) RecalculateSize();
367 m_pAuiManager->LoadPaneInfo(g_AisTargetList_perspective, pane);
368 m_pAuiManager->Update();
372 m_pAuiManager->GetPane(_T(
"AISTargetList"));
377 pane.Dockable(
false);
379 wxSize screen_size = gFrame->GetClientSize();
380 pane.FloatingSize(screen_size.x * 8 / 10, screen_size.y * 8 / 10);
381 pane.FloatingPosition(screen_size.x * 1 / 10, screen_size.y * 1 / 10);
382 m_pAuiManager->Update();
385 bool b_reset_pos =
false;
386 if ((pane.floating_size.x != -1) && (pane.floating_size.y != -1)) {
391 RECT frame_title_rect;
392 frame_title_rect.left = pane.floating_pos.x;
393 frame_title_rect.top = pane.floating_pos.y;
394 frame_title_rect.right = pane.floating_pos.x + pane.floating_size.x;
395 frame_title_rect.bottom = pane.floating_pos.y + 30;
397 if (NULL == MonitorFromRect(&frame_title_rect, MONITOR_DEFAULTTONULL))
403 wxRect window_title_rect;
404 window_title_rect.x = pane.floating_pos.x;
405 window_title_rect.y = pane.floating_pos.y;
406 window_title_rect.width = pane.floating_size.x;
407 window_title_rect.height = 30;
409 wxRect ClientRect = wxGetClientDisplayRect();
412 if (!ClientRect.Intersects(window_title_rect)) b_reset_pos =
true;
417 pane.FloatingPosition(50, 50);
418 m_pAuiManager->Update();
424 if (pane.IsDocked() && (pane.dock_row == 0)) {
428 m_pAuiManager->Update();
432 m_pAuiManager->Update();
434 g_AisTargetList_perspective = m_pAuiManager->SavePaneInfo(pane);
435 pConfig->UpdateSettings();
437 m_pAuiManager->Connect(
438 wxEVT_AUI_PANE_CLOSE,
439 wxAuiManagerEventHandler(AISTargetListDialog::OnPaneClose), NULL,
this);
446 esize.y = GetCharHeight() * 10;
451 Connect(wxEVT_CONTEXT_MENU,
452 wxCommandEventHandler(AISTargetListDialog::OnRightClickContext), NULL,
456AISTargetListDialog::~AISTargetListDialog() {
457 Disconnect_decoder();
458 g_pAISTargetList = NULL;
461void AISTargetListDialog::RecalculateSize() {
465 esize.x = GetCharWidth() * 110;
466 esize.y = GetCharHeight() * 40;
468 wxSize dsize = gFrame->GetClientSize();
469 esize.y = wxMin(esize.y, dsize.y - (4 * GetCharHeight()));
470 esize.x = wxMin(esize.x, dsize.x - (2 * GetCharHeight()));
471 SetClientSize(esize);
473 wxSize fsize = GetSize();
474 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
475 fsize.x = wxMin(fsize.x, dsize.x - (2 * GetCharHeight()));
479 wxAuiPaneInfo &pane = m_pAuiManager->GetPane(_T(
"AISTargetList"));
482 pane.FloatingSize(fsize.x, fsize.y);
483 wxPoint pos = gFrame->GetScreenPosition();
484 pane.FloatingPosition(pos.x + (dsize.x - fsize.x) / 2,
485 pos.y + (dsize.y - fsize.y) / 2);
488 m_pAuiManager->Update();
492void AISTargetListDialog::CreateControls() {
493 wxBoxSizer *topSizer =
new wxBoxSizer(wxHORIZONTAL);
496 this->GetHandle()->setStyleSheet(getQtStyleSheet());
500 wxStringTokenizer tkz(g_AisTargetList_column_spec, _T(
";"));
501 wxString s_width = tkz.GetNextToken();
505 long flags = wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_HRULES | wxLC_VRULES |
508 flags |= wxLC_VIRTUAL;
512 this, ID_AIS_TARGET_LIST, wxDefaultPosition, wxDefaultSize, flags);
514 wxImageList *imglist =
new wxImageList(16, 16,
true, 2);
517 imglist->Add(style->GetIcon(_T(
"sort_asc")));
518 imglist->Add(style->GetIcon(_T(
"sort_desc")));
520 m_pListCtrlAISTargets->AssignImageList(imglist, wxIMAGE_LIST_SMALL);
521 m_pListCtrlAISTargets->Connect(
522 wxEVT_COMMAND_LIST_ITEM_SELECTED,
523 wxListEventHandler(AISTargetListDialog::OnTargetSelected), NULL,
this);
524 m_pListCtrlAISTargets->Connect(
525 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
526 wxListEventHandler(AISTargetListDialog::OnTargetSelected), NULL,
this);
527 m_pListCtrlAISTargets->Connect(
528 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
529 wxListEventHandler(AISTargetListDialog::OnTargetDefaultAction), NULL,
531 m_pListCtrlAISTargets->Connect(
532 wxEVT_COMMAND_LIST_COL_CLICK,
533 wxListEventHandler(AISTargetListDialog::OnTargetListColumnClicked), NULL,
536 int dx = GetCharWidth();
539 if (s_width.ToLong(&lwidth)) {
540 width = wxMax(dx * 2, lwidth);
541 width = wxMin(width, dx * 30);
543 m_pListCtrlAISTargets->InsertColumn(tlTRK, _(
"Trk"), wxLIST_FORMAT_LEFT,
545 s_width = tkz.GetNextToken();
548 if (s_width.ToLong(&lwidth)) {
549 width = wxMax(dx * 2, lwidth);
550 width = wxMin(width, dx * 30);
552 m_pListCtrlAISTargets->InsertColumn(tlNAME, _(
"Name"), wxLIST_FORMAT_LEFT,
554 s_width = tkz.GetNextToken();
557 if (s_width.ToLong(&lwidth)) {
558 width = wxMax(dx * 2, lwidth);
559 width = wxMin(width, dx * 30);
561 m_pListCtrlAISTargets->InsertColumn(tlCALL, _(
"Call"), wxLIST_FORMAT_LEFT,
563 s_width = tkz.GetNextToken();
566 if (s_width.ToLong(&lwidth)) {
567 width = wxMax(dx * 2, lwidth);
568 width = wxMin(width, dx * 30);
570 m_pListCtrlAISTargets->InsertColumn(tlMMSI, _(
"MMSI"), wxLIST_FORMAT_LEFT,
572 s_width = tkz.GetNextToken();
575 if (s_width.ToLong(&lwidth)) {
576 width = wxMax(dx * 2, lwidth);
577 width = wxMin(width, dx * 30);
579 m_pListCtrlAISTargets->InsertColumn(tlCLASS, _(
"Class"), wxLIST_FORMAT_CENTER,
581 s_width = tkz.GetNextToken();
584 if (s_width.ToLong(&lwidth)) {
585 width = wxMax(dx * 2, lwidth);
586 width = wxMin(width, dx * 30);
588 m_pListCtrlAISTargets->InsertColumn(tlTYPE, _(
"Type"), wxLIST_FORMAT_LEFT,
590 s_width = tkz.GetNextToken();
593 if (s_width.ToLong(&lwidth)) {
594 width = wxMax(dx * 2, lwidth);
595 width = wxMin(width, dx * 30);
597 m_pListCtrlAISTargets->InsertColumn(tlNAVSTATUS, _(
"Nav Status"),
598 wxLIST_FORMAT_LEFT, width);
599 s_width = tkz.GetNextToken();
602 if (s_width.ToLong(&lwidth)) {
603 width = wxMax(dx * 2, lwidth);
604 width = wxMin(width, dx * 30);
606 m_pListCtrlAISTargets->InsertColumn(tlBRG, _(
"Brg"), wxLIST_FORMAT_RIGHT,
608 s_width = tkz.GetNextToken();
611 if (s_width.ToLong(&lwidth)) {
612 width = wxMax(dx * 2, lwidth);
613 width = wxMin(width, dx * 30);
615 m_pListCtrlAISTargets->InsertColumn(tlRNG, _(
"Range"), wxLIST_FORMAT_RIGHT,
617 s_width = tkz.GetNextToken();
620 if (s_width.ToLong(&lwidth)) {
621 width = wxMax(dx * 2, lwidth);
622 width = wxMin(width, dx * 30);
624 m_pListCtrlAISTargets->InsertColumn(tlCOG, _(
"CoG"), wxLIST_FORMAT_RIGHT,
626 s_width = tkz.GetNextToken();
629 if (s_width.ToLong(&lwidth)) {
630 width = wxMax(dx * 2, lwidth);
631 width = wxMin(width, dx * 30);
633 m_pListCtrlAISTargets->InsertColumn(tlSOG, _(
"SoG"), wxLIST_FORMAT_RIGHT,
637 if (s_width.ToLong(&lwidth)) {
638 width = wxMax(dx * 2, lwidth);
639 width = wxMin(width, dx * 30);
641 m_pListCtrlAISTargets->InsertColumn(tlCPA, _(
"CPA"), wxLIST_FORMAT_RIGHT,
645 if (s_width.ToLong(&lwidth)) {
646 width = wxMax(dx * 2, lwidth);
647 width = wxMin(width, dx * 30);
649 m_pListCtrlAISTargets->InsertColumn(tlTCPA, _(
"TCPA"), wxLIST_FORMAT_RIGHT,
652 item.SetMask(wxLIST_MASK_IMAGE);
653 item.SetImage(g_bAisTargetList_sortReverse ? 1 : 0);
654 g_AisTargetList_sortColumn = wxMax(g_AisTargetList_sortColumn, 0);
655 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
657#ifdef wxHAS_LISTCTRL_COLUMN_ORDER
658 wxStringTokenizer tkz_order(g_AisTargetList_column_order, _T(
";"));
659 wxString s_order = tkz_order.GetNextToken();
660 int i_columns = m_pListCtrlAISTargets->GetColumnCount();
661 wxArrayInt a_order(i_columns);
662 for (
int i = 0; i < i_columns; i++) {
663 long l_order = (long)i;
664 s_order.ToLong(&l_order);
665 if (l_order < 0 || l_order > i_columns) {
668 a_order[i] = l_order;
669 s_order = tkz_order.GetNextToken();
672 m_pListCtrlAISTargets->SetColumnsOrder(a_order);
675 topSizer->Add(m_pListCtrlAISTargets, 1, wxEXPAND | wxALL, 0);
677 wxBoxSizer *boxSizer02 =
new wxBoxSizer(wxVERTICAL);
678 boxSizer02->AddSpacer(22);
679 topSizer->Add(boxSizer02, 0, wxEXPAND | wxALL, 2);
681 wxScrolledWindow *winr =
682 new wxScrolledWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
683 wxNO_BORDER | wxTAB_TRAVERSAL | wxVSCROLL);
684 winr->SetScrollRate(0, 5);
686 boxSizer02->Add(winr, 1, wxALL | wxEXPAND, 3);
688 wxBoxSizer *bsRouteButtonsInner =
new wxBoxSizer(wxVERTICAL);
689 winr->SetSizer(bsRouteButtonsInner);
691 m_pButtonInfo =
new wxButton(winr, wxID_ANY, _(
"Target info"),
692 wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW);
693 m_pButtonInfo->Connect(
694 wxEVT_COMMAND_BUTTON_CLICKED,
695 wxCommandEventHandler(AISTargetListDialog::OnTargetQuery), NULL,
this);
696 bsRouteButtonsInner->Add(m_pButtonInfo, 0, wxEXPAND | wxALL, 2);
697 bsRouteButtonsInner->AddSpacer(5);
700 new wxButton(winr, wxID_ANY, _(
"Center view"), wxDefaultPosition,
701 wxDefaultSize, wxBU_AUTODRAW);
702 m_pButtonJumpTo->Connect(
703 wxEVT_COMMAND_BUTTON_CLICKED,
704 wxCommandEventHandler(AISTargetListDialog::OnTargetScrollTo), NULL,
this);
705 bsRouteButtonsInner->Add(m_pButtonJumpTo, 0, wxEXPAND | wxALL, 2);
707 m_pButtonJumpTo_Close =
708 new wxButton(winr, wxID_ANY, _(
"Center-Info-Close"), wxDefaultPosition,
709 wxDefaultSize, wxBU_AUTODRAW);
710 m_pButtonJumpTo_Close->Connect(
711 wxEVT_COMMAND_BUTTON_CLICKED,
712 wxCommandEventHandler(AISTargetListDialog::OnTargetScrollToClose), NULL,
714 bsRouteButtonsInner->Add(m_pButtonJumpTo_Close, 0, wxEXPAND | wxALL, 2);
717 new wxButton(winr, wxID_ANY, _(
"Create WPT"), wxDefaultPosition,
718 wxDefaultSize, wxBU_AUTODRAW);
719 m_pButtonCreateWpt->Connect(
720 wxEVT_COMMAND_BUTTON_CLICKED,
721 wxCommandEventHandler(AISTargetListDialog::OnTargetCreateWpt), NULL,
723 bsRouteButtonsInner->Add(m_pButtonCreateWpt, 0, wxEXPAND | wxALL, 0);
725 m_pButtonHideAllTracks =
726 new wxButton(winr, wxID_ANY, _(
"Hide All Tracks"), wxDefaultPosition,
727 wxDefaultSize, wxBU_AUTODRAW);
728 m_pButtonHideAllTracks->Connect(
729 wxEVT_COMMAND_BUTTON_CLICKED,
730 wxCommandEventHandler(AISTargetListDialog::OnHideAllTracks), NULL,
this);
731 bsRouteButtonsInner->Add(m_pButtonHideAllTracks, 0, wxEXPAND | wxALL, 2);
733 m_pButtonShowAllTracks =
734 new wxButton(winr, wxID_ANY, _(
"Show All Tracks"), wxDefaultPosition,
735 wxDefaultSize, wxBU_AUTODRAW);
736 m_pButtonShowAllTracks->Connect(
737 wxEVT_COMMAND_BUTTON_CLICKED,
738 wxCommandEventHandler(AISTargetListDialog::OnShowAllTracks), NULL,
this);
739 bsRouteButtonsInner->Add(m_pButtonShowAllTracks, 0, wxEXPAND | wxALL, 2);
741 m_pButtonToggleTrack =
742 new wxButton(winr, wxID_ANY, _(
"Toggle track"), wxDefaultPosition,
743 wxDefaultSize, wxBU_AUTODRAW);
744 m_pButtonToggleTrack->Connect(
745 wxEVT_COMMAND_BUTTON_CLICKED,
746 wxCommandEventHandler(AISTargetListDialog::OnToggleTrack), NULL,
this);
747 bsRouteButtonsInner->Add(m_pButtonToggleTrack, 0, wxEXPAND | wxALL, 2);
750 new wxButton(winr, wxID_ANY, _(
"Copy MMSI"), wxDefaultPosition,
751 wxDefaultSize, wxBU_AUTODRAW);
752 m_pButtonCopyMMSI->Connect(
753 wxEVT_COMMAND_BUTTON_CLICKED,
754 wxCommandEventHandler(AISTargetListDialog::OnCopyMMSI), NULL,
this);
755 bsRouteButtonsInner->Add(m_pButtonCopyMMSI, 0, wxEXPAND | wxALL, 2);
758 new wxCheckBox(winr, wxID_ANY, _(
"AutoSort"), wxDefaultPosition,
759 wxDefaultSize, wxBU_AUTODRAW);
760 m_pCBAutosort->Connect(
761 wxEVT_COMMAND_CHECKBOX_CLICKED,
762 wxCommandEventHandler(AISTargetListDialog::OnAutosortCB), NULL,
this);
763 bsRouteButtonsInner->Add(m_pCBAutosort, 0, wxEXPAND | wxALL, 2);
764 g_bAisTargetList_autosort =
true;
765 m_pCBAutosort->SetValue(g_bAisTargetList_autosort);
767 bsRouteButtonsInner->AddSpacer(10);
769 m_pStaticTextRange =
new wxStaticText(winr, wxID_ANY, _(
"Limit range: NM"),
770 wxDefaultPosition, wxDefaultSize, 0);
771 bsRouteButtonsInner->Add(m_pStaticTextRange, 0, wxALL, 2);
772 bsRouteButtonsInner->AddSpacer(2);
773 m_pSpinCtrlRange =
new wxSpinCtrl(
774 winr, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(50, -1),
775 wxSP_ARROW_KEYS, 1, 20000, g_AisTargetList_range);
776 m_pSpinCtrlRange->Connect(
777 wxEVT_COMMAND_SPINCTRL_UPDATED,
778 wxCommandEventHandler(AISTargetListDialog::OnLimitRange), NULL,
this);
779 m_pSpinCtrlRange->Connect(
780 wxEVT_COMMAND_TEXT_UPDATED,
781 wxCommandEventHandler(AISTargetListDialog::OnLimitRange), NULL,
this);
782 bsRouteButtonsInner->Add(m_pSpinCtrlRange, 0, wxEXPAND | wxALL, 0);
784 bsRouteButtonsInner->AddSpacer(10);
785 m_pStaticTextCount =
new wxStaticText(winr, wxID_ANY, _(
"Target Count"),
786 wxDefaultPosition, wxDefaultSize, 0);
787 bsRouteButtonsInner->Add(m_pStaticTextCount, 0, wxALL, 2);
789 bsRouteButtonsInner->AddSpacer(2);
790 m_pTextTargetCount =
new wxTextCtrl(winr, wxID_ANY, _T(
""), wxDefaultPosition,
791 wxDefaultSize, wxTE_READONLY);
792 m_pTextTargetCount->SetMinSize(wxSize(6 * GetCharWidth(), -1));
793 bsRouteButtonsInner->Add(m_pTextTargetCount, 0, wxALL, 2);
795 bsRouteButtonsInner->AddSpacer(10);
796 m_pButtonOK =
new wxButton(winr, wxID_ANY, _(
"Close"), wxDefaultPosition,
797 wxDefaultSize, wxBU_AUTODRAW);
798 m_pButtonOK->Connect(
799 wxEVT_COMMAND_BUTTON_CLICKED,
800 wxCommandEventHandler(AISTargetListDialog::OnCloseButton), NULL,
this);
801 bsRouteButtonsInner->Add(m_pButtonOK, 0, wxEXPAND | wxALL, 0);
808 SetSize(GetSize().x, GetSize().y - 1);
811void AISTargetListDialog::OnClose(wxCloseEvent &event) {
812 Disconnect_decoder();
814 g_pAISTargetList = NULL;
817void AISTargetListDialog::Disconnect_decoder() { m_pdecoder = NULL; }
819void AISTargetListDialog::SetColorScheme() { DimeControl(
this); }
821void AISTargetListDialog::OnPaneClose(wxAuiManagerEvent &event) {
822 if (event.pane->name == _T(
"AISTargetList")) {
823 g_AisTargetList_perspective = m_pAuiManager->SavePaneInfo(*event.pane);
828void AISTargetListDialog::OnCloseButton(wxCommandEvent &event) { Shutdown(); }
830void AISTargetListDialog::Shutdown(
void) {
832 wxAuiPaneInfo pane = m_pAuiManager->GetPane(
this);
833 g_AisTargetList_perspective = m_pAuiManager->SavePaneInfo(pane);
834 m_pAuiManager->DetachPane(
this);
835 Disconnect_decoder();
837 m_pAuiManager->Update();
839 GetParent()->Refresh(
true);
845void AISTargetListDialog::UpdateButtons() {
847 item = m_pListCtrlAISTargets->GetNextItem(item, wxLIST_NEXT_ALL,
848 wxLIST_STATE_SELECTED);
849 bool enable = (item != -1);
851 m_pButtonInfo->Enable(enable);
853 if (m_pdecoder && item != -1) {
855 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(item));
856 if (pAISTargetSel && (!pAISTargetSel->b_positionOnceValid)) enable =
false;
858 m_pButtonJumpTo->Enable(enable);
859 m_pButtonJumpTo_Close->Enable(enable);
860 m_pButtonCreateWpt->Enable(enable);
861 m_pButtonToggleTrack->Enable(enable);
862 m_pButtonCopyMMSI->Enable(enable);
865void AISTargetListDialog::OnTargetSelected(wxListEvent &event) {
869void AISTargetListDialog::DoTargetQuery(
int mmsi) {
870 ShowAISTargetQueryDialog(m_pparent, mmsi);
877void AISTargetListDialog::OnTargetDefaultAction(wxListEvent &event) {
879 if ((mmsi_no = event.GetData())) DoTargetQuery(mmsi_no);
882void AISTargetListDialog::OnTargetQuery(wxCommandEvent &event) {
884 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
885 wxLIST_STATE_SELECTED);
886 if (selItemID == -1)
return;
890 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
891 if (pAISTarget) DoTargetQuery(pAISTarget->MMSI);
895void AISTargetListDialog::OnAutosortCB(wxCommandEvent &event) {
896 g_bAisTargetList_autosort = m_pCBAutosort->GetValue();
898 m_bautosort_force = g_bAisTargetList_autosort;
900 if (!g_bAisTargetList_autosort) {
902 item.SetMask(wxLIST_MASK_IMAGE);
904 g_AisTargetList_sortColumn = wxMax(g_AisTargetList_sortColumn, 0);
905 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
908 item.SetMask(wxLIST_MASK_IMAGE);
909 item.SetImage(g_bAisTargetList_sortReverse ? 1 : 0);
911 if (g_AisTargetList_sortColumn >= 0) {
912 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
913 UpdateAISTargetList();
918void AISTargetListDialog::OnTargetListColumnClicked(wxListEvent &event) {
919 int key =
event.GetColumn();
921 item.SetMask(wxLIST_MASK_IMAGE);
922 if (key == g_AisTargetList_sortColumn)
923 g_bAisTargetList_sortReverse = !g_bAisTargetList_sortReverse;
926 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
927 g_bAisTargetList_sortReverse =
false;
928 g_AisTargetList_sortColumn = key;
930 item.SetImage(g_bAisTargetList_sortReverse ? 1 : 0);
932 if (!g_bAisTargetList_autosort) g_bsort_once =
true;
934 if (g_AisTargetList_sortColumn >= 0) {
935 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
936 UpdateAISTargetList();
940void AISTargetListDialog::OnTargetScrollTo(wxCommandEvent &event) {
941 CenterToTarget(
false);
944void AISTargetListDialog::OnTargetScrollToClose(wxCommandEvent &event) {
945 CenterToTarget(
true);
948void AISTargetListDialog::OnTargetCreateWpt(wxCommandEvent &event) {
950 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
951 wxLIST_STATE_SELECTED);
952 if (selItemID == -1)
return;
954 std::shared_ptr<AisTargetData> pAISTarget = NULL;
957 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
961 new RoutePoint(pAISTarget->Lat, pAISTarget->Lon, g_default_wp_icon,
962 wxEmptyString, wxEmptyString);
963 pWP->m_bIsolatedMark =
true;
964 pSelect->AddSelectableRoutePoint(pAISTarget->Lat, pAISTarget->Lon, pWP);
965 pConfig->AddNewWayPoint(pWP, -1);
967 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
968 pRouteManagerDialog->UpdateWptListCtrl();
969 gFrame->GetPrimaryCanvas()->undo->BeforeUndoableAction(
970 Undo_CreateWaypoint, pWP, Undo_HasParent, NULL);
971 gFrame->GetPrimaryCanvas()->undo->AfterUndoableAction(NULL);
976void AISTargetListDialog::OnShowAllTracks(wxCommandEvent &event) {
978 for (
const auto &it : m_pdecoder->GetTargetList()) {
979 auto pAISTarget = it.second;
980 if (NULL != pAISTarget) {
981 pAISTarget->b_show_track =
true;
984 UpdateAISTargetList();
988void AISTargetListDialog::OnHideAllTracks(wxCommandEvent &event) {
990 for (
const auto &it : m_pdecoder->GetTargetList()) {
991 auto pAISTarget = it.second;
992 if (NULL != pAISTarget) {
993 pAISTarget->b_show_track =
false;
996 std::map<int, Track *>::iterator it;
997 it = g_pAIS->m_persistent_tracks.find(pAISTarget->MMSI);
998 if (it != g_pAIS->m_persistent_tracks.end())
999 pAISTarget->b_show_track =
true;
1002 UpdateAISTargetList();
1006void AISTargetListDialog::OnToggleTrack(wxCommandEvent &event) {
1007 long selItemID = -1;
1008 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1009 wxLIST_STATE_SELECTED);
1010 if (selItemID == -1)
return;
1012 std::shared_ptr<AisTargetData> pAISTarget = NULL;
1015 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
1018 pAISTarget->b_show_track = !pAISTarget->b_show_track;
1019 UpdateAISTargetList();
1023void AISTargetListDialog::OnCopyMMSI(wxCommandEvent &event) {
1024 long selItemID = -1;
1025 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1026 wxLIST_STATE_SELECTED);
1027 if (selItemID == -1)
return;
1028 CopyMMSItoClipBoard((
int)m_pMMSI_array->Item(selItemID));
1031void AISTargetListDialog::CenterToTarget(
bool close) {
1032 long selItemID = -1;
1033 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1034 wxLIST_STATE_SELECTED);
1035 if (selItemID == -1)
return;
1037 std::shared_ptr<AisTargetData> pAISTarget = NULL;
1040 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
1043 double scale = gFrame->GetFocusCanvas()->GetVPScale();
1044 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), pAISTarget->Lat,
1045 pAISTarget->Lon,
scale);
1050 double factor = cc->GetScaleValue() / 5000.0;
1053 DoTargetQuery(pAISTarget->MMSI);
1060void AISTargetListDialog::CopyMMSItoClipBoard(
int mmsi) {
1062 if (wxTheClipboard->Open()) {
1063 wxTheClipboard->SetData(
1064 new wxTextDataObject(wxString::Format(wxT(
"%09d"), mmsi)));
1065 wxTheClipboard->Close();
1068void AISTargetListDialog::OnLimitRange(wxCommandEvent &event) {
1069 g_AisTargetList_range = m_pSpinCtrlRange->GetValue();
1070 UpdateAISTargetList();
1073std::shared_ptr<AisTargetData> AISTargetListDialog::GetpTarget(
1074 unsigned int list_item) {
1076 return m_pdecoder->Get_Target_Data_From_MMSI(
1077 m_pMMSI_array->Item(list_item));
1082void AISTargetListDialog::UpdateAISTargetList(
void) {
1083 if (m_pListCtrlAISTargets && !m_pListCtrlAISTargets->IsVirtual())
1084 return UpdateNVAISTargetList();
1086 if (m_pdecoder && m_pListCtrlAISTargets) {
1088 long selItemID = -1;
1089 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1090 wxLIST_STATE_SELECTED);
1093 if (selItemID != -1) selMMSI = m_pMMSI_array->Item(selItemID);
1095 const auto ¤t_targets = m_pdecoder->GetTargetList();
1099 m_pMMSI_array->Clear();
1101 for (
auto it = current_targets.begin(); it != current_targets.end();
1103 auto pAISTarget = it->second;
1106 if (NULL != pAISTarget) {
1108 if ((pAISTarget->b_positionOnceValid) &&
1109 (pAISTarget->Range_NM <= g_AisTargetList_range))
1111 else if (!pAISTarget->b_positionOnceValid)
1115 if (pAISTarget->b_lost) b_add =
false;
1118 m_pMMSI_array->Add(pAISTarget->MMSI);
1123 g_bsort_once =
false;
1125 m_pListCtrlAISTargets->SetItemCount(m_pMMSI_array->GetCount());
1127 g_AisTargetList_count = m_pMMSI_array->GetCount();
1129 if ((g_AisTargetList_count > 1000) && !m_bautosort_force)
1130 g_bAisTargetList_autosort =
false;
1132 m_pCBAutosort->SetValue(g_bAisTargetList_autosort);
1136 if ((selItemID != -1) && (selMMSI != -1)) {
1137 for (
unsigned int i = 0; i < m_pMMSI_array->GetCount(); i++) {
1138 if (m_pMMSI_array->Item(i) == selMMSI) {
1145 if (m_pMMSI_array->GetCount())
1146 m_pListCtrlAISTargets->SetItemState(
1147 item_sel, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
1148 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1150 m_pListCtrlAISTargets->DeleteAllItems();
1153 count.Printf(_T(
"%lu"), (
unsigned long)m_pMMSI_array->GetCount());
1154 m_pTextTargetCount->ChangeValue(count);
1157 m_pListCtrlAISTargets->Refresh(
false);
1162void AISTargetListDialog::UpdateNVAISTargetList(
void) {
1165 long selItemID = -1;
1166 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1167 wxLIST_STATE_SELECTED);
1170 if (selItemID != -1) selMMSI = m_pMMSI_array->Item(selItemID);
1172 const auto ¤t_targets = m_pdecoder->GetTargetList();
1176 m_pMMSI_array->Clear();
1178 for (
auto it = current_targets.begin(); it != current_targets.end();
1180 auto pAISTarget = it->second;
1183 if (NULL != pAISTarget) {
1185 if ((pAISTarget->b_positionOnceValid) &&
1186 (pAISTarget->Range_NM <= g_AisTargetList_range))
1188 else if (!pAISTarget->b_positionOnceValid)
1192 m_pMMSI_array->Add(pAISTarget->MMSI);
1197 g_bsort_once =
false;
1199 g_AisTargetList_count = m_pMMSI_array->GetCount();
1201 m_pListCtrlAISTargets->DeleteAllItems();
1203 for (
int i = 0; i < g_AisTargetList_count; i++) {
1206 m_pListCtrlAISTargets->InsertItem(item);
1207 for (
int j = 0; j < tlTCPA + 1; j++) {
1209 item.SetText(m_pListCtrlAISTargets->OnGetItemText(i, j));
1210 m_pListCtrlAISTargets->SetItem(item);
1214 if ((g_AisTargetList_count > 1000) && !m_bautosort_force)
1215 g_bAisTargetList_autosort =
false;
1217 m_pCBAutosort->SetValue(g_bAisTargetList_autosort);
1221 if ((selItemID != -1) && (selMMSI != -1)) {
1222 for (
unsigned int i = 0; i < m_pMMSI_array->GetCount(); i++) {
1223 if (m_pMMSI_array->Item(i) == selMMSI) {
1230 if (m_pMMSI_array->GetCount())
1231 m_pListCtrlAISTargets->SetItemState(
1232 item_sel, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
1233 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1235 m_pListCtrlAISTargets->DeleteAllItems();
1238 count.Printf(_T(
"%lu"), (
unsigned long)m_pMMSI_array->GetCount());
1239 m_pTextTargetCount->ChangeValue(count);
1242 m_pListCtrlAISTargets->Refresh(
false);
1247void AISTargetListDialog::OnRightClickContext(wxCommandEvent &event) {
1248 wxAuiPaneInfo &pane = m_pAuiManager->GetPane(_T(
"AISTargetList"));
1249 if (pane.IsDocked()) {
1250 wxMenu *popup =
new wxMenu();
1251 popup->Append(ID_RCLK_UNDOCK, _(
"Undock Target List"));
1252 popup->Connect(wxEVT_COMMAND_MENU_SELECTED,
1253 wxCommandEventHandler(AISTargetListDialog::OnContextUndock),
1261void AISTargetListDialog::OnContextUndock(wxCommandEvent &event) {
1262 wxAuiPaneInfo &pane = m_pAuiManager->GetPane(_T(
"AISTargetList"));
1264 m_pAuiManager->Update();
Global state for AIS decoder.
Dialog for displaying a list of AIS targets.
void DoZoomCanvas(double factor, bool can_zoom_to_cursor=true)
Internal function that implements the actual zoom operation.
A custom list control for displaying AIS target information.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.