Save some time in GCode.pm method calls

This commit is contained in:
Alessandro Ranellucci 2013-08-27 00:02:24 +02:00
parent 9fb14f2119
commit f1e9216c70

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
my $was_clockwise = $loop->make_counter_clockwise; my $was_clockwise = $loop->make_counter_clockwise;
@ -278,8 +274,7 @@ sub extrude_loop {
} }
sub extrude_path { sub extrude_path {
my $self = shift; my ($self, $path, $description, %params) = @_;
my ($path, $description, %params) = @_;
$path->simplify(&Slic3r::SCALED_RESOLUTION); $path->simplify(&Slic3r::SCALED_RESOLUTION);
@ -365,8 +360,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 = "";
my $travel = Slic3r::Line->new($self->last_pos, $point); my $travel = Slic3r::Line->new($self->last_pos, $point);
@ -414,8 +408,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;
@ -444,8 +437,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}
@ -532,7 +524,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';
@ -557,7 +549,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;
@ -566,8 +558,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",
@ -586,15 +577,14 @@ 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 (defined $point) { if (defined $point) {
$gcode .= sprintf " X%.${dec}f Y%.${dec}f", $gcode .= sprintf " X%.${dec}f Y%.${dec}f",
($point->x * &Slic3r::SCALING_FACTOR) + $self->shift_x - $self->extruder->extruder_offset->[X], ($point->x * &Slic3r::SCALING_FACTOR) + $self->shift_x - $self->extruder->extruder_offset->[X],
($point->y * &Slic3r::SCALING_FACTOR) + $self->shift_y - $self->extruder->extruder_offset->[Y]; #** ($point->y * &Slic3r::SCALING_FACTOR) + $self->shift_y - $self->extruder->extruder_offset->[Y]; #**
$gcode = $self->_limit_frequency($point) . $gcode; $gcode = $self->_limit_frequency($point) . $gcode if $self->config->vibration_limit != 0;
$self->last_pos($point->clone); $self->last_pos($point->clone);
} }
if (defined $z && (!defined $self->z || $z != $self->z)) { if (defined $z && (!defined $self->z || $z != $self->z)) {
@ -606,8 +596,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";
@ -626,8 +615,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
@ -671,8 +659,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);
@ -712,8 +699,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;
@ -737,8 +723,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)$/;
@ -756,8 +741,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')
@ -773,10 +757,8 @@ 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;
my $min_time = 1 / ($self->config->vibration_limit * 60); # in minutes my $min_time = 1 / ($self->config->vibration_limit * 60); # in minutes
# calculate the move vector and move direction # calculate the move vector and move direction