Simplify layer change code now that we have distinct support layers

This commit is contained in:
Alessandro Ranellucci 2013-08-09 19:46:20 +02:00
parent 548b301432
commit 4862d832b5
3 changed files with 13 additions and 21 deletions

View File

@ -17,7 +17,6 @@ has 'layer' => (is => 'rw');
has '_layer_islands' => (is => 'rw');
has '_upper_layer_islands' => (is => 'rw');
has '_layer_overhangs' => (is => 'rw');
has 'move_z_callback' => (is => 'rw');
has 'shift_x' => (is => 'rw', default => sub {0} );
has 'shift_y' => (is => 'rw', default => sub {0} );
has 'z' => (is => 'rw');
@ -132,6 +131,8 @@ sub change_layer {
$gcode .= $self->set_acceleration($self->config->default_acceleration);
}
}
$gcode .= $self->move_z($layer->print_z);
return $gcode;
}
@ -153,7 +154,6 @@ sub move_z {
$self->speed('travel');
$gcode .= $self->G0(undef, $z, 0, $comment || ('move to next layer (' . $self->layer->id . ')'))
if !defined $self->z || abs($z - ($self->z - $self->lifted)) > epsilon;
$gcode .= $self->move_z_callback->() if defined $self->move_z_callback;
} elsif ($z < $self->z && $z > ($self->z - $self->lifted + epsilon)) {
# we're moving to a layer height which is greater than the nominal current one
# (nominal = actual - lifted) and less than the actual one. we're basically

View File

@ -46,23 +46,16 @@ sub process_layer {
$self->second_layer_things_done(1);
}
# set new layer, but don't move Z as support material contact areas may need an intermediate one
# set new layer - this will change Z and force a retraction if retract_layer_change is enabled
$gcode .= $self->gcodegen->change_layer($layer);
# prepare callback to call as soon as a Z command is generated
$self->gcodegen->move_z_callback(sub {
$self->gcodegen->move_z_callback(undef); # circular ref or not?
return "" if !$Slic3r::Config->layer_gcode;
return $Slic3r::Config->replace_options($Slic3r::Config->layer_gcode, {
$gcode .= $Slic3r::Config->replace_options($Slic3r::Config->layer_gcode, {
layer_num => $self->gcodegen->layer->id,
}) . "\n";
});
}) . "\n" if $Slic3r::Config->layer_gcode;
# extrude skirt
if ((values %{$self->skirt_done}) < $Slic3r::Config->skirt_height && !$self->skirt_done->{$layer->print_z}) {
$self->gcodegen->set_shift(@{$self->shift});
$gcode .= $self->gcodegen->set_extruder($self->extruders->[0]); # move_z requires extruder
$gcode .= $self->gcodegen->move_z($layer->print_z);
$gcode .= $self->gcodegen->set_extruder($self->extruders->[0]);
# skip skirt if we have a large brim
if ($layer->id < $Slic3r::Config->skirt_height) {
# distribute skirt loops across all extruders
@ -81,8 +74,7 @@ sub process_layer {
# extrude brim
if (!$self->brim_done) {
$gcode .= $self->gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_extruder-1]); # move_z requires extruder
$gcode .= $self->gcodegen->move_z($layer->print_z);
$gcode .= $self->gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_extruder-1]);
$self->gcodegen->set_shift(@{$self->shift});
$gcode .= $self->gcodegen->extrude_loop($_, 'brim') for @{$self->print->brim};
$self->brim_done(1);
@ -98,7 +90,6 @@ sub process_layer {
# extrude support material before other things because it might use a lower Z
# and also because we avoid travelling on other things when printing it
if ($self->print->has_support_material && $layer->isa('Slic3r::Layer::Support')) {
$gcode .= $self->gcodegen->move_z($layer->print_z);
if ($layer->support_interface_fills) {
$gcode .= $self->gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_interface_extruder-1]);
$gcode .= $self->gcodegen->extrude_path($_, 'support material interface')
@ -111,9 +102,6 @@ sub process_layer {
}
}
# set actual Z - this will force a retraction
$gcode .= $self->gcodegen->move_z($layer->print_z);
# tweak region ordering to save toolchanges
my @region_ids = 0 .. ($self->print->regions_count-1);
if ($self->gcodegen->multiple_extruders) {

View File

@ -732,7 +732,7 @@ sub write_gcode {
# set up our extruder object
my $gcodegen = Slic3r::GCode->new(
config => $self->config,
extruders => $self->extruders,
extruders => $self->extruders, # we should only pass the *used* extruders (but maintain the Tx indices right!)
layer_count => $self->layer_count,
);
print $fh "G21 ; set units to millimeters\n" if $Slic3r::Config->gcode_flavor ne 'makerware';
@ -768,6 +768,10 @@ sub write_gcode {
}
}
# always start with first extruder
# TODO: make sure we select the first *used* extruder
print $fh $gcodegen->set_extruder($self->extruders->[0]);
# calculate X,Y shift to center print around specified origin
my $print_bb = $self->bounding_box;
my $print_size = $print_bb->size;