diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 629f39ef43..5ed0553a11 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -1077,16 +1077,14 @@ ConfigSubstitutions ConfigBase::load_from_binary_gcode_file(const std::string& f std::vector cs_buffer(65536); EResult res = is_valid_binary_gcode(*file.f, true, cs_buffer.data(), cs_buffer.size()); if (res != EResult::Success) - throw Slic3r::RuntimeError(format("The selected file is not a valid binary gcode.\nError: %1%", - std::string(translate_result(res)))); - - rewind(file.f); + throw Slic3r::RuntimeError(format("The selected file is not a valid binary gcode.\nError: %1%", std::string(translate_result(res)))); FileHeader file_header; res = read_header(*file.f, file_header, nullptr); if (res != EResult::Success) throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(translate_result(res)))); + // searches for config block BlockHeader block_header; res = read_next_block_header(*file.f, file_header, block_header, EBlockType::SlicerMetadata, cs_buffer.data(), cs_buffer.size()); if (res != EResult::Success) @@ -1098,6 +1096,7 @@ ConfigSubstitutions ConfigBase::load_from_binary_gcode_file(const std::string& f if (res != EResult::Success) throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(translate_result(res)))); + // extracts data from block for (const auto& [key, value] : slicer_metadata_block.raw_data) { this->set_deserialize(key, value, substitutions_ctxt); } diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index b12b0508e7..ff49610764 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1214,13 +1214,10 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato binary_data.printer_metadata.raw_data.emplace_back("extruder_colour", extruder_colours_str); // duplicated into config data } } - - // modifies m_silent_time_estimator_enabled - DoExport::init_gcode_processor(print.config(), m_processor, m_silent_time_estimator_enabled); -#else - // modifies m_silent_time_estimator_enabled - DoExport::init_gcode_processor(print.config(), m_processor, m_silent_time_estimator_enabled); #endif // ENABLE_BINARIZED_GCODE + + // modifies m_silent_time_estimator_enabled + DoExport::init_gcode_processor(print.config(), m_processor, m_silent_time_estimator_enabled); if (! print.config().gcode_substitutions.values.empty()) { m_find_replace = make_unique(print.config()); diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 7065f5db14..0e58a318dd 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -71,7 +71,7 @@ const float GCodeProcessor::Wipe_Height = 0.05f; #if ENABLE_BINARIZED_GCODE bgcode::binarize::BinarizerConfig GCodeProcessor::s_binarizer_config{}; -#endif // ENABLE_BINARIZED +#endif // ENABLE_BINARIZED_GCODE #if ENABLE_GCODE_VIEWER_DATA_CHECKING const std::string GCodeProcessor::Mm3_Per_Mm_Tag = "MM3_PER_MM:"; @@ -1129,7 +1129,7 @@ void GCodeProcessor::process_ascii_file(const std::string& filename, std::functi } #if ENABLE_BINARIZED_GCODE -static void update_out_file_pos(const std::string& out_string, std::vector& lines_ends, size_t* out_file_pos) +static void update_lines_ends_and_out_file_pos(const std::string& out_string, std::vector& lines_ends, size_t* out_file_pos) { for (size_t i = 0; i < out_string.size(); ++i) { if (out_string[i] == '\n') @@ -1306,7 +1306,7 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n"); std::vector& lines_ends = m_result.lines_ends.emplace_back(std::vector()); - update_out_file_pos(block.raw_data, lines_ends, nullptr); + update_lines_ends_and_out_file_pos(block.raw_data, lines_ends, nullptr); m_parser.parse_buffer(block.raw_data, [this](GCodeReader& reader, const GCodeReader::GCodeLine& line) { this->process_gcode_line(line, true); @@ -3730,9 +3730,8 @@ void GCodeProcessor::post_process() } } - using namespace bgcode::core; - const EResult res = m_binarizer.initialize(*out.f, s_binarizer_config); - if (res != EResult::Success) + const bgcode::core::EResult res = m_binarizer.initialize(*out.f, s_binarizer_config); + if (res != bgcode::core::EResult::Success) throw Slic3r::RuntimeError(std::string("Unable to initialize the gcode binarizer.\n")); } #endif // ENABLE_BINARIZED_GCODE @@ -3985,13 +3984,12 @@ void GCodeProcessor::post_process() #if ENABLE_BINARIZED_GCODE if (m_binarizer.is_enabled()) { - bgcode::core::EResult res = m_binarizer.append_gcode(out_string); - if (res != bgcode::core::EResult::Success) + if (m_binarizer.append_gcode(out_string) != bgcode::core::EResult::Success) throw Slic3r::RuntimeError(std::string("Error while sending gcode to the binarizer.\n")); } else { write_to_file(out, out_string, result, out_path); - update_out_file_pos(out_string, result.lines_ends.front(), &m_out_file_pos); + update_lines_ends_and_out_file_pos(out_string, result.lines_ends.front(), &m_out_file_pos); } #else write_to_file(out, out_string, result, out_path); @@ -4018,7 +4016,7 @@ void GCodeProcessor::post_process() } else { write_to_file(out, out_string, result, out_path); - update_out_file_pos(out_string, result.lines_ends.front(), &m_out_file_pos); + update_lines_ends_and_out_file_pos(out_string, result.lines_ends.front(), &m_out_file_pos); } #else write_to_file(out, out_string, result, out_path); diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 45db76451b..6a1743285e 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -69,9 +69,9 @@ // Enable export of binarized gcode #define ENABLE_BINARIZED_GCODE (1 && ENABLE_2_6_2_ALPHA1) -#define ENABLE_BINARIZED_GCODE_DEBUG (1 && ENABLE_BINARIZED_GCODE) +#define ENABLE_BINARIZED_GCODE_DEBUG (0 && ENABLE_BINARIZED_GCODE) #ifdef _WIN32 -#define ENABLE_BINARIZED_GCODE_WIN_DEBUG (0 && ENABLE_BINARIZED_GCODE_DEBUG) +#define ENABLE_BINARIZED_GCODE_WIN_DEBUG (1 && ENABLE_BINARIZED_GCODE_DEBUG) #endif // _WIN32 #define ENABLE_BINARIZED_GCODE_DEBUG_WINDOW (1 && ENABLE_BINARIZED_GCODE)