23 #include <wx/textctrl.h> 24 #include <wx/stattext.h> 25 #include <wx/combobox.h> 26 #include <wx/dataview.h> 27 #include <wx/html/helpctrl.h> 28 #include <wx/cshelp.h> 31 wxWindow *parent, wxWindowID
id,
33 const int additional_grid_rows,
36 const wxString &name) :
37 wxDialog(parent, id, std::move(title), pos, wxSize(-1,-1), style, name),
39 mac_{{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}},
43 panel_ =
new wxPanel(
this, -1);
44 vbox_ =
new wxBoxSizer(wxVERTICAL);
46 grid_ =
new wxFlexGridSizer(2 + additional_grid_rows, 2, 10, 25);
48 auto *sensors_text =
new wxStaticText(
panel_, wxID_ANY,
"rc_visard");
49 grid_->Add(sensors_text);
51 auto *sensors_box =
new wxBoxSizer(wxHORIZONTAL);
54 grid_->Add(sensors_box, 1, wxEXPAND);
56 auto *mac_text =
new wxStaticText(
panel_, wxID_ANY,
"MAC address");
59 auto *mac_box =
new wxBoxSizer(wxHORIZONTAL);
67 m =
new wxTextCtrl(
panel_, wxID_ANY, wxEmptyString,
68 wxDefaultPosition, wxSize(35, -1));
72 grid_->Add(mac_box, 1, wxEXPAND);
84 const wxDataViewListModel *sensor_list,
85 const std::vector<bool>& show)
89 if (sensor_list !=
nullptr)
95 const auto rows = sensor_list->GetCount();
96 unsigned int sensors_row = 0;
97 for (
typename std::decay<decltype(rows)>::type i = 0; i < rows; ++i)
99 if (show.empty() || show[i])
101 wxVariant hostname{};
105 const auto s = wxString::Format(
"%s - %s", hostname.GetString(), mac.GetString());
107 row_map_.emplace(i, sensors_row + 1);
121 const auto found =
row_map_.find(static_cast<int>(row));
150 std::array<uint8_t, 6> mac;
151 for (uint8_t i = 0; i < 6; ++i)
153 const auto s =
mac_[i]->GetValue().ToStdString();
157 const auto v = std::stoul(s,
nullptr, 16);
160 throw std::invalid_argument(
"");
162 mac[i] =
static_cast<uint8_t
>(v);
164 catch(
const std::invalid_argument&)
166 throw std::runtime_error(
167 std::string(
"Each MAC address segment must contain ") +
168 "a hex value ranging from 0x00 to 0xff.");
176 const auto mac =
getMac();
178 std::ostringstream mac_string;
180 for (
const auto m : mac)
186 mac_string << std::hex << std::setfill(
'0') << std::setw(2);
187 mac_string << static_cast<unsigned int>(m);
190 return mac_string.str();
195 const std::string url = std::string(
"help.htm#") + section;
210 if (
sensors_->GetSelection() != wxNOT_FOUND)
225 const int row =
sensors_->GetSelection();
227 if (row == wxNOT_FOUND)
232 wxVariant mac_string{};
237 const auto mac = split<6>(mac_string.GetString().ToStdString(),
':');
239 for (uint8_t i = 0; i < 6; ++i)
241 mac_[i]->ChangeValue(mac[i]);
242 mac_[i]->SetEditable(
false);
250 for (uint8_t i = 0; i < 6; ++i)
253 mac_[i]->SetEditable(
true);
std::string getMacString() const
wxBoxSizer * getVerticalBox()
std::unordered_map< unsigned int, unsigned int > row_map_
SensorCommandDialog()=default
void onSensorSelected(wxCommandEvent &event)
Event handler for selection of an device from drop down menu.
const wxDataViewListModel * sensor_list_
virtual void clear()
Reset and clear all fields.
wxFlexGridSizer * getGrid()
Base class for dialogs for sending commands to a camera.
wxHtmlHelpController * help_ctrl_
std::array< wxTextCtrl *, 6 > mac_
void setDiscoveredSensors(const wxDataViewListModel *sensor_list, const std::vector< bool > &show={})
Set list of discovered devices to provide a drop down menu to the user.
void fillMac()
Fill MAC address according to selected device.
void clearMac()
Clear MAC address.
void displayHelp(const std::string §ion)
std::unordered_map< unsigned int, unsigned int > row_map_inv_
void setActiveSensor(const unsigned int row)
Select a specific device of the list set by setDiscoveredSensors.
std::array< uint8_t, 6 > getMac() const