Minor optimizations in GCode.pm

This commit is contained in:
Alessandro Ranellucci 2013-08-28 15:29:18 +02:00
parent 94a7d6b941
commit 7fbacc5885

View File

@ -78,8 +78,7 @@ sub _build_enable_wipe {
}
sub set_shift {
my $self = shift;
my @shift = @_;
my ($self, @shift) = @_;
# if shift increases (goes towards right), last_pos decreases because it goes towards left
my @translate = (
@ -94,8 +93,7 @@ sub set_shift {
}
sub change_layer {
my $self = shift;
my ($layer) = @_;
my ($self, $layer) = @_;
$self->layer($layer);
@ -138,8 +136,7 @@ sub change_layer {
# this method accepts Z in unscaled coordinates
sub move_z {
my $self = shift;
my ($z, $comment) = @_;
my ($self, $z, $comment) = @_;
$z += $self->config->z_offset;
@ -174,8 +171,7 @@ sub extrude {
}
sub extrude_loop {
my $self = shift;
my ($loop, $description) = @_;
my ($self, $loop, $description) = @_;
# extrude all loops ccw
$loop = $loop->unpack if $loop->isa('Slic3r::ExtrusionLoop::Packed');
@ -280,8 +276,7 @@ sub extrude_loop {
}
sub extrude_path {
my $self = shift;
my ($path, $description, %params) = @_;
my ($self, $path, $description, %params) = @_;
$path = $path->unpack if $path->isa('Slic3r::ExtrusionPath::Packed');
$path->simplify(&Slic3r::SCALED_RESOLUTION);
@ -367,8 +362,7 @@ sub extrude_path {
}
sub travel_to {
my $self = shift;
my ($point, $role, $comment) = @_;
my ($self, $point, $role, $comment) = @_;
my $gcode = "";
@ -417,8 +411,7 @@ sub travel_to {
}
sub _plan {
my $self = shift;
my ($mp, $point, $comment) = @_;
my ($self, $mp, $point, $comment) = @_;
my $gcode = "";
my @travel = $mp->shortest_path($self->last_pos, $point)->lines;
@ -447,8 +440,7 @@ sub _plan {
}
sub retract {
my $self = shift;
my %params = @_;
my ($self, %params) = @_;
# get the retraction length and abort if none
my ($length, $restart_extra, $comment) = $params{toolchange}
@ -535,7 +527,7 @@ sub retract {
}
sub unretract {
my $self = shift;
my ($self) = @_;
my $gcode = "";
$gcode .= "M101 ; extruder on\n" if $self->config->gcode_flavor eq 'makerware';
@ -560,7 +552,7 @@ sub unretract {
}
sub reset_e {
my $self = shift;
my ($self) = @_;
return "" if $self->config->gcode_flavor =~ /^(?:mach3|makerware|sailfish)$/;
$self->extruder->e(0) if $self->extruder;
@ -569,8 +561,7 @@ sub reset_e {
}
sub set_acceleration {
my $self = shift;
my ($acceleration) = @_;
my ($self, $acceleration) = @_;
return "" if !$acceleration;
return sprintf "M204 S%s%s\n",
@ -589,8 +580,7 @@ sub G1 {
}
sub _G0_G1 {
my $self = shift;
my ($gcode, $point, $z, $e, $comment) = @_;
my ($self, $gcode, $point, $z, $e, $comment) = @_;
my $dec = $self->dec;
if ($point) {
@ -609,8 +599,7 @@ sub _G0_G1 {
}
sub G2_G3 {
my $self = shift;
my ($point, $orientation, $center, $e, $comment) = @_;
my ($self, $point, $orientation, $center, $e, $comment) = @_;
my $dec = $self->dec;
my $gcode = $orientation eq 'cw' ? "G2" : "G3";
@ -629,8 +618,7 @@ sub G2_G3 {
}
sub _Gx {
my $self = shift;
my ($gcode, $e, $comment) = @_;
my ($self, $gcode, $e, $comment) = @_;
my $dec = $self->dec;
# output speed if it's different from last one used
@ -674,8 +662,7 @@ sub _Gx {
}
sub set_extruder {
my $self = shift;
my ($extruder) = @_;
my ($self, $extruder) = @_;
# return nothing if this extruder was already selected
return "" if (defined $self->extruder) && ($self->extruder->id == $extruder->id);
@ -715,8 +702,7 @@ sub set_extruder {
}
sub set_fan {
my $self = shift;
my ($speed, $dont_save) = @_;
my ($self, $speed, $dont_save) = @_;
if ($self->last_fan_speed != $speed || $dont_save) {
$self->last_fan_speed($speed) if !$dont_save;
@ -740,8 +726,7 @@ sub set_fan {
}
sub set_temperature {
my $self = shift;
my ($temperature, $wait, $tool) = @_;
my ($self, $temperature, $wait, $tool) = @_;
return "" if $wait && $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/;
@ -759,8 +744,7 @@ sub set_temperature {
}
sub set_bed_temperature {
my $self = shift;
my ($temperature, $wait) = @_;
my ($self, $temperature, $wait) = @_;
my ($code, $comment) = ($wait && $self->config->gcode_flavor ne 'teacup')
? (($self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/ ? 'M109' : 'M190'), 'wait for bed temperature to be reached')
@ -776,8 +760,7 @@ sub set_bed_temperature {
# http://hydraraptor.blogspot.it/2010/12/frequency-limit.html
sub _limit_frequency {
my $self = shift;
my ($point) = @_;
my ($self, $point) = @_;
return '' if $self->config->vibration_limit == 0;
my $min_time = 1 / ($self->config->vibration_limit * 60); # in minutes