From 4986afe94fc725e07b2410022d82486b7d3f8720 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 26 Apr 2023 09:34:02 +0200 Subject: [PATCH] Tech ENABLE_GCODE_POSTPROCESS_BACKTRACE set as default --- src/libslic3r/GCode/GCodeProcessor.cpp | 144 ------------------------- src/libslic3r/GCode/GCodeProcessor.hpp | 2 - src/libslic3r/GCodeReader.hpp | 2 - src/libslic3r/Technologies.hpp | 2 - 4 files changed, 150 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 02088ee7b..9dab740e5 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -442,9 +442,7 @@ void GCodeProcessorResult::reset() { max_print_height = 0.0f; settings_ids.reset(); extruders_count = 0; -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE backtrace_enabled = false; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE extruder_colors = std::vector(); filament_diameters = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER); filament_densities = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY); @@ -462,9 +460,7 @@ void GCodeProcessorResult::reset() { max_print_height = 0.0f; settings_ids.reset(); extruders_count = 0; -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE backtrace_enabled = false; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE extruder_colors = std::vector(); filament_diameters = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER); filament_densities = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY); @@ -558,9 +554,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_producer = EProducer::PrusaSlicer; m_flavor = config.gcode_flavor; -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE m_result.backtrace_enabled = is_XL_printer(config); -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE size_t extruders_count = config.nozzle_diameter.values.size(); m_result.extruders_count = extruders_count; @@ -3477,7 +3471,6 @@ void GCodeProcessor::post_process() last_exported_stop[i] = time_in_minutes(m_time_processor.machines[i].time); } -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE // Helper class to modify and export gcode to file class ExportLines { @@ -3712,26 +3705,15 @@ void GCodeProcessor::post_process() }; ExportLines export_lines(m_result.backtrace_enabled ? ExportLines::EWriteType::ByTime : ExportLines::EWriteType::BySize, m_time_processor.machines[0]); -#else - // buffer line to export only when greater than 64K to reduce writing calls - std::string export_line; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE // 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) { -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE bool processed = false; -#else - unsigned int extra_lines_count = 0; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE // remove trailing '\n' auto line = std::string_view(gcode_line).substr(0, gcode_line.length() - 1); -#if !ENABLE_GCODE_POSTPROCESS_BACKTRACE - std::string ret; -#endif // !ENABLE_GCODE_POSTPROCESS_BACKTRACE if (line.length() > 1) { line = line.substr(1); if (m_time_processor.export_remaining_time_enabled && @@ -3740,29 +3722,16 @@ void GCodeProcessor::post_process() const TimeMachine& machine = m_time_processor.machines[i]; if (machine.enabled) { // export pair -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE export_lines.append_line(format_line_M73_main(machine.line_m73_main_mask.c_str(), (line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? 0 : 100, (line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? time_in_minutes(machine.time) : 0)); processed = true; -#else - ret += format_line_M73_main(machine.line_m73_main_mask.c_str(), - (line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? 0 : 100, - (line == reserved_tag(ETags::First_Line_M73_Placeholder)) ? time_in_minutes(machine.time) : 0); - ++extra_lines_count; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE // export remaining time to next printer stop if (line == reserved_tag(ETags::First_Line_M73_Placeholder) && !machine.stop_times.empty()) { const int to_export_stop = time_in_minutes(machine.stop_times.front().elapsed_time); -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE export_lines.append_line(format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop)); last_exported_stop[i] = to_export_stop; -#else - ret += format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop); - last_exported_stop[i] = to_export_stop; - ++extra_lines_count; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE } } } @@ -3776,12 +3745,8 @@ void GCodeProcessor::post_process() sprintf(buf, "; estimated printing time (%s mode) = %s\n", (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent", get_time_dhms(machine.time).c_str()); -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE export_lines.append_line(buf); processed = true; -#else - ret += buf; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE } } for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { @@ -3792,25 +3757,14 @@ void GCodeProcessor::post_process() sprintf(buf, "; estimated first layer printing time (%s mode) = %s\n", (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent", get_time_dhms(machine.layers_time.empty() ? 0.f : machine.layers_time.front()).c_str()); -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE export_lines.append_line(buf); processed = true; -#else - ret += buf; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE } } } } -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE return processed; -#else - if (!ret.empty()) - // Not moving the move operator on purpose, so that the gcode_line allocation will grow and it will not be reallocated after handful of lines are processed. - gcode_line = ret; - return std::tuple(!ret.empty(), (extra_lines_count == 0) ? extra_lines_count : extra_lines_count - 1); -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE }; std::vector filament_mm(m_result.extruders_count, 0.0); @@ -3884,16 +3838,8 @@ void GCodeProcessor::post_process() time_in_minutes, format_time_float, format_line_M73_main, format_line_M73_stop_int, format_line_M73_stop_float, time_in_last_minute, // Caches, to be modified &g1_times_cache_it, &last_exported_main, &last_exported_stop, -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE &export_lines] -#else - // String output - &export_line] -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE (const size_t g1_lines_counter) { -#if !ENABLE_GCODE_POSTPROCESS_BACKTRACE - unsigned int exported_lines_count = 0; -#endif // !ENABLE_GCODE_POSTPROCESS_BACKTRACE if (m_time_processor.export_remaining_time_enabled) { for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { const TimeMachine& machine = m_time_processor.machines[i]; @@ -3907,17 +3853,9 @@ void GCodeProcessor::post_process() std::pair to_export_main = { int(100.0f * it->elapsed_time / machine.time), time_in_minutes(machine.time - it->elapsed_time) }; if (last_exported_main[i] != to_export_main) { -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE export_lines.append_line(format_line_M73_main(machine.line_m73_main_mask.c_str(), to_export_main.first, to_export_main.second)); -#else - export_line += format_line_M73_main(machine.line_m73_main_mask.c_str(), - to_export_main.first, to_export_main.second); -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE last_exported_main[i] = to_export_main; -#if !ENABLE_GCODE_POSTPROCESS_BACKTRACE - ++exported_lines_count; -#endif // !ENABLE_GCODE_POSTPROCESS_BACKTRACE } // export remaining time to next printer stop auto it_stop = std::upper_bound(machine.stop_times.begin(), machine.stop_times.end(), it->elapsed_time, @@ -3927,15 +3865,8 @@ void GCodeProcessor::post_process() if (last_exported_stop[i] != to_export_stop) { if (to_export_stop > 0) { if (last_exported_stop[i] != to_export_stop) { -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE export_lines.append_line(format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop)); -#else - export_line += format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop); -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE last_exported_stop[i] = to_export_stop; -#if !ENABLE_GCODE_POSTPROCESS_BACKTRACE - ++exported_lines_count; -#endif // !ENABLE_GCODE_POSTPROCESS_BACKTRACE } } else { @@ -3954,22 +3885,12 @@ void GCodeProcessor::post_process() } if (is_last) { -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE if (std::distance(machine.stop_times.begin(), it_stop) == static_cast(machine.stop_times.size() - 1)) export_lines.append_line(format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop)); else export_lines.append_line(format_line_M73_stop_float(machine.line_m73_stop_mask.c_str(), time_in_last_minute(it_stop->elapsed_time - it->elapsed_time))); -#else - if (std::distance(machine.stop_times.begin(), it_stop) == static_cast(machine.stop_times.size() - 1)) - export_line += format_line_M73_stop_int(machine.line_m73_stop_mask.c_str(), to_export_stop); - else - export_line += format_line_M73_stop_float(machine.line_m73_stop_mask.c_str(), time_in_last_minute(it_stop->elapsed_time - it->elapsed_time)); -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE last_exported_stop[i] = to_export_stop; -#if !ENABLE_GCODE_POSTPROCESS_BACKTRACE - ++exported_lines_count; -#endif // !ENABLE_GCODE_POSTPROCESS_BACKTRACE } } } @@ -3978,12 +3899,8 @@ void GCodeProcessor::post_process() } } } -#if !ENABLE_GCODE_POSTPROCESS_BACKTRACE - return exported_lines_count; -#endif // !ENABLE_GCODE_POSTPROCESS_BACKTRACE }; -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE // add lines XXX to exported gcode auto process_line_T = [this, &export_lines](const std::string& gcode_line, const size_t g1_lines_counter, const ExportLines::Backtrace& backtrace) { const std::string cmd = GCodeReader::GCodeLine::extract_cmd(gcode_line); @@ -4028,37 +3945,15 @@ void GCodeProcessor::post_process() }); } }; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE m_result.lines_ends.clear(); -#if !ENABLE_GCODE_POSTPROCESS_BACKTRACE - // helper function to write to disk - size_t out_file_pos = 0; - auto write_string = [this, &export_line, &out, &out_path, &out_file_pos](const std::string& str) { - fwrite((const void*)export_line.c_str(), 1, export_line.length(), out.f); - if (ferror(out.f)) { - out.close(); - boost::nowide::remove(out_path.c_str()); - throw Slic3r::RuntimeError(std::string("GCode processor post process export failed.\nIs the disk full?\n")); - } - for (size_t i = 0; i < export_line.size(); ++i) - if (export_line[i] == '\n') - m_result.lines_ends.emplace_back(out_file_pos + i + 1); - out_file_pos += export_line.size(); - export_line.clear(); - }; -#endif // !ENABLE_GCODE_POSTPROCESS_BACKTRACE unsigned int line_id = 0; -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE // Backtrace data for Tx gcode lines static const ExportLines::Backtrace backtrace_T = { 120.0f, 10 }; // In case there are multiple sources of backtracing, keeps track of the longest backtrack time needed // to flush the backtrace cache accordingly float max_backtrace_time = 120.0f; -#else - std::vector> offsets; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE { // Read the input stream 64kB at a time, extract lines and process them. @@ -4082,24 +3977,15 @@ void GCodeProcessor::post_process() gcode_line.insert(gcode_line.end(), it, it_end); if (eol) { ++line_id; -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE export_lines.update(line_id, g1_lines_counter); -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE gcode_line += "\n"; // replace placeholder lines -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE bool processed = process_placeholders(gcode_line); if (processed) gcode_line.clear(); -#else - auto [processed, lines_added_count] = process_placeholders(gcode_line); - if (processed && lines_added_count > 0) - offsets.push_back({ line_id, lines_added_count }); -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE if (!processed) processed = process_used_filament(gcode_line); -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE if (!processed && !is_temporary_decoration(gcode_line)) { if (GCodeReader::GCodeLine::cmd_is(gcode_line, "G1")) // add lines M73 where needed @@ -4114,18 +4000,6 @@ void GCodeProcessor::post_process() if (!gcode_line.empty()) export_lines.append_line(gcode_line); export_lines.write(out, 1.1f * max_backtrace_time, m_result, out_path); -#else - if (!processed && !is_temporary_decoration(gcode_line) && GCodeReader::GCodeLine::cmd_is(gcode_line, "G1")) { - // remove temporary lines, add lines M73 where needed - unsigned int extra_lines_count = process_line_G1(g1_lines_counter++); - if (extra_lines_count > 0) - offsets.push_back({ line_id, extra_lines_count }); - } - - export_line += gcode_line; - if (export_line.length() > 65535) - write_string(export_line); -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE gcode_line.clear(); } // Skip EOL. @@ -4140,30 +4014,12 @@ void GCodeProcessor::post_process() } } -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE export_lines.flush(out, m_result, out_path); -#else - if (!export_line.empty()) - write_string(export_line); -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE out.close(); in.close(); -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE export_lines.synchronize_moves(m_result); -#else - // updates moves' gcode ids which have been modified by the insertion of the M73 lines - unsigned int curr_offset_id = 0; - unsigned int total_offset = 0; - for (GCodeProcessorResult::MoveVertex& move : m_result.moves) { - while (curr_offset_id < static_cast(offsets.size()) && offsets[curr_offset_id].first <= move.gcode_id) { - total_offset += offsets[curr_offset_id].second; - ++curr_offset_id; - } - move.gcode_id += total_offset; - } -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE if (rename_file(out_path, m_result.filename)) throw Slic3r::RuntimeError(std::string("Failed to rename the output G-code file from ") + out_path + " to " + m_result.filename + '\n' + diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 1f29488c3..26cb89894 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -127,9 +127,7 @@ namespace Slic3r { float max_print_height; SettingsIds settings_ids; size_t extruders_count; -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE bool backtrace_enabled; -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE std::vector extruder_colors; std::vector filament_diameters; std::vector filament_densities; diff --git a/src/libslic3r/GCodeReader.hpp b/src/libslic3r/GCodeReader.hpp index bf85a5131..58f55fdcf 100644 --- a/src/libslic3r/GCodeReader.hpp +++ b/src/libslic3r/GCodeReader.hpp @@ -71,7 +71,6 @@ public: return strncmp(cmd, cmd_test, len) == 0 && GCodeReader::is_end_of_word(cmd[len]); } -#if ENABLE_GCODE_POSTPROCESS_BACKTRACE static bool cmd_starts_with(const std::string& gcode_line, const char* cmd_test) { return strncmp(GCodeReader::skip_whitespaces(gcode_line.c_str()), cmd_test, strlen(cmd_test)) == 0; } @@ -82,7 +81,6 @@ public: const std::string_view cmd = temp.cmd(); return { cmd.begin(), cmd.end() }; } -#endif // ENABLE_GCODE_POSTPROCESS_BACKTRACE private: std::string m_raw; diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index c33f24311..60d89c9e9 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -58,8 +58,6 @@ // Enable alternative version of file_wildcards() #define ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR (1 && ENABLE_2_6_0_ALPHA1) -// Enable gcode postprocess modified to allow for backward insertion of new lines -#define ENABLE_GCODE_POSTPROCESS_BACKTRACE (1 && ENABLE_2_6_0_ALPHA1) #endif // _prusaslicer_technologies_h_