From 8138fbf349a33adf35a61eccd931908d15dbdbf6 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 18 Dec 2015 18:36:39 +0100 Subject: [PATCH] New --retract-lift-above and --retract-lift-below options. #763 #3057 --- README.md | 2 ++ lib/Slic3r/GUI/Tab.pm | 20 ++++++++++++++++++-- slic3r.pl | 2 ++ t/retraction.t | 27 ++++++++++++++++++++++++++- xs/src/libslic3r/GCodeWriter.cpp | 9 ++++++++- xs/src/libslic3r/Print.cpp | 2 ++ xs/src/libslic3r/PrintConfig.cpp | 24 ++++++++++++++++++++++++ xs/src/libslic3r/PrintConfig.hpp | 4 ++++ 8 files changed, 86 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f24fdfc66..7747bbd63 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,8 @@ The author of the Silk icon set is Mark James. --retract-before-travel Only retract before travel moves of this length in mm (default: 2) --retract-lift Lift Z by the given distance in mm when retracting (default: 0) + --retract-lift-above Only lift Z when above the specified height (default: 0) + --retract-lift-below Only lift Z when below the specified height (default: 0) --retract-layer-change Enforce a retraction before each Z move (default: no) --wipe Wipe the nozzle while doing a retraction (default: no) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index d7ec57d58..18c246e95 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -1257,7 +1257,7 @@ sub _extruders_count_changed { $self->_update; } -sub _extruder_options { qw(nozzle_diameter extruder_offset retract_length retract_lift retract_speed retract_restart_extra retract_before_travel wipe +sub _extruder_options { qw(nozzle_diameter extruder_offset retract_length retract_lift retract_lift_above retract_lift_below retract_speed retract_restart_extra retract_before_travel wipe retract_layer_change retract_length_toolchange retract_restart_extra_toolchange) } sub _build_extruder_pages { @@ -1293,7 +1293,19 @@ sub _build_extruder_pages { { my $optgroup = $page->new_optgroup('Retraction'); $optgroup->append_single_option_line($_, $extruder_idx) - for qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe); + for qw(retract_length retract_lift); + + { + my $line = Slic3r::GUI::OptionsGroup::Line->new( + label => 'Only lift Z', + ); + $line->append_option($optgroup->get_option('retract_lift_above', $extruder_idx)); + $line->append_option($optgroup->get_option('retract_lift_below', $extruder_idx)); + $optgroup->append_line($line); + } + + $optgroup->append_single_option_line($_, $extruder_idx) + for qw(retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe); } { my $optgroup = $page->new_optgroup('Retraction when tool is disabled (advanced settings for multi-extruder setups)'); @@ -1360,6 +1372,10 @@ sub _update { $self->get_field($_, $i)->toggle($retraction) for qw(retract_lift retract_layer_change); + # retract lift above/below only applies if using retract lift + $self->get_field($_, $i)->toggle($retraction && $config->get_at('retract_lift', $i) > 0) + for qw(retract_lift_above retract_lift_below); + # some options only apply when not using firmware retraction $self->get_field($_, $i)->toggle($retraction && !$config->use_firmware_retraction) for qw(retract_speed retract_restart_extra wipe); diff --git a/slic3r.pl b/slic3r.pl index 0fbd3bbba..b1f40847d 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -439,6 +439,8 @@ $j --retract-before-travel Only retract before travel moves of this length in mm (default: $config->{retract_before_travel}[0]) --retract-lift Lift Z by the given distance in mm when retracting (default: $config->{retract_lift}[0]) + --retract-lift-above Only lift Z when above the specified height (default: $config->{retract_lift_above}[0]) + --retract-lift-below Only lift Z when below the specified height (default: $config->{retract_lift_below}[0]) --retract-layer-change Enforce a retraction before each Z move (default: no) --wipe Wipe the nozzle while doing a retraction (default: no) diff --git a/t/retraction.t b/t/retraction.t index 4a8993ae5..05370e672 100644 --- a/t/retraction.t +++ b/t/retraction.t @@ -1,4 +1,4 @@ -use Test::More tests => 18; +use Test::More tests => 21; use strict; use warnings; @@ -7,6 +7,7 @@ BEGIN { use lib "$FindBin::Bin/../lib"; } +use List::Util qw(any); use Slic3r; use Slic3r::Test qw(_eq); @@ -200,4 +201,28 @@ use Slic3r::Test qw(_eq); ok $retracted, 'retracting also when --retract-length is 0 but --use-firmware-retraction is enabled'; } +{ + my $config = Slic3r::Config->new_from_defaults; + $config->set('start_gcode', ''); + $config->set('retract_lift', [3]); + $config->set('retract_lift_above', [5]); + $config->set('retract_lift_below', [15]); + + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + my @lifted_at = (); + Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + + if ($cmd eq 'G1' && $info->{dist_Z} < 0) { + push @lifted_at, $info->{new_Z}; + } + }); + + ok !!@lifted_at, 'lift takes place'; + ok !(any { $_ < $config->get_at('retract_lift_above', 0) } @lifted_at), + 'Z is not lifted below the configured value'; + ok !(any { $_ > $config->get_at('retract_lift_below', 0) } @lifted_at), + 'Z is not lifted above the configured value'; +} + __END__ diff --git a/xs/src/libslic3r/GCodeWriter.cpp b/xs/src/libslic3r/GCodeWriter.cpp index e6bcb8df8..3ec301d70 100644 --- a/xs/src/libslic3r/GCodeWriter.cpp +++ b/xs/src/libslic3r/GCodeWriter.cpp @@ -495,7 +495,14 @@ GCodeWriter::unretract() std::string GCodeWriter::lift() { - double target_lift = this->config.retract_lift.get_at(0); + // check whether the above/below conditions are met + double target_lift = 0; + { + double above = this->config.retract_lift_above.get_at(0); + double below = this->config.retract_lift_below.get_at(0); + if (this->_pos.z >= above && this->_pos.z <= below && below > 0) + target_lift = this->config.retract_lift.get_at(0); + } if (this->_lifted == 0 && target_lift > 0) { this->_lifted = target_lift; return this->_travel_to_z(this->_pos.z + target_lift, "lift Z"); diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 19dc63263..8d114f6e2 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -218,6 +218,8 @@ Print::invalidate_state_by_config_options(const std::vector || *opt_key == "retract_length" || *opt_key == "retract_length_toolchange" || *opt_key == "retract_lift" + || *opt_key == "retract_lift_above" + || *opt_key == "retract_lift_below" || *opt_key == "retract_restart_extra" || *opt_key == "retract_restart_extra_toolchange" || *opt_key == "retract_speed" diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 9f892400f..4ab886f9f 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -818,6 +818,30 @@ PrintConfigDef::PrintConfigDef() def->default_value = opt; } + def = this->add("retract_lift_above", coFloats); + def->label = "Above Z"; + def->full_label = "Only lift Z above"; + def->tooltip = "If you set this to a positive value, Z lift will only take place above the specified absolute Z. You can tune this setting for skipping lift on the first layers."; + def->sidetext = "mm"; + def->cli = "retract-lift-above=f@"; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(0); + def->default_value = opt; + } + + def = this->add("retract_lift_below", coFloats); + def->label = "Below Z"; + def->full_label = "Only lift Z below"; + def->tooltip = "If you set this to a positive value, Z lift will only take place below the specified absolute Z. You can tune this setting for limiting lift to the first layers."; + def->sidetext = "mm"; + def->cli = "retract-lift-below=f@"; + { + ConfigOptionFloats* opt = new ConfigOptionFloats(); + opt->values.push_back(0); + def->default_value = opt; + } + def = this->add("retract_restart_extra", coFloats); def->label = "Extra length on restart"; def->tooltip = "When the retraction is compensated after the travel move, the extruder will push this additional amount of filament. This setting is rarely needed."; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 41add7f2c..1492e61e8 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -254,6 +254,8 @@ class GCodeConfig : public virtual StaticPrintConfig ConfigOptionFloats retract_length; ConfigOptionFloats retract_length_toolchange; ConfigOptionFloats retract_lift; + ConfigOptionFloats retract_lift_above; + ConfigOptionFloats retract_lift_below; ConfigOptionFloats retract_restart_extra; ConfigOptionFloats retract_restart_extra_toolchange; ConfigOptionFloats retract_speed; @@ -283,6 +285,8 @@ class GCodeConfig : public virtual StaticPrintConfig OPT_PTR(retract_length); OPT_PTR(retract_length_toolchange); OPT_PTR(retract_lift); + OPT_PTR(retract_lift_above); + OPT_PTR(retract_lift_below); OPT_PTR(retract_restart_extra); OPT_PTR(retract_restart_extra_toolchange); OPT_PTR(retract_speed);