From f9f2361acbc9a398fef875fb447f32b9b081f53d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 28 Jun 2012 16:22:11 +0200 Subject: [PATCH] Allow setting different temperatures and first layer temperatures for each extruder. Also make support material extruder selection compatible with the new architecture --- lib/Slic3r.pm | 4 ++-- lib/Slic3r/Config.pm | 39 ++++++++++++++++++++---------------- lib/Slic3r/Extruder.pm | 8 +++++--- lib/Slic3r/GCode.pm | 17 ++++++++++++---- lib/Slic3r/GUI/SkeinPanel.pm | 2 +- lib/Slic3r/Print.pm | 34 +++++++++++++++++-------------- 6 files changed, 62 insertions(+), 42 deletions(-) diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 38084eaf..ac57be63 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -70,8 +70,6 @@ our $g0 = 0; our $gcode_comments = 0; # filament options -our $temperature = 200; -our $first_layer_temperature; our $bed_temperature = 0; our $first_layer_bed_temperature; @@ -80,6 +78,8 @@ our $extruders = []; our $nozzle_diameter = [0.5]; our $filament_diameter = [3]; # mm our $extrusion_multiplier = [1]; +our $temperature = [200]; +our $first_layer_temperature= []; # speed options our $travel_speed = 130; # mm/s diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 417dbc59..893e0d65 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -6,7 +6,7 @@ use utf8; use constant PI => 4 * atan2(1, 1); # cemetery of old config settings -our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y); +our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool); our $Options = { @@ -105,24 +105,28 @@ our $Options = { serialize => sub { join ',', @{$_[0]} }, deserialize => sub { [ split /,/, $_[0] ] }, }, - - # filament options + 'temperature' => { + label => 'Temperature (°C)', + cli => 'temperature=i@', + type => 'i', + important => 1, + serialize => sub { join ',', @{$_[0]} }, + deserialize => sub { [ split /,/, $_[0] ] }, + }, 'first_layer_temperature' => { label => 'First layer temperature (°C)', - cli => 'first-layer-temperature=i', + cli => 'first-layer-temperature=i@', type => 'i', + serialize => sub { join ',', @{$_[0]} }, + deserialize => sub { [ split /,/, $_[0] ] }, }, + + # filament options 'first_layer_bed_temperature' => { label => 'First layer bed temperature (°C)', cli => 'first-layer-bed-temperature=i', type => 'i', }, - 'temperature' => { - label => 'Temperature (°C)', - cli => 'temperature=i', - type => 'i', - important => 1, - }, 'bed_temperature' => { label => 'Bed Temperature (°C)', cli => 'bed-temperature=i', @@ -324,7 +328,6 @@ our $Options = { label => 'Extruder', cli => 'support-material-extruder=i', type => 'i', - aliases => [qw(support_material_tool)], }, 'start_gcode' => { label => 'Start G-code', @@ -680,11 +683,12 @@ sub validate { # initialize extruder(s) $Slic3r::extruders = []; - push @$Slic3r::extruders, Slic3r::Extruder->new( - nozzle_diameter => $Slic3r::nozzle_diameter->[0], - filament_diameter => $Slic3r::filament_diameter->[0], - extrusion_multiplier => $Slic3r::extrusion_multiplier->[0], - ); + for my $t (0, $Slic3r::support_material_extruder-1) { + $Slic3r::extruders->[$t] ||= Slic3r::Extruder->new( + map { $_ => Slic3r::Config->get($_)->[$t] // Slic3r::Config->get($_)->[0] } #/ + qw(nozzle_diameter filament_diameter extrusion_multiplier temperature first_layer_temperature) + ); + } # calculate flow $Slic3r::flow = $Slic3r::extruders->[0]->make_flow(width => $Slic3r::extrusion_width); @@ -775,7 +779,8 @@ sub validate { die "Invalid value for --extruder-clearance-height\n" if $Slic3r::extruder_clearance_height <= 0; - $Slic3r::first_layer_temperature //= $Slic3r::temperature; #/ + $_->first_layer_temperature($_->temperature) for grep !defined $_->first_layer_temperature, @$Slic3r::extruders; + $Slic3r::first_layer_temperature->[$_] = $Slic3r::extruders->[$_]->first_layer_temperature for 0 .. $#$Slic3r::extruders; # this is needed to provide a value to the legacy GUI and for config file re-serialization $Slic3r::first_layer_bed_temperature //= $Slic3r::bed_temperature; #/ # G-code flavors diff --git a/lib/Slic3r/Extruder.pm b/lib/Slic3r/Extruder.pm index 1dd21c31..3f06cd64 100644 --- a/lib/Slic3r/Extruder.pm +++ b/lib/Slic3r/Extruder.pm @@ -3,9 +3,11 @@ use Moo; use Slic3r::Geometry qw(PI); -has 'nozzle_diameter' => (is => 'rw', required => 1); -has 'filament_diameter' => (is => 'rw', required => 1); -has 'extrusion_multiplier' => (is => 'rw', required => 1); +has 'nozzle_diameter' => (is => 'rw', required => 1); +has 'filament_diameter' => (is => 'rw', required => 1); +has 'extrusion_multiplier' => (is => 'rw', required => 1); +has 'temperature' => (is => 'rw', required => 1); +has 'first_layer_temperature' => (is => 'rw', required => 1); has 'e_per_mmc' => (is => 'rw'); diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index 4e299669..6a1ee027 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -10,7 +10,7 @@ has 'shift_y' => (is => 'rw', default => sub {0} ); has 'z' => (is => 'rw', default => sub {0} ); has 'speed' => (is => 'rw'); -has 'extruder' => (is => 'rw', default => sub { $Slic3r::extruders->[0] }); +has 'extruder_idx' => (is => 'rw', default => sub {0}); has 'extrusion_distance' => (is => 'rw', default => sub {0} ); has 'elapsed_time' => (is => 'rw', default => sub {0} ); # seconds has 'total_extrusion_length' => (is => 'rw', default => sub {0} ); @@ -52,6 +52,11 @@ my %role_speeds = ( use Slic3r::Geometry qw(points_coincide PI X Y); +sub extruder { + my $self = shift; + return $Slic3r::extruders->[$self->extruder_idx]; +} + sub change_layer { my $self = shift; my ($layer) = @_; @@ -374,6 +379,9 @@ sub set_tool { my $self = shift; my ($tool) = @_; + return "" if $self->extruder_idx == $tool; + + $self->extruder_idx($tool); return $self->retract . sprintf "T%d%s\n", $tool, ($Slic3r::gcode_comments ? ' ; change tool' : ''); } @@ -395,15 +403,16 @@ sub set_fan { sub set_temperature { my $self = shift; - my ($temperature, $wait) = @_; + my ($temperature, $wait, $tool) = @_; return "" if $wait && $Slic3r::gcode_flavor eq 'makerbot'; my ($code, $comment) = $wait ? ('M109', 'wait for temperature to be reached') : ('M104', 'set temperature'); - return sprintf "$code %s%d ; $comment\n", - ($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature; + return sprintf "$code %s%d %s; $comment\n", + ($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature, + (defined $tool && $tool != $self->extruder_idx) ? "T$tool " : ""; } sub set_bed_temperature { diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index 7e57f676..f7a740c4 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -29,7 +29,7 @@ sub new { }, filament => { title => 'Filament', - options => [qw(filament_diameter#0 extrusion_multiplier#0 temperature first_layer_temperature bed_temperature first_layer_bed_temperature)], + options => [qw(filament_diameter#0 extrusion_multiplier#0 temperature#0 first_layer_temperature#0 bed_temperature first_layer_bed_temperature)], }, print_speed => { title => 'Print speed', diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 5a2fb98e..411bf931 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -497,10 +497,12 @@ sub write_gcode { print $fh "; $_\n" foreach split /\R/, $Slic3r::notes; print $fh "\n" if $Slic3r::notes; - for (qw(layer_height perimeters solid_layers fill_density nozzle_diameter filament_diameter - extrusion_multiplier perimeter_speed infill_speed travel_speed scale)) { + for (qw(layer_height perimeters solid_layers fill_density perimeter_speed infill_speed travel_speed scale)) { printf $fh "; %s = %s\n", $_, Slic3r::Config->get($_); } + for (qw(nozzle_diameter filament_diameter extrusion_multiplier)) { + printf $fh "; %s = %s\n", $_, Slic3r::Config->get($_)->[0]; + } printf $fh "; single wall width = %.2fmm\n", $Slic3r::flow->width; printf $fh "; first layer single wall width = %.2fmm\n", $Slic3r::first_layer_flow->width if $Slic3r::first_layer_flow; @@ -510,19 +512,21 @@ sub write_gcode { my $gcodegen = Slic3r::GCode->new; my $min_print_speed = 60 * $Slic3r::min_print_speed; my $dec = $gcodegen->dec; - if ($Slic3r::support_material && $Slic3r::support_material_extruder > 0) { - print $fh $gcodegen->set_tool(0); - } + print $fh $gcodegen->set_tool(0) if @$Slic3r::extruders > 1; print $fh $gcodegen->set_fan(0, 1) if $Slic3r::cooling && $Slic3r::disable_fan_first_layers; # write start commands to file printf $fh $gcodegen->set_bed_temperature($Slic3r::first_layer_bed_temperature, 1), if $Slic3r::first_layer_bed_temperature && $Slic3r::start_gcode !~ /M190/i; - printf $fh $gcodegen->set_temperature($Slic3r::first_layer_temperature) - if $Slic3r::first_layer_temperature; + for my $t (grep $Slic3r::extruders->[$_], 0 .. $#$Slic3r::first_layer_temperature) { + printf $fh $gcodegen->set_temperature($Slic3r::extruders->[$t]->first_layer_temperature, 0, $t) + if $Slic3r::extruders->[$t]->first_layer_temperature; + } printf $fh "%s\n", Slic3r::Config->replace_options($Slic3r::start_gcode); - printf $fh $gcodegen->set_temperature($Slic3r::first_layer_temperature, 1) - if $Slic3r::first_layer_temperature && $Slic3r::start_gcode !~ /M109/i; + for my $t (grep $Slic3r::extruders->[$_], 0 .. $#$Slic3r::first_layer_temperature) { + printf $fh $gcodegen->set_temperature($Slic3r::extruders->[$t]->first_layer_temperature, 1, $t) + if $Slic3r::extruders->[$t]->first_layer_temperature && $Slic3r::start_gcode !~ /M109/i; + } print $fh "G90 ; use absolute coordinates\n"; print $fh "G21 ; set units to millimeters\n"; if ($Slic3r::gcode_flavor =~ /^(?:reprap|teacup)$/) { @@ -551,8 +555,10 @@ sub write_gcode { my $gcode = ""; if ($layer_id == 1) { - $gcode .= $gcodegen->set_temperature($Slic3r::temperature) - if $Slic3r::temperature && $Slic3r::temperature != $Slic3r::first_layer_temperature; + for my $t (grep $Slic3r::extruders->[$_], 0 .. $#$Slic3r::temperature) { + $gcode .= $gcodegen->set_temperature($Slic3r::extruders->[$t]->temperature, 0, $t) + if $Slic3r::extruders->[$t]->temperature && $Slic3r::extruders->[$t]->temperature != $Slic3r::extruders->[$t]->first_layer_temperature; + } $gcode .= $gcodegen->set_bed_temperature($Slic3r::bed_temperature) if $Slic3r::first_layer_bed_temperature && $Slic3r::bed_temperature != $Slic3r::first_layer_bed_temperature; } @@ -601,12 +607,10 @@ sub write_gcode { # extrude support material if ($layer->support_fills) { - $gcode .= $gcodegen->set_tool($Slic3r::support_material_extruder) - if $Slic3r::support_material_extruder > 0; + $gcode .= $gcodegen->set_tool($Slic3r::support_material_extruder-1); $gcode .= $gcodegen->extrude_path($_, 'support material') for $layer->support_fills->shortest_path($gcodegen->last_pos); - $gcode .= $gcodegen->set_tool(0) - if $Slic3r::support_material_extruder > 0; + $gcode .= $gcodegen->set_tool(0); } } return if !$gcode;