From 19eea19d916d2b45ca45e22cf34e4e148ac477a1 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 26 Nov 2016 01:02:51 -0600 Subject: [PATCH] Filament-specific start and end gcode. GUI page copied from Printer settings. --- lib/Slic3r/GUI/Tab.pm | 24 ++++++++++++++++++++++++ lib/Slic3r/Print/GCode.pm | 6 ++++++ xs/src/libslic3r/PrintConfig.cpp | 26 ++++++++++++++++++++++++++ xs/src/libslic3r/PrintConfig.hpp | 4 ++++ 4 files changed, 60 insertions(+) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 259ec7752d..8ca5bcb414 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -893,6 +893,7 @@ sub build { fan_always_on cooling min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers fan_below_layer_time slowdown_below_layer_time min_print_speed + start_filament_gcode end_filament_gcode )); $self->{config}->set('filament_settings_id', ''); @@ -905,6 +906,8 @@ sub build { $optgroup->append_single_option_line('extrusion_multiplier', 0); } + + { my $optgroup = $page->new_optgroup('Temperature (°C)'); @@ -990,6 +993,27 @@ sub build { $optgroup->append_single_option_line($option); } } + { + my $page = $self->add_options_page('Custom G-code', 'cog.png'); + { + my $optgroup = $page->new_optgroup('Start G-code', + label_width => 0, + ); + my $option = $optgroup->get_option('start_filament_gcode', 0); + $option->full_width(1); + $option->height(150); + $optgroup->append_single_option_line($option); + } + { + my $optgroup = $page->new_optgroup('End G-code', + label_width => 0, + ); + my $option = $optgroup->get_option('end_filament_gcode', 0); + $option->full_width(1); + $option->height(150); + $optgroup->append_single_option_line($option); + } + } } sub _update { diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 3c32875edb..73fa8baca8 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -169,6 +169,9 @@ sub export { # set extruder(s) temperature before and after start G-code $self->_print_first_layer_temperature(0); printf $fh "%s\n", $gcodegen->placeholder_parser->process($self->config->start_gcode); + foreach my $start_gcode (@{ $self->config->start_filament_gcode }) { # process filament gcode in order + printf $fh "%s\n", $gcodegen->placeholder_parser->process($start_gcode); + } $self->_print_first_layer_temperature(1); # set other general things @@ -302,6 +305,9 @@ sub export { # write end commands to file print $fh $gcodegen->retract; # TODO: process this retract through PressureRegulator in order to discharge fully print $fh $gcodegen->writer->set_fan(0); + foreach my $end_gcode (@{ $self->config->end_filament_gcode }) { # Process filament-specific gcode in extruder order. + printf $fh "%s\n", $gcodegen->placeholder_parser->process($end_gcode); + } printf $fh "%s\n", $gcodegen->placeholder_parser->process($self->config->end_gcode); print $fh $gcodegen->writer->update_progress($gcodegen->layer_count, $gcodegen->layer_count, 1); # 100% print $fh $gcodegen->writer->postamble; diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index a93fcd00f0..9dcfc0680b 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -149,6 +149,19 @@ PrintConfigDef::PrintConfigDef() def->height = 120; def->default_value = new ConfigOptionString("M104 S0 ; turn off temperature\nG28 X0 ; home X axis\nM84 ; disable motors\n"); + def = this->add("end_filament_gcode", coStrings); + def->label = "End G-code"; + def->tooltip = "This end procedure is inserted at the end of the output file, before the printer end gcode. Note that you can use placeholder variables for all Slic3r settings. If you have multiple extruders, the gcode is processed in extruder order."; + def->cli = "end-filament-gcode=s@"; + def->multiline = true; + def->full_width = true; + def->height = 120; + { + ConfigOptionStrings* opt = new ConfigOptionStrings(); + opt->values.push_back("; Filament-specific end gcode \n;END gcode for filament\n"); + def->default_value = opt; + } + def = this->add("external_fill_pattern", coEnum); def->label = "Top/bottom fill pattern"; def->category = "Infill"; @@ -1083,6 +1096,19 @@ PrintConfigDef::PrintConfigDef() def->height = 120; def->default_value = new ConfigOptionString("G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n"); + def = this->add("start_filament_gcode", coStrings); + def->label = "Start G-code"; + def->tooltip = "This start procedure is inserted at the beginning, after any printer start gcode. This is used to override settings for a specific filament. If Slic3r detects M104, M109, M140 or M190 in your custom codes, such commands will not be prepended automatically so you're free to customize the order of heating commands and other custom actions. Note that you can use placeholder variables for all Slic3r settings, so you can put a \"M109 S[first_layer_temperature]\" command wherever you want. If you have multiple extruders, the gcode is processed in extruder order."; + def->cli = "start-filament-gcode=s@"; + def->multiline = true; + def->full_width = true; + def->height = 120; + { + ConfigOptionStrings* opt = new ConfigOptionStrings(); + opt->values.push_back("; Filament gcode\n"); + def->default_value = opt; + } + def = this->add("support_material", coBool); def->label = "Generate support material"; def->category = "Support material"; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 0c402e50a8..15f442833f 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -286,6 +286,7 @@ class GCodeConfig : public virtual StaticPrintConfig public: ConfigOptionString before_layer_gcode; ConfigOptionString end_gcode; + ConfigOptionStrings end_filament_gcode; ConfigOptionString extrusion_axis; ConfigOptionFloats extrusion_multiplier; ConfigOptionFloats filament_diameter; @@ -305,6 +306,7 @@ class GCodeConfig : public virtual StaticPrintConfig ConfigOptionFloats retract_restart_extra_toolchange; ConfigOptionFloats retract_speed; ConfigOptionString start_gcode; + ConfigOptionStrings start_filament_gcode; ConfigOptionString toolchange_gcode; ConfigOptionFloat travel_speed; ConfigOptionBool use_firmware_retraction; @@ -319,6 +321,7 @@ class GCodeConfig : public virtual StaticPrintConfig virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(before_layer_gcode); OPT_PTR(end_gcode); + OPT_PTR(end_filament_gcode); OPT_PTR(extrusion_axis); OPT_PTR(extrusion_multiplier); OPT_PTR(filament_diameter); @@ -338,6 +341,7 @@ class GCodeConfig : public virtual StaticPrintConfig OPT_PTR(retract_restart_extra_toolchange); OPT_PTR(retract_speed); OPT_PTR(start_gcode); + OPT_PTR(start_filament_gcode); OPT_PTR(toolchange_gcode); OPT_PTR(travel_speed); OPT_PTR(use_firmware_retraction);