25#include <wx/textctrl.h>
27#include <wx/tokenzr.h>
28#include <wx/clipbrd.h>
31#include "androidUTIL.h"
54extern wxString g_default_wp_icon;
59static int g_AisTargetList_count;
61static bool g_bAisTargetList_autosort;
66EVT_CLOSE(AISTargetListDialog::OnClose)
69static
bool g_bsort_once;
75 bool b_cmptype_num =
false;
78 if (!g_bAisTargetList_autosort && !g_bsort_once)
return 0;
83 if (t1->Class == AIS_SART) {
84 if (t2->Class == AIS_DSC)
90 if (t2->Class == AIS_SART) {
91 if (t1->Class == AIS_DSC)
97 switch (g_AisTargetList_sortColumn) {
99 n1 = t1->b_show_track;
100 n2 = t2->b_show_track;
101 b_cmptype_num =
true;
105 s1 = trimAISField(t1->ShipName);
106 if ((!t1->b_nameValid && (t1->Class == AIS_BASE)) ||
107 (t1->Class == AIS_SART))
110 s2 = trimAISField(t2->ShipName);
111 if ((!t2->b_nameValid && (t2->Class == AIS_BASE)) ||
112 (t2->Class == AIS_SART))
117 s1 = trimAISField(t1->CallSign);
118 s2 = trimAISField(t2->CallSign);
124 b_cmptype_num =
true;
128 s1 = t1->Get_class_string(
true);
129 s2 = t2->Get_class_string(
true);
133 s1 = t1->Get_vessel_type_string(
false);
134 if ((t1->Class == AIS_BASE) ||
135 (t1->Class == AIS_SART || (t1->Class == AIS_METEO)))
138 s2 = t2->Get_vessel_type_string(
false);
139 if ((t1->Class == AIS_BASE) || (t1->Class == AIS_SART) ||
140 (t1->Class == AIS_METEO))
145 s1 = t1->GetCountryCode(
true);
146 s2 = t2->GetCountryCode(
true);
149 if ((t1->NavStatus <= 15) && (t1->NavStatus >= 0)) {
150 if (t1->Class == AIS_SART) {
151 if (t1->NavStatus == RESERVED_14)
153 else if (t1->NavStatus == UNDEFINED)
156 s1 = ais_get_status(t1->NavStatus);
160 if ((t1->Class == AIS_ATON) || (t1->Class == AIS_BASE) ||
161 (t1->Class == AIS_CLASS_B) || (t1->Class == AIS_METEO))
164 if ((t2->NavStatus <= 15) && (t2->NavStatus >= 0)) {
165 if (t2->Class == AIS_SART) {
166 if (t2->NavStatus == RESERVED_14)
168 else if (t2->NavStatus == UNDEFINED)
171 s2 = ais_get_status(t2->NavStatus);
175 if ((t2->Class == AIS_ATON) || (t2->Class == AIS_BASE) ||
176 (t2->Class == AIS_CLASS_B) || (t2->Class == AIS_METEO))
183 int brg1 = wxRound(t1->Brg);
189 int brg2 = wxRound(t2->Brg);
195 b_cmptype_num =
true;
200 if ((t1->COG >= 360.0) || (t1->Class == AIS_ATON) ||
201 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
204 int crs = wxRound(t1->COG);
211 if ((t2->COG >= 360.0) || (t2->Class == AIS_ATON) ||
212 (t2->Class == AIS_BASE) || (t2->Class == AIS_METEO))
215 int crs = wxRound(t2->COG);
222 b_cmptype_num =
true;
227 if ((t1->SOG > 100.) || (t1->Class == AIS_ATON) ||
228 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
233 if ((t2->SOG > 100.) || (t2->Class == AIS_ATON) ||
234 (t2->Class == AIS_BASE) || (t2->Class == AIS_METEO))
239 b_cmptype_num =
true;
243 if ((!t1->bCPA_Valid) || (t1->Class == AIS_ATON) ||
244 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
249 if ((!t2->bCPA_Valid) || (t2->Class == AIS_ATON) ||
250 (t2->Class == AIS_BASE))
255 b_cmptype_num =
true;
259 if ((!t1->bCPA_Valid) || (t1->Class == AIS_ATON) ||
260 (t1->Class == AIS_BASE) || (t1->Class == AIS_METEO))
265 if ((!t2->bCPA_Valid) || (t2->Class == AIS_ATON) ||
266 (t2->Class == AIS_BASE) || (t2->Class == AIS_METEO))
271 b_cmptype_num =
true;
277 b_cmptype_num =
true;
285 if (!b_cmptype_num) {
286 if (g_bAisTargetList_sortReverse)
return s2.Cmp(s1);
290 if (g_bAisTargetList_sortReverse) {
296 return (t1->Range_NM > t2->Range_NM);
303 return (t1->Range_NM > t2->Range_NM);
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);
315 if (pAISTarget1 && pAISTarget2)
316 return ItemCompare(pAISTarget1.get(), pAISTarget2.get());
323AISTargetListDialog::AISTargetListDialog(wxWindow *parent, wxAuiManager *auimgr,
325 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(-1, -1 ),
328 m_pAuiManager = auimgr;
329 m_pdecoder = pdecoder;
330 g_bsort_once =
false;
331 m_bautosort_force =
false;
336 s_p_sort_decoder = pdecoder;
337 m_pMMSI_array =
new ArrayOfMMSI(ArrayItemCompareMMSI);
342 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
348 wxAuiPaneInfo paneproto = wxAuiPaneInfo()
349 .Name(
"AISTargetList")
350 .CaptionVisible(
true)
352 .FloatingPosition(50, 50)
353 .FloatingSize(400, 200)
354 .BestSize(700, GetCharHeight() * 10);
358 paneproto.Caption(wxGetTranslation(_(
"AIS target list")));
359 paneproto.Name(
"AISTargetList");
360 paneproto.DestroyOnClose(
true);
361 paneproto.TopDockable(
false)
362 .BottomDockable(
true)
364 .RightDockable(
false);
365 paneproto.Show(
true);
367 m_pAuiManager->AddPane(
this, paneproto);
369 wxAuiPaneInfo &pane = m_pAuiManager->GetPane(
"AISTargetList");
371 if (g_AisTargetList_perspective.IsEmpty()) {
372 if (!g_btouch) RecalculateSize();
374 m_pAuiManager->LoadPaneInfo(g_AisTargetList_perspective, pane);
375 m_pAuiManager->Update();
378 pane = m_pAuiManager->GetPane(
"AISTargetList");
383 pane.Dockable(
false);
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();
391 bool b_reset_pos =
false;
392 if ((pane.floating_size.x != -1) && (pane.floating_size.y != -1)) {
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;
403 if (NULL == MonitorFromRect(&frame_title_rect, MONITOR_DEFAULTTONULL))
409 wxRect window_title_rect;
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;
415 wxRect ClientRect = wxGetClientDisplayRect();
418 if (!ClientRect.Intersects(window_title_rect)) b_reset_pos =
true;
423 pane.FloatingPosition(50, 50);
424 m_pAuiManager->Update();
430 if (pane.IsDocked() && (pane.dock_row == 0)) {
434 m_pAuiManager->Update();
438 m_pAuiManager->Update();
440 g_AisTargetList_perspective = m_pAuiManager->SavePaneInfo(pane);
441 pConfig->UpdateSettings();
443 m_pAuiManager->Connect(
444 wxEVT_AUI_PANE_CLOSE,
445 wxAuiManagerEventHandler(AISTargetListDialog::OnPaneClose), NULL,
this);
452 esize.y = GetCharHeight() * 10;
457 Connect(wxEVT_CONTEXT_MENU,
458 wxCommandEventHandler(AISTargetListDialog::OnRightClickContext), NULL,
462AISTargetListDialog::~AISTargetListDialog() {
463 Disconnect_decoder();
467void AISTargetListDialog::RecalculateSize() {
471 esize.x = GetCharWidth() * 110;
472 esize.y = GetCharHeight() * 40;
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);
479 wxSize fsize = GetSize();
480 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
481 fsize.x = wxMin(fsize.x, dsize.x - (2 * GetCharHeight()));
485 wxAuiPaneInfo &pane = m_pAuiManager->GetPane(
"AISTargetList");
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);
494 m_pAuiManager->Update();
498void AISTargetListDialog::CreateControls() {
499 wxBoxSizer *topSizer =
new wxBoxSizer(wxHORIZONTAL);
502 this->GetHandle()->setStyleSheet(getQtStyleSheet());
506 wxStringTokenizer tkz(g_AisTargetList_column_spec,
";");
507 wxString s_width = tkz.GetNextToken();
511 long flags = wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_HRULES | wxLC_VRULES |
514 flags |= wxLC_VIRTUAL;
518 this, ID_AIS_TARGET_LIST, wxDefaultPosition, wxDefaultSize, flags);
520 wxImageList *imglist =
new wxImageList(16, 16,
true, 2);
523 imglist->Add(style->GetIcon(
"sort_asc"));
524 imglist->Add(style->GetIcon(
"sort_desc"));
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,
537 m_pListCtrlAISTargets->Connect(
538 wxEVT_COMMAND_LIST_COL_CLICK,
539 wxListEventHandler(AISTargetListDialog::OnTargetListColumnClicked), NULL,
542 int dx = GetCharWidth();
545 if (s_width.ToLong(&lwidth)) {
546 width = wxMax(dx * 2, lwidth);
547 width = wxMin(width, dx * 30);
549 m_pListCtrlAISTargets->InsertColumn(tlTRK, _(
"Trk"), wxLIST_FORMAT_LEFT,
551 s_width = tkz.GetNextToken();
554 if (s_width.ToLong(&lwidth)) {
555 width = wxMax(dx * 2, lwidth);
556 width = wxMin(width, dx * 30);
558 m_pListCtrlAISTargets->InsertColumn(tlNAME, _(
"Name"), wxLIST_FORMAT_LEFT,
560 s_width = tkz.GetNextToken();
563 if (s_width.ToLong(&lwidth)) {
564 width = wxMax(dx * 2, lwidth);
565 width = wxMin(width, dx * 30);
567 m_pListCtrlAISTargets->InsertColumn(tlCALL, _(
"Call"), wxLIST_FORMAT_LEFT,
569 s_width = tkz.GetNextToken();
572 if (s_width.ToLong(&lwidth)) {
573 width = wxMax(dx * 2, lwidth);
574 width = wxMin(width, dx * 30);
576 m_pListCtrlAISTargets->InsertColumn(tlMMSI, _(
"MMSI"), wxLIST_FORMAT_LEFT,
578 s_width = tkz.GetNextToken();
581 if (s_width.ToLong(&lwidth)) {
582 width = wxMax(dx * 2, lwidth);
583 width = wxMin(width, dx * 30);
585 m_pListCtrlAISTargets->InsertColumn(tlCLASS, _(
"Class"), wxLIST_FORMAT_CENTER,
587 s_width = tkz.GetNextToken();
590 if (s_width.ToLong(&lwidth)) {
591 width = wxMax(dx * 2, lwidth);
592 width = wxMin(width, dx * 30);
594 m_pListCtrlAISTargets->InsertColumn(tlTYPE, _(
"Type"), wxLIST_FORMAT_LEFT,
596 s_width = tkz.GetNextToken();
599 if (s_width.ToLong(&lwidth)) {
600 width = wxMax(dx * 2, lwidth);
601 width = wxMin(width, dx * 30);
603 m_pListCtrlAISTargets->InsertColumn(tlNAVSTATUS, _(
"Flag"),
604 wxLIST_FORMAT_LEFT, width);
605 s_width = tkz.GetNextToken();
608 if (s_width.ToLong(&lwidth)) {
609 width = wxMax(dx * 2, lwidth);
610 width = wxMin(width, dx * 30);
612 m_pListCtrlAISTargets->InsertColumn(tlNAVSTATUS, _(
"Nav Status"),
613 wxLIST_FORMAT_LEFT, width);
614 s_width = tkz.GetNextToken();
617 if (s_width.ToLong(&lwidth)) {
618 width = wxMax(dx * 2, lwidth);
619 width = wxMin(width, dx * 30);
621 m_pListCtrlAISTargets->InsertColumn(tlBRG, _(
"Brg"), wxLIST_FORMAT_RIGHT,
623 s_width = tkz.GetNextToken();
626 if (s_width.ToLong(&lwidth)) {
627 width = wxMax(dx * 2, lwidth);
628 width = wxMin(width, dx * 30);
630 m_pListCtrlAISTargets->InsertColumn(tlRNG, _(
"Range"), wxLIST_FORMAT_RIGHT,
632 s_width = tkz.GetNextToken();
635 if (s_width.ToLong(&lwidth)) {
636 width = wxMax(dx * 2, lwidth);
637 width = wxMin(width, dx * 30);
639 m_pListCtrlAISTargets->InsertColumn(tlCOG, _(
"CoG"), wxLIST_FORMAT_RIGHT,
641 s_width = tkz.GetNextToken();
644 if (s_width.ToLong(&lwidth)) {
645 width = wxMax(dx * 2, lwidth);
646 width = wxMin(width, dx * 30);
648 m_pListCtrlAISTargets->InsertColumn(tlSOG, _(
"SoG"), wxLIST_FORMAT_RIGHT,
652 if (s_width.ToLong(&lwidth)) {
653 width = wxMax(dx * 2, lwidth);
654 width = wxMin(width, dx * 30);
656 m_pListCtrlAISTargets->InsertColumn(tlCPA, _(
"CPA"), wxLIST_FORMAT_RIGHT,
660 if (s_width.ToLong(&lwidth)) {
661 width = wxMax(dx * 2, lwidth);
662 width = wxMin(width, dx * 30);
664 m_pListCtrlAISTargets->InsertColumn(tlTCPA, _(
"TCPA"), wxLIST_FORMAT_RIGHT,
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);
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) {
683 a_order[i] = l_order;
684 s_order = tkz_order.GetNextToken();
687 m_pListCtrlAISTargets->SetColumnsOrder(a_order);
690 topSizer->Add(m_pListCtrlAISTargets, 1, wxEXPAND | wxALL, 0);
692 wxBoxSizer *boxSizer02 =
new wxBoxSizer(wxVERTICAL);
693 boxSizer02->AddSpacer(22);
694 topSizer->Add(boxSizer02, 0, wxEXPAND | wxALL, 2);
696 wxScrolledWindow *winr =
697 new wxScrolledWindow(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
698 wxNO_BORDER | wxTAB_TRAVERSAL | wxVSCROLL);
699 winr->SetScrollRate(0, 5);
701 boxSizer02->Add(winr, 1, wxALL | wxEXPAND, 3);
703 wxBoxSizer *bsRouteButtonsInner =
new wxBoxSizer(wxVERTICAL);
704 winr->SetSizer(bsRouteButtonsInner);
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);
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);
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,
729 bsRouteButtonsInner->Add(m_pButtonJumpTo_Close, 0, wxEXPAND | wxALL, 2);
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,
738 bsRouteButtonsInner->Add(m_pButtonCreateWpt, 0, wxEXPAND | wxALL, 0);
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);
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);
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);
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);
772 m_pStaticTextFind =
new wxStaticText(winr, wxID_ANY, _(
"Find target name"),
773 wxDefaultPosition, wxDefaultSize, 0);
774 bsRouteButtonsInner->Add(m_pStaticTextFind, 0, wxALL, 2);
777 new wxTextCtrl(winr, wxID_ANY,
"", wxDefaultPosition, wxDefaultSize, 0);
778 m_pFindTargetName->SetMinSize(wxSize(15 * GetCharWidth(), -1));
779 m_pFindTargetName->Connect(
780 wxEVT_COMMAND_TEXT_UPDATED,
781 wxCommandEventHandler(AISTargetListDialog::OnEditFindTarget), NULL,
this);
782 bsRouteButtonsInner->Add(m_pFindTargetName, 0, wxALL, 2);
785 new wxCheckBox(winr, wxID_ANY, _(
"AutoSort"), wxDefaultPosition,
786 wxDefaultSize, wxBU_AUTODRAW);
787 m_pCBAutosort->Connect(
788 wxEVT_COMMAND_CHECKBOX_CLICKED,
789 wxCommandEventHandler(AISTargetListDialog::OnAutosortCB), NULL,
this);
790 bsRouteButtonsInner->Add(m_pCBAutosort, 0, wxEXPAND | wxALL, 2);
791 g_bAisTargetList_autosort =
true;
792 m_pCBAutosort->SetValue(g_bAisTargetList_autosort);
794 bsRouteButtonsInner->AddSpacer(10);
796 m_pStaticTextRange =
new wxStaticText(winr, wxID_ANY, _(
"Limit range: NM"),
797 wxDefaultPosition, wxDefaultSize, 0);
798 bsRouteButtonsInner->Add(m_pStaticTextRange, 0, wxALL, 2);
799 bsRouteButtonsInner->AddSpacer(2);
800 m_pSpinCtrlRange =
new wxSpinCtrl(
801 winr, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(50, -1),
802 wxSP_ARROW_KEYS, 1, 20000, g_AisTargetList_range);
803 m_pSpinCtrlRange->Connect(
804 wxEVT_COMMAND_SPINCTRL_UPDATED,
805 wxCommandEventHandler(AISTargetListDialog::OnLimitRange), NULL,
this);
806 m_pSpinCtrlRange->Connect(
807 wxEVT_COMMAND_TEXT_UPDATED,
808 wxCommandEventHandler(AISTargetListDialog::OnLimitRange), NULL,
this);
809 bsRouteButtonsInner->Add(m_pSpinCtrlRange, 0, wxEXPAND | wxALL, 0);
811 bsRouteButtonsInner->AddSpacer(10);
812 m_pStaticTextCount =
new wxStaticText(winr, wxID_ANY, _(
"Target Count"),
813 wxDefaultPosition, wxDefaultSize, 0);
814 bsRouteButtonsInner->Add(m_pStaticTextCount, 0, wxALL, 2);
816 bsRouteButtonsInner->AddSpacer(2);
817 m_pTextTargetCount =
new wxTextCtrl(winr, wxID_ANY,
"", wxDefaultPosition,
818 wxDefaultSize, wxTE_READONLY);
819 m_pTextTargetCount->SetMinSize(wxSize(6 * GetCharWidth(), -1));
820 bsRouteButtonsInner->Add(m_pTextTargetCount, 0, wxALL, 2);
822 bsRouteButtonsInner->AddSpacer(10);
823 m_pButtonOK =
new wxButton(winr, wxID_ANY, _(
"Close"), wxDefaultPosition,
824 wxDefaultSize, wxBU_AUTODRAW);
825 m_pButtonOK->Connect(
826 wxEVT_COMMAND_BUTTON_CLICKED,
827 wxCommandEventHandler(AISTargetListDialog::OnCloseButton), NULL,
this);
828 bsRouteButtonsInner->Add(m_pButtonOK, 0, wxEXPAND | wxALL, 0);
835 SetSize(GetSize().x, GetSize().y - 1);
838void AISTargetListDialog::OnClose(wxCloseEvent &event) {
839 Disconnect_decoder();
844void AISTargetListDialog::Disconnect_decoder() { m_pdecoder = NULL; }
846void AISTargetListDialog::SetColorScheme() { DimeControl(
this); }
848void AISTargetListDialog::OnPaneClose(wxAuiManagerEvent &event) {
849 if (event.pane->name ==
"AISTargetList") {
850 g_AisTargetList_perspective = m_pAuiManager->SavePaneInfo(*event.pane);
855void AISTargetListDialog::OnCloseButton(wxCommandEvent &event) { Shutdown(); }
857void AISTargetListDialog::Shutdown() {
859 wxAuiPaneInfo pane = m_pAuiManager->GetPane(
this);
860 g_AisTargetList_perspective = m_pAuiManager->SavePaneInfo(pane);
861 m_pAuiManager->DetachPane(
this);
862 Disconnect_decoder();
864 m_pAuiManager->Update();
866 GetParent()->Refresh(
true);
872void AISTargetListDialog::UpdateButtons() {
874 item = m_pListCtrlAISTargets->GetNextItem(item, wxLIST_NEXT_ALL,
875 wxLIST_STATE_SELECTED);
876 bool enable = (item != -1);
878 m_pButtonInfo->Enable(enable);
880 if (m_pdecoder && item != -1) {
882 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(item));
883 if (pAISTargetSel && (!pAISTargetSel->b_positionOnceValid)) enable =
false;
885 m_pButtonJumpTo->Enable(enable);
886 m_pButtonJumpTo_Close->Enable(enable);
887 m_pButtonCreateWpt->Enable(enable);
888 m_pButtonToggleTrack->Enable(enable);
889 m_pButtonCopyMMSI->Enable(enable);
892void AISTargetListDialog::OnTargetSelected(wxListEvent &event) {
896void AISTargetListDialog::DoTargetQuery(
int mmsi) {
897 ShowAISTargetQueryDialog(m_pparent, mmsi);
904void AISTargetListDialog::OnTargetDefaultAction(wxListEvent &event) {
906 if ((mmsi_no = event.GetData())) DoTargetQuery(mmsi_no);
909void AISTargetListDialog::OnTargetQuery(wxCommandEvent &event) {
911 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
912 wxLIST_STATE_SELECTED);
913 if (selItemID == -1)
return;
917 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
918 if (pAISTarget) DoTargetQuery(pAISTarget->MMSI);
922void AISTargetListDialog::OnAutosortCB(wxCommandEvent &event) {
923 g_bAisTargetList_autosort = m_pCBAutosort->GetValue();
925 m_bautosort_force = g_bAisTargetList_autosort;
927 if (!g_bAisTargetList_autosort) {
929 item.SetMask(wxLIST_MASK_IMAGE);
931 g_AisTargetList_sortColumn = wxMax(g_AisTargetList_sortColumn, 0);
932 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
935 item.SetMask(wxLIST_MASK_IMAGE);
936 item.SetImage(g_bAisTargetList_sortReverse ? 1 : 0);
938 if (g_AisTargetList_sortColumn >= 0) {
939 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
940 UpdateAISTargetList();
945void AISTargetListDialog::OnTargetListColumnClicked(wxListEvent &event) {
946 int key =
event.GetColumn();
948 item.SetMask(wxLIST_MASK_IMAGE);
949 if (key == g_AisTargetList_sortColumn)
950 g_bAisTargetList_sortReverse = !g_bAisTargetList_sortReverse;
953 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
954 g_bAisTargetList_sortReverse =
false;
955 g_AisTargetList_sortColumn = key;
957 item.SetImage(g_bAisTargetList_sortReverse ? 1 : 0);
959 if (!g_bAisTargetList_autosort) g_bsort_once =
true;
961 if (g_AisTargetList_sortColumn >= 0) {
962 m_pListCtrlAISTargets->SetColumn(g_AisTargetList_sortColumn, item);
963 UpdateAISTargetList();
967void AISTargetListDialog::OnTargetScrollTo(wxCommandEvent &event) {
968 CenterToTarget(
false);
971void AISTargetListDialog::OnTargetScrollToClose(wxCommandEvent &event) {
972 CenterToTarget(
true);
975void AISTargetListDialog::OnTargetCreateWpt(wxCommandEvent &event) {
977 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
978 wxLIST_STATE_SELECTED);
979 if (selItemID == -1)
return;
981 std::shared_ptr<AisTargetData> pAISTarget = NULL;
984 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
988 new RoutePoint(pAISTarget->Lat, pAISTarget->Lon, g_default_wp_icon,
989 wxEmptyString, wxEmptyString);
991 pSelect->AddSelectableRoutePoint(pAISTarget->Lat, pAISTarget->Lon, pWP);
993 NavObj_dB::GetInstance().InsertRoutePoint(pWP);
995 if (pRouteManagerDialog && pRouteManagerDialog->IsShown())
996 pRouteManagerDialog->UpdateWptListCtrl();
997 gFrame->GetPrimaryCanvas()->undo->BeforeUndoableAction(
998 Undo_CreateWaypoint, pWP, Undo_HasParent, NULL);
999 gFrame->GetPrimaryCanvas()->undo->AfterUndoableAction(NULL);
1004void AISTargetListDialog::OnShowAllTracks(wxCommandEvent &event) {
1006 for (
const auto &it : m_pdecoder->GetTargetList()) {
1007 auto pAISTarget = it.second;
1008 if (NULL != pAISTarget) {
1009 pAISTarget->b_show_track =
true;
1012 std::map<int, Track *>::iterator it;
1013 it =
g_pAIS->m_persistent_tracks.find(pAISTarget->MMSI);
1014 if (it !=
g_pAIS->m_persistent_tracks.end()) {
1015 pAISTarget->b_show_track_old =
true;
1019 UpdateAISTargetList();
1023void AISTargetListDialog::OnHideAllTracks(wxCommandEvent &event) {
1025 for (
const auto &it : m_pdecoder->GetTargetList()) {
1026 auto pAISTarget = it.second;
1027 if (NULL != pAISTarget) {
1028 pAISTarget->b_show_track =
false;
1031 std::map<int, Track *>::iterator it;
1032 it =
g_pAIS->m_persistent_tracks.find(pAISTarget->MMSI);
1033 if (it !=
g_pAIS->m_persistent_tracks.end()) {
1034 pAISTarget->b_show_track =
true;
1035 pAISTarget->b_show_track_old =
false;
1039 UpdateAISTargetList();
1043void AISTargetListDialog::OnToggleTrack(wxCommandEvent &event) {
1044 long selItemID = -1;
1045 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1046 wxLIST_STATE_SELECTED);
1047 if (selItemID == -1)
return;
1049 std::shared_ptr<AisTargetData> pAISTarget = NULL;
1052 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
1055 pAISTarget->b_show_track_old =
1056 pAISTarget->b_show_track;
1057 pAISTarget->b_show_track = !pAISTarget->b_show_track;
1058 UpdateAISTargetList();
1062void AISTargetListDialog::OnCopyMMSI(wxCommandEvent &event) {
1063 long selItemID = -1;
1064 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1065 wxLIST_STATE_SELECTED);
1066 if (selItemID == -1)
return;
1067 CopyMMSItoClipBoard((
int)m_pMMSI_array->Item(selItemID));
1070void AISTargetListDialog::OnEditFindTarget(wxCommandEvent &event) {
1071 wxString name = m_pFindTargetName->GetValue().MakeUpper();
1072 if (name.size() < 2 || name ==
" ")
return;
1078 for (
const auto &it : m_pdecoder->GetTargetList()) {
1079 auto pAISTarget = it.second;
1080 if (NULL != pAISTarget) {
1081 wxString s = pAISTarget->GetFullName();
1084 int selMMSI = pAISTarget->MMSI;
1085 if (selMMSI != -1) {
1087 for (
unsigned int i = 0; i < m_pMMSI_array->GetCount(); i++) {
1088 if (m_pMMSI_array->Item(i) == selMMSI) {
1100 for (
const auto &it : m_pdecoder->GetTargetList()) {
1101 auto pAISTarget = it.second;
1102 if (NULL != pAISTarget) {
1103 wxString s = pAISTarget->GetFullName();
1104 if (s.Find(name) != wxNOT_FOUND) {
1106 int selMMSI = pAISTarget->MMSI;
1107 if (selMMSI != -1) {
1109 for (
unsigned int i = 0; i < m_pMMSI_array->GetCount(); i++) {
1110 if (m_pMMSI_array->Item(i) == selMMSI) {
1122 if (m_pMMSI_array->GetCount())
1123 m_pListCtrlAISTargets->SetItemState(
1124 item_sel, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
1125 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1127 m_pListCtrlAISTargets->EnsureVisible(item_sel);
1128 UpdateAISTargetList();
1133void AISTargetListDialog::CenterToTarget(
bool close) {
1134 long selItemID = -1;
1135 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1136 wxLIST_STATE_SELECTED);
1137 if (selItemID == -1)
return;
1139 std::shared_ptr<AisTargetData> pAISTarget = NULL;
1142 m_pdecoder->Get_Target_Data_From_MMSI(m_pMMSI_array->Item(selItemID));
1147 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), pAISTarget->Lat,
1148 pAISTarget->Lon,
scale);
1154 factor = cc->GetScaleValue() / 5000.0;
1156 gFrame->JumpToPosition(gFrame->GetFocusCanvas(), pAISTarget->Lat,
1157 pAISTarget->Lon,
scale * factor);
1158 DoTargetQuery(pAISTarget->MMSI);
1165void AISTargetListDialog::CopyMMSItoClipBoard(
int mmsi) {
1167 if (wxTheClipboard->Open()) {
1168 wxTheClipboard->SetData(
1169 new wxTextDataObject(wxString::Format(
"%09d", mmsi)));
1170 wxTheClipboard->Close();
1173void AISTargetListDialog::OnLimitRange(wxCommandEvent &event) {
1174 g_AisTargetList_range = m_pSpinCtrlRange->GetValue();
1175 UpdateAISTargetList();
1178std::shared_ptr<AisTargetData> AISTargetListDialog::GetpTarget(
1179 unsigned int list_item) {
1181 return m_pdecoder->Get_Target_Data_From_MMSI(
1182 m_pMMSI_array->Item(list_item));
1187void AISTargetListDialog::UpdateAISTargetList() {
1188 if (m_pListCtrlAISTargets && !m_pListCtrlAISTargets->IsVirtual())
1189 return UpdateNVAISTargetList();
1191 if (m_pdecoder && m_pListCtrlAISTargets) {
1193 long selItemID = -1;
1194 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1195 wxLIST_STATE_SELECTED);
1198 if (selItemID != -1) selMMSI = m_pMMSI_array->Item(selItemID);
1200 const auto ¤t_targets = m_pdecoder->GetTargetList();
1204 m_pMMSI_array->Clear();
1206 for (
auto it = current_targets.begin(); it != current_targets.end();
1208 auto pAISTarget = it->second;
1211 if (NULL != pAISTarget) {
1213 if ((pAISTarget->b_positionOnceValid) &&
1214 (pAISTarget->Range_NM <= g_AisTargetList_range))
1216 else if (!pAISTarget->b_positionOnceValid)
1220 if (pAISTarget->b_lost) b_add =
false;
1223 m_pMMSI_array->Add(pAISTarget->MMSI);
1228 g_bsort_once =
false;
1230 m_pListCtrlAISTargets->SetItemCount(m_pMMSI_array->GetCount());
1232 g_AisTargetList_count = m_pMMSI_array->GetCount();
1234 if ((g_AisTargetList_count > 1000) && !m_bautosort_force)
1235 g_bAisTargetList_autosort =
false;
1237 m_pCBAutosort->SetValue(g_bAisTargetList_autosort);
1241 if ((selItemID != -1) && (selMMSI != -1)) {
1242 for (
unsigned int i = 0; i < m_pMMSI_array->GetCount(); i++) {
1243 if (m_pMMSI_array->Item(i) == selMMSI) {
1250 if (m_pMMSI_array->GetCount())
1251 m_pListCtrlAISTargets->SetItemState(
1252 item_sel, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
1253 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1255 m_pListCtrlAISTargets->DeleteAllItems();
1258 count.Printf(
"%lu", (
unsigned long)m_pMMSI_array->GetCount());
1259 m_pTextTargetCount->ChangeValue(count);
1262 m_pListCtrlAISTargets->Refresh(
false);
1267void AISTargetListDialog::UpdateNVAISTargetList() {
1270 long selItemID = -1;
1271 selItemID = m_pListCtrlAISTargets->GetNextItem(selItemID, wxLIST_NEXT_ALL,
1272 wxLIST_STATE_SELECTED);
1275 if (selItemID != -1) selMMSI = m_pMMSI_array->Item(selItemID);
1277 const auto ¤t_targets = m_pdecoder->GetTargetList();
1281 m_pMMSI_array->Clear();
1283 for (
auto it = current_targets.begin(); it != current_targets.end();
1285 auto pAISTarget = it->second;
1288 if (NULL != pAISTarget) {
1290 if ((pAISTarget->b_positionOnceValid) &&
1291 (pAISTarget->Range_NM <= g_AisTargetList_range))
1293 else if (!pAISTarget->b_positionOnceValid)
1297 m_pMMSI_array->Add(pAISTarget->MMSI);
1302 g_bsort_once =
false;
1304 g_AisTargetList_count = m_pMMSI_array->GetCount();
1306 m_pListCtrlAISTargets->DeleteAllItems();
1308 for (
int i = 0; i < g_AisTargetList_count; i++) {
1311 m_pListCtrlAISTargets->InsertItem(item);
1312 for (
int j = 0; j < tlTCPA + 1; j++) {
1314 item.SetText(m_pListCtrlAISTargets->OnGetItemText(i, j));
1315 m_pListCtrlAISTargets->SetItem(item);
1319 if ((g_AisTargetList_count > 1000) && !m_bautosort_force)
1320 g_bAisTargetList_autosort =
false;
1322 m_pCBAutosort->SetValue(g_bAisTargetList_autosort);
1326 if ((selItemID != -1) && (selMMSI != -1)) {
1327 for (
unsigned int i = 0; i < m_pMMSI_array->GetCount(); i++) {
1328 if (m_pMMSI_array->Item(i) == selMMSI) {
1335 if (m_pMMSI_array->GetCount())
1336 m_pListCtrlAISTargets->SetItemState(
1337 item_sel, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
1338 wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
1340 m_pListCtrlAISTargets->DeleteAllItems();
1343 count.Printf(
"%lu", (
unsigned long)m_pMMSI_array->GetCount());
1344 m_pTextTargetCount->ChangeValue(count);
1347 m_pListCtrlAISTargets->Refresh(
false);
1352void AISTargetListDialog::OnRightClickContext(wxCommandEvent &event) {
1353 wxAuiPaneInfo &pane = m_pAuiManager->GetPane(
"AISTargetList");
1354 if (pane.IsDocked()) {
1355 wxMenu *popup =
new wxMenu();
1356 popup->Append(ID_RCLK_UNDOCK, _(
"Undock Target List"));
1357 popup->Connect(wxEVT_COMMAND_MENU_SELECTED,
1358 wxCommandEventHandler(AISTargetListDialog::OnContextUndock),
1366void AISTargetListDialog::OnContextUndock(wxCommandEvent &event) {
1367 wxAuiPaneInfo &pane = m_pAuiManager->GetPane(
"AISTargetList");
1369 m_pAuiManager->Update();
AisDecoder * g_pAIS
Global instance.
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.
float GetVPScale()
Return the ViewPort scale factor, in physical pixels per meter.
A custom list control for displaying AIS target information.
Represents a waypoint or mark within the navigation system.
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.
MySQL based storage for routes, tracks, etc.
AIS info display component.
Waypoint or mark abstraction.
Select * pSelect
Global instance.
Selected route, segment, waypoint, etc.