mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 12:11:15 -06:00 
			
		
		
		
	Refactoring: moved Slic3r::GCode::Base to Slic3r::GCode::Writer
This commit is contained in:
		
							parent
							
								
									c2e710d092
								
							
						
					
					
						commit
						7f57f007cd
					
				
					 12 changed files with 154 additions and 212 deletions
				
			
		|  | @ -9,9 +9,10 @@ use Slic3r::Geometry qw(epsilon scale unscale scaled_epsilon points_coincide PI | |||
| use Slic3r::Geometry::Clipper qw(union_ex offset_ex); | ||||
| use Slic3r::Surface ':types'; | ||||
| 
 | ||||
| extends 'Slic3r::GCode::Base'; | ||||
| 
 | ||||
| has 'config'             => (is => 'ro', default => sub { Slic3r::Config::Full->new }); | ||||
| has '_writer'            => (is => 'ro', default => sub { Slic3r::GCode::Writer->new }, | ||||
|                                 handles => [qw(set_fan set_temperature set_bed_temperature | ||||
|                                                 extruders reset_e multiple_extruders extruder)]); | ||||
| has 'placeholder_parser' => (is => 'rw', default => sub { Slic3r::GCode::PlaceholderParser->new }); | ||||
| has 'ooze_prevention'    => (is => 'rw'); | ||||
| has 'enable_loop_clipping' => (is => 'rw', default => sub {1}); | ||||
|  | @ -36,17 +37,17 @@ has 'wipe_path'          => (is => 'rw'); | |||
| sub apply_print_config { | ||||
|     my ($self, $print_config) = @_; | ||||
|      | ||||
|     $self->SUPER::apply_print_config($print_config); | ||||
|     $self->_writer->apply_print_config($print_config); | ||||
|     $self->config->apply_print_config($print_config); | ||||
| } | ||||
| 
 | ||||
| sub set_extruders { | ||||
|     my ($self, $extruder_ids) = @_; | ||||
|      | ||||
|     $self->SUPER::set_extruders($extruder_ids); | ||||
|     $self->_writer->set_extruders($extruder_ids); | ||||
|      | ||||
|     # enable wipe path generation if any extruder has wipe enabled | ||||
|     $self->enable_wipe(defined first { $_->wipe } values %{$self->_extruders}); | ||||
|     $self->enable_wipe(defined first { $self->config->get_at('wipe', $_) } @$extruder_ids); | ||||
| } | ||||
| 
 | ||||
| sub set_shift { | ||||
|  | @ -82,15 +83,14 @@ sub change_layer { | |||
|     my $gcode = ""; | ||||
|     if (defined $self->layer_count) { | ||||
|         # TODO: cap this to 99% and add an explicit M73 P100 in the end G-code | ||||
|         $gcode .= $self->update_progress(int(99 * ($self->_layer_index / ($self->layer_count - 1)))); | ||||
|         $gcode .= $self->_writer->update_progress(int(99 * ($self->_layer_index / ($self->layer_count - 1)))); | ||||
|     } | ||||
|      | ||||
|     my $z = $layer->print_z + $self->config->z_offset;  # in unscaled coordinates | ||||
|     if ($self->_extruder->retract_layer_change && $self->will_move_z($z)) { | ||||
|     if ($self->config->get_at('retract_layer_change', $self->_writer->extruder->id) && $self->_writer->will_move_z($z)) { | ||||
|         $gcode .= $self->retract; | ||||
|         $gcode .= $self->lift; | ||||
|     } | ||||
|     $gcode .= $self->travel_to_z($z, 'move to next layer (' . $self->layer->id . ')'); | ||||
|     $gcode .= $self->_writer->travel_to_z($z, 'move to next layer (' . $self->layer->id . ')'); | ||||
|     return $gcode; | ||||
| } | ||||
| 
 | ||||
|  | @ -120,7 +120,7 @@ sub extrude_loop { | |||
|     } elsif ($self->config->seam_position eq 'nearest' || $self->config->seam_position eq 'aligned') { | ||||
|         # simplify polygon in order to skip false positives in concave/convex detection | ||||
|         my $polygon = $loop->polygon; | ||||
|         my @simplified = @{$polygon->simplify(scale $self->_extruder->nozzle_diameter/2)}; | ||||
|         my @simplified = @{$polygon->simplify(scale $self->config->get_at('nozzle_diameter', $self->_writer->extruder->id)/2)}; | ||||
|          | ||||
|         # concave vertices have priority | ||||
|         my @candidates = map @{$_->concave_points(PI*4/3)}, @simplified; | ||||
|  | @ -166,7 +166,7 @@ sub extrude_loop { | |||
|     # if polyline was shorter than the clipping distance we'd get a null polyline, so | ||||
|     # we discard it in that case | ||||
|     my $clip_length = $self->enable_loop_clipping | ||||
|         ? scale($self->_extruder->nozzle_diameter) * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_NOZZLE_DIAMETER | ||||
|         ? scale($self->config->get_at('nozzle_diameter', $self->_writer->extruder->id)) * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_NOZZLE_DIAMETER | ||||
|         : 0; | ||||
|      | ||||
|     # get paths | ||||
|  | @ -183,7 +183,7 @@ sub extrude_loop { | |||
|     my $gcode = join '', map $self->_extrude_path($_, $description, $speed), @paths; | ||||
|      | ||||
|     # reset acceleration | ||||
|     $gcode .= $self->set_acceleration($self->config->default_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 | ||||
|      | ||||
|  | @ -200,7 +200,7 @@ sub extrude_loop { | |||
|         # we make sure we don't exceed the segment length because we don't know | ||||
|         # the rotation of the second segment so we might cross the object boundary | ||||
|         my $first_segment = Slic3r::Line->new(@$last_path_polyline[0,1]); | ||||
|         my $distance = min(scale($self->_extruder->nozzle_diameter), $first_segment->length); | ||||
|         my $distance = min(scale($self->config->get_at('nozzle_diameter', $self->_writer->extruder->id)), $first_segment->length); | ||||
|         my $point = $first_segment->point_at($distance); | ||||
|         $point->rotate($angle, $last_path_polyline->first_point); | ||||
|          | ||||
|  | @ -217,7 +217,7 @@ sub extrude_path { | |||
|     my $gcode = $self->_extrude_path($path, $description, $speed); | ||||
|      | ||||
|     # reset acceleration | ||||
|     $gcode .= $self->set_acceleration($self->config->default_acceleration); | ||||
|     $gcode .= $self->_writer->set_acceleration($self->config->default_acceleration); | ||||
|      | ||||
|     return $gcode; | ||||
| } | ||||
|  | @ -252,12 +252,12 @@ sub _extrude_path { | |||
|         } else { | ||||
|             $acceleration = $self->config->default_acceleration; | ||||
|         } | ||||
|         $gcode .= $self->set_acceleration($acceleration); | ||||
|         $gcode .= $self->_writer->set_acceleration($acceleration); | ||||
|     } | ||||
|      | ||||
|     # calculate extrusion length per distance unit | ||||
|     my $e_per_mm = $self->_extruder->e_per_mm3 * $path->mm3_per_mm; | ||||
|     $e_per_mm = 0 if !$self->_extrusion_axis; | ||||
|     my $e_per_mm = $self->_writer->extruder->e_per_mm3 * $path->mm3_per_mm; | ||||
|     $e_per_mm = 0 if !$self->_writer->_extrusion_axis; | ||||
|      | ||||
|     # set speed | ||||
|     my $F; | ||||
|  | @ -289,10 +289,11 @@ sub _extrude_path { | |||
|     $gcode .= ";_BRIDGE_FAN_START\n" if $path->is_bridge; | ||||
|     my $path_length = unscale $path->length; | ||||
|     { | ||||
|         $gcode .= $path->gcode($self->_extruder, $e_per_mm, $F, | ||||
|             $self->shift_x - $self->_extruder->extruder_offset->x, | ||||
|             $self->shift_y - $self->_extruder->extruder_offset->y,  #,, | ||||
|             $self->_extrusion_axis, | ||||
|         my $extruder_offset = $self->config->get_at('extruder_offset', $self->_writer->extruder->id); | ||||
|         $gcode .= $path->gcode($self->_writer->extruder, $e_per_mm, $F, | ||||
|             $self->shift_x - $extruder_offset->x, | ||||
|             $self->shift_y - $extruder_offset->y,  #,, | ||||
|             $self->_writer->_extrusion_axis, | ||||
|             $self->config->gcode_comments ? " ; $description" : ""); | ||||
| 
 | ||||
|         if ($self->enable_wipe) { | ||||
|  | @ -324,7 +325,7 @@ sub travel_to { | |||
|      | ||||
|     # skip retraction if the travel move is contained in an island in the current layer | ||||
|     # *and* in an island in the upper layer (so that the ooze will not be visible) | ||||
|     if ($travel->length < scale $self->_extruder->retract_before_travel | ||||
|     if ($travel->length < scale $self->config->get_at('retract_before_travel', $self->_writer->extruder->id) | ||||
|         || ($self->config->only_retract_when_crossing_perimeters | ||||
|             && $self->config->fill_density > 0 | ||||
|             && (first { $_->contains_line($travel) } @{$self->_upper_layer_islands}) | ||||
|  | @ -332,11 +333,11 @@ sub travel_to { | |||
|         || (defined $role && $role == EXTR_ROLE_SUPPORTMATERIAL && (first { $_->contains_line($travel) } @{$self->layer->support_islands})) | ||||
|         ) { | ||||
|         $self->straight_once(0); | ||||
|         $gcode .= $self->travel_to_xy($self->point_to_gcode($point), $comment); | ||||
|         $gcode .= $self->_writer->travel_to_xy($self->point_to_gcode($point), $comment); | ||||
|     } elsif (!$self->config->avoid_crossing_perimeters || $self->straight_once) { | ||||
|         $self->straight_once(0); | ||||
|         $gcode .= $self->retract; | ||||
|         $gcode .= $self->travel_to_xy($self->point_to_gcode($point), $comment); | ||||
|         $gcode .= $self->_writer->travel_to_xy($self->point_to_gcode($point), $comment); | ||||
|     } else { | ||||
|         if ($self->new_object) { | ||||
|             $self->new_object(0); | ||||
|  | @ -383,7 +384,7 @@ sub _plan { | |||
|     # append the actual path and return | ||||
|     # use G1 because we rely on paths being straight (G0 may make round paths) | ||||
|     $gcode .= join '', | ||||
|         map $self->travel_to_xy($self->point_to_gcode($_->b), $comment), | ||||
|         map $self->_writer->travel_to_xy($self->point_to_gcode($_->b), $comment), | ||||
|         @travel; | ||||
|     return $gcode; | ||||
| } | ||||
|  | @ -391,25 +392,25 @@ sub _plan { | |||
| sub retract { | ||||
|     my ($self, $toolchange) = @_; | ||||
|      | ||||
|     return "" if !defined $self->_extruder; | ||||
|     return "" if !defined $self->_writer->extruder; | ||||
|      | ||||
|     my $gcode = ""; | ||||
|      | ||||
|     # wipe (if it's enabled for this extruder and we have a stored wipe path) | ||||
|     if ($self->_extruder->wipe && $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->gcode_config->travel_speed * 0.8; | ||||
|         my $wipe_speed = $self->_writer->config->travel_speed * 0.8; | ||||
|          | ||||
|         # get the retraction length | ||||
|         my $length = $toolchange | ||||
|             ? $self->_extruder->retract_length | ||||
|             : $self->_extruder->retract_length_toolchange; | ||||
|             ? $self->_writer->extruder->retract_length | ||||
|             : $self->_writer->extruder->retract_length_toolchange; | ||||
|          | ||||
|         # Calculate how long we need to travel in order to consume the required | ||||
|         # amount of retraction. In other words, how far do we move in XY at $wipe_speed | ||||
|         # for the time needed to consume retract_length at retract_speed? | ||||
|         my $wipe_dist = scale($length / $self->_extruder->retract_speed * $wipe_speed); | ||||
|         my $wipe_dist = scale($length / $self->_writer->extruder->retract_speed * $wipe_speed); | ||||
|          | ||||
|         # Take the stored wipe path and replace first point with the current actual position | ||||
|         # (they might be different, for example, in case of loop clipping). | ||||
|  | @ -427,25 +428,25 @@ sub retract { | |||
|             # Reduce retraction length a bit to avoid effective retraction speed to be greater than the configured one | ||||
|             # due to rounding (TODO: test and/or better math for this) | ||||
|             my $dE = $length * ($segment_length / $wipe_dist) * 0.95; | ||||
|             $gcode .= $self->set_speed($wipe_speed*60); | ||||
|             $gcode .= $self->extrude_to_xy( | ||||
|             $gcode .= $self->_writer->set_speed($wipe_speed*60); | ||||
|             $gcode .= $self->_writer->extrude_to_xy( | ||||
|                 $self->point_to_gcode($line->b), | ||||
|                 -$dE, | ||||
|                 'retract;_WIPE', | ||||
|             ); | ||||
|             $retracted += $dE; | ||||
|         } | ||||
|         $self->_extruder->set_retracted($self->_extruder->retracted + $retracted); | ||||
|         $self->_writer->extruder->set_retracted($self->_writer->extruder->retracted + $retracted); | ||||
|     } | ||||
|      | ||||
|     # The parent class will decide whether we need to perform an actual retraction | ||||
|     # (the extruder might be already retracted fully or partially). We call these  | ||||
|     # methods even if we performed wipe, since this will ensure the entire retraction | ||||
|     # length is honored in case wipe path was too short.p | ||||
|     $gcode .= $toolchange ? $self->retract_for_toolchange : $self->SUPER::retract; | ||||
|     $gcode .= $toolchange ? $self->_writer->retract_for_toolchange : $self->_writer->retract; | ||||
|      | ||||
|     $gcode .= $self->reset_e; | ||||
|     $gcode .= $self->lift; | ||||
|     $gcode .= $self->_writer->reset_e; | ||||
|     $gcode .= $self->_writer->lift; | ||||
|      | ||||
|     return $gcode; | ||||
| } | ||||
|  | @ -454,8 +455,8 @@ sub unretract { | |||
|     my ($self) = @_; | ||||
|      | ||||
|     my $gcode = ""; | ||||
|     $gcode .= $self->unlift; | ||||
|     $gcode .= $self->SUPER::unretract('compensate retraction'); | ||||
|     $gcode .= $self->_writer->unlift; | ||||
|     $gcode .= $self->_writer->unretract('compensate retraction'); | ||||
|     return $gcode; | ||||
| } | ||||
| 
 | ||||
|  | @ -463,29 +464,30 @@ sub unretract { | |||
| sub point_to_gcode { | ||||
|     my ($self, $point) = @_; | ||||
|      | ||||
|     my $extruder_offset = $self->config->get_at('extruder_offset', $self->_writer->extruder->id); | ||||
|     return Slic3r::Pointf->new( | ||||
|         ($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->x * &Slic3r::SCALING_FACTOR) + $self->shift_x - $extruder_offset->x, | ||||
|         ($point->y * &Slic3r::SCALING_FACTOR) + $self->shift_y - $extruder_offset->y,  #** | ||||
|     ); | ||||
| } | ||||
| 
 | ||||
| sub set_extruder { | ||||
|     my ($self, $extruder_id) = @_; | ||||
|      | ||||
|     return "" if !$self->need_toolchange($extruder_id); | ||||
|     return "" if !$self->_writer->need_toolchange($extruder_id); | ||||
|      | ||||
|     # if we are running a single-extruder setup, just set the extruder and return nothing | ||||
|     if (!$self->_multiple_extruders) { | ||||
|         return $self->_toolchange($extruder_id); | ||||
|     if (!$self->_writer->multiple_extruders) { | ||||
|         return $self->_writer->toolchange($extruder_id); | ||||
|     } | ||||
|      | ||||
|     # prepend retraction on the current extruder | ||||
|     my $gcode = $self->retract(1); | ||||
|      | ||||
|     # append custom toolchange G-code | ||||
|     if (defined $self->_extruder && $self->config->toolchange_gcode) { | ||||
|     if (defined $self->_writer->extruder && $self->config->toolchange_gcode) { | ||||
|         $gcode .= sprintf "%s\n", $self->placeholder_parser->process($self->config->toolchange_gcode, { | ||||
|             previous_extruder   => $self->_extruder->id, | ||||
|             previous_extruder   => $self->_writer->extruder->id, | ||||
|             next_extruder       => $extruder_id, | ||||
|         }); | ||||
|     } | ||||
|  | @ -493,10 +495,10 @@ sub set_extruder { | |||
|     # if ooze prevention is enabled, park current extruder in the nearest | ||||
|     # standby point and set it to the standby temperature | ||||
|     $gcode .= $self->ooze_prevention->pre_toolchange($self) | ||||
|         if $self->ooze_prevention && defined $self->_extruder; | ||||
|         if $self->ooze_prevention && defined $self->_writer->extruder; | ||||
|      | ||||
|     # append the toolchange command | ||||
|     $gcode .= $self->_toolchange($extruder_id); | ||||
|     $gcode .= $self->_writer->toolchange($extruder_id); | ||||
|      | ||||
|     # set the new extruder to the operating temperature | ||||
|     $gcode .= $self->ooze_prevention->post_toolchange($self) | ||||
|  |  | |||
|  | @ -4,7 +4,7 @@ use Moo; | |||
| use List::Util qw(first); | ||||
| use Slic3r::Geometry qw(X Y unscale); | ||||
| 
 | ||||
| has 'print'                         => (is => 'ro', required => 1); | ||||
| has 'print'                         => (is => 'ro', required => 1, handles => [qw(config)]); | ||||
| has 'gcodegen'                      => (is => 'ro', required => 1, handles => [qw(extruders)]); | ||||
| has 'shift'                         => (is => 'ro', default => sub { [0,0] }); | ||||
| 
 | ||||
|  | @ -64,8 +64,9 @@ sub process_layer { | |||
|      | ||||
|     if (!$self->second_layer_things_done && $layer->id == 1) { | ||||
|         for my $extruder (@{$self->extruders}) { | ||||
|             $gcode .= $self->gcodegen->set_temperature($extruder->temperature, 0, $extruder->id) | ||||
|                 if $extruder->temperature && $extruder->temperature != $extruder->first_layer_temperature; | ||||
|             my $temperature = $self->config->get_at('temperature', $extruder->id); | ||||
|             $gcode .= $self->gcodegen->set_temperature($temperature, 0, $extruder->id) | ||||
|                 if $temperature && $temperature != $self->config->get_at('first_layer_temperature', $extruder->id); | ||||
|         } | ||||
|         $gcode .= $self->gcodegen->set_bed_temperature($self->print->config->bed_temperature) | ||||
|             if $self->print->config->bed_temperature && $self->print->config->bed_temperature != $self->print->config->first_layer_bed_temperature; | ||||
|  | @ -135,9 +136,9 @@ sub process_layer { | |||
|          | ||||
|         # tweak region ordering to save toolchanges | ||||
|         my @region_ids = 0 .. ($self->print->region_count-1); | ||||
|         if ($self->gcodegen->has_multiple_extruders) { | ||||
|             my $last_extruder = $self->gcodegen->extruder; | ||||
|             my $best_region_id = first { $self->print->regions->[$_]->config->perimeter_extruder-1 eq $last_extruder } @region_ids; | ||||
|         if ($self->gcodegen->multiple_extruders) { | ||||
|             my $last_extruder_id = $self->gcodegen->extruder->id; | ||||
|             my $best_region_id = first { $self->print->regions->[$_]->config->perimeter_extruder-1 == $last_extruder_id } @region_ids; | ||||
|             @region_ids = ($best_region_id, grep $_ != $best_region_id, @region_ids) if $best_region_id; | ||||
|         } | ||||
|          | ||||
|  | @ -175,7 +176,7 @@ sub process_layer { | |||
|                 # give priority to infill if we were already using its extruder and it wouldn't | ||||
|                 # be good for perimeters | ||||
|                 if ($self->print->config->infill_first | ||||
|                     || ($self->gcodegen->has_multiple_extruders && $region->config->infill_extruder-1 == $self->gcodegen->extruder->id && $region->config->infill_extruder != $region->config->perimeter_extruder)) { | ||||
|                     || ($self->gcodegen->multiple_extruders && $region->config->infill_extruder-1 == $self->gcodegen->extruder->id && $region->config->infill_extruder != $region->config->perimeter_extruder)) { | ||||
|                     $gcode .= $self->_extrude_infill($infill_by_island[$i], $region); | ||||
|                     $gcode .= $self->_extrude_perimeters($perimeters_by_island[$i], $region); | ||||
|                 } else { | ||||
|  |  | |||
|  | @ -21,8 +21,8 @@ sub pre_toolchange { | |||
|      | ||||
|     if ($gcodegen->config->standby_temperature_delta != 0) { | ||||
|         my $temp = defined $gcodegen->layer && $gcodegen->layer->id == 0 | ||||
|             ? $gcodegen->_extruder->first_layer_temperature | ||||
|             : $gcodegen->_extruder->temperature; | ||||
|             ? $gcodegen->config->get_at('first_layer_temperature', $gcodegen->extruder->id) | ||||
|             : $gcodegen->config->get_at('temperature', $gcodegen->extruder->id); | ||||
|         # we assume that heating is always slower than cooling, so no need to block | ||||
|         $gcode .= $gcodegen->set_temperature($temp + $gcodegen->config->standby_temperature_delta, 0); | ||||
|     } | ||||
|  | @ -37,8 +37,8 @@ sub post_toolchange { | |||
|      | ||||
|     if ($gcodegen->config->standby_temperature_delta != 0) { | ||||
|         my $temp = defined $gcodegen->layer && $gcodegen->layer->id == 0 | ||||
|             ? $gcodegen->_extruder->first_layer_temperature | ||||
|             : $gcodegen->_extruder->temperature; | ||||
|             ? $gcodegen->config->get_at('first_layer_temperature', $gcodegen->extruder->id) | ||||
|             : $gcodegen->config->get_at('temperature', $gcodegen->extruder->id); | ||||
|         $gcode .= $gcodegen->set_temperature($temp, 1); | ||||
|     } | ||||
|      | ||||
|  |  | |||
|  | @ -1,14 +1,14 @@ | |||
| package Slic3r::GCode::Base; | ||||
| package Slic3r::GCode::Writer; | ||||
| use Moo; | ||||
| 
 | ||||
| use List::Util qw(min max first); | ||||
| use Slic3r::Geometry qw(X Y epsilon); | ||||
| 
 | ||||
| has 'gcode_config'          => (is => 'ro', default => sub { Slic3r::Config::GCode->new }); | ||||
| has 'config'                => (is => 'ro', default => sub { Slic3r::Config::GCode->new }); | ||||
| has 'multiple_extruders'    => (is => 'rw', default => sub { 0 }); | ||||
| has '_extrusion_axis'       => (is => 'rw', default => sub { 'E' }); | ||||
| has '_extruders'            => (is => 'ro', default => sub {{}}); | ||||
| has '_extruder'             => (is => 'rw'); | ||||
| has '_multiple_extruders'   => (is => 'rw', default => sub { 0 }); | ||||
| has '_extruder'             => (is => 'rw', reader => 'extruder'); | ||||
| has '_last_acceleration'    => (is => 'rw', default => sub { 0 }); | ||||
| has '_last_fan_speed'       => (is => 'rw', default => sub { 0 }); | ||||
| has '_lifted'               => (is => 'rw', default => sub { 0 }); | ||||
|  | @ -17,14 +17,14 @@ has '_pos'                  => (is => 'rw', default => sub { Slic3r::Pointf3->ne | |||
| sub apply_print_config { | ||||
|     my ($self, $print_config) = @_; | ||||
|      | ||||
|     $self->gcode_config->apply_print_config($print_config); | ||||
|     $self->config->apply_print_config($print_config); | ||||
|      | ||||
|     if ($self->gcode_config->gcode_flavor eq 'mach3') { | ||||
|     if ($self->config->gcode_flavor eq 'mach3') { | ||||
|         $self->_extrusion_axis('A'); | ||||
|     } elsif ($self->gcode_config->gcode_flavor eq 'no-extrusion') { | ||||
|     } elsif ($self->config->gcode_flavor eq 'no-extrusion') { | ||||
|         $self->_extrusion_axis(''); | ||||
|     } else { | ||||
|         $self->_extrusion_axis($self->gcode_config->extrusion_axis); | ||||
|         $self->_extrusion_axis($self->config->extrusion_axis); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -38,23 +38,23 @@ sub set_extruders { | |||
|     # we enable support for multiple extruder if any extruder greater than 0 is used | ||||
|     # (even if prints only uses that one) since we need to output Tx commands | ||||
|     # first extruder has index 0 | ||||
|     $self->_multiple_extruders(max(@$extruder_ids) > 0); | ||||
|     $self->multiple_extruders(max(@$extruder_ids) > 0); | ||||
| } | ||||
| 
 | ||||
| sub set_temperature { | ||||
|     my ($self, $temperature, $wait, $tool) = @_; | ||||
|      | ||||
|     return "" if $wait && $self->gcode_config->gcode_flavor =~ /^(?:makerware|sailfish)$/; | ||||
|     return "" if $wait && $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/; | ||||
|      | ||||
|     my ($code, $comment) = ($wait && $self->gcode_config->gcode_flavor ne 'teacup') | ||||
|     my ($code, $comment) = ($wait && $self->config->gcode_flavor ne 'teacup') | ||||
|         ? ('M109', 'wait for temperature to be reached') | ||||
|         : ('M104', 'set temperature'); | ||||
|     my $gcode = sprintf "$code %s%d %s; $comment\n", | ||||
|         ($self->gcode_config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature, | ||||
|         (defined $tool && ($self->_multiple_extruders || $self->gcode_config->gcode_flavor =~ /^(?:makerware|sailfish)$/)) ? "T$tool " : ""; | ||||
|         ($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature, | ||||
|         (defined $tool && ($self->multiple_extruders || $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/)) ? "T$tool " : ""; | ||||
|      | ||||
|     $gcode .= "M116 ; wait for temperature to be reached\n" | ||||
|         if $self->gcode_config->gcode_flavor eq 'teacup' && $wait; | ||||
|         if $self->config->gcode_flavor eq 'teacup' && $wait; | ||||
|      | ||||
|     return $gcode; | ||||
| } | ||||
|  | @ -62,14 +62,14 @@ sub set_temperature { | |||
| sub set_bed_temperature { | ||||
|     my ($self, $temperature, $wait) = @_; | ||||
|      | ||||
|     my ($code, $comment) = ($wait && $self->gcode_config->gcode_flavor ne 'teacup') | ||||
|         ? (($self->gcode_config->gcode_flavor =~ /^(?:makerware|sailfish)$/ ? 'M109' : 'M190'), 'wait for bed temperature to be reached') | ||||
|     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') | ||||
|         : ('M140', 'set bed temperature'); | ||||
|     my $gcode = sprintf "$code %s%d ; $comment\n", | ||||
|         ($self->gcode_config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature; | ||||
|         ($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature; | ||||
|      | ||||
|     $gcode .= "M116 ; wait for bed temperature to be reached\n" | ||||
|         if $self->gcode_config->gcode_flavor eq 'teacup' && $wait; | ||||
|         if $self->config->gcode_flavor eq 'teacup' && $wait; | ||||
|      | ||||
|     return $gcode; | ||||
| } | ||||
|  | @ -80,18 +80,18 @@ sub set_fan { | |||
|     if ($self->_last_fan_speed != $speed || $dont_save) { | ||||
|         $self->_last_fan_speed($speed) if !$dont_save; | ||||
|         if ($speed == 0) { | ||||
|             my $code = $self->gcode_config->gcode_flavor eq 'teacup' | ||||
|             my $code = $self->config->gcode_flavor eq 'teacup' | ||||
|                 ? 'M106 S0' | ||||
|                 : $self->gcode_config->gcode_flavor =~ /^(?:makerware|sailfish)$/ | ||||
|                 : $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/ | ||||
|                     ? 'M127' | ||||
|                     : 'M107'; | ||||
|             return sprintf "$code%s\n", ($self->gcode_config->gcode_comments ? ' ; disable fan' : ''); | ||||
|             return sprintf "$code%s\n", ($self->config->gcode_comments ? ' ; disable fan' : ''); | ||||
|         } else { | ||||
|             if ($self->gcode_config->gcode_flavor =~ /^(?:makerware|sailfish)$/) { | ||||
|                 return sprintf "M126%s\n", ($self->gcode_config->gcode_comments ? ' ; enable fan' : ''); | ||||
|             if ($self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/) { | ||||
|                 return sprintf "M126%s\n", ($self->config->gcode_comments ? ' ; enable fan' : ''); | ||||
|             } else { | ||||
|                 return sprintf "M106 %s%d%s\n", ($self->gcode_config->gcode_flavor eq 'mach3' ? 'P' : 'S'), | ||||
|                     (255 * $speed / 100), ($self->gcode_config->gcode_comments ? ' ; enable fan' : ''); | ||||
|                 return sprintf "M106 %s%d%s\n", ($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), | ||||
|                     (255 * $speed / 100), ($self->config->gcode_comments ? ' ; enable fan' : ''); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | @ -105,13 +105,13 @@ sub set_acceleration { | |||
|      | ||||
|     $self->_last_acceleration($acceleration); | ||||
|     return sprintf "M204 S%s%s\n", | ||||
|         $acceleration, ($self->gcode_config->gcode_comments ? ' ; adjust acceleration' : ''); | ||||
|         $acceleration, ($self->config->gcode_comments ? ' ; adjust acceleration' : ''); | ||||
| } | ||||
| 
 | ||||
| sub update_progress { | ||||
|     my ($self, $percent) = @_; | ||||
|      | ||||
|     return "" if $self->gcode_config->gcode_flavor !~ /^(?:makerware|sailfish)$/; | ||||
|     return "" if $self->config->gcode_flavor !~ /^(?:makerware|sailfish)$/; | ||||
|     return sprintf "M73 P%s%s\n", | ||||
|         int($percent), | ||||
|         $self->_comment('update progress'); | ||||
|  | @ -128,10 +128,10 @@ sub set_extruder { | |||
|     my ($self, $extruder_id) = @_; | ||||
|      | ||||
|     return "" if !$self->need_toolchange; | ||||
|     return $self->_toolchange($extruder_id); | ||||
|     return $self->toolchange($extruder_id); | ||||
| } | ||||
| 
 | ||||
| sub _toolchange { | ||||
| sub toolchange { | ||||
|     my ($self, $extruder_id) = @_; | ||||
|      | ||||
|     # set the new extruder | ||||
|  | @ -140,15 +140,15 @@ sub _toolchange { | |||
|     # return the toolchange command | ||||
|     # if we are running a single-extruder setup, just set the extruder and return nothing | ||||
|     my $gcode = ""; | ||||
|     if ($self->_multiple_extruders) { | ||||
|     if ($self->multiple_extruders) { | ||||
|         $gcode .= sprintf "%s%d%s\n", | ||||
|             ($self->gcode_config->gcode_flavor eq 'makerware' | ||||
|             ($self->config->gcode_flavor eq 'makerware' | ||||
|                 ? 'M135 T' | ||||
|                 : $self->gcode_config->gcode_flavor eq 'sailfish' | ||||
|                 : $self->config->gcode_flavor eq 'sailfish' | ||||
|                     ? 'M108 T' | ||||
|                     : 'T'), | ||||
|             $extruder_id, | ||||
|             ($self->gcode_config->gcode_comments ? ' ; change extruder' : ''); | ||||
|             ($self->config->gcode_comments ? ' ; change extruder' : ''); | ||||
|          | ||||
|         $gcode .= $self->reset_e(1); | ||||
|     } | ||||
|  | @ -165,8 +165,8 @@ sub reset_e { | |||
|         $self->_extruder->set_E(0) if $self->_extruder; | ||||
|     } | ||||
|      | ||||
|     if ($self->_extrusion_axis ne '' && !$self->gcode_config->use_relative_e_distances) { | ||||
|         return sprintf "G92 %s0%s\n", $self->gcode_config->extrusion_axis, ($self->config->gcode_comments ? ' ; reset extrusion distance' : ''); | ||||
|     if ($self->_extrusion_axis ne '' && !$self->config->use_relative_e_distances) { | ||||
|         return sprintf "G92 %s0%s\n", $self->config->extrusion_axis, ($self->config->gcode_comments ? ' ; reset extrusion distance' : ''); | ||||
|     } else { | ||||
|         return ""; | ||||
|     } | ||||
|  | @ -194,7 +194,7 @@ sub travel_to_xy { | |||
|     $self->_pos->set_y($pointf->y);     # )) | ||||
|     return sprintf "G1 X%.3f Y%.3f F%.3f%s\n", | ||||
|         @$pointf, | ||||
|         $self->gcode_config->travel_speed*60, | ||||
|         $self->config->travel_speed*60, | ||||
|         $self->_comment($comment); | ||||
| } | ||||
| 
 | ||||
|  | @ -223,7 +223,7 @@ sub _travel_to_xyz { | |||
|     $self->_pos($pointf3); | ||||
|     return sprintf "G1 X%.3f Y%.3f Z%.3f F%.3f%s\n", | ||||
|         @$pointf3, | ||||
|         $self->gcode_config->travel_speed*60, | ||||
|         $self->config->travel_speed*60, | ||||
|         $self->_comment($comment); | ||||
| } | ||||
| 
 | ||||
|  | @ -251,7 +251,7 @@ sub _travel_to_z { | |||
|     $self->_pos->set_z($z); | ||||
|     return sprintf "G1 Z%.3f F%.3f%s\n", | ||||
|         $z, | ||||
|         $self->gcode_config->travel_speed*60, | ||||
|         $self->config->travel_speed*60, | ||||
|         $self->_comment($comment); | ||||
| } | ||||
| 
 | ||||
|  | @ -318,7 +318,7 @@ sub retract_for_toolchange { | |||
| sub _retract { | ||||
|     my ($self, $length, $restart_extra, $comment) = @_; | ||||
|      | ||||
|     if ($self->gcode_config->use_firmware_retraction) { | ||||
|     if ($self->config->use_firmware_retraction) { | ||||
|         return "G10 ; retract\n"; | ||||
|     } | ||||
|      | ||||
|  | @ -329,11 +329,11 @@ sub _retract { | |||
|             $self->_extrusion_axis, | ||||
|             $self->_extruder->E, | ||||
|             $self->_extruder->retract_speed_mm_min, | ||||
|             $self->_comment($comment . " dE = $dE"); | ||||
|             $self->_comment($comment); | ||||
|     } | ||||
|      | ||||
|     $gcode .= "M103 ; extruder off\n" | ||||
|         if $self->gcode_config->gcode_flavor eq 'makerware'; | ||||
|         if $self->config->gcode_flavor eq 'makerware'; | ||||
|      | ||||
|     return $gcode; | ||||
| } | ||||
|  | @ -344,9 +344,9 @@ sub unretract { | |||
|     my $gcode = ""; | ||||
|      | ||||
|     $gcode .= "M101 ; extruder on\n" | ||||
|         if $self->gcode_config->gcode_flavor eq 'makerware'; | ||||
|         if $self->config->gcode_flavor eq 'makerware'; | ||||
|      | ||||
|     if ($self->gcode_config->use_firmware_retraction) { | ||||
|     if ($self->config->use_firmware_retraction) { | ||||
|         $gcode .= "G11 ; unretract\n"; | ||||
|         $gcode .= $self->reset_e; | ||||
|         return $gcode; | ||||
|  | @ -371,8 +371,8 @@ sub unretract { | |||
| sub lift { | ||||
|     my ($self) = @_; | ||||
|      | ||||
|     if ($self->_lifted == 0 && $self->gcode_config->retract_lift->[0] > 0) { | ||||
|         my $to_lift = $self->gcode_config->retract_lift->[0]; | ||||
|     if ($self->_lifted == 0 && $self->config->retract_lift->[0] > 0) { | ||||
|         my $to_lift = $self->config->retract_lift->[0]; | ||||
|         $self->_lifted($to_lift); | ||||
|         return $self->_travel_to_z($self->_pos->z + $to_lift, 'lift Z'); | ||||
|     } | ||||
|  | @ -390,14 +390,9 @@ sub unlift { | |||
|     return $gcode; | ||||
| } | ||||
| 
 | ||||
| sub has_multiple_extruders { | ||||
| sub hasmultiple_extruders { | ||||
|     my ($self) = @_; | ||||
|     return $self->_multiple_extruders; | ||||
| } | ||||
| 
 | ||||
| sub extruder { | ||||
|     my ($self) = @_; | ||||
|     return $self->_extruder; | ||||
|     return $self->multiple_extruders; | ||||
| } | ||||
| 
 | ||||
| sub extruders { | ||||
|  | @ -875,8 +875,9 @@ sub write_gcode { | |||
|                 if ($finished_objects > 0) { | ||||
|                     $gcodegen->set_shift(map unscale $copy->[$_], X,Y); | ||||
|                     print $fh $gcodegen->retract; | ||||
|                     print $fh $gcodegen->travel_to_xy( | ||||
|                         $gcodegen->point_to_gcode($object->_copies_shift->negative), | ||||
|                     print $fh $gcodegen->travel_to( | ||||
|                         $object->_copies_shift->negative, | ||||
|                         undef, | ||||
|                         'move to origin position for next object', | ||||
|                     ); | ||||
|                 } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci