Thumbnails feature revamp. (#5555)

* Thumbnails feature revamp.
Support generating different size/format combinations
* misc fix

Co-authored-by: Lukas Matena <lukasmatena@seznam.cz>
This commit is contained in:
SoftFever 2024-06-03 21:30:38 +08:00 committed by GitHub
parent 50d00a1d54
commit c083541e0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 1145 additions and 854 deletions

View file

@ -66,6 +66,7 @@
#include "MarkdownTip.hpp"
#include "Search.hpp"
#include "BedShapeDialog.hpp"
#include "libslic3r/GCode/Thumbnails.hpp"
#include "BedShapeDialog.hpp"
// #include "BonjourDialog.hpp"
@ -3669,7 +3670,43 @@ void TabPrinter::build_fff()
option = optgroup->get_option("thumbnails");
option.opt.full_width = true;
optgroup->append_single_option_line(option, "thumbnails");
optgroup->append_single_option_line("thumbnails_format", "thumbnails");
// optgroup->append_single_option_line("thumbnails_format", "thumbnails");
optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
wxTheApp->CallAfter([this, opt_key, value]() {
if (opt_key == "thumbnails" && m_config->has("thumbnails_format")) {
// to backward compatibility we need to update "thumbnails_format" from new "thumbnails"
const std::string val = boost::any_cast<std::string>(value);
if (!value.empty()) {
auto [thumbnails_list, errors] = GCodeThumbnails::make_and_check_thumbnail_list(val);
if (errors != enum_bitmask<ThumbnailError>()) {
// TRN: First argument is parameter name, the second one is the value.
std::string error_str = format(_u8L("Invalid value provided for parameter %1%: %2%"), "thumbnails", val);
error_str += GCodeThumbnails::get_error_string(errors);
InfoDialog(parent(), _L("G-code flavor is switched"), from_u8(error_str)).ShowModal();
}
if (!thumbnails_list.empty()) {
GCodeThumbnailsFormat old_format = GCodeThumbnailsFormat(m_config->option("thumbnails_format")->getInt());
GCodeThumbnailsFormat new_format = thumbnails_list.begin()->first;
if (old_format != new_format) {
DynamicPrintConfig new_conf = *m_config;
auto* opt = m_config->option("thumbnails_format")->clone();
opt->setInt(int(new_format));
new_conf.set_key_value("thumbnails_format", opt);
load_config(new_conf);
}
}
}
}
update_dirty();
on_value_change(opt_key, value);
});
};
optgroup->append_single_option_line("use_relative_e_distances");
optgroup->append_single_option_line("use_firmware_retraction");
// optgroup->append_single_option_line("spaghetti_detector");