From 5c4979943e328b2596602c511f6beb0707c34eb7 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 30 Nov 2023 21:47:19 +0800 Subject: [PATCH] Add option to disable emitting M73 gcode (#2114) --- src/libslic3r/GCode/GCodeProcessor.cpp | 23 ++++++++++++++++++++--- src/libslic3r/GCode/GCodeProcessor.hpp | 1 + src/libslic3r/GCodeWriter.cpp | 4 ++++ src/libslic3r/Preset.cpp | 3 ++- src/libslic3r/Print.cpp | 4 ++-- src/libslic3r/PrintConfig.cpp | 6 ++++++ src/libslic3r/PrintConfig.hpp | 1 + src/slic3r/GUI/Tab.cpp | 1 + 8 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index d4aee4b0edd..cc90f893b0a 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -397,6 +397,8 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st if (in.f == nullptr) throw Slic3r::RuntimeError(std::string("Time estimator post process export failed.\nCannot open file for reading.\n")); + const bool disable_m73 = this->disable_m73; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": before process %1%")%filename.c_str(); // temporary file to contain modified gcode std::string out_path = filename + ".postprocess"; @@ -467,7 +469,7 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st // replace placeholder lines with the proper final value // gcode_line is in/out parameter, to reduce expensive memory allocation auto process_placeholders = [&](std::string& gcode_line) { - unsigned int extra_lines_count = 0; + int extra_lines_count = 0; // remove trailing '\n' auto line = std::string_view(gcode_line).substr(0, gcode_line.length() - 1); @@ -476,6 +478,12 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st if (line.length() > 1) { line = line.substr(1); if (line == reserved_tag(ETags::First_Line_M73_Placeholder) || line == reserved_tag(ETags::Last_Line_M73_Placeholder)) { + if (disable_m73) { + // Remove current line + gcode_line = ""; + return std::tuple(true, -1); + } + for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { const TimeMachine& machine = machines[i]; if (machine.enabled) { @@ -673,9 +681,10 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st gcode_line += '\n'; // replace placeholder lines auto [processed, lines_added_count] = process_placeholders(gcode_line); - if (processed && lines_added_count > 0) + if (processed && lines_added_count != 0) offsets.push_back({ line_id, lines_added_count }); - if (! processed && ! is_temporary_decoration(gcode_line) && + + if (!disable_m73 && !processed &&!is_temporary_decoration(gcode_line) && (GCodeReader::GCodeLine::cmd_is(gcode_line, "G1") || GCodeReader::GCodeLine::cmd_is(gcode_line, "G2") || GCodeReader::GCodeLine::cmd_is(gcode_line, "G3"))) { @@ -685,6 +694,12 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st offsets.push_back({ line_id, extra_lines_count }); } + if (disable_m73 && !processed && GCodeReader::GCodeLine::cmd_is(gcode_line, "M73")) { + // Remove any existing M73 command + gcode_line = ""; + offsets.push_back({line_id, -1}); + } + export_line += gcode_line; if (export_line.length() > 65535) write_string(export_line); @@ -1010,6 +1025,8 @@ void GCodeProcessor::apply_config(const PrintConfig& config) DEFAULT_TRAVEL_ACCELERATION; } + m_time_processor.disable_m73 = config.disable_m73; + const ConfigOptionFloat* initial_layer_print_height = config.option("initial_layer_print_height"); if (initial_layer_print_height != nullptr) m_first_layer_height = std::abs(initial_layer_print_height->value); diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 95f4680fd5e..a0bba6ae0cb 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -459,6 +459,7 @@ namespace Slic3r { // Additional load / unload times for a filament exchange sequence. float filament_load_times; float filament_unload_times; + bool disable_m73; std::array(PrintEstimatedStatistics::ETimeMode::Count)> machines; diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 76ac289ae79..5fc57307f06 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -341,6 +341,10 @@ std::string GCodeWriter::update_progress(unsigned int num, unsigned int tot, boo { if (FLAVOR_IS_NOT(gcfMakerWare) && FLAVOR_IS_NOT(gcfSailfish)) return ""; + + if (config.disable_m73) { + return ""; + } unsigned int percent = (unsigned int)floor(100.0 * num / tot + 0.5); if (!allow_100) percent = std::min(percent, (unsigned int)99); diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 9136fec7223..8441763e774 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -835,7 +835,8 @@ static std::vector s_Preset_printer_options { "use_firmware_retraction", "use_relative_e_distances", "printer_notes", "cooling_tube_retraction", "cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "purge_in_prime_tower", "enable_filament_ramming", - "z_offset" + "z_offset", + "disable_m73", }; static std::vector s_Preset_sla_print_options { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 33cdcab5be2..8e39fae33c6 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -203,8 +203,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "during_print_exhaust_fan_speed", "complete_print_exhaust_fan_speed", "activate_chamber_temp_control", - "manual_filament_change" - + "manual_filament_change", + "disable_m73", }; static std::unordered_set steps_ignore; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index cecda027f89..0962d2496df 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3163,6 +3163,12 @@ def = this->add("filament_loading_speed", coFloats); def->mode = comAdvanced; def->set_default_value(new ConfigOptionBool(true)); + def = this->add("disable_m73", coBool); + def->label = L("Disable set remaining print time"); + def->tooltip = "Disable generating of the M73: Set remaining print time in the final gcode"; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionBool(false)); + def = this->add("seam_position", coEnum); def->label = L("Seam position"); def->category = L("Quality"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 7cdd605142d..38bf3f0d371 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -994,6 +994,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionPercent, accel_to_decel_factor)) ((ConfigOptionFloatOrPercent, initial_layer_travel_speed)) ((ConfigOptionBool, bbl_calib_mark_logo)) + ((ConfigOptionBool, disable_m73)) // Orca: mmu ((ConfigOptionFloat, cooling_tube_retraction)) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 94eb6e45798..db34ba7fd14 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3141,6 +3141,7 @@ void TabPrinter::build_fff() optgroup = page->new_optgroup(L("Advanced"), L"param_advanced"); optgroup->append_single_option_line("printer_structure"); optgroup->append_single_option_line("gcode_flavor"); + optgroup->append_single_option_line("disable_m73"); option = optgroup->get_option("thumbnails"); option.opt.full_width = true; optgroup->append_single_option_line(option);