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