NEW:Support direct connection to X printer

Change-Id: I4ea38d3a69834f607161ae35eda00d042b7c4f47
(cherry picked from commit a0f63b9a3a4efd2fd6d396aa757750cd0ff28178)
This commit is contained in:
tao wang 2024-10-28 20:26:41 +08:00 committed by Noisyfox
parent d57cfa2a99
commit 98ba252862
4 changed files with 243 additions and 111 deletions

View file

@ -5953,6 +5953,7 @@ std::string DeviceManager::get_printer_ams_img(std::string type_str)
bool DeviceManager::get_printer_is_enclosed(std::string type_str) {
return get_value_from_config<bool>(type_str, "printer_is_enclosed");
}
std::vector<std::string> DeviceManager::get_resolution_supported(std::string type_str)
{
std::vector<std::string> resolution_supported;
@ -5998,6 +5999,43 @@ std::vector<std::string> DeviceManager::get_compatible_machine(std::string type_
return compatible_machine;
}
std::vector<std::string> DeviceManager::get_all_model_id()
{
std::vector<std::string> models;
std::vector<wxString> m_files;
wxDir dir(Slic3r::resources_dir() + "/printers/");
if (!dir.IsOpened()) {
return models;
}
wxString filename;
bool hasFile = dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES);
while (hasFile) {
m_files.push_back(filename);
hasFile = dir.GetNext(&filename);
}
for (wxString file : m_files) {
std::string config_file = Slic3r::resources_dir() + "/printers/" + file.ToStdString();
boost::nowide::ifstream json_file(config_file.c_str());
try {
json jj;
if (json_file.is_open()) {
json_file >> jj;
if (jj.contains("00.00.00.00")) {
json const &printer = jj["00.00.00.00"];
if (printer.contains("model_id")) {
for (auto res : printer["model_id"]) models.emplace_back(res.get<std::string>());
}
}
}
} catch (...) {}
}
return models;
}
bool DeviceManager::load_filaments_blacklist_config()
{

View file

@ -1080,7 +1080,8 @@ public:
static bool get_printer_is_enclosed(std::string type_str);
static std::vector<std::string> get_resolution_supported(std::string type_str);
static std::vector<std::string> get_compatible_machine(std::string type_str);
static bool load_filaments_blacklist_config();
static std::vector<std::string> get_all_model_id();
static bool load_filaments_blacklist_config();
static void check_filaments_in_blacklist(std::string tag_vendor, std::string tag_type, bool& in_blacklist, std::string& ac, std::string& info);
static std::string load_gcode(std::string type_str, std::string gcode_file);
};

View file

@ -1454,55 +1454,71 @@ void ConfirmBeforeSendDialog::rescale()
m_button_cancel->Rescale();
}
InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
:DPIDialog(static_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, _L("Connect the printer using IP and access code"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
InputIpAddressDialog::InputIpAddressDialog(wxWindow *parent)
: DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe),
wxID_ANY,
_L("Connect the printer using IP and access code"),
wxDefaultPosition,
wxDefaultSize,
wxCAPTION | wxCLOSE_BOX)
{
std::string icon_path = (boost::format("%1%/images/OrcaSlicerTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
SetBackgroundColour(*wxWHITE);
m_result = -1;
wxBoxSizer* m_sizer_body = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* m_sizer_main = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer* m_sizer_main_left = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* m_sizer_main_right = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* m_sizer_msg = new wxBoxSizer(wxHORIZONTAL);
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1));
m_result = -1;
wxBoxSizer *m_sizer_body = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *m_sizer_main = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *m_sizer_main_left = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *m_sizer_main_right = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *m_sizer_msg = new wxBoxSizer(wxHORIZONTAL);
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1));
m_line_top->SetBackgroundColour(wxColour(166, 169, 170));
comfirm_before_enter_text = _L("Step 1, please confirm Orca Slicer and your printer are in the same LAN.");
comfirm_after_enter_text = _L("Step 2, if the IP and Access Code below are different from the actual values on your printer, please correct them.");
comfirm_before_enter_text = _L("Step 1. Please confirm Orca Slicer and your printer are in the same LAN.");
comfirm_after_enter_text = _L("Step 2. If the IP and Access Code below are different from the actual values on your printer, please correct them.");
comfirm_last_enter_text = _L("Step 3. Please obtain the device SN from the printer side; it is usually found in the device information on the printer screen.");
m_tip1 = new Label(this, ::Label::Body_13, comfirm_before_enter_text, LB_AUTO_WRAP);
m_tip1->SetMinSize(wxSize(FromDIP(352), -1));
m_tip1->SetMaxSize(wxSize(FromDIP(352), -1));
m_tip1->Wrap(FromDIP(352));
auto m_line_tips = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1));
m_line_tips->SetBackgroundColour(wxColour(0xEEEEEE));
m_tip2 = new Label(this, ::Label::Body_13, comfirm_after_enter_text, LB_AUTO_WRAP);
m_tip2->SetMinSize(wxSize(FromDIP(352), -1));
m_tip2->SetMaxSize(wxSize(FromDIP(352), -1));
auto m_input_tip_area = new wxBoxSizer(wxHORIZONTAL);
auto m_input_area = new wxBoxSizer(wxHORIZONTAL);
m_tip3 = new Label(this, ::Label::Body_13, comfirm_last_enter_text, LB_AUTO_WRAP);
m_tip3->SetMinSize(wxSize(FromDIP(352), -1));
m_tip3->SetMaxSize(wxSize(FromDIP(352), -1));
m_tips_ip = new Label(this, _L("IP"));
ip_input_top_panel = new wxPanel(this);
ip_input_bot_panel = new wxPanel(this);
ip_input_top_panel->SetBackgroundColour(*wxWHITE);
ip_input_bot_panel->SetBackgroundColour(*wxWHITE);
auto m_input_top_sizer = new wxBoxSizer(wxVERTICAL);
auto m_input_bot_sizer = new wxBoxSizer(wxVERTICAL);
/*top input*/
auto m_input_tip_area = new wxBoxSizer(wxHORIZONTAL);
auto m_input_area = new wxBoxSizer(wxHORIZONTAL);
m_tips_ip = new Label(ip_input_top_panel, _L("IP"));
m_tips_ip->SetMinSize(wxSize(FromDIP(168), -1));
m_tips_ip->SetMaxSize(wxSize(FromDIP(168), -1));
m_input_ip = new TextInput(this, wxEmptyString, wxEmptyString);
m_input_ip = new TextInput(ip_input_top_panel, wxEmptyString, wxEmptyString);
m_input_ip->Bind(wxEVT_TEXT, &InputIpAddressDialog::on_text, this);
m_input_ip->SetMinSize(wxSize(FromDIP(168), FromDIP(28)));
m_input_ip->SetMaxSize(wxSize(FromDIP(168), FromDIP(28)));
m_tips_access_code = new Label(this, _L("Access Code"));
m_tips_access_code->SetMinSize(wxSize(FromDIP(168),-1));
m_tips_access_code->SetMaxSize(wxSize(FromDIP(168),-1));
m_tips_access_code = new Label(ip_input_top_panel, _L("Access Code"));
m_tips_access_code->SetMinSize(wxSize(FromDIP(168), -1));
m_tips_access_code->SetMaxSize(wxSize(FromDIP(168), -1));
m_input_access_code = new TextInput(this, wxEmptyString, wxEmptyString);
m_input_access_code = new TextInput(ip_input_top_panel, wxEmptyString, wxEmptyString);
m_input_access_code->Bind(wxEVT_TEXT, &InputIpAddressDialog::on_text, this);
m_input_access_code->SetMinSize(wxSize(FromDIP(168), FromDIP(28)));
m_input_access_code->SetMaxSize(wxSize(FromDIP(168), FromDIP(28)));
@ -1510,40 +1526,87 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
m_input_tip_area->Add(m_tips_ip, 0, wxALIGN_CENTER, 0);
m_input_tip_area->Add(0, 0, 0, wxLEFT, FromDIP(16));
m_input_tip_area->Add(m_tips_access_code, 0, wxALIGN_CENTER, 0);
m_input_area->Add(m_input_ip, 0, wxALIGN_CENTER, 0);
m_input_area->Add(0, 0, 0, wxLEFT, FromDIP(16));
m_input_area->Add(m_input_access_code, 0, wxALIGN_CENTER, 0);
m_input_top_sizer->Add(m_input_tip_area, 0, wxRIGHT | wxEXPAND, FromDIP(18));
m_input_top_sizer->Add(0, 0, 0, wxTOP, FromDIP(4));
m_input_top_sizer->Add(m_input_area, 0, wxRIGHT | wxEXPAND, FromDIP(18));
ip_input_top_panel->SetSizer(m_input_top_sizer);
ip_input_top_panel->Layout();
ip_input_top_panel->Fit();
/*bom input*/
auto m_input_sn_area = new wxBoxSizer(wxHORIZONTAL);
auto m_input_modelID_area = new wxBoxSizer(wxHORIZONTAL);
m_tips_sn = new Label(ip_input_bot_panel, "SN");
m_tips_sn->SetMinSize(wxSize(FromDIP(168), -1));
m_tips_sn->SetMaxSize(wxSize(FromDIP(168), -1));
m_input_sn = new TextInput(ip_input_bot_panel, wxEmptyString, wxEmptyString);
m_input_sn->Bind(wxEVT_TEXT, &InputIpAddressDialog::on_text, this);
m_input_sn->SetMinSize(wxSize(FromDIP(168), FromDIP(28)));
m_input_sn->SetMaxSize(wxSize(FromDIP(168), FromDIP(28)));
m_tips_modelID = new Label(ip_input_bot_panel, _L("Printer model"));
m_tips_modelID->SetMinSize(wxSize(FromDIP(168), -1));
m_tips_modelID->SetMaxSize(wxSize(FromDIP(168), -1));
m_input_modelID = new ComboBox(ip_input_bot_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(FromDIP(168), FromDIP(28)), 0, nullptr, wxCB_READONLY);
// m_input_modelID->Bind(wxEVT_TEXT, &InputIpAddressDialog::on_text, this);
m_input_modelID->SetMinSize(wxSize(FromDIP(168), FromDIP(28)));
m_input_modelID->SetMaxSize(wxSize(FromDIP(168), FromDIP(28)));
auto models = DeviceManager::get_all_model_id();
for (int i = 0; i < models.size(); i++) {
m_input_modelID->Append(models[i]);
m_input_modelID->SetSelection(0);
}
m_input_sn_area->Add(m_tips_sn, 0, wxALIGN_CENTER, 0);
m_input_sn_area->Add(0, 0, 0, wxLEFT, FromDIP(16));
m_input_sn_area->Add(m_tips_modelID, 0, wxALIGN_CENTER, 0);
m_input_modelID_area->Add(m_input_sn, 0, wxALIGN_CENTER, 0);
m_input_modelID_area->Add(0, 0, 0, wxLEFT, FromDIP(16));
m_input_modelID_area->Add(m_input_modelID, 0, wxALIGN_CENTER, 0);
m_input_bot_sizer->Add(m_input_sn_area, 0, wxRIGHT | wxEXPAND, FromDIP(18));
m_input_bot_sizer->Add(0, 0, 0, wxTOP, FromDIP(4));
m_input_bot_sizer->Add(m_input_modelID_area, 0, wxRIGHT | wxEXPAND, FromDIP(18));
ip_input_bot_panel->SetSizer(m_input_bot_sizer);
ip_input_bot_panel->Layout();
ip_input_bot_panel->Fit();
/*other*/
m_test_right_msg = new Label(this, Label::Body_13, wxEmptyString, LB_AUTO_WRAP);
m_test_right_msg->SetForegroundColour(wxColour(38, 166, 154));
m_test_right_msg->Hide();
m_test_wrong_msg = new Label(this, Label::Body_13, wxEmptyString, LB_AUTO_WRAP);
m_test_wrong_msg->SetForegroundColour(wxColour(208, 27, 27));
m_test_wrong_msg->Hide();
m_tip3 = new Label(this, Label::Body_12, _L("Where to find your printer's IP and Access Code?"), LB_AUTO_WRAP);
m_tip3->SetMinSize(wxSize(FromDIP(352), -1));
m_tip3->SetMaxSize(wxSize(FromDIP(352), -1));
m_tip4 = new Label(this, ::Label::Body_13, _L("Step 3: Ping the IP address to check for packet loss and latency."), LB_AUTO_WRAP);
m_tip4 = new Label(this, Label::Body_12, _L("Where to find your printer's IP and Access Code?"), LB_AUTO_WRAP);
m_tip4->SetMinSize(wxSize(FromDIP(352), -1));
m_tip4->SetMaxSize(wxSize(FromDIP(352), -1));
m_trouble_shoot = new wxHyperlinkCtrl(this, wxID_ANY, "How to trouble shooting", "");
m_img_help = new wxStaticBitmap(this, wxID_ANY, create_scaled_bitmap("input_access_code_x1_en", this, 198), wxDefaultPosition, wxSize(FromDIP(352), -1), 0);
auto m_sizer_button = new wxBoxSizer(wxHORIZONTAL);
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(38, 166, 154), StateColor::Pressed), std::pair<wxColour, int>(wxColour(38, 166, 154), StateColor::Hovered),
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
m_button_ok = new Button(this, _L("Connect"));
m_button_ok->SetBackgroundColor(btn_bg_green);
@ -1553,9 +1616,10 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
m_button_ok->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_ok->SetCornerRadius(FromDIP(12));
m_button_ok->Bind(wxEVT_LEFT_DOWN, &InputIpAddressDialog::on_ok, this);
m_button_ok->Enable(false);
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
/*auto m_button_cancel = new Button(this, _L("Close"));
m_button_cancel->SetBackgroundColor(btn_bg_white);
@ -1571,35 +1635,27 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
m_sizer_button->AddStretchSpacer();
m_sizer_button->Add(m_button_ok, 0, wxALL, FromDIP(5));
//m_sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5));
// m_sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5));
m_sizer_button->Layout();
m_status_bar = std::make_shared<BBLStatusBarSend>(this);
m_status_bar = std::make_shared<BBLStatusBarSend>(this);
m_status_bar->get_panel()->Hide();
auto m_step_icon_panel1 = new wxWindow(this, wxID_ANY);
auto m_step_icon_panel2 = new wxWindow(this, wxID_ANY);
m_step_icon_panel3 = new wxWindow(this, wxID_ANY);
m_step_icon_panel1->SetBackgroundColour(*wxWHITE);
m_step_icon_panel2->SetBackgroundColour(*wxWHITE);
m_step_icon_panel3->SetBackgroundColour(*wxWHITE);
auto m_sizer_step_icon_panel1 = new wxBoxSizer(wxVERTICAL);
auto m_sizer_step_icon_panel2 = new wxBoxSizer(wxVERTICAL);
auto m_sizer_step_icon_panel3 = new wxBoxSizer(wxVERTICAL);
m_img_step1 = new wxStaticBitmap(m_step_icon_panel1, wxID_ANY, create_scaled_bitmap("ip_address_step", this, 6), wxDefaultPosition, wxSize(FromDIP(6), FromDIP(6)), 0);
auto m_line_tips_left = new wxPanel(m_step_icon_panel1, wxID_ANY, wxDefaultPosition, wxSize(-1, 1));
m_line_tips_left->SetBackgroundColour(wxColour(0xEEEEEE));
m_img_step2 = new wxStaticBitmap(m_step_icon_panel2, wxID_ANY, create_scaled_bitmap("ip_address_step", this, 6), wxDefaultPosition, wxSize(FromDIP(6), FromDIP(6)), 0);
m_img_step3 = new wxStaticBitmap(this, wxID_ANY, create_scaled_bitmap("ip_address_step", this, 6), wxDefaultPosition, wxSize(FromDIP(6), FromDIP(6)), 0);
m_sizer_step_icon_panel1->Add(m_img_step1, 0, wxALIGN_CENTER|wxALL, FromDIP(5));
m_img_step3 = new wxStaticBitmap(m_step_icon_panel3, wxID_ANY, create_scaled_bitmap("ip_address_step", this, 6), wxDefaultPosition, wxSize(FromDIP(6), FromDIP(6)), 0);
m_step_icon_panel1->SetSizer(m_sizer_step_icon_panel1);
m_step_icon_panel1->Layout();
@ -1609,45 +1665,45 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
m_step_icon_panel2->Layout();
m_step_icon_panel2->Fit();
m_step_icon_panel3->SetSizer(m_sizer_step_icon_panel3);
m_step_icon_panel3->Layout();
m_step_icon_panel3->Fit();
m_sizer_step_icon_panel2->Add(m_img_step2, 0, wxALIGN_CENTER|wxALL, FromDIP(5));
//m_sizer_step_icon_panel3->Add(m_img_step3, 0, wxALIGN_CENTER|wxALL, FromDIP(5));
m_sizer_step_icon_panel1->Add(m_img_step1, 0, wxALIGN_CENTER | wxALL, FromDIP(5));
m_sizer_step_icon_panel2->Add(m_img_step2, 0, wxALIGN_CENTER | wxALL, FromDIP(5));
m_sizer_step_icon_panel3->Add(m_img_step3, 0, wxALIGN_CENTER | wxALL, FromDIP(5));
m_step_icon_panel1->SetMinSize(wxSize(-1, m_tip1->GetBestSize().y));
m_step_icon_panel1->SetMaxSize(wxSize(-1, m_tip1->GetBestSize().y));
m_sizer_msg->Add(0, 0, 0, wxALIGN_CENTER, FromDIP(20));
m_sizer_msg->Add(m_img_step3, 0, wxALL, FromDIP(5));
m_sizer_msg->Add(0, 0, 0, wxALIGN_CENTER, FromDIP(8));
m_sizer_msg->Add(m_tip4, 0, wxALIGN_CENTER | wxEXPAND | wxLEFT, FromDIP(5));
m_img_step3->Hide();
m_tip4->Hide();
m_step_icon_panel2->SetMinSize(wxSize(-1, m_tip2->GetBestSize().y));
m_step_icon_panel2->SetMaxSize(wxSize(-1, m_tip2->GetBestSize().y));
m_sizer_msg->Layout();
m_sizer_main_left->Add(m_step_icon_panel1, 0, wxEXPAND, 0);
m_sizer_main_left->Add(0, 0, 0, wxTOP, FromDIP(20));
m_sizer_main_left->Add(m_line_tips_left, 1, wxEXPAND, 0);
m_sizer_main_left->Add(0, 0, 0, wxTOP, FromDIP(20));
m_sizer_main_left->Add(m_step_icon_panel2, 0, wxEXPAND, 0);
m_sizer_main_left->Add(0, 0, 0, wxTOP, FromDIP(20));
m_sizer_main_left->Add(m_step_icon_panel3, 0, wxEXPAND, 0);
m_sizer_main_left->Layout();
m_trouble_shoot->Hide();
m_sizer_main_right->Add(m_tip1, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(m_tip1, 0, wxRIGHT | wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(20));
m_sizer_main_right->Add(m_line_tips, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(20));
m_sizer_main_right->Add(m_tip2, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(m_tip2, 0, wxRIGHT | wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(2));
m_sizer_main_right->Add(m_tip3, 0, wxTOP|wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(12));
m_sizer_main_right->Add(m_tip3, 0, wxRIGHT | wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_main_right->Add(m_tip4, 0, wxRIGHT | wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(3));
m_sizer_main_right->Add(m_img_help, 0, 0, 0);
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(12));
m_sizer_main_right->Add(m_input_tip_area, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_main_right->Add(m_input_area, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(ip_input_top_panel, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(ip_input_bot_panel, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4));
//m_sizer_main_right->Add(m_button_ok, 0, wxRIGHT, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4));
@ -1663,18 +1719,19 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
m_sizer_main->Layout();
m_sizer_body->Add(m_line_top, 0, wxEXPAND, 0);
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(10));
m_sizer_body->Add(m_sizer_main, 0, wxRIGHT, FromDIP(10));
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_body->Add(m_sizer_msg, 0, wxLEFT|wxEXPAND, FromDIP(18));
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_body->Add(m_trouble_shoot, 0, wxLEFT | wxRIGHT | wxEXPAND, FromDIP(40));
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(8));
m_sizer_body->Add(m_sizer_button, 0, wxRIGHT | wxEXPAND, FromDIP(25));
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(10));
m_sizer_body->Layout();
switch_input_panel(0);
SetSizer(m_sizer_body);
Layout();
Fit();
@ -1687,7 +1744,7 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
closeTimer->SetOwner(this);
Bind(wxEVT_TIMER, &InputIpAddressDialog::OnTimer, this);
Bind(EVT_CHECK_IP_ADDRESS_FAILED, &InputIpAddressDialog::on_check_ip_address_failed, this);
//Bind(EVT_CHECK_IP_ADDRESS_FAILED, &InputIpAddressDialog::on_check_ip_address_failed, this);
Bind(EVT_CLOSE_IPADDRESS_DLG, [this](auto& e) {
m_status_bar->reset();
@ -1697,7 +1754,26 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
on_cancel();
closeTimer->Stop();
});
}
void InputIpAddressDialog::switch_input_panel(int index)
{
if (index == 0) {
ip_input_top_panel->Show();
ip_input_bot_panel->Hide();
m_step_icon_panel3->Hide();
m_tip3->Hide();
} else {
ip_input_top_panel->Hide();
ip_input_bot_panel->Show();
m_step_icon_panel3->Show();
m_tip3->Show();
m_button_ok->Enable(false);
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
}
current_input_index = index;
}
void InputIpAddressDialog::on_cancel()
@ -1793,26 +1869,11 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
{
m_test_right_msg->Hide();
m_test_wrong_msg->Hide();
m_img_step3->Hide();
m_tip4->Hide();
m_trouble_shoot->Hide();
std::string str_ip = m_input_ip->GetTextCtrl()->GetValue().ToStdString();
std::string str_access_code = m_input_access_code->GetTextCtrl()->GetValue().ToStdString();
//check support function
/*if (!m_obj) return;
if (!m_obj->is_support_send_to_sdcard) {
wxString input_str = wxString::Format("%s|%s", ip, str_access_code);
auto event = wxCommandEvent(EVT_ENTER_IP_ADDRESS);
event.SetString(input_str);
event.SetEventObject(this);
wxPostEvent(this, event);
auto event_close = wxCommandEvent(EVT_CLOSE_IPADDRESS_DLG);
event_close.SetEventObject(this);
wxPostEvent(this, event_close);
return;
}*/
std::string str_sn = m_input_sn->GetTextCtrl()->GetValue().ToStdString();
std::string str_model_id = m_input_modelID->GetStringSelection().ToStdString();
m_button_ok->Enable(false);
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
@ -1822,14 +1883,24 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
Layout();
Fit();
m_thread = new boost::thread(boost::bind(&InputIpAddressDialog::workerThreadFunc, this, str_ip, str_access_code));
m_thread = new boost::thread(boost::bind(&InputIpAddressDialog::workerThreadFunc, this, str_ip, str_access_code, str_sn, str_model_id));
}
void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_access_code)
void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_access_code, std::string sn, std::string model_id)
{
update_test_msg(_L("connecting..."), true);
detectResult detectData;
auto result = wxGetApp().getAgent()->bind_detect(str_ip, "secure", detectData);
auto result = -1;
if (current_input_index == 0) {
result = wxGetApp().getAgent()->bind_detect(str_ip, "secure", detectData);
} else {
result = 0;
detectData.dev_name = sn;
detectData.dev_id = sn;
detectData.connect_type = "lan";
detectData.connect_type = "free";
}
if (result < 0) {
update_test_msg(wxEmptyString, true);
@ -1840,17 +1911,17 @@ void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_
update_test_msg(_L("Failed to publish login request."), false);
}
else if (result == -3) {
update_test_msg(_L("The device does not support using IP and Access Code for connection."), false);
switch_input_panel(1);
//update_test_msg(_L("The device does not support using IP and Access Code for connection."), false);
}
m_button_ok->Enable(true);
m_button_ok->Enable(true);
/*m_button_ok->Enable(true);
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered),
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
m_button_ok->SetTextColor(StateColor::darkModeColorFor("#FFFFFE"));
m_button_ok->SetBackgroundColor(btn_bg_green);
m_button_ok->SetBorderColor(*wxWHITE);
m_button_ok->SetBorderColor(*wxWHITE);*/
Layout();
Fit();
@ -1922,8 +1993,6 @@ void InputIpAddressDialog::on_check_ip_address_failed(wxCommandEvent& evt)
}
else {
update_test_msg(_L("Connection failed! If your IP and Access Code is correct, \nplease move to step 3 for troubleshooting network issues"), false);
m_img_step3->Show();
m_tip4->Show();
//m_trouble_shoot->Show();
Layout();
Fit();
@ -1936,10 +2005,11 @@ void InputIpAddressDialog::on_check_ip_address_failed(wxCommandEvent& evt)
m_button_ok->SetBackgroundColor(btn_bg_green);
}
void InputIpAddressDialog::on_text(wxCommandEvent& evt)
void InputIpAddressDialog::on_text(wxCommandEvent &evt)
{
auto str_ip = m_input_ip->GetTextCtrl()->GetValue();
auto str_access_code = m_input_access_code->GetTextCtrl()->GetValue();
auto str_ip = m_input_ip->GetTextCtrl()->GetValue();
auto str_access_code = m_input_access_code->GetTextCtrl()->GetValue();
auto str_sn = m_input_sn->GetTextCtrl()->GetValue();
bool invalid_access_code = true;
for (char c : str_access_code) {
@ -1952,15 +2022,28 @@ void InputIpAddressDialog::on_text(wxCommandEvent& evt)
if (isIp(str_ip.ToStdString()) && str_access_code.Length() == 8 && invalid_access_code) {
m_button_ok->Enable(true);
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(0, 137, 123), StateColor::Pressed), std::pair<wxColour, int>(wxColour(38, 166, 154), StateColor::Hovered),
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
m_button_ok->SetTextColor(StateColor::darkModeColorFor("#FFFFFE"));
m_button_ok->SetBackgroundColor(btn_bg_green);
}
else {
} else {
m_button_ok->Enable(false);
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
}
if (current_input_index == 1){
if (str_sn.length() == 15) {
m_button_ok->Enable(true);
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered),
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
m_button_ok->SetTextColor(StateColor::darkModeColorFor("#FFFFFE"));
m_button_ok->SetBackgroundColor(btn_bg_green);
} else {
m_button_ok->Enable(false);
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
}
}
}
InputIpAddressDialog::~InputIpAddressDialog()

View file

@ -275,10 +275,12 @@ class InputIpAddressDialog : public DPIDialog
public:
wxString comfirm_before_enter_text;
wxString comfirm_after_enter_text;
wxString comfirm_last_enter_text;
boost::thread* m_thread{nullptr};
std::string m_ip;
wxWindow* m_step_icon_panel3{ nullptr };
Label* m_tip1{ nullptr };
Label* m_tip2{ nullptr };
Label* m_tip3{ nullptr };
@ -287,13 +289,19 @@ public:
~InputIpAddressDialog();
MachineObject* m_obj{nullptr};
wxPanel * ip_input_top_panel{ nullptr };
wxPanel * ip_input_bot_panel{ nullptr };
Button* m_button_ok{ nullptr };
Label* m_tips_ip{ nullptr };
Label* m_tips_access_code{ nullptr };
Label* m_tips_sn{nullptr};
Label* m_tips_modelID{nullptr};
Label* m_test_right_msg{ nullptr };
Label* m_test_wrong_msg{ nullptr };
TextInput* m_input_ip{ nullptr };
TextInput* m_input_access_code{ nullptr };
TextInput* m_input_sn{ nullptr };
ComboBox* m_input_modelID{ nullptr };
wxStaticBitmap* m_img_help{ nullptr };
wxStaticBitmap* m_img_step1{ nullptr };
wxStaticBitmap* m_img_step2{ nullptr };
@ -303,8 +311,10 @@ public:
int closeCount{3};
bool m_show_access_code{ false };
int m_result;
int current_input_index {0};
std::shared_ptr<BBLStatusBarSend> m_status_bar;
void switch_input_panel(int index);
void on_cancel();
void update_title(wxString title);
void set_machine_obj(MachineObject* obj);
@ -313,7 +323,7 @@ public:
void check_ip_address_failed(int result);
void on_check_ip_address_failed(wxCommandEvent& evt);
void on_ok(wxMouseEvent& evt);
void workerThreadFunc(std::string str_ip, std::string str_access_code);
void workerThreadFunc(std::string str_ip, std::string str_access_code, std::string sn, std::string model_id);
void OnTimer(wxTimerEvent& event);
void on_text(wxCommandEvent& evt);
void on_dpi_changed(const wxRect& suggested_rect) override;