Merge of pull request Add support for RepetierServer #4384 by @docbobo

with the following refactorings:

1) Removed the "printhost_slug" config from the Printer config
   and from all the Printer config related spots.
2) "printhost_slug" renamed to "printhost_port". Slug sounds nasty.
3) Improved error reporting of RepetierHost class.
4) Refactored for the new "Physical Printers"

Following refactorings were done independently of the Repetier pull request:
1) Removed PrintHost static print config.
2) Clean-up after conversion of print host configuration
   from Printer config to Physical Printer config.
3) Fixed some issues, where the Printer config was still queried for
   host configuration. Vojtech believes that this should not happen
   after the host configuration is converted to physical printers.

Vojtech still feels that more refactoring is needed in regard to porting
the host configuration from Printer profile to the new Physical Printer
profile.
This commit is contained in:
Vojtech Bubnik 2020-10-28 09:51:05 +01:00
parent 0798fa8185
commit 7c571c1d9d
24 changed files with 556 additions and 200 deletions

View file

@ -32,10 +32,6 @@
#include "BitmapCache.hpp"
#include "BonjourDialog.hpp"
using Slic3r::GUI::format_wxstr;
//static const std::pair<unsigned int, unsigned int> THUMBNAIL_SIZE_3MF = { 256, 256 };
namespace Slic3r {
namespace GUI {
@ -248,10 +244,30 @@ PhysicalPrinterDialog::~PhysicalPrinterDialog()
}
}
void PhysicalPrinterDialog::update_printers()
{
wxBusyCursor wait;
std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
wxArrayString printers;
Field *rs = m_optgroup->get_field("printhost_port");
try {
if (! host->get_printers(printers))
printers.clear();
} catch (const HostNetworkError &err) {
printers.clear();
show_error(this, _L("Querying printers connected to a print host failed.") + "\n\n" + from_u8(err.what()));
}
Choice *choice = dynamic_cast<Choice*>(rs);
choice->set_values(printers);
printers.empty() ? rs->disable() : rs->enable();
}
void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgroup)
{
m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
if (opt_key == "printhost_authorization_type")
if (opt_key == "host_type" || opt_key == "printhost_authorization_type")
this->update();
};
@ -291,17 +307,30 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
return;
}
wxString msg;
if (host->test(msg)) {
bool result;
{
// Show a wait cursor during the connection test, as it is blocking UI.
wxBusyCursor wait;
result = host->test(msg);
}
if (result)
show_info(this, host->get_test_ok_msg(), _L("Success!"));
}
else {
else
show_error(this, host->get_test_failed_msg(msg));
}
});
return sizer;
};
auto print_host_printers = [this, create_sizer_with_btn](wxWindow* parent) {
//add_scaled_button(parent, &m_printhost_port_browse_btn, "browse", _(L("Refresh Printers")), wxBU_LEFT | wxBU_EXACTFIT);
auto sizer = create_sizer_with_btn(parent, &m_printhost_port_browse_btn, "browse", _(L("Refresh Printers")));
ScalableButton* btn = m_printhost_port_browse_btn;
btn->SetFont(Slic3r::GUI::wxGetApp().normal_font());
btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) { update_printers(); });
return sizer;
};
// Set a wider width for a better alignment
Option option = m_optgroup->get_option("print_host");
option.opt.width = Field::def_width_wider();
@ -316,6 +345,12 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
option.opt.width = Field::def_width_wider();
m_optgroup->append_single_option_line(option);
option = m_optgroup->get_option("printhost_port");
option.opt.width = Field::def_width_wider();
Line port_line = m_optgroup->create_single_option_line(option);
port_line.append_widget(print_host_printers);
m_optgroup->append_line(port_line);
const auto ca_file_hint = _u8L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate.");
if (Http::ca_file_supported()) {
@ -377,6 +412,14 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
}
m_optgroup->activate();
// Always fill in the "printhost_port" combo box from the config and select it.
{
Choice* choice = dynamic_cast<Choice*>(m_optgroup->get_field("printhost_port"));
choice->set_values({ m_config->opt_string("printhost_port") });
choice->set_selection();
}
update();
}
@ -386,11 +429,14 @@ void PhysicalPrinterDialog::update()
const PrinterTechnology tech = Preset::printer_technology(*m_config);
// Only offer the host type selection for FFF, for SLA it's always the SL1 printer (at the moment)
bool supports_multiple_printers = false;
if (tech == ptFFF) {
m_optgroup->show_field("host_type");
m_optgroup->hide_field("printhost_authorization_type");
for (const std::string& opt_key : std::vector<std::string>{ "printhost_user", "printhost_password" })
m_optgroup->hide_field(opt_key);
const auto opt = m_config->option<ConfigOptionEnum<PrintHostType>>("host_type");
supports_multiple_printers = opt && opt->value == htRepetier;
}
else {
m_optgroup->set_value("host_type", int(PrintHostType::htOctoPrint), false);
@ -401,10 +447,12 @@ void PhysicalPrinterDialog::update()
AuthorizationType auth_type = m_config->option<ConfigOptionEnum<AuthorizationType>>("printhost_authorization_type")->value;
m_optgroup->show_field("printhost_apikey", auth_type == AuthorizationType::atKeyPassword);
for (const std::string& opt_key : std::vector<std::string>{ "printhost_user", "printhost_password" })
for (const char *opt_key : { "printhost_user", "printhost_password" })
m_optgroup->show_field(opt_key, auth_type == AuthorizationType::atUserPassword);
}
m_optgroup->show_field("printhost_port", supports_multiple_printers);
m_printhost_port_browse_btn->Show(supports_multiple_printers);
this->Layout();
}