1
package Slic3r::Test::SectionCut;
4
use List::Util qw(first max);
5
use Slic3r::Geometry qw(X Y A B X1 Y1 X2 Y2 unscale);
6
use Slic3r::Geometry::Clipper qw(union_ex intersection_pl);
10
has 'scale' => (is => 'ro', default => sub {30});
11
has 'print' => (is => 'ro', required => 1);
12
has 'y_percent' => (is => 'ro', default => sub {0.5});
13
has 'line' => (is => 'rw');
14
has 'height' => (is => 'rw');
19
my $bb = $self->print->bounding_box;
20
my $y = ($bb->y_min + $bb->y_max) * $self->y_percent;
21
my $line = Slic3r::Line->new([ $bb->x_min, $y ], [ $bb->x_max, $y ]);
29
my $print_size = $self->print->size;
30
$self->height(max(map $_->print_z, map @{$_->layers}, @{$self->print->objects}));
32
width => $self->scale * unscale($print_size->[X]),
33
height => $self->scale * $self->height,
38
my $g = $svg->group(style => $p{style});
39
my $items = $self->_plot($p{filter});
40
$g->rectangle(%$_) for @{ $items->{rectangles} };
41
$g->circle(%$_) for @{ $items->{circles} };
45
filter => sub { map @{$_->perimeters}, @{$_[0]->regions} },
54
filter => sub { map @{$_->fills}, @{$_[0]->regions} },
57
'stroke' => '#444444',
63
filter => sub { $_[0]->isa('Slic3r::Layer::Support') ? ($_[0]->support_fills, $_[0]->support_interface_fills) : () },
66
'stroke' => '#444444',
71
Slic3r::open(\my $fh, '>', $filename);
72
print $fh $svg->xmlify;
74
printf "Section cut SVG written to %s\n", $filename;
81
my (@rectangles, @circles) = ();
83
foreach my $object (@{$self->print->objects}) {
84
foreach my $copy (@{$object->_shifted_copies}) {
85
foreach my $layer (@{$object->layers}, @{$object->support_layers}) {
86
# get all ExtrusionPath objects
88
map { $_->isa('Slic3r::ExtrusionLoop') ? $_->split_at_first_point : $_->clone }
89
map { $_->isa('Slic3r::ExtrusionPath::Collection') ? @$_ : $_ }
93
$_->polyline->translate(@$copy) for @paths;
95
require "Slic3r/SVG.pm";
99
#polygon => $line->grow(Slic3r::Geometry::scale $path->width/2),
100
polygons => [ $object->bounding_box->polygon ],
101
lines => [ $self->line ],
102
red_polylines => [ map $_->polyline, @paths ],
106
foreach my $path (@paths) {
107
foreach my $line (@{$path->lines}) {
108
my @intersections = @{intersection_pl(
109
[ $self->line->as_polyline ],
110
$line->grow(Slic3r::Geometry::scale $path->width/2),
113
die "Intersection has more than two points!\n" if first { @$_ > 2 } @intersections;
115
if ($path->is_bridge) {
116
foreach my $line (@intersections) {
117
my $radius = $path->width / 2;
118
my $width = unscale abs($line->[B][X] - $line->[A][X]);
119
if ((10 * Slic3r::Geometry::scale $radius) < $width) {
120
# we're cutting the path in the longitudinal direction, so we've got a rectangle
122
'x' => $self->scale * unscale $line->[A][X],
123
'y' => $self->scale * $self->_y($layer->print_z),
124
'width' => $self->scale * $width,
125
'height' => $self->scale * $radius * 2,
126
'rx' => $self->scale * $radius * 0.35,
127
'ry' => $self->scale * $radius * 0.35,
131
'cx' => $self->scale * (unscale($line->[A][X]) + $radius),
132
'cy' => $self->scale * $self->_y($layer->print_z - $radius),
133
'r' => $self->scale * $radius,
138
push @rectangles, map {
139
my $height = $path->height;
140
$height = $layer->height if $height == -1;
142
'x' => $self->scale * unscale $_->[A][X],
143
'y' => $self->scale * $self->_y($layer->print_z),
144
'width' => $self->scale * unscale(abs($_->[B][X] - $_->[A][X])),
145
'height' => $self->scale * $height,
146
'rx' => $self->scale * $height * 0.35,
147
'ry' => $self->scale * $height * 0.35,
158
rectangles => \@rectangles,
159
circles => \@circles,
167
return $self->height - $y;