mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-07-20 18:04:24 +08:00
Support for selecting printer (slug)
This commit is contained in:
parent
5e236a70cb
commit
62c6637976
@ -152,6 +152,7 @@ void PrintConfigDef::init_common_params()
|
||||
def = this->add("repetier_slug", coString);
|
||||
def->label = L("Repetier Printer");
|
||||
def->tooltip = L("Name of the Repetier printer");
|
||||
def->gui_type = "select_open";
|
||||
def->mode = comAdvanced;
|
||||
def->set_default_value(new ConfigOptionString(""));
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace GUI {
|
||||
|
||||
static const char *CONFIG_KEY_PATH = "printhost_path";
|
||||
static const char *CONFIG_KEY_PRINT = "printhost_print";
|
||||
static const char *CONFIG_KEY_GROUP = "repetier_group";
|
||||
static const char *CONFIG_KEY_GROUP = "printhost_group";
|
||||
|
||||
PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, bool can_start_print, wxArrayString& groups)
|
||||
: MsgDialog(nullptr, _(L("Send G-Code to printer host")), _(L("Upload to Printer Host with the following filename:")), wxID_NONE)
|
||||
|
@ -1992,26 +1992,18 @@ void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup)
|
||||
return sizer;
|
||||
};
|
||||
|
||||
auto repetier_slug_browse = [=](wxWindow* parent) {
|
||||
add_scaled_button(parent, &m_repetier_slug_browse_btn, "printers", _(L("Printers")) + " "+ dots, wxBU_LEFT | wxBU_EXACTFIT);
|
||||
auto print_host_printers = [this](wxWindow* parent) {
|
||||
add_scaled_button(parent, &m_repetier_slug_browse_btn, "browse", _(L("Refresh Printers")), wxBU_LEFT | wxBU_EXACTFIT);
|
||||
ScalableButton* btn = m_repetier_slug_browse_btn;
|
||||
btn->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
||||
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(btn);
|
||||
|
||||
btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent &e) {
|
||||
BonjourDialog dialog(parent, tech);
|
||||
if (dialog.show_and_lookup()) {
|
||||
optgroup->set_value("repetier_slug", std::move(dialog.get_selected()), true);
|
||||
optgroup->get_field("repetier_slug")->field_changed();
|
||||
}
|
||||
});
|
||||
|
||||
btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) { update_printers(); });
|
||||
return sizer;
|
||||
};
|
||||
|
||||
|
||||
// Set a wider width for a better alignment
|
||||
Option option = optgroup->get_option("print_host");
|
||||
option.opt.width = Field::def_width_wider();
|
||||
@ -2025,7 +2017,9 @@ void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup)
|
||||
|
||||
option = optgroup->get_option("repetier_slug");
|
||||
option.opt.width = Field::def_width_wider();
|
||||
optgroup->append_single_option_line(option);
|
||||
Line slug_line = optgroup->create_single_option_line(option);
|
||||
slug_line.append_widget(print_host_printers);
|
||||
optgroup->append_line(slug_line);
|
||||
|
||||
const auto ca_file_hint = _utf8(L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate."));
|
||||
|
||||
@ -2139,6 +2133,32 @@ void TabPrinter::update_serial_ports()
|
||||
choice->set_values(Utils::scan_serial_ports());
|
||||
}
|
||||
|
||||
void TabPrinter::update_printers()
|
||||
{
|
||||
std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
|
||||
|
||||
wxArrayString printers;
|
||||
Field *rs = get_field("repetier_slug");
|
||||
if (!host->get_printers(printers)) {
|
||||
std::vector<std::string> slugs;
|
||||
|
||||
Choice *choice = dynamic_cast<Choice *>(rs);
|
||||
choice->set_values(slugs);
|
||||
|
||||
rs->disable();
|
||||
} else {
|
||||
std::vector<std::string> slugs;
|
||||
for (int i = 0; i < printers.size(); i++) {
|
||||
slugs.push_back(printers[i].ToStdString());
|
||||
}
|
||||
|
||||
Choice *choice = dynamic_cast<Choice *>(rs);
|
||||
choice->set_values(slugs);
|
||||
|
||||
rs->enable();
|
||||
}
|
||||
}
|
||||
|
||||
void TabPrinter::extruders_count_changed(size_t extruders_count)
|
||||
{
|
||||
bool is_count_changed = false;
|
||||
@ -2501,6 +2521,15 @@ void TabPrinter::update_fff()
|
||||
m_print_host_test_btn->Enable(!m_config->opt_string("print_host").empty() && host->can_test());
|
||||
if(m_printhost_browse_btn)
|
||||
m_printhost_browse_btn->Enable(host->has_auto_discovery());
|
||||
m_repetier_slug_browse_btn->Enable(host->can_support_multiple_printers());
|
||||
|
||||
Field *rs = get_field("repetier_slug");
|
||||
if (host->can_support_multiple_printers()) {
|
||||
update_printers();
|
||||
rs->enable();
|
||||
} else {
|
||||
rs->disable();
|
||||
}
|
||||
}
|
||||
|
||||
bool have_multiple_extruders = m_extruders_count > 1;
|
||||
@ -2629,16 +2658,6 @@ void TabPrinter::update_fff()
|
||||
}
|
||||
}
|
||||
|
||||
bool is_repetier = m_config->option<ConfigOptionEnum<PrintHostType>>("host_type")->value == htRepetier;
|
||||
{
|
||||
Field *rs = get_field("repetier_slug");
|
||||
if (is_repetier) {
|
||||
rs->enable();
|
||||
} else {
|
||||
rs->disable();
|
||||
}
|
||||
}
|
||||
|
||||
//z step checks
|
||||
{
|
||||
double z_step = m_config->opt_float("z_step");
|
||||
|
@ -392,6 +392,7 @@ public:
|
||||
wxButton* m_serial_test_btn = nullptr;
|
||||
ScalableButton* m_print_host_test_btn = nullptr;
|
||||
ScalableButton* m_printhost_browse_btn = nullptr;
|
||||
ScalableButton* m_printhost_browse_printer_btn = nullptr;
|
||||
ScalableButton* m_repetier_slug_browse_btn = nullptr;
|
||||
ScalableButton* m_reset_to_filament_color = nullptr;
|
||||
|
||||
@ -419,6 +420,7 @@ public:
|
||||
void update_sla();
|
||||
void update_pages(); // update m_pages according to printer technology
|
||||
void update_serial_ports();
|
||||
void update_printers();
|
||||
void extruders_count_changed(size_t extruders_count);
|
||||
void milling_count_changed(size_t extruders_count);
|
||||
PageShp build_kinematics_page();
|
||||
|
@ -27,8 +27,11 @@ public:
|
||||
bool has_auto_discovery() const override { return true; }
|
||||
bool can_test() const override { return true; }
|
||||
bool can_start_print() const override { return true; }
|
||||
bool can_support_multiple_printers() const override { return false; }
|
||||
std::string get_host() const override { return host; }
|
||||
bool get_groups(wxArrayString& groups) const override { return false; }
|
||||
|
||||
bool get_groups(wxArrayString &groups) const override { return false; }
|
||||
bool get_printers(wxArrayString &printers) const override { return false; }
|
||||
|
||||
protected:
|
||||
bool validate_version_text(const boost::optional<std::string> &version_text) const;
|
||||
|
@ -26,8 +26,11 @@ public:
|
||||
bool has_auto_discovery() const override { return false; }
|
||||
bool can_test() const override { return true; }
|
||||
bool can_start_print() const override { return true; }
|
||||
bool can_support_multiple_printers() const override { return false; }
|
||||
std::string get_host() const override { return host; }
|
||||
bool get_groups(wxArrayString& groups) const override { return false; }
|
||||
|
||||
bool get_groups(wxArrayString &groups) const override { return false; }
|
||||
bool get_printers(wxArrayString &printers) const override { return false; }
|
||||
|
||||
private:
|
||||
std::string host;
|
||||
|
@ -27,8 +27,11 @@ public:
|
||||
bool has_auto_discovery() const override { return false; }
|
||||
bool can_test() const override { return true; }
|
||||
bool can_start_print() const override { return false; }
|
||||
bool can_support_multiple_printers() const override { return false; }
|
||||
std::string get_host() const override { return host; }
|
||||
bool get_groups(wxArrayString& groups) const override { return false; }
|
||||
|
||||
bool get_groups(wxArrayString &groups) const override { return false; }
|
||||
bool get_printers(wxArrayString &printers) const override { return false; }
|
||||
|
||||
private:
|
||||
std::string host;
|
||||
|
@ -28,8 +28,10 @@ public:
|
||||
bool has_auto_discovery() const override { return true; }
|
||||
bool can_test() const override { return true; }
|
||||
bool can_start_print() const override { return true; }
|
||||
bool can_support_multiple_printers() const override { return false; }
|
||||
std::string get_host() const override { return host; }
|
||||
bool get_groups(wxArrayString& groups) const override { return false; }
|
||||
bool get_groups(wxArrayString &groups) const override { return false; }
|
||||
bool get_printers(wxArrayString &printers) const override { return false; }
|
||||
|
||||
protected:
|
||||
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
|
||||
|
@ -44,8 +44,10 @@ public:
|
||||
virtual bool has_auto_discovery() const = 0;
|
||||
virtual bool can_test() const = 0;
|
||||
virtual bool can_start_print() const = 0;
|
||||
virtual bool can_support_multiple_printers() const = 0;
|
||||
virtual std::string get_host() const = 0;
|
||||
virtual bool get_groups(wxArrayString& groups) const = 0;
|
||||
virtual bool get_printers(wxArrayString &printers) const = 0;
|
||||
|
||||
static PrintHost* get_print_host(DynamicPrintConfig *config);
|
||||
|
||||
|
@ -41,12 +41,13 @@ bool Repetier::test(wxString &msg) const
|
||||
const char *name = get_name();
|
||||
|
||||
bool res = true;
|
||||
auto url = make_url("printer/info");
|
||||
auto url = make_url("printer/version");
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Get version at: %2%") % name % url;
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: List version at: %2%") % name % url;
|
||||
|
||||
auto http = Http::get(std::move(url));
|
||||
set_auth(http);
|
||||
|
||||
http.on_error([&](std::string body, std::string error, unsigned status) {
|
||||
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
|
||||
res = false;
|
||||
@ -60,11 +61,20 @@ bool Repetier::test(wxString &msg) const
|
||||
pt::ptree ptree;
|
||||
pt::read_json(ss, ptree);
|
||||
|
||||
const auto text = ptree.get_optional<std::string>("name");
|
||||
res = validate_version_text(text);
|
||||
if (! res) {
|
||||
msg = GUI::from_u8((boost::format(_utf8(L("Mismatched type of print host: %s"))) % (text ? *text : "Repetier")).str());
|
||||
/*
|
||||
const auto error = ptree.get_optional<std::string>("error");
|
||||
if (error) {
|
||||
msg = GUI::from_u8((boost::format(_utf8(L("%s"))) % error).str());
|
||||
res = false;
|
||||
} else {
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, ptree.get_child("data.")) {
|
||||
const auto slug = v.second.get<std::string>("slug");
|
||||
slugs.push_back(slug);
|
||||
}
|
||||
|
||||
//res = !printers.empty();
|
||||
}
|
||||
*/
|
||||
}
|
||||
catch (const std::exception &) {
|
||||
res = false;
|
||||
@ -83,7 +93,7 @@ wxString Repetier::get_test_ok_msg () const
|
||||
|
||||
wxString Repetier::get_test_failed_msg (wxString &msg) const
|
||||
{
|
||||
return GUI::from_u8((boost::format("%s: %s\n\n%s")
|
||||
return GUI::from_u8((boost::format("%s: %s\n\n%s")
|
||||
% _utf8(L("Could not connect to Repetier"))
|
||||
% std::string(msg.ToUTF8())
|
||||
% _utf8(L("Note: Repetier version at least 0.90.0 is required."))).str());
|
||||
@ -213,4 +223,50 @@ bool Repetier::get_groups(wxArrayString& groups) const
|
||||
return res;
|
||||
}
|
||||
|
||||
bool Repetier::get_printers(wxArrayString& printers) const
|
||||
{
|
||||
const char *name = get_name();
|
||||
|
||||
bool res = true;
|
||||
auto url = make_url("printer/list");
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("%1%: List printers at: %2%") % name % url;
|
||||
|
||||
auto http = Http::get(std::move(url));
|
||||
set_auth(http);
|
||||
|
||||
auto &slugs = printers;
|
||||
http.on_error([&](std::string body, std::string error, unsigned status) {
|
||||
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error listing printers: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
|
||||
res = false;
|
||||
})
|
||||
.on_complete([&, this](std::string body, unsigned) {
|
||||
BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got printers: %2%") % name % body;
|
||||
|
||||
try {
|
||||
std::stringstream ss(body);
|
||||
pt::ptree ptree;
|
||||
pt::read_json(ss, ptree);
|
||||
|
||||
const auto error = ptree.get_optional<std::string>("error");
|
||||
if (error) {
|
||||
res = false;
|
||||
} else {
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, ptree.get_child("data.")) {
|
||||
const auto slug = v.second.get<std::string>("slug");
|
||||
printers.push_back(slug);
|
||||
}
|
||||
|
||||
//res = !printers.empty();
|
||||
}
|
||||
}
|
||||
catch (const std::exception &) {
|
||||
res = false;
|
||||
}
|
||||
})
|
||||
.perform_sync();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,8 +28,11 @@ public:
|
||||
bool has_auto_discovery() const override { return false; }
|
||||
bool can_test() const override { return true; }
|
||||
bool can_start_print() const override { return false; }
|
||||
bool can_support_multiple_printers() const override { return true; }
|
||||
std::string get_host() const override { return host; }
|
||||
bool get_groups(wxArrayString& groups) const override;
|
||||
|
||||
bool get_groups(wxArrayString &groups) const override;
|
||||
bool get_printers(wxArrayString &printers) const override;
|
||||
|
||||
protected:
|
||||
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user