Skip to content

Commit cbfd082

Browse files
committed
data_momitor: Use system filters.
1 parent 2f2d74e commit cbfd082

3 files changed

Lines changed: 46 additions & 15 deletions

File tree

data/filters/nmea-input.filter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"filter" : {
3-
"name" : "all-nmea",
3+
"name" : "nmea-input",
44
"buses" : [
55
"nmea0183",
66
"nmea2000"

data/filters/nmea-output.filter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"filter" : {
3-
"name" : "all-nmea",
3+
"name" : "nmea-output",
44
"buses" : [
55
"nmea0183",
66
"nmea2000"

gui/src/data_monitor.cpp

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <wx/sstream.h>
1515
#include <wx/statline.h>
1616
#include <wx/stattext.h>
17+
#include <wx/translation.h>
1718
#include <wx/wrapsizer.h>
1819

1920
#ifndef ocpnUSE_wxBitmapBundle
@@ -24,16 +25,27 @@
2425
#include "androidUTIL.h"
2526
#endif
2627

27-
#include "tty_scroll.h"
28+
#include "model/navmsg_filter.h"
29+
#include "model/nmea_log.h"
30+
#include "model/gui.h"
31+
2832
#include "data_monitor_src.h"
2933
#include "svg_icons.h"
34+
#include "tty_scroll.h"
35+
3036
#include "std_filesystem.h"
31-
#include "model/nmea_log.h"
32-
#include "model/gui.h"
3337

3438
#pragma clang diagnostic push
3539
#pragma ide diagnostic ignored "UnreachableCode"
3640

41+
// Make _() return std::string instead of wxString;
42+
#undef _
43+
#if wxCHECK_VERSION(3, 2, 0)
44+
#define _(s) wxGetTranslation(wxASCII_STR(s)).ToStdString()
45+
#else
46+
#define _(s) wxGetTranslation((s)).ToStdString()
47+
#endif
48+
3749
using SetLogFunc = std::function<void(int)>;
3850

3951
/** Main window, a rolling log of messages. */
@@ -121,17 +133,36 @@ class LogButton : public wxButton {
121133
/** Offer user to select current filter. */
122134
class FilterChoice : public wxChoice {
123135
public:
124-
FilterChoice(wxWindow* parent) : wxChoice() {
125-
wxArrayString choices;
126-
choices.Add(_("All data"));
127-
choices.Add(_("All NMEA data"));
128-
choices.Add(_("Incoming NMEA data"));
129-
choices.Add(_("Outgoing NMEA data"));
130-
choices.Add(_("Malformed data only"));
131-
choices.Add(_("Plugin data"));
132-
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
133-
SetSelection(0);
136+
FilterChoice(wxWindow* parent) : wxChoice(parent, wxID_ANY) {
137+
m_filters = NavmsgFilter::GetSystemFilters();
138+
OnFilterListChange();
139+
}
140+
141+
void OnFilterListChange() {
142+
Clear();
143+
for (auto& filter : m_filters) {
144+
try {
145+
Append(kLabels.at(filter.m_name));
146+
} catch (std::out_of_range&) {
147+
Append(filter.m_description);
148+
}
149+
}
150+
if (!m_filters.empty()) SetSelection(0);
134151
}
152+
153+
private:
154+
// Translated labels for system filters by filter name. If not
155+
// found the untranslated json description is used.
156+
const std::unordered_map<std::string, std::string> kLabels = {
157+
{"all-data", _("All data")},
158+
{"all-nmea", _("All NMEA data")},
159+
{"malformed", _("Malformed messages")},
160+
{"nmea-input", _("NMEA input data")},
161+
{"nmea-output", _("NMEA output data")},
162+
{"plugins", _("Messages to plugins")},
163+
};
164+
165+
std::vector<NavmsgFilter> m_filters;
135166
};
136167

137168
/** Button to stop/resume messages in main log window. */

0 commit comments

Comments
 (0)