diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index fb9d8089f..556c14377 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -719,6 +719,11 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessor::Result* re } BOOST_LOG_TRIVIAL(debug) << "Start processing gcode, " << log_memory_info(); + //klipper can hide gcode into a macro, so add guessed init gcode to the processor. + if (this->config().start_gcode_manual) { + std::string gcode = m_writer.preamble(); + m_processor.process_string(gcode, [print]() { print->throw_if_canceled(); }); + } m_processor.process_file(path_tmp, true, [print]() { print->throw_if_canceled(); }); DoExport::update_print_estimated_times_stats(m_processor, print->m_print_statistics); if (result != nullptr) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index fdc1ea236..ffefa9139 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -842,6 +842,15 @@ void GCodeProcessor::reset() m_width_compare.reset(); #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING } +void GCodeProcessor::process_string(const std::string& gcode, std::function cancel_callback) +{ + std::stringstream ss(gcode); + std::string strline; + while ( std::getline(ss, strline)) + m_parser.parse_line(strline, [this](GCodeReader& reader, const GCodeReader::GCodeLine& line) { + process_gcode_line(line); + }); +} void GCodeProcessor::process_file(const std::string& filename, bool apply_postprocess, std::function cancel_callback) { diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 6b13bb812..48dc1e5f2 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -479,6 +479,7 @@ namespace Slic3r { // Process the gcode contained in the file with the given filename // throws CanceledException through print->throw_if_canceled() (sent by the caller as callback). void process_file(const std::string& filename, bool apply_postprocess, std::function cancel_callback = nullptr); + void process_string(const std::string& gcode, std::function cancel_callback = nullptr); float get_time(PrintEstimatedTimeStatistics::ETimeMode mode) const; std::string get_time_dhm(PrintEstimatedTimeStatistics::ETimeMode mode) const;