From b7625edc454afc517dcd09d453233377a6e3da2f Mon Sep 17 00:00:00 2001 From: sunsets <845944018@qq.com> Date: Fri, 12 Jan 2024 19:29:50 +0800 Subject: [PATCH] Fix some bugs --- src/libslic3r/GCode.cpp | 18 +++++++ src/libslic3r/GCode/Thumbnails.hpp | 82 ++++++++++++++++++++++++++---- src/slic3r/GUI/UpdateDialogs.cpp | 4 +- 3 files changed, 92 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index a5c16af..e0f4c91 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -993,6 +993,7 @@ void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, Thumbnail // Write information on the generator. file.write_format("; %s\n\n", Slic3r::header_slic3r_generated().c_str()); + if (! export_to_binary_gcode) { // if exporting gcode in ascii format, generate the thumbnails here auto [thumbnails, errors] = GCodeThumbnails::make_and_check_thumbnail_list(print.full_print_config()); @@ -1409,6 +1410,23 @@ void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, Thumbnail if (print.m_print_statistics.total_toolchanges > 0) file.write_format("; total toolchanges = %i\n", print.m_print_statistics.total_toolchanges); file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Estimated_Printing_Time_Placeholder).c_str()); + + //B3 + if (!export_to_binary_gcode) { + // if exporting gcode in ascii format, generate the thumbnails here + auto [thumbnails, errors] = GCodeThumbnails::make_and_check_thumbnail_list(print.full_print_config()); + if (errors != enum_bitmask()) { + std::string error_str = format("Invalid thumbnails value:"); + error_str += GCodeThumbnails::get_error_string(errors); + throw Slic3r::ExportError(error_str); + } + if (!thumbnails.empty()) + GCodeThumbnails::export_qidi_thumbnails_to_file( + thumbnail_cb, thumbnails, [&file](const char *sz) { file.write(sz); }, [&print]() { print.throw_if_canceled(); }); + } + + file.write("\n"); + // Append full config, delimited by two 'phony' configuration keys qidislicer_config = begin and qidislicer_config = end. // The delimiters are structured as configuration key / value pairs to be parsable by older versions of QIDISlicer G-code viewer. { diff --git a/src/libslic3r/GCode/Thumbnails.hpp b/src/libslic3r/GCode/Thumbnails.hpp index 456cf87..3b1756a 100644 --- a/src/libslic3r/GCode/Thumbnails.hpp +++ b/src/libslic3r/GCode/Thumbnails.hpp @@ -86,17 +86,18 @@ inline void export_thumbnails_to_file(ThumbnailsGeneratorCallback &thumbnail_cb, if (data.is_valid()) { switch (format) { case GCodeThumbnailsFormat::QIDI: { - auto compressed = compress_qidi_thumbnail(data, format); + //auto compressed = compress_qidi_thumbnail(data, format); - if (count == 0) { - output((boost::format("\n\n;gimage:%s\n\n") % compressed).str().c_str()); - count++; - break; - } else { - output((boost::format("\n\n;simage:%s\n\n") % compressed).str().c_str()); - count++; - break; - } + //if (count == 0) { + // output((boost::format("\n\n;gimage:%s\n\n") % compressed).str().c_str()); + // count++; + // break; + //} else { + // output((boost::format("\n\n;simage:%s\n\n") % compressed).str().c_str()); + // count++; + // break; + //} + break; } default: { auto compressed = compress_thumbnail(data, format); @@ -129,6 +130,67 @@ inline void export_thumbnails_to_file(ThumbnailsGeneratorCallback &thumbnail_cb, } } } +//B3 +template +inline void export_qidi_thumbnails_to_file(ThumbnailsGeneratorCallback & thumbnail_cb, + const std::vector> &thumbnails_list, + WriteToOutput output, + ThrowIfCanceledCallback throw_if_canceled) +{ + // Write thumbnails using base64 encoding + if (thumbnail_cb != nullptr) { + //B3 + int count = 0; + for (const auto &[format, size] : thumbnails_list) { + static constexpr const size_t max_row_length = 78; + ThumbnailsList thumbnails = thumbnail_cb(ThumbnailsParams{{size}, true, false, false, true}); + for (const ThumbnailData &data : thumbnails) + if (data.is_valid()) { + switch (format) { + case GCodeThumbnailsFormat::QIDI: { + auto compressed = compress_qidi_thumbnail(data, format); + + if (count == 0) { + output((boost::format("\n\n;gimage:%s\n\n") % compressed).str().c_str()); + count++; + break; + } else { + output((boost::format("\n\n;simage:%s\n\n") % compressed).str().c_str()); + count++; + break; + } + } + default: { + //auto compressed = compress_thumbnail(data, format); + //if (compressed->data && compressed->size) { + // std::string encoded; + // encoded.resize(boost::beast::detail::base64::encoded_size(compressed->size)); + // encoded.resize(boost::beast::detail::base64::encode((void *) encoded.data(), (const void *) compressed->data, + // compressed->size)); + + // output((boost::format("\n;\n; %s begin %dx%d %d\n") % compressed->tag() % data.width % data.height % + // encoded.size()) + // .str() + // .c_str()); + + // while (encoded.size() > max_row_length) { + // output((boost::format("; %s\n") % encoded.substr(0, max_row_length)).str().c_str()); + // encoded = encoded.substr(max_row_length); + // } + + // if (encoded.size() > 0) + // output((boost::format("; %s\n") % encoded).str().c_str()); + + // output((boost::format("; %s end\n;\n") % compressed->tag()).str().c_str()); + //} + } + } + throw_if_canceled(); + } + } + } +} + template inline void generate_binary_thumbnails(ThumbnailsGeneratorCallback& thumbnail_cb, std::vector& out_thumbnails, diff --git a/src/slic3r/GUI/UpdateDialogs.cpp b/src/slic3r/GUI/UpdateDialogs.cpp index 4006246..2203672 100644 --- a/src/slic3r/GUI/UpdateDialogs.cpp +++ b/src/slic3r/GUI/UpdateDialogs.cpp @@ -328,8 +328,8 @@ MsgUpdateConfig::MsgUpdateConfig(const std::vector &updates, bool force_ // auto changelog_url = (boost::format(update.changelog_url) % lang_code).str(); //B51 auto changelog_url = ""; - line->AddSpacer(3*VERT_SPACING); - line->Add(new wxHyperlinkCtrl(this, wxID_ANY, _(L("Open changelog page")), changelog_url)); + //line->AddSpacer(3*VERT_SPACING); + //line->Add(new wxHyperlinkCtrl(this, wxID_ANY, _(L("Open changelog page")), changelog_url)); versions->Add(line); versions->AddSpacer(1); // empty value for the correct alignment inside a GridSizer }