From 615bcb27dd6114b9a6ecacf5c5ddb59ae301c191 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 20 Feb 2012 11:44:30 +0100 Subject: [PATCH] New --gcode-flavor option. extrusion_axis, use_relative_e_distances options hidden and implied. #158 --- README.markdown | 6 ++---- lib/Slic3r.pm | 3 ++- lib/Slic3r/Config.pm | 10 ++++++++++ lib/Slic3r/GUI/SkeinPanel.pm | 2 +- lib/Slic3r/Print.pm | 18 +++++++++++------- slic3r.pl | 6 ++---- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.markdown b/README.markdown index 702f91c34..f5eaea572 100644 --- a/README.markdown +++ b/README.markdown @@ -97,12 +97,10 @@ The author is Alessandro Ranellucci (me). --nozzle-diameter Diameter of nozzle in mm (default: 0.5) --print-center Coordinates in mm of the point to center the print around (default: 100,100) - --use-relative-e-distances - Use relative distances for extrusion in GCODE output - --extrusion-axis The axis used for extrusion; leave empty to disable extrusion - (default: E) --z-offset Additional height in mm to add to vertical coordinates (+/-, default: 0) + --gcode-flavor The type of G-code to generate (reprap/teacup/makerbot/mach3/no-extrusion, + default: reprap) --gcode-arcs Use G2/G3 commands for native arcs (experimental, not supported by all firmwares) --g0 Use G0 commands for retraction (experimental, not supported by all diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 229383e99..ff82b57b0 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -48,9 +48,10 @@ our $output_filename_format = '[input_filename_base].gcode'; # printer options our $nozzle_diameter = 0.5; our $print_center = [100,100]; # object will be centered around this point +our $z_offset = 0; +our $gcode_flavor = 'reprap'; our $use_relative_e_distances = 0; our $extrusion_axis = 'E'; -our $z_offset = 0; our $gcode_arcs = 0; our $g0 = 0; our $gcode_comments = 0; diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 268441d22..b169af3af 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -40,6 +40,13 @@ our $Options = { serialize => sub { join ',', @{$_[0]} }, deserialize => sub { [ split /,/, $_[0] ] }, }, + 'gcode_flavor' => { + label => 'G-code flavor', + cli => 'gcode-flavor=s', + type => 'select', + values => [qw(reprap teacup makerbot mach3 no-extrusion)], + labels => ['RepRap (Marlin/Sprinter)', 'Teacup', 'MakerBot', 'Mach3/EMC', 'No extrusion'], + }, 'use_relative_e_distances' => { label => 'Use relative E distances', cli => 'use-relative-e-distances', @@ -520,6 +527,9 @@ sub validate { die "Invalid value for --bridge-flow-ratio\n" if $Slic3r::bridge_flow_ratio <= 0; + # G-code flavors + $Slic3r::extrusion_axis = 'A' if $Slic3r::gcode_flavor eq 'mach3'; + # legacy with existing config files $Slic3r::small_perimeter_speed ||= $Slic3r::perimeter_speed; $Slic3r::bridge_speed ||= $Slic3r::infill_speed; diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index f420d9e1e..2ad87521b 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -21,7 +21,7 @@ sub new { my %panels = ( printer => { title => 'Printer', - options => [qw(nozzle_diameter print_center z_offset use_relative_e_distances extrusion_axis g0)], + options => [qw(nozzle_diameter print_center z_offset gcode_flavor g0)], }, filament => { title => 'Filament', diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 2f5c40705..7a739d28a 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -546,16 +546,20 @@ sub export_gcode { print $fh "\n"; # write start commands to file - printf $fh "M104 S%d ; set temperature\n", $Slic3r::temperature if $Slic3r::temperature; + printf $fh "M104 %s%d ; set temperature\n", + ($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $Slic3r::temperature + if $Slic3r::temperature; print $fh "$Slic3r::start_gcode\n"; - printf $fh "M109 S%d ; wait for temperature to be reached\n", $Slic3r::temperature if $Slic3r::temperature; + printf $fh "M109 %s%d ; wait for temperature to be reached\n", + ($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $Slic3r::temperature + if $Slic3r::temperature && $Slic3r::gcode_flavor ne 'makerbot'; print $fh "G90 ; use absolute coordinates\n"; print $fh "G21 ; set units to millimeters\n"; - printf $fh "G92 %s0 ; reset extrusion distance\n", $Slic3r::extrusion_axis if $Slic3r::extrusion_axis; - if ($Slic3r::use_relative_e_distances) { - print $fh "M83 ; use relative distances for extrusion\n"; - } else { - print $fh "M82 ; use absolute distances for extrusion\n"; + if ($Slic3r::gcode_flavor =~ /^(?:reprap|teacup|makerbot)$/) { + printf $fh "G92 %s0 ; reset extrusion distance\n", $Slic3r::extrusion_axis; + if (!$Slic3r::use_relative_e_distances && $Slic3r::gcode_flavor =~ /^(?:reprap|makerbot)$/) { + print $fh "M82 ; use absolute distances for extrusion\n"; + } } # calculate X,Y shift to center print around specified origin diff --git a/slic3r.pl b/slic3r.pl index 7d534c027..fd1a9fdbc 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -113,12 +113,10 @@ Usage: slic3r.pl [ OPTIONS ] file.stl --nozzle-diameter Diameter of nozzle in mm (default: $Slic3r::nozzle_diameter) --print-center Coordinates in mm of the point to center the print around (default: $Slic3r::print_center->[0],$Slic3r::print_center->[1]) - --use-relative-e-distances - Use relative distances for extrusion in GCODE output - --extrusion-axis The axis used for extrusion; leave empty to disable extrusion - (default: $Slic3r::extrusion_axis) --z-offset Additional height in mm to add to vertical coordinates (+/-, default: $Slic3r::z_offset) + --gcode-flavor The type of G-code to generate (reprap/teacup/makerbot/mach3/no-extrusion, + default: $Slic3r::gcode_flavor) --gcode-arcs Use G2/G3 commands for native arcs (experimental, not supported by all firmwares) --g0 Use G0 commands for retraction (experimental, not supported by all