From 51de3ce14fe3630f1337ae95efe93d1e22e28b2f Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 29 Jul 2013 00:27:53 +0200 Subject: [PATCH] Switch print_z to unscaled coordinates --- lib/Slic3r/GCode.pm | 3 +-- lib/Slic3r/GCode/SpiralVase.pm | 2 +- lib/Slic3r/Layer.pm | 4 ++-- lib/Slic3r/Print/Object.pm | 6 +++--- lib/Slic3r/Test/SectionCut.pm | 8 ++++---- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index d2710af4..e8b7e6dd 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -119,12 +119,11 @@ sub change_layer { return $gcode; } -# this method accepts Z in scaled coordinates +# this method accepts Z in unscaled coordinates sub move_z { my $self = shift; my ($z, $comment) = @_; - $z *= &Slic3r::SCALING_FACTOR; $z += $self->config->z_offset; my $gcode = ""; diff --git a/lib/Slic3r/GCode/SpiralVase.pm b/lib/Slic3r/GCode/SpiralVase.pm index dc67aafc..1c94b251 100644 --- a/lib/Slic3r/GCode/SpiralVase.pm +++ b/lib/Slic3r/GCode/SpiralVase.pm @@ -16,7 +16,7 @@ sub process_layer { my $new_gcode = ""; my $layer_height = $layer->height; - my $z = unscale($layer->print_z) - $layer_height; + my $z = $layer->print_z - $layer_height; my $newlayer = 0; Slic3r::GCode::Reader->new(gcode => $gcode)->parse(sub { my ($reader, $cmd, $args, $info) = @_; diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index 77dd4ad9..ece50625 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -11,7 +11,7 @@ has 'regions' => (is => 'ro', default => sub { [] }); has 'slicing_errors' => (is => 'rw'); has 'slice_z' => (is => 'ro', required => 1); # Z used for slicing in scaled coordinates -has 'print_z' => (is => 'ro', required => 1); # Z used for printing in scaled 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; @@ -51,7 +51,7 @@ sub support_material_contact_height { # Z used for printing support material contact in scaled coordinates sub support_material_contact_z { my $self = shift; - return $self->print_z - ($self->height - $self->support_material_contact_height) / &Slic3r::SCALING_FACTOR; + return ($self->print_z - ($self->height - $self->support_material_contact_height)) / &Slic3r::SCALING_FACTOR; } sub upper_layer_slices { diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 446a7c02..8bd80d15 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -36,7 +36,7 @@ sub BUILD { object => $self, id => $id, height => $height, - print_z => scale $print_z, + print_z => $print_z, slice_z => -1, ); } @@ -71,7 +71,7 @@ sub BUILD { object => $self, id => $id, height => $height, - print_z => scale $print_z, + print_z => $print_z, slice_z => scale $slice_z, ); @@ -904,7 +904,7 @@ sub generate_support_material { if ($Slic3r::debug) { printf "Layer %d (z = %.2f) has %d generic support areas, %d normal interface areas, %d contact areas\n", - $i, unscale($layer->print_z), scalar(@{$layers{$i}}), scalar(@{$layers_interfaces{$i}}), scalar(@{$layers_contact_areas{$i}}); + $i, $layer->print_z, scalar(@{$layers{$i}}), scalar(@{$layers_interfaces{$i}}), scalar(@{$layers_contact_areas{$i}}); } } } diff --git a/lib/Slic3r/Test/SectionCut.pm b/lib/Slic3r/Test/SectionCut.pm index b2403ef3..97d76af8 100644 --- a/lib/Slic3r/Test/SectionCut.pm +++ b/lib/Slic3r/Test/SectionCut.pm @@ -25,7 +25,7 @@ sub export_svg { my ($filename) = @_; my $print_size = $self->print->size; - $self->height(unscale max(map $_->print_z, map @{$_->layers}, @{$self->print->objects})); + $self->height(max(map $_->print_z, map @{$_->layers}, @{$self->print->objects})); my $svg = SVG->new( width => $self->scale * unscale($print_size->[X]), height => $self->scale * $self->height, @@ -106,7 +106,7 @@ sub _plot { # we're cutting the path in the longitudinal direction, so we've got a rectangle push @rectangles, { 'x' => $self->scale * unscale $line->[A][X], - 'y' => $self->scale * $self->_y(unscale($layer->print_z)), + 'y' => $self->scale * $self->_y($layer->print_z), 'width' => $self->scale * $width, 'height' => $self->scale * $radius * 2, 'rx' => $self->scale * $radius * 0.35, @@ -115,7 +115,7 @@ sub _plot { } else { push @circles, { 'cx' => $self->scale * (unscale($line->[A][X]) + $radius), - 'cy' => $self->scale * $self->_y(unscale($layer->print_z) - $radius), + 'cy' => $self->scale * $self->_y($layer->print_z - $radius), 'r' => $self->scale * $radius, }; } @@ -125,7 +125,7 @@ sub _plot { my $height = $path->height // $layer->height; { 'x' => $self->scale * unscale $_->[A][X], - 'y' => $self->scale * $self->_y(unscale($layer->print_z)), + 'y' => $self->scale * $self->_y($layer->print_z), 'width' => $self->scale * unscale(abs($_->[B][X] - $_->[A][X])), 'height' => $self->scale * $height, 'rx' => $self->scale * $height * 0.35,