From 52ce6e4a7bfc8b223f68199cb79f910e26491914 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 3 Jan 2014 10:44:36 +0100 Subject: [PATCH] Some initial work for refactoring Print->extruders --- lib/Slic3r/Print.pm | 20 ++++++++++++-------- lib/Slic3r/Print/Object.pm | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index d5884c10c..f7283954c 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -18,7 +18,6 @@ has 'default_region_config' => (is => 'ro', default => sub { Slic3r::Config::Pr has 'extra_variables' => (is => 'rw', default => sub {{}}); has 'objects' => (is => 'rw', default => sub {[]}); has 'status_cb' => (is => 'rw'); -has 'extruders' => (is => 'rw', default => sub {[]}); has 'regions' => (is => 'rw', default => sub {[]}); has '_state' => (is => 'ro', default => sub { Slic3r::Print::State->new }); @@ -282,8 +281,9 @@ sub validate { } } -sub init_extruders { - my $self = shift; +# 0-based indices of used extruders +sub extruders { + my ($self) = @_; # initialize all extruder(s) we need my @used_extruders = (); @@ -298,7 +298,15 @@ sub init_extruders { qw(support_material support_material_interface); } - for my $extruder_id (keys %{{ map {$_ => 1} @used_extruders }}) { + my %h = map { $_ => 1 } @used_extruders; + return [ sort keys %h ]; +} + +sub init_extruders { + my $self = shift; + + # initialize all extruder(s) we need + for my $extruder_id (@{$self->extruders}) { # make sure print config contains a value for all extruders my %extruder_config = (); foreach my $opt_key (@{&Slic3r::Extruder::OPTIONS}) { @@ -845,10 +853,6 @@ 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]); - # initialize a motion planner for object-to-object travel moves if ($self->config->avoid_crossing_perimeters) { my $distance_from_objects = 1; diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 84dc33b36..fd07d73e5 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -758,7 +758,7 @@ sub combine_infill { my $every = $region->config->infill_every_layers; # limit the number of combined layers to the maximum height allowed by this regions' nozzle - my $nozzle_diameter = $self->print->regions->[$region_id]->extruders->{infill}->nozzle_diameter; + my $nozzle_diameter = $self->print->config->nozzle_diameter->[ $region->config->infill_extruder-1 ]; # define the combinations my @combine = (); # layer_id => thickness in layers