diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index fa565cbe21f..d2ae580d9d8 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1402,6 +1402,8 @@ namespace DoExport { //BBS //if (ret.size() < MAX_TAGS_COUNT) check(_(L("Printing by object G-code")), config.printing_by_object_gcode.value); //if (ret.size() < MAX_TAGS_COUNT) check(_(L("Color Change G-code")), config.color_change_gcode.value); + //Orca + if (ret.size() < MAX_TAGS_COUNT) check(_(L("Change extrusion role G-code")), config.change_extrusion_role_gcode.value); if (ret.size() < MAX_TAGS_COUNT) check(_(L("Pause G-code")), config.machine_pause_gcode.value); if (ret.size() < MAX_TAGS_COUNT) check(_(L("Template Custom G-code")), config.template_custom_gcode.value); if (ret.size() < MAX_TAGS_COUNT) { @@ -4755,6 +4757,18 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, double F = speed * 60; // convert mm/sec to mm/min + //Orca: process custom gcode for extrusion role change + if (path.role() != m_last_extrusion_role && !m_config.change_extrusion_role_gcode.value.empty()) { + DynamicConfig config; + config.set_key_value("extrusion_role", new ConfigOptionString(extrusion_role_to_string_for_parser(path.role()))); + config.set_key_value("last_extrusion_role", new ConfigOptionString(extrusion_role_to_string_for_parser(m_last_extrusion_role))); + config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index + 1)); + config.set_key_value("layer_z", new ConfigOptionFloat(m_layer == nullptr ? m_last_height : m_layer->print_z)); + gcode += this->placeholder_parser_process("change_extrusion_role_gcode", + m_config.change_extrusion_role_gcode.value, m_writer.extruder()->id(), &config) + + "\n"; + } + // extrude arc or line if (m_enable_extrusion_role_markers) { if (path.role() != m_last_extrusion_role) { @@ -5002,6 +5016,35 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, return gcode; } +//Orca: get string name of extrusion role. used for change_extruder_role_gcode +std::string GCode::extrusion_role_to_string_for_parser(const ExtrusionRole & role) +{ + switch (role) { + case erPerimeter: return "Perimeter"; + case erExternalPerimeter: return "ExternalPerimeter"; + case erOverhangPerimeter: return "OverhangPerimeter"; + case erInternalInfill: return "InternalInfill"; + case erSolidInfill: return "SolidInfill"; + case erTopSolidInfill: return "TopSolidInfill"; + case erBottomSurface: return "BottomSurface"; + case erBridgeInfill: + case erInternalBridgeInfill: return "BridgeInfill"; + case erGapFill: return "GapFill"; + case erIroning: return "Ironing"; + case erSkirt: return "Skirt"; + case erBrim: return "Brim"; + case erSupportMaterial: return "SupportMaterial"; + case erSupportMaterialInterface: return "SupportMaterialInterface"; + case erSupportTransition: return "SupportTransition"; + case erWipeTower: return "WipeTower"; + case erCustom: + case erMixed: + case erCount: + case erNone: + default: return "Mixed"; + } +} + std::string encodeBase64(uint64_t value) { //Always use big endian mode diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 9fc63f63be6..5e8d8d19341 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -205,6 +205,7 @@ class GCode { // inside the generated string and after the G-code export finishes. std::string placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override = nullptr); bool enable_cooling_markers() const { return m_enable_cooling_markers; } + std::string extrusion_role_to_string_for_parser(const ExtrusionRole &); // For Perl bindings, to be used exclusively by unit tests. unsigned int layer_count() const { return m_layer_count; } diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index f09240129ef..c8c158f9308 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -819,7 +819,7 @@ static std::vector s_Preset_printer_options { "printer_technology", "printable_area", "bed_exclude_area","bed_custom_texture", "bed_custom_model", "gcode_flavor", "fan_kickstart", "fan_speedup_time", "fan_speedup_overhangs", - "single_extruder_multi_material", "manual_filament_change", "machine_start_gcode", "machine_end_gcode", "before_layer_change_gcode", "layer_change_gcode", "time_lapse_gcode", "change_filament_gcode", + "single_extruder_multi_material", "manual_filament_change", "machine_start_gcode", "machine_end_gcode", "before_layer_change_gcode", "layer_change_gcode", "time_lapse_gcode", "change_filament_gcode", "change_extrusion_role_gcode", "printer_model", "printer_variant", "printable_height", "extruder_clearance_radius", "extruder_clearance_height_to_lid", "extruder_clearance_height_to_rod", "default_print_profile", "inherits", "silent_mode", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index aa63e6bfd7b..2702e3b47f2 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3970,6 +3970,15 @@ def = this->add("filament_loading_speed", coFloats); def->mode = comAdvanced; def->set_default_value(new ConfigOptionString("")); + def = this->add("change_extrusion_role_gcode", coString); + def->label = L("Change extrusion role G-code"); + def->tooltip = L("This gcode is inserted when the extrusion role is changed"); + def->multiline = true; + def->full_width = true; + def->height = 5; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionString("")); + def = this->add("top_surface_line_width", coFloatOrPercent); def->label = L("Top surface"); def->category = L("Quality"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index fd853e1d0ca..a44137a1aed 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -969,6 +969,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionBool, single_extruder_multi_material_priming)) ((ConfigOptionBool, wipe_tower_no_sparse_layers)) ((ConfigOptionString, change_filament_gcode)) + ((ConfigOptionString, change_extrusion_role_gcode)) ((ConfigOptionFloat, travel_speed)) ((ConfigOptionFloat, travel_speed_z)) ((ConfigOptionBool, silent_mode)) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 312944a524e..9a38c7409a7 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3231,6 +3231,17 @@ void TabPrinter::build_fff() option.opt.height = gcode_field_height;//150; optgroup->append_single_option_line(option); + optgroup = page->new_optgroup(L("Change extrusion role G-code"), L"param_gcode", 0); + optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { + validate_custom_gcode_cb(this, optgroup, opt_key, value); + }; + + option = optgroup->get_option("change_extrusion_role_gcode"); + option.opt.full_width = true; + option.opt.is_code = true; + option.opt.height = gcode_field_height;//150; + optgroup->append_single_option_line(option); + optgroup = page->new_optgroup(L("Pause G-code"), L"param_gcode", 0); optgroup->m_on_change = [this, optgroup](const t_config_option_key& opt_key, const boost::any& value) { validate_custom_gcode_cb(this, optgroup, opt_key, value);