Merge remote-tracking branch 'origin/master' into feature_arrange_with_libnest2d

This commit is contained in:
tamasmeszaros 2018-08-22 13:54:45 +02:00
commit 9036a11c7f
28 changed files with 692 additions and 147 deletions

View File

@ -38,7 +38,6 @@ if ($gui) {
%prereqs = qw( %prereqs = qw(
Class::Accessor 0 Class::Accessor 0
Wx 0.9918 Wx 0.9918
Socket 2.016
); );
%recommends = qw( %recommends = qw(
Wx::GLCanvas 0 Wx::GLCanvas 0

View File

@ -1,5 +1,4 @@
# Boost 1.63 requires CMake 3.7 or newer cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 2.8)
project(Slic3r) project(Slic3r)
@ -23,6 +22,7 @@ option(SLIC3R_GUI "Compile Slic3r with GUI components (OpenGL, wxWidgets)"
option(SLIC3R_PRUSACONTROL "Compile Slic3r with the PrusaControl prject file format (requires wxWidgets base library)" 1) option(SLIC3R_PRUSACONTROL "Compile Slic3r with the PrusaControl prject file format (requires wxWidgets base library)" 1)
option(SLIC3R_PROFILE "Compile Slic3r with an invasive Shiny profiler" 0) option(SLIC3R_PROFILE "Compile Slic3r with an invasive Shiny profiler" 0)
option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1) option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1)
option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1)
if (MSVC AND SLIC3R_MSVC_COMPILE_PARALLEL) if (MSVC AND SLIC3R_MSVC_COMPILE_PARALLEL)
add_compile_options(/MP) add_compile_options(/MP)
@ -36,10 +36,18 @@ else()
set(ENV_PATH_SEPARATOR ":") set(ENV_PATH_SEPARATOR ":")
endif() endif()
set(ENV{PATH} "${PROJECT_SOURCE_DIR}/local-lib/bin${ENV_PATH_SEPARATOR}$ENV{PATH}") set(ENV{PATH} "${PROJECT_SOURCE_DIR}/local-lib/bin${ENV_PATH_SEPARATOR}$ENV{PATH}")
set(ENV{PERL5LIB} "${PROJECT_SOURCE_DIR}/local-lib/lib/perl${ENV_PATH_SEPARATOR}$ENV{PERL5LIB}") set(PERL_INCLUDE "${PROJECT_SOURCE_DIR}/local-lib/lib/perl5${ENV_PATH_SEPARATOR}$ENV{PERL5LIB}")
message("PATH: $ENV{PATH}") message("PATH: $ENV{PATH}")
message("PERL5LIB: $ENV{PERL5LIB}") message("PERL_INCLUDE: ${PERL_INCLUDE}")
find_package(Perl REQUIRED) find_package(Perl REQUIRED)
if (WIN32)
# On Windows passing the PERL5LIB variable causes various problems (such as with MAX_PATH and others),
# basically I've found no good way to do it on Windows.
set(PERL5LIB_ENV_CMD "")
else()
set(PERL5LIB_ENV_CMD ${CMAKE_COMMAND} -E env PERL5LIB=${PERL_INCLUDE})
endif()
# CMAKE_PREFIX_PATH is used to point CMake to the remaining dependencies (Boost, TBB, ...) # CMAKE_PREFIX_PATH is used to point CMake to the remaining dependencies (Boost, TBB, ...)
# We pick it from environment if it is not defined in another way # We pick it from environment if it is not defined in another way

View File

@ -167,6 +167,7 @@ sub thread_cleanup {
*Slic3r::GUI::PresetHints::DESTROY = sub {}; *Slic3r::GUI::PresetHints::DESTROY = sub {};
*Slic3r::GUI::TabIface::DESTROY = sub {}; *Slic3r::GUI::TabIface::DESTROY = sub {};
*Slic3r::OctoPrint::DESTROY = sub {}; *Slic3r::OctoPrint::DESTROY = sub {};
*Slic3r::Duet::DESTROY = sub {};
*Slic3r::PresetUpdater::DESTROY = sub {}; *Slic3r::PresetUpdater::DESTROY = sub {};
return undef; # this prevents a "Scalars leaked" warning return undef; # this prevents a "Scalars leaked" warning
} }

View File

@ -53,7 +53,7 @@ sub new {
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
$self->{config} = Slic3r::Config::new_from_defaults_keys([qw( $self->{config} = Slic3r::Config::new_from_defaults_keys([qw(
bed_shape complete_objects extruder_clearance_radius skirts skirt_distance brim_width variable_layer_height bed_shape complete_objects extruder_clearance_radius skirts skirt_distance brim_width variable_layer_height
serial_port serial_speed octoprint_host octoprint_apikey octoprint_cafile serial_port serial_speed host_type print_host printhost_apikey printhost_cafile
nozzle_diameter single_extruder_multi_material wipe_tower wipe_tower_x wipe_tower_y wipe_tower_width nozzle_diameter single_extruder_multi_material wipe_tower wipe_tower_x wipe_tower_y wipe_tower_width
wipe_tower_rotation_angle extruder_colour filament_colour max_print_height printer_model wipe_tower_rotation_angle extruder_colour filament_colour max_print_height printer_model
)]); )]);
@ -1569,7 +1569,7 @@ sub on_export_completed {
$message = L("File added to print queue"); $message = L("File added to print queue");
$do_print = 1; $do_print = 1;
} elsif ($self->{send_gcode_file}) { } elsif ($self->{send_gcode_file}) {
$message = L("Sending G-code file to the OctoPrint server..."); $message = L("Sending G-code file to the Printer Host ...");
$send_gcode = 1; $send_gcode = 1;
} else { } else {
$message = L("G-code file exported to ") . $self->{export_gcode_output_file}; $message = L("G-code file exported to ") . $self->{export_gcode_output_file};
@ -1585,9 +1585,10 @@ sub on_export_completed {
# Send $self->{send_gcode_file} to OctoPrint. # Send $self->{send_gcode_file} to OctoPrint.
if ($send_gcode) { if ($send_gcode) {
my $op = Slic3r::OctoPrint->new($self->{config}); my $host = Slic3r::PrintHost::get_print_host($self->{config});
if ($op->send_gcode($self->{send_gcode_file})) {
$self->statusbar->SetStatusText(L("OctoPrint upload finished.")); if ($host->send_gcode($self->{send_gcode_file})) {
$self->statusbar->SetStatusText(L("Upload to host finished."));
} else { } else {
$self->statusbar->SetStatusText(""); $self->statusbar->SetStatusText("");
} }
@ -1914,8 +1915,8 @@ sub on_config_change {
} elsif ($opt_key eq 'serial_port') { } elsif ($opt_key eq 'serial_port') {
$self->{btn_print}->Show($config->get('serial_port')); $self->{btn_print}->Show($config->get('serial_port'));
$self->Layout; $self->Layout;
} elsif ($opt_key eq 'octoprint_host') { } elsif ($opt_key eq 'print_host') {
$self->{btn_send_gcode}->Show($config->get('octoprint_host')); $self->{btn_send_gcode}->Show($config->get('print_host'));
$self->Layout; $self->Layout;
} elsif ($opt_key eq 'variable_layer_height') { } elsif ($opt_key eq 'variable_layer_height') {
if ($config->get('variable_layer_height') != 1) { if ($config->get('variable_layer_height') != 1) {

View File

@ -251,8 +251,14 @@ add_library(libslic3r_gui STATIC
${LIBDIR}/slic3r/Utils/Http.hpp ${LIBDIR}/slic3r/Utils/Http.hpp
${LIBDIR}/slic3r/Utils/FixModelByWin10.cpp ${LIBDIR}/slic3r/Utils/FixModelByWin10.cpp
${LIBDIR}/slic3r/Utils/FixModelByWin10.hpp ${LIBDIR}/slic3r/Utils/FixModelByWin10.hpp
${LIBDIR}/slic3r/Utils/PrintHostSendDialog.cpp
${LIBDIR}/slic3r/Utils/PrintHostSendDialog.hpp
${LIBDIR}/slic3r/Utils/OctoPrint.cpp ${LIBDIR}/slic3r/Utils/OctoPrint.cpp
${LIBDIR}/slic3r/Utils/OctoPrint.hpp ${LIBDIR}/slic3r/Utils/OctoPrint.hpp
${LIBDIR}/slic3r/Utils/Duet.cpp
${LIBDIR}/slic3r/Utils/Duet.hpp
${LIBDIR}/slic3r/Utils/PrintHost.cpp
${LIBDIR}/slic3r/Utils/PrintHost.hpp
${LIBDIR}/slic3r/Utils/Bonjour.cpp ${LIBDIR}/slic3r/Utils/Bonjour.cpp
${LIBDIR}/slic3r/Utils/Bonjour.hpp ${LIBDIR}/slic3r/Utils/Bonjour.hpp
${LIBDIR}/slic3r/Utils/PresetUpdater.cpp ${LIBDIR}/slic3r/Utils/PresetUpdater.cpp
@ -367,7 +373,7 @@ set(MyTypemap ${CMAKE_CURRENT_BINARY_DIR}/typemap)
add_custom_command( add_custom_command(
OUTPUT ${MyTypemap} OUTPUT ${MyTypemap}
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/xsp/my.map DEPENDS ${CMAKE_CURRENT_LIST_DIR}/xsp/my.map
COMMAND ${PERL_EXECUTABLE} -MExtUtils::Typemaps -MExtUtils::Typemaps::Basic -e "$typemap = ExtUtils::Typemaps->new(file => \"${CMAKE_CURRENT_LIST_DIR}/xsp/my.map\"); $typemap->merge(typemap => ExtUtils::Typemaps::Basic->new); $typemap->write(file => \"${MyTypemap}\")" COMMAND ${PERL5LIB_ENV_CMD} ${PERL_EXECUTABLE} -MExtUtils::Typemaps -MExtUtils::Typemaps::Basic -e "$typemap = ExtUtils::Typemaps->new(file => \"${CMAKE_CURRENT_LIST_DIR}/xsp/my.map\"); $typemap->merge(typemap => ExtUtils::Typemaps::Basic->new); $typemap->write(file => \"${MyTypemap}\")"
VERBATIM VERBATIM
) )
@ -411,7 +417,7 @@ set(XS_XSP_FILES
${XSP_DIR}/Surface.xsp ${XSP_DIR}/Surface.xsp
${XSP_DIR}/SurfaceCollection.xsp ${XSP_DIR}/SurfaceCollection.xsp
${XSP_DIR}/TriangleMesh.xsp ${XSP_DIR}/TriangleMesh.xsp
${XSP_DIR}/Utils_OctoPrint.xsp ${XSP_DIR}/Utils_PrintHost.xsp
${XSP_DIR}/Utils_PresetUpdater.xsp ${XSP_DIR}/Utils_PresetUpdater.xsp
${XSP_DIR}/AppController.xsp ${XSP_DIR}/AppController.xsp
${XSP_DIR}/XS.xsp ${XSP_DIR}/XS.xsp
@ -432,7 +438,8 @@ set(XS_MAIN_CPP ${CMAKE_CURRENT_BINARY_DIR}/XS.cpp)
add_custom_command( add_custom_command(
OUTPUT ${XS_MAIN_CPP} OUTPUT ${XS_MAIN_CPP}
DEPENDS ${MyTypemap} ${XS_XSP_FILES} ${CMAKE_CURRENT_LIST_DIR}/xsp/typemap.xspt DEPENDS ${MyTypemap} ${XS_XSP_FILES} ${CMAKE_CURRENT_LIST_DIR}/xsp/typemap.xspt
COMMAND COMMAND xsubpp -typemap typemap -output ${XS_MAIN_CPP} -hiertype ${XS_MAIN_XS} COMMAND ${PERL5LIB_ENV_CMD} xsubpp -typemap typemap -output ${XS_MAIN_CPP} -hiertype ${XS_MAIN_XS}
VERBATIM
) )
# Define the Perl XS shared library. # Define the Perl XS shared library.
@ -496,6 +503,14 @@ if (WIN32)
target_compile_definitions(XS PRIVATE -DNOGDI -DNOMINMAX -DHAS_BOOL) target_compile_definitions(XS PRIVATE -DNOGDI -DNOMINMAX -DHAS_BOOL)
endif () endif ()
# SLIC3R_MSVC_PDB
if (MSVC AND SLIC3R_MSVC_PDB AND ${CMAKE_BUILD_TYPE} STREQUAL "Release")
set_target_properties(XS PROPERTIES
COMPILE_FLAGS "/Zi"
LINK_FLAGS "/DEBUG /OPT:REF /OPT:ICF"
)
endif()
## Configuration flags ## Configuration flags
if (SLIC3R_GUI) if (SLIC3R_GUI)
message("Slic3r will be built with GUI support") message("Slic3r will be built with GUI support")

View File

@ -518,7 +518,7 @@ PrintConfigDef::PrintConfigDef()
def->cli = "filament-minimal-purge-on-wipe-tower=f@"; def->cli = "filament-minimal-purge-on-wipe-tower=f@";
def->sidetext = L("mm³"); def->sidetext = L("mm³");
def->min = 0; def->min = 0;
def->default_value = new ConfigOptionFloats { 5.f }; def->default_value = new ConfigOptionFloats { 15.f };
def = this->add("filament_cooling_final_speed", coFloats); def = this->add("filament_cooling_final_speed", coFloats);
def->label = L("Speed of the last cooling move"); def->label = L("Speed of the last cooling move");
@ -572,10 +572,7 @@ PrintConfigDef::PrintConfigDef()
def = this->add("filament_type", coStrings); def = this->add("filament_type", coStrings);
def->label = L("Filament type"); def->label = L("Filament type");
def->tooltip = L("If you want to process the output G-code through custom scripts, just list their " def->tooltip = L("The filament material type for use in custom G-codes.");
"absolute paths here. Separate multiple scripts with a semicolon. Scripts will be passed "
"the absolute path to the G-code file as the first argument, and they can access "
"the Slic3r config settings by reading environment variables.");
def->cli = "filament_type=s@"; def->cli = "filament_type=s@";
def->gui_type = "f_enum_open"; def->gui_type = "f_enum_open";
def->gui_flags = "show_value"; def->gui_flags = "show_value";
@ -921,7 +918,7 @@ PrintConfigDef::PrintConfigDef()
def = this->add("remaining_times", coBool); def = this->add("remaining_times", coBool);
def->label = L("Supports remaining times"); def->label = L("Supports remaining times");
def->tooltip = L("Emit M73 P[percent printed] R[remaining time in seconds] at 1 minute" def->tooltip = L("Emit M73 P[percent printed] R[remaining time in minutes] at 1 minute"
" intervals into the G-code to let the firmware show accurate remaining time." " intervals into the G-code to let the firmware show accurate remaining time."
" As of now only the Prusa i3 MK3 firmware recognizes M73." " As of now only the Prusa i3 MK3 firmware recognizes M73."
" Also the i3 MK3 firmware supports M73 Qxx Sxx for the silent mode."); " Also the i3 MK3 firmware supports M73 Qxx Sxx for the silent mode.");
@ -1140,25 +1137,37 @@ PrintConfigDef::PrintConfigDef()
def->cli = "nozzle-diameter=f@"; def->cli = "nozzle-diameter=f@";
def->default_value = new ConfigOptionFloats { 0.5 }; def->default_value = new ConfigOptionFloats { 0.5 };
def = this->add("octoprint_apikey", coString); def = this->add("host_type", coEnum);
def->label = L("API Key"); def->label = L("Host Type");
def->tooltip = L("Slic3r can upload G-code files to OctoPrint. This field should contain " def->tooltip = L("Slic3r can upload G-code files to a printer host. This field must contain "
"the API Key required for authentication."); "the kind of the host.");
def->cli = "octoprint-apikey=s"; def->cli = "host-type=s";
def->enum_keys_map = &ConfigOptionEnum<PrintHostType>::get_enum_values();
def->enum_values.push_back("octoprint");
def->enum_values.push_back("duet");
def->enum_labels.push_back("OctoPrint");
def->enum_labels.push_back("Duet");
def->default_value = new ConfigOptionEnum<PrintHostType>(htOctoPrint);
def = this->add("printhost_apikey", coString);
def->label = L("API Key / Password");
def->tooltip = L("Slic3r can upload G-code files to a printer host. This field should contain "
"the API Key or the password required for authentication.");
def->cli = "printhost-apikey=s";
def->default_value = new ConfigOptionString(""); def->default_value = new ConfigOptionString("");
def = this->add("octoprint_cafile", coString); def = this->add("printhost_cafile", coString);
def->label = "HTTPS CA file"; def->label = "HTTPS CA file";
def->tooltip = "Custom CA certificate file can be specified for HTTPS OctoPrint connections, in crt/pem format. " def->tooltip = "Custom CA certificate file can be specified for HTTPS OctoPrint connections, in crt/pem format. "
"If left blank, the default OS CA certificate repository is used."; "If left blank, the default OS CA certificate repository is used.";
def->cli = "octoprint-cafile=s"; def->cli = "printhost-cafile=s";
def->default_value = new ConfigOptionString(""); def->default_value = new ConfigOptionString("");
def = this->add("octoprint_host", coString); def = this->add("print_host", coString);
def->label = L("Hostname, IP or URL"); def->label = L("Hostname, IP or URL");
def->tooltip = L("Slic3r can upload G-code files to OctoPrint. This field should contain " def->tooltip = L("Slic3r can upload G-code files to a printer host. This field should contain "
"the hostname, IP address or URL of the OctoPrint instance."); "the hostname, IP address or URL of the printer host instance.");
def->cli = "octoprint-host=s"; def->cli = "print-host=s";
def->default_value = new ConfigOptionString(""); def->default_value = new ConfigOptionString("");
def = this->add("only_retract_when_crossing_perimeters", coBool); def = this->add("only_retract_when_crossing_perimeters", coBool);
@ -2110,10 +2119,6 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
std::ostringstream oss; std::ostringstream oss;
oss << "0x0," << p.value.x << "x0," << p.value.x << "x" << p.value.y << ",0x" << p.value.y; oss << "0x0," << p.value.x << "x0," << p.value.x << "x" << p.value.y << ",0x" << p.value.y;
value = oss.str(); value = oss.str();
// Maybe one day we will rename octoprint_host to print_host as it has been done in the upstream Slic3r.
// Commenting this out fixes github issue #869 for now.
// } else if (opt_key == "octoprint_host" && !value.empty()) {
// opt_key = "print_host";
} else if ((opt_key == "perimeter_acceleration" && value == "25") } else if ((opt_key == "perimeter_acceleration" && value == "25")
|| (opt_key == "infill_acceleration" && value == "50")) { || (opt_key == "infill_acceleration" && value == "50")) {
/* For historical reasons, the world's full of configs having these very low values; /* For historical reasons, the world's full of configs having these very low values;
@ -2124,6 +2129,12 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
} else if (opt_key == "support_material_pattern" && value == "pillars") { } else if (opt_key == "support_material_pattern" && value == "pillars") {
// Slic3r PE does not support the pillars. They never worked well. // Slic3r PE does not support the pillars. They never worked well.
value = "rectilinear"; value = "rectilinear";
} else if (opt_key == "octoprint_host") {
opt_key = "print_host";
} else if (opt_key == "octoprint_cafile") {
opt_key = "printhost_cafile";
} else if (opt_key == "octoprint_apikey") {
opt_key = "printhost_apikey";
} }
// Ignore the following obsolete configuration keys: // Ignore the following obsolete configuration keys:
@ -2133,9 +2144,6 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
"standby_temperature", "scale", "rotate", "duplicate", "duplicate_grid", "standby_temperature", "scale", "rotate", "duplicate", "duplicate_grid",
"start_perimeters_at_concave_points", "start_perimeters_at_non_overhang", "randomize_start", "start_perimeters_at_concave_points", "start_perimeters_at_non_overhang", "randomize_start",
"seal_position", "vibration_limit", "bed_size", "seal_position", "vibration_limit", "bed_size",
// Maybe one day we will rename octoprint_host to print_host as it has been done in the upstream Slic3r.
// Commenting this out fixes github issue #869 for now.
// "octoprint_host",
"print_center", "g0", "threads", "pressure_advance", "wipe_tower_per_color_wipe" "print_center", "g0", "threads", "pressure_advance", "wipe_tower_per_color_wipe"
}; };
@ -2145,7 +2153,6 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
} }
if (! print_config_def.has(opt_key)) { if (! print_config_def.has(opt_key)) {
//printf("Unknown option %s\n", opt_key.c_str());
opt_key = ""; opt_key = "";
return; return;
} }

View File

@ -27,6 +27,10 @@ enum GCodeFlavor {
gcfSmoothie, gcfNoExtrusion, gcfSmoothie, gcfNoExtrusion,
}; };
enum PrintHostType {
htOctoPrint, htDuet,
};
enum InfillPattern { enum InfillPattern {
ipRectilinear, ipGrid, ipTriangles, ipStars, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb, ipRectilinear, ipGrid, ipTriangles, ipStars, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb,
ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral,
@ -61,6 +65,15 @@ template<> inline t_config_enum_values& ConfigOptionEnum<GCodeFlavor>::get_enum_
return keys_map; return keys_map;
} }
template<> inline t_config_enum_values& ConfigOptionEnum<PrintHostType>::get_enum_values() {
static t_config_enum_values keys_map;
if (keys_map.empty()) {
keys_map["octoprint"] = htOctoPrint;
keys_map["duet"] = htDuet;
}
return keys_map;
}
template<> inline t_config_enum_values& ConfigOptionEnum<InfillPattern>::get_enum_values() { template<> inline t_config_enum_values& ConfigOptionEnum<InfillPattern>::get_enum_values() {
static t_config_enum_values keys_map; static t_config_enum_values keys_map;
if (keys_map.empty()) { if (keys_map.empty()) {
@ -789,18 +802,20 @@ class HostConfig : public StaticPrintConfig
{ {
STATIC_PRINT_CONFIG_CACHE(HostConfig) STATIC_PRINT_CONFIG_CACHE(HostConfig)
public: public:
ConfigOptionString octoprint_host; ConfigOptionEnum<PrintHostType> host_type;
ConfigOptionString octoprint_apikey; ConfigOptionString print_host;
ConfigOptionString octoprint_cafile; ConfigOptionString printhost_apikey;
ConfigOptionString printhost_cafile;
ConfigOptionString serial_port; ConfigOptionString serial_port;
ConfigOptionInt serial_speed; ConfigOptionInt serial_speed;
protected: protected:
void initialize(StaticCacheBase &cache, const char *base_ptr) void initialize(StaticCacheBase &cache, const char *base_ptr)
{ {
OPT_PTR(octoprint_host); OPT_PTR(host_type);
OPT_PTR(octoprint_apikey); OPT_PTR(print_host);
OPT_PTR(octoprint_cafile); OPT_PTR(printhost_apikey);
OPT_PTR(printhost_cafile);
OPT_PTR(serial_port); OPT_PTR(serial_port);
OPT_PTR(serial_speed); OPT_PTR(serial_speed);
} }

View File

@ -64,9 +64,9 @@ REGISTER_CLASS(PresetCollection, "GUI::PresetCollection");
REGISTER_CLASS(PresetBundle, "GUI::PresetBundle"); REGISTER_CLASS(PresetBundle, "GUI::PresetBundle");
REGISTER_CLASS(TabIface, "GUI::Tab"); REGISTER_CLASS(TabIface, "GUI::Tab");
REGISTER_CLASS(PresetUpdater, "PresetUpdater"); REGISTER_CLASS(PresetUpdater, "PresetUpdater");
REGISTER_CLASS(OctoPrint, "OctoPrint");
REGISTER_CLASS(AppController, "AppController"); REGISTER_CLASS(AppController, "AppController");
REGISTER_CLASS(PrintController, "PrintController"); REGISTER_CLASS(PrintController, "PrintController");
REGISTER_CLASS(PrintHost, "PrintHost");
SV* ConfigBase__as_hash(ConfigBase* THIS) SV* ConfigBase__as_hash(ConfigBase* THIS)
{ {

View File

@ -586,6 +586,8 @@ boost::any& Choice::get_value()
m_value = static_cast<SupportMaterialPattern>(ret_enum); m_value = static_cast<SupportMaterialPattern>(ret_enum);
else if (m_opt_id.compare("seam_position") == 0) else if (m_opt_id.compare("seam_position") == 0)
m_value = static_cast<SeamPosition>(ret_enum); m_value = static_cast<SeamPosition>(ret_enum);
else if (m_opt_id.compare("host_type") == 0)
m_value = static_cast<PrintHostType>(ret_enum);
} }
return m_value; return m_value;

View File

@ -604,6 +604,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
config.set_key_value(opt_key, new ConfigOptionEnum<SupportMaterialPattern>(boost::any_cast<SupportMaterialPattern>(value))); config.set_key_value(opt_key, new ConfigOptionEnum<SupportMaterialPattern>(boost::any_cast<SupportMaterialPattern>(value)));
else if (opt_key.compare("seam_position") == 0) else if (opt_key.compare("seam_position") == 0)
config.set_key_value(opt_key, new ConfigOptionEnum<SeamPosition>(boost::any_cast<SeamPosition>(value))); config.set_key_value(opt_key, new ConfigOptionEnum<SeamPosition>(boost::any_cast<SeamPosition>(value)));
else if (opt_key.compare("host_type") == 0)
config.set_key_value(opt_key, new ConfigOptionEnum<PrintHostType>(boost::any_cast<PrintHostType>(value)));
} }
break; break;
case coPoints:{ case coPoints:{

View File

@ -459,8 +459,12 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
else if (opt_key.compare("support_material_pattern") == 0){ else if (opt_key.compare("support_material_pattern") == 0){
ret = static_cast<int>(config.option<ConfigOptionEnum<SupportMaterialPattern>>(opt_key)->value); ret = static_cast<int>(config.option<ConfigOptionEnum<SupportMaterialPattern>>(opt_key)->value);
} }
else if (opt_key.compare("seam_position") == 0) else if (opt_key.compare("seam_position") == 0){
ret = static_cast<int>(config.option<ConfigOptionEnum<SeamPosition>>(opt_key)->value); ret = static_cast<int>(config.option<ConfigOptionEnum<SeamPosition>>(opt_key)->value);
}
else if (opt_key.compare("host_type") == 0){
ret = static_cast<int>(config.option<ConfigOptionEnum<PrintHostType>>(opt_key)->value);
}
} }
break; break;
case coPoints: case coPoints:

View File

@ -329,8 +329,8 @@ const std::vector<std::string>& Preset::printer_options()
static std::vector<std::string> s_opts; static std::vector<std::string> s_opts;
if (s_opts.empty()) { if (s_opts.empty()) {
s_opts = { s_opts = {
"bed_shape", "z_offset", "gcode_flavor", "use_relative_e_distances", "serial_port", "serial_speed", "bed_shape", "z_offset", "gcode_flavor", "use_relative_e_distances", "serial_port", "serial_speed", "host_type",
"octoprint_host", "octoprint_apikey", "octoprint_cafile", "use_firmware_retraction", "use_volumetric_e", "variable_layer_height", "print_host", "printhost_apikey", "printhost_cafile", "use_firmware_retraction", "use_volumetric_e", "variable_layer_height",
"single_extruder_multi_material", "start_gcode", "end_gcode", "before_layer_gcode", "layer_gcode", "toolchange_gcode", "single_extruder_multi_material", "start_gcode", "end_gcode", "before_layer_gcode", "layer_gcode", "toolchange_gcode",
"between_objects_gcode", "printer_vendor", "printer_model", "printer_variant", "printer_notes", "cooling_tube_retraction", "between_objects_gcode", "printer_vendor", "printer_model", "printer_variant", "printer_notes", "cooling_tube_retraction",
"cooling_tube_length", "parking_pos_retraction", "extra_loading_move", "max_print_height", "default_print_profile", "inherits", "cooling_tube_length", "parking_pos_retraction", "extra_loading_move", "max_print_height", "default_print_profile", "inherits",

View File

@ -5,7 +5,7 @@
#include "../../libslic3r/Utils.hpp" #include "../../libslic3r/Utils.hpp"
#include "slic3r/Utils/Http.hpp" #include "slic3r/Utils/Http.hpp"
#include "slic3r/Utils/OctoPrint.hpp" #include "slic3r/Utils/PrintHost.hpp"
#include "slic3r/Utils/Serial.hpp" #include "slic3r/Utils/Serial.hpp"
#include "BonjourDialog.hpp" #include "BonjourDialog.hpp"
#include "WipeTowerDialog.hpp" #include "WipeTowerDialog.hpp"
@ -1521,10 +1521,12 @@ void TabPrinter::build()
optgroup->append_line(line); optgroup->append_line(line);
} }
optgroup = page->new_optgroup(_(L("OctoPrint upload"))); optgroup = page->new_optgroup(_(L("Printer Host upload")));
auto octoprint_host_browse = [this, optgroup] (wxWindow* parent) { optgroup->append_single_option_line("host_type");
auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
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)); btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn); sizer->Add(btn);
@ -1532,47 +1534,50 @@ void TabPrinter::build()
btn->Bind(wxEVT_BUTTON, [this, parent, optgroup](wxCommandEvent e) { btn->Bind(wxEVT_BUTTON, [this, parent, optgroup](wxCommandEvent e) {
BonjourDialog dialog(parent); BonjourDialog dialog(parent);
if (dialog.show_and_lookup()) { if (dialog.show_and_lookup()) {
optgroup->set_value("octoprint_host", std::move(dialog.get_selected()), true); optgroup->set_value("print_host", std::move(dialog.get_selected()), true);
} }
}); });
return sizer; return sizer;
}; };
auto octoprint_host_test = [this](wxWindow* parent) { auto print_host_test = [this](wxWindow* parent) {
auto btn = m_octoprint_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")), auto btn = m_print_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")),
wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("wrench.png")), wxBITMAP_TYPE_PNG)); btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("wrench.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn); sizer->Add(btn);
btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) { btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {
OctoPrint octoprint(m_config); std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
wxString msg; if (! host) {
if (octoprint.test(msg)) { const auto text = wxString::Format("%s",
show_info(this, _(L("Connection to OctoPrint works correctly.")), _(L("Success!"))); _(L("Could not get a valid Printer Host reference")));
} else {
const auto text = 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."))
);
show_error(this, text); 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; return sizer;
}; };
Line host_line = optgroup->create_single_option_line("octoprint_host"); Line host_line = optgroup->create_single_option_line("print_host");
host_line.append_widget(octoprint_host_browse); host_line.append_widget(printhost_browse);
host_line.append_widget(octoprint_host_test); host_line.append_widget(print_host_test);
optgroup->append_line(host_line); optgroup->append_line(host_line);
optgroup->append_single_option_line("octoprint_apikey"); optgroup->append_single_option_line("printhost_apikey");
if (Http::ca_file_supported()) { if (Http::ca_file_supported()) {
Line cafile_line = optgroup->create_single_option_line("octoprint_cafile"); Line cafile_line = optgroup->create_single_option_line("printhost_cafile");
auto octoprint_cafile_browse = [this, optgroup] (wxWindow* parent) { auto printhost_cafile_browse = [this, optgroup] (wxWindow* parent) {
auto btn = new wxButton(parent, wxID_ANY, _(L(" Browse "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT); 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)); btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("zoom.png")), wxBITMAP_TYPE_PNG));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
@ -1582,17 +1587,17 @@ void TabPrinter::build()
static const auto filemasks = _(L("Certificate files (*.crt, *.pem)|*.crt;*.pem|All files|*.*")); 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); wxFileDialog openFileDialog(this, _(L("Open CA certificate file")), "", "", filemasks, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() != wxID_CANCEL) { if (openFileDialog.ShowModal() != wxID_CANCEL) {
optgroup->set_value("octoprint_cafile", std::move(openFileDialog.GetPath()), true); optgroup->set_value("printhost_cafile", std::move(openFileDialog.GetPath()), true);
} }
}); });
return sizer; return sizer;
}; };
cafile_line.append_widget(octoprint_cafile_browse); cafile_line.append_widget(printhost_cafile_browse);
optgroup->append_line(cafile_line); optgroup->append_line(cafile_line);
auto octoprint_cafile_hint = [this, optgroup] (wxWindow* parent) { auto printhost_cafile_hint = [this, optgroup] (wxWindow* parent) {
auto txt = new wxStaticText(parent, wxID_ANY, 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."))); _(L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate.")));
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
@ -1602,7 +1607,7 @@ void TabPrinter::build()
Line cafile_hint { "", "" }; Line cafile_hint { "", "" };
cafile_hint.full_width = 1; cafile_hint.full_width = 1;
cafile_hint.widget = std::move(octoprint_cafile_hint); cafile_hint.widget = std::move(printhost_cafile_hint);
optgroup->append_line(cafile_hint); optgroup->append_line(cafile_hint);
} }
@ -1897,8 +1902,12 @@ void TabPrinter::update(){
m_serial_test_btn->Disable(); m_serial_test_btn->Disable();
} }
m_octoprint_host_test_btn->Enable(!m_config->opt_string("octoprint_host").empty()); {
std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
m_print_host_test_btn->Enable(!m_config->opt_string("print_host").empty() && host->can_test());
m_printhost_browse_btn->Enable(host->has_auto_discovery());
}
bool have_multiple_extruders = m_extruders_count > 1; bool have_multiple_extruders = m_extruders_count > 1;
get_field("toolchange_gcode")->toggle(have_multiple_extruders); get_field("toolchange_gcode")->toggle(have_multiple_extruders);
get_field("single_extruder_multi_material")->toggle(have_multiple_extruders); get_field("single_extruder_multi_material")->toggle(have_multiple_extruders);

View File

@ -321,7 +321,8 @@ class TabPrinter : public Tab
bool m_rebuild_kinematics_page = false; bool m_rebuild_kinematics_page = false;
public: public:
wxButton* m_serial_test_btn; wxButton* m_serial_test_btn;
wxButton* m_octoprint_host_test_btn; wxButton* m_print_host_test_btn;
wxButton* m_printhost_browse_btn;
size_t m_extruders_count; size_t m_extruders_count;
size_t m_extruders_count_old = 0; size_t m_extruders_count_old = 0;

View File

@ -0,0 +1,279 @@
#include "Duet.hpp"
#include "PrintHostSendDialog.hpp"
#include <algorithm>
#include <ctime>
#include <boost/filesystem/path.hpp>
#include <boost/format.hpp>
#include <boost/log/trivial.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <wx/frame.h>
#include <wx/event.h>
#include <wx/progdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include "libslic3r/PrintConfig.hpp"
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/MsgDialog.hpp"
#include "Http.hpp"
namespace fs = boost::filesystem;
namespace pt = boost::property_tree;
namespace Slic3r {
Duet::Duet(DynamicPrintConfig *config) :
host(config->opt_string("print_host")),
password(config->opt_string("printhost_apikey"))
{}
Duet::~Duet() {}
bool Duet::test(wxString &msg) const
{
bool connected = connect(msg);
if (connected) {
disconnect();
}
return connected;
}
wxString Duet::get_test_ok_msg () const
{
return wxString::Format("%s", _(L("Connection to Duet works correctly.")));
}
wxString Duet::get_test_failed_msg (wxString &msg) const
{
return wxString::Format("%s: %s", _(L("Could not connect to Duet")), msg);
}
bool Duet::send_gcode(const std::string &filename) const
{
enum { PROGRESS_RANGE = 1000 };
const auto errortitle = _(L("Error while uploading to the Duet"));
fs::path filepath(filename);
PrintHostSendDialog send_dialog(filepath.filename(), true);
if (send_dialog.ShowModal() != wxID_OK) { return false; }
const bool print = send_dialog.print();
const auto upload_filepath = send_dialog.filename();
const auto upload_filename = upload_filepath.filename();
const auto upload_parent_path = upload_filepath.parent_path();
wxProgressDialog progress_dialog(
_(L("Duet upload")),
_(L("Sending G-code file to Duet...")),
PROGRESS_RANGE, nullptr, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
progress_dialog.Pulse();
wxString connect_msg;
if (!connect(connect_msg)) {
auto errormsg = wxString::Format("%s: %s", errortitle, connect_msg);
GUI::show_error(&progress_dialog, std::move(errormsg));
return false;
}
bool res = true;
auto upload_cmd = get_upload_url(upload_filepath.string());
BOOST_LOG_TRIVIAL(info) << boost::format("Duet: Uploading file %1%, filename: %2%, path: %3%, print: %4%, command: %5%")
% filepath.string()
% upload_filename.string()
% upload_parent_path.string()
% print
% upload_cmd;
auto http = Http::post(std::move(upload_cmd));
http.set_post_body(filename)
.on_complete([&](std::string body, unsigned status) {
BOOST_LOG_TRIVIAL(debug) << boost::format("Duet: File uploaded: HTTP %1%: %2%") % status % body;
progress_dialog.Update(PROGRESS_RANGE);
int err_code = get_err_code_from_body(body);
if (err_code != 0) {
auto msg = format_error(body, L("Unknown error occured"), 0);
GUI::show_error(&progress_dialog, std::move(msg));
res = false;
} else if (print) {
wxString errormsg;
res = start_print(errormsg, upload_filepath.string());
if (!res) {
GUI::show_error(&progress_dialog, std::move(errormsg));
}
}
})
.on_error([&](std::string body, std::string error, unsigned status) {
BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Error uploading file: %1%, HTTP %2%, body: `%3%`") % error % status % body;
auto errormsg = wxString::Format("%s: %s", errortitle, format_error(body, error, status));
GUI::show_error(&progress_dialog, std::move(errormsg));
res = false;
})
.on_progress([&](Http::Progress progress, bool &cancel) {
if (cancel) {
// Upload was canceled
res = false;
} else if (progress.ultotal > 0) {
int value = PROGRESS_RANGE * progress.ulnow / progress.ultotal;
cancel = !progress_dialog.Update(std::min(value, PROGRESS_RANGE - 1)); // Cap the value to prevent premature dialog closing
} else {
cancel = !progress_dialog.Pulse();
}
})
.perform_sync();
disconnect();
return res;
}
bool Duet::has_auto_discovery() const
{
return false;
}
bool Duet::can_test() const
{
return true;
}
bool Duet::connect(wxString &msg) const
{
bool res = false;
auto url = get_connect_url();
auto http = Http::get(std::move(url));
http.on_error([&](std::string body, std::string error, unsigned status) {
BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Error connecting: %1%, HTTP %2%, body: `%3%`") % error % status % body;
msg = format_error(body, error, status);
})
.on_complete([&](std::string body, unsigned) {
BOOST_LOG_TRIVIAL(debug) << boost::format("Duet: Got: %1%") % body;
int err_code = get_err_code_from_body(body);
switch (err_code) {
case 0:
res = true;
break;
case 1:
msg = format_error(body, L("Wrong password"), 0);
break;
case 2:
msg = format_error(body, L("Could not get resources to create a new connection"), 0);
break;
default:
msg = format_error(body, L("Unknown error occured"), 0);
break;
}
})
.perform_sync();
return res;
}
void Duet::disconnect() const
{
auto url = (boost::format("%1%rr_disconnect")
% get_base_url()).str();
auto http = Http::get(std::move(url));
http.on_error([&](std::string body, std::string error, unsigned status) {
// we don't care about it, if disconnect is not working Duet will disconnect automatically after some time
BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Error disconnecting: %1%, HTTP %2%, body: `%3%`") % error % status % body;
})
.perform_sync();
}
std::string Duet::get_upload_url(const std::string &filename) const
{
return (boost::format("%1%rr_upload?name=0:/gcodes/%2%&%3%")
% get_base_url()
% filename
% timestamp_str()).str();
}
std::string Duet::get_connect_url() const
{
return (boost::format("%1%rr_connect?password=%2%&%3%")
% get_base_url()
% (password.empty() ? "reprap" : password)
% timestamp_str()).str();
}
std::string Duet::get_base_url() const
{
if (host.find("http://") == 0 || host.find("https://") == 0) {
if (host.back() == '/') {
return host;
} else {
return (boost::format("%1%/") % host).str();
}
} else {
return (boost::format("http://%1%/") % host).str();
}
}
std::string Duet::timestamp_str() const
{
enum { BUFFER_SIZE = 32 };
auto t = std::time(nullptr);
auto tm = *std::localtime(&t);
char buffer[BUFFER_SIZE];
std::strftime(buffer, BUFFER_SIZE, "time=%Y-%d-%mT%H:%M:%S", &tm);
return std::string(buffer);
}
wxString Duet::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());
}
}
bool Duet::start_print(wxString &msg, const std::string &filename) const
{
bool res = false;
auto url = (boost::format("%1%rr_gcode?gcode=M32%%20\"%2%\"")
% get_base_url()
% filename).str();
auto http = Http::get(std::move(url));
http.on_error([&](std::string body, std::string error, unsigned status) {
BOOST_LOG_TRIVIAL(error) << boost::format("Duet: Error starting print: %1%, HTTP %2%, body: `%3%`") % error % status % body;
msg = format_error(body, error, status);
})
.on_complete([&](std::string body, unsigned) {
BOOST_LOG_TRIVIAL(debug) << boost::format("Duet: Got: %1%") % body;
res = true;
})
.perform_sync();
return res;
}
int Duet::get_err_code_from_body(const std::string &body) const
{
pt::ptree root;
std::istringstream iss (body); // wrap returned json to istringstream
pt::read_json(iss, root);
return root.get<int>("err", 0);
}
}

View File

@ -0,0 +1,47 @@
#ifndef slic3r_Duet_hpp_
#define slic3r_Duet_hpp_
#include <string>
#include <wx/string.h>
#include "PrintHost.hpp"
namespace Slic3r {
class DynamicPrintConfig;
class Http;
class Duet : public PrintHost
{
public:
Duet(DynamicPrintConfig *config);
virtual ~Duet();
bool test(wxString &curl_msg) const;
wxString get_test_ok_msg () const;
wxString get_test_failed_msg (wxString &msg) const;
// Send gcode file to duet, filename is expected to be in UTF-8
bool send_gcode(const std::string &filename) const;
bool has_auto_discovery() const;
bool can_test() const;
private:
std::string host;
std::string password;
std::string get_upload_url(const std::string &filename) const;
std::string get_connect_url() const;
std::string get_base_url() const;
std::string timestamp_str() const;
bool connect(wxString &msg) const;
void disconnect() const;
bool start_print(wxString &msg, const std::string &filename) const;
int get_err_code_from_body(const std::string &body) const;
static wxString format_error(const std::string &body, const std::string &error, unsigned status);
};
}
#endif

View File

@ -4,6 +4,7 @@
#include <functional> #include <functional>
#include <thread> #include <thread>
#include <deque> #include <deque>
#include <sstream>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
@ -42,6 +43,7 @@ struct Http::priv
// Used for storing file streams added as multipart form parts // Used for storing file streams added as multipart form parts
// Using a deque here because unlike vector it doesn't ivalidate pointers on insertion // Using a deque here because unlike vector it doesn't ivalidate pointers on insertion
std::deque<fs::ifstream> form_files; std::deque<fs::ifstream> form_files;
std::string postfields;
size_t limit; size_t limit;
bool cancel; bool cancel;
@ -60,6 +62,7 @@ struct Http::priv
static size_t form_file_read_cb(char *buffer, size_t size, size_t nitems, void *userp); static size_t form_file_read_cb(char *buffer, size_t size, size_t nitems, void *userp);
void form_add_file(const char *name, const fs::path &path, const char* filename); void form_add_file(const char *name, const fs::path &path, const char* filename);
void set_post_body(const fs::path &path);
std::string curl_error(CURLcode curlcode); std::string curl_error(CURLcode curlcode);
std::string body_size_error(); std::string body_size_error();
@ -187,6 +190,13 @@ void Http::priv::form_add_file(const char *name, const fs::path &path, const cha
} }
} }
void Http::priv::set_post_body(const fs::path &path)
{
std::ifstream file(path.string());
std::string file_content { std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>() };
postfields = file_content;
}
std::string Http::priv::curl_error(CURLcode curlcode) std::string Http::priv::curl_error(CURLcode curlcode)
{ {
return (boost::format("%1% (%2%)") return (boost::format("%1% (%2%)")
@ -229,6 +239,11 @@ void Http::priv::http_perform()
::curl_easy_setopt(curl, CURLOPT_HTTPPOST, form); ::curl_easy_setopt(curl, CURLOPT_HTTPPOST, form);
} }
if (!postfields.empty()) {
::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfields.c_str());
::curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, postfields.size());
}
CURLcode res = ::curl_easy_perform(curl); CURLcode res = ::curl_easy_perform(curl);
if (res != CURLE_OK) { if (res != CURLE_OK) {
@ -338,6 +353,12 @@ Http& Http::form_add_file(const std::string &name, const fs::path &path, const s
return *this; return *this;
} }
Http& Http::set_post_body(const fs::path &path)
{
if (p) { p->set_post_body(path);}
return *this;
}
Http& Http::on_complete(CompleteFn fn) Http& Http::on_complete(CompleteFn fn)
{ {
if (p) { p->completefn = std::move(fn); } if (p) { p->completefn = std::move(fn); }

View File

@ -73,6 +73,11 @@ public:
// Same as above except also override the file's filename with a custom one // Same as above except also override the file's filename with a custom one
Http& form_add_file(const std::string &name, const boost::filesystem::path &path, const std::string &filename); Http& form_add_file(const std::string &name, const boost::filesystem::path &path, const std::string &filename);
// Set the file contents as a POST request body.
// The data is used verbatim, it is not additionally encoded in any way.
// This can be used for hosts which do not support multipart requests.
Http& set_post_body(const boost::filesystem::path &path);
// Callback called on HTTP request complete // Callback called on HTTP request complete
Http& on_complete(CompleteFn fn); Http& on_complete(CompleteFn fn);
// Callback called on an error occuring at any stage of the requests: Url parsing, DNS lookup, // Callback called on an error occuring at any stage of the requests: Url parsing, DNS lookup,

View File

@ -1,21 +1,11 @@
#include "OctoPrint.hpp" #include "OctoPrint.hpp"
#include "PrintHostSendDialog.hpp"
#include <algorithm> #include <algorithm>
#include <boost/filesystem/path.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
#include <wx/frame.h>
#include <wx/event.h>
#include <wx/progdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include "libslic3r/PrintConfig.hpp" #include "libslic3r/PrintConfig.hpp"
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/MsgDialog.hpp"
#include "Http.hpp" #include "Http.hpp"
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
@ -23,49 +13,14 @@ namespace fs = boost::filesystem;
namespace Slic3r { namespace Slic3r {
struct SendDialog : public GUI::MsgDialog
{
wxTextCtrl *txt_filename;
wxCheckBox *box_print;
SendDialog(const fs::path &path) :
MsgDialog(nullptr, _(L("Send G-Code to printer")), _(L("Upload to OctoPrint with the following filename:")), wxID_NONE),
txt_filename(new wxTextCtrl(this, wxID_ANY, path.filename().wstring())),
box_print(new wxCheckBox(this, wxID_ANY, _(L("Start printing after upload"))))
{
auto *label_dir_hint = new wxStaticText(this, wxID_ANY, _(L("Use forward slashes ( / ) as a directory separator if needed.")));
label_dir_hint->Wrap(CONTENT_WIDTH);
content_sizer->Add(txt_filename, 0, wxEXPAND);
content_sizer->Add(label_dir_hint);
content_sizer->AddSpacer(VERT_SPACING);
content_sizer->Add(box_print, 0, wxBOTTOM, 2*VERT_SPACING);
btn_sizer->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL));
txt_filename->SetFocus();
wxString stem(path.stem().wstring());
txt_filename->SetSelection(0, stem.Length());
Fit();
}
fs::path filename() const {
return fs::path(txt_filename->GetValue().wx_str());
}
bool print() const { return box_print->GetValue(); }
};
OctoPrint::OctoPrint(DynamicPrintConfig *config) : OctoPrint::OctoPrint(DynamicPrintConfig *config) :
host(config->opt_string("octoprint_host")), host(config->opt_string("print_host")),
apikey(config->opt_string("octoprint_apikey")), apikey(config->opt_string("printhost_apikey")),
cafile(config->opt_string("octoprint_cafile")) cafile(config->opt_string("printhost_cafile"))
{} {}
OctoPrint::~OctoPrint() {}
bool OctoPrint::test(wxString &msg) const bool OctoPrint::test(wxString &msg) const
{ {
// Since the request is performed synchronously here, // Since the request is performed synchronously here,
@ -91,6 +46,17 @@ bool OctoPrint::test(wxString &msg) const
return res; return res;
} }
wxString OctoPrint::get_test_ok_msg () const
{
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.")));
}
bool OctoPrint::send_gcode(const std::string &filename) const bool OctoPrint::send_gcode(const std::string &filename) const
{ {
enum { PROGRESS_RANGE = 1000 }; enum { PROGRESS_RANGE = 1000 };
@ -98,7 +64,7 @@ bool OctoPrint::send_gcode(const std::string &filename) const
const auto errortitle = _(L("Error while uploading to the OctoPrint server")); const auto errortitle = _(L("Error while uploading to the OctoPrint server"));
fs::path filepath(filename); fs::path filepath(filename);
SendDialog send_dialog(filepath.filename()); PrintHostSendDialog send_dialog(filepath.filename(), true);
if (send_dialog.ShowModal() != wxID_OK) { return false; } if (send_dialog.ShowModal() != wxID_OK) { return false; }
const bool print = send_dialog.print(); const bool print = send_dialog.print();
@ -161,6 +127,16 @@ bool OctoPrint::send_gcode(const std::string &filename) const
return res; return res;
} }
bool OctoPrint::has_auto_discovery() const
{
return true;
}
bool OctoPrint::can_test() const
{
return true;
}
void OctoPrint::set_auth(Http &http) const void OctoPrint::set_auth(Http &http) const
{ {
http.header("X-Api-Key", apikey); http.header("X-Api-Key", apikey);

View File

@ -4,6 +4,8 @@
#include <string> #include <string>
#include <wx/string.h> #include <wx/string.h>
#include "PrintHost.hpp"
namespace Slic3r { namespace Slic3r {
@ -11,14 +13,19 @@ namespace Slic3r {
class DynamicPrintConfig; class DynamicPrintConfig;
class Http; class Http;
class OctoPrint class OctoPrint : public PrintHost
{ {
public: public:
OctoPrint(DynamicPrintConfig *config); OctoPrint(DynamicPrintConfig *config);
virtual ~OctoPrint();
bool test(wxString &curl_msg) const; bool test(wxString &curl_msg) const;
wxString get_test_ok_msg () const;
wxString get_test_failed_msg (wxString &msg) const;
// Send gcode file to octoprint, filename is expected to be in UTF-8 // Send gcode file to octoprint, filename is expected to be in UTF-8
bool send_gcode(const std::string &filename) const; bool send_gcode(const std::string &filename) const;
bool has_auto_discovery() const;
bool can_test() const;
private: private:
std::string host; std::string host;
std::string apikey; std::string apikey;

View File

@ -0,0 +1,23 @@
#include "OctoPrint.hpp"
#include "Duet.hpp"
#include "libslic3r/PrintConfig.hpp"
namespace Slic3r {
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);
}
return nullptr;
}
}

View File

@ -0,0 +1,35 @@
#ifndef slic3r_PrintHost_hpp_
#define slic3r_PrintHost_hpp_
#include <memory>
#include <string>
#include <wx/string.h>
namespace Slic3r {
class DynamicPrintConfig;
class PrintHost
{
public:
virtual ~PrintHost();
virtual bool test(wxString &curl_msg) const = 0;
virtual wxString get_test_ok_msg () const = 0;
virtual wxString get_test_failed_msg (wxString &msg) const = 0;
// Send gcode file to print host, filename is expected to be in UTF-8
virtual bool send_gcode(const std::string &filename) const = 0;
virtual bool has_auto_discovery() const = 0;
virtual bool can_test() const = 0;
static PrintHost* get_print_host(DynamicPrintConfig *config);
};
}
#endif

View File

@ -0,0 +1,52 @@
#include "PrintHostSendDialog.hpp"
#include <wx/frame.h>
#include <wx/event.h>
#include <wx/progdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/MsgDialog.hpp"
namespace fs = boost::filesystem;
namespace Slic3r {
PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, bool can_start_print) :
MsgDialog(nullptr, _(L("Send G-Code to printer host")), _(L("Upload to Printer Host with the following filename:")), wxID_NONE),
txt_filename(new wxTextCtrl(this, wxID_ANY, path.filename().wstring())),
box_print(new wxCheckBox(this, wxID_ANY, _(L("Start printing after upload")))),
can_start_print(can_start_print)
{
auto *label_dir_hint = new wxStaticText(this, wxID_ANY, _(L("Use forward slashes ( / ) as a directory separator if needed.")));
label_dir_hint->Wrap(CONTENT_WIDTH);
content_sizer->Add(txt_filename, 0, wxEXPAND);
content_sizer->Add(label_dir_hint);
content_sizer->AddSpacer(VERT_SPACING);
content_sizer->Add(box_print, 0, wxBOTTOM, 2*VERT_SPACING);
btn_sizer->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL));
txt_filename->SetFocus();
wxString stem(path.stem().wstring());
txt_filename->SetSelection(0, stem.Length());
box_print->Enable(can_start_print);
Fit();
}
fs::path PrintHostSendDialog::filename() const
{
return fs::path(txt_filename->GetValue().wx_str());
}
bool PrintHostSendDialog::print() const
{
return box_print->GetValue(); }
}

View File

@ -0,0 +1,38 @@
#ifndef slic3r_PrintHostSendDialog_hpp_
#define slic3r_PrintHostSendDialog_hpp_
#include <string>
#include <boost/filesystem/path.hpp>
#include <wx/string.h>
#include <wx/frame.h>
#include <wx/event.h>
#include <wx/progdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/MsgDialog.hpp"
namespace Slic3r {
class PrintHostSendDialog : public GUI::MsgDialog
{
private:
wxTextCtrl *txt_filename;
wxCheckBox *box_print;
bool can_start_print;
public:
PrintHostSendDialog(const boost::filesystem::path &path, bool can_start_print);
boost::filesystem::path filename() const;
bool print() const;
};
}
#endif

View File

@ -1,13 +0,0 @@
%module{Slic3r::XS};
%{
#include <xsinit.h>
#include "slic3r/Utils/OctoPrint.hpp"
%}
%name{Slic3r::OctoPrint} class OctoPrint {
OctoPrint(DynamicPrintConfig *config);
~OctoPrint();
bool send_gcode(std::string filename) const;
};

View File

@ -0,0 +1,12 @@
%module{Slic3r::XS};
%{
#include <xsinit.h>
#include "slic3r/Utils/PrintHost.hpp"
%}
%name{Slic3r::PrintHost} class PrintHost {
bool send_gcode(std::string filename) const;
static PrintHost* get_print_host(DynamicPrintConfig *config);
};

View File

@ -239,9 +239,7 @@ Ref<TabIface> O_OBJECT_SLIC3R_T
PresetUpdater* O_OBJECT_SLIC3R PresetUpdater* O_OBJECT_SLIC3R
Ref<PresetUpdater> O_OBJECT_SLIC3R_T Ref<PresetUpdater> O_OBJECT_SLIC3R_T
OctoPrint* O_OBJECT_SLIC3R PrintHost* O_OBJECT_SLIC3R
Ref<OctoPrint> O_OBJECT_SLIC3R_T
Clone<OctoPrint> O_OBJECT_SLIC3R_T
Axis T_UV Axis T_UV
ExtrusionLoopRole T_UV ExtrusionLoopRole T_UV

View File

@ -270,3 +270,4 @@
}; };
%typemap{AppController*}; %typemap{AppController*};
%typemap{PrintController*}; %typemap{PrintController*};
%typemap{PrintHost*};