Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable emitting M73 gcode (#2114) #2940

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/libslic3r/GCode/GCodeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
SoftFever marked this conversation as resolved.
Show resolved Hide resolved
// Remove current line
gcode_line = "";
return std::tuple(true, -1);
}

for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
const TimeMachine& machine = machines[i];
if (machine.enabled) {
Expand Down Expand Up @@ -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"))) {
Expand All @@ -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);
Expand Down Expand Up @@ -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<ConfigOptionFloat>("initial_layer_print_height");
if (initial_layer_print_height != nullptr)
m_first_layer_height = std::abs(initial_layer_print_height->value);
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/GCode/GCodeProcessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeMachine, static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count)> machines;

Expand Down
4 changes: 4 additions & 0 deletions src/libslic3r/GCodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,8 @@ static std::vector<std::string> 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<std::string> s_Preset_sla_print_options {
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> steps_ignore;
Expand Down
6 changes: 6 additions & 0 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading