diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index ffef07066..86c7cde9c 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -1046,7 +1046,7 @@ sub build { my (%params) = @_; $self->init_config_options(qw( - bed_shape z_offset + bed_shape z_offset has_heatbed gcode_flavor use_relative_e_distances serial_port serial_speed octoprint_host octoprint_apikey @@ -1113,6 +1113,7 @@ sub build { ); $optgroup->append_single_option_line($option); } + $optgroup->append_single_option_line('has_heatbed'); $optgroup->on_change(sub { my ($opt_id) = @_; if ($opt_id eq 'extruders_count') { diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 3c32875ed..798395ba3 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -162,7 +162,7 @@ sub export { if $self->config->cooling && $self->config->disable_fan_first_layers; # set bed temperature - if ((my $temp = $self->config->first_layer_bed_temperature) && $self->config->start_gcode !~ /M(?:190|140)/i) { + if ($self->config->has_heatbed && (my $temp = $self->config->first_layer_bed_temperature) && $self->config->start_gcode !~ /M(?:190|140)/i) { printf $fh $gcodegen->writer->set_bed_temperature($temp, 1); } @@ -264,7 +264,7 @@ sub export { # is triggered, so machine has more time to reach such temperatures if ($layer->id == 0 && $finished_objects > 0) { printf $fh $gcodegen->writer->set_bed_temperature($self->config->first_layer_bed_temperature), - if $self->config->first_layer_bed_temperature; + if $self->config->first_layer_bed_temperature && $self->config->has_heatbed; $self->_print_first_layer_temperature(0); } $self->process_layer($layer, [$copy]); @@ -375,7 +375,7 @@ sub process_layer { if $temperature && $temperature != $self->config->get_at('first_layer_temperature', $extruder->id); } $gcode .= $self->_gcodegen->writer->set_bed_temperature($self->print->config->bed_temperature) - if $self->print->config->bed_temperature && $self->print->config->bed_temperature != $self->print->config->first_layer_bed_temperature; + if $self->config->has_heatbed && $self->print->config->bed_temperature && $self->print->config->bed_temperature != $self->print->config->first_layer_bed_temperature; $self->_second_layer_things_done(1); } diff --git a/t/gcode.t b/t/gcode.t index 956c579d4..ec9b7bb2a 100644 --- a/t/gcode.t +++ b/t/gcode.t @@ -1,4 +1,4 @@ -use Test::More tests => 25; +use Test::More tests => 27; use strict; use warnings; @@ -216,7 +216,6 @@ use Slic3r::Test; ok !$spiral, 'spiral vase is correctly disabled on layers with multiple loops'; } - { # Tests that the Repetier flavor produces M201 Xnnn Ynnn for resetting # acceleration, also that M204 Snnn syntax is not generated. @@ -243,4 +242,48 @@ use Slic3r::Test; ok !$has_m204, 'M204 is not generated for repetier firmware'; } +{ + # Test verifies that if has_heatbed is false, M190/M140 gcodes are not + # generated by default even if a bed temperature is set. + my $config = Slic3r::Config->new_from_defaults; + $config->set('has_heatbed', 0); + $config->set('first_layer_bed_temperature', 100); + $config->set('bed_temperature', 60); + + my $had_gcode = 0; + my $print = Slic3r::Test::init_print('cube_with_hole', config => $config); + Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + + if (($cmd eq 'M140' && exists $args->{S}) || + ($cmd eq 'M190' && exists $args->{S})) { + $had_gcode = 1; + } + }); + + ok !$had_gcode, 'M190/M140 codes are not generated if has_heatbed = 0'; +} + +{ + # Test verifies that if has_heatbed is true, M190/M140 gcodes are + # generated by default if a bed temperature is set. + my $config = Slic3r::Config->new_from_defaults; + $config->set('has_heatbed', 1); + $config->set('first_layer_bed_temperature', 100); + $config->set('bed_temperature', 60); + + my $had_gcode = 0; + my $print = Slic3r::Test::init_print('cube_with_hole', config => $config); + Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + + if (($cmd eq 'M140' && exists $args->{S}) || + ($cmd eq 'M190' && exists $args->{S})) { + $had_gcode = 1; + } + }); + + ok $had_gcode, 'M190/M140 codes are generated if has_heatbed = 1'; +} + __END__ diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 036e80e19..4197b1465 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -23,6 +23,11 @@ PrintConfigDef::PrintConfigDef() opt->values.push_back(Pointf(0,200)); def->default_value = opt; } + def = this->add("has_heatbed", coBool); + def->label = "Has heated bed"; + def->tooltip = "Unselecting this will suppress automatic generation of bed heating gcode."; + def->cli = "has_heatbed!"; + def->default_value = new ConfigOptionBool(true); def = this->add("bed_temperature", coInt); def->label = "Other layers"; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 6bc2b6099..9a446cf77 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -362,6 +362,7 @@ class PrintConfig : public GCodeConfig public: ConfigOptionBool avoid_crossing_perimeters; ConfigOptionPoints bed_shape; + ConfigOptionBool has_heatbed; ConfigOptionInt bed_temperature; ConfigOptionFloat bridge_acceleration; ConfigOptionInt bridge_fan_speed; @@ -420,6 +421,7 @@ class PrintConfig : public GCodeConfig virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(avoid_crossing_perimeters); OPT_PTR(bed_shape); + OPT_PTR(has_heatbed); OPT_PTR(bed_temperature); OPT_PTR(bridge_acceleration); OPT_PTR(bridge_fan_speed);