From 6f1d04f270249e358e2b14a5518afc4deaaa47e9 Mon Sep 17 00:00:00 2001 From: slynn1324 Date: Wed, 23 Aug 2023 17:12:13 +0800 Subject: [PATCH] ENH: support thumbnail in gcode for 3rd printers Thanks @slynn1324 1. Add thumbnail size in printer params page 2. Optimize writing thumbnail data in gcode jira:STUDIO-3942 Github: #2166 Github pull request: #2333 Change-Id: I6897cfddfa6a1b0c95decf67329a486d40ec0cc2 --- src/libslic3r/GCode.cpp | 22 ++++++++++----------- src/libslic3r/Preset.cpp | 4 ++-- src/libslic3r/PresetBundle.cpp | 2 +- src/libslic3r/Print.cpp | 1 + src/libslic3r/PrintConfig.cpp | 9 +++++++++ src/libslic3r/PrintConfig.hpp | 1 + src/slic3r/GUI/BackgroundSlicingProcess.cpp | 4 ++-- src/slic3r/GUI/GUI.cpp | 2 +- src/slic3r/GUI/OptionsGroup.cpp | 4 ++++ src/slic3r/GUI/Tab.cpp | 8 +++++++- src/slic3r/GUI/UnsavedChangesDialog.cpp | 4 +++- 11 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 732644784..beb937d04 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1292,16 +1292,13 @@ namespace DoExport { output((boost::format("; thumbnail begin %dx%d %d\n") % data.width % data.height % encoded.size()).str().c_str()); unsigned int row_count = 0; - 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); + //BBS: optimize performance ,reduce too much memeory operation + size_t current_index = 0; + while(current_index 0) - output((boost::format("; %s\n") % encoded).str().c_str()); - output("; thumbnail end\n"); output("; THUMBNAIL_BLOCK_END\n\n"); @@ -1580,10 +1577,11 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato } //BBS: add plate id into thumbnail render logic - //DoExport::export_thumbnails_to_file(thumbnail_cb, print.get_plate_index(), THUMBNAIL_SIZE, - // [&file](const char* sz) { file.write(sz); }, - // [&print]() { print.throw_if_canceled(); }); - + if(!print.is_BBL_Printer()){ + DoExport::export_thumbnails_to_file(thumbnail_cb, print.get_plate_index(), print.full_print_config().option("thumbnail_size")->values, + [&file](const char* sz) { file.write(sz); }, + [&print]() { print.throw_if_canceled(); }); + } // Write some terse information on the slicing parameters. const PrintObject *first_object = print.objects().front(); diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index e49ac3f35..6bf2e4011 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -852,7 +852,7 @@ static std::vector s_Preset_printer_options { "silent_mode", // BBS "scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time", "machine_pause_gcode", "template_custom_gcode", - "nozzle_type","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types","support_chamber_temp_control","support_air_filtration","printer_structure", + "nozzle_type","auxiliary_fan", "nozzle_volume","upward_compatible_machine", "z_hop_types","support_chamber_temp_control","support_air_filtration","printer_structure","thumbnail_size", "best_object_pos", //OrcaSlicer "host_type", "print_host", "printhost_apikey", @@ -2379,7 +2379,7 @@ inline t_config_option_keys deep_diff(const ConfigBase &config_this, const Confi if (this_opt != nullptr && other_opt != nullptr && *this_opt != *other_opt) { //BBS: add bed_exclude_area - if (opt_key == "printable_area" || opt_key == "bed_exclude_area" || opt_key == "compatible_prints" || opt_key == "compatible_printers") { + if (opt_key == "printable_area" || opt_key == "bed_exclude_area" || opt_key == "compatible_prints" || opt_key == "compatible_printers"|| opt_key == "thumbnail_size") { // Scalar variable, or a vector variable, which is independent from number of extruders, // thus the vector is presented to the user as a single input. diff.emplace_back(opt_key); diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 037504f32..57bff3b26 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -88,7 +88,7 @@ PresetBundle::PresetBundle() for (size_t i = 0; i < 1; ++i) { // The following ugly switch is to avoid printers.preset(0) to return the edited instance, as the 0th default is the current one. Preset &preset = this->printers.default_preset(i); - for (const char *key : {"printer_settings_id", "printer_model", "printer_variant"}) preset.config.optptr(key, true); + for (const char *key : {"printer_settings_id", "printer_model", "printer_variant","thumbnail_size"}) preset.config.optptr(key, true); //if (i == 0) { preset.config.optptr("default_print_profile", true); preset.config.option("default_filament_profile", true); diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 3dfaa0a25..4e2959613 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -76,6 +76,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "printable_area", //BBS: add bed_exclude_area "bed_exclude_area", + "thumbnail_size", "before_layer_change_gcode", "enable_pressure_advance", "pressure_advance", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 0c6b984e3..93cbf13e1 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1725,6 +1725,15 @@ void PrintConfigDef::init_fff_params() def->tooltip = L("Enable this to enable the camera on printer to check the quality of first layer"); def->mode = comDevelop; def->set_default_value(new ConfigOptionBool(false)); + + // BBS + def = this->add("thumbnail_size", coPoints); + def->label = L("Thumbnail size"); + def->tooltip = L("Decides the size of thumbnail stored in gcode files"); + def->mode = comDevelop; + def->gui_type = ConfigOptionDef::GUIType::one_string; + def->set_default_value(new ConfigOptionPoints{ Vec2d(50,50) }); + //BBS // def = this->add("spaghetti_detector", coBool); // def->label = L("Enable spaghetti detector"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index e0ad6744e..2bcdcc863 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -854,6 +854,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloats, filament_minimal_purge_on_wipe_tower)) // BBS ((ConfigOptionBool, scan_first_layer)) + ((ConfigOptionPoints, thumbnail_size)) // ((ConfigOptionBool, spaghetti_detector)) ((ConfigOptionBool, gcode_add_line_number)) ((ConfigOptionBool, bbl_bed_temperature_gcode)) diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index d8e824a85..a7bff81db 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -274,7 +274,7 @@ void BackgroundSlicingProcess::process_sla() //BBS: add plate id for thumbnail generation ThumbnailsList thumbnails = this->render_thumbnails( - ThumbnailsParams{ THUMBNAIL_SIZE, true, true, true, true, 0 }); + ThumbnailsParams{ current_print()->full_print_config().option("thumbnail_size")->values, true, true, true, true, 0 }); Zipper zipper(export_path); m_sla_archive.export_print(zipper, *m_sla_print); // true, false, true, true); // renders also supports and pad @@ -859,7 +859,7 @@ void BackgroundSlicingProcess::prepare_upload() } else { m_upload_job.upload_data.upload_path = m_sla_print->print_statistics().finalize_output_path(m_upload_job.upload_data.upload_path.string()); ThumbnailsList thumbnails = this->render_thumbnails( - ThumbnailsParams{current_print()->full_print_config().option("thumbnails")->values, true, true, true, true}); + ThumbnailsParams{current_print()->full_print_config().option("thumbnail_size")->values, true, true, true, true}); // true, false, true, true); // renders also supports and pad Zipper zipper{source_path.string()}; m_sla_archive.export_print(zipper, *m_sla_print, m_upload_job.upload_data.upload_path.string()); diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 3470442ea..e6c478981 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -199,7 +199,7 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt } break; case coPoints:{ - if (opt_key == "printable_area" || opt_key == "bed_exclude_area") { + if (opt_key == "printable_area" || opt_key == "bed_exclude_area" || opt_key=="thumbnail_size") { config.option(opt_key)->values = boost::any_cast>(value); break; } diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index df5a79656..e5512bff3 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -1036,6 +1036,8 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config if (opt_key == "printable_area") ret = config.option(opt_key)->values; else if (opt_key == "bed_exclude_area") + ret = get_thumbnails_string(config.option(opt_key)->values); + else if (opt_key == "thumbnail_size") ret = get_thumbnails_string(config.option(opt_key)->values); else ret = config.option(opt_key)->get_at(idx); @@ -1147,6 +1149,8 @@ boost::any ConfigOptionsGroup::get_config_value2(const DynamicPrintConfig& confi ret = config.option(opt_key)->values; else if (opt_key == "bed_exclude_area") ret = get_thumbnails_string(config.option(opt_key)->values); + else if (opt_key == "thumbnail_size") + ret = get_thumbnails_string(config.option(opt_key)->values); else ret = config.option(opt_key)->get_at(idx); break; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 2631f6a6c..dab4908a9 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -861,7 +861,7 @@ void TabPrinter::init_options_list() for (const std::string& opt_key : m_config->keys()) { - if (opt_key == "printable_area" || opt_key == "bed_exclude_area") { + if (opt_key == "printable_area" || opt_key == "bed_exclude_area"|| opt_key=="thumbnail_size") { m_options_list.emplace(opt_key, m_opt_status_value); continue; } @@ -3097,6 +3097,11 @@ void TabPrinter::build_fff() optgroup = page->new_optgroup(L("Advanced"), L"param_advanced"); optgroup->append_single_option_line("printer_structure"); optgroup->append_single_option_line("gcode_flavor"); + + option =optgroup->get_option("thumbnail_size"); + option.opt.full_width=true; + optgroup->append_single_option_line(option); + optgroup->append_single_option_line("scan_first_layer"); optgroup->append_single_option_line("use_relative_e_distances"); // optgroup->append_single_option_line("spaghetti_detector"); @@ -3677,6 +3682,7 @@ void TabPrinter::toggle_options() toggle_option("single_extruder_multi_material", have_multiple_extruders); //BBS: gcode_flavore of BBL printer can't be edited and changed toggle_option("gcode_flavor", !is_BBL_printer); + toggle_option("thumbnail_size",!is_BBL_printer); toggle_option("printer_structure", !is_BBL_printer); toggle_option("use_relative_e_distances", !is_BBL_printer); toggle_option("support_chamber_temp_control", 0); diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index d615cdfb8..1980be7ad 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -1359,7 +1359,9 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig& else if (opt_key == "bed_exclude_area") { return get_thumbnails_string(config.option(opt_key)->values); } - + else if (opt_key == "thumbnail_size") { + return get_thumbnails_string(config.option(opt_key)->values); + } Vec2d val = config.opt(opt_key)->get_at(opt_idx); return from_u8((boost::format("[%1%]") % ConfigOptionPoint(val).serialize()).str()); }