2011-09-25 21:15:45 +00:00
|
|
|
package Slic3r::ExtrusionLoop;
|
|
|
|
use Moo;
|
|
|
|
|
2012-07-22 18:59:42 +00:00
|
|
|
use Slic3r::Geometry qw(same_point);
|
|
|
|
|
2011-12-30 18:59:51 +00:00
|
|
|
# the underlying Slic3r::Polygon objects holds the geometry
|
|
|
|
has 'polygon' => (
|
2012-05-19 15:57:38 +00:00
|
|
|
is => 'rw',
|
2011-12-30 18:59:51 +00:00
|
|
|
required => 1,
|
2012-07-02 19:26:56 +00:00
|
|
|
handles => [qw(is_printable nearest_point_index_to reverse)],
|
2011-12-30 18:59:51 +00:00
|
|
|
);
|
2011-09-25 21:15:45 +00:00
|
|
|
|
2012-10-30 13:07:50 +00:00
|
|
|
has 'flow_spacing' => (is => 'rw', required => 1);
|
2012-07-01 16:12:21 +00:00
|
|
|
|
2012-05-19 13:40:11 +00:00
|
|
|
# see EXTR_ROLE_* constants in ExtrusionPath.pm
|
2011-12-05 11:15:52 +00:00
|
|
|
has 'role' => (is => 'rw', required => 1);
|
2011-11-28 17:37:53 +00:00
|
|
|
|
2012-07-20 12:39:07 +00:00
|
|
|
use constant PACK_FMT => 'fca*';
|
2012-05-19 15:57:38 +00:00
|
|
|
|
2012-07-20 12:39:07 +00:00
|
|
|
# class or object method
|
|
|
|
sub pack {
|
2012-05-19 15:57:38 +00:00
|
|
|
my $self = shift;
|
2012-07-20 12:39:07 +00:00
|
|
|
my %args = @_;
|
|
|
|
|
|
|
|
if (ref $self) {
|
|
|
|
%args = map { $_ => $self->$_ } qw(flow_spacing role polygon);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $o = \ pack PACK_FMT,
|
|
|
|
$args{flow_spacing} || -1,
|
|
|
|
$args{role} // (die "Missing mandatory attribute 'role'"), #/
|
|
|
|
$args{polygon}->serialize;
|
|
|
|
|
|
|
|
bless $o, 'Slic3r::ExtrusionLoop::Packed';
|
|
|
|
return $o;
|
2011-12-30 18:59:51 +00:00
|
|
|
}
|
|
|
|
|
2013-03-11 11:47:27 +00:00
|
|
|
# no-op
|
|
|
|
sub unpack { $_[0] }
|
|
|
|
|
2012-07-02 19:26:56 +00:00
|
|
|
sub split_at_index {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return Slic3r::ExtrusionPath->new(
|
2012-10-30 14:29:13 +00:00
|
|
|
polyline => $self->polygon->split_at_index(@_),
|
|
|
|
role => $self->role,
|
|
|
|
flow_spacing => $self->flow_spacing,
|
2012-07-02 19:26:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-09-25 21:15:45 +00:00
|
|
|
sub split_at {
|
|
|
|
my $self = shift;
|
|
|
|
|
2012-10-30 14:29:13 +00:00
|
|
|
return Slic3r::ExtrusionPath->new(
|
|
|
|
polyline => $self->polygon->split_at(@_),
|
|
|
|
role => $self->role,
|
|
|
|
flow_spacing => $self->flow_spacing,
|
|
|
|
);
|
2011-09-25 21:15:45 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 11:03:36 +00:00
|
|
|
sub split_at_first_point {
|
|
|
|
my $self = shift;
|
2012-07-02 19:26:56 +00:00
|
|
|
return $self->split_at_index(0);
|
2012-02-19 11:03:36 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 15:09:03 +00:00
|
|
|
sub first_point {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->polygon->[0];
|
|
|
|
}
|
|
|
|
|
2012-07-20 12:39:07 +00:00
|
|
|
package Slic3r::ExtrusionLoop::Packed;
|
|
|
|
sub unpack {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my ($flow_spacing, $role, $polygon_s)
|
|
|
|
= unpack Slic3r::ExtrusionLoop::PACK_FMT, $$self;
|
|
|
|
|
|
|
|
return Slic3r::ExtrusionLoop->new(
|
|
|
|
flow_spacing => ($flow_spacing == -1) ? undef : $flow_spacing,
|
|
|
|
role => $role,
|
|
|
|
polygon => Slic3r::Polygon->deserialize($polygon_s),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-09-25 21:15:45 +00:00
|
|
|
1;
|