mirror of
https://github.com/QIDITECH/QIDISlicer.git
synced 2026-01-30 23:48:44 +03:00
Optimize device connectivity, and fix some bug
This commit is contained in:
@@ -5111,14 +5111,16 @@ void Plater::priv::show_action_buttons(const bool ready_to_slice_) const
|
||||
DynamicPrintConfig* selected_printer_config = wxGetApp().preset_bundle->physical_printers.get_selected_printer_config();
|
||||
const auto print_host_opt = selected_printer_config ? selected_printer_config->option<ConfigOptionString>("print_host") : nullptr;
|
||||
const bool send_gcode_shown = print_host_opt != nullptr && !print_host_opt->value.empty();
|
||||
|
||||
|
||||
auto m_devices = wxGetApp().get_devices();
|
||||
const bool link_has_machine = m_devices.size() > 0;
|
||||
|
||||
// when a background processing is ON, export_btn and/or send_btn are showing
|
||||
if (get_config_bool("background_processing"))
|
||||
{
|
||||
RemovableDriveManager::RemovableDrivesStatus removable_media_status = wxGetApp().removable_drive_manager()->status();
|
||||
if (sidebar->show_reslice(false) |
|
||||
sidebar->show_export(true) |
|
||||
sidebar->show_send(send_gcode_shown) |
|
||||
sidebar->show_export(true) | sidebar->show_send(send_gcode_shown | link_has_machine) |
|
||||
sidebar->show_export_removable(removable_media_status.has_removable_drives))
|
||||
// sidebar->show_eject(removable_media_status.has_eject))
|
||||
sidebar->Layout();
|
||||
@@ -5130,7 +5132,7 @@ void Plater::priv::show_action_buttons(const bool ready_to_slice_) const
|
||||
removable_media_status = wxGetApp().removable_drive_manager()->status();
|
||||
if (sidebar->show_reslice(ready_to_slice) |
|
||||
sidebar->show_export(!ready_to_slice) |
|
||||
sidebar->show_send(send_gcode_shown && !ready_to_slice) |
|
||||
sidebar->show_send((send_gcode_shown | link_has_machine) && !ready_to_slice) |
|
||||
sidebar->show_export_removable(!ready_to_slice && removable_media_status.has_removable_drives))
|
||||
// sidebar->show_eject(!ready_to_slice && removable_media_status.has_eject))
|
||||
sidebar->Layout();
|
||||
@@ -8011,11 +8013,10 @@ void Plater::send_gcode()
|
||||
{
|
||||
// if physical_printer is selected, send gcode for this printer
|
||||
DynamicPrintConfig* physical_printer_config = wxGetApp().preset_bundle->physical_printers.get_selected_printer_config();
|
||||
if (! physical_printer_config || p->model.objects.empty())
|
||||
return;
|
||||
auto m_devices = wxGetApp().get_devices();
|
||||
const bool link_has_machine = m_devices.size() > 0;
|
||||
|
||||
PrintHostJob upload_job(physical_printer_config);
|
||||
if (upload_job.empty())
|
||||
if ((!physical_printer_config && !link_has_machine) || p->model.objects.empty())
|
||||
return;
|
||||
|
||||
// Obtain default output path
|
||||
@@ -8039,25 +8040,30 @@ void Plater::send_gcode()
|
||||
|
||||
// Repetier specific: Query the server for the list of file groups.
|
||||
wxArrayString groups;
|
||||
{
|
||||
wxBusyCursor wait;
|
||||
upload_job.printhost->get_groups(groups);
|
||||
}
|
||||
// QIDILink specific: Query the server for the list of file groups.
|
||||
wxArrayString storage_paths;
|
||||
wxArrayString storage_names;
|
||||
{
|
||||
bool only_link = false;
|
||||
if (physical_printer_config) {
|
||||
PrintHostJob upload_job(physical_printer_config);
|
||||
if (upload_job.empty())
|
||||
return;
|
||||
wxBusyCursor wait;
|
||||
upload_job.printhost->get_groups(groups);
|
||||
|
||||
try {
|
||||
upload_job.printhost->get_storage(storage_paths, storage_names);
|
||||
} catch (const Slic3r::IOError& ex) {
|
||||
} catch (const Slic3r::IOError &ex) {
|
||||
show_error(this, ex.what(), false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
only_link = true;
|
||||
}
|
||||
|
||||
//B61
|
||||
PrintHostSendDialog dlg(default_output_file, upload_job.printhost->get_post_upload_actions(), groups, storage_paths, storage_names,
|
||||
this, (this->fff_print().print_statistics()));
|
||||
PrintHostSendDialog dlg(default_output_file, PrintHostPostUploadAction::StartPrint, groups, storage_paths, storage_names, this,
|
||||
(this->fff_print().print_statistics()), only_link);
|
||||
|
||||
if (dlg.ShowModal() == wxID_OK) {
|
||||
if (printer_technology() == ptFFF) {
|
||||
|
||||
@@ -46,7 +46,8 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path & path,
|
||||
const wxArrayString & storage_paths,
|
||||
const wxArrayString & storage_names,
|
||||
Plater * plater,
|
||||
const PrintStatistics & ps)
|
||||
const PrintStatistics & ps,
|
||||
bool onlylink)
|
||||
: MsgDialog(static_cast<wxWindow *>(wxGetApp().mainframe),
|
||||
_L("Send G-Code to printer host"),
|
||||
_L(""),
|
||||
@@ -196,9 +197,15 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path & path,
|
||||
}
|
||||
}
|
||||
//y4
|
||||
PhysicalPrinter selected_printer = ph_printers.get_selected_printer();
|
||||
std::set<std::string> selected_printer_presets = selected_printer.get_preset_names();
|
||||
std::string printer_preset = *selected_printer_presets.begin();
|
||||
std::string printer_preset = "";
|
||||
if (!onlylink) {
|
||||
PhysicalPrinter selected_printer = ph_printers.get_selected_printer();
|
||||
std::set<std::string> selected_printer_presets = selected_printer.get_preset_names();
|
||||
printer_preset = *selected_printer_presets.begin();
|
||||
} else {
|
||||
Preset &select_preset = preset_bundle.printers.get_edited_preset();
|
||||
printer_preset = select_preset.name;
|
||||
}
|
||||
m_presetData = preset_data;
|
||||
for (const PhysicalPrinterPresetData &data : preset_data) {
|
||||
//y4
|
||||
@@ -939,20 +946,20 @@ void PrintHostQueueDialog::on_error(Event &evt)
|
||||
wxCHECK_RET(evt.job_id < (size_t)job_list->GetItemCount(), "Out of bounds access to job list");
|
||||
|
||||
set_state(evt.job_id, ST_ERROR);
|
||||
// y1
|
||||
std::string response_msg = into_u8(evt.status);
|
||||
size_t pos_404 = evt.status.find("HTTP 404:");
|
||||
wxString code_msg = "";
|
||||
if (pos_404 != std::string::npos) {
|
||||
code_msg = _L("Network connection fails.");
|
||||
if (response_msg.find("HTTP 404:") != std::string::npos) {
|
||||
size_t isAws = response_msg.find("AWS");
|
||||
if(isAws != std::string::npos)
|
||||
code_msg += _L("Unable to get required resources from AWS server, please check your network settings.");
|
||||
code_msg = _L("HTTP 404. Unable to get required resources from AWS server, please check your network settings.");
|
||||
else
|
||||
code_msg += _L("Unable to get required resources from Aliyun server, please check your network settings.");
|
||||
code_msg = _L("HTTP 404. Unable to get required resources from Aliyun server, please check your network settings.");
|
||||
}
|
||||
else if (response_msg.find("HTTP 401:") != std::string::npos)
|
||||
code_msg = _L("HTTP 401: Unauthorized. Please check whether your physical printer has added users. If a user exists, add the "
|
||||
"APIKEY when adding/editing the printer.");
|
||||
else
|
||||
code_msg = _L("Network connection times out. Please check the device network Settings.");
|
||||
code_msg = response_msg;
|
||||
|
||||
auto errormsg = format_wxstr("%1%\n%2%", _L("Error uploading to print host") + ":", code_msg);
|
||||
job_list->SetValue(wxVariant(0), evt.job_id, COL_PROGRESS);
|
||||
|
||||
@@ -66,7 +66,8 @@ public:
|
||||
const wxArrayString & storage_paths,
|
||||
const wxArrayString & storage_names,
|
||||
Plater * plater,
|
||||
const PrintStatistics & ps);
|
||||
const PrintStatistics & ps,
|
||||
bool onlyLik);
|
||||
boost::filesystem::path filename() const;
|
||||
PrintHostPostUploadAction post_action() const;
|
||||
std::string group() const;
|
||||
|
||||
@@ -281,9 +281,13 @@ void PrinterWebView::CreatThread() {
|
||||
if (m_pauseThread)
|
||||
break;
|
||||
|
||||
|
||||
DynamicPrintConfig cfg_t;
|
||||
cfg_t.set_key_value("print_host", new ConfigOptionString(into_u8(button->getIPLabel())));
|
||||
cfg_t.set_key_value("printhost_apikey", new ConfigOptionString(into_u8(button->GetApikey())));
|
||||
cfg_t.set_key_value("printhost_cafile", new ConfigOptionString(""));
|
||||
cfg_t.set_key_value("printhost_ssl_ignore_revoke", new ConfigOptionBool(false));
|
||||
std::unique_ptr<PrintHost> printhost(
|
||||
PrintHost::get_print_host_url((button->getIPLabel()).ToStdString(), (button->getIPLabel()).ToStdString()));
|
||||
PrintHost::get_print_host(&cfg_t));
|
||||
if (!printhost) {
|
||||
BOOST_LOG_TRIVIAL(error) << ("Could not get a valid Printer Host reference");
|
||||
return;
|
||||
@@ -291,13 +295,15 @@ void PrinterWebView::CreatThread() {
|
||||
wxString msg;
|
||||
std::string state = "standby";
|
||||
float progress = 0;
|
||||
state = printhost->get_status(msg);
|
||||
std::pair<std::string, float> state_progress = printhost->get_status_progress(msg);
|
||||
|
||||
state = state_progress.first;
|
||||
|
||||
if ((button->GetStateText()).ToStdString() != state)
|
||||
button->SetStateText(state);
|
||||
|
||||
if (state == "printing") {
|
||||
progress = (printhost->get_progress(msg)) * 100;
|
||||
progress = state_progress.second * 100;
|
||||
int progressInt = static_cast<int>(progress);
|
||||
button->SetProgressText(wxString::Format(wxT("(%d%%)"), progressInt));
|
||||
}
|
||||
@@ -321,13 +327,14 @@ void PrinterWebView::CreatThread() {
|
||||
wxString msg;
|
||||
std::string state = "standby";
|
||||
float progress = 0;
|
||||
state = printhost->get_status(msg);
|
||||
std::pair<std::string, float> state_progress = printhost->get_status_progress(msg);
|
||||
state = state_progress.first;
|
||||
|
||||
if ((m_net_buttons[count]->GetStateText()).ToStdString() != state)
|
||||
m_net_buttons[count]->SetStateText(state);
|
||||
|
||||
if (state == "printing") {
|
||||
progress = (printhost->get_progress(msg)) * 100;
|
||||
progress = state_progress.second * 100;
|
||||
int progressInt = static_cast<int>(progress);
|
||||
m_net_buttons[count]->SetProgressText(wxString::Format(wxT("(%d%%)"), progressInt));
|
||||
}
|
||||
@@ -355,6 +362,7 @@ void PrinterWebView::SetPresetChanged(bool status) {
|
||||
PhysicalPrinterCollection &ph_printers = preset_bundle.physical_printers;
|
||||
for (PhysicalPrinterCollection::ConstIterator it = ph_printers.begin(); it != ph_printers.end(); ++it) {
|
||||
std::string host = (it->config.opt_string("print_host"));
|
||||
wxString apikey = from_u8(it->config.opt_string("printhost_apikey"));
|
||||
for (const std::string &preset_name : it->get_preset_names()) {
|
||||
Preset * preset = wxGetApp().preset_bundle->printers.find_preset(preset_name);
|
||||
std::string full_name = it->get_full_name(preset_name);
|
||||
@@ -385,8 +393,7 @@ void PrinterWebView::SetPresetChanged(bool status) {
|
||||
//BOOST_LOG_TRIVIAL(error) << (it->get_short_name(full_name));
|
||||
//BOOST_LOG_TRIVIAL(error) << (it->get_preset_name(full_name));
|
||||
//BOOST_LOG_TRIVIAL(error) << model_id;
|
||||
AddButton((it->get_short_name(full_name)), host, model_id, full_name, is_selected,
|
||||
(host_type == htMoonraker));
|
||||
AddButton((it->get_short_name(full_name)), host, model_id, full_name, is_selected, (host_type == htMoonraker), apikey);
|
||||
m_exit_host.insert(host);
|
||||
}
|
||||
}
|
||||
@@ -399,47 +406,42 @@ void PrinterWebView::SetPresetChanged(bool status) {
|
||||
AddNetButton(device);
|
||||
}
|
||||
#endif
|
||||
if (m_isNetMode)
|
||||
ShowNetPrinterButton();
|
||||
else
|
||||
ShowLocalPrinterButton();
|
||||
//y3
|
||||
if (webisNetMode == isNetWeb) {
|
||||
ShowNetPrinterButton();
|
||||
for (DeviceButton* button : m_net_buttons) {
|
||||
if (m_ip == (button->getIPLabel())) {
|
||||
button->SetIsSelected(true);
|
||||
wxCommandEvent event(wxEVT_BUTTON, button->GetId());
|
||||
wxPostEvent(button, event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
toggleBar->SetValue(true);
|
||||
m_isNetMode = true;
|
||||
} else if (webisNetMode == isLocalWeb) {
|
||||
ShowLocalPrinterButton();
|
||||
}
|
||||
else if (webisNetMode == isLocalWeb)
|
||||
{
|
||||
if (m_exit_host.find(into_u8(m_ip)) != m_exit_host.end())
|
||||
{
|
||||
for (DeviceButton* button : m_buttons) {
|
||||
if (m_ip == (button->getIPLabel())) {
|
||||
for (DeviceButton* button : m_buttons)
|
||||
{
|
||||
if (m_ip == (button->getIPLabel()))
|
||||
{
|
||||
button->SetIsSelected(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
toggleBar->SetValue(false);
|
||||
m_isNetMode = false;
|
||||
} else {
|
||||
wxString m_host = wxString::Format("file://%s/web/qidi/missing_connection.html", from_u8(resources_dir()));
|
||||
load_disconnect_url(m_host);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_isNetMode)
|
||||
{
|
||||
ShowNetPrinterButton();
|
||||
wxString m_host = wxString::Format("file://%s/web/qidi/link_missing_connection.html", from_u8(resources_dir()));
|
||||
load_disconnect_url(m_host);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowLocalPrinterButton();
|
||||
wxString m_host = wxString::Format("file://%s/web/qidi/missing_connection.html", from_u8(resources_dir()));
|
||||
load_disconnect_url(m_host);
|
||||
}
|
||||
@@ -501,7 +503,8 @@ void PrinterWebView::AddButton(const wxString & device_name,
|
||||
const wxString & machine_type,
|
||||
const wxString & fullname,
|
||||
bool isSelected,
|
||||
bool isQIDI)
|
||||
bool isQIDI,
|
||||
const wxString & apikey)
|
||||
{
|
||||
wxString Machine_Name = Machine_Name.Format("%s%s", machine_type, "_thumbnail");
|
||||
|
||||
@@ -509,7 +512,7 @@ void PrinterWebView::AddButton(const wxString & device_name,
|
||||
std::pair<wxColour, int>(wxColour(76, 76, 80), StateColor::Hovered),
|
||||
std::pair<wxColour, int>(wxColour(67, 67, 71), StateColor::Normal));
|
||||
|
||||
DeviceButton *machine_button = new DeviceButton(leftScrolledWindow, fullname, Machine_Name, wxBU_LEFT, wxSize(80, 80), device_name, ip);
|
||||
DeviceButton *machine_button = new DeviceButton(leftScrolledWindow, fullname, Machine_Name, wxBU_LEFT, wxSize(80, 80), device_name, ip, apikey);
|
||||
machine_button->SetBackgroundColor(mac_btn_bg);
|
||||
machine_button->SetBorderColor(wxColour(67, 67, 71));
|
||||
machine_button->SetCanFocus(false);
|
||||
@@ -607,23 +610,32 @@ void PrinterWebView::AddNetButton(const Device device)
|
||||
machine_button->Bind(wxEVT_BUTTON, [this, device](wxCommandEvent &event) {
|
||||
//y5
|
||||
std::string formattedHost;
|
||||
if (wxGetApp().app_config->get("dark_color_mode") == "1")
|
||||
formattedHost = device.link_url + "&theme=dark";
|
||||
else
|
||||
formattedHost = device.link_url + "&theme=light";
|
||||
|
||||
std::string formattedHost1 = "http://fluidd_" + formattedHost;
|
||||
std::string formattedHost2 = "http://fluidd2_" + formattedHost;
|
||||
if (formattedHost1 == m_web || formattedHost2 == m_web)
|
||||
return;
|
||||
if (device.isSpecialMachine)
|
||||
{
|
||||
if (wxGetApp().app_config->get("dark_color_mode") == "1")
|
||||
formattedHost = device.link_url + "&theme=dark";
|
||||
else
|
||||
formattedHost = device.link_url + "&theme=light";
|
||||
|
||||
if (m_isfluidd_1) {
|
||||
formattedHost = "http://fluidd_" + formattedHost;
|
||||
m_isfluidd_1 = false;
|
||||
} else {
|
||||
formattedHost = "http://fluidd2_" + formattedHost;
|
||||
m_isfluidd_1 = true;
|
||||
std::string formattedHost1 = "http://fluidd_" + formattedHost;
|
||||
std::string formattedHost2 = "http://fluidd2_" + formattedHost;
|
||||
if (formattedHost1 == m_web || formattedHost2 == m_web)
|
||||
return;
|
||||
|
||||
if (m_isfluidd_1) {
|
||||
formattedHost = "http://fluidd_" + formattedHost;
|
||||
m_isfluidd_1 = false;
|
||||
} else {
|
||||
formattedHost = "http://fluidd2_" + formattedHost;
|
||||
m_isfluidd_1 = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
formattedHost = "http://" + device.link_url;
|
||||
}
|
||||
|
||||
load_net_url(formattedHost, device.local_ip);
|
||||
});
|
||||
|
||||
@@ -1056,7 +1068,7 @@ void PrinterWebView::load_url(wxString &url)
|
||||
}
|
||||
|
||||
for (DeviceButton *button : m_buttons) {
|
||||
if (url == (button->getIPLabel()))
|
||||
if ((button->getIPLabel()).find(m_ip) != std::string::npos)
|
||||
button->SetIsSelected(true);
|
||||
else
|
||||
button->SetIsSelected(false);
|
||||
|
||||
@@ -94,7 +94,8 @@ public:
|
||||
const wxString & machine_type,
|
||||
const wxString & fullname,
|
||||
bool isSelected,
|
||||
bool isQIDI);
|
||||
bool isQIDI,
|
||||
const wxString & apikey);
|
||||
void DeleteButton();
|
||||
void UnSelectedButton();
|
||||
void ShowNetPrinterButton();
|
||||
|
||||
@@ -23,7 +23,7 @@ END_EVENT_TABLE()
|
||||
* calling Refresh()/Update().
|
||||
*/
|
||||
|
||||
DeviceButton::DeviceButton(wxString name_text, wxString ip_text) : paddingSize(10, 8), m_name_text(name_text), m_ip_text(ip_text)
|
||||
DeviceButton::DeviceButton(wxString name_text, wxString ip_text, wxString api_text) : paddingSize(10, 8), m_name_text(name_text), m_ip_text(ip_text), m_apikey(api_text)
|
||||
{
|
||||
background_color = StateColor(
|
||||
std::make_pair(0x262629, (int) StateColor::Disabled),
|
||||
@@ -37,13 +37,14 @@ DeviceButton::DeviceButton(wxString name_text, wxString ip_text) : paddingSize(1
|
||||
}
|
||||
|
||||
DeviceButton::DeviceButton(wxWindow *parent,
|
||||
wxString text,
|
||||
wxString icon,
|
||||
long style,
|
||||
wxSize iconSize /* = wxSize(16, 16)*/,
|
||||
wxString name_text,
|
||||
wxString ip_text)
|
||||
: DeviceButton(name_text,ip_text)
|
||||
wxString text,
|
||||
wxString icon,
|
||||
long style,
|
||||
wxSize iconSize /* = wxSize(16, 16)*/,
|
||||
wxString name_text,
|
||||
wxString ip_text,
|
||||
wxString api_text)
|
||||
: DeviceButton(name_text,ip_text, api_text)
|
||||
{
|
||||
m_icon_text = icon;
|
||||
Create(parent, text, icon, style, iconSize);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../wxExtensions.hpp"
|
||||
#include "StaticBox.hpp"
|
||||
|
||||
|
||||
class DeviceButton : public StaticBox
|
||||
{
|
||||
wxSize textSize;
|
||||
@@ -22,7 +23,7 @@ class DeviceButton : public StaticBox
|
||||
static const int buttonHeight = 50;
|
||||
|
||||
public:
|
||||
DeviceButton(wxString name_text, wxString ip_text);
|
||||
DeviceButton(wxString name_text, wxString ip_text, wxString api_text);
|
||||
|
||||
DeviceButton(wxWindow *parent,
|
||||
wxString text,
|
||||
@@ -30,7 +31,8 @@ public:
|
||||
long style = 0,
|
||||
wxSize iconSize = wxSize(16, 16),
|
||||
wxString name_text = "",
|
||||
wxString ip_text = "");
|
||||
wxString ip_text = "",
|
||||
wxString api_text = "");
|
||||
//y3
|
||||
DeviceButton(wxWindow *parent, wxString icon, long style);
|
||||
|
||||
@@ -76,6 +78,7 @@ public:
|
||||
|
||||
wxString GetStateText() { return m_state_text; }
|
||||
|
||||
wxString GetApikey() { return m_apikey; };
|
||||
|
||||
void Rescale();
|
||||
|
||||
@@ -108,6 +111,7 @@ private:
|
||||
wxString m_progress_text = "(0%)";
|
||||
bool m_isSimpleMode = true;
|
||||
bool m_isSelected = false;
|
||||
wxString m_apikey;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
//B45
|
||||
virtual std::string get_status(wxString &curl_msg) const override { return "1"; };
|
||||
virtual float get_progress(wxString &curl_msg) const override { return 1; };
|
||||
virtual std::pair<std::string, float> get_status_progress(wxString &curl_msg) const override { return std::make_pair("1", 1); };
|
||||
|
||||
wxString get_test_ok_msg () const override;
|
||||
wxString get_test_failed_msg (wxString &msg) const override;
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
//B45
|
||||
virtual std::string get_status(wxString &curl_msg) const override { return "1"; };
|
||||
virtual float get_progress(wxString &curl_msg) const override { return 1; };
|
||||
virtual std::pair<std::string, float> get_status_progress(wxString &curl_msg) const override { return std::make_pair("1", 1); };
|
||||
|
||||
wxString get_test_ok_msg() const override;
|
||||
wxString get_test_failed_msg(wxString &msg) const override;
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
//B45
|
||||
virtual std::string get_status(wxString &curl_msg) const override { return "1"; };
|
||||
virtual float get_progress(wxString &curl_msg) const override { return 1; };
|
||||
virtual std::pair<std::string, float> get_status_progress(wxString &curl_msg) const override { return std::make_pair("1", 1); };
|
||||
|
||||
wxString get_test_ok_msg() const override;
|
||||
wxString get_test_failed_msg(wxString &msg) const override;
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
//B45
|
||||
virtual std::string get_status(wxString &curl_msg) const override { return "1"; };
|
||||
virtual float get_progress(wxString &curl_msg) const override { return 1; };
|
||||
virtual std::pair<std::string, float> get_status_progress(wxString &curl_msg) const override { return std::make_pair("1", 1); };
|
||||
|
||||
wxString get_test_ok_msg() const override;
|
||||
wxString get_test_failed_msg(wxString& msg) const override;
|
||||
|
||||
@@ -294,6 +294,82 @@ float Moonraker::get_progress(wxString &msg) const
|
||||
return process;
|
||||
}
|
||||
|
||||
std::pair<std::string, float> Moonraker::get_status_progress(wxString &msg) const
|
||||
{
|
||||
// GET /server/info
|
||||
|
||||
// Since the request is performed synchronously here,
|
||||
// it is ok to refer to `msg` from within the closure
|
||||
const char *name = get_name();
|
||||
|
||||
bool res = true;
|
||||
std::string print_state = "standby";
|
||||
float process = 0;
|
||||
auto url = make_url("printer/objects/query?print_stats=state&display_status=progress");
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Get version at: %2%") % name % url;
|
||||
|
||||
auto http = Http::get(std::move(url));
|
||||
set_auth(http);
|
||||
// B64 //y6
|
||||
http.timeout_connect(4)
|
||||
.on_error([&](std::string body, std::string error, unsigned status) {
|
||||
// y1
|
||||
if (status == 404) {
|
||||
body = ("Network connection fails.");
|
||||
if (body.find("AWS") != std::string::npos)
|
||||
body += ("Unable to get required resources from AWS server, please check your network settings.");
|
||||
else
|
||||
body += ("Unable to get required resources from Aliyun server, please check your network settings.");
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status %
|
||||
body;
|
||||
print_state = "offline";
|
||||
msg = format_error(body, error, status);
|
||||
})
|
||||
.on_complete([&](std::string body, unsigned) {
|
||||
BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got print_stats and process: %2%") % name % body;
|
||||
try {
|
||||
// All successful HTTP requests will return a json encoded object in the form of :
|
||||
// {result: <response data>}
|
||||
std::stringstream ss(body);
|
||||
pt::ptree ptree;
|
||||
pt::read_json(ss, ptree);
|
||||
if (ptree.front().first != "result") {
|
||||
msg = "Could not parse server response";
|
||||
print_state = "offline";
|
||||
process = 0;
|
||||
return;
|
||||
}
|
||||
if (!ptree.front().second.get_optional<std::string>("status")) {
|
||||
msg = "Could not parse server response";
|
||||
print_state = "offline";
|
||||
process = 0;
|
||||
return;
|
||||
}
|
||||
print_state = ptree.get<std::string>("result.status.print_stats.state");
|
||||
process = std::stof(ptree.get<std::string>("result.status.display_status.progress"));
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Got state: %2%") % name % print_state;
|
||||
;
|
||||
} catch (const std::exception &) {
|
||||
print_state = "offline";
|
||||
process = 0;
|
||||
msg = "Could not parse server response";
|
||||
}
|
||||
})
|
||||
#ifdef _WIN32
|
||||
.ssl_revoke_best_effort(m_ssl_revoke_best_effort)
|
||||
.on_ip_resolve([&](std::string address) {
|
||||
// Workaround for Windows 10/11 mDNS resolve issue, where two mDNS resolves in succession fail.
|
||||
// Remember resolved address to be reused at successive REST API call.
|
||||
msg = GUI::from_u8(address);
|
||||
})
|
||||
#endif // _WIN32
|
||||
.perform_sync();
|
||||
|
||||
return std::make_pair(print_state, process);
|
||||
}
|
||||
|
||||
bool Moonraker::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const
|
||||
{
|
||||
// POST /server/files/upload
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
//B45
|
||||
virtual std::string get_status(wxString &curl_msg) const override;
|
||||
virtual float get_progress(wxString &curl_msg) const override;
|
||||
virtual std::pair<std::string, float> get_status_progress(wxString &curl_msg) const override;
|
||||
|
||||
wxString get_test_ok_msg () const override;
|
||||
wxString get_test_failed_msg (wxString &msg) const override;
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
//B45
|
||||
virtual std::string get_status(wxString &curl_msg) const override { return "1"; };
|
||||
virtual float get_progress(wxString &curl_msg) const override { return 1; };
|
||||
virtual std::pair<std::string, float> get_status_progress(wxString &curl_msg) const override { return std::make_pair("1", 1); };
|
||||
|
||||
wxString get_test_ok_msg () const override;
|
||||
wxString get_test_failed_msg (wxString &msg) const override;
|
||||
|
||||
@@ -46,7 +46,7 @@ PrintHost* PrintHost::get_print_host(DynamicPrintConfig *config)
|
||||
|
||||
if (tech == ptFFF) {
|
||||
const auto opt = config->option<ConfigOptionEnum<PrintHostType>>("host_type");
|
||||
const auto host_type = opt != nullptr ? opt->value : htOctoPrint;
|
||||
const auto host_type = opt != nullptr ? opt->value : htMoonraker;
|
||||
|
||||
//B55
|
||||
switch (host_type) {
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
//B45
|
||||
virtual std::string get_status(wxString &curl_msg) const = 0;
|
||||
virtual float get_progress(wxString &curl_msg) const = 0;
|
||||
virtual std::pair<std::string, float> get_status_progress(wxString &curl_msg) const = 0;
|
||||
virtual wxString get_test_ok_msg () const = 0;
|
||||
virtual wxString get_test_failed_msg (wxString &msg) const = 0;
|
||||
virtual bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const = 0;
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
//B45
|
||||
virtual std::string get_status(wxString &curl_msg) const override { return "1"; };
|
||||
virtual float get_progress(wxString &curl_msg) const override { return 1; };
|
||||
virtual std::pair<std::string, float> get_status_progress(wxString &curl_msg) const override { return std::make_pair("1", 1); };
|
||||
wxString get_test_ok_msg () const override;
|
||||
wxString get_test_failed_msg (wxString &msg) const override;
|
||||
bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const override;
|
||||
|
||||
Reference in New Issue
Block a user