394class FilterConfigPanelImpl :
public FilterConfigPanel {
395 friend FilterConfigPanel* FilterConfigPanel::Create(wxWindow*,
399 class Statbox :
public wxStaticBoxSizer {
401 Statbox(wxWindow* parent, ListType& type, wxArrayString& list,
402 const std::string& label)
403 : wxStaticBoxSizer(wxVERTICAL, parent, label),
407 auto radio_btn_box =
new wxBoxSizer(wxHORIZONTAL);
409 new wxRadioButton(parent, wxID_ANY, _(
"Accept only sentences"),
410 wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
411 m_ignore_btn =
new wxRadioButton(parent, wxID_ANY, _(
"Ignore sentences"));
412 radio_btn_box->Add(m_accept_btn, wxSizerFlags().Border());
413 radio_btn_box->Add(m_ignore_btn, wxSizerFlags().Border());
415 auto setup_box =
new wxBoxSizer(wxHORIZONTAL);
416 auto flags1 = wxSizerFlags(1);
417 auto flags0 = wxSizerFlags(0);
419 new wxStaticText(parent, wxID_ANY,
"", wxDefaultPosition,
420 wxDefaultSize, wxST_ELLIPSIZE_END);
421 m_edit_btn =
new wxButton(parent, wxID_ANY,
"...");
422 m_edit_btn->Bind(wxEVT_BUTTON, [&](wxCommandEvent& e) { OnEdit(e); });
423 m_edit_btn->SetMaxSize(wxSize(parent->GetCharWidth() * 4, -1));
424 setup_box->Add(m_sentences_text, flags1.Expand());
425 setup_box->Add(m_edit_btn, flags0.Border(wxDOWN | wxRIGHT | wxLEFT));
427 auto vbox =
new wxBoxSizer(wxVERTICAL);
428 vbox->Add(radio_btn_box, wxSizerFlags());
429 vbox->Add(setup_box, flags1.DoubleBorder(wxLEFT | wxRIGHT | wxDOWN));
434 m_ignore_btn->Bind(wxEVT_RADIOBUTTON,
435 [&](wxCommandEvent& e) { OnDirectionChange(e); });
436 m_accept_btn->Bind(wxEVT_RADIOBUTTON,
437 [&](wxCommandEvent& e) { OnDirectionChange(e); });
441 m_accept_btn->SetValue(m_type == ListType::WHITELIST);
442 m_ignore_btn->SetValue(m_type == ListType::BLACKLIST);
443 auto text = StringArrayToString(m_list);
444 text = text.empty() ? _(
"No sentences selected") : text;
445 m_sentences_text->SetLabel(text);
446 m_parent->GetGrandParent()->Layout();
452 wxArrayString& m_list;
453 wxRadioButton* m_accept_btn;
454 wxRadioButton* m_ignore_btn;
455 wxStaticText* m_sentences_text;
456 wxButton* m_edit_btn;
458 void OnDirectionChange(wxCommandEvent& e) {
459 if (m_accept_btn->GetValue()) m_type = ListType::WHITELIST;
460 if (m_ignore_btn->GetValue()) m_type = ListType::BLACKLIST;
464 void OnEdit(wxCommandEvent&) {
465 static const std::string kNothingHere = _(
"No sentences selected");
466 if (m_sentences_text->GetLabel() == kNothingHere)
467 m_sentences_text->SetLabel(
"");
468 const wxArrayString list =
469 wxStringTokenize(m_sentences_text->GetLabel(),
",");
471 if (dlg.ShowModal() != wxID_OK)
return;
473 std::string text = dlg.GetSentences().ToStdString();
474 m_list = wxStringTokenize(text,
",");
475 if (text.empty()) text = kNothingHere;
476 m_sentences_text->SetLabel(text);
483 m_output_filter->Reload();
484 m_input_filter->Reload();
490 auto* vbox =
new wxBoxSizer(wxVERTICAL);
491 auto flags = wxSizerFlags().Border();
493 new Statbox(
this, m_params.input_sentence_list_type,
494 m_params.input_sentence_list, _(
"Input filtering"));
495 vbox->Add(m_input_filter, flags);
497 new Statbox(
this, m_params.output_sentence_list_type,
498 m_params.output_sentence_list, _(
"Output filtering"));
499 vbox->Add(m_output_filter, flags);
501 wxWindowBase::Layout();
505 Statbox* m_input_filter;
506 Statbox* m_output_filter;
576class NetConfigPanelImpl :
public NetConfigPanel {
577 friend NetConfigPanel* NetConfigPanel::Create(wxWindow*,
ConnectionParams&);
579 class ExpertModeCheckBox :
public wxCheckBox {
581 explicit ExpertModeCheckBox(wxWindow* parent)
582 : wxCheckBox(parent, wxID_ANY,
"") {}
586 class ConnectionTypeChoice :
public wxChoice {
588 ConnectionTypeChoice(wxWindow* parent, std::function<
void()> on_choice)
589 : wxChoice(parent, wxID_ANY), m_on_choice(std::move(on_choice)) {
590 for (
const auto& view : kBasicNetViews) Append(view);
591 Append(kBasicNetViews[0]);
592 wxChoice::SetSelection(0);
593 Bind(wxEVT_CHOICE, [&](wxCommandEvent e) {
600 std::function<void()> m_on_choice;
609 "IP address or hostname, often 255.255.255.255"),
612 Bind(wxEVT_TEXT, [&](wxCommandEvent& e) {
613 m_params.network_address = GetValue();
616 wxWindowBase::SetMinSize(wxSize(60 * wxWindow::GetCharWidth(), -1));
624 void ChangeValue(
const wxString& text)
override {
626 m_params.network_address = text;
629 void SetClientMode() {
630 if (GetValue() ==
"0.0.0.0") ChangeValue(
"");
635 void SetServerMode() {
636 ChangeValue(
"0.0.0.0");
637 m_params.network_address =
"0.0.0.0";
641 void SetClientMode(
const std::string& help) {
652 class CommentTextCtrl :
public wxTextCtrl,
public Reloadable<wxTextCtrl> {
655 : wxTextCtrl(parent, wxID_ANY), m_params(params) {
657 Bind(wxEVT_TEXT, [&](wxCommandEvent& e) {
658 m_params.user_comment = GetValue();
663 void Reload()
override { ChangeValue(m_params.user_comment); }
670 class NetGrid :
public wxFlexGridSizer {
674 std::function<
void(DataProtocol)> on_protocol_change)
675 : wxFlexGridSizer(2),
678 m_in_out_panel(in_out_panel),
679 m_on_protocol_change(std::move(on_protocol_change)) {
682 static const wxSize kHelpSize = parent->GetTextExtent(kAddressMcastHelp);
684 auto flags = wxSizerFlags().Border();
685 auto label_flags = wxSizerFlags().Border();
686#if wxCHECK_VERSION(3, 2, 0)
687 label_flags = label_flags.CentreVertical();
689 m_expert_mode_checkbox =
new ExpertModeCheckBox(parent);
690 m_expert_mode_checkbox->Bind(wxEVT_CHECKBOX, [&](wxCommandEvent& e) {
691 OnExpertModeChange();
694 m_expert_mode_label =
695 new wxStaticText(parent, wxID_ANY, _(
"Expert mode"));
696 Add(m_expert_mode_label, label_flags);
697 Add(m_expert_mode_checkbox, flags);
699 m_connection_type_label =
700 new wxStaticText(parent, wxID_ANY, _(
"Connection type"));
701 m_connection_type_choice =
702 new ConnectionTypeChoice(parent, [&] { OnConnectionTypeChange(); });
703 Add(m_connection_type_label, label_flags);
704 Add(m_connection_type_choice, flags);
706 m_protocol_label =
new wxStaticText(parent, wxID_ANY, _(
"Data Protocol"));
707 m_protocol_choice = ProtocolChoice::Create(parent, m_params, [&] {
708 m_on_protocol_change(m_params.data_protocol);
710 Add(m_protocol_label, label_flags);
711 Add(m_protocol_choice, flags);
713 m_address_label =
new wxStaticText(parent, wxID_ANY, _(
"Server address"));
714 m_address_textctrl =
new AddressTextCtrl(parent, m_params);
715 m_address_textctrl->SetMinSize(wxSize(kHelpSize.x, -1));
716 m_address_textctrl->Bind(wxEVT_KILL_FOCUS,
717 [&](wxFocusEvent& ev) { OnAddressChange(ev); });
718 Add(m_address_label, label_flags);
719 Add(m_address_textctrl, wxSizerFlags().Border());
721 m_port_label =
new wxStaticText(parent, wxID_ANY, _(
"Data Port"));
722 m_port_textctrl = conn_edit::PortTextCtrl::Create(parent, m_params);
723 m_port_textctrl->SetMinSize(wxSize(kHelpSize.x, -1));
724 Add(m_port_label, label_flags);
725 Add(m_port_textctrl, wxSizerFlags().Border());
727 m_comment_label =
new wxStaticText(parent, wxID_ANY, _(
"User comment"));
728 m_comment_textctrl =
new CommentTextCtrl(parent, m_params);
729 Add(m_comment_label, label_flags);
730 Add(m_comment_textctrl, wxSizerFlags(1).Expand().Border());
731 OnExpertModeChange();
732 ConfigureControlsForView(kTcpDevice);
737 bool ok = CheckAddress(m_parent, *m_address_textctrl);
738 if (ok) ok = CheckPort(m_parent, *m_port_textctrl);
744 if (m_params.type != ConnectionType::NETWORK)
return;
748 if (IsDefaultParams(&m_params)) {
752 view = NetViewByConnection(&m_params);
754 std::find(kBasicNetViews.begin(), kBasicNetViews.end(), view);
755 is_expert = found == kBasicNetViews.end();
757 m_expert_mode_checkbox->SetValue(is_expert);
758 OnExpertModeChange();
760 auto item = m_connection_type_choice->FindString(view);
761 if (item != wxNOT_FOUND) m_connection_type_choice->SetSelection(item);
762 OnConnectionTypeChange();
769 std::function<void(DataProtocol)> m_on_protocol_change;
770 wxStaticText* m_expert_mode_label;
771 ExpertModeCheckBox* m_expert_mode_checkbox;
772 wxStaticText* m_connection_type_label;
773 wxChoice* m_connection_type_choice;
774 wxStaticText* m_protocol_label;
776 wxStaticText* m_address_label;
777 AddressTextCtrl* m_address_textctrl;
778 wxStaticText* m_port_label;
780 wxStaticText* m_comment_label;
781 wxTextCtrl* m_comment_textctrl;
783 void OnExpertModeChange() {
784 bool is_expert = m_expert_mode_checkbox->GetValue();
785 int view = m_connection_type_choice->GetSelection();
786 m_connection_type_choice->Clear();
788 for (
const auto& choice : kAdvancedNetViews)
789 m_connection_type_choice->Append(choice);
790 m_connection_type_label->SetLabel(_(
"Connection type"));
791 if (m_comment_label) m_comment_label->Show();
792 if (m_comment_textctrl) m_comment_textctrl->Show();
794 if (view != wxNOT_FOUND) {
795 if (
static_cast<size_t>(view) >= kBasicNetViews.size()) view = 0;
797 for (
const auto& choice : kBasicNetViews)
798 m_connection_type_choice->Append(choice);
799 m_connection_type_label->SetLabel(_(
"Connect to"));
800 if (m_comment_label) m_comment_label->Hide();
801 if (m_comment_textctrl) m_comment_textctrl->Hide();
803 m_connection_type_choice->SetSelection(view);
805 m_connection_type_choice->GetStringSelection().ToStdString();
806 if (!view_str.empty()) ConfigureControlsForView(view_str);
807 m_parent->GetParent()->Layout();
808 m_parent->FitInside();
811 void OnAddressChange(wxFocusEvent& ev)
const {
812 int selection = m_connection_type_choice->GetSelection();
813 if (selection != wxNOT_FOUND) {
815 m_connection_type_choice->GetString(selection).ToStdString();
816 if (type == kMulticastClient || type == kMulticastServer) {
817 auto address = m_address_textctrl->GetValue().ToStdString();
818 if (!IsAddressMultiCast(address)) {
820 wxMessageDialog(m_parent, _(
"Illegal multicast address"),
821 _(
"OpenCPN warning"), wxOK | wxICON_WARNING);
829 void OnConnectionTypeChange() {
830 if (m_params.type != ConnectionType::NETWORK)
return;
831 int selection = m_connection_type_choice->GetSelection();
832 if (selection == wxNOT_FOUND)
return;
834 m_connection_type_choice->GetStringSelection().ToStdString();
835 if (view == kTcpDevice || view == kTcpClient || view == kTcpServer)
836 m_params.net_protocol = NetworkProtocol::TCP;
837 else if (view == kSignalkClient || view == kSignalkDevice)
838 m_params.net_protocol = NetworkProtocol::SIGNALK;
839 else if (view == kGpsdClient || view == kGpsdDevice)
840 m_params.net_protocol = NetworkProtocol::GPSD;
841 else if (view == kUdpReceive || view == kUdpInput || view == kUdpSend ||
842 view == kUdpOutput || view == kMulticastClient ||
843 view == kMulticastServer || view == kUdpInputOutput)
844 m_params.net_protocol = NetworkProtocol::UDP;
846 assert(
false &&
"Cannot handle view");
847 if (view == kTcpServer || view == kUdpReceive || view == kUdpInput ||
848 view == kMulticastServer)
849 m_params.network_address =
"0.0.0.0";
850 ConfigureControlsForView(view);
851 OnExpertModeChange();
860 auto address = cp->network_address.ToStdString();
861 bool is_server = address.empty() || address ==
"0.0.0.0";
862 if (IsAddressMultiCast(cp->network_address))
863 return is_server ? kMulticastServer : kMulticastClient;
864 switch (cp->net_protocol) {
865 case NetworkProtocol::GPSD:
867 case NetworkProtocol::SIGNALK:
868 return kSignalkDevice;
869 case NetworkProtocol::UDP:
870 if (cp->direction == PortDirection::kInOut)
return kUdpInputOutput;
871 if (!is_server)
return kUdpSend;
873 case NetworkProtocol::TCP:
874 return is_server ? kTcpServer : kTcpDevice;
876 wxLogWarning(
"Cannot deduce connection params view type");
882 void ConfigureControlsForView(
const std::string& view) {
883 if (m_params.type != ConnectionType::NETWORK) {
884 m_connection_type_choice->SetSelection(0);
887 int selection = m_connection_type_choice->GetSelection();
888 assert(selection != wxNOT_FOUND);
890 std::find(kBasicNetViews.begin(), kBasicNetViews.end(), view);
891 m_expert_mode_checkbox->SetValue(found == kBasicNetViews.end());
892 m_address_textctrl->Reload();
893 m_address_textctrl->SetClientMode();
894 m_address_textctrl->Show();
895 m_address_label->SetLabel(_(
"Server address"));
896 m_address_label->Show();
897 m_in_out_panel->EnableOutput(
false);
898 m_in_out_panel->EnableInput(
false);
899 m_port_textctrl->
Reload();
900 auto port = m_port_textctrl->GetValue();
901 if (port == kDefaultGpsdPort || port == kDefaultSignalkPort ||
905 m_protocol_choice->
Reload();
906 m_protocol_choice->Enable();
907 if (view == kTcpDevice || view == kTcpClient) {
908 m_address_label->Show();
909 m_address_textctrl->SetClientMode();
911 m_in_out_panel->EnableInput(
true);
912 m_in_out_panel->EnableOutput(
true);
913 }
else if (view == kUdpReceive || view == kUdpInput ||
914 view == kUdpInputOutput) {
915 m_address_label->Show(view == kUdpInputOutput);
916 if (view != kUdpInputOutput) m_address_textctrl->SetServerMode();
917 m_address_textctrl->Show(view == kUdpInputOutput);
919 m_in_out_panel->SetOutput(view == kUdpInputOutput);
920 m_in_out_panel->SetInput(
true);
921 }
else if (view == kUdpSend || view == kUdpOutput) {
922 m_address_textctrl->SetClientMode(kAddressUdpHelp);
923 m_in_out_panel->SetInput(
false);
924 m_in_out_panel->SetOutput(
true);
925 }
else if (view == kGpsdClient || view == kGpsdDevice) {
926 m_protocol_choice->Clear();
927 m_protocol_choice->Append(
"gpsd");
928 m_protocol_choice->SetSelection(0);
929 m_protocol_choice->Disable();
930 m_address_textctrl->SetClientMode();
933 m_in_out_panel->SetInput(
true);
934 m_in_out_panel->SetOutput(
false);
935 }
else if (view == kSignalkClient || view == kSignalkDevice) {
936 m_protocol_choice->Clear();
937 m_protocol_choice->Append(
"SignalK");
938 m_protocol_choice->SetSelection(0);
939 m_protocol_choice->Disable();
940 m_address_textctrl->SetClientMode(kAddressUdpHelp);
943 m_in_out_panel->SetInput(
true);
944 m_in_out_panel->SetOutput(
false);
945 }
else if (view == kTcpServer) {
946 m_address_label->SetLabel(_(
"Interface"));
947 m_address_textctrl->SetServerMode();
948 m_in_out_panel->EnableInput(
true);
949 m_in_out_panel->EnableOutput(
true);
950 }
else if (view == kMulticastClient || view == kMulticastServer) {
951 auto address = m_address_textctrl->GetValue();
952 if (address.empty() || address ==
"0.0.0.0")
953 m_address_textctrl->
SetHelp(kAddressMcastHelp);
954 m_address_label->SetLabel(_(
"Multicast group"));
956 m_port_textctrl->
SetHelp(kMcastPortHelp);
958 m_address_textctrl->
SetHelp(kAddressMcastHelp);
959 if (view == kMulticastClient) {
960 m_in_out_panel->SetInput(
false);
961 m_in_out_panel->SetOutput(
true);
963 m_in_out_panel->SetInput(
true);
964 m_in_out_panel->EnableOutput(
true);
967 wxLogError(
"Illegal view: %s", view.c_str());
968 assert(
false &&
"Illegal view");
974 return ConnectionType::NETWORK == params->type &&
975 default_params.net_protocol == params->net_protocol &&
976 default_params.network_port == params->network_port &&
977 default_params.network_address == params->network_address;
981 class NetGridPanel :
public wxPanel,
public Reloadable<wxPanel> {
985 std::function<
void(DataProtocol)> on_protocol_change)
987 m_net_grid(
new NetGrid(
this, params, in_out_panel,
988 std::move(on_protocol_change))) {
989 SetSizer(m_net_grid);
990 wxWindowBase::Layout();
993 bool CheckStatus() {
return m_net_grid->CheckStatus(); }
995 void Reload()
override { m_net_grid->Reload(); }
1008 if (m_params.type != ConnectionType::NETWORK)
return true;
1009 return m_grid_panel->CheckStatus();
1014 :
NetConfigPanel(parent), m_params(params), m_grid_panel(nullptr) {
1015 auto flags = wxSizerFlags().Border();
1016 auto vbox =
new wxBoxSizer(wxVERTICAL);
1017 auto input_output_panel = InputOutputPanel::Create(
this, m_params);
1018 m_filter_panel = FilterConfigPanel::Create(
this, m_params);
1020 GetParent()->Layout();
1023 auto on_proto_change = [&](DataProtocol p) {
1024 m_advanced_panel->
EnableChild(p == DataProtocol::PROTO_NMEA0183);
1027 new NetGridPanel(
this, m_params, input_output_panel, on_proto_change);
1028 vbox->Add(m_grid_panel, flags.Expand());
1029 vbox->Add(input_output_panel, flags);
1031 auto hbox =
new wxBoxSizer(wxHORIZONTAL);
1032 hbox->Add(
new wxStaticText(
this, wxID_ANY, _(
"Advanced")));
1033 hbox->Add(m_advanced_panel);
1034 vbox->Add(hbox, flags.Expand());
1035 vbox->Add(m_filter_panel, flags.Expand());
1043 ConnectionParams& m_params;
1044 NetGridPanel* m_grid_panel;
1045 FilterConfigPanel* m_filter_panel;
1046 ExpandablePanel* m_advanced_panel;