From 059b00a82985b4490c54cfa320f5057af49e7a46 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 30 Jan 2015 20:08:00 +0100 Subject: [PATCH] New --before-layer-change option and new layer_z placeholder. #2602 --- README.md | 3 ++- lib/Slic3r/GUI/Tab.pm | 13 +++++++++++-- lib/Slic3r/Print/GCode.pm | 5 +++++ slic3r.pl | 1 + xs/src/libslic3r/PrintConfig.cpp | 14 +++++++++++--- xs/src/libslic3r/PrintConfig.hpp | 3 +++ 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1607d0dd8..e9a14100e 100644 --- a/README.md +++ b/README.md @@ -219,7 +219,8 @@ The author of the Silk icon set is Mark James. --end-gcode Load final G-code from the supplied file. This will overwrite the default commands (turn off temperature [M104 S0], home X axis [G28 X], disable motors [M84]). - --layer-gcode Load layer-change G-code from the supplied file (default: nothing). + --before-layer-gcode Load before-layer-change G-code from the supplied file (default: nothing). + --layer-gcode Load after-layer-change G-code from the supplied file (default: nothing). --toolchange-gcode Load tool-change G-code from the supplied file (default: nothing). --seam-position Position of loop starting points (random/nearest/aligned, default: aligned). --external-perimeters-first Reverse perimeter order. (default: no) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 9a03e7e7a..6ef153191 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -945,7 +945,7 @@ sub build { octoprint_host octoprint_apikey use_firmware_retraction pressure_advance vibration_limit use_volumetric_e - start_gcode end_gcode layer_gcode toolchange_gcode + start_gcode end_gcode before_layer_gcode layer_gcode toolchange_gcode nozzle_diameter extruder_offset retract_length retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe retract_length_toolchange retract_restart_extra_toolchange @@ -1110,7 +1110,16 @@ sub build { $optgroup->append_single_option_line($option); } { - my $optgroup = $page->new_optgroup('Layer change G-code', + my $optgroup = $page->new_optgroup('Before layer change G-code', + label_width => 0, + ); + my $option = $optgroup->get_option('before_layer_gcode'); + $option->full_width(1); + $option->height(150); + $optgroup->append_single_option_line($option); + } + { + my $optgroup = $page->new_optgroup('After layer change G-code', label_width => 0, ); my $option = $optgroup->get_option('layer_gcode'); diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 56196ba31..b2c96d122 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -318,9 +318,14 @@ sub process_layer { } # set new layer - this will change Z and force a retraction if retract_layer_change is enabled + $gcode .= $self->_gcodegen->placeholder_parser->process($self->print->config->before_layer_gcode, { + layer_num => $layer->id, + layer_z => $layer->print_z, + }) . "\n" if $self->print->config->before_layer_gcode; $gcode .= $self->_gcodegen->change_layer($layer); $gcode .= $self->_gcodegen->placeholder_parser->process($self->print->config->layer_gcode, { layer_num => $layer->id, + layer_z => $layer->print_z, }) . "\n" if $self->print->config->layer_gcode; # extrude skirt diff --git a/slic3r.pl b/slic3r.pl index 585d6845b..cad1e6a8b 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -371,6 +371,7 @@ $j --end-gcode Load final G-code from the supplied file. This will overwrite the default commands (turn off temperature [M104 S0], home X axis [G28 X], disable motors [M84]). + --before-layer-gcode Load before-layer-change G-code from the supplied file (default: nothing). --layer-gcode Load layer-change G-code from the supplied file (default: nothing). --toolchange-gcode Load tool-change G-code from the supplied file (default: nothing). --seam-position Position of loop starting points (random/nearest/aligned, default: $config->{seam_position}). diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 439aef84e..1a31265e0 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -22,6 +22,14 @@ PrintConfigDef::build_def() { Options["bed_temperature"].min = 0; Options["bed_temperature"].max = 300; + Options["before_layer_gcode"].type = coString; + Options["before_layer_gcode"].label = "Before layer change G-code"; + Options["before_layer_gcode"].tooltip = "This custom code is inserted at every layer change, right before the Z move. Note that you can use placeholder variables for all Slic3r settings as well as [layer_num] and [layer_z]."; + Options["before_layer_gcode"].cli = "before-layer-gcode=s"; + Options["before_layer_gcode"].multiline = true; + Options["before_layer_gcode"].full_width = true; + Options["before_layer_gcode"].height = 50; + Options["bottom_solid_layers"].type = coInt; Options["bottom_solid_layers"].label = "Bottom"; Options["bottom_solid_layers"].category = "Layers and Perimeters"; @@ -438,9 +446,9 @@ PrintConfigDef::build_def() { Options["interface_shells"].category = "Layers and Perimeters"; Options["layer_gcode"].type = coString; - Options["layer_gcode"].label = "Layer change G-code"; - Options["layer_gcode"].tooltip = "This custom code is inserted at every layer change, right after the Z move and before the extruder moves to the first layer point. Note that you can use placeholder variables for all Slic3r settings."; - Options["layer_gcode"].cli = "layer-gcode=s"; + Options["layer_gcode"].label = "After layer change G-code"; + Options["layer_gcode"].tooltip = "This custom code is inserted at every layer change, right after the Z move and before the extruder moves to the first layer point. Note that you can use placeholder variables for all Slic3r settings as well as [layer_num] and [layer_z]."; + Options["layer_gcode"].cli = "after-layer-gcode|layer-gcode=s"; Options["layer_gcode"].multiline = true; Options["layer_gcode"].full_width = true; Options["layer_gcode"].height = 50; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index e622f2e95..4a9ea7844 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -324,6 +324,7 @@ class PrintRegionConfig : public virtual StaticPrintConfig class GCodeConfig : public virtual StaticPrintConfig { public: + ConfigOptionString before_layer_gcode; ConfigOptionString end_gcode; ConfigOptionString extrusion_axis; ConfigOptionFloats extrusion_multiplier; @@ -346,6 +347,7 @@ class GCodeConfig : public virtual StaticPrintConfig ConfigOptionBool use_volumetric_e; GCodeConfig() : StaticPrintConfig() { + this->before_layer_gcode.value = ""; this->end_gcode.value = "M104 S0 ; turn off temperature\nG28 X0 ; home X axis\nM84 ; disable motors\n"; this->extrusion_axis.value = "E"; this->extrusion_multiplier.values.resize(1); @@ -377,6 +379,7 @@ class GCodeConfig : public virtual StaticPrintConfig }; ConfigOption* option(const t_config_option_key opt_key, bool create = false) { + if (opt_key == "before_layer_gcode") return &this->before_layer_gcode; if (opt_key == "end_gcode") return &this->end_gcode; if (opt_key == "extrusion_axis") return &this->extrusion_axis; if (opt_key == "extrusion_multiplier") return &this->extrusion_multiplier;