Merge branch 'printcpp' of github.com:sapir/Slic3r into sapir-printcpp

Conflicts:
	lib/Slic3r/GCode.pm
	lib/Slic3r/Print.pm
	lib/Slic3r/Print/Object.pm
	lib/Slic3r/Print/Region.pm
This commit is contained in:
Alessandro Ranellucci 2014-06-10 14:46:40 +02:00
commit ba8148f4ad
26 changed files with 1293 additions and 266 deletions

View file

@ -145,6 +145,7 @@ sub thread_cleanup {
*Slic3r::ExtrusionPath::DESTROY = sub {};
*Slic3r::ExtrusionPath::Collection::DESTROY = sub {};
*Slic3r::Flow::DESTROY = sub {};
*Slic3r::GCode::PlaceholderParser::DESTROY = sub {};
*Slic3r::Geometry::BoundingBox::DESTROY = sub {};
*Slic3r::Geometry::BoundingBoxf3::DESTROY = sub {};
*Slic3r::Line::DESTROY = sub {};
@ -156,7 +157,9 @@ sub thread_cleanup {
*Slic3r::Polygon::DESTROY = sub {};
*Slic3r::Polyline::DESTROY = sub {};
*Slic3r::Polyline::Collection::DESTROY = sub {};
*Slic3r::Print::DESTROY = sub {};
*Slic3r::Print::State::DESTROY = sub {};
*Slic3r::Print::Region::DESTROY = sub {};
*Slic3r::Surface::DESTROY = sub {};
*Slic3r::Surface::Collection::DESTROY = sub {};
*Slic3r::TriangleMesh::DESTROY = sub {};

View file

@ -1,60 +1,60 @@
package Slic3r::GCode::PlaceholderParser;
use Moo;
has '_single' => (is => 'ro', default => sub { {} });
has '_multiple' => (is => 'ro', default => sub { {} });
sub BUILD {
my ($self) = @_;
my $s = $self->_single;
# environment variables
$s->{$_} = $ENV{$_} for grep /^SLIC3R_/, keys %ENV;
sub new {
# TODO: move this code to C++ constructor, remove this method
my ($class) = @_;
my $self = $class->_new;
$self->apply_env_variables;
$self->update_timestamp;
return $self;
}
sub apply_env_variables {
my ($self) = @_;
$self->_single_set($_, $ENV{$_}) for grep /^SLIC3R_/, keys %ENV;
}
sub update_timestamp {
my ($self) = @_;
my $s = $self->_single;
my @lt = localtime; $lt[5] += 1900; $lt[4] += 1;
$s->{timestamp} = sprintf '%04d%02d%02d-%02d%02d%02d', @lt[5,4,3,2,1,0];
$s->{year} = $lt[5];
$s->{month} = $lt[4];
$s->{day} = $lt[3];
$s->{hour} = $lt[2];
$s->{minute} = $lt[1];
$s->{second} = $lt[0];
$s->{version} = $Slic3r::VERSION;
$self->_single_set('timestamp', sprintf '%04d%02d%02d-%02d%02d%02d', @lt[5,4,3,2,1,0]);
$self->_single_set('year', $lt[5]);
$self->_single_set('month', $lt[4]);
$self->_single_set('day', $lt[3]);
$self->_single_set('hour', $lt[2]);
$self->_single_set('minute', $lt[1]);
$self->_single_set('second', $lt[0]);
$self->_single_set('version', $Slic3r::VERSION);
}
sub apply_config {
my ($self, $config) = @_;
# options with single value
my $s = $self->_single;
my @opt_keys = grep !$Slic3r::Config::Options->{$_}{multiline}, @{$config->get_keys};
$s->{$_} = $config->serialize($_) for @opt_keys;
$self->_single_set($_, $config->serialize($_)) for @opt_keys;
# options with multiple values
my $m = $self->_multiple;
foreach my $opt_key (@opt_keys) {
my $value = $config->$opt_key;
next unless ref($value) eq 'ARRAY';
$m->{"${opt_key}_" . $_} = $value->[$_] for 0..$#$value;
$m->{$opt_key} = $value->[0];
# TODO: this is a workaroud for XS string param handling
# https://rt.cpan.org/Public/Bug/Display.html?id=94110
"$_" for @$value;
$self->_multiple_set("${opt_key}_" . $_, $value->[$_]) for 0..$#$value;
$self->_multiple_set($opt_key, $value->[0]);
if ($Slic3r::Config::Options->{$opt_key}{type} eq 'point') {
$m->{"${opt_key}_X"} = $value->[0];
$m->{"${opt_key}_Y"} = $value->[1];
$self->_multiple_set("${opt_key}_X", $value->[0]);
$self->_multiple_set("${opt_key}_Y", $value->[1]);
}
}
}
# TODO: or this could be an alias
sub set {
my ($self, $key, $val) = @_;
$self->_single->{$key} = $val;
$self->_single_set($key, $val);
}
sub process {
@ -66,15 +66,15 @@ sub process {
$string =~ s/\[($regex)\]/$extra->{$1}/eg;
}
{
my $regex = join '|', keys %{$self->_single};
$string =~ s/\[($regex)\]/$self->_single->{$1}/eg;
my $regex = join '|', @{$self->_single_keys};
$string =~ s/\[($regex)\]/$self->_single_get("$1")/eg;
}
{
my $regex = join '|', keys %{$self->_multiple};
$string =~ s/\[($regex)\]/$self->_multiple->{$1}/egx;
my $regex = join '|', @{$self->_multiple_keys};
$string =~ s/\[($regex)\]/$self->_multiple_get("$1")/egx;
# unhandled indices are populated using the first value
$string =~ s/\[($regex)_\d+\]/$self->_multiple->{$1}/egx;
$string =~ s/\[($regex)_\d+\]/$self->_multiple_get("$1")/egx;
}
return $string;

View file

@ -773,14 +773,14 @@ sub export_gcode2 {
my @warnings = ();
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
$print->status_cb(sub { $params{progressbar}->(@_) });
$print->set_status_cb(sub { $params{progressbar}->(@_) });
if ($params{export_svg}) {
$print->export_svg(output_file => $output_file);
} else {
$print->process;
$print->export_gcode(output_file => $output_file);
}
$print->status_cb(undef);
$print->set_status_cb(undef);
Slic3r::GUI::warning_catcher($self, $Slic3r::have_threads ? sub {
Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $MESSAGE_DIALOG_EVENT, shared_clone([@_])));
} : undef)->($_) for @warnings;

View file

@ -1,24 +1,19 @@
package Slic3r::Layer;
use Moo;
use List::Util qw(first);
use Slic3r::Geometry qw(scale chained_path);
use Slic3r::Geometry::Clipper qw(union_ex);
has 'id' => (is => 'rw', required => 1); # sequential number of layer, 0-based
has 'object' => (is => 'ro', weak_ref => 1, required => 1, handles => [qw(print config)]);
has 'upper_layer' => (is => 'rw', weak_ref => 1);
has 'lower_layer' => (is => 'rw', weak_ref => 1);
has 'regions' => (is => 'ro', default => sub { [] });
has 'slicing_errors' => (is => 'rw');
# the following two were previously generated by Moo
sub print {
my $self = shift;
return $self->object->print;
}
has 'slice_z' => (is => 'ro', required => 1); # Z used for slicing in unscaled coordinates
has 'print_z' => (is => 'ro', required => 1); # Z used for printing in unscaled coordinates
has 'height' => (is => 'ro', required => 1); # layer height in unscaled coordinates
# collection of expolygons generated by slicing the original geometry;
# also known as 'islands' (all regions and surface types are merged here)
has 'slices' => (is => 'rw', default => sub { Slic3r::ExPolygon::Collection->new });
sub config {
my $self = shift;
return $self->object->config;
}
# the purpose of this method is to be overridden for ::Support layers
sub islands {
@ -30,14 +25,16 @@ sub region {
my $self = shift;
my ($region_id) = @_;
for (my $i = @{$self->regions}; $i <= $region_id; $i++) {
$self->regions->[$i] //= Slic3r::Layer::Region->new(
layer => $self,
region => $self->object->print->regions->[$i],
);
while ($self->region_count <= $region_id) {
$self->add_region($self->object->print->get_region($self->region_count));
}
return $self->regions->[$region_id];
return $self->get_region($region_id);
}
sub regions {
my ($self) = @_;
return [ map $self->get_region($_), 0..($self->region_count-1) ];
}
# merge all regions' slices to get islands
@ -65,13 +62,8 @@ sub make_perimeters {
}
package Slic3r::Layer::Support;
use Moo;
extends 'Slic3r::Layer';
# ordered collection of extrusion paths to fill surfaces for support material
has 'support_islands' => (is => 'rw', default => sub { Slic3r::ExPolygon::Collection->new });
has 'support_fills' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
has 'support_interface_fills' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
our @ISA = qw(Slic3r::Layer);
sub islands {
my $self = shift;

View file

@ -1,5 +1,4 @@
package Slic3r::Layer::Region;
use Moo;
use List::Util qw(sum first);
use Slic3r::ExtrusionLoop ':roles';
@ -11,42 +10,22 @@ use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex
union diff intersection_ppl diff_ppl);
use Slic3r::Surface ':types';
has 'layer' => (
is => 'ro',
weak_ref => 1,
required => 1,
handles => [qw(id slice_z print_z height object print)],
);
has 'region' => (is => 'ro', required => 1, handles => [qw(config)]);
has 'infill_area_threshold' => (is => 'lazy');
# collection of surfaces generated by slicing the original geometry
# divided by type top/bottom/internal
has 'slices' => (is => 'rw', default => sub { Slic3r::Surface::Collection->new });
# collection of extrusion paths/loops filling gaps
has 'thin_fills' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
# collection of surfaces for infill generation
has 'fill_surfaces' => (is => 'rw', default => sub { Slic3r::Surface::Collection->new });
# collection of expolygons representing the bridged areas (thus not needing support material)
has 'bridged' => (is => 'rw', default => sub { Slic3r::ExPolygon::Collection->new });
# collection of polylines representing the unsupported bridge edges
has 'unsupported_bridge_edges' => (is => 'rw', default => sub { Slic3r::Polyline::Collection->new });
# ordered collection of extrusion paths/loops to build all perimeters
has 'perimeters' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
# ordered collection of extrusion paths to fill surfaces
has 'fills' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
sub _build_infill_area_threshold {
# TODO: lazy
sub infill_area_threshold {
my $self = shift;
return $self->flow(FLOW_ROLE_SOLID_INFILL)->scaled_spacing ** 2;
}
sub id { return $_[0]->layer->id; }
sub slice_z { return $_[0]->layer->slice_z; }
sub print_z { return $_[0]->layer->print_z; }
sub height { return $_[0]->layer->height; }
sub object { return $_[0]->layer->object; }
sub print { return $_[0]->layer->print; }
sub config { return $_[0]->region->config; }
sub flow {
my ($self, $role, $bridge, $width) = @_;
return $self->region->flow(

View file

@ -1,5 +1,4 @@
package Slic3r::Print;
use Moo;
use File::Basename qw(basename fileparse);
use File::Spec;
@ -12,22 +11,27 @@ use Slic3r::Geometry::Clipper qw(diff_ex union_ex union_pt intersection_ex inter
offset2 union union_pt_chained JT_ROUND JT_SQUARE);
use Slic3r::Print::State ':steps';
has 'config' => (is => 'ro', default => sub { Slic3r::Config::Print->new });
has 'default_object_config' => (is => 'ro', default => sub { Slic3r::Config::PrintObject->new });
has 'default_region_config' => (is => 'ro', default => sub { Slic3r::Config::PrintRegion->new });
has 'placeholder_parser' => (is => 'rw', default => sub { Slic3r::GCode::PlaceholderParser->new });
has 'objects' => (is => 'rw', default => sub {[]});
has 'status_cb' => (is => 'rw');
has 'regions' => (is => 'rw', default => sub {[]});
has 'total_used_filament' => (is => 'rw');
has 'total_extruded_volume' => (is => 'rw');
has '_state' => (is => 'ro', default => sub { Slic3r::Print::State->new });
# ordered collection of extrusion paths to build skirt loops
has 'skirt' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
our $status_cb;
# ordered collection of extrusion paths to build a brim
has 'brim' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
sub new {
# TODO: port PlaceholderParser methods to C++, then its own constructor
# can call them and no need for this new() method at all
my ($class) = @_;
my $self = $class->_new;
$self->placeholder_parser->apply_env_variables;
$self->placeholder_parser->update_timestamp;
return $self;
}
sub set_status_cb {
my ($class, $cb) = @_;
$status_cb = $cb;
}
sub status_cb {
return $status_cb;
}
sub apply_config {
my ($self, $config) = @_;
@ -74,9 +78,9 @@ sub apply_config {
# All regions now have distinct settings.
# Check whether applying the new region config defaults we'd get different regions.
my $rearrange_regions = 0;
REGION: foreach my $region_id (0..$#{$self->regions}) {
REGION: foreach my $region_id (0..($self->region_count - 1)) {
foreach my $object (@{$self->objects}) {
foreach my $volume_id (@{ $object->region_volumes->[$region_id] }) {
foreach my $volume_id (@{ $object->get_region_volumes($region_id) }) {
my $volume = $object->model_object->volumes->[$volume_id];
my $new = $self->default_region_config->clone;
@ -125,8 +129,22 @@ sub add_model_object {
my $object_config = $object->config->clone;
$object_config->normalize;
my %volumes = (); # region_id => [ volume_id, ... ]
# initialize print object and store it at the given position
my $o;
if (defined $obj_idx) {
$o = $self->set_new_object($obj_idx, $object, $object->bounding_box);
} else {
$o = $self->add_object($object, $object->bounding_box);
}
$o->set_copies([ map Slic3r::Point->new_scale(@{ $_->offset }), @{ $object->instances } ]);
$o->set_layer_height_ranges($object->layer_height_ranges);
# TODO: translate _trigger_copies to C++, then this can be done by
# PrintObject constructor
$o->_trigger_copies;
foreach my $volume_id (0..$#{$object->volumes}) {
my $volume = $object->volumes->[$volume_id];
@ -145,7 +163,7 @@ sub add_model_object {
# find an existing print region with the same config
my $region_id;
foreach my $i (0..$#{$self->regions}) {
foreach my $i (0..($self->region_count - 1)) {
my $region = $self->regions->[$i];
if ($config->equals($region->config)) {
$region_id = $i;
@ -155,58 +173,19 @@ sub add_model_object {
# if no region exists with the same config, create a new one
if (!defined $region_id) {
push @{$self->regions}, my $r = Slic3r::Print::Region->new(
print => $self,
);
my $r = $self->add_region();
$r->config->apply($config);
$region_id = $#{$self->regions};
$region_id = $self->region_count - 1;
}
# assign volume to region
$volumes{$region_id} //= [];
push @{ $volumes{$region_id} }, $volume_id;
$o->add_region_volume($region_id, $volume_id);
}
# initialize print object
my $o = Slic3r::Print::Object->new(
print => $self,
model_object => $object,
region_volumes => [ map $volumes{$_}, 0..$#{$self->regions} ],
copies => [ map Slic3r::Point->new_scale(@{ $_->offset }), @{ $object->instances } ],
layer_height_ranges => $object->layer_height_ranges,
);
# apply config to print object
$o->config->apply($self->default_object_config);
$o->config->apply_dynamic($object_config);
# store print object at the given position
if (defined $obj_idx) {
splice @{$self->objects}, $obj_idx, 0, $o;
} else {
push @{$self->objects}, $o;
}
$self->_state->invalidate(STEP_SKIRT);
$self->_state->invalidate(STEP_BRIM);
}
sub delete_object {
my ($self, $obj_idx) = @_;
splice @{$self->objects}, $obj_idx, 1;
# TODO: purge unused regions
$self->_state->invalidate(STEP_SKIRT);
$self->_state->invalidate(STEP_BRIM);
}
sub clear_objects {
my ($self) = @_;
@{$self->objects} = ();
@{$self->regions} = ();
$self->_state->invalidate(STEP_SKIRT);
$self->_state->invalidate(STEP_BRIM);
}
@ -325,9 +304,9 @@ sub init_extruders {
# this value is not supposed to be compared with $layer->id
# since they have different semantics
sub layer_count {
sub total_layer_count {
my $self = shift;
return max(map $_->layer_count, @{$self->objects});
return max(map $_->total_layer_count, @{$self->objects});
}
sub regions_count {
@ -380,7 +359,7 @@ sub process {
};
my $object_step = sub {
my ($step, $cb) = @_;
for my $obj_idx (0..$#{$self->objects}) {
for my $obj_idx (0..($self->object_count - 1)) {
my $object = $self->objects->[$obj_idx];
if (!$object->_state->done($step)) {
$object->_state->set_started($step);
@ -454,7 +433,7 @@ sub process {
items => sub {
my @items = (); # [layer_id, region_id]
for my $region_id (0 .. ($self->regions_count-1)) {
push @items, map [$_, $region_id], 0..$#{$object->layers};
push @items, map [$_, $region_id], 0..($object->layer_count - 1);
}
@items;
},
@ -760,7 +739,7 @@ sub make_brim {
my $grow_distance = $flow->scaled_width / 2;
my @islands = (); # array of polygons
foreach my $obj_idx (0 .. $#{$self->objects}) {
foreach my $obj_idx (0 .. ($self->object_count - 1)) {
my $object = $self->objects->[$obj_idx];
my $layer0 = $object->layers->[0];
my @object_islands = (
@ -914,7 +893,7 @@ sub write_gcode {
my $distance_from_objects = 1;
# compute the offsetted convex hull for each object and repeat it for each copy.
my @islands = ();
foreach my $obj_idx (0 .. $#{$self->objects}) {
foreach my $obj_idx (0 .. ($self->object_count - 1)) {
my $convex_hull = convex_hull([
map @{$_->contour}, map @{$_->slices}, @{$self->objects->[$obj_idx]->layers},
]);
@ -961,7 +940,7 @@ sub write_gcode {
if ($self->config->complete_objects) {
# print objects from the smallest to the tallest to avoid collisions
# when moving onto next object starting point
my @obj_idx = sort { $self->objects->[$a]->size->[Z] <=> $self->objects->[$b]->size->[Z] } 0..$#{$self->objects};
my @obj_idx = sort { $self->objects->[$a]->size->[Z] <=> $self->objects->[$b]->size->[Z] } 0..($self->object_count - 1);
my $finished_objects = 0;
for my $obj_idx (@obj_idx) {
@ -1008,7 +987,7 @@ sub write_gcode {
# sort layers by Z
my %layers = (); # print_z => [ [layers], [layers], [layers] ] by obj_idx
foreach my $obj_idx (0 .. $#{$self->objects}) {
foreach my $obj_idx (0 .. ($self->object_count - 1)) {
my $object = $self->objects->[$obj_idx];
foreach my $layer (@{$object->layers}, @{$object->support_layers}) {
$layers{ $layer->print_z } ||= [];

View file

@ -1,5 +1,4 @@
package Slic3r::Print::Object;
use Moo;
use List::Util qw(min max sum first);
use Slic3r::Flow ':roles';
@ -9,56 +8,38 @@ use Slic3r::Geometry::Clipper qw(diff diff_ex intersection intersection_ex union
use Slic3r::Print::State ':steps';
use Slic3r::Surface ':types';
has 'print' => (is => 'ro', weak_ref => 1, required => 1);
has 'model_object' => (is => 'ro', required => 1); # caller is responsible for holding the Model object
has 'region_volumes' => (is => 'rw', default => sub { [] }); # by region_id
has 'copies' => (is => 'ro'); # Slic3r::Point objects in scaled G-code coordinates
has 'config' => (is => 'ro', default => sub { Slic3r::Config::PrintObject->new });
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
has 'size' => (is => 'rw'); # XYZ in scaled coordinates
has '_copies_shift' => (is => 'rw'); # scaled coordinates to add to copies (to compensate for the alignment operated when creating the object but still preserving a coherent API for external callers)
has '_shifted_copies' => (is => 'rw'); # Slic3r::Point objects in scaled G-code coordinates in our coordinates
has 'layers' => (is => 'rw', default => sub { [] });
has 'support_layers' => (is => 'rw', default => sub { [] });
has 'fill_maker' => (is => 'lazy');
has '_state' => (is => 'ro', default => sub { Slic3r::Print::State->new });
sub BUILD {
my ($self) = @_;
# Compute the translation to be applied to our meshes so that we work with smaller coordinates
{
my $bb = $self->model_object->bounding_box;
# Translate meshes so that our toolpath generation algorithms work with smaller
# XY coordinates; this translation is an optimization and not strictly required.
# A cloned mesh will be aligned to 0 before slicing in _slice_region() since we
# don't assume it's already aligned and we don't alter the original position in model.
# We store the XY translation so that we can place copies correctly in the output G-code
# (copies are expressed in G-code coordinates and this translation is not publicly exposed).
$self->_copies_shift(Slic3r::Point->new_scale($bb->x_min, $bb->y_min));
$self->_trigger_copies;
# Scale the object size and store it
my $scaled_bb = $bb->clone;
$scaled_bb->scale(1 / &Slic3r::SCALING_FACTOR);
$self->size($scaled_bb->size);
}
}
sub _build_fill_maker {
# TODO: lazy
sub fill_maker {
my $self = shift;
return Slic3r::Fill->new(bounding_box => $self->bounding_box);
}
sub region_volumes {
my $self = shift;
return [ map $self->get_region_volumes($_), 0..($self->region_count - 1) ];
}
sub layers {
my $self = shift;
return [ map $self->get_layer($_), 0..($self->layer_count - 1) ];
}
sub support_layers {
my $self = shift;
return [ map $self->get_support_layer($_), 0..($self->support_layer_count - 1) ];
}
# TODO: translate to C++, then call it from constructor (see also
# Print->add_model_object)
sub _trigger_copies {
my $self = shift;
# TODO: should this mean point is 0,0?
return if !defined $self->_copies_shift;
# order copies with a nearest neighbor search and translate them by _copies_shift
$self->_shifted_copies([
$self->set_shifted_copies([
map {
my $c = $_->clone;
$c->translate(@{ $self->_copies_shift });
@ -73,28 +54,32 @@ sub _trigger_copies {
# in unscaled coordinates
sub add_copy {
my ($self, $x, $y) = @_;
push @{$self->copies}, Slic3r::Point->new_scale($x, $y);
my @copies = $self->copies;
push @copies, Slic3r::Point->new_scale($x, $y);
$self->set_copies(\@copies);
$self->_trigger_copies;
}
sub delete_last_copy {
my ($self) = @_;
pop @{$self->copies};
my @copies = $self->copies;
pop @copies;
$self->set_copies(\@copies);
$self->_trigger_copies;
}
sub delete_all_copies {
my ($self) = @_;
@{$self->copies} = ();
$self->set_copies([]);
$self->_trigger_copies;
}
# this is the *total* layer count
# this is the *total* layer count (including support layers)
# this value is not supposed to be compared with $layer->id
# since they have different semantics
sub layer_count {
sub total_layer_count {
my $self = shift;
return scalar @{ $self->layers } + scalar @{ $self->support_layers };
return $self->layer_count + $self->support_layer_count;
}
sub bounding_box {
@ -114,7 +99,7 @@ sub slice {
# init layers
{
@{$self->layers} = ();
$self->clear_layers;
# make layers taking custom heights into account
my $print_z = my $slice_z = my $height = my $id = 0;
@ -167,16 +152,10 @@ sub slice {
### Slic3r::debugf "Layer %d: height = %s; slice_z = %s; print_z = %s\n", $id, $height, $slice_z, $print_z;
push @{$self->layers}, Slic3r::Layer->new(
object => $self,
id => $id,
height => $height,
print_z => $print_z,
slice_z => $slice_z,
);
$self->add_layer($id, $height, $print_z, $slice_z);
if (@{$self->layers} >= 2) {
$self->layers->[-2]->upper_layer($self->layers->[-1]);
$self->layers->[-1]->lower_layer($self->layers->[-2]);
$self->layers->[-2]->set_upper_layer($self->layers->[-1]);
$self->layers->[-1]->set_lower_layer($self->layers->[-2]);
}
$id++;
@ -194,7 +173,7 @@ sub slice {
my @z = map $_->slice_z, @{$self->layers};
# slice all non-modifier volumes
for my $region_id (0..$#{$self->region_volumes}) {
for my $region_id (0..($self->region_count - 1)) {
my $expolygons_by_layer = $self->_slice_region($region_id, \@z, 0);
for my $layer_id (0..$#$expolygons_by_layer) {
my $layerm = $self->layers->[$layer_id]->regions->[$region_id];
@ -209,12 +188,12 @@ sub slice {
}
# then slice all modifier volumes
if (@{$self->region_volumes} > 1) {
for my $region_id (0..$#{$self->region_volumes}) {
if ($self->region_count > 1) {
for my $region_id (0..$self->region_count) {
my $expolygons_by_layer = $self->_slice_region($region_id, \@z, 1);
# loop through the other regions and 'steal' the slices belonging to this one
for my $other_region_id (0..$#{$self->region_volumes}) {
for my $other_region_id (0..$self->region_count) {
next if $other_region_id == $region_id;
for my $layer_id (0..$#$expolygons_by_layer) {
@ -248,7 +227,8 @@ sub slice {
}
# remove last layer(s) if empty
pop @{$self->layers} while @{$self->layers} && (!map @{$_->slices}, @{$self->layers->[-1]->regions});
$self->delete_layer($self->layer_count - 1)
while $self->layer_count && (!map @{$_->slices}, @{$self->layers->[-1]->regions});
foreach my $layer (@{ $self->layers }) {
# apply size compensation
@ -310,7 +290,7 @@ sub slice {
# detect slicing errors
my $warning_thrown = 0;
for my $i (0 .. $#{$self->layers}) {
for my $i (0 .. ($self->layer_count - 1)) {
my $layer = $self->layers->[$i];
next unless $layer->slicing_errors;
if (!$warning_thrown) {
@ -323,11 +303,11 @@ sub slice {
# neighbor layers
Slic3r::debugf "Attempting to repair layer %d\n", $i;
foreach my $region_id (0 .. $#{$layer->regions}) {
foreach my $region_id (0 .. ($layer->region_count - 1)) {
my $layerm = $layer->region($region_id);
my (@upper_surfaces, @lower_surfaces);
for (my $j = $i+1; $j <= $#{$self->layers}; $j++) {
for (my $j = $i+1; $j < $self->layer_count; $j++) {
if (!$self->layers->[$j]->slicing_errors) {
@upper_surfaces = @{$self->layers->[$j]->region($region_id)->slices};
last;
@ -377,11 +357,11 @@ sub slice {
sub _slice_region {
my ($self, $region_id, $z, $modifier) = @_;
return [] if !defined $self->region_volumes->[$region_id];
return [] if !@{$self->get_region_volumes($region_id)};
# compose mesh
my $mesh;
foreach my $volume_id (@{$self->region_volumes->[$region_id]}) {
foreach my $volume_id (@{ $self->get_region_volumes($region_id) }) {
my $volume = $self->model_object->volumes->[$volume_id];
next if $volume->modifier && !$modifier;
next if !$volume->modifier && $modifier;
@ -421,7 +401,7 @@ sub make_perimeters {
my $region_perimeters = $region->config->perimeters;
if ($region->config->extra_perimeters && $region_perimeters > 0 && $region->config->fill_density > 0) {
for my $i (0 .. $#{$self->layers}-1) {
for my $i (0 .. ($self->layer_count - 2)) {
my $layerm = $self->layers->[$i]->regions->[$region_id];
my $upper_layerm = $self->layers->[$i+1]->regions->[$region_id];
my $perimeter_spacing = $layerm->flow(FLOW_ROLE_PERIMETER)->scaled_spacing;
@ -471,7 +451,7 @@ sub make_perimeters {
Slic3r::parallelize(
threads => $self->print->config->threads,
items => sub { 0 .. $#{$self->layers} },
items => sub { 0 .. ($self->layer_count - 1) },
thread_cb => sub {
my $q = shift;
while (defined (my $i = $q->dequeue)) {
@ -495,7 +475,7 @@ sub detect_surfaces_type {
Slic3r::debugf "Detecting solid surfaces...\n";
for my $region_id (0 .. ($self->print->regions_count-1)) {
for my $i (0 .. $#{$self->layers}) {
for my $i (0 .. ($self->layer_count - 1)) {
my $layerm = $self->layers->[$i]->regions->[$region_id];
# prepare a reusable subroutine to make surface differences
@ -623,7 +603,7 @@ sub clip_fill_surfaces {
my $additional_margin = scale 3*0;
my $overhangs = []; # arrayref of polygons
for my $layer_id (reverse 0..$#{$self->layers}) {
for my $layer_id (reverse 0..($self->layer_count - 1)) {
my $layer = $self->layers->[$layer_id];
my @layer_internal = (); # arrayref of Surface objects
my @new_internal = (); # arrayref of Surface objects
@ -672,11 +652,11 @@ sub clip_fill_surfaces {
sub bridge_over_infill {
my $self = shift;
for my $region_id (0..$#{$self->print->regions}) {
for my $region_id (0..($self->print->region_count - 1)) {
my $fill_density = $self->print->regions->[$region_id]->config->fill_density;
next if $fill_density == 100 || $fill_density == 0;
for my $layer_id (1..$#{$self->layers}) {
for my $layer_id (1..($self->layer_count - 1)) {
my $layer = $self->layers->[$layer_id];
my $layerm = $layer->regions->[$region_id];
my $lower_layer = $self->layers->[$layer_id-1];
@ -750,7 +730,7 @@ sub process_external_surfaces {
for my $region_id (0 .. ($self->print->regions_count-1)) {
$self->layers->[0]->regions->[$region_id]->process_external_surfaces(undef);
for my $i (1 .. $#{$self->layers}) {
for my $i (1 .. ($self->layer_count - 1)) {
$self->layers->[$i]->regions->[$region_id]->process_external_surfaces($self->layers->[$i-1]);
}
}
@ -762,7 +742,7 @@ sub discover_horizontal_shells {
Slic3r::debugf "==> DISCOVERING HORIZONTAL SHELLS\n";
for my $region_id (0 .. ($self->print->regions_count-1)) {
for (my $i = 0; $i <= $#{$self->layers}; $i++) {
for (my $i = 0; $i < $self->layer_count; $i++) {
my $layerm = $self->layers->[$i]->regions->[$region_id];
if ($layerm->config->solid_infill_every_layers && $layerm->config->fill_density > 0
@ -794,7 +774,7 @@ sub discover_horizontal_shells {
abs($n - $i) <= $solid_layers-1;
($type == S_TYPE_TOP) ? $n-- : $n++) {
next if $n < 0 || $n > $#{$self->layers};
next if $n < 0 || $n >= $self->layer_count;
Slic3r::debugf " looking for neighbors on layer %d...\n", $n;
my $neighbor_layerm = $self->layers->[$n]->regions->[$region_id];

View file

@ -1,5 +1,4 @@
package Slic3r::Print::Region;
use Moo;
use Slic3r::Extruder ':roles';
use Slic3r::Flow ':roles';
@ -7,9 +6,6 @@ use Slic3r::Flow ':roles';
# A Print::Region object represents a group of volumes to print
# sharing the same config (including the same assigned extruder(s))
has 'print' => (is => 'ro', required => 1, weak_ref => 1);
has 'config' => (is => 'ro', default => sub { Slic3r::Config::PrintRegion->new});
sub flow {
my ($self, $role, $layer_height, $bridge, $first_layer, $width, $object) = @_;
@ -51,14 +47,14 @@ sub flow {
} else {
die "Unknown role $role";
}
my $nozzle_diameter = $self->print->config->get_at('nozzle_diameter', $extruder-1);
my $nozzle_diameter = $self->print_config->get_at('nozzle_diameter', $extruder-1);
return Slic3r::Flow->new_from_width(
width => $config_width,
role => $role,
nozzle_diameter => $nozzle_diameter,
layer_height => $layer_height,
bridge_flow_ratio => ($bridge ? $self->print->config->bridge_flow_ratio : 0),
bridge_flow_ratio => ($bridge ? $self->print_config->bridge_flow_ratio : 0),
);
}

View file

@ -74,14 +74,14 @@ sub set_model {
sub _before_export {
my ($self) = @_;
$self->_print->status_cb($self->status_cb);
$self->_print->set_status_cb($self->status_cb);
$self->_print->validate;
}
sub _after_export {
my ($self) = @_;
$self->_print->status_cb(undef);
$self->_print->set_status_cb(undef);
}
sub export_gcode {

View file

@ -71,17 +71,14 @@ sub generate {
# Install support layers into object.
for my $i (0 .. $#$support_z) {
push @{$object->support_layers}, Slic3r::Layer::Support->new(
object => $object,
id => $i,
height => ($i == 0) ? $support_z->[$i] : ($support_z->[$i] - $support_z->[$i-1]),
print_z => $support_z->[$i],
slice_z => -1,
slices => [],
);
$object->add_support_layer(
$i, # id
($i == 0) ? $support_z->[$i] : ($support_z->[$i] - $support_z->[$i-1]), # height
$support_z->[$i], # print_z
-1); # slice_z
if ($i >= 1) {
$object->support_layers->[-2]->upper_layer($object->support_layers->[-1]);
$object->support_layers->[-1]->lower_layer($object->support_layers->[-2]);
$object->support_layers->[-2]->set_upper_layer($object->support_layers->[-1]);
$object->support_layers->[-1]->set_lower_layer($object->support_layers->[-2]);
}
}