From e29569a2cd4de2f85dba8b1753fff778f8ab85fd Mon Sep 17 00:00:00 2001
From: Alessandro Ranellucci <aar@cpan.org>
Date: Sat, 25 Oct 2014 11:00:08 +0200
Subject: [PATCH] Minor cleanup and refactoring in Slic3r::GCode

---
 lib/Slic3r/GCode.pm       | 17 +++++++----------
 lib/Slic3r/GCode/Layer.pm |  2 +-
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm
index e5fb2eb1e..72280be06 100644
--- a/lib/Slic3r/GCode.pm
+++ b/lib/Slic3r/GCode.pm
@@ -28,16 +28,13 @@ has 'layer'              => (is => 'rw');
 has '_layer_islands'     => (is => 'rw');
 has '_upper_layer_islands'  => (is => 'rw');
 has '_seam_position'     => (is => 'ro', default => sub { {} });  # $object => pos
-has 'shift_x'            => (is => 'rw', default => sub {0} );
-has 'shift_y'            => (is => 'rw', default => sub {0} );
-has 'z'                  => (is => 'rw');
 has 'external_mp'        => (is => 'rw');
 has 'layer_mp'           => (is => 'rw');
 has 'new_object'         => (is => 'rw', default => sub {0});
 has 'straight_once'      => (is => 'rw', default => sub {1});
 has 'elapsed_time'       => (is => 'rw', default => sub {0} );  # seconds
 has 'last_pos'           => (is => 'rw', default => sub { Slic3r::Point->new(0,0) } );
-has 'wipe_path'          => (is => 'rw');
+has '_wipe_path'         => (is => 'rw');
 
 sub apply_print_config {
     my ($self, $print_config) = @_;
@@ -64,7 +61,7 @@ sub set_origin {
         scale ($self->origin->y - $pointf->y),  #-
     );
     $self->last_pos->translate(@translate);
-    $self->wipe_path->translate(@translate) if $self->wipe_path;
+    $self->_wipe_path->translate(@translate) if $self->_wipe_path;
     
     $self->origin($pointf);
 }
@@ -189,7 +186,7 @@ sub extrude_loop {
     # reset acceleration
     $gcode .= $self->_writer->set_acceleration($self->config->default_acceleration);
     
-    $self->wipe_path($paths[-1]->polyline->clone) if $self->enable_wipe;  # TODO: don't limit wipe to last path
+    $self->_wipe_path($paths[-1]->polyline->clone) if $self->enable_wipe;  # TODO: don't limit wipe to last path
     
     # make a little move inwards before leaving loop
     if ($paths[-1]->role == EXTR_ROLE_EXTERNAL_PERIMETER && defined $self->layer && $self->config->perimeters > 1) {
@@ -301,8 +298,8 @@ sub _extrude_path {
             $self->config->gcode_comments ? " ; $description" : "");
 
         if ($self->enable_wipe) {
-            $self->wipe_path($path->polyline->clone);
-            $self->wipe_path->reverse;
+            $self->_wipe_path($path->polyline->clone);
+            $self->_wipe_path->reverse;
         }
     }
     $gcode .= ";_BRIDGE_FAN_END\n" if $path->is_bridge;
@@ -401,7 +398,7 @@ sub retract {
     my $gcode = "";
     
     # wipe (if it's enabled for this extruder and we have a stored wipe path)
-    if ($self->config->get_at('wipe', $self->_writer->extruder->id) && $self->wipe_path) {
+    if ($self->config->get_at('wipe', $self->_writer->extruder->id) && $self->_wipe_path) {
         # Reduce feedrate a bit; travel speed is often too high to move on existing material.
         # Too fast = ripping of existing material; too slow = short wipe path, thus more blob.
         my $wipe_speed = $self->_writer->config->travel_speed * 0.8;
@@ -420,7 +417,7 @@ sub retract {
         # (they might be different, for example, in case of loop clipping).
         my $wipe_path = Slic3r::Polyline->new(
             $self->last_pos,
-            @{$self->wipe_path}[1..$#{$self->wipe_path}],
+            @{$self->_wipe_path}[1..$#{$self->_wipe_path}],
         );
         # 
         $wipe_path->clip_end($wipe_path->length - $wipe_dist);
diff --git a/lib/Slic3r/GCode/Layer.pm b/lib/Slic3r/GCode/Layer.pm
index 0859b7d8c..32b53c37e 100644
--- a/lib/Slic3r/GCode/Layer.pm
+++ b/lib/Slic3r/GCode/Layer.pm
@@ -76,7 +76,7 @@ sub process_layer {
     # set new layer - this will change Z and force a retraction if retract_layer_change is enabled
     $gcode .= $self->gcodegen->change_layer($layer);
     $gcode .= $self->gcodegen->placeholder_parser->process($self->print->config->layer_gcode, {
-        layer_num => $self->gcodegen->layer->id,
+        layer_num => $layer->id,
     }) . "\n" if $self->print->config->layer_gcode;
     
     # extrude skirt