mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-20 07:11:12 -06:00 
			
		
		
		
	Satisfy test suite and CLI
This commit is contained in:
		
							parent
							
								
									e2f1040a76
								
							
						
					
					
						commit
						5bf0942f45
					
				
					 20 changed files with 300 additions and 272 deletions
				
			
		|  | @ -3,11 +3,12 @@ use Moo; | |||
| 
 | ||||
| use List::Util qw(min first); | ||||
| use Slic3r::ExtrusionPath ':roles'; | ||||
| use Slic3r::Flow ':roles'; | ||||
| use Slic3r::Geometry qw(epsilon scale unscale scaled_epsilon points_coincide PI X Y B); | ||||
| use Slic3r::Geometry::Clipper qw(union_ex); | ||||
| use Slic3r::Surface ':types'; | ||||
| 
 | ||||
| has 'config'             => (is => 'ro', required => 1); | ||||
| has 'print_config'       => (is => 'ro', default => sub { Slic3r::Config::Print->new }); | ||||
| has 'extra_variables'    => (is => 'rw', default => sub {{}}); | ||||
| has 'extruders'          => (is => 'ro', required => 1); | ||||
| has 'multiple_extruders' => (is => 'lazy'); | ||||
|  | @ -16,6 +17,7 @@ has 'enable_loop_clipping' => (is => 'rw', default => sub {1}); | |||
| has 'enable_wipe'        => (is => 'lazy');   # at least one extruder has wipe enabled | ||||
| has 'layer_count'        => (is => 'ro', required => 1 ); | ||||
| has 'layer'              => (is => 'rw'); | ||||
| has 'region'             => (is => 'rw'); | ||||
| has '_layer_islands'     => (is => 'rw'); | ||||
| has '_upper_layer_islands'  => (is => 'rw'); | ||||
| has '_layer_overhangs'   => (is => 'ro', default => sub { Slic3r::ExPolygon::Collection->new }); | ||||
|  | @ -23,6 +25,8 @@ has 'shift_x'            => (is => 'rw', default => sub {0} ); | |||
| has 'shift_y'            => (is => 'rw', default => sub {0} ); | ||||
| has 'z'                  => (is => 'rw'); | ||||
| has 'speed'              => (is => 'rw'); | ||||
| has '_extrusion_axis'    => (is => 'rw'); | ||||
| has '_retract_lift'      => (is => 'rw'); | ||||
| 
 | ||||
| has 'speeds'             => (is => 'lazy');  # mm/min | ||||
| has 'external_mp'        => (is => 'rw'); | ||||
|  | @ -38,12 +42,19 @@ has 'last_f'             => (is => 'rw', default => sub {""}); | |||
| has 'last_fan_speed'     => (is => 'rw', default => sub {0}); | ||||
| has 'wipe_path'          => (is => 'rw'); | ||||
| 
 | ||||
| sub BUILD { | ||||
|     my ($self) = @_; | ||||
|      | ||||
|     $self->_extrusion_axis($self->print_config->get_extrusion_axis); | ||||
|     $self->_retract_lift($self->print_config->retract_lift->[0]); | ||||
| } | ||||
| 
 | ||||
| sub _build_speeds { | ||||
|     my $self = shift; | ||||
|     return { | ||||
|         map { $_ => 60 * $self->config->get_value("${_}_speed") } | ||||
|         map { $_ => 60 * $self->print_config->get_value("${_}_speed") } | ||||
|             qw(travel perimeter small_perimeter external_perimeter infill | ||||
|                 solid_infill top_solid_infill support_material bridge gap_fill retract), | ||||
|                 solid_infill top_solid_infill bridge gap_fill retract), | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  | @ -59,7 +70,6 @@ my %role_speeds = ( | |||
|     &EXTR_ROLE_BRIDGE                       => 'bridge', | ||||
|     &EXTR_ROLE_INTERNALBRIDGE               => 'solid_infill', | ||||
|     &EXTR_ROLE_SKIRT                        => 'perimeter', | ||||
|     &EXTR_ROLE_SUPPORTMATERIAL              => 'support_material', | ||||
|     &EXTR_ROLE_GAPFILL                      => 'gap_fill', | ||||
| ); | ||||
| 
 | ||||
|  | @ -97,29 +107,29 @@ sub change_layer { | |||
|     $self->_layer_islands($layer->islands); | ||||
|     $self->_upper_layer_islands($layer->upper_layer ? $layer->upper_layer->islands : []); | ||||
|     $self->_layer_overhangs->clear; | ||||
|     if ($layer->id > 0 && ($layer->config->overhangs || $self->config->start_perimeters_at_non_overhang)) { | ||||
|     if ($layer->id > 0 && ($self->print_config->overhangs || $self->print_config->start_perimeters_at_non_overhang)) { | ||||
|         $self->_layer_overhangs->append( | ||||
|             # clone ExPolygons because they come from Surface objects but will be used outside here | ||||
|             map $_->expolygon, map @{$_->slices->filter_by_type(S_TYPE_BOTTOM)}, @{$layer->regions} | ||||
|         ); | ||||
|     } | ||||
|     if ($self->config->avoid_crossing_perimeters) { | ||||
|     if ($self->print_config->avoid_crossing_perimeters) { | ||||
|         $self->layer_mp(Slic3r::GCode::MotionPlanner->new( | ||||
|             islands => union_ex([ map @$_, @{$layer->slices} ], 1), | ||||
|         )); | ||||
|     } | ||||
|      | ||||
|     my $gcode = ""; | ||||
|     if ($self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/) { | ||||
|     if ($self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/) { | ||||
|         $gcode .= sprintf "M73 P%s%s\n", | ||||
|             int(99 * ($layer->id / ($self->layer_count - 1))), | ||||
|             ($self->config->gcode_comments ? ' ; update progress' : ''); | ||||
|             ($self->print_config->gcode_comments ? ' ; update progress' : ''); | ||||
|     } | ||||
|     if ($self->config->first_layer_acceleration) { | ||||
|     if ($self->print_config->first_layer_acceleration) { | ||||
|         if ($layer->id == 0) { | ||||
|             $gcode .= $self->set_acceleration($self->config->first_layer_acceleration); | ||||
|             $gcode .= $self->set_acceleration($self->print_config->first_layer_acceleration); | ||||
|         } elsif ($layer->id == 1) { | ||||
|             $gcode .= $self->set_acceleration($self->config->default_acceleration); | ||||
|             $gcode .= $self->set_acceleration($self->print_config->default_acceleration); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|  | @ -133,7 +143,7 @@ sub move_z { | |||
|      | ||||
|     my $gcode = ""; | ||||
|      | ||||
|     $z += $self->config->z_offset; | ||||
|     $z += $self->print_config->z_offset; | ||||
|     my $current_z = $self->z; | ||||
|     my $nominal_z = defined $current_z ? ($current_z - $self->lifted) : undef; | ||||
|      | ||||
|  | @ -181,11 +191,11 @@ sub extrude_loop { | |||
|     # find candidate starting points | ||||
|     # start looking for concave vertices not being overhangs | ||||
|     my @concave = (); | ||||
|     if ($self->config->start_perimeters_at_concave_points) { | ||||
|     if ($self->print_config->start_perimeters_at_concave_points) { | ||||
|         @concave = $polygon->concave_points; | ||||
|     } | ||||
|     my @candidates = (); | ||||
|     if ($self->config->start_perimeters_at_non_overhang) { | ||||
|     if ($self->print_config->start_perimeters_at_non_overhang) { | ||||
|         @candidates = grep !$self->_layer_overhangs->contains_point($_), @concave; | ||||
|     } | ||||
|     if (!@candidates) { | ||||
|  | @ -193,7 +203,7 @@ sub extrude_loop { | |||
|         @candidates = @concave; | ||||
|         if (!@candidates) { | ||||
|             # if none, look for any non-overhang vertex | ||||
|             if ($self->config->start_perimeters_at_non_overhang) { | ||||
|             if ($self->print_config->start_perimeters_at_non_overhang) { | ||||
|                 @candidates = grep !$self->_layer_overhangs->contains_point($_), @$polygon; | ||||
|             } | ||||
|             if (!@candidates) { | ||||
|  | @ -206,9 +216,9 @@ sub extrude_loop { | |||
|     # find the point of the loop that is closest to the current extruder position | ||||
|     # or randomize if requested | ||||
|     my $last_pos = $self->last_pos; | ||||
|     if ($self->config->randomize_start && $loop->role == EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER) { | ||||
|         $last_pos = Slic3r::Point->new(scale $self->config->print_center->[X], scale $self->config->bed_size->[Y]); | ||||
|         $last_pos->rotate(rand(2*PI), $self->config->print_center); | ||||
|     if ($self->print_config->randomize_start && $loop->role == EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER) { | ||||
|         $last_pos = Slic3r::Point->new(scale $self->print_config->print_center->[X], scale $self->print_config->bed_size->[Y]); | ||||
|         $last_pos->rotate(rand(2*PI), $self->print_config->print_center); | ||||
|     } | ||||
|      | ||||
|     # split the loop at the starting point and make a path | ||||
|  | @ -224,7 +234,7 @@ sub extrude_loop { | |||
|      | ||||
|     my @paths = (); | ||||
|     # detect overhanging/bridging perimeters | ||||
|     if ($self->layer->config->overhangs && $extrusion_path->is_perimeter && $self->_layer_overhangs->count > 0) { | ||||
|     if ($self->layer->print->config->overhangs && $extrusion_path->is_perimeter && $self->_layer_overhangs->count > 0) { | ||||
|         # get non-overhang paths by subtracting overhangs from the loop | ||||
|         push @paths, | ||||
|             map $_->clone, | ||||
|  | @ -234,7 +244,7 @@ sub extrude_loop { | |||
|         push @paths, | ||||
|             map { | ||||
|                 $_->role(EXTR_ROLE_OVERHANG_PERIMETER); | ||||
|                 $_->flow_spacing($self->extruder->bridge_flow->width); | ||||
|                 $_->flow_spacing($self->region->flow(FLOW_ROLE_PERIMETER, undef, 1)->width); | ||||
|                 $_ | ||||
|             } | ||||
|             map $_->clone, | ||||
|  | @ -259,7 +269,7 @@ sub extrude_loop { | |||
|     $self->wipe_path($extrusion_path->polyline->clone) if $self->enable_wipe; | ||||
|      | ||||
|     # make a little move inwards before leaving loop | ||||
|     if ($loop->role == EXTR_ROLE_EXTERNAL_PERIMETER && defined $self->layer && $self->layer->object->config->perimeters > 1) { | ||||
|     if ($loop->role == EXTR_ROLE_EXTERNAL_PERIMETER && defined $self->layer && $self->region->config->perimeters > 1) { | ||||
|         # detect angle between last and first segment | ||||
|         # the side depends on the original winding order of the polygon (left for contours, right for holes) | ||||
|         my @points = $was_clockwise ? (-2, 1) : (1, -2); | ||||
|  | @ -299,13 +309,13 @@ sub extrude_path { | |||
|      | ||||
|     # adjust acceleration | ||||
|     my $acceleration; | ||||
|     if (!$self->config->first_layer_acceleration || $self->layer->id != 0) { | ||||
|         if ($self->config->perimeter_acceleration && $path->is_perimeter) { | ||||
|             $acceleration = $self->config->perimeter_acceleration; | ||||
|         } elsif ($self->config->infill_acceleration && $path->is_fill) { | ||||
|             $acceleration = $self->config->infill_acceleration; | ||||
|         } elsif ($self->config->infill_acceleration && $path->is_bridge) { | ||||
|             $acceleration = $self->config->bridge_acceleration; | ||||
|     if (!$self->print_config->first_layer_acceleration || $self->layer->id != 0) { | ||||
|         if ($self->print_config->perimeter_acceleration && $path->is_perimeter) { | ||||
|             $acceleration = $self->print_config->perimeter_acceleration; | ||||
|         } elsif ($self->print_config->infill_acceleration && $path->is_fill) { | ||||
|             $acceleration = $self->print_config->infill_acceleration; | ||||
|         } elsif ($self->print_config->infill_acceleration && $path->is_bridge) { | ||||
|             $acceleration = $self->print_config->bridge_acceleration; | ||||
|         } | ||||
|         $gcode .= $self->set_acceleration($acceleration) if $acceleration; | ||||
|     } | ||||
|  | @ -322,15 +332,13 @@ sub extrude_path { | |||
|      | ||||
|     # calculate extrusion length per distance unit | ||||
|     my $e = $self->extruder->e_per_mm3 * $area; | ||||
|     $e = 0 if !$self->config->extrusion_axis; | ||||
|     $e = 0 if !$self->_extrusion_axis; | ||||
|      | ||||
|     # set speed | ||||
|     $self->speed( $params{speed} || $role_speeds{$path->role} || die "Unknown role: " . $path->role ); | ||||
|     my $F = $self->speeds->{$self->speed} // $self->speed; | ||||
|     if ($self->layer->id == 0) { | ||||
|         $F = $self->config->first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/ | ||||
|             ? sprintf("%.3f", $F * $1/100) | ||||
|             : $self->config->first_layer_speed * 60; | ||||
|         $F = $self->print_config->get_abs_value_over('first_layer_speed', $F/60) * 60; | ||||
|     } | ||||
|      | ||||
|     # extrude arc or line | ||||
|  | @ -350,12 +358,12 @@ sub extrude_path { | |||
|             $gcode .= sprintf "G1 X%.3f Y%.3f", | ||||
|                 ($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];  #** | ||||
|             $gcode .= sprintf(" %s%.5f", $self->config->extrusion_axis, $E) | ||||
|             $gcode .= sprintf(" %s%.5f", $self->_extrusion_axis, $E) | ||||
|                 if $E; | ||||
|             $gcode .= " F$local_F" | ||||
|                 if $local_F; | ||||
|             $gcode .= " ; $description" | ||||
|                 if $self->config->gcode_comments; | ||||
|                 if $self->print_config->gcode_comments; | ||||
|             $gcode .= "\n"; | ||||
|              | ||||
|             # only include F in the first line | ||||
|  | @ -369,19 +377,14 @@ sub extrude_path { | |||
|     $gcode .= ";_BRIDGE_FAN_END\n" if $path->is_bridge; | ||||
|     $self->last_pos($path->last_point); | ||||
|      | ||||
|     if ($self->config->cooling) { | ||||
|     if ($self->print_config->cooling) { | ||||
|         my $path_time = $path_length / $F * 60; | ||||
|         if ($self->layer->id == 0) { | ||||
|             $path_time = $self->config->first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/ | ||||
|                 ? $path_time / ($1/100) | ||||
|                 : $path_length / $self->config->first_layer_speed * 60; | ||||
|         } | ||||
|         $self->elapsed_time($self->elapsed_time + $path_time); | ||||
|     } | ||||
|      | ||||
|     # reset acceleration | ||||
|     $gcode .= $self->set_acceleration($self->config->default_acceleration) | ||||
|         if $acceleration && $self->config->default_acceleration; | ||||
|     $gcode .= $self->set_acceleration($self->print_config->default_acceleration) | ||||
|         if $acceleration && $self->print_config->default_acceleration; | ||||
|      | ||||
|     return $gcode; | ||||
| } | ||||
|  | @ -400,7 +403,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 | ||||
|         || ($self->config->only_retract_when_crossing_perimeters | ||||
|         || ($self->print_config->only_retract_when_crossing_perimeters | ||||
|             && (first { $_->contains_line($travel) } @{$self->_upper_layer_islands}) | ||||
|             && (first { $_->contains_line($travel) } @{$self->_layer_islands})) | ||||
|         || (defined $role && $role == EXTR_ROLE_SUPPORTMATERIAL && (first { $_->contains_line($travel) } @{$self->layer->support_islands})) | ||||
|  | @ -408,7 +411,7 @@ sub travel_to { | |||
|         $self->straight_once(0); | ||||
|         $self->speed('travel'); | ||||
|         $gcode .= $self->G0($point, undef, 0, $comment || ""); | ||||
|     } elsif (!$self->config->avoid_crossing_perimeters || $self->straight_once) { | ||||
|     } elsif (!$self->print_config->avoid_crossing_perimeters || $self->straight_once) { | ||||
|         $self->straight_once(0); | ||||
|         $gcode .= $self->retract; | ||||
|         $self->speed('travel'); | ||||
|  | @ -441,7 +444,7 @@ sub _plan { | |||
|     my @travel = @{$mp->shortest_path($self->last_pos, $point)->lines}; | ||||
|      | ||||
|     # if the path is not contained in a single island we need to retract | ||||
|     my $need_retract = !$self->config->only_retract_when_crossing_perimeters; | ||||
|     my $need_retract = !$self->print_config->only_retract_when_crossing_perimeters; | ||||
|     if (!$need_retract) { | ||||
|         $need_retract = 1; | ||||
|         foreach my $island (@{$self->_upper_layer_islands}) { | ||||
|  | @ -481,14 +484,14 @@ sub retract { | |||
|     if ($self->extruder->wipe && $self->wipe_path) { | ||||
|         my @points = @{$self->wipe_path}; | ||||
|         $wipe_path = Slic3r::Polyline->new($self->last_pos, @{$self->wipe_path}[1..$#{$self->wipe_path}]); | ||||
|         $wipe_path->clip_end($wipe_path->length - $self->extruder->scaled_wipe_distance($self->config->travel_speed)); | ||||
|         $wipe_path->clip_end($wipe_path->length - $self->extruder->scaled_wipe_distance($self->print_config->travel_speed)); | ||||
|     } | ||||
|      | ||||
|     # prepare moves | ||||
|     my $retract = [undef, undef, -$length, $comment]; | ||||
|     my $lift    = ($self->extruder->retract_lift == 0 || defined $params{move_z}) && !$self->lifted | ||||
|     my $lift    = ($self->_retract_lift == 0 || defined $params{move_z}) && !$self->lifted | ||||
|         ? undef | ||||
|         : [undef, $self->z + $self->extruder->retract_lift, 0, 'lift plate during travel']; | ||||
|         : [undef, $self->z + $self->_retract_lift, 0, 'lift plate during travel']; | ||||
|      | ||||
|     # check that we have a positive wipe length | ||||
|     if ($wipe_path) { | ||||
|  | @ -500,7 +503,7 @@ sub retract { | |||
|             my $segment_length = $line->length; | ||||
|             # reduce retraction length a bit to avoid effective retraction speed to be greater than the configured one | ||||
|             # due to rounding | ||||
|             my $e = $retract->[2] * ($segment_length / $self->extruder->scaled_wipe_distance($self->config->travel_speed)) * 0.95; | ||||
|             my $e = $retract->[2] * ($segment_length / $self->extruder->scaled_wipe_distance($self->print_config->travel_speed)) * 0.95; | ||||
|             $retracted += $e; | ||||
|             $gcode .= $self->G1($line->b, undef, $e, $retract->[3] . ";_WIPE"); | ||||
|         } | ||||
|  | @ -510,7 +513,7 @@ sub retract { | |||
|             $self->speed('retract'); | ||||
|             $gcode .= $self->G1(undef, undef, $retract->[2] - $retracted, $comment); | ||||
|         } | ||||
|     } elsif ($self->config->use_firmware_retraction) { | ||||
|     } elsif ($self->print_config->use_firmware_retraction) { | ||||
|         $gcode .= "G10 ; retract\n"; | ||||
|     } else { | ||||
|         $self->speed('retract'); | ||||
|  | @ -518,23 +521,23 @@ sub retract { | |||
|     } | ||||
|     if (!$self->lifted) { | ||||
|         $self->speed('travel'); | ||||
|         if (defined $params{move_z} && $self->extruder->retract_lift > 0) { | ||||
|             my $travel = [undef, $params{move_z} + $self->extruder->retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift']; | ||||
|         if (defined $params{move_z} && $self->_retract_lift > 0) { | ||||
|             my $travel = [undef, $params{move_z} + $self->_retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift']; | ||||
|             $gcode .= $self->G0(@$travel); | ||||
|             $self->lifted($self->extruder->retract_lift); | ||||
|             $self->lifted($self->_retract_lift); | ||||
|         } elsif ($lift) { | ||||
|             $gcode .= $self->G1(@$lift); | ||||
|         } | ||||
|     } | ||||
|     $self->extruder->retracted($self->extruder->retracted + $length); | ||||
|     $self->extruder->restart_extra($restart_extra); | ||||
|     $self->lifted($self->extruder->retract_lift) if $lift; | ||||
|     $self->lifted($self->_retract_lift) if $lift; | ||||
|      | ||||
|     # reset extrusion distance during retracts | ||||
|     # this makes sure we leave sufficient precision in the firmware | ||||
|     $gcode .= $self->reset_e; | ||||
|      | ||||
|     $gcode .= "M103 ; extruder off\n" if $self->config->gcode_flavor eq 'makerware'; | ||||
|     $gcode .= "M103 ; extruder off\n" if $self->print_config->gcode_flavor eq 'makerware'; | ||||
|      | ||||
|     return $gcode; | ||||
| } | ||||
|  | @ -543,7 +546,7 @@ sub unretract { | |||
|     my ($self) = @_; | ||||
|      | ||||
|     my $gcode = ""; | ||||
|     $gcode .= "M101 ; extruder on\n" if $self->config->gcode_flavor eq 'makerware'; | ||||
|     $gcode .= "M101 ; extruder on\n" if $self->print_config->gcode_flavor eq 'makerware'; | ||||
|      | ||||
|     if ($self->lifted) { | ||||
|         $self->speed('travel'); | ||||
|  | @ -554,15 +557,15 @@ sub unretract { | |||
|     my $to_unretract = $self->extruder->retracted + $self->extruder->restart_extra; | ||||
|     if ($to_unretract) { | ||||
|         $self->speed('retract'); | ||||
|         if ($self->config->use_firmware_retraction) { | ||||
|         if ($self->print_config->use_firmware_retraction) { | ||||
|             $gcode .= "G11 ; unretract\n"; | ||||
|         } elsif ($self->config->extrusion_axis) { | ||||
|         } elsif ($self->_extrusion_axis) { | ||||
|             # use G1 instead of G0 because G0 will blend the restart with the previous travel move | ||||
|             $gcode .= sprintf "G1 %s%.5f F%.3f", | ||||
|                 $self->config->extrusion_axis, | ||||
|                 $self->_extrusion_axis, | ||||
|                 $self->extruder->extrude($to_unretract), | ||||
|                 $self->extruder->retract_speed_mm_min; | ||||
|             $gcode .= " ; compensate retraction" if $self->config->gcode_comments; | ||||
|             $gcode .= " ; compensate retraction" if $self->print_config->gcode_comments; | ||||
|             $gcode .= "\n"; | ||||
|         } | ||||
|         $self->extruder->retracted(0); | ||||
|  | @ -574,11 +577,11 @@ sub unretract { | |||
| 
 | ||||
| sub reset_e { | ||||
|     my ($self) = @_; | ||||
|     return "" if $self->config->gcode_flavor =~ /^(?:mach3|makerware|sailfish)$/; | ||||
|     return "" if $self->print_config->gcode_flavor =~ /^(?:mach3|makerware|sailfish)$/; | ||||
|      | ||||
|     $self->extruder->E(0) if $self->extruder; | ||||
|     return sprintf "G92 %s0%s\n", $self->config->extrusion_axis, ($self->config->gcode_comments ? ' ; reset extrusion distance' : '') | ||||
|         if $self->config->extrusion_axis && !$self->config->use_relative_e_distances; | ||||
|     return sprintf "G92 %s0%s\n", $self->_extrusion_axis, ($self->print_config->gcode_comments ? ' ; reset extrusion distance' : '') | ||||
|         if $self->_extrusion_axis && !$self->print_config->use_relative_e_distances; | ||||
| } | ||||
| 
 | ||||
| sub set_acceleration { | ||||
|  | @ -586,12 +589,12 @@ sub set_acceleration { | |||
|     return "" if !$acceleration; | ||||
|      | ||||
|     return sprintf "M204 S%s%s\n", | ||||
|         $acceleration, ($self->config->gcode_comments ? ' ; adjust acceleration' : ''); | ||||
|         $acceleration, ($self->print_config->gcode_comments ? ' ; adjust acceleration' : ''); | ||||
| } | ||||
| 
 | ||||
| sub G0 { | ||||
|     my $self = shift; | ||||
|     return $self->G1(@_) if !($self->config->g0 || $self->config->gcode_flavor eq 'mach3'); | ||||
|     return $self->G1(@_) if !($self->print_config->g0 || $self->print_config->gcode_flavor eq 'mach3'); | ||||
|     return $self->_G0_G1("G0", @_); | ||||
| } | ||||
| 
 | ||||
|  | @ -628,11 +631,11 @@ sub _Gx { | |||
|     $gcode .= sprintf " F%.3f", $F; | ||||
|      | ||||
|     # output extrusion distance | ||||
|     if ($e && $self->config->extrusion_axis) { | ||||
|         $gcode .= sprintf " %s%.5f", $self->config->extrusion_axis, $self->extruder->extrude($e); | ||||
|     if ($e && $self->_extrusion_axis) { | ||||
|         $gcode .= sprintf " %s%.5f", $self->_extrusion_axis, $self->extruder->extrude($e); | ||||
|     } | ||||
|      | ||||
|     $gcode .= " ; $comment" if $comment && $self->config->gcode_comments; | ||||
|     $gcode .= " ; $comment" if $comment && $self->print_config->gcode_comments; | ||||
|     return "$gcode\n"; | ||||
| } | ||||
| 
 | ||||
|  | @ -653,8 +656,8 @@ sub set_extruder { | |||
|     $gcode .= $self->retract(toolchange => 1) if defined $self->extruder; | ||||
|      | ||||
|     # append custom toolchange G-code | ||||
|     if (defined $self->extruder && $self->config->toolchange_gcode) { | ||||
|         $gcode .= sprintf "%s\n", $self->replace_variables($self->config->toolchange_gcode, { | ||||
|     if (defined $self->extruder && $self->print_config->toolchange_gcode) { | ||||
|         $gcode .= sprintf "%s\n", $self->replace_variables($self->print_config->toolchange_gcode, { | ||||
|             previous_extruder   => $self->extruder->id, | ||||
|             next_extruder       => $extruder->id, | ||||
|         }); | ||||
|  | @ -669,24 +672,24 @@ sub set_extruder { | |||
|             ? $self->extruder->first_layer_temperature | ||||
|             : $self->extruder->temperature; | ||||
|         # we assume that heating is always slower than cooling, so no need to block | ||||
|         $gcode .= $self->set_temperature($temp + $self->config->standby_temperature_delta, 0); | ||||
|         $gcode .= $self->set_temperature($temp + $self->print_config->standby_temperature_delta, 0); | ||||
|     } | ||||
|      | ||||
|     # set the new extruder | ||||
|     $self->extruder($extruder); | ||||
|     $gcode .= sprintf "%s%d%s\n",  | ||||
|         ($self->config->gcode_flavor eq 'makerware' | ||||
|         ($self->print_config->gcode_flavor eq 'makerware' | ||||
|             ? 'M135 T' | ||||
|             : $self->config->gcode_flavor eq 'sailfish' | ||||
|             : $self->print_config->gcode_flavor eq 'sailfish' | ||||
|                 ? 'M108 T' | ||||
|                 : 'T'), | ||||
|         $extruder->id, | ||||
|         ($self->config->gcode_comments ? ' ; change extruder' : ''); | ||||
|         ($self->print_config->gcode_comments ? ' ; change extruder' : ''); | ||||
|      | ||||
|     $gcode .= $self->reset_e; | ||||
|      | ||||
|     # set the new extruder to the operating temperature | ||||
|     if ($self->config->ooze_prevention) { | ||||
|     if ($self->print_config->ooze_prevention) { | ||||
|         my $temp = defined $self->layer && $self->layer->id == 0 | ||||
|             ? $self->extruder->first_layer_temperature | ||||
|             : $self->extruder->temperature; | ||||
|  | @ -702,18 +705,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->config->gcode_flavor eq 'teacup' | ||||
|             my $code = $self->print_config->gcode_flavor eq 'teacup' | ||||
|                 ? 'M106 S0' | ||||
|                 : $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/ | ||||
|                 : $self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/ | ||||
|                     ? 'M127' | ||||
|                     : 'M107'; | ||||
|             return sprintf "$code%s\n", ($self->config->gcode_comments ? ' ; disable fan' : ''); | ||||
|             return sprintf "$code%s\n", ($self->print_config->gcode_comments ? ' ; disable fan' : ''); | ||||
|         } else { | ||||
|             if ($self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/) { | ||||
|                 return sprintf "M126%s\n", ($self->config->gcode_comments ? ' ; enable fan' : ''); | ||||
|             if ($self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/) { | ||||
|                 return sprintf "M126%s\n", ($self->print_config->gcode_comments ? ' ; enable fan' : ''); | ||||
|             } else { | ||||
|                 return sprintf "M106 %s%d%s\n", ($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), | ||||
|                     (255 * $speed / 100), ($self->config->gcode_comments ? ' ; enable fan' : ''); | ||||
|                 return sprintf "M106 %s%d%s\n", ($self->print_config->gcode_flavor eq 'mach3' ? 'P' : 'S'), | ||||
|                     (255 * $speed / 100), ($self->print_config->gcode_comments ? ' ; enable fan' : ''); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | @ -723,17 +726,17 @@ sub set_fan { | |||
| sub set_temperature { | ||||
|     my ($self, $temperature, $wait, $tool) = @_; | ||||
|      | ||||
|     return "" if $wait && $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/; | ||||
|     return "" if $wait && $self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/; | ||||
|      | ||||
|     my ($code, $comment) = ($wait && $self->config->gcode_flavor ne 'teacup') | ||||
|     my ($code, $comment) = ($wait && $self->print_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->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature, | ||||
|         (defined $tool && ($self->multiple_extruders || $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/)) ? "T$tool " : ""; | ||||
|         ($self->print_config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature, | ||||
|         (defined $tool && ($self->multiple_extruders || $self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/)) ? "T$tool " : ""; | ||||
|      | ||||
|     $gcode .= "M116 ; wait for temperature to be reached\n" | ||||
|         if $self->config->gcode_flavor eq 'teacup' && $wait; | ||||
|         if $self->print_config->gcode_flavor eq 'teacup' && $wait; | ||||
|      | ||||
|     return $gcode; | ||||
| } | ||||
|  | @ -741,21 +744,21 @@ sub set_temperature { | |||
| sub set_bed_temperature { | ||||
|     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') | ||||
|     my ($code, $comment) = ($wait && $self->print_config->gcode_flavor ne 'teacup') | ||||
|         ? (($self->print_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->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature; | ||||
|         ($self->print_config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature; | ||||
|      | ||||
|     $gcode .= "M116 ; wait for bed temperature to be reached\n" | ||||
|         if $self->config->gcode_flavor eq 'teacup' && $wait; | ||||
|         if $self->print_config->gcode_flavor eq 'teacup' && $wait; | ||||
|      | ||||
|     return $gcode; | ||||
| } | ||||
| 
 | ||||
| sub replace_variables { | ||||
|     my ($self, $string, $extra) = @_; | ||||
|     return $self->config->replace_options($string, { %{$self->extra_variables}, %{ $extra || {} } }); | ||||
|     return $self->print_config->replace_options($string, { %{$self->extra_variables}, %{ $extra || {} } }); | ||||
| } | ||||
| 
 | ||||
| 1; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci