Merge branch 'master' of https://github.com/prusa3d/Slic3r
This commit is contained in:
commit
9335eb9780
@ -1231,7 +1231,7 @@ void GCode::process_layer(
|
||||
const Print &print,
|
||||
// Set of object & print layers of the same PrintObject and with the same print_z.
|
||||
const std::vector<LayerToPrint> &layers,
|
||||
const LayerTools &layer_tools,
|
||||
const LayerTools &layer_tools,
|
||||
// If set to size_t(-1), then print all copies of all objects.
|
||||
// Otherwise print a single copy of a single object.
|
||||
const size_t single_object_idx)
|
||||
@ -1644,6 +1644,8 @@ void GCode::process_layer(
|
||||
// printf("G-code after filter:\n%s\n", out.c_str());
|
||||
|
||||
_write(file, gcode);
|
||||
BOOST_LOG_TRIVIAL(trace) << "Exported layer " << layer.id() << " print_z " << print_z << ", time estimator memory: " +
|
||||
format_memsize_MB(m_normal_time_estimator.memory_used() + m_silent_time_estimator_enabled ? m_silent_time_estimator.memory_used() : 0);
|
||||
}
|
||||
|
||||
void GCode::apply_print_config(const PrintConfig &print_config)
|
||||
|
@ -309,8 +309,9 @@ namespace Slic3r {
|
||||
gcode_line += "\n";
|
||||
|
||||
// add remaining time lines where needed
|
||||
G1LineIdToBlockIdMap::const_iterator it_line_id = _g1_line_ids.begin();
|
||||
_parser.parse_line(gcode_line,
|
||||
[this, &g1_lines_count, &last_recorded_time, &time_line, &gcode_line, time_mask, interval](GCodeReader& reader, const GCodeReader::GCodeLine& line)
|
||||
[this, &it_line_id, &g1_lines_count, &last_recorded_time, &time_line, &gcode_line, time_mask, interval](GCodeReader& reader, const GCodeReader::GCodeLine& line)
|
||||
{
|
||||
if (line.cmd_is("G1"))
|
||||
{
|
||||
@ -319,10 +320,10 @@ namespace Slic3r {
|
||||
if (!line.has_e())
|
||||
return;
|
||||
|
||||
G1LineIdToBlockIdMap::const_iterator it = _g1_line_ids.find(g1_lines_count);
|
||||
if ((it != _g1_line_ids.end()) && (it->second < (unsigned int)_blocks.size()))
|
||||
if ((it_line_id != _g1_line_ids.end()) && (it_line_id->first == g1_lines_count) && (it_line_id->second < (unsigned int)_blocks.size()))
|
||||
{
|
||||
const Block& block = _blocks[it->second];
|
||||
const Block& block = _blocks[it_line_id->second];
|
||||
++ it_line_id;
|
||||
if (block.elapsed_time != -1.0f)
|
||||
{
|
||||
float block_remaining_time = _time - block.elapsed_time;
|
||||
@ -667,6 +668,21 @@ namespace Slic3r {
|
||||
return _get_time_minutes(get_time());
|
||||
}
|
||||
|
||||
// Return an estimate of the memory consumed by the time estimator.
|
||||
size_t GCodeTimeEstimator::memory_used() const
|
||||
{
|
||||
size_t out = sizeof(*this);
|
||||
#if WIN32
|
||||
#define STDVEC_MEMSIZE(NAME, TYPE) NAME.capacity() * ((sizeof(TYPE) + __alignof(TYPE) - 1) / __alignof(TYPE)) * __alignof(TYPE)
|
||||
#else
|
||||
#define STDVEC_MEMSIZE(NAME, TYPE) NAME.capacity() * ((sizeof(TYPE) + alignof(TYPE) - 1) / alignof(TYPE)) * alignof(TYPE)
|
||||
#endif
|
||||
out += STDVEC_MEMSIZE(this->_blocks, Block);
|
||||
out += STDVEC_MEMSIZE(this->_g1_line_ids, G1LineIdToBlockId);
|
||||
#undef STDVEC_MEMSIZE
|
||||
return out;
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_reset()
|
||||
{
|
||||
_curr.reset();
|
||||
@ -1072,7 +1088,7 @@ namespace Slic3r {
|
||||
|
||||
// adds block to blocks list
|
||||
_blocks.emplace_back(block);
|
||||
_g1_line_ids.insert(G1LineIdToBlockIdMap::value_type(get_g1_line_id(), (unsigned int)_blocks.size() - 1));
|
||||
_g1_line_ids.emplace_back(G1LineIdToBlockIdMap::value_type(get_g1_line_id(), (unsigned int)_blocks.size() - 1));
|
||||
}
|
||||
|
||||
void GCodeTimeEstimator::_processG4(const GCodeReader::GCodeLine& line)
|
||||
|
@ -209,7 +209,8 @@ namespace Slic3r {
|
||||
typedef std::map<Block::EMoveType, MoveStats> MovesStatsMap;
|
||||
#endif // ENABLE_MOVE_STATS
|
||||
|
||||
typedef std::map<unsigned int, unsigned int> G1LineIdToBlockIdMap;
|
||||
typedef std::pair<unsigned int, unsigned int> G1LineIdToBlockId;
|
||||
typedef std::vector<G1LineIdToBlockId> G1LineIdToBlockIdMap;
|
||||
|
||||
private:
|
||||
EMode _mode;
|
||||
@ -338,6 +339,9 @@ namespace Slic3r {
|
||||
// Returns the estimated time, in minutes (integer)
|
||||
std::string get_time_minutes() const;
|
||||
|
||||
// Return an estimate of the memory consumed by the time estimator.
|
||||
size_t memory_used() const;
|
||||
|
||||
private:
|
||||
void _reset();
|
||||
void _reset_time();
|
||||
|
@ -36,7 +36,7 @@ enum GCodeFlavor {
|
||||
};
|
||||
|
||||
enum PrintHostType {
|
||||
htOctoPrint, htDuet,
|
||||
htOctoPrint, htDuet, htSL1,
|
||||
};
|
||||
|
||||
enum InfillPattern {
|
||||
|
@ -12,6 +12,8 @@ namespace Slic3r {
|
||||
|
||||
extern void set_logging_level(unsigned int level);
|
||||
extern void trace(unsigned int level, const char *message);
|
||||
// Format memory allocated, separate thousands by comma.
|
||||
extern std::string format_memsize_MB(size_t n);
|
||||
// Return string to be added to the boost::log output to inform about the current process memory allocation.
|
||||
// The string is non-empty only if the loglevel >= info (3).
|
||||
extern std::string log_memory_info();
|
||||
|
@ -3244,6 +3244,8 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
|
||||
#endif // ENABLE_REMOVE_TABS_FROM_PLATER
|
||||
if (p->preview) p->preview->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values);
|
||||
update_scheduled = true;
|
||||
} else if (opt_key == "host_type" && this->p->printer_technology == ptSLA) {
|
||||
p->config->option<ConfigOptionEnum<PrintHostType>>(opt_key)->value = htSL1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -456,6 +456,7 @@ const std::vector<std::string>& Preset::sla_printer_options()
|
||||
"display_width", "display_height", "display_pixels_x", "display_pixels_y",
|
||||
"display_orientation",
|
||||
"printer_correction",
|
||||
"print_host", "printhost_apikey", "printhost_cafile",
|
||||
"printer_notes",
|
||||
"inherits"
|
||||
};
|
||||
|
@ -1538,6 +1538,108 @@ bool Tab::current_preset_is_dirty()
|
||||
return m_presets->current_is_dirty();
|
||||
}
|
||||
|
||||
void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup)
|
||||
{
|
||||
const bool sla = m_presets->get_selected_preset().printer_technology() == ptSLA;
|
||||
|
||||
// Only offer the host type selection for FFF, for SLA it's always the SL1 printer (at the moment)
|
||||
if (! sla) {
|
||||
optgroup->append_single_option_line("host_type");
|
||||
} else {
|
||||
m_config->option<ConfigOptionEnum<PrintHostType>>("host_type", true)->value = htSL1;
|
||||
}
|
||||
|
||||
auto printhost_browse = [this, optgroup] (wxWindow* parent) {
|
||||
|
||||
// TODO: SLA
|
||||
|
||||
auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(btn);
|
||||
|
||||
btn->Bind(wxEVT_BUTTON, [this, parent, optgroup](wxCommandEvent e) {
|
||||
BonjourDialog dialog(parent);
|
||||
if (dialog.show_and_lookup()) {
|
||||
optgroup->set_value("print_host", std::move(dialog.get_selected()), true);
|
||||
}
|
||||
});
|
||||
|
||||
return sizer;
|
||||
};
|
||||
|
||||
auto print_host_test = [this](wxWindow* parent) {
|
||||
auto btn = m_print_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")),
|
||||
wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
|
||||
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("wrench.png")), wxBITMAP_TYPE_PNG));
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(btn);
|
||||
|
||||
btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {
|
||||
std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
|
||||
if (! host) {
|
||||
const auto text = wxString::Format("%s",
|
||||
_(L("Could not get a valid Printer Host reference")));
|
||||
show_error(this, text);
|
||||
return;
|
||||
}
|
||||
wxString msg;
|
||||
if (host->test(msg)) {
|
||||
show_info(this, host->get_test_ok_msg(), _(L("Success!")));
|
||||
} else {
|
||||
show_error(this, host->get_test_failed_msg(msg));
|
||||
}
|
||||
});
|
||||
|
||||
return sizer;
|
||||
};
|
||||
|
||||
Line host_line = optgroup->create_single_option_line("print_host");
|
||||
host_line.append_widget(printhost_browse);
|
||||
host_line.append_widget(print_host_test);
|
||||
optgroup->append_line(host_line);
|
||||
optgroup->append_single_option_line("printhost_apikey");
|
||||
|
||||
if (Http::ca_file_supported()) {
|
||||
|
||||
Line cafile_line = optgroup->create_single_option_line("printhost_cafile");
|
||||
|
||||
auto printhost_cafile_browse = [this, optgroup] (wxWindow* parent) {
|
||||
auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(btn);
|
||||
|
||||
btn->Bind(wxEVT_BUTTON, [this, optgroup] (wxCommandEvent e) {
|
||||
static const auto filemasks = _(L("Certificate files (*.crt, *.pem)|*.crt;*.pem|All files|*.*"));
|
||||
wxFileDialog openFileDialog(this, _(L("Open CA certificate file")), "", "", filemasks, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
if (openFileDialog.ShowModal() != wxID_CANCEL) {
|
||||
optgroup->set_value("printhost_cafile", std::move(openFileDialog.GetPath()), true);
|
||||
}
|
||||
});
|
||||
|
||||
return sizer;
|
||||
};
|
||||
|
||||
cafile_line.append_widget(printhost_cafile_browse);
|
||||
optgroup->append_line(cafile_line);
|
||||
|
||||
auto printhost_cafile_hint = [this, optgroup] (wxWindow* parent) {
|
||||
auto txt = new wxStaticText(parent, wxID_ANY,
|
||||
_(L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate.")));
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(txt);
|
||||
return sizer;
|
||||
};
|
||||
|
||||
Line cafile_hint { "", "" };
|
||||
cafile_hint.full_width = 1;
|
||||
cafile_hint.widget = std::move(printhost_cafile_hint);
|
||||
optgroup->append_line(cafile_hint);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void TabPrinter::build()
|
||||
{
|
||||
m_presets = &m_preset_bundle->printers;
|
||||
@ -1665,96 +1767,8 @@ void TabPrinter::build_fff()
|
||||
}
|
||||
#endif
|
||||
|
||||
optgroup = page->new_optgroup(_(L("Printer Host upload")));
|
||||
|
||||
optgroup->append_single_option_line("host_type");
|
||||
|
||||
auto printhost_browse = [this, optgroup] (wxWindow* parent) {
|
||||
auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(btn);
|
||||
|
||||
btn->Bind(wxEVT_BUTTON, [this, parent, optgroup](wxCommandEvent e) {
|
||||
BonjourDialog dialog(parent);
|
||||
if (dialog.show_and_lookup()) {
|
||||
optgroup->set_value("print_host", std::move(dialog.get_selected()), true);
|
||||
}
|
||||
});
|
||||
|
||||
return sizer;
|
||||
};
|
||||
|
||||
auto print_host_test = [this](wxWindow* parent) {
|
||||
auto btn = m_print_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")),
|
||||
wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
|
||||
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("wrench.png")), wxBITMAP_TYPE_PNG));
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(btn);
|
||||
|
||||
btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {
|
||||
std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
|
||||
if (! host) {
|
||||
const auto text = wxString::Format("%s",
|
||||
_(L("Could not get a valid Printer Host reference")));
|
||||
show_error(this, text);
|
||||
return;
|
||||
}
|
||||
wxString msg;
|
||||
if (host->test(msg)) {
|
||||
show_info(this, host->get_test_ok_msg(), _(L("Success!")));
|
||||
} else {
|
||||
show_error(this, host->get_test_failed_msg(msg));
|
||||
}
|
||||
});
|
||||
|
||||
return sizer;
|
||||
};
|
||||
|
||||
Line host_line = optgroup->create_single_option_line("print_host");
|
||||
host_line.append_widget(printhost_browse);
|
||||
host_line.append_widget(print_host_test);
|
||||
optgroup->append_line(host_line);
|
||||
optgroup->append_single_option_line("printhost_apikey");
|
||||
|
||||
if (Http::ca_file_supported()) {
|
||||
|
||||
Line cafile_line = optgroup->create_single_option_line("printhost_cafile");
|
||||
|
||||
auto printhost_cafile_browse = [this, optgroup] (wxWindow* parent) {
|
||||
auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(btn);
|
||||
|
||||
btn->Bind(wxEVT_BUTTON, [this, optgroup] (wxCommandEvent e) {
|
||||
static const auto filemasks = _(L("Certificate files (*.crt, *.pem)|*.crt;*.pem|All files|*.*"));
|
||||
wxFileDialog openFileDialog(this, _(L("Open CA certificate file")), "", "", filemasks, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
if (openFileDialog.ShowModal() != wxID_CANCEL) {
|
||||
optgroup->set_value("printhost_cafile", std::move(openFileDialog.GetPath()), true);
|
||||
}
|
||||
});
|
||||
|
||||
return sizer;
|
||||
};
|
||||
|
||||
cafile_line.append_widget(printhost_cafile_browse);
|
||||
optgroup->append_line(cafile_line);
|
||||
|
||||
auto printhost_cafile_hint = [this, optgroup] (wxWindow* parent) {
|
||||
auto txt = new wxStaticText(parent, wxID_ANY,
|
||||
_(L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate.")));
|
||||
auto sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizer->Add(txt);
|
||||
return sizer;
|
||||
};
|
||||
|
||||
Line cafile_hint { "", "" };
|
||||
cafile_hint.full_width = 1;
|
||||
cafile_hint.widget = std::move(printhost_cafile_hint);
|
||||
optgroup->append_line(cafile_hint);
|
||||
|
||||
}
|
||||
optgroup = page->new_optgroup(_(L("Print Host upload")));
|
||||
build_printhost(optgroup.get());
|
||||
|
||||
optgroup = page->new_optgroup(_(L("Firmware")));
|
||||
optgroup->append_single_option_line("gcode_flavor");
|
||||
@ -1897,6 +1911,9 @@ void TabPrinter::build_sla()
|
||||
}
|
||||
optgroup->append_line(line);
|
||||
|
||||
optgroup = page->new_optgroup(_(L("Print Host upload")));
|
||||
build_printhost(optgroup.get());
|
||||
|
||||
page = add_options_page(_(L("Notes")), "note.png");
|
||||
optgroup = page->new_optgroup(_(L("Notes")), 0);
|
||||
option = optgroup->get_option("printer_notes");
|
||||
|
@ -325,6 +325,8 @@ class TabPrinter : public Tab
|
||||
|
||||
std::vector<PageShp> m_pages_fff;
|
||||
std::vector<PageShp> m_pages_sla;
|
||||
|
||||
void build_printhost(ConfigOptionsGroup *optgroup);
|
||||
public:
|
||||
wxButton* m_serial_test_btn = nullptr;
|
||||
wxButton* m_print_host_test_btn = nullptr;
|
||||
|
@ -17,141 +17,161 @@ namespace fs = boost::filesystem;
|
||||
namespace Slic3r {
|
||||
|
||||
OctoPrint::OctoPrint(DynamicPrintConfig *config) :
|
||||
host(config->opt_string("print_host")),
|
||||
apikey(config->opt_string("printhost_apikey")),
|
||||
cafile(config->opt_string("printhost_cafile"))
|
||||
host(config->opt_string("print_host")),
|
||||
apikey(config->opt_string("printhost_apikey")),
|
||||
cafile(config->opt_string("printhost_cafile"))
|
||||
{}
|
||||
|
||||
OctoPrint::~OctoPrint() {}
|
||||
|
||||
bool OctoPrint::test(wxString &msg) const
|
||||
{
|
||||
// Since the request is performed synchronously here,
|
||||
// it is ok to refer to `msg` from within the closure
|
||||
// Since the request is performed synchronously here,
|
||||
// it is ok to refer to `msg` from within the closure
|
||||
|
||||
bool res = true;
|
||||
auto url = make_url("api/version");
|
||||
bool res = true;
|
||||
auto url = make_url("api/version");
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("Octoprint: Get version at: %1%") % url;
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("Octoprint: Get version at: %1%") % 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("Octoprint: Error getting version: %1%, HTTP %2%, body: `%3%`") % error % status % body;
|
||||
res = false;
|
||||
msg = format_error(body, error, status);
|
||||
})
|
||||
.on_complete([&](std::string body, unsigned) {
|
||||
BOOST_LOG_TRIVIAL(debug) << boost::format("Octoprint: Got version: %1%") % body;
|
||||
})
|
||||
.perform_sync();
|
||||
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("Octoprint: Error getting version: %1%, HTTP %2%, body: `%3%`") % error % status % body;
|
||||
res = false;
|
||||
msg = format_error(body, error, status);
|
||||
})
|
||||
.on_complete([&](std::string body, unsigned) {
|
||||
BOOST_LOG_TRIVIAL(debug) << boost::format("Octoprint: Got version: %1%") % body;
|
||||
|
||||
return res;
|
||||
// TODO: parse body, call validate_version_text
|
||||
|
||||
})
|
||||
.perform_sync();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
wxString OctoPrint::get_test_ok_msg () const
|
||||
{
|
||||
return wxString::Format("%s", _(L("Connection to OctoPrint works correctly.")));
|
||||
return wxString::Format("%s", _(L("Connection to OctoPrint works correctly.")));
|
||||
}
|
||||
|
||||
wxString OctoPrint::get_test_failed_msg (wxString &msg) const
|
||||
{
|
||||
return wxString::Format("%s: %s\n\n%s",
|
||||
_(L("Could not connect to OctoPrint")), msg, _(L("Note: OctoPrint version at least 1.1.0 is required.")));
|
||||
return wxString::Format("%s: %s\n\n%s",
|
||||
_(L("Could not connect to OctoPrint")), msg, _(L("Note: OctoPrint version at least 1.1.0 is required.")));
|
||||
}
|
||||
|
||||
bool OctoPrint::upload(PrintHostUpload upload_data, Http::ProgressFn prorgess_fn, Http::ErrorFn error_fn) const
|
||||
{
|
||||
const auto upload_filename = upload_data.upload_path.filename();
|
||||
const auto upload_parent_path = upload_data.upload_path.parent_path();
|
||||
const auto upload_filename = upload_data.upload_path.filename();
|
||||
const auto upload_parent_path = upload_data.upload_path.parent_path();
|
||||
|
||||
wxString test_msg;
|
||||
if (! test(test_msg)) {
|
||||
wxString test_msg;
|
||||
if (! test(test_msg)) {
|
||||
|
||||
// TODO:
|
||||
// TODO:
|
||||
|
||||
// auto errormsg = wxString::Format("%s: %s", errortitle, test_msg);
|
||||
// GUI::show_error(&progress_dialog, std::move(errormsg));
|
||||
// return false;
|
||||
}
|
||||
// auto errormsg = wxString::Format("%s: %s", errortitle, test_msg);
|
||||
// GUI::show_error(&progress_dialog, std::move(errormsg));
|
||||
// return false;
|
||||
}
|
||||
|
||||
bool res = true;
|
||||
bool res = true;
|
||||
|
||||
auto url = make_url("api/files/local");
|
||||
auto url = make_url("api/files/local");
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("Octoprint: Uploading file %1% at %2%, filename: %3%, path: %4%, print: %5%")
|
||||
% upload_data.source_path.string()
|
||||
% url
|
||||
% upload_filename.string()
|
||||
% upload_parent_path.string()
|
||||
% upload_data.start_print;
|
||||
BOOST_LOG_TRIVIAL(info) << boost::format("Octoprint: Uploading file %1% at %2%, filename: %3%, path: %4%, print: %5%")
|
||||
% upload_data.source_path.string()
|
||||
% url
|
||||
% upload_filename.string()
|
||||
% upload_parent_path.string()
|
||||
% upload_data.start_print;
|
||||
|
||||
auto http = Http::post(std::move(url));
|
||||
set_auth(http);
|
||||
http.form_add("print", upload_data.start_print ? "true" : "false")
|
||||
.form_add("path", upload_parent_path.string()) // XXX: slashes on windows ???
|
||||
.form_add_file("file", upload_data.source_path.string(), upload_filename.string())
|
||||
.on_complete([&](std::string body, unsigned status) {
|
||||
BOOST_LOG_TRIVIAL(debug) << boost::format("Octoprint: File uploaded: HTTP %1%: %2%") % status % body;
|
||||
})
|
||||
.on_error([&](std::string body, std::string error, unsigned status) {
|
||||
BOOST_LOG_TRIVIAL(error) << boost::format("Octoprint: Error uploading file: %1%, HTTP %2%, body: `%3%`") % error % status % body;
|
||||
error_fn(std::move(body), std::move(error), status);
|
||||
res = false;
|
||||
})
|
||||
.on_progress([&](Http::Progress progress, bool &cancel) {
|
||||
prorgess_fn(std::move(progress), cancel);
|
||||
if (cancel) {
|
||||
// Upload was canceled
|
||||
BOOST_LOG_TRIVIAL(error) << "Octoprint: Upload canceled";
|
||||
res = false;
|
||||
}
|
||||
})
|
||||
.perform_sync();
|
||||
auto http = Http::post(std::move(url));
|
||||
set_auth(http);
|
||||
http.form_add("print", upload_data.start_print ? "true" : "false")
|
||||
.form_add("path", upload_parent_path.string()) // XXX: slashes on windows ???
|
||||
.form_add_file("file", upload_data.source_path.string(), upload_filename.string())
|
||||
.on_complete([&](std::string body, unsigned status) {
|
||||
BOOST_LOG_TRIVIAL(debug) << boost::format("Octoprint: File uploaded: HTTP %1%: %2%") % status % body;
|
||||
})
|
||||
.on_error([&](std::string body, std::string error, unsigned status) {
|
||||
BOOST_LOG_TRIVIAL(error) << boost::format("Octoprint: Error uploading file: %1%, HTTP %2%, body: `%3%`") % error % status % body;
|
||||
error_fn(std::move(body), std::move(error), status);
|
||||
res = false;
|
||||
})
|
||||
.on_progress([&](Http::Progress progress, bool &cancel) {
|
||||
prorgess_fn(std::move(progress), cancel);
|
||||
if (cancel) {
|
||||
// Upload was canceled
|
||||
BOOST_LOG_TRIVIAL(error) << "Octoprint: Upload canceled";
|
||||
res = false;
|
||||
}
|
||||
})
|
||||
.perform_sync();
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool OctoPrint::has_auto_discovery() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OctoPrint::can_test() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OctoPrint::validate_version_text(const std::string &version_text)
|
||||
{
|
||||
// FIXME
|
||||
return true;
|
||||
}
|
||||
|
||||
void OctoPrint::set_auth(Http &http) const
|
||||
{
|
||||
http.header("X-Api-Key", apikey);
|
||||
http.header("X-Api-Key", apikey);
|
||||
|
||||
if (! cafile.empty()) {
|
||||
http.ca_file(cafile);
|
||||
}
|
||||
if (! cafile.empty()) {
|
||||
http.ca_file(cafile);
|
||||
}
|
||||
}
|
||||
|
||||
std::string OctoPrint::make_url(const std::string &path) const
|
||||
{
|
||||
if (host.find("http://") == 0 || host.find("https://") == 0) {
|
||||
if (host.back() == '/') {
|
||||
return (boost::format("%1%%2%") % host % path).str();
|
||||
} else {
|
||||
return (boost::format("%1%/%2%") % host % path).str();
|
||||
}
|
||||
} else {
|
||||
return (boost::format("http://%1%/%2%") % host % path).str();
|
||||
}
|
||||
if (host.find("http://") == 0 || host.find("https://") == 0) {
|
||||
if (host.back() == '/') {
|
||||
return (boost::format("%1%%2%") % host % path).str();
|
||||
} else {
|
||||
return (boost::format("%1%/%2%") % host % path).str();
|
||||
}
|
||||
} else {
|
||||
return (boost::format("http://%1%/%2%") % host % path).str();
|
||||
}
|
||||
}
|
||||
|
||||
wxString OctoPrint::format_error(const std::string &body, const std::string &error, unsigned status)
|
||||
{
|
||||
if (status != 0) {
|
||||
auto wxbody = wxString::FromUTF8(body.data());
|
||||
return wxString::Format("HTTP %u: %s", status, wxbody);
|
||||
} else {
|
||||
return wxString::FromUTF8(error.data());
|
||||
}
|
||||
if (status != 0) {
|
||||
auto wxbody = wxString::FromUTF8(body.data());
|
||||
return wxString::Format("HTTP %u: %s", status, wxbody);
|
||||
} else {
|
||||
return wxString::FromUTF8(error.data());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// SL1
|
||||
|
||||
SL1Host::~SL1Host() {}
|
||||
|
||||
bool SL1Host::validate_version_text(const std::string &version_text)
|
||||
{
|
||||
// FIXME
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,24 +16,39 @@ class Http;
|
||||
class OctoPrint : public PrintHost
|
||||
{
|
||||
public:
|
||||
OctoPrint(DynamicPrintConfig *config);
|
||||
virtual ~OctoPrint();
|
||||
OctoPrint(DynamicPrintConfig *config);
|
||||
virtual ~OctoPrint();
|
||||
|
||||
bool test(wxString &curl_msg) const;
|
||||
wxString get_test_ok_msg () const;
|
||||
wxString get_test_failed_msg (wxString &msg) const;
|
||||
bool upload(PrintHostUpload upload_data, Http::ProgressFn prorgess_fn, Http::ErrorFn error_fn) const;
|
||||
bool has_auto_discovery() const;
|
||||
bool can_test() const;
|
||||
virtual std::string get_host() const { return host; }
|
||||
|
||||
protected:
|
||||
virtual bool validate_version_text(const std::string &version_text);
|
||||
|
||||
bool test(wxString &curl_msg) const;
|
||||
wxString get_test_ok_msg () const;
|
||||
wxString get_test_failed_msg (wxString &msg) const;
|
||||
bool upload(PrintHostUpload upload_data, Http::ProgressFn prorgess_fn, Http::ErrorFn error_fn) const;
|
||||
bool has_auto_discovery() const;
|
||||
bool can_test() const;
|
||||
virtual std::string get_host() const { return host; }
|
||||
private:
|
||||
std::string host;
|
||||
std::string apikey;
|
||||
std::string cafile;
|
||||
std::string host;
|
||||
std::string apikey;
|
||||
std::string cafile;
|
||||
|
||||
void set_auth(Http &http) const;
|
||||
std::string make_url(const std::string &path) const;
|
||||
static wxString format_error(const std::string &body, const std::string &error, unsigned status);
|
||||
void set_auth(Http &http) const;
|
||||
std::string make_url(const std::string &path) const;
|
||||
static wxString format_error(const std::string &body, const std::string &error, unsigned status);
|
||||
};
|
||||
|
||||
|
||||
class SL1Host: public OctoPrint
|
||||
{
|
||||
public:
|
||||
SL1Host(DynamicPrintConfig *config) : OctoPrint(config) {}
|
||||
virtual ~SL1Host();
|
||||
|
||||
protected:
|
||||
virtual bool validate_version_text(const std::string &version_text);
|
||||
};
|
||||
|
||||
|
||||
|
@ -24,13 +24,15 @@ PrintHost::~PrintHost() {}
|
||||
|
||||
PrintHost* PrintHost::get_print_host(DynamicPrintConfig *config)
|
||||
{
|
||||
PrintHostType kind = config->option<ConfigOptionEnum<PrintHostType>>("host_type")->value;
|
||||
if (kind == htOctoPrint) {
|
||||
return new OctoPrint(config);
|
||||
} else if (kind == htDuet) {
|
||||
return new Duet(config);
|
||||
const auto opt = config->option<ConfigOptionEnum<PrintHostType>>("host_type");
|
||||
if (opt == nullptr) { return nullptr; }
|
||||
|
||||
switch (opt->value) {
|
||||
case htOctoPrint: return new OctoPrint(config);
|
||||
case htSL1: return new SL1Host(config);
|
||||
case htDuet: return new Duet(config);
|
||||
default: return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user