Fix some bugs

This commit is contained in:
sunsets
2024-01-12 19:29:50 +08:00
parent 6a26320804
commit b7625edc45
3 changed files with 92 additions and 12 deletions

View File

@@ -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<ThumbnailError>()) {
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.
{

View File

@@ -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++;
//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;
} else {
output((boost::format("\n\n;simage:%s\n\n") % compressed).str().c_str());
count++;
break;
}
}
default: {
auto compressed = compress_thumbnail(data, format);
@@ -129,6 +130,67 @@ inline void export_thumbnails_to_file(ThumbnailsGeneratorCallback &thumbnail_cb,
}
}
}
//B3
template<typename WriteToOutput, typename ThrowIfCanceledCallback>
inline void export_qidi_thumbnails_to_file(ThumbnailsGeneratorCallback & thumbnail_cb,
const std::vector<std::pair<GCodeThumbnailsFormat, Vec2d>> &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<typename ThrowIfCanceledCallback>
inline void generate_binary_thumbnails(ThumbnailsGeneratorCallback& thumbnail_cb, std::vector<bgcode::binarize::ThumbnailBlock>& out_thumbnails,

View File

@@ -328,8 +328,8 @@ MsgUpdateConfig::MsgUpdateConfig(const std::vector<Update> &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
}