From 00718edfa7b4b6e1c09d392ae3107c75edce38b6 Mon Sep 17 00:00:00 2001 From: sunsets <845944018@qq.com> Date: Wed, 20 Mar 2024 10:08:22 +0800 Subject: [PATCH] print_host --- src/slic3r/GUI/MainFrame.cpp | 24 ++++----- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 8 --- src/slic3r/GUI/PrinterWebView.cpp | 63 ++++++++++++++---------- src/slic3r/GUI/PrinterWebView.hpp | 2 +- 4 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index eb6e7ce..e030107 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -59,6 +59,8 @@ #include #include +//B55 +#include "../Utils/PrintHost.hpp" namespace Slic3r { namespace GUI { @@ -2147,16 +2149,6 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) if (isValidIPAddress) { m_printer_view->AddButton( printer_name, host, (data->model_id), (data->fullname), - [host, this](wxMouseEvent &event) { - //B55 - wxString formattedHost = host; - //wxString formattedHost = wxString::Format("http://%s", host); - if (!host.Lower().starts_with("http")) - formattedHost = wxString::Format("http://%s", host); - //if (!formattedHost.Lower().ends_with("10088")) - // formattedHost = wxString::Format("%s:10088", formattedHost); - this->m_printer_view->load_url(formattedHost); - }, (data->selected), cfg_t); } } @@ -2177,14 +2169,18 @@ void MainFrame::select_tab(size_t tab/* = size_t(-1)*/) if (host.empty()) { tem_host = ""; host = wxString::Format("file://%s/web/qidi/missing_connection.html", from_u8(resources_dir())); - } + } else { //B55 - else { + const auto opt = cfg->option>("host_type"); + const auto host_type = opt != nullptr ? opt->value : htOctoPrint; if (!host.Lower().starts_with("http")) host = wxString::Format("http://%s", host); - // if (!host.Lower().ends_with("10088")) - // host = wxString::Format("%s:10088", host); + if (host_type == htMoonraker) { + if (!host.Lower().ends_with("10088")) + host = wxString::Format("%s:10088", host); + } } + //B55 if (tem_host != host) { //B45 m_printer_view->load_url(host); diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index cb38db5..6f91771 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -747,14 +747,6 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) Field * printhost_field = m_optgroup->get_field("print_host"); text_ctrl *printhost_win = printhost_field ? dynamic_cast(printhost_field->getWindow()) : nullptr; wxString temp_host = printhost_win->GetValue(); - //B55 - wxString formattedHost = temp_host; - /* if (!temp_host.Lower().starts_with("http")) - wxString formattedHost = wxString::Format("http://%s", temp_host);*/ - if (!formattedHost.Lower().ends_with("10088")) - formattedHost = wxString::Format("%s:10088", formattedHost); - m_optgroup->set_value("print_host", formattedHost, true); - m_optgroup->get_field("print_host")->field_changed(); } if (opt->value == htQIDIConnect) { if (printhost_win && printhost_win->GetValue() != L"https://connect.qidi3d.com"){ diff --git a/src/slic3r/GUI/PrinterWebView.cpp b/src/slic3r/GUI/PrinterWebView.cpp index 1f0bbce..823cae0 100644 --- a/src/slic3r/GUI/PrinterWebView.cpp +++ b/src/slic3r/GUI/PrinterWebView.cpp @@ -17,6 +17,8 @@ #include #include #include +//B55 +#include "../Utils/PrintHost.hpp" namespace pt = boost::property_tree; namespace Slic3r { @@ -331,11 +333,11 @@ PrinterWebView::PrinterWebView(wxWindow *parent) + //B55 void PrinterWebView::AddButton(const wxString & device_name, const wxString & ip, const wxString & machine_type, const wxString & fullname, - const std::function &handler, bool isSelected, DynamicPrintConfig * cfg_t) { @@ -356,16 +358,28 @@ void PrinterWebView::AddButton(const wxString & devi customButton->SetIPText(ip); customButton->SetStateText("standby"); customButton->SetProgressText("(0%)"); - customButton->SetClickHandler(handler); - //customButton->Bind(wxEVT_BUTTON, std::bind(&PrinterWebView::OnCustomButtonClick, this,handler)); - customButton->Bind(wxEVT_BUTTON, [this, ip, customButton](wxCommandEvent &event) { - wxString host = ip; + const auto opt = cfg_t->option>("host_type"); + const auto host_type = opt != nullptr ? opt->value : htOctoPrint; + wxString formattedHost = ip; + if (!formattedHost.Lower().starts_with("http")) + formattedHost = wxString::Format("http://%s", formattedHost); + if (host_type == htMoonraker) { + if (!formattedHost.Lower().ends_with("10088")) + formattedHost = wxString::Format("%s:10088", formattedHost); + } + + customButton->Bind(wxEVT_BUTTON, [this, ip, customButton, cfg_t](wxCommandEvent &event) { //B55 - if (!host.Lower().starts_with("http")) - host = wxString::Format("http://%s", host); - // if (!host.Lower().ends_with("10088")) - // host = wxString::Format("%s:10088", host); - load_url(host); + const auto opt = cfg_t->option>("host_type"); + const auto host_type = opt != nullptr ? opt->value : htOctoPrint; + wxString formattedHost = ip; + if (!formattedHost.Lower().starts_with("http")) + formattedHost = wxString::Format("http://%s", formattedHost); + if (host_type == htMoonraker) { + if (!formattedHost.Lower().ends_with("10088")) + formattedHost = wxString::Format("%s:10088", formattedHost); + } + load_url(formattedHost); customButton->ResumeStatusThread(); }); #if defined(__WIN32__) || defined(__WXMAC__) @@ -391,7 +405,6 @@ void PrinterWebView::AddButton(const wxString & devi //B45 void PrinterWebView::PauseButton() { - //BOOST_LOG_TRIVIAL(error) << " Pause"; if (m_buttons.empty()) { BOOST_LOG_TRIVIAL(info) << " empty"; @@ -404,7 +417,6 @@ void PrinterWebView::AddButton(const wxString & devi //B45 void PrinterWebView::ResumeButton() { - //BOOST_LOG_TRIVIAL(error) << " Resume"; if (m_buttons.empty()) { BOOST_LOG_TRIVIAL(info) << " empty"; @@ -418,7 +430,6 @@ void PrinterWebView::AddButton(const wxString & devi //B45 void PrinterWebView::StopAllThread() { - // BOOST_LOG_TRIVIAL(error) << " Stop"; if (m_buttons.empty()) { BOOST_LOG_TRIVIAL(info) << " empty"; @@ -432,7 +443,6 @@ void PrinterWebView::AddButton(const wxString & devi //B45 void PrinterWebView::UnSelectedButton() { - // BOOST_LOG_TRIVIAL(error) << " Resume"; if (m_buttons.empty()) { BOOST_LOG_TRIVIAL(info) << " empty"; @@ -529,6 +539,7 @@ void PrinterWebView::OnRightButtonClick(wxCommandEvent &event) Refresh(); } +//B55 void PrinterWebView::OnAddButtonClick(wxCommandEvent &event) { PhysicalPrinterDialog dlg(this->GetParent(), wxEmptyString); @@ -541,13 +552,6 @@ void PrinterWebView::OnAddButtonClick(wxCommandEvent &event) std::string printer_name = printer.name; wxString host = printer.config.opt_string("print_host"); - //B55 - wxString formattedHost = host; - // wxString formattedHost = wxString::Format("http://%s", host); - if (!host.Lower().starts_with("http")) - wxString formattedHost = wxString::Format("http://%s", host); - // if (!formattedHost.Lower().ends_with("10088")) - // formattedHost = wxString::Format("%s:10088", formattedHost); std::string fullname = preset_bundle.physical_printers.get_selected_full_printer_name(); std::string preset_name = printer.get_preset_name(fullname); @@ -565,14 +569,19 @@ void PrinterWebView::OnAddButtonClick(wxCommandEvent &event) bool isValidIPAddress = true; DynamicPrintConfig *cfg_t = &(printer.config); + const auto opt = cfg_t->option>("host_type"); + const auto host_type = opt != nullptr ? opt->value : htOctoPrint; + wxString formattedHost = host; + if (!formattedHost.Lower().starts_with("http")) + formattedHost = wxString::Format("http://%s", formattedHost); + if (host_type == htMoonraker) { + if (!formattedHost.Lower().ends_with("10088")) + formattedHost = wxString::Format("%s:10088", formattedHost); + } UnSelectedButton(); if (isValidIPAddress) AddButton( printer_name, host, model_id, fullname, - [formattedHost, this](wxMouseEvent &event) { - wxString host = formattedHost; - load_url(host); - }, true, cfg_t); load_url(formattedHost); UpdateLayout(); @@ -765,8 +774,10 @@ void PrinterWebView::load_url(wxString& url) m_browser->LoadURL(url); //B55 + if (url.Lower().starts_with("http")) url.Remove(0, 7); - //url.Remove(url.length() - 6); + if (url.Lower().ends_with("10088")) + url.Remove(url.length() - 6); for (MachineListButton *button : m_buttons) { if (url == (button->getIPLabel())) button->SetSelect(true); diff --git a/src/slic3r/GUI/PrinterWebView.hpp b/src/slic3r/GUI/PrinterWebView.hpp index 21c4e6f..172e5ac 100644 --- a/src/slic3r/GUI/PrinterWebView.hpp +++ b/src/slic3r/GUI/PrinterWebView.hpp @@ -257,11 +257,11 @@ public: //B45 //void SendRecentList(int images); void SetButtons(std::vector buttons); + //B55 void AddButton(const wxString & device_name, const wxString & ip, const wxString & machine_type, const wxString & fullname, - const std::function &handler, bool isSelected, DynamicPrintConfig * cfg_t); void DeleteButton();