25#include "filter_sentence_dlg.h"
33#include "androidUTIL.h"
36static wxString StringArrayToString(
const wxArrayString& arr) {
37 wxString ret = wxEmptyString;
38 for (
size_t i = 0; i < arr.Count(); i++) {
39 if (i > 0) ret.Append(
",");
45FilterSentenceDlg::FilterSentenceDlg(wxWindow* parent, FilterDirection dir,
46 ListType type,
const wxArrayString& list)
47 : wxDialog(parent, wxID_ANY, _(
"Sentence Filter"), wxDefaultPosition,
51 m_sentences(NMEA0183().GetRecognizedArray()) {
53 auto* mainSizer =
new wxBoxSizer(wxVERTICAL);
54 auto* secondSizer =
new wxBoxSizer(wxHORIZONTAL);
55 auto* pclbBox =
new wxStaticBox(
this, wxID_ANY, GetBoxLabel());
56 auto* stcSizer =
new wxStaticBoxSizer(pclbBox, wxVERTICAL);
57 m_sentences_clb =
new wxCheckListBox(
this, wxID_ANY, wxDefaultPosition,
58 wxDefaultSize, m_sentences);
59 auto* btnEntrySizer =
new wxBoxSizer(wxVERTICAL);
60 auto* btnCheckAll =
new wxButton(
this, wxID_ANY, _(
"Select All"));
61 auto* btnClearAll =
new wxButton(
this, wxID_ANY, _(
"Clear All"));
62 auto* btnAdd =
new wxButton(
this, wxID_ANY, _(
"Add"));
63 m_del_btn =
new wxButton(
this, wxID_ANY, _(
"Delete"));
65 auto* btnSizer =
new wxStdDialogButtonSizer();
66 auto* btnOK =
new wxButton(
this, wxID_OK);
67 auto* btnCancel =
new wxButton(
this, wxID_CANCEL, _(
"Cancel"));
69 secondSizer->Add(stcSizer, 1, wxALL | wxEXPAND, 5);
70 stcSizer->Add(m_sentences_clb, 1, wxALL | wxEXPAND, 5);
71 btnEntrySizer->Add(btnCheckAll, 0, wxALL, 5);
72 btnEntrySizer->Add(btnClearAll, 0, wxALL, 5);
73 btnEntrySizer->AddSpacer(1);
74 btnEntrySizer->Add(btnAdd, 0, wxALL, 5);
75 btnEntrySizer->Add(m_del_btn, 0, wxALL, 5);
76 secondSizer->Add(btnEntrySizer, 0, wxALL | wxEXPAND, 5);
77 mainSizer->Add(secondSizer, 1, wxEXPAND, 5);
78 btnSizer->AddButton(btnOK);
79 btnSizer->AddButton(btnCancel);
81 mainSizer->Add(btnSizer, 0, wxALL | wxEXPAND, 5);
84 mainSizer->SetSizeHints(
this);
87 btnAdd->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
88 wxCommandEventHandler(FilterSentenceDlg::OnAddClick),
nullptr,
90 m_del_btn->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
91 wxCommandEventHandler(FilterSentenceDlg::OnDeleteClick),
93 m_sentences_clb->Connect(
94 wxEVT_COMMAND_LISTBOX_SELECTED,
95 wxCommandEventHandler(FilterSentenceDlg::OnCLBSelect),
nullptr,
this);
97 wxEVT_COMMAND_BUTTON_CLICKED,
98 wxCommandEventHandler(FilterSentenceDlg::OnCheckAllClick),
nullptr,
this);
100 wxEVT_COMMAND_BUTTON_CLICKED,
101 wxCommandEventHandler(FilterSentenceDlg::OnClearAllClick),
nullptr,
this);
105wxString FilterSentenceDlg::GetBoxLabel()
const {
106 if (m_dir == FILTER_OUTPUT)
107 return m_type == WHITELIST ? _(
"Transmit sentences") : _(
"Drop sentences");
109 return m_type == WHITELIST ? _(
"Accept only sentences")
110 : _(
"Ignore sentences");
113void FilterSentenceDlg::Populate(
const wxArrayString& list) {
114 if (m_dir == FILTER_OUTPUT) {
116 m_sentences.Add(g_TalkerIdText + wxString(
"RMB"));
117 m_sentences.Add(g_TalkerIdText + wxString(
"RMC"));
118 m_sentences.Add(g_TalkerIdText + wxString(
"APB"));
119 m_sentences.Add(g_TalkerIdText + wxString(
"XTE"));
121 m_sentences.Add(
"AIVDM");
122 m_sentences.Add(
"AIVDO");
123 m_sentences.Add(
"FRPOS");
124 m_sentences.Add(g_TalkerIdText);
125 m_sentences.Add(
"CD");
127 m_sentences_clb->Clear();
128 m_sentences_clb->InsertItems(m_sentences, 0);
130 wxArrayString new_strings;
131 if (list.Count() == 0) {
132 for (
size_t i = 0; i < m_sentences_clb->GetCount(); ++i)
133 m_sentences_clb->Check(i, m_type == WHITELIST);
135 for (
size_t i = 0; i < list.Count(); ++i) {
136 int item = m_sentences_clb->FindString(list[i]);
137 if (item != wxNOT_FOUND)
138 m_sentences_clb->Check(item);
140 new_strings.Add(list[i]);
142 if (new_strings.GetCount()) {
143 m_sentences_clb->InsertItems(new_strings, m_sentences_clb->GetCount());
144 for (
size_t i = 0; i < new_strings.GetCount(); ++i) {
145 int item = m_sentences_clb->FindString(new_strings[i]);
146 if (item != wxNOT_FOUND) m_sentences_clb->Check(item);
152wxString FilterSentenceDlg::GetSentences() {
153 wxArrayString retString;
154 for (
size_t i = 0; i < m_sentences_clb->GetCount(); i++) {
155 if (m_sentences_clb->IsChecked(i))
156 retString.Add(m_sentences_clb->GetString(i));
158 return StringArrayToString(retString);
161void FilterSentenceDlg::OnCLBSelect(wxCommandEvent& e) {
164 m_del_btn->Enable(m_sentences.Index(e.GetString()) == wxNOT_FOUND);
167void FilterSentenceDlg::OnAddClick(wxCommandEvent& event) {
169 androidDisableRotation();
172 wxTextEntryDialog textdlg(
174 _(
"Enter the NMEA sentence (2, 3 or 5 characters)\n or a valid REGEX "
175 "expression (6 characters or longer)"),
176 _(
"Enter the NMEA sentence"));
178 textdlg.SetTextValidator(wxFILTER_ASCII);
179 int result = textdlg.ShowModal();
182 androidEnableRotation();
185 if (result == wxID_CANCEL)
return;
186 wxString stc = textdlg.GetValue();
188 if (stc.Length() == 2 || stc.Length() == 3 || stc.Length() == 5) {
189 m_sentences_clb->Append(stc);
190 m_sentences_clb->Check(m_sentences_clb->FindString(stc));
192 }
else if (stc.Length() < 2) {
195 _(
"An NMEA sentence is generally 3 characters long (like RMC, GGA etc.)\n \
196 It can also have a two letter prefix identifying the source, or TALKER, of the message.\n \
197 The whole sentences then looks like GPGGA or AITXT.\n \
198 You may filter out all the sentences with certain TALKER prefix (like GP, AI etc.).\n \
199 The filter also accepts Regular Expressions (REGEX) with 6 or more characters. \n\n"),
208 m_sentences_clb->Append(stc);
209 m_sentences_clb->Check(m_sentences_clb->FindString(stc));
212 OCPNMessageBox(
this, _(
"REGEX syntax error: \n") + stc,
219void FilterSentenceDlg::OnDeleteClick(wxCommandEvent& event) {
220 m_sentences_clb->Delete(m_sentences_clb->GetSelection());
223void FilterSentenceDlg::OnClearAllClick(wxCommandEvent& event) {
224 for (
size_t i = 0; i < m_sentences_clb->GetCount(); i++)
225 m_sentences_clb->Check(i,
false);
228void FilterSentenceDlg::OnCheckAllClick(wxCommandEvent& event) {
229 for (
size_t i = 0; i < m_sentences_clb->GetCount(); i++)
230 m_sentences_clb->Check(i,
true);