From 8c7160079e73626061eaa6f157c84e9c501461cd Mon Sep 17 00:00:00 2001 From: Lam Wei Lun Date: Thu, 3 Sep 2026 13:17:13 +0800 Subject: [PATCH] Revert clang-format changes then reapplied chagnes for Plater/PresetBundle. Fixed extruder masking incorrectness. Fix warning notifications stacking --- src/libslic3r/Format/bbs_3mf.cpp | 12 +- src/libslic3r/Preset.cpp | 2 + src/libslic3r/PresetBundle.cpp | 3706 ++++---- src/libslic3r/PublishSettings.cpp | 44 +- src/slic3r/GUI/NotificationManager.cpp | 36 +- src/slic3r/GUI/NotificationManager.hpp | 5 +- src/slic3r/GUI/Plater.cpp | 10596 ++++++++++++----------- tests/libslic3r/test_3mf.cpp | 93 + 8 files changed, 7286 insertions(+), 7208 deletions(-) diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index 3a3ee20e6f..4b9c666ce0 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -6997,8 +6997,16 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) // receivers onto a geometry-only fallback whose baked-in popup misreports the // file ("old OrcaSlicer version" / "BambuStudio"), while tag-less files classify // as From_Other and import the geometry silently. - if (!m_minimal_published) + if (m_minimal_published) { + // metadata_item_map is seeded from the input file's metadata_items above, so a + // project opened from a regular Orca/BBS 3MF still carries the Application / + // OrcaSlicer tags it came with. Erase them: skipping the overwrite is not enough, + // and an empty value would still emit a "present-looking" tag to old receivers. + metadata_item_map.erase(BBL_APPLICATION_TAG); + metadata_item_map.erase(ORCASLICER_TAG); + } else { metadata_item_map[BBL_APPLICATION_TAG] = (boost::format("%1%-%2%") % "BambuStudio" % SLIC3R_VERSION).str(); + } } metadata_item_map[BBS_3MF_VERSION] = std::to_string(VERSION_BBS_3MF); @@ -7025,7 +7033,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) << xml_escape(item.second) << "\n"; if (item.first == BBL_APPLICATION_TAG) { // The OrcaSlicer tag is only written for files that carry the Application - // tag, which a minimal published 3MF omits (see the map assignment above): + // tag, which a minimal published 3MF erases (see the map assignment above): // the branch below is unreachable in minimal mode. stream << " <" << METADATA_TAG << " name=\"" << ORCASLICER_TAG << "\">" << xml_escape(SoftFever_VERSION) << "\n"; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 6646d98e71..460276c420 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -3096,6 +3096,8 @@ std::string PresetCollection::add_detached_preset(const std::string &name_base, // effects or project-embedded path. lock(); const auto it = this->find_preset_internal(final_name); + if (m_presets.begin() + m_idx_selected >= it) + ++m_idx_selected; Preset &preset = *m_presets.insert(it, stored); preset.name = final_name; preset.vendor = nullptr; diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 3e88d67ea6..e4bafd0071 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -43,7 +43,7 @@ // Store the print/filament/printer presets into a "presets" subdirectory of the Slic3rPE config dir. // This breaks compatibility with the upstream Slic3r if the --datadir is used to switch between the two versions. -// #define SLIC3R_PROFILE_USE_PRESETS_SUBDIR +//#define SLIC3R_PROFILE_USE_PRESETS_SUBDIR namespace Slic3r { @@ -51,29 +51,45 @@ namespace Slic3r { // below is the reduced subset that crosses over in "published" 3MF mode; keep both in sync. // s_project_options_published additionally carries wipe_tower_rotation_angle, which normal // loads do not import (it is not listed here): published-only plate geometry. -static std::vector s_project_options{"flush_volumes_vector", "flush_volumes_matrix", - // BBS - "filament_colour", "filament_colour_type", "filament_multi_colour", "wipe_tower_x", - "wipe_tower_y", "curr_bed_type", "flush_multiplier", - // Fast-purge mode: project-level purge control, inert at Default. - "flush_multiplier_fast", "prime_volume_mode", "nozzle_volume_type", "filament_map_mode", - "filament_map", - // Per-filament nozzle-volume choice; project-level like filament_map so the per-filament - // slot resolution survives preset switches. - "filament_volume_map", - // Per-filament physical-nozzle choice the grouping engine writes back; project-level so a - // saved project round-trips the assignment alongside filament_map/filament_volume_map. - "filament_nozzle_map", - // Filament Track Switch device state: whether the switch is installed and ready, and - // whether dynamic per-nozzle filament mapping is active. Persisted with the project and - // restored from a saved 3mf; reset to false on load and set true only by live device sync. - "has_filament_switcher", "enable_filament_dynamic_map", - // Mixed-color filament slots. Project-level parallel arrays indexed like filament_colour: - // which slots are virtual mixes, their component filaments, blend ratios and the optional - // Z-gradient description. Kept with the project so a saved 3mf round-trips the mix setup. - "filament_is_mixed", "filament_mixed_components", "filament_mixed_sublayer_ratios", - "filament_mixed_gradient", "filament_mixed_gradient_range", - "filament_mixed_gradient_curve", "filament_mixed_gradient_per_part"}; +static std::vector s_project_options { + "flush_volumes_vector", + "flush_volumes_matrix", + // BBS + "filament_colour", + "filament_colour_type", + "filament_multi_colour", + "wipe_tower_x", + "wipe_tower_y", + "curr_bed_type", + "flush_multiplier", + // Fast-purge mode: project-level purge control, inert at Default. + "flush_multiplier_fast", + "prime_volume_mode", + "nozzle_volume_type", + "filament_map_mode", + "filament_map", + // Per-filament nozzle-volume choice; project-level like filament_map so the per-filament + // slot resolution survives preset switches. + "filament_volume_map", + // Per-filament physical-nozzle choice the grouping engine writes back; project-level so a + // saved project round-trips the assignment alongside filament_map/filament_volume_map. + "filament_nozzle_map", + // Filament Track Switch device state: whether the switch is installed and ready, and + // whether dynamic per-nozzle filament mapping is active. Persisted with the project and + // restored from a saved 3mf; reset to false on load and set true only by live device sync. + "has_filament_switcher", + "enable_filament_dynamic_map", + // Mixed-color filament slots. Project-level parallel arrays indexed like filament_colour: + // which slots are virtual mixes, their component filaments, blend ratios and the optional + // Z-gradient description. Kept with the project so a saved 3mf round-trips the mix setup. + "filament_is_mixed", + "filament_mixed_components", + "filament_mixed_sublayer_ratios", + "filament_mixed_gradient", + "filament_mixed_gradient_range", + "filament_mixed_gradient_curve", + "filament_mixed_gradient_per_part" +}; // Project options applied when loading a "published" 3MF project: s_project_options minus the // filament/purge keys, plus wipe_tower_rotation_angle (plate geometry that only published @@ -90,24 +106,25 @@ static std::vector s_project_options{"flush_volumes_vector", "flush // assertions in tests/libslic3r/test_preset_bundle_loading.cpp guard both directions. static std::vector s_project_options_published{"wipe_tower_x", "wipe_tower_y", "wipe_tower_rotation_angle"}; -// Orca: add custom as default -const char* PresetBundle::ORCA_DEFAULT_BUNDLE = "Custom"; -const char* PresetBundle::ORCA_DEFAULT_PRINTER_MODEL = "MyKlipper 0.4 nozzle"; -const char* PresetBundle::ORCA_DEFAULT_PRINTER_VARIANT = "0.4"; -const char* PresetBundle::ORCA_DEFAULT_FILAMENT = "Generic PLA @System"; -const char* PresetBundle::ORCA_FILAMENT_LIBRARY = "OrcaFilamentLibrary"; -const char* PresetBundle::ORCA_DEFAULT_FILAMENT_PLACEHOLDER = "Default Filament"; +//Orca: add custom as default +const char *PresetBundle::ORCA_DEFAULT_BUNDLE = "Custom"; +const char *PresetBundle::ORCA_DEFAULT_PRINTER_MODEL = "MyKlipper 0.4 nozzle"; +const char *PresetBundle::ORCA_DEFAULT_PRINTER_VARIANT = "0.4"; +const char *PresetBundle::ORCA_DEFAULT_FILAMENT = "Generic PLA @System"; +const char *PresetBundle::ORCA_FILAMENT_LIBRARY = "OrcaFilamentLibrary"; +const char *PresetBundle::ORCA_DEFAULT_FILAMENT_PLACEHOLDER = "Default Filament"; -DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset, - Preset& in_print_preset, - const DynamicPrintConfig& project_config, - std::vector& in_filament_presets, - bool apply_extruder, - std::optional> filament_maps_new, - std::optional> filament_volume_maps_new) +DynamicPrintConfig PresetBundle::construct_full_config( + Preset& in_printer_preset, + Preset& in_print_preset, + const DynamicPrintConfig& project_config, + std::vector& in_filament_presets, + bool apply_extruder, + std::optional> filament_maps_new, + std::optional> filament_volume_maps_new) { - DynamicPrintConfig& printer_config = in_printer_preset.config; - DynamicPrintConfig& print_config = in_print_preset.config; + DynamicPrintConfig &printer_config = in_printer_preset.config; + DynamicPrintConfig &print_config = in_print_preset.config; DynamicPrintConfig out; out.apply(FullPrintConfig::defaults()); @@ -119,7 +136,7 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset size_t num_filaments = in_filament_presets.size(); std::vector filament_maps = out.option("filament_map")->values; - std::vector filament_volume_maps(num_filaments, (int) nvtStandard); + std::vector filament_volume_maps(num_filaments, (int)nvtStandard); ConfigOptionInts* filament_volume_map_opt = out.option("filament_volume_map"); if (filament_maps_new.has_value()) @@ -137,7 +154,7 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset filament_volume_maps.resize(num_filaments, nvtStandard); } - auto* extruder_diameter = dynamic_cast(out.option("nozzle_diameter")); + auto *extruder_diameter = dynamic_cast(out.option("nozzle_diameter")); // Collect the "compatible_printers_condition" and "inherits" values over all presets (print, filaments, printers) into a single vector. std::vector compatible_printers_condition; std::vector compatible_prints_condition; @@ -146,12 +163,11 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset std::vector print_compatible_printers; // BBS: add logic for settings check between different system presets std::vector different_settings; - std::string different_print_settings, different_printer_settings; + std::string different_print_settings, different_printer_settings; compatible_printers_condition.emplace_back(in_print_preset.compatible_printers_condition()); - const ConfigOptionStrings* compatible_printers = print_config.option("compatible_printers", false); - if (compatible_printers) - print_compatible_printers = compatible_printers->values; + const ConfigOptionStrings *compatible_printers = print_config.option("compatible_printers", false); + if (compatible_printers) print_compatible_printers = compatible_printers->values; // BBS: add logic for settings check between different system presets std::string print_inherits = in_print_preset.inherits(); inherits.emplace_back(print_inherits); @@ -161,7 +177,7 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset int extruder_count = 1, extruder_volume_type_count = 1; bool different_extruder = false; if (apply_extruder) { - different_extruder = out.support_different_extruders(extruder_count); + different_extruder = out.support_different_extruders(extruder_count); extruder_volume_type_count = out.get_extruder_nozzle_volume_count(extruder_count, nozzle_volume_types); if ((extruder_count > 1) || different_extruder) { @@ -173,13 +189,10 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset // per variant (e.g. X2D machine_max_speed_e/machine_max_acceleration_e). The slicing // path composes variant_2 first and is unaffected; changing the order here would alter // long-standing composed values, so any fix must re-baseline them. - out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, - printer_options_with_variant_1, "printer_extruder_id", "printer_extruder_variant"); - out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, - printer_options_with_variant_2, "printer_extruder_id", "printer_extruder_variant", 2); + out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, printer_options_with_variant_1, "printer_extruder_id", "printer_extruder_variant"); + out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, printer_options_with_variant_2, "printer_extruder_id", "printer_extruder_variant", 2); // update print config related with variants - out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, - print_options_with_variant, "print_extruder_id", "print_extruder_variant"); + out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, print_options_with_variant, "print_extruder_id", "print_extruder_variant"); } } @@ -187,9 +200,7 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset // BBS: update filament config related with variants DynamicPrintConfig filament_config = in_filament_presets[0].config; if (apply_extruder && ((extruder_count > 1) || different_extruder)) - filament_config.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, - filament_options_with_variant, "", "filament_extruder_variant", 1, - filament_maps[0], (NozzleVolumeType) filament_volume_maps[0]); + filament_config.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, filament_options_with_variant, "", "filament_extruder_variant", 1, filament_maps[0], (NozzleVolumeType)filament_volume_maps[0]); out.apply(filament_config); compatible_printers_condition.emplace_back(in_filament_presets[0].compatible_printers_condition()); compatible_prints_condition.emplace_back(in_filament_presets[0].compatible_prints_condition()); @@ -197,13 +208,13 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset inherits.emplace_back(filament_inherits); filament_ids.emplace_back(in_filament_presets[0].filament_id); - std::vector& filament_self_indice = out.option("filament_self_index", true)->values; - int index_size = out.option("filament_extruder_variant")->size(); + std::vector &filament_self_indice = out.option("filament_self_index", true)->values; + int index_size = out.option("filament_extruder_variant")->size(); filament_self_indice.resize(index_size, 1); } else { - std::vector filament_configs; - std::vector filament_presets; - for (const Preset& preset : in_filament_presets) { + std::vector filament_configs; + std::vector filament_presets; + for (const Preset & preset : in_filament_presets) { filament_presets.emplace_back(&preset); filament_configs.emplace_back(&(preset.config)); } @@ -213,45 +224,37 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset for (size_t i = 0; i < num_filaments; ++i) { filament_temp_configs[i] = *(filament_configs[i]); if (apply_extruder && ((extruder_count > 1) || different_extruder)) - filament_temp_configs[i].update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, - nozzle_volume_types, filament_options_with_variant, "", - "filament_extruder_variant", 1, filament_maps[i], - (NozzleVolumeType) filament_volume_maps[i]); + filament_temp_configs[i].update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, filament_options_with_variant, "", "filament_extruder_variant", 1, filament_maps[i], (NozzleVolumeType)filament_volume_maps[i]); } // loop through options and apply them to the resulting config. std::vector filament_variant_count(num_filaments, 1); - for (const t_config_option_key& key : in_filament_presets[0].config.keys()) { - if (key == "compatible_prints" || key == "compatible_printers") - continue; + for (const t_config_option_key &key : in_filament_presets[0].config.keys()) { + if (key == "compatible_prints" || key == "compatible_printers") continue; // Get a destination option. - ConfigOption* opt_dst = out.option(key, false); + ConfigOption *opt_dst = out.option(key, false); if (opt_dst->is_scalar()) { // Get an option, do not create if it does not exist. - const ConfigOption* opt_src = filament_temp_configs.front().option(key); - if (opt_src != nullptr) - opt_dst->set(opt_src); + const ConfigOption *opt_src = filament_temp_configs.front().option(key); + if (opt_src != nullptr) opt_dst->set(opt_src); } else { // BBS - ConfigOptionVectorBase* opt_vec_dst = static_cast(opt_dst); + ConfigOptionVectorBase *opt_vec_dst = static_cast(opt_dst); { if (apply_extruder) { - std::vector filament_opts(num_filaments, nullptr); + std::vector filament_opts(num_filaments, nullptr); // Setting a vector value from all filament_configs. - for (size_t i = 0; i < filament_opts.size(); ++i) - filament_opts[i] = filament_temp_configs[i].option(key); + for (size_t i = 0; i < filament_opts.size(); ++i) filament_opts[i] = filament_temp_configs[i].option(key); opt_vec_dst->set(filament_opts); } else { for (size_t i = 0; i < num_filaments; ++i) { - const ConfigOptionVectorBase* filament_option = static_cast( - filament_temp_configs[i].option(key)); + const ConfigOptionVectorBase *filament_option = static_cast(filament_temp_configs[i].option(key)); if (i == 0) opt_vec_dst->set(filament_option); else opt_vec_dst->append(filament_option); - if (key == "filament_extruder_variant") - filament_variant_count[i] = filament_option->size(); + if (key == "filament_extruder_variant") filament_variant_count[i] = filament_option->size(); } } } @@ -260,14 +263,12 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset if (!apply_extruder) { // append filament_self_index - std::vector& filament_self_indice = out.option("filament_self_index", true)->values; - int index_size = out.option("filament_extruder_variant")->size(); + std::vector &filament_self_indice = out.option("filament_self_index", true)->values; + int index_size = out.option("filament_extruder_variant")->size(); filament_self_indice.resize(index_size, 1); int k = 0; for (size_t i = 0; i < num_filaments; i++) { - for (size_t j = 0; j < filament_variant_count[i]; j++) { - filament_self_indice[k++] = i + 1; - } + for (size_t j = 0; j < filament_variant_count[i]; j++) { filament_self_indice[k++] = i + 1; } } } } @@ -281,10 +282,10 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset // BBS: add logic for settings check between different system presets out.erase("different_settings_to_system"); - static const char* keys[] = {"support_filament", "support_interface_filament"}; + static const char *keys[] = {"support_filament", "support_interface_filament"}; for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); ++i) { std::string key = std::string(keys[i]); - auto* opt = dynamic_cast(out.option(key, false)); + auto *opt = dynamic_cast(out.option(key, false)); assert(opt != nullptr); opt->value = boost::algorithm::clamp(opt->value, 0, int(num_filaments)); } @@ -300,28 +301,27 @@ DynamicPrintConfig PresetBundle::construct_full_config(Preset& in_printer_preset out.option("filament_map", true)->values = filament_maps; out.option("filament_volume_map", true)->values = filament_volume_maps; - auto add_if_some_non_empty = [&out](std::vector&& values, const std::string& key) { + auto add_if_some_non_empty = [&out](std::vector &&values, const std::string &key) { bool nonempty = false; - for (const std::string& v : values) + for (const std::string &v : values) if (!v.empty()) { nonempty = true; break; } - if (nonempty) - out.set_key_value(key, new ConfigOptionStrings(std::move(values))); + if (nonempty) out.set_key_value(key, new ConfigOptionStrings(std::move(values))); }; add_if_some_non_empty(std::move(compatible_printers_condition), "compatible_machine_expression_group"); add_if_some_non_empty(std::move(compatible_prints_condition), "compatible_process_expression_group"); add_if_some_non_empty(std::move(inherits), "inherits_group"); // BBS: add logic for settings check between different system presets - // add_if_some_non_empty(std::move(different_settings), "different_settings_to_system"); + //add_if_some_non_empty(std::move(different_settings), "different_settings_to_system"); add_if_some_non_empty(std::move(print_compatible_printers), "print_compatible_printers"); out.option("printer_technology", true)->value = ptFFF; return out; } -std::string PresetBundle::find_preset_vendor(const std::string& preset_name, Preset::Type type) +std::string PresetBundle::find_preset_vendor(const std::string &preset_name, Preset::Type type) { // Get the resources preset directory (contains all bundled vendor profiles) fs::path system_dir = fs::path(Slic3r::resources_dir()) / PRESET_PROFILES_DIR; @@ -347,9 +347,10 @@ std::string PresetBundle::find_preset_vendor(const std::string& preset_name, Pre // instead of the raw profile JSONs, by its cache alone. for (const std::string& vendor_name : vendor_names_in(system_dir)) { const fs::path vendor_json = system_dir / (vendor_name + ".json"); - if (!fs::exists(vendor_json)) { + if (! fs::exists(vendor_json)) { if (VendorCacheFile::carries_preset((system_dir / (vendor_name + ".opc")).string(), vendor_name, type, preset_name)) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found preset " << preset_name << " in vendor cache " << vendor_name; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found preset " << preset_name + << " in vendor cache " << vendor_name; return vendor_name; } continue; @@ -385,11 +386,13 @@ std::string PresetBundle::find_preset_vendor(const std::string& preset_name, Pre continue; // Found the preset! Get the vendor name and install the entire bundle - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found preset " << p_name << " in vendor bundle " << vendor_name; - + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found preset " << p_name + << " in vendor bundle " << vendor_name; + return vendor_name; } - } catch (const std::exception& e) { + } + catch (const std::exception &e) { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " Failed to find vendor name for " << preset_name << ": " << e.what(); return ""; } @@ -400,21 +403,11 @@ std::string PresetBundle::find_preset_vendor(const std::string& preset_name, Pre } PresetBundle::PresetBundle() - : prints(Preset::TYPE_PRINT, Preset::print_options(), static_cast(FullPrintConfig::defaults())) - , filaments(Preset::TYPE_FILAMENT, - Preset::filament_options(), - static_cast(FullPrintConfig::defaults()), - ORCA_DEFAULT_FILAMENT_PLACEHOLDER) - , sla_materials(Preset::TYPE_SLA_MATERIAL, - Preset::sla_material_options(), - static_cast(SLAFullPrintConfig::defaults())) - , sla_prints(Preset::TYPE_SLA_PRINT, - Preset::sla_print_options(), - static_cast(SLAFullPrintConfig::defaults())) - , printers(Preset::TYPE_PRINTER, - Preset::printer_options(), - static_cast(FullPrintConfig::defaults()), - "Default Printer") + : prints(Preset::TYPE_PRINT, Preset::print_options(), static_cast(FullPrintConfig::defaults())) + , filaments(Preset::TYPE_FILAMENT, Preset::filament_options(), static_cast(FullPrintConfig::defaults()), ORCA_DEFAULT_FILAMENT_PLACEHOLDER) + , sla_materials(Preset::TYPE_SLA_MATERIAL, Preset::sla_material_options(), static_cast(SLAFullPrintConfig::defaults())) + , sla_prints(Preset::TYPE_SLA_PRINT, Preset::sla_print_options(), static_cast(SLAFullPrintConfig::defaults())) + , printers(Preset::TYPE_PRINTER, Preset::printer_options(), static_cast(FullPrintConfig::defaults()), "Default Printer") , physical_printers(PhysicalPrinter::printer_options()) { // The following keys are handled by the UI, they do not have a counterpart in any StaticPrintConfig derived classes, @@ -436,12 +429,12 @@ PresetBundle::PresetBundle() // Set all the nullable values to nils. { auto& default_config = this->filaments.default_preset().config; - for (const std::string& opt_key : default_config.keys()) { - ConfigOption* opt = default_config.optptr(opt_key, false); + for(const std::string& opt_key : default_config.keys()){ + ConfigOption* opt = default_config.optptr(opt_key, false); bool is_override_key = is_filament_extruder_override_key(opt_key); - if (!is_override_key || !opt->nullable()) + if(!is_override_key || !opt->nullable()) continue; - opt->deserialize("nil", ForwardCompatibilitySubstitutionRule::Disable); + opt->deserialize("nil",ForwardCompatibilitySubstitutionRule::Disable); } } @@ -454,16 +447,15 @@ PresetBundle::PresetBundle() this->sla_prints.default_preset().compatible_printers_condition(); this->sla_prints.default_preset().inherits(); - // this->printers.add_default_preset(Preset::sla_printer_options(), static_cast(SLAFullPrintConfig::defaults()), "- default SLA -"); this->printers.preset(1).printer_technology_ref() = ptSLA; + //this->printers.add_default_preset(Preset::sla_printer_options(), static_cast(SLAFullPrintConfig::defaults()), "- default SLA -"); + //this->printers.preset(1).printer_technology_ref() = ptSLA; 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", "thumbnails"}) - preset.config.optptr(key, true); - // if (i == 0) { - preset.config.optptr("default_print_profile", true); - preset.config.option("default_filament_profile", true); + Preset &preset = this->printers.default_preset(i); + for (const char *key : {"printer_settings_id", "printer_model", "printer_variant", "thumbnails"}) preset.config.optptr(key, true); + //if (i == 0) { + preset.config.optptr("default_print_profile", true); + preset.config.option("default_filament_profile", true); //} else { // preset.config.optptr("default_sla_print_profile", true); // preset.config.optptr("default_sla_material_profile", true); @@ -482,29 +474,32 @@ PresetBundle::PresetBundle() this->project_config.apply_only(FullPrintConfig::defaults(), s_project_options); } -PresetBundle::PresetBundle(const PresetBundle& rhs) { *this = rhs; } - -PresetBundle& PresetBundle::operator=(const PresetBundle& rhs) +PresetBundle::PresetBundle(const PresetBundle &rhs) { - prints = rhs.prints; - sla_prints = rhs.sla_prints; - filaments = rhs.filaments; - sla_materials = rhs.sla_materials; - printers = rhs.printers; - physical_printers = rhs.physical_printers; + *this = rhs; +} - filament_presets = rhs.filament_presets; - project_config = rhs.project_config; - vendors = rhs.vendors; - obsolete_presets = rhs.obsolete_presets; - m_errors = rhs.m_errors; +PresetBundle& PresetBundle::operator=(const PresetBundle &rhs) +{ + prints = rhs.prints; + sla_prints = rhs.sla_prints; + filaments = rhs.filaments; + sla_materials = rhs.sla_materials; + printers = rhs.printers; + physical_printers = rhs.physical_printers; + + filament_presets = rhs.filament_presets; + project_config = rhs.project_config; + vendors = rhs.vendors; + obsolete_presets = rhs.obsolete_presets; + m_errors = rhs.m_errors; // Adjust Preset::vendor pointers to point to the copied vendors map. - prints.update_vendor_ptrs_after_copy(this->vendors); - sla_prints.update_vendor_ptrs_after_copy(this->vendors); - filaments.update_vendor_ptrs_after_copy(this->vendors); + prints .update_vendor_ptrs_after_copy(this->vendors); + sla_prints .update_vendor_ptrs_after_copy(this->vendors); + filaments .update_vendor_ptrs_after_copy(this->vendors); sla_materials.update_vendor_ptrs_after_copy(this->vendors); - printers.update_vendor_ptrs_after_copy(this->vendors); + printers .update_vendor_ptrs_after_copy(this->vendors); return *this; } @@ -513,13 +508,13 @@ void PresetBundle::reset(bool delete_files) { // Clear the existing presets, delete their respective files. this->vendors.clear(); - this->prints.reset(delete_files); - this->sla_prints.reset(delete_files); - this->filaments.reset(delete_files); + this->prints .reset(delete_files); + this->sla_prints .reset(delete_files); + this->filaments .reset(delete_files); this->sla_materials.reset(delete_files); - this->printers.reset(delete_files); + this->printers .reset(delete_files); // BBS: filament_presets is load from project config, not handled here - // this->filament_presets.clear(); + //this->filament_presets.clear(); if (this->filament_presets.empty()) this->filament_presets.emplace_back(this->filaments.get_selected_preset_name()); this->obsolete_presets.prints.clear(); @@ -532,25 +527,26 @@ void PresetBundle::reset(bool delete_files) void PresetBundle::setup_directories() { boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir()); - // BBS: change directoties by design + //BBS: change directoties by design std::initializer_list paths = { data_dir, data_dir / "ota", - data_dir / PRESET_SYSTEM_DIR, + data_dir / PRESET_SYSTEM_DIR, data_dir / PRESET_USER_DIR, // Store the print/filament/printer presets at the same location as the upstream Slic3r. - // data_dir / PRESET_SYSTEM_DIR / PRESET_PRINT_NAME, - // data_dir / PRESET_SYSTEM_DIR / PRESET_FILAMENT_NAME, - // data_dir / PRESET_SYSTEM_DIR / PRESET_PRINTER_NAME + //data_dir / PRESET_SYSTEM_DIR / PRESET_PRINT_NAME, + //data_dir / PRESET_SYSTEM_DIR / PRESET_FILAMENT_NAME, + //data_dir / PRESET_SYSTEM_DIR / PRESET_PRINTER_NAME }; - for (const boost::filesystem::path& path : paths) { - boost::filesystem::path subdir = path; + for (const boost::filesystem::path &path : paths) { + boost::filesystem::path subdir = path; subdir.make_preferred(); - if (!boost::filesystem::is_directory(subdir) && !boost::filesystem::create_directory(subdir)) { + if (! boost::filesystem::is_directory(subdir) && + ! boost::filesystem::create_directory(subdir)) { if (boost::filesystem::is_directory(subdir)) { - BOOST_LOG_TRIVIAL(warning) << boost::format("creating directory %1% failed, maybe created by other instance, go on!") % - subdir.string(); - } else + BOOST_LOG_TRIVIAL(warning) << boost::format("creating directory %1% failed, maybe created by other instance, go on!")%subdir.string(); + } + else throw Slic3r::RuntimeError(std::string("Unable to create directory ") + subdir.string()); } } @@ -559,7 +555,7 @@ void PresetBundle::setup_directories() // recursively copy all files and dirs in from_dir to to_dir static void copy_dir(const boost::filesystem::path& from_dir, const boost::filesystem::path& to_dir) { - if (!boost::filesystem::is_directory(from_dir)) + if(!boost::filesystem::is_directory(from_dir)) return; // i assume to_dir.parent surely exists if (!boost::filesystem::is_directory(to_dir)) @@ -583,33 +579,33 @@ void PresetBundle::copy_files(const std::string& from) // list of searched paths based on current directory system in setup_directories() // do not copy cache and snapshots boost::filesystem::path from_data_dir = boost::filesystem::path(from); - // BBS: change directoties by design - std::initializer_list from_dirs = - {// from_data_dir / "vendor", - // Store the print/filament/printer presets at the same location as the upstream Slic3r. - from_data_dir / PRESET_PRINT_NAME, from_data_dir / PRESET_FILAMENT_NAME, from_data_dir / PRESET_PRINTER_NAME}; + //BBS: change directoties by design + std::initializer_list from_dirs= { + //from_data_dir / "vendor", + // Store the print/filament/printer presets at the same location as the upstream Slic3r. + from_data_dir / PRESET_PRINT_NAME, + from_data_dir / PRESET_FILAMENT_NAME, + from_data_dir / PRESET_PRINTER_NAME + }; // copy recursively all files - // BBS: change directoties by design + //BBS: change directoties by design for (const boost::filesystem::path& from_dir : from_dirs) { - copy_dir(from_dir, data_dir / "old" / from_dir.filename()); + copy_dir(from_dir, data_dir /"old"/from_dir.filename()); } } -PresetsConfigSubstitutions PresetBundle::load_presets(AppConfig& config, - ForwardCompatibilitySubstitutionRule substitution_rule, - const PresetPreferences& preferred_selection /* = PresetPreferences()*/) +PresetsConfigSubstitutions PresetBundle::load_presets(AppConfig &config, ForwardCompatibilitySubstitutionRule substitution_rule, + const PresetPreferences& preferred_selection/* = PresetPreferences()*/) { // First load the vendor specific system presets. PresetsConfigSubstitutions substitutions; std::string errors_cummulative; - // BBS: add config related logs - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(" enter, substitution_rule %1%, preferred printer_model_id %2%") % substitution_rule % - preferred_selection.printer_model_id; + //BBS: add config related logs + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, substitution_rule %1%, preferred printer_model_id %2%")%substitution_rule%preferred_selection.printer_model_id; const auto startup_t0 = std::chrono::steady_clock::now(); - // BBS: change system config to json + //BBS: change system config to json std::tie(substitutions, errors_cummulative) = this->load_system_presets_from_json(substitution_rule); // BBS load preset from user's folder, load system default if @@ -635,26 +631,35 @@ PresetsConfigSubstitutions PresetBundle::load_presets(AppConfig& config, set_calibrate_printer(""); { - const auto total_ms = std::chrono::duration_cast(std::chrono::steady_clock::now() - startup_t0).count(); + const auto total_ms = std::chrono::duration_cast( + std::chrono::steady_clock::now() - startup_t0).count(); BOOST_LOG_TRIVIAL(info) << "PresetBundle: all presets loaded in " << total_ms << " ms"; } - // BBS: add config related logs - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" finished, returned substitutions %1%") % substitutions.size(); + //BBS: add config related logs + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" finished, returned substitutions %1%")%substitutions.size(); return substitutions; } -// BBS: add function to generate differed preset for save -// the pointer should be freed by the caller +//BBS: add function to generate differed preset for save +//the pointer should be freed by the caller Preset* PresetBundle::get_preset_differed_for_save(Preset& preset) { PresetCollection* preset_collection; - switch (preset.type) { - case Preset::TYPE_PRINT: preset_collection = &(this->prints); break; - case Preset::TYPE_PRINTER: preset_collection = &(this->printers); break; - case Preset::TYPE_FILAMENT: preset_collection = &(this->filaments); break; - default: BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" invalid type %1%, return directly") % preset.type; return nullptr; + switch(preset.type) { + case Preset::TYPE_PRINT: + preset_collection = &(this->prints); + break; + case Preset::TYPE_PRINTER: + preset_collection = &(this->printers); + break; + case Preset::TYPE_FILAMENT: + preset_collection = &(this->filaments); + break; + default: + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" invalid type %1%, return directly")%preset.type; + return nullptr; } return preset_collection->get_preset_differed_for_save(preset); @@ -664,17 +669,25 @@ int PresetBundle::get_differed_values_to_update(Preset& preset, std::mapprints); break; - case Preset::TYPE_PRINTER: preset_collection = &(this->printers); break; - case Preset::TYPE_FILAMENT: preset_collection = &(this->filaments); break; - default: BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" invalid type %1%, return directly") % preset.type; return -1; + switch(preset.type) { + case Preset::TYPE_PRINT: + preset_collection = &(this->prints); + break; + case Preset::TYPE_PRINTER: + preset_collection = &(this->printers); + break; + case Preset::TYPE_FILAMENT: + preset_collection = &(this->filaments); + break; + default: + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" invalid type %1%, return directly")%preset.type; + return -1; } return preset_collection->get_differed_values_to_update(preset, key_values); } -// BBS: get vendor's current version +//BBS: get vendor's current version Semver PresetBundle::get_vendor_profile_version(std::string vendor_name) { Semver result_ver; @@ -689,11 +702,12 @@ Semver PresetBundle::get_vendor_profile_version(std::string vendor_name) VendorType PresetBundle::get_current_vendor_type() { - auto t = VendorType::Unknown; - auto config = &printers.get_edited_preset().config; + auto t = VendorType::Unknown; + auto config = &printers.get_edited_preset().config; const auto* printer_model = config->opt("printer_model"); if (printer_model == nullptr) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": printer_model is " << (config->has("printer_model") ? "not a string" : "missing") + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": printer_model is " + << (config->has("printer_model") ? "not a string" : "missing") << ", vendor type is Unknown"; return t; } @@ -709,11 +723,12 @@ VendorType PresetBundle::get_current_vendor_type() if (!vendor_name.empty()) break; } - if (!vendor_name.empty()) { - if (vendor_name.compare("BBL") == 0) + if (!vendor_name.empty()) + { + if(vendor_name.compare("BBL") == 0) t = VendorType::Marlin_BBL; - - if (vendor_name.compare("Qidi") == 0) + + if(vendor_name.compare("Qidi") == 0) t = VendorType::Klipper_Qidi; } return t; @@ -726,8 +741,7 @@ bool PresetBundle::use_bbl_network() return use_bbl_network; } -bool PresetBundle::use_bbl_device_tab() -{ +bool PresetBundle::use_bbl_device_tab() { if (!is_bbl_vendor()) { return false; } @@ -737,7 +751,7 @@ bool PresetBundle::use_bbl_device_tab() } const auto cfg = printers.get_edited_preset().config; - // Use bbl device tab if printhost webui url is not set + // Use bbl device tab if printhost webui url is not set return cfg.opt_string("print_host_webui").empty(); } @@ -764,8 +778,7 @@ bool PresetBundle::backup_user_folder() const } } -std::optional PresetBundle::get_filament_by_filament_id(const std::string& filament_id, - const std::string& printer_name) const +std::optional PresetBundle::get_filament_by_filament_id(const std::string& filament_id, const std::string& printer_name) const { if (filament_id.empty()) return std::nullopt; @@ -775,11 +788,11 @@ std::optional PresetBundle::get_filament_by_filament_id(const for (auto iter = filaments.begin(); iter != filaments.end(); ++iter) { const Preset& filament_preset = *iter; - const auto& config = filament_preset.config; + const auto& config = filament_preset.config; if (filament_preset.filament_id == filament_id) { FilamentBaseInfo info; - info.filament_id = filament_id; - info.is_system = filament_preset.is_system; + info.filament_id = filament_id; + info.is_system = filament_preset.is_system; info.filament_name = filament_preset.alias; if (config.has("filament_is_support")) info.is_support = config.option("filament_is_support")->values[0]; @@ -791,7 +804,7 @@ std::optional PresetBundle::get_filament_by_filament_id(const info.nozzle_temp_range_high = config.option("nozzle_temperature_range_high")->values[0]; if (config.has("nozzle_temperature_range_low")) info.nozzle_temp_range_low = config.option("nozzle_temperature_range_low")->values[0]; - if (config.has("temperature_vitrification")) + if(config.has("temperature_vitrification")) info.temperature_vitrification = config.option("temperature_vitrification")->values[0]; if (!printer_name.empty()) { @@ -800,11 +813,11 @@ std::optional PresetBundle::get_filament_by_filament_id(const if (iter != compatible_printers.end() && config.has("filament_printable")) { info.filament_printable = config.option("filament_printable")->values[0]; if (config.has("filament_extruder_compatibility")) - info.set_filament_extruder_compatibility( - config.option("filament_extruder_compatibility")->values[0]); + info.set_filament_extruder_compatibility(config.option("filament_extruder_compatibility")->values[0]); return info; } - } else { + } + else { return info; } } @@ -812,47 +825,44 @@ std::optional PresetBundle::get_filament_by_filament_id(const return std::nullopt; } -// BBS: load project embedded presets -PresetsConfigSubstitutions PresetBundle::load_project_embedded_presets(std::vector project_presets, - ForwardCompatibilitySubstitutionRule substitution_rule) +//BBS: load project embedded presets +PresetsConfigSubstitutions PresetBundle::load_project_embedded_presets(std::vector project_presets, ForwardCompatibilitySubstitutionRule substitution_rule) { // First load the vendor specific system presets. PresetsConfigSubstitutions substitutions; std::string errors_cummulative; - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(" enter, substitution_rule %1%, preset toltal count %2%") % substitution_rule % - project_presets.size(); + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, substitution_rule %1%, preset toltal count %2%")%substitution_rule% project_presets.size(); try { this->prints.load_project_embedded_presets(project_presets, PRESET_PRINT_NAME, substitutions, substitution_rule); - } catch (const std::runtime_error& err) { + } catch (const std::runtime_error &err) { errors_cummulative += err.what(); } try { this->filaments.load_project_embedded_presets(project_presets, PRESET_FILAMENT_NAME, substitutions, substitution_rule); - } catch (const std::runtime_error& err) { + } catch (const std::runtime_error &err) { errors_cummulative += err.what(); } try { this->printers.load_project_embedded_presets(project_presets, PRESET_PRINTER_NAME, substitutions, substitution_rule); - } catch (const std::runtime_error& err) { + } catch (const std::runtime_error &err) { errors_cummulative += err.what(); } - // this->update_multi_material_filament_presets(); - // this->update_compatible(PresetSelectCompatibleType::Never); - // Rewrite renamed compatible references before the caller (Plater) selects the project presets. + //this->update_multi_material_filament_presets(); + //this->update_compatible(PresetSelectCompatibleType::Never); + // Rewrite renamed compatible references before the caller (Plater) selects the project presets. this->normalize_compatible_presets(); - if (!errors_cummulative.empty()) + if (! errors_cummulative.empty()) throw Slic3r::RuntimeError(errors_cummulative); - // this->load_selections(config, ""); + //this->load_selections(config, ""); - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, returned substitutions %1%") % substitutions.size(); + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, returned substitutions %1%")%substitutions.size(); return substitutions; } -// BBS: get current project embedded presets +//BBS: get current project embedded presets std::vector PresetBundle::get_current_project_embedded_presets() { std::vector project_presets; @@ -866,38 +876,39 @@ std::vector PresetBundle::get_current_project_embedded_presets() if (!printer_presets.empty()) std::copy(printer_presets.begin(), printer_presets.end(), std::back_inserter(project_presets)); - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, returned project_presets count %1%") % project_presets.size(); + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, returned project_presets count %1%")%project_presets.size(); return project_presets; } -// BBS: reset project embedded presets +//BBS: reset project embedded presets void PresetBundle::reset_project_embedded_presets() { std::string prefer_printer; Preset& current_printer = this->printers.get_selected_preset(); - ConfigOption* inherits = current_printer.config.option("inherits"); + ConfigOption* inherits = current_printer.config.option("inherits"); if (inherits) { - prefer_printer = dynamic_cast(inherits)->value; + prefer_printer = dynamic_cast(inherits)->value; } - // first printer, then filament, then print - bool printer_reselect = this->printers.reset_project_embedded_presets(); + //first printer, then filament, then print + bool printer_reselect = this->printers.reset_project_embedded_presets(); bool filament_reselect = this->filaments.reset_project_embedded_presets(); - bool print_reselect = this->prints.reset_project_embedded_presets(); + bool print_reselect = this->prints.reset_project_embedded_presets(); if (printer_reselect) { if (!prefer_printer.empty()) - this->printers.select_preset_by_name(prefer_printer, true); + this->printers.select_preset_by_name(prefer_printer, true); else - this->printers.select_preset(this->printers.first_visible_idx()); + this->printers.select_preset(this->printers.first_visible_idx()); - // this->update_multi_material_filament_presets(); + //this->update_multi_material_filament_presets(); this->update_compatible(PresetSelectCompatibleType::Never); - } else if (filament_reselect || print_reselect) { - // Preset& current_printer = this->printers.get_selected_preset(); + } + else if (filament_reselect || print_reselect) { + //Preset& current_printer = this->printers.get_selected_preset(); /*if (filament_reselect) { - const std::vector &prefered_filament_profiles = - current_printer.config.option("default_filament_profile")->values; const std::string prefered_filament_profile - = prefered_filament_profiles.empty() ? std::string() : prefered_filament_profiles.front(); if (!prefered_filament_profile.empty()) + const std::vector &prefered_filament_profiles = current_printer.config.option("default_filament_profile")->values; + const std::string prefered_filament_profile = prefered_filament_profiles.empty() ? std::string() : prefered_filament_profiles.front(); + if (!prefered_filament_profile.empty()) this->filaments.select_preset_by_name(prefered_filament_profile, true); else this->filaments.select_preset(this->filaments.first_visible_idx()); @@ -908,18 +919,17 @@ void PresetBundle::reset_project_embedded_presets() this->update_compatible(PresetSelectCompatibleType::Never); } - // this->update_multi_material_filament_presets(); + //this->update_multi_material_filament_presets(); - // update filament_presets - for (size_t i = 0; i < filament_presets.size(); ++i) { + //update filament_presets + for (size_t i = 0; i < filament_presets.size(); ++ i) + { Preset* selected_filament = this->filaments.find_preset(filament_presets[i], false); if (!selected_filament) { - // it should be the project embedded presets + //it should be the project embedded presets Preset& current_printer = this->printers.get_selected_preset(); - const std::vector& prefered_filament_profiles = - current_printer.config.option("default_filament_profile")->values; - const std::string prefered_filament_profile = prefered_filament_profiles.empty() ? std::string() : - prefered_filament_profiles.front(); + const std::vector &prefered_filament_profiles = current_printer.config.option("default_filament_profile")->values; + const std::string prefered_filament_profile = prefered_filament_profiles.empty() ? std::string() : prefered_filament_profiles.front(); if (!prefered_filament_profile.empty()) { // Check if preferred filament exists and is visible const Preset* preferred_preset = this->filaments.find_preset(prefered_filament_profile, false); @@ -935,22 +945,26 @@ void PresetBundle::reset_project_embedded_presets() } } -// BBS: get bed texture for printer model +//BBS: get bed texture for printer model std::string PresetBundle::get_texture_for_printer_model(std::string model_name) { std::string texture_name, vendor_name, out; - for (auto vendor_profile : this->vendors) { - for (auto vendor_model : vendor_profile.second.models) { - if (vendor_model.name == model_name || vendor_model.id == model_name) { + for (auto vendor_profile: this->vendors) + { + for (auto vendor_model: vendor_profile.second.models) + { + if (vendor_model.name == model_name || vendor_model.id == model_name) + { texture_name = vendor_model.bed_texture; - vendor_name = vendor_profile.first; + vendor_name = vendor_profile.first; break; } } } - if (!texture_name.empty()) { + if (!texture_name.empty()) + { out = Slic3r::data_dir() + "/vendor/" + vendor_name + "/" + texture_name; if (!boost::filesystem::exists(boost::filesystem::path(out))) out = Slic3r::resources_dir() + "/profiles/" + vendor_name + "/" + texture_name; @@ -959,22 +973,26 @@ std::string PresetBundle::get_texture_for_printer_model(std::string model_name) return out; } -// BBS: get stl model for printer model +//BBS: get stl model for printer model std::string PresetBundle::get_stl_model_for_printer_model(std::string model_name) { std::string stl_name, vendor_name, out; - for (auto vendor_profile : this->vendors) { - for (auto vendor_model : vendor_profile.second.models) { - if (vendor_model.name == model_name) { - stl_name = vendor_model.bed_model; + for (auto vendor_profile: this->vendors) + { + for (auto vendor_model: vendor_profile.second.models) + { + if (vendor_model.name == model_name) + { + stl_name = vendor_model.bed_model; vendor_name = vendor_profile.first; break; } } } - if (!stl_name.empty()) { + if (!stl_name.empty()) + { out = Slic3r::data_dir() + "/vendor/" + vendor_name + "/" + stl_name; if (!boost::filesystem::exists(boost::filesystem::path(out))) out = Slic3r::resources_dir() + "/profiles/" + vendor_name + "/" + stl_name; @@ -987,23 +1005,27 @@ std::string PresetBundle::get_hotend_model_for_printer_model(std::string model_n { std::string hotend_stl, vendor_name, out; - for (auto vendor_profile : this->vendors) { - for (auto vendor_model : vendor_profile.second.models) { - if (vendor_model.name == model_name) { - hotend_stl = vendor_model.hotend_model; + for (auto vendor_profile: this->vendors) + { + for (auto vendor_model: vendor_profile.second.models) + { + if (vendor_model.name == model_name) + { + hotend_stl = vendor_model.hotend_model; vendor_name = vendor_profile.first; break; } } } - if (!hotend_stl.empty()) { + if (!hotend_stl.empty()) + { out = Slic3r::data_dir() + "/vendor/" + vendor_name + "/" + hotend_stl; if (!boost::filesystem::exists(boost::filesystem::path(out))) out = Slic3r::resources_dir() + "/profiles/" + vendor_name + "/" + hotend_stl; } - if (out.empty() || !boost::filesystem::exists(boost::filesystem::path(out))) + if (out.empty() ||!boost::filesystem::exists(boost::filesystem::path(out))) out = Slic3r::resources_dir() + "/profiles/hotend.stl"; return out; @@ -1016,13 +1038,11 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(std::string user, For std::string errors_cummulative; fs::path user_folder(data_dir() + "/" + PRESET_USER_DIR); - if (!fs::exists(user_folder)) - fs::create_directory(user_folder); + if (!fs::exists(user_folder)) fs::create_directory(user_folder); std::string dir_user_presets = data_dir() + "/" + PRESET_USER_DIR + "/" + user; - fs::path folder(user_folder / user); - if (!fs::exists(folder)) - fs::create_directory(folder); + fs::path folder(user_folder / user); + if (!fs::exists(folder)) fs::create_directory(folder); bundles.WriteLock(); bundles.m_bundles.clear(); @@ -1035,36 +1055,30 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(std::string user, For if (fs::exists(local_dir)) { dir_user_presets_local = local_dir; for (auto& entry : fs::directory_iterator(local_dir)) { - if (!fs::is_directory(entry.path())) - continue; + if (!fs::is_directory(entry.path())) continue; std::string bundle_dir = entry.path().string(); fs::path metadata_file = entry.path() / PRESET_BUNDLE_METADATA; - if (!fs::exists(metadata_file)) - continue; + if (!fs::exists(metadata_file)) continue; BundleMetadata metadata; - if (!metadata.load_from_json(metadata_file.string())) - continue; + if (!metadata.load_from_json(metadata_file.string())) continue; metadata.print_presets.clear(); metadata.filament_presets.clear(); metadata.printer_presets.clear(); - this->prints.load_presets( - bundle_dir, PRESET_PRINT_NAME, substitutions, substitution_rule, - [&](Preset& preset) { metadata.print_presets.push_back(preset.name); }, - PresetOrigin(PresetOrigin::Kind::LocalBundle, metadata.id)); - this->filaments.load_presets( - bundle_dir, PRESET_FILAMENT_NAME, substitutions, substitution_rule, - [&](Preset& preset) { metadata.filament_presets.push_back(preset.name); }, - PresetOrigin(PresetOrigin::Kind::LocalBundle, metadata.id)); - this->printers.load_presets( - bundle_dir, PRESET_PRINTER_NAME, substitutions, substitution_rule, - [&](Preset& preset) { metadata.printer_presets.push_back(preset.name); }, - PresetOrigin(PresetOrigin::Kind::LocalBundle, metadata.id)); + this->prints.load_presets(bundle_dir, PRESET_PRINT_NAME, substitutions, substitution_rule, [&](Preset& preset) { + metadata.print_presets.push_back(preset.name); + }, PresetOrigin(PresetOrigin::Kind::LocalBundle, metadata.id)); + this->filaments.load_presets(bundle_dir, PRESET_FILAMENT_NAME, substitutions, substitution_rule, [&](Preset& preset) { + metadata.filament_presets.push_back(preset.name); + }, PresetOrigin(PresetOrigin::Kind::LocalBundle, metadata.id)); + this->printers.load_presets(bundle_dir, PRESET_PRINTER_NAME, substitutions, substitution_rule, [&](Preset& preset) { + metadata.printer_presets.push_back(preset.name); + }, PresetOrigin(PresetOrigin::Kind::LocalBundle, metadata.id)); metadata.bundle_type = BundleType::Local; - metadata.path = metadata_file.string(); + metadata.path = metadata_file.string(); bundles.WriteLock(); bundles.m_bundles[metadata.id] = metadata; @@ -1076,38 +1090,32 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(std::string user, For fs::path subscribed_dir(folder / PRESET_SUBSCRIBED_DIR); if (fs::exists(subscribed_dir)) { for (auto& entry : fs::directory_iterator(subscribed_dir)) { - if (!fs::is_directory(entry.path())) - continue; + if (!fs::is_directory(entry.path())) continue; std::string bundle_dir = entry.path().string(); fs::path metadata_file = entry.path() / PRESET_BUNDLE_METADATA; - if (!fs::exists(metadata_file)) - continue; + if (!fs::exists(metadata_file)) continue; BundleMetadata metadata; - if (!metadata.load_from_json(metadata_file.string())) - continue; + if (!metadata.load_from_json(metadata_file.string())) continue; metadata.print_presets.clear(); metadata.filament_presets.clear(); metadata.printer_presets.clear(); metadata.is_subscribed = true; - this->prints.load_presets( - bundle_dir, PRESET_PRINT_NAME, substitutions, substitution_rule, - [&](Preset& preset) { metadata.print_presets.push_back(preset.name); }, - PresetOrigin(PresetOrigin::Kind::SubscribedBundle, metadata.id)); - this->filaments.load_presets( - bundle_dir, PRESET_FILAMENT_NAME, substitutions, substitution_rule, - [&](Preset& preset) { metadata.filament_presets.push_back(preset.name); }, - PresetOrigin(PresetOrigin::Kind::SubscribedBundle, metadata.id)); - this->printers.load_presets( - bundle_dir, PRESET_PRINTER_NAME, substitutions, substitution_rule, - [&](Preset& preset) { metadata.printer_presets.push_back(preset.name); }, - PresetOrigin(PresetOrigin::Kind::SubscribedBundle, metadata.id)); + this->prints.load_presets(bundle_dir, PRESET_PRINT_NAME, substitutions, substitution_rule, [&](Preset& preset) { + metadata.print_presets.push_back(preset.name); + }, PresetOrigin(PresetOrigin::Kind::SubscribedBundle, metadata.id)); + this->filaments.load_presets(bundle_dir, PRESET_FILAMENT_NAME, substitutions, substitution_rule, [&](Preset& preset) { + metadata.filament_presets.push_back(preset.name); + }, PresetOrigin(PresetOrigin::Kind::SubscribedBundle, metadata.id)); + this->printers.load_presets(bundle_dir, PRESET_PRINTER_NAME, substitutions, substitution_rule, [&](Preset& preset) { + metadata.printer_presets.push_back(preset.name); + }, PresetOrigin(PresetOrigin::Kind::SubscribedBundle, metadata.id)); - metadata.bundle_type = BundleType::Subscribed; - metadata.path = metadata_file.string(); + metadata.bundle_type = BundleType::Subscribed; + metadata.path = metadata_file.string(); metadata.update_available = false; bundles.WriteLock(); @@ -1125,32 +1133,27 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(std::string user, For std::string sel = prints.get_selected_preset().name; this->prints.load_presets(dir_user_presets, PRESET_PRINT_NAME, substitutions, substitution_rule); prints.select_preset_by_name(sel, false); - } catch (const std::runtime_error& err) { - errors_cummulative += err.what(); - } + } catch (const std::runtime_error& err) { errors_cummulative += err.what(); } try { std::string sel = filaments.get_selected_preset().name; this->filaments.load_presets(dir_user_presets, PRESET_FILAMENT_NAME, substitutions, substitution_rule); filaments.select_preset_by_name(sel, false); - } catch (const std::runtime_error& err) { - errors_cummulative += err.what(); - } + } catch (const std::runtime_error& err) { errors_cummulative += err.what(); } try { std::string sel = printers.get_selected_preset().name; this->printers.load_presets(dir_user_presets, PRESET_PRINTER_NAME, substitutions, substitution_rule); printers.select_preset_by_name(sel, false); - } catch (const std::runtime_error& err) { - errors_cummulative += err.what(); - } - if (!errors_cummulative.empty()) - throw Slic3r::RuntimeError(errors_cummulative); + } catch (const std::runtime_error& err) { errors_cummulative += err.what(); } + if (!errors_cummulative.empty()) throw Slic3r::RuntimeError(errors_cummulative); - const auto json_ms = std::chrono::duration_cast(std::chrono::steady_clock::now() - json_t0).count(); + const auto json_ms = std::chrono::duration_cast( + std::chrono::steady_clock::now() - json_t0).count(); BOOST_LOG_TRIVIAL(info) << "PresetBundle: user presets loaded from JSON in " << json_ms << " ms"; } { - const auto ms = std::chrono::duration_cast(std::chrono::steady_clock::now() - user_load_t0).count(); + const auto ms = std::chrono::duration_cast( + std::chrono::steady_clock::now() - user_load_t0).count(); BOOST_LOG_TRIVIAL(info) << "PresetBundle: user + bundle presets loaded in " << ms << " ms"; } @@ -1161,70 +1164,62 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(std::string user, For return PresetsConfigSubstitutions(); } -PresetsConfigSubstitutions PresetBundle::load_user_presets(AppConfig& config, - std::map>& my_presets, - ForwardCompatibilitySubstitutionRule substitution_rule) +PresetsConfigSubstitutions PresetBundle::load_user_presets(AppConfig & config, + std::map> &my_presets, + ForwardCompatibilitySubstitutionRule substitution_rule) { // First load the vendor specific system presets. PresetsConfigSubstitutions substitutions; std::string errors_cummulative; bool process_added = false, filament_added = false, machine_added = false; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(" enter, substitution_rule %1%, preset toltal count %2%") % substitution_rule % - my_presets.size(); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(" print's selected_idx %1%, selected_name %2%") % prints.get_selected_idx() % - prints.get_selected_preset_name(); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(" filament's selected_idx %1%, selected_name %2%") % filaments.get_selected_idx() % - filaments.get_selected_preset_name(); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(" printers's selected_idx %1%, selected_name %2%") % printers.get_selected_idx() % - printers.get_selected_preset_name(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, substitution_rule %1%, preset toltal count %2%")%substitution_rule%my_presets.size(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" print's selected_idx %1%, selected_name %2%") %prints.get_selected_idx() %prints.get_selected_preset_name(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" filament's selected_idx %1%, selected_name %2%") %filaments.get_selected_idx() %filaments.get_selected_preset_name(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" printers's selected_idx %1%, selected_name %2%") %printers.get_selected_idx() %printers.get_selected_preset_name(); // Sync removing remove_users_preset(config, &my_presets); std::map>::iterator it; for (int pass = 0; pass < 2; ++pass) - for (it = my_presets.begin(); it != my_presets.end(); it++) { - std::string name = it->first; - std::map& value_map = it->second; - // Load user root presets at first pass - std::map::iterator inherits_iter = value_map.find(BBL_JSON_KEY_INHERITS); - if ((pass == 1) == (inherits_iter == value_map.end() || inherits_iter->second.empty())) - continue; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " start load from cloud: " << name; - // get the type first - std::map::iterator type_iter = value_map.find(BBL_JSON_KEY_TYPE); - if (type_iter == value_map.end()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(" can not find type for setting %1%") % name; - continue; + for (it = my_presets.begin(); it != my_presets.end(); it++) { + std::string name = it->first; + std::map& value_map = it->second; + // Load user root presets at first pass + std::map::iterator inherits_iter = value_map.find(BBL_JSON_KEY_INHERITS); + if ((pass == 1) == (inherits_iter == value_map.end() || inherits_iter->second.empty())) + continue; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " start load from cloud: " << name; + //get the type first + std::map::iterator type_iter = value_map.find(BBL_JSON_KEY_TYPE); + if (type_iter == value_map.end()) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(" can not find type for setting %1%")%name; + continue; + } + try { + PresetCollection *preset_collection = nullptr; + if (type_iter->second == PRESET_IOT_PRINT_TYPE) { + preset_collection = &(this->prints); + process_added |= preset_collection->load_user_preset(name, value_map, substitutions, substitution_rule, PresetOrigin(PresetOrigin::Kind::User)); } - try { - PresetCollection* preset_collection = nullptr; - if (type_iter->second == PRESET_IOT_PRINT_TYPE) { - preset_collection = &(this->prints); - process_added |= preset_collection->load_user_preset(name, value_map, substitutions, substitution_rule, - PresetOrigin(PresetOrigin::Kind::User)); - } else if (type_iter->second == PRESET_IOT_FILAMENT_TYPE) { - preset_collection = &(this->filaments); - filament_added |= preset_collection->load_user_preset(name, value_map, substitutions, substitution_rule, - PresetOrigin(PresetOrigin::Kind::User)); - } else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) { - preset_collection = &(this->printers); - machine_added |= preset_collection->load_user_preset(name, value_map, substitutions, substitution_rule, - PresetOrigin(PresetOrigin::Kind::User)); - } else { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format("invalid type %1% for setting %2%") % type_iter->second % name; - continue; - } - } catch (const std::runtime_error& err) { - errors_cummulative += err.what(); + else if (type_iter->second == PRESET_IOT_FILAMENT_TYPE) { + preset_collection = &(this->filaments); + filament_added |= preset_collection->load_user_preset(name, value_map, substitutions, substitution_rule, PresetOrigin(PresetOrigin::Kind::User)); + } + else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) { + preset_collection = &(this->printers); + machine_added |= preset_collection->load_user_preset(name, value_map, substitutions, substitution_rule, PresetOrigin(PresetOrigin::Kind::User)); + } + else { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("invalid type %1% for setting %2%") %type_iter->second %name; + continue; } } + catch (const std::runtime_error& err) { + errors_cummulative += err.what(); + } + } /*if (process_added) { this->prints.update_after_user_presets_loaded(); } @@ -1240,38 +1235,37 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(AppConfig& config, this->update_multi_material_filament_presets(); this->update_compatible(PresetSelectCompatibleType::Never); - // this->load_selections(config, PresetPreferences()); + //this->load_selections(config, PresetPreferences()); set_calibrate_printer(""); - if (!errors_cummulative.empty()) + if (! errors_cummulative.empty()) throw Slic3r::RuntimeError(errors_cummulative); - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(" finished, process_added %1%, filament_added %2%, machine_added %3%") % process_added % - filament_added % machine_added; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, process_added %1%, filament_added %2%, machine_added %3%")%process_added %filament_added %machine_added; return substitutions; } -bool PresetBundle::apply_vendor_config(const std::map>>& new_vendors, - const std::map& new_filaments, - AppConfig* app_config, - bool overwrite, - const std::string& preferred_printer_model, - const std::string& preferred_printer_variant, - const std::string& preferred_filament) +bool PresetBundle::apply_vendor_config( + const std::map>>& new_vendors, + const std::map& new_filaments, + AppConfig* app_config, + bool overwrite, + const std::string& preferred_printer_model, + const std::string& preferred_printer_variant, + const std::string& preferred_filament) { namespace fs = boost::filesystem; // Get current configuration from AppConfig - const auto old_vendors = app_config->vendors(); - const auto old_filaments = app_config->has_section(AppConfig::SECTION_FILAMENTS) ? - app_config->get_section(AppConfig::SECTION_FILAMENTS) : - std::map(); + const auto old_vendors = app_config->vendors(); + const auto old_filaments = app_config->has_section(AppConfig::SECTION_FILAMENTS) + ? app_config->get_section(AppConfig::SECTION_FILAMENTS) + : std::map(); // Find vendors that need installation std::vector install_bundles; - for (const auto& it : new_vendors) { + for (const auto &it : new_vendors) { if (it.second.size() > 0) { if (!is_vendor_installed(it.first)) { install_bundles.emplace_back(it.first); @@ -1295,9 +1289,9 @@ bool PresetBundle::apply_vendor_config(const std::mapsecond.empty(); + static const std::string system_suffix = " @System"; + auto it_default = new_vendors.find(PresetBundle::ORCA_DEFAULT_BUNDLE); + bool has_default_bundle_printer = it_default != new_vendors.end() && !it_default->second.empty(); // Check if any non-default vendor has selected printers bool has_vendor_printer = false; @@ -1325,8 +1319,7 @@ bool PresetBundle::apply_vendor_config(const std::mapvendors.end()) { // Vendor is loaded, check if the filament exists for (auto f : vendor_it->second.default_filaments) { - BOOST_LOG_TRIVIAL(info) - << " checking if vendor filament " << f << " matches " << short_name << "(" << name << ")"; + BOOST_LOG_TRIVIAL(info) << " checking if vendor filament " << f << " matches " << short_name << "(" << name << ")"; if (f.find(short_name) != std::string::npos) { BOOST_LOG_TRIVIAL(info) << name << " has filament from vendor: " << vendor; has_vendor_filament = true; @@ -1356,7 +1349,8 @@ bool PresetBundle::apply_vendor_config(const std::mapset_section(AppConfig::SECTION_FILAMENTS, supplemented_filaments); app_config->set_vendors(new_vendors); - } else { + } + else { // Merge filaments std::map merged_filaments = old_filaments; for (const auto& [name, value] : supplemented_filaments) { @@ -1378,7 +1372,7 @@ bool PresetBundle::apply_vendor_config(const std::mapload_presets(*app_config, ForwardCompatibilitySubstitutionRule::Enable, - {preferred_printer_model, preferred_printer_variant, preferred_filament, std::string()}); + {preferred_printer_model, preferred_printer_variant, preferred_filament, std::string()}); // Ensure active filament compatibility // If the active filament is not in the wizard-selected filaments, switch to the first @@ -1404,56 +1398,49 @@ bool PresetBundle::apply_vendor_config(const std::map& files, - std::function override_confirm, - ForwardCompatibilitySubstitutionRule rule, - AppConfig& config) +PresetsConfigSubstitutions PresetBundle::import_presets(std::vector & files, + std::function override_confirm, + ForwardCompatibilitySubstitutionRule rule, + AppConfig& config) { bundles.PauseRead(); // Pause threads from reading BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " entry"; PresetsConfigSubstitutions substitutions; int overwrite = 0; - std::vector result; - std::string user_id = config.get("preset_folder"); + std::vector result; + std::string user_id = config.get("preset_folder"); if (user_id.empty()) user_id = DEFAULT_USER_FOLDER_NAME; this->update_user_presets_directory(user_id); - for (auto& file : files) { + for (auto &file : files) { if (Slic3r::is_json_file(file)) { import_json_presets(substitutions, file, override_confirm, rule, overwrite, result); } // Determine if it is a preset bundle - if (boost::iends_with(file, ".orca_printer") || boost::iends_with(file, ".orca_bundle") || - boost::iends_with(file, ".orca_filament") || boost::iends_with(file, ".zip")) { + if (boost::iends_with(file, ".orca_printer") || boost::iends_with(file, ".orca_bundle") || boost::iends_with(file, ".orca_filament") || boost::iends_with(file, ".zip")) { boost::system::error_code ec; // create user folder fs::path user_folder(data_dir() + "/" + PRESET_USER_DIR); - if (!fs::exists(user_folder)) - fs::create_directory(user_folder, ec); - if (ec) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " create directory failed: " << ec.message(); + if (!fs::exists(user_folder)) fs::create_directory(user_folder, ec); + if (ec) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " create directory failed: " << ec.message(); // create default folder fs::path configs_folder(user_folder / user_id); - if (!fs::exists(configs_folder)) - fs::create_directory(configs_folder, ec); - if (ec) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " create directory failed: " << ec.message(); - // create temp folder - // std::string user_default_temp_dir = data_dir() + "/" + PRESET_USER_DIR + "/" + DEFAULT_USER_FOLDER_NAME + "/" + "temp"; + if (!fs::exists(configs_folder)) fs::create_directory(configs_folder, ec); + if (ec) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " create directory failed: " << ec.message(); + //create temp folder + //std::string user_default_temp_dir = data_dir() + "/" + PRESET_USER_DIR + "/" + DEFAULT_USER_FOLDER_NAME + "/" + "temp"; fs::path temp_folder(configs_folder / "temp"); std::string user_default_temp_dir = temp_folder.make_preferred().string(); - if (fs::exists(temp_folder)) - fs::remove_all(temp_folder); + if (fs::exists(temp_folder)) fs::remove_all(temp_folder); fs::create_directory(temp_folder, ec); - if (ec) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " create directory failed: " << ec.message(); + if (ec) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " create directory failed: " << ec.message(); file = boost::filesystem::path(file).make_preferred().string(); mz_zip_archive zip_archive; mz_zip_zero_struct(&zip_archive); mz_bool status; - FILE* zipFile = boost::nowide::fopen(file.c_str(), "rb"); + FILE *zipFile = boost::nowide::fopen(file.c_str(), "rb"); status = mz_zip_reader_init_cfile(&zip_archive, zipFile, 0, MZ_ZIP_FLAG_CASE_SENSITIVE | MZ_ZIP_FLAG_IGNORE_PATH); if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Failed to initialize reader ZIP archive"; @@ -1467,19 +1454,17 @@ PresetsConfigSubstitutions PresetBundle::import_presets(std::vector bool has_bundle_structure = false; BundleMetadata metadata; fs::path metadata_path = temp_folder / BUNDLE_STRUCTURE_JSON_NAME; - status = mz_zip_reader_extract_file_to_file(&zip_archive, BUNDLE_STRUCTURE_JSON_NAME, - encode_path(metadata_path.string().c_str()).c_str(), MZ_ZIP_FLAG_CASE_SENSITIVE); + status = mz_zip_reader_extract_file_to_file(&zip_archive, BUNDLE_STRUCTURE_JSON_NAME, encode_path(metadata_path.string().c_str()).c_str(), MZ_ZIP_FLAG_CASE_SENSITIVE); if (status) { if (metadata.load_from_json(metadata_path.string())) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found bundle_id: " << metadata.id << " from " - << BUNDLE_STRUCTURE_JSON_NAME; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Found bundle_id: " << metadata.id << " from " << BUNDLE_STRUCTURE_JSON_NAME; has_bundle_structure = true; } } if (has_bundle_structure && metadata.id.empty()) { boost::uuids::uuid uuid = boost::uuids::random_generator()(); - metadata.id = to_string(uuid); + metadata.id = to_string(uuid); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " bundle_id was empty, so generating a UUID: " << metadata.id; } @@ -1491,11 +1476,9 @@ PresetsConfigSubstitutions PresetBundle::import_presets(std::vector if (!fs::exists(bundle_base_dir)) fs::create_directories(bundle_base_dir, ec); if (ec) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " Failed to create bundle directory: " << bundle_base_dir.string() - << " error: " << ec.message(); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " Failed to create bundle directory: " << bundle_base_dir.string() << " error: " << ec.message(); } else { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << " No bundle_structure.json found, importing presets into the user preset directory"; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " No bundle_structure.json found, importing presets into the user preset directory"; } // Extract Files @@ -1510,21 +1493,18 @@ PresetsConfigSubstitutions PresetBundle::import_presets(std::vector if (std::string::npos != index) { file_name = file_name.substr(index + 1); } - if (BUNDLE_STRUCTURE_JSON_NAME == file_name) - continue; + if (BUNDLE_STRUCTURE_JSON_NAME == file_name) continue; // create target file path std::string target_file_path = boost::filesystem::path(temp_folder / file_name).make_preferred().string(); - status = mz_zip_reader_extract_to_file(&zip_archive, i, encode_path(target_file_path.c_str()).c_str(), - MZ_ZIP_FLAG_CASE_SENSITIVE); + status = mz_zip_reader_extract_to_file(&zip_archive, i, encode_path(target_file_path.c_str()).c_str(), MZ_ZIP_FLAG_CASE_SENSITIVE); // target file is opened if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Failed to open target file: " << target_file_path; } else { bool is_success = import_json_presets(substitutions, target_file_path, override_confirm, rule, overwrite, result, has_bundle_structure ? bundle_base_dir.string() : std::string()); - BOOST_LOG_TRIVIAL(info) - << __FUNCTION__ << " import target file: " << target_file_path << " import result" << is_success; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " import target file: " << target_file_path << " import result" << is_success; } } } @@ -1542,8 +1522,9 @@ PresetsConfigSubstitutions PresetBundle::import_presets(std::vector BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Saved bundle metadata to: " << metadata_save_path.string(); metadata.bundle_type = BundleType::Local; - metadata.path = metadata_save_path.string(); + metadata.path = metadata_save_path.string(); // Store the bundle metadata in m_bundles for tracking + bundles.WriteLock(); bundles.m_bundles[metadata.id] = metadata; @@ -1554,10 +1535,8 @@ PresetsConfigSubstitutions PresetBundle::import_presets(std::vector } fclose(zipFile); - if (fs::exists(temp_folder)) - fs::remove_all(temp_folder, ec); - if (ec) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " remove directory failed: " << ec.message(); + if (fs::exists(temp_folder)) fs::remove_all(temp_folder, ec); + if (ec) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " remove directory failed: " << ec.message(); } } bundles.UnpauseRead(); @@ -1565,37 +1544,38 @@ PresetsConfigSubstitutions PresetBundle::import_presets(std::vector return substitutions; } -bool PresetBundle::import_json_presets(PresetsConfigSubstitutions& substitutions, - std::string& file, - std::function override_confirm, - ForwardCompatibilitySubstitutionRule rule, - int& overwrite, - std::vector& result, - const std::string& bundle_dir) +bool PresetBundle::import_json_presets(PresetsConfigSubstitutions & substitutions, + std::string & file, + std::function override_confirm, + ForwardCompatibilitySubstitutionRule rule, + int & overwrite, + std::vector & result, + const std::string & bundle_dir) { try { DynamicPrintConfig config; // BBS: change to json format // ConfigSubstitutions config_substitutions = config.load_from_ini(preset.file, substitution_rule); std::map key_values; - std::string reason; - ConfigSubstitutions config_substitutions = config.load_from_json(file, rule, key_values, reason); - std::string name = key_values[BBL_JSON_KEY_NAME]; - std::string version_str = key_values[BBL_JSON_KEY_VERSION]; - boost::optional version = Semver::parse(version_str); - if (!version) - return false; + std::string reason; + ConfigSubstitutions config_substitutions = config.load_from_json(file, rule, key_values, reason); + std::string name = key_values[BBL_JSON_KEY_NAME]; + std::string version_str = key_values[BBL_JSON_KEY_VERSION]; + boost::optional version = Semver::parse(version_str); + if (!version) return false; - std::string type_subdir; // also note the type subdir for bundles - PresetCollection* collection = nullptr; + std::string type_subdir; // also note the type subdir for bundles + PresetCollection *collection = nullptr; if (config.has("printer_settings_id")) { - collection = &printers; + collection = &printers; type_subdir = PRESET_PRINTER_NAME; - } else if (config.has("print_settings_id")) { - collection = &prints; + } + else if (config.has("print_settings_id")) { + collection = &prints; type_subdir = PRESET_PRINT_NAME; - } else if (config.has("filament_settings_id")) { - collection = &filaments; + } + else if (config.has("filament_settings_id")) { + collection = &filaments; type_subdir = PRESET_FILAMENT_NAME; } if (collection == nullptr) { @@ -1603,17 +1583,15 @@ bool PresetBundle::import_json_presets(PresetsConfigSubstitutions& substitutions return false; } const PresetOrigin load_origin = detect_origin_from_path(boost::filesystem::path(bundle_dir)); - const std::string preset_name = get_preset_canonical_name(name, load_origin); + const std::string preset_name = get_preset_canonical_name(name, load_origin); - if (overwrite == 0) - overwrite = 1; + if (overwrite == 0) overwrite = 1; if (auto p = collection->find_preset(preset_name, false)) { if (p->is_default || p->is_system) { BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << " Preset already present and is system preset, not loading: " << preset_name; return false; } - if (overwrite != 2 && overwrite != 3) - overwrite = override_confirm(preset_name); // 3: yes to all 2: no to all + if (overwrite != 2 && overwrite != 3) overwrite = override_confirm(preset_name); //3: yes to all 2: no to all } if (overwrite == 0 || overwrite == 2) { BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << " Preset already present, not loading: " << preset_name; @@ -1621,61 +1599,55 @@ bool PresetBundle::import_json_presets(PresetsConfigSubstitutions& substitutions } DynamicPrintConfig new_config; - Preset* inherit_preset = nullptr; - ConfigOption* inherits_config = config.option(BBL_JSON_KEY_INHERITS); - std::string inherits_value; + Preset * inherit_preset = nullptr; + ConfigOption * inherits_config = config.option(BBL_JSON_KEY_INHERITS); + std::string inherits_value; if (inherits_config) { - ConfigOptionString* option_str = dynamic_cast(inherits_config); + ConfigOptionString *option_str = dynamic_cast(inherits_config); inherits_value = option_str->value; inherit_preset = collection->find_preset2(inherits_value, true); Preset::normalize_inherits(config, inherit_preset); if (inherit_preset) - inherits_value = inherit_preset->name; // keep the base_id redo below in sync + inherits_value = inherit_preset->name; // keep the base_id redo below in sync } if (inherit_preset) { new_config = inherit_preset->config; new_config.apply(std::move(config)); } else { // We support custom root preset now - auto inherits_config2 = dynamic_cast(inherits_config); + auto inherits_config2 = dynamic_cast(inherits_config); if (inherits_config2 && !inherits_config2->value.empty()) { // we should skip this preset here - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format(", can not find inherit preset for user preset %1%, just skip") % name; + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", can not find inherit preset for user preset %1%, just skip") % name; return false; } - // Find a default preset for the config. The PrintPresetCollection provides different default preset based on the - // "printer_technology" field. - const Preset& default_preset = collection->default_preset_for(config); + // Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field. + const Preset &default_preset = collection->default_preset_for(config); new_config = default_preset.config; new_config.apply(std::move(config)); extend_default_config_length(new_config, true, default_preset.config); } - Preset& preset = collection->load_preset(collection->path_from_name(name, inherit_preset == nullptr), preset_name, - std::move(new_config), false); + Preset &preset = collection->load_preset(collection->path_from_name(name, inherit_preset == nullptr), preset_name, std::move(new_config), false); preset.bundle_id = load_origin.bundle_id; if (key_values.find(BBL_JSON_KEY_FILAMENT_ID) != key_values.end()) preset.filament_id = key_values[BBL_JSON_KEY_FILAMENT_ID]; preset.is_external = true; preset.version = *version; inherit_preset = collection->find_preset(inherits_value, false, true); // pointer maybe wrong after insert, redo find - if (inherit_preset) - preset.base_id = inherit_preset->setting_id; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << preset.name << " have filament_id: " << preset.filament_id - << " and base_id: " << preset.base_id; + if (inherit_preset) preset.base_id = inherit_preset->setting_id; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << preset.name << " have filament_id: " << preset.filament_id << " and base_id: " << preset.base_id; Preset::normalize(preset.config); // Report configuration fields, which are misplaced into a wrong group. - const Preset& default_preset = collection->default_preset_for(new_config); - std::string incorrect_keys = Preset::remove_invalid_keys(preset.config, default_preset.config); + const Preset &default_preset = collection->default_preset_for(new_config); + std::string incorrect_keys = Preset::remove_invalid_keys(preset.config, default_preset.config); if (!incorrect_keys.empty()) { ++m_errors; BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" << preset.file << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed"; } if (!config_substitutions.empty()) - substitutions.push_back( - {name, collection->type(), PresetConfigSubstitutions::Source::UserFile, file, std::move(config_substitutions)}); + substitutions.push_back({name, collection->type(), PresetConfigSubstitutions::Source::UserFile, file, std::move(config_substitutions)}); collection->set_custom_preset_alias(preset); // If bundle_dir is provided, use it for the save operation @@ -1689,26 +1661,26 @@ bool PresetBundle::import_json_presets(PresetsConfigSubstitutions& substitutions } result.push_back(file); - } catch (const std::ifstream::failure& err) { + } catch (const std::ifstream::failure &err) { ++m_errors; BOOST_LOG_TRIVIAL(error) << boost::format("The config cannot be loaded: %1%. Reason: %2%") % file % err.what(); - } catch (const std::runtime_error& err) { + } catch (const std::runtime_error &err) { ++m_errors; BOOST_LOG_TRIVIAL(error) << boost::format("Failed importing config file: %1%. Reason: %2%") % file % err.what(); } return true; } -// BBS save user preset to user_id preset folder +//BBS save user preset to user_id preset folder void PresetBundle::save_user_presets(AppConfig& config, std::map& need_to_delete_list) { std::string user_sub_folder = DEFAULT_USER_FOLDER_NAME; if (!config.get("preset_folder").empty()) user_sub_folder = config.get("preset_folder"); - // BBS: change directory by design - const std::string dir_user_presets = data_dir() + "/" + PRESET_USER_DIR + "/" + user_sub_folder; + //BBS: change directory by design + const std::string dir_user_presets = data_dir() + "/" + PRESET_USER_DIR + "/"+ user_sub_folder; - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, save to %1%") % dir_user_presets; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, save to %1%")%dir_user_presets; fs::path user_folder(data_dir() + "/" + PRESET_USER_DIR); if (!fs::exists(user_folder)) @@ -1740,7 +1712,7 @@ void PresetBundle::check_and_fix_user_presets_syncinfo(const std::string& user_i process_collection(this->printers); } -// Orca: Import subscribed bundle presets (load and save to disk in one operation) +//Orca: Import subscribed bundle presets (load and save to disk in one operation) PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( AppConfig& config, const std::map>& bundle_presets, @@ -1751,8 +1723,7 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( std::string errors_cumulative; bool process_added = false, filament_added = false, machine_added = false; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " enter, substitution_rule " << substitution_rule << ", bundle_id: " << remote_metadata.id - << ", preset count: " << bundle_presets.size(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " enter, substitution_rule " << substitution_rule << ", bundle_id: " << remote_metadata.id << ", preset count: " << bundle_presets.size(); BundleMetadata merged_metadata; auto existing_it = bundles.m_bundles.find(remote_metadata.id); @@ -1762,16 +1733,16 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( merged_metadata.imported_time = std::time(nullptr); } - merged_metadata.id = remote_metadata.id; - merged_metadata.name = remote_metadata.name; - merged_metadata.version = remote_metadata.version; - merged_metadata.description = remote_metadata.description; - merged_metadata.author = remote_metadata.author; - merged_metadata.updated_time = remote_metadata.updated_time; - merged_metadata.bundle_type = BundleType::Subscribed; - merged_metadata.is_subscribed = true; + merged_metadata.id = remote_metadata.id; + merged_metadata.name = remote_metadata.name; + merged_metadata.version = remote_metadata.version; + merged_metadata.description = remote_metadata.description; + merged_metadata.author = remote_metadata.author; + merged_metadata.updated_time = remote_metadata.updated_time; + merged_metadata.bundle_type = BundleType::Subscribed; + merged_metadata.is_subscribed = true; merged_metadata.update_available = false; - merged_metadata.unauthorized = false; + merged_metadata.unauthorized = false; const PresetOrigin subscribed_origin(PresetOrigin::Kind::SubscribedBundle, remote_metadata.id); @@ -1795,8 +1766,8 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( remote_printers.insert(subscribed_name); } - auto remove_obsolete_bundle_presets = [&](PresetCollection& collection, const std::unordered_set& remote_names, - const char* type_name) -> int { + auto remove_obsolete_bundle_presets = + [&](PresetCollection& collection, const std::unordered_set& remote_names, const char* type_name) -> int { int removed_count = 0; std::vector to_delete; @@ -1810,12 +1781,10 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( for (const std::string& preset_name : to_delete) { if (collection.delete_preset(preset_name, true)) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": " << type_name << " preset '" << preset_name - << "' no longer in remote bundle, deleted"; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": " << type_name << " preset '" << preset_name << "' no longer in remote bundle, deleted"; ++removed_count; } else { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": failed to delete obsolete " << type_name << " preset '" << preset_name - << "'"; + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": failed to delete obsolete " << type_name << " preset '" << preset_name << "'"; } } @@ -1833,8 +1802,7 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( // Get current user ID for path construction std::string user_id = config.get("preset_folder"); - if (user_id.empty()) - user_id = DEFAULT_USER_FOLDER_NAME; + if (user_id.empty()) user_id = DEFAULT_USER_FOLDER_NAME; // Create the subscribed directory base path boost::filesystem::path user_folder(Slic3r::data_dir() + "/" + PRESET_USER_DIR); @@ -1845,8 +1813,7 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( if (!boost::filesystem::exists(subscribed_base)) boost::filesystem::create_directories(subscribed_base, ec); if (ec) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to create subscribed directory: " << subscribed_base.string() - << " error: " << ec.message(); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to create subscribed directory: " << subscribed_base.string() << " error: " << ec.message(); return substitutions; } @@ -1857,8 +1824,7 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( if (!boost::filesystem::exists(bundle_dir)) boost::filesystem::create_directories(bundle_dir, ec); if (ec) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to create bundle directory: " << bundle_dir.string() - << " error: " << ec.message(); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to create bundle directory: " << bundle_dir.string() << " error: " << ec.message(); return substitutions; } @@ -1868,8 +1834,8 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( // Load each preset from the bundle and save to disk for (const auto& preset_entry : bundle_presets) { - const std::string& preset_name = preset_entry.first; - const std::string subscribed_name = get_preset_canonical_name(preset_name, subscribed_origin); + const std::string& preset_name = preset_entry.first; + const std::string subscribed_name = get_preset_canonical_name(preset_name, subscribed_origin); std::map value_map = preset_entry.second; // Make a copy since we might modify it BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " importing preset: " << preset_name << " from bundle: " << remote_metadata.id; @@ -1884,8 +1850,7 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( // If this preset inherits from another preset inside the same bundle, rewrite the // reference to the canonical (bundle-prefixed) name so the lookup matches the stored identity. auto inherits_iter = value_map.find(BBL_JSON_KEY_INHERITS); - if (inherits_iter != value_map.end() && !inherits_iter->second.empty() && - bundle_presets.find(inherits_iter->second) != bundle_presets.end()) + if (inherits_iter != value_map.end() && !inherits_iter->second.empty() && bundle_presets.find(inherits_iter->second) != bundle_presets.end()) inherits_iter->second = get_preset_canonical_name(inherits_iter->second, subscribed_origin); try { @@ -1895,23 +1860,23 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( if (type_iter->second == PRESET_IOT_PRINT_TYPE) { preset_collection = &(this->prints); - type_subdir = PRESET_PRINT_NAME; - preset_added = preset_collection->load_user_preset(preset_name, value_map, substitutions, substitution_rule, - subscribed_origin); + type_subdir = PRESET_PRINT_NAME; + preset_added = preset_collection->load_user_preset(preset_name, value_map, substitutions, substitution_rule, subscribed_origin); process_added |= preset_added; - } else if (type_iter->second == PRESET_IOT_FILAMENT_TYPE) { + } + else if (type_iter->second == PRESET_IOT_FILAMENT_TYPE) { preset_collection = &(this->filaments); - type_subdir = PRESET_FILAMENT_NAME; - preset_added = preset_collection->load_user_preset(preset_name, value_map, substitutions, substitution_rule, - subscribed_origin); + type_subdir = PRESET_FILAMENT_NAME; + preset_added = preset_collection->load_user_preset(preset_name, value_map, substitutions, substitution_rule, subscribed_origin); filament_added |= preset_added; - } else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) { + } + else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) { preset_collection = &(this->printers); - type_subdir = PRESET_PRINTER_NAME; - preset_added = preset_collection->load_user_preset(preset_name, value_map, substitutions, substitution_rule, - subscribed_origin); + type_subdir = PRESET_PRINTER_NAME; + preset_added = preset_collection->load_user_preset(preset_name, value_map, substitutions, substitution_rule, subscribed_origin); machine_added |= preset_added; - } else { + } + else { BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << " invalid type " << type_iter->second << " for preset " << preset_name; continue; } @@ -1933,19 +1898,20 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) merged_metadata.printer_presets.push_back(preset->name); } - } catch (const std::runtime_error& err) { + } + catch (const std::runtime_error& err) { errors_cumulative += err.what(); BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " error importing preset " << preset_name << ": " << err.what(); } } boost::filesystem::path metadata_save_path = bundle_dir / PRESET_BUNDLE_METADATA; - merged_metadata.path = metadata_save_path.string(); - bundles.m_bundles[remote_metadata.id] = merged_metadata; + merged_metadata.path = metadata_save_path.string(); + bundles.m_bundles[remote_metadata.id] = merged_metadata; if (bundles.m_bundles[remote_metadata.id].save_to_json(metadata_save_path.string())) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " saved bundle metadata to: " << metadata_save_path.string(); - } else { + } else { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to save bundle metadata to: " << metadata_save_path.string(); } @@ -1960,18 +1926,15 @@ PresetsConfigSubstitutions PresetBundle::update_subscribed_presets( if (!errors_cumulative.empty()) throw Slic3r::RuntimeError(errors_cumulative); - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << " finished, process_added " << process_added << ", filament_added " << filament_added - << ", machine_added " << machine_added; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << " finished, process_added " << process_added << ", filament_added " << filament_added << ", machine_added " << machine_added; return substitutions; } // Helper function: save preset to bundle directory with common logic // This function extracts the common code used by both import_json_presets and import_subscribed_presets -bool PresetBundle::save_preset_to_bundle_dir(Preset& preset, - PresetCollection* collection, - const std::string& bundle_id, - const std::string& type_subdir, - const std::string& bundle_base_dir) +bool PresetBundle::save_preset_to_bundle_dir(Preset& preset, PresetCollection* collection, + const std::string& bundle_id, const std::string& type_subdir, + const std::string& bundle_base_dir) { if (bundle_base_dir.empty()) { BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << " bundle_base_dir is empty, cannot save preset " << preset.name; @@ -1988,8 +1951,7 @@ bool PresetBundle::save_preset_to_bundle_dir(Preset& preset, if (!boost::filesystem::exists(bundle_dir)) boost::filesystem::create_directories(bundle_dir, ec); if (ec) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to create bundle directory: " << bundle_dir.string() - << " error: " << ec.message(); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to create bundle directory: " << bundle_dir.string() << " error: " << ec.message(); return false; } @@ -1998,8 +1960,7 @@ bool PresetBundle::save_preset_to_bundle_dir(Preset& preset, if (!boost::filesystem::exists(type_dir)) { boost::filesystem::create_directories(type_dir, ec); if (ec) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to create type directory: " << type_dir.string() - << " error: " << ec.message(); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to create type directory: " << type_dir.string() << " error: " << ec.message(); return false; } } @@ -2009,8 +1970,8 @@ bool PresetBundle::save_preset_to_bundle_dir(Preset& preset, // Bundle preset names may include the subscribed/local prefix path. // Persist the file under the type directory using only the base preset name. const std::string preset_filename = boost::filesystem::path(preset.name).filename().string(); - const std::string file_name = boost::iends_with(preset_filename, ".json") ? preset_filename : (preset_filename + ".json"); - preset.file = (type_dir / file_name).make_preferred().string(); + const std::string file_name = boost::iends_with(preset_filename, ".json") ? preset_filename : (preset_filename + ".json"); + preset.file = (type_dir / file_name).make_preferred().string(); // Save with parent config if inherits from another preset std::string inherits = Preset::inherits(preset.config); @@ -2026,8 +1987,10 @@ bool PresetBundle::save_preset_to_bundle_dir(Preset& preset, Preset::normalize_inherits(preset.config, parent_preset); if (preset.base_id.empty()) preset.base_id = parent_preset->setting_id; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " saved preset " << preset.name << " filament_id: " << preset.filament_id - << " base_id: " << preset.base_id << " bundle: " << bundle_id; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " saved preset " << preset.name + << " filament_id: " << preset.filament_id + << " base_id: " << preset.base_id + << " bundle: " << bundle_id; preset.save(&(parent_preset->config)); } } @@ -2043,13 +2006,13 @@ bool PresetBundle::save_preset_to_bundle_dir(Preset& preset, } } -// BBS: save user preset to user_id preset folder +//BBS: save user preset to user_id preset folder void PresetBundle::update_user_presets_directory(const std::string preset_folder) { - // BBS: change directory by design - const std::string dir_user_presets = data_dir() + "/" + PRESET_USER_DIR + "/" + preset_folder; + //BBS: change directory by design + const std::string dir_user_presets = data_dir() + "/" + PRESET_USER_DIR + "/"+ preset_folder; - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, update directory to %1%") % dir_user_presets; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, update directory to %1%")%dir_user_presets; fs::path user_folder(data_dir() + "/" + PRESET_USER_DIR); if (!fs::exists(user_folder)) @@ -2070,8 +2033,7 @@ void PresetBundle::remove_user_presets_directory(const std::string preset_folder const std::string dir_user_presets = data_dir() + "/" + PRESET_USER_DIR + "/" + preset_folder; if (preset_folder.empty()) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(": preset_folder is empty, no need to remove directory : %1%") % dir_user_presets; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": preset_folder is empty, no need to remove directory : %1%") % dir_user_presets; return; } BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, delete directory : %1%") % dir_user_presets; @@ -2083,69 +2045,72 @@ void PresetBundle::remove_user_presets_directory(const std::string preset_folder void PresetBundle::update_system_preset_setting_ids(std::map>& system_presets) { - for (auto iterator : system_presets) { - std::string name = iterator.first; + for (auto iterator: system_presets) + { + std::string name = iterator.first; std::map& value_map = iterator.second; - // get the type first + //get the type first std::map::iterator type_iter = value_map.find(BBL_JSON_KEY_TYPE); if (type_iter == value_map.end()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(" can not find type for setting %1%") % name; + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(" can not find type for setting %1%")%name; continue; } - PresetCollection* preset_collection = nullptr; + PresetCollection *preset_collection = nullptr; if (type_iter->second == PRESET_IOT_PRINTER_TYPE) { preset_collection = &(this->printers); - } else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) { + } + else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) { preset_collection = &(this->printers); - } else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) { + } + else if (type_iter->second == PRESET_IOT_PRINTER_TYPE) { preset_collection = &(this->printers); - } else { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("invalid type %1% for setting %2%") % type_iter->second % name; + } + else { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("invalid type %1% for setting %2%") %type_iter->second %name; continue; } std::string setting_id; if (value_map.count(BBL_JSON_KEY_SETTING_ID) > 0) setting_id = value_map[BBL_JSON_KEY_SETTING_ID]; else { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(" can not find setting_id for setting %1%") % name; + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(" can not find setting_id for setting %1%")%name; continue; } Preset* preset = preset_collection->find_preset(name, false, true); if (preset) { if (!preset->setting_id.empty() && (preset->setting_id.compare(setting_id) != 0)) { ++m_errors; - BOOST_LOG_TRIVIAL(error) << boost::format("name %1%, local setting_id %2% is different with remote id %3%") % preset->name % - preset->setting_id % setting_id; - } else if (preset->setting_id.empty()) + BOOST_LOG_TRIVIAL(error) << boost::format("name %1%, local setting_id %2% is different with remote id %3%") + %preset->name %preset->setting_id %setting_id; + } + else if (preset->setting_id.empty()) preset->setting_id = setting_id; - } else { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format("can not find setting %1% in system presets, type %2%") % name % type_iter->second; + } + else { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find setting %1% in system presets, type %2%") %name %type_iter->second; continue; } } return; } -// BBS: validate printers from previous project -static std::set gcodes_key_set = {"filament_end_gcode", "filament_start_gcode", "change_filament_gcode", - "layer_change_gcode", "machine_end_gcode", "machine_pause_gcode", - "machine_start_gcode", "template_custom_gcode", "printing_by_object_gcode", - "before_layer_change_gcode", "time_lapse_gcode", "wrapping_detection_gcode"}; -int PresetBundle::validate_presets(const std::string& file_name, DynamicPrintConfig& config, std::set& different_gcodes) +//BBS: validate printers from previous project +static std::set gcodes_key_set = {"filament_end_gcode", "filament_start_gcode", "change_filament_gcode", "layer_change_gcode", "machine_end_gcode", "machine_pause_gcode", "machine_start_gcode", + "template_custom_gcode", "printing_by_object_gcode", "before_layer_change_gcode", "time_lapse_gcode", "wrapping_detection_gcode"}; +int PresetBundle::validate_presets(const std::string &file_name, DynamicPrintConfig& config, std::set& different_gcodes) { - bool validated = false; - std::vector inherits_values = config.option("inherits_group", true)->values; - std::vector filament_preset_name = config.option("filament_settings_id", true)->values; - std::string printer_preset = config.option("printer_settings_id", true)->value; - bool has_different_settings_to_system = config.option("different_settings_to_system") ? true : false; + bool validated = false; + std::vector inherits_values = config.option("inherits_group", true)->values; + std::vector filament_preset_name = config.option("filament_settings_id", true)->values; + std::string printer_preset = config.option("printer_settings_id", true)->value; + bool has_different_settings_to_system = config.option("different_settings_to_system")?true:false; std::vector different_values; - int ret = VALIDATE_PRESETS_SUCCESS; + int ret = VALIDATE_PRESETS_SUCCESS; if (has_different_settings_to_system) different_values = config.option("different_settings_to_system", true)->values; - // PrinterTechnology printer_technology = Preset::printer_technology(config); + //PrinterTechnology printer_technology = Preset::printer_technology(config); size_t filament_count = config.option("filament_diameter")->values.size(); inherits_values.resize(filament_count + 2, std::string()); different_values.resize(filament_count + 2, std::string()); @@ -2155,14 +2120,14 @@ int PresetBundle::validate_presets(const std::string& file_name, DynamicPrintCon validated = this->printers.validate_preset(printer_preset, printer_inherits); if (!validated) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format(":file_name %1%, found the printer preset not inherit from system") % file_name; + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found the printer preset not inherit from system") % file_name; different_gcodes.emplace(printer_preset); ret = VALIDATE_PRESETS_PRINTER_NOT_FOUND; } - for (unsigned int index = 0; index < filament_count; index++) { - std::string filament_preset = filament_preset_name[index]; - std::string filament_inherits = inherits_values[index + 1]; + for(unsigned int index = 0; index < filament_count; index ++) + { + std::string filament_preset = filament_preset_name[index]; + std::string filament_inherits = inherits_values[index+1]; // filament_preset_name is padded up to filament_count from filament_diameter. Unfilled // slots have no assigned preset, so there's nothing to validate or warn about. @@ -2171,23 +2136,21 @@ int PresetBundle::validate_presets(const std::string& file_name, DynamicPrintCon validated = this->filaments.validate_preset(filament_preset, filament_inherits); if (!validated) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format(":file_name %1%, found the filament %2% preset not inherit from system") % - file_name % (index + 1); + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found the filament %2% preset not inherit from system") % file_name %(index+1); different_gcodes.emplace(filament_preset); ret = VALIDATE_PRESETS_FILAMENTS_NOT_FOUND; } } - // self defined presets, return directly - if (ret) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format(":file_name %1%, found self defined presets, count %2%") % file_name % - different_gcodes.size(); + //self defined presets, return directly + if (ret) + { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found self defined presets, count %2%") %file_name %different_gcodes.size(); return ret; } - for (unsigned int index = 1; index < filament_count; index++) { + for(unsigned int index = 1; index < filament_count; index ++) + { std::string different_settingss = different_values[index]; std::vector different_keys; @@ -2197,16 +2160,14 @@ int PresetBundle::validate_presets(const std::string& file_name, DynamicPrintCon for (unsigned int j = 0; j < different_keys.size(); j++) { if (gcodes_key_set.find(different_keys[j]) != gcodes_key_set.end()) { different_gcodes.emplace(different_keys[j]); - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format(":preset index %1%, different key %2%") % index % different_keys[j]; + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":preset index %1%, different key %2%") %index %different_keys[j]; } } } - if (!different_gcodes.empty()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format(":file_name %1%, found different gcodes count %2%") % file_name % - different_gcodes.size(); + if (!different_gcodes.empty()) + { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found different gcodes count %2%") %file_name %different_gcodes.size(); return VALIDATE_PRESETS_MODIFIED_GCODES; } @@ -2215,7 +2176,7 @@ int PresetBundle::validate_presets(const std::string& file_name, DynamicPrintCon return VALIDATE_PRESETS_SUCCESS; } -void PresetBundle::remove_users_preset(AppConfig& config, std::map>* my_presets) +void PresetBundle::remove_users_preset(AppConfig &config, std::map> *my_presets) { auto check_removed = [my_presets](Preset &preset) -> bool { if (my_presets == nullptr) return true; @@ -2230,18 +2191,17 @@ void PresetBundle::remove_users_preset(AppConfig& config, std::mapis_user() && it->user_id.compare(preset_folder_user_id) == 0 && check_removed(*it)) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(":printers erase %1%, type %2%, user_id %3%") % it->name % - Preset::get_type_string(it->type) % it->user_id; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":printers erase %1%, type %2%, user_id %3%") % it->name % Preset::get_type_string(it->type) % it->user_id; if (it->name == printer_selected_preset_name) need_reset_printer_preset = true; it = printers.erase(it); - } else { + } + else { it++; } } @@ -2263,17 +2223,16 @@ void PresetBundle::remove_users_preset(AppConfig& config, std::mapis_user() && it->user_id.compare(preset_folder_user_id) == 0 && check_removed(*it)) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(":prints erase %1%, type %2%, user_id %3%") % it->name % - Preset::get_type_string(it->type) % it->user_id; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":prints erase %1%, type %2%, user_id %3%")%it->name %Preset::get_type_string(it->type) %it->user_id; if (it->name == selected_print_name) need_reset_print_preset = true; it = prints.erase(it); - } else { + } + else { it++; } } @@ -2285,22 +2244,20 @@ void PresetBundle::remove_users_preset(AppConfig& config, std::mapis_user() && it->user_id.compare(preset_folder_user_id) == 0 && check_removed(*it)) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(":filaments erase %1%, type %2%, user_id %3%") % it->name % - Preset::get_type_string(it->type) % it->user_id; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":filaments erase %1%, type %2%, user_id %3%")%it->name %Preset::get_type_string(it->type) %it->user_id; if (it->name == selected_filament_name) need_reset_filament_preset = true; it = filaments.erase(it); - } else { + } + else { it++; } } if (need_reset_filament_preset && printers.get_selected_preset().config.has("default_filament_profile")) { - const std::vector& prefered_filament_profiles = - printers.get_selected_preset().config.option("default_filament_profile")->values; + const std::vector& prefered_filament_profiles = printers.get_selected_preset().config.option("default_filament_profile")->values; if (prefered_filament_profiles.size() > 0) filaments.select_preset_by_name(prefered_filament_profiles[0], true); } else { @@ -2310,7 +2267,8 @@ void PresetBundle::remove_users_preset(AppConfig& config, std::mapfilaments.find_preset(filament_presets[i]); if (preset == nullptr) filament_presets[i] = filaments.get_selected_preset_name(); @@ -2328,12 +2286,11 @@ void PresetBundle::clear_printer_hold_aliases() this->printers.m_printer_hold_alias.clear(); } -// BBS: add json related logic, load system presets from json -std::pair PresetBundle::load_system_presets_from_json( - ForwardCompatibilitySubstitutionRule compatibility_rule) +//BBS: add json related logic, load system presets from json +std::pair PresetBundle::load_system_presets_from_json(ForwardCompatibilitySubstitutionRule compatibility_rule) { - // BBS: add config related logs - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, compatibility_rule %1%") % compatibility_rule; + //BBS: add config related logs + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, compatibility_rule %1%")%compatibility_rule; if (compatibility_rule == ForwardCompatibilitySubstitutionRule::EnableSystemSilent) // Loading system presets, don't log substitutions. compatibility_rule = ForwardCompatibilitySubstitutionRule::EnableSilent; @@ -2342,8 +2299,8 @@ std::pair PresetBundle::load_system_pre compatibility_rule = ForwardCompatibilitySubstitutionRule::Disable; // Here the vendor specific read only Config Bundles are stored. - // BBS: change directory by design - boost::filesystem::path dir = (boost::filesystem::path(data_dir()) / PRESET_SYSTEM_DIR).make_preferred(); + //BBS: change directory by design + boost::filesystem::path dir = (boost::filesystem::path(data_dir()) / PRESET_SYSTEM_DIR).make_preferred(); if (validation_mode) dir = (boost::filesystem::path(data_dir())).make_preferred(); @@ -2352,10 +2309,10 @@ std::pair PresetBundle::load_system_pre // The vendors below are loaded whole and against each other — the filament // library first, then every other vendor with it as the base — so each parse // is complete enough to be worth caching. - m_generate_vendor_caches = m_generate_vendor_caches || !validation_mode; + m_generate_vendor_caches = m_generate_vendor_caches || ! validation_mode; - PresetsConfigSubstitutions substitutions; - std::string errors_cummulative; + PresetsConfigSubstitutions substitutions; + std::string errors_cummulative; bool first = true; // Sorted, so any duplicate-preset warning below comes out in the same order on // every run. @@ -2375,17 +2332,16 @@ std::pair PresetBundle::load_system_pre } // Step 1: Load ORCA_FILAMENT_LIBRARY into `this` synchronously. - if (!orca_lib_vendor.empty()) { + if (! orca_lib_vendor.empty()) { try { // Match a fresh launch before parsing: hold aliases and the error // counter survive reset(), and would otherwise carry prior-cycle // state into this load. this->clear_printer_hold_aliases(); this->m_errors = 0; - append(substitutions, - this->load_vendor_configs_from_json(dir.string(), orca_lib_vendor, PresetBundle::LoadSystem, compatibility_rule).first); + append(substitutions, this->load_vendor_configs_from_json(dir.string(), orca_lib_vendor, PresetBundle::LoadSystem, compatibility_rule).first); first = false; - } catch (const std::runtime_error& err) { + } catch (const std::runtime_error &err) { if (validation_mode) throw err; errors_cummulative += err.what(); @@ -2396,25 +2352,26 @@ std::pair PresetBundle::load_system_pre // Step 2: Load remaining vendors in parallel. Each gets its own // PresetBundle and uses `this` (which contains ORCA_FILAMENT_LIBRARY) // as the base_bundle for cross-bundle inheritance lookups. - std::vector> parallel_bundles(other_vendors.size()); - std::vector parallel_substitutions(other_vendors.size()); - std::vector parallel_errors(other_vendors.size()); + std::vector> parallel_bundles(other_vendors.size()); + std::vector parallel_substitutions(other_vendors.size()); + std::vector parallel_errors(other_vendors.size()); - tbb::parallel_for(tbb::blocked_range(0, other_vendors.size()), [&](const tbb::blocked_range& range) { - for (size_t i = range.begin(); i < range.end(); ++i) { - auto bundle = std::make_unique(); - bundle->set_is_validation_mode(validation_mode); - bundle->set_generate_vendor_caches(m_generate_vendor_caches); - try { - auto result = bundle->load_vendor_configs_from_json(dir.string(), other_vendors[i], PresetBundle::LoadSystem, - compatibility_rule, this); - parallel_substitutions[i] = std::move(result.first); - parallel_bundles[i] = std::move(bundle); - } catch (const std::runtime_error& err) { - parallel_errors[i] = err.what(); + tbb::parallel_for(tbb::blocked_range(0, other_vendors.size()), + [&](const tbb::blocked_range& range) { + for (size_t i = range.begin(); i < range.end(); ++i) { + auto bundle = std::make_unique(); + bundle->set_is_validation_mode(validation_mode); + bundle->set_generate_vendor_caches(m_generate_vendor_caches); + try { + auto result = bundle->load_vendor_configs_from_json( + dir.string(), other_vendors[i], PresetBundle::LoadSystem, compatibility_rule, this); + parallel_substitutions[i] = std::move(result.first); + parallel_bundles[i] = std::move(bundle); + } catch (const std::runtime_error &err) { + parallel_errors[i] = err.what(); + } } - } - }); + }); // Step 3: Sequentially merge the parallel-loaded bundles into `this`. // The merge order is the original vendor order so any duplicate-warning @@ -2433,7 +2390,7 @@ std::pair PresetBundle::load_system_pre const std::string& vendor_name = other_vendors[i]; append(substitutions, std::move(parallel_substitutions[i])); std::vector duplicates = this->merge_presets(std::move(*parallel_bundles[i])); - first = false; + first = false; if (!duplicates.empty()) { errors_cummulative += "Found duplicated settings in vendor " + vendor_name + "'s json file lists: "; for (size_t j = 0; j < duplicates.size(); ++j) { @@ -2447,22 +2404,22 @@ std::pair PresetBundle::load_system_pre } if (first) { - // No config bundle loaded, reset. - this->reset(false); - } + // No config bundle loaded, reset. + this->reset(false); + } - this->update_system_maps(); + this->update_system_maps(); - const auto load_ms = std::chrono::duration_cast(std::chrono::steady_clock::now() - load_t0).count(); + const auto load_ms = std::chrono::duration_cast( + std::chrono::steady_clock::now() - load_t0).count(); BOOST_LOG_TRIVIAL(info) << "PresetBundle: " << vendor_names.size() << " vendor(s) loaded in " << load_ms << " ms"; - // BBS: add config related logs - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, errors_cummulative %1%") % errors_cummulative; + //BBS: add config related logs + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, errors_cummulative %1%")%errors_cummulative; return std::make_pair(std::move(substitutions), errors_cummulative); } -std::pair PresetBundle::load_system_models_from_json( - ForwardCompatibilitySubstitutionRule compatibility_rule) +std::pair PresetBundle::load_system_models_from_json(ForwardCompatibilitySubstitutionRule compatibility_rule) { BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, compatibility_rule %1%") % compatibility_rule; if (compatibility_rule == ForwardCompatibilitySubstitutionRule::EnableSystemSilent) @@ -2473,10 +2430,10 @@ std::pair PresetBundle::load_system_mod compatibility_rule = ForwardCompatibilitySubstitutionRule::Disable; // Here the vendor specific read only Config Bundles are stored. - boost::filesystem::path dir = (boost::filesystem::path(resources_dir()) / "profiles").make_preferred(); + boost::filesystem::path dir = (boost::filesystem::path(resources_dir()) / "profiles").make_preferred(); PresetsConfigSubstitutions substitutions; - std::string errors_cummulative; - for (auto& dir_entry : boost::filesystem::directory_iterator(dir)) { + std::string errors_cummulative; + for (auto &dir_entry : boost::filesystem::directory_iterator(dir)) { std::string vendor_file = dir_entry.path().string(); if (Slic3r::is_json_file(vendor_file)) { std::string vendor_name = dir_entry.path().filename().string(); @@ -2484,9 +2441,8 @@ std::pair PresetBundle::load_system_mod vendor_name.erase(vendor_name.size() - 5); try { // Load the config bundle, flatten it. - append(substitutions, - load_vendor_configs_from_json(dir.string(), vendor_name, PresetBundle::LoadVendorOnly, compatibility_rule).first); - } catch (const std::runtime_error& err) { + append(substitutions, load_vendor_configs_from_json(dir.string(), vendor_name, PresetBundle::LoadVendorOnly, compatibility_rule).first); + } catch (const std::runtime_error &err) { errors_cummulative += err.what(); errors_cummulative += "\n"; } @@ -2497,8 +2453,7 @@ std::pair PresetBundle::load_system_mod return std::make_pair(std::move(substitutions), errors_cummulative); } -std::pair PresetBundle::load_system_filaments_json( - ForwardCompatibilitySubstitutionRule compatibility_rule) +std::pair PresetBundle::load_system_filaments_json(ForwardCompatibilitySubstitutionRule compatibility_rule) { BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, compatibility_rule %1%") % compatibility_rule; if (compatibility_rule == ForwardCompatibilitySubstitutionRule::EnableSystemSilent) @@ -2509,11 +2464,11 @@ std::pair PresetBundle::load_system_fil compatibility_rule = ForwardCompatibilitySubstitutionRule::Disable; // Here the vendor specific read only Config Bundles are stored. - boost::filesystem::path dir = (boost::filesystem::path(resources_dir()) / "profiles").make_preferred(); + boost::filesystem::path dir = (boost::filesystem::path(resources_dir()) / "profiles").make_preferred(); PresetsConfigSubstitutions substitutions; - std::string errors_cummulative; - bool first = true; - for (auto& dir_entry : boost::filesystem::directory_iterator(dir)) { + std::string errors_cummulative; + bool first = true; + for (auto &dir_entry : boost::filesystem::directory_iterator(dir)) { std::string vendor_file = dir_entry.path().string(); if (Slic3r::is_json_file(vendor_file)) { std::string vendor_name = dir_entry.path().filename().string(); @@ -2522,31 +2477,23 @@ std::pair PresetBundle::load_system_fil try { if (first) { // Reset this PresetBundle and load the first vendor config. - append(substitutions, this->load_vendor_configs_from_json(dir.string(), vendor_name, - PresetBundle::LoadSystem | PresetBundle::LoadFilamentOnly, - compatibility_rule) - .first); + append(substitutions, this->load_vendor_configs_from_json(dir.string(), vendor_name, PresetBundle::LoadSystem | PresetBundle::LoadFilamentOnly, compatibility_rule).first); first = false; } else { // Load the other vendor configs, merge them with this PresetBundle. // Report duplicate profiles. PresetBundle other; - append(substitutions, - other - .load_vendor_configs_from_json(dir.string(), vendor_name, - PresetBundle::LoadSystem | PresetBundle::LoadFilamentOnly, compatibility_rule) - .first); + append(substitutions, other.load_vendor_configs_from_json(dir.string(), vendor_name, PresetBundle::LoadSystem | PresetBundle::LoadFilamentOnly, compatibility_rule).first); std::vector duplicates = this->merge_presets(std::move(other)); if (!duplicates.empty()) { errors_cummulative += "Found duplicated settings in vendor " + vendor_name + "'s json file lists: "; for (size_t i = 0; i < duplicates.size(); ++i) { - if (i > 0) - errors_cummulative += ", "; + if (i > 0) errors_cummulative += ", "; errors_cummulative += duplicates[i]; } } } - } catch (const std::runtime_error& err) { + } catch (const std::runtime_error &err) { errors_cummulative += err.what(); errors_cummulative += "\n"; } @@ -2562,19 +2509,17 @@ VendorProfile PresetBundle::get_custom_vendor_models() const VendorProfile vendor; vendor.name = PRESET_CUSTOM_VENDOR; vendor.id = PRESET_CUSTOM_VENDOR; - for (auto& preset : printers.get_presets()) { - if (preset.is_system) - continue; - if (printers.get_preset_base(preset) != &preset) - continue; - if (preset.is_default) - continue; - auto model = preset.config.opt_string("printer_model"); - auto variant = preset.config.opt_string("printer_variant"); - auto iter_model = std::find_if(vendor.models.begin(), vendor.models.end(), - [model](VendorProfile::PrinterModel& m) { return m.name == model; }); + for (auto &preset : printers.get_presets()) { + if (preset.is_system) continue; + if (printers.get_preset_base(preset) != &preset) continue; + if (preset.is_default) continue; + auto model = preset.config.opt_string("printer_model"); + auto variant = preset.config.opt_string("printer_variant"); + auto iter_model = std::find_if(vendor.models.begin(), vendor.models.end(), [model](VendorProfile::PrinterModel &m) { + return m.name == model; + }); if (iter_model == vendor.models.end()) { - iter_model = vendor.models.emplace(vendor.models.end(), VendorProfile::PrinterModel{}); + iter_model = vendor.models.emplace(vendor.models.end(), VendorProfile::PrinterModel{}); iter_model->id = model; iter_model->name = model; iter_model->variants = {VendorProfile::PrinterVariant(variant)}; @@ -2586,21 +2531,21 @@ VendorProfile PresetBundle::get_custom_vendor_models() const } // Merge one vendor's presets with the other vendor's presets, report duplicates. -std::vector PresetBundle::merge_presets(PresetBundle&& other) +std::vector PresetBundle::merge_presets(PresetBundle &&other) { this->vendors.insert(other.vendors.begin(), other.vendors.end()); - std::vector duplicate_prints = this->prints.merge_presets(std::move(other.prints), this->vendors); - std::vector duplicate_sla_prints = this->sla_prints.merge_presets(std::move(other.sla_prints), this->vendors); - std::vector duplicate_filaments = this->filaments.merge_presets(std::move(other.filaments), this->vendors); + std::vector duplicate_prints = this->prints .merge_presets(std::move(other.prints), this->vendors); + std::vector duplicate_sla_prints = this->sla_prints .merge_presets(std::move(other.sla_prints), this->vendors); + std::vector duplicate_filaments = this->filaments .merge_presets(std::move(other.filaments), this->vendors); std::vector duplicate_sla_materials = this->sla_materials.merge_presets(std::move(other.sla_materials), this->vendors); - std::vector duplicate_printers = this->printers.merge_presets(std::move(other.printers), this->vendors); - append(this->obsolete_presets.prints, std::move(other.obsolete_presets.prints)); - append(this->obsolete_presets.sla_prints, std::move(other.obsolete_presets.sla_prints)); - append(this->obsolete_presets.filaments, std::move(other.obsolete_presets.filaments)); + std::vector duplicate_printers = this->printers .merge_presets(std::move(other.printers), this->vendors); + append(this->obsolete_presets.prints, std::move(other.obsolete_presets.prints)); + append(this->obsolete_presets.sla_prints, std::move(other.obsolete_presets.sla_prints)); + append(this->obsolete_presets.filaments, std::move(other.obsolete_presets.filaments)); append(this->obsolete_presets.sla_materials, std::move(other.obsolete_presets.sla_materials)); - append(this->obsolete_presets.printers, std::move(other.obsolete_presets.printers)); - append(duplicate_prints, std::move(duplicate_sla_prints)); - append(duplicate_prints, std::move(duplicate_filaments)); + append(this->obsolete_presets.printers, std::move(other.obsolete_presets.printers)); + append(duplicate_prints, std::move(duplicate_sla_prints)); + append(duplicate_prints, std::move(duplicate_filaments)); append(duplicate_prints, std::move(duplicate_sla_materials)); append(duplicate_prints, std::move(duplicate_printers)); m_errors += other.m_errors; @@ -2609,22 +2554,22 @@ std::vector PresetBundle::merge_presets(PresetBundle&& other) void PresetBundle::update_system_maps() { - this->prints.update_map_system_profile_renamed(); - this->sla_prints.update_map_system_profile_renamed(); - this->filaments.update_map_system_profile_renamed(); + this->prints .update_map_system_profile_renamed(); + this->sla_prints .update_map_system_profile_renamed(); + this->filaments .update_map_system_profile_renamed(); this->sla_materials.update_map_system_profile_renamed(); - this->printers.update_map_system_profile_renamed(); + this->printers .update_map_system_profile_renamed(); - this->prints.update_map_alias_to_profile_name(); - this->sla_prints.update_map_alias_to_profile_name(); - this->filaments.update_map_alias_to_profile_name(); + this->prints .update_map_alias_to_profile_name(); + this->sla_prints .update_map_alias_to_profile_name(); + this->filaments .update_map_alias_to_profile_name(); this->sla_materials.update_map_alias_to_profile_name(); - this->printers.update_map_alias_to_profile_name(); + this->printers .update_map_alias_to_profile_name(); this->filaments.update_library_profile_excluded_from(); } -static inline std::string remove_ini_suffix(const std::string& name) +static inline std::string remove_ini_suffix(const std::string &name) { std::string out = name; if (boost::iends_with(out, ".ini")) @@ -2635,14 +2580,14 @@ static inline std::string remove_ini_suffix(const std::string& name) // Set the "enabled" flag for printer vendors, printer models and printer variants // based on the user configuration. // If the "vendor" section is missing, enable all models and variants of the particular vendor. -void PresetBundle::load_installed_printers(const AppConfig& config) +void PresetBundle::load_installed_printers(const AppConfig &config) { - this->update_system_maps(); - for (auto& preset : printers) + this->update_system_maps(); + for (auto &preset : printers) preset.set_visible_from_appconfig(config); } -const std::string& PresetBundle::get_preset_name_by_alias(const Preset::Type& preset_type, const std::string& alias) const +const std::string& PresetBundle::get_preset_name_by_alias( const Preset::Type& preset_type, const std::string& alias) const { if (preset_type == Preset::TYPE_INVALID) return alias; @@ -2651,21 +2596,21 @@ const std::string& PresetBundle::get_preset_name_by_alias(const Preset::Type& pr preset_type == Preset::TYPE_SLA_PRINT ? sla_prints : preset_type == Preset::TYPE_FILAMENT ? filaments : preset_type == Preset::TYPE_PRINTER ? printers : - sla_materials; + sla_materials; return presets.get_preset_name_by_alias(alias); } -// BBS: get filament required hrc by filament type +//BBS: get filament required hrc by filament type const int PresetBundle::get_required_hrc_by_filament_type(const std::string& filament_type) const { - static std::unordered_map filament_type_to_hrc; + static std::unordered_mapfilament_type_to_hrc; if (filament_type_to_hrc.empty()) { for (auto iter = filaments.m_presets.begin(); iter != filaments.m_presets.end(); iter++) { if (iter->vendor && iter->vendor->id == "BBL") { if (iter->config.has("filament_type") && iter->config.has("required_nozzle_HRC")) { - auto type = iter->config.opt_string("filament_type", 0); - auto hrc = iter->config.opt_int("required_nozzle_HRC", 0); + auto type = iter->config.opt_string("filament_type", 0); + auto hrc = iter->config.opt_int("required_nozzle_HRC", 0); filament_type_to_hrc[type] = hrc; } } @@ -2678,17 +2623,14 @@ const int PresetBundle::get_required_hrc_by_filament_type(const std::string& fil return 0; } -// BBS: add project embedded preset logic -void PresetBundle::save_changes_for_preset(const std::string& new_name, - Preset::Type type, - const std::vector& unselected_options, - bool save_to_project) +//BBS: add project embedded preset logic +void PresetBundle::save_changes_for_preset(const std::string& new_name, Preset::Type type, + const std::vector& unselected_options, bool save_to_project) { - PresetCollection& presets = type == Preset::TYPE_PRINT ? prints : - type == Preset::TYPE_SLA_PRINT ? sla_prints : - type == Preset::TYPE_FILAMENT ? filaments : - type == Preset::TYPE_SLA_MATERIAL ? sla_materials : - printers; + PresetCollection& presets = type == Preset::TYPE_PRINT ? prints : + type == Preset::TYPE_SLA_PRINT ? sla_prints : + type == Preset::TYPE_FILAMENT ? filaments : + type == Preset::TYPE_SLA_MATERIAL ? sla_materials : printers; // if we want to save just some from selected options if (!unselected_options.empty()) { @@ -2697,12 +2639,11 @@ void PresetBundle::save_changes_for_preset(const std::string& new_name, } // Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini - // BBS: add project embedded preset logic - // presets.save_current_preset(new_name); + //BBS: add project embedded preset logic + //presets.save_current_preset(new_name); presets.save_current_preset(new_name, false, save_to_project); // Mark the print & filament enabled if they are compatible with the currently selected preset. - // If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a - // "red flag" icon showing that they are no more compatible. + // If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a "red flag" icon showing that they are no more compatible. update_compatible(PresetSelectCompatibleType::Never); if (type == Preset::TYPE_FILAMENT) { @@ -2711,90 +2652,87 @@ void PresetBundle::save_changes_for_preset(const std::string& new_name, } } -void PresetBundle::load_installed_filaments(AppConfig& config) +void PresetBundle::load_installed_filaments(AppConfig &config) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, printer size %1%") % printers.size(); - // if (! config.has_section(AppConfig::SECTION_FILAMENTS) - // || config.get_section(AppConfig::SECTION_FILAMENTS).empty()) { - // Compatibility with the PrusaSlicer 2.1.1 and older, where the filament profiles were not installable yet. - // Find all filament profiles, which are compatible with installed printers, and act as if these filament profiles - // were installed. - std::unordered_set compatible_filaments; - for (const Preset& printer : printers) - if (printer.is_visible && printer.printer_technology() == ptFFF && printer.vendor && (!printer.vendor->models.empty())) { - bool add_default_materials = true; - if (config.has_section(AppConfig::SECTION_FILAMENTS)) { - const std::map& installed_filament = config.get_section(AppConfig::SECTION_FILAMENTS); - for (auto filament_iter : installed_filament) { - Preset* filament = filaments.find_preset(filament_iter.first, false, true); - if (filament && is_compatible_with_printer(PresetWithVendorProfile(*filament, filament->vendor), - PresetWithVendorProfile(printer, printer.vendor))) { - // already has compatible filament - add_default_materials = false; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": printer %1% vendor %2% already has default filament %3%") % - printer.name % printer.vendor % filament_iter.first; - break; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, printer size %1%")%printers.size(); + //if (! config.has_section(AppConfig::SECTION_FILAMENTS) + // || config.get_section(AppConfig::SECTION_FILAMENTS).empty()) { + // Compatibility with the PrusaSlicer 2.1.1 and older, where the filament profiles were not installable yet. + // Find all filament profiles, which are compatible with installed printers, and act as if these filament profiles + // were installed. + std::unordered_set compatible_filaments; + for (const Preset &printer : printers) + if (printer.is_visible && printer.printer_technology() == ptFFF && printer.vendor && (!printer.vendor->models.empty())) { + bool add_default_materials = true; + if (config.has_section(AppConfig::SECTION_FILAMENTS)) + { + const std::map& installed_filament = config.get_section(AppConfig::SECTION_FILAMENTS); + for (auto filament_iter : installed_filament) + { + Preset* filament = filaments.find_preset(filament_iter.first, false, true); + if (filament && is_compatible_with_printer(PresetWithVendorProfile(*filament, filament->vendor), PresetWithVendorProfile(printer, printer.vendor))) + { + + //already has compatible filament + add_default_materials = false; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1% vendor %2% already has default filament %3%")%printer.name %printer.vendor %filament_iter.first; + break; + } } } - } - if (!add_default_materials) - continue; + if (!add_default_materials) + continue; - const VendorProfile::PrinterModel* printer_model = PresetUtils::system_printer_model(printer); - if (!printer_model) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": can not find printer_model for printer %1%") % printer.name; - continue; + const VendorProfile::PrinterModel *printer_model = PresetUtils::system_printer_model(printer); + if (!printer_model) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": can not find printer_model for printer %1%")%printer.name; + continue; + } + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1% vendor %2% don't have filament visible, will add %3% default filaments")%printer.name %printer.vendor %printer_model->default_materials.size(); + for (auto default_filament: printer_model->default_materials) + { + Preset* filament = filaments.find_preset(default_filament, false, true); + if (filament && filament->is_system) + compatible_filaments.insert(filament); + } + //const PresetWithVendorProfile printer_with_vendor_profile = printers.get_preset_with_vendor_profile(printer); + //for (const Preset &filament : filaments) + // if (filament.is_system && is_compatible_with_printer(filaments.get_preset_with_vendor_profile(filament), printer_with_vendor_profile)) + // compatible_filaments.insert(&filament); } - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format( - ": printer %1% vendor %2% don't have filament visible, will add %3% default filaments") % - printer.name % printer.vendor % printer_model->default_materials.size(); - for (auto default_filament : printer_model->default_materials) { - Preset* filament = filaments.find_preset(default_filament, false, true); - if (filament && filament->is_system) - compatible_filaments.insert(filament); - } - // const PresetWithVendorProfile printer_with_vendor_profile = printers.get_preset_with_vendor_profile(printer); - // for (const Preset &filament : filaments) - // if (filament.is_system && is_compatible_with_printer(filaments.get_preset_with_vendor_profile(filament), - // printer_with_vendor_profile)) - // compatible_filaments.insert(&filament); + // and mark these filaments as installed, therefore this code will not be executed at the next start of the application. + for (const auto &filament: compatible_filaments) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": set filament %1% to visible by default")%filament->name; + config.set(AppConfig::SECTION_FILAMENTS, filament->name, "true"); } - // and mark these filaments as installed, therefore this code will not be executed at the next start of the application. - for (const auto& filament : compatible_filaments) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": set filament %1% to visible by default") % filament->name; - config.set(AppConfig::SECTION_FILAMENTS, filament->name, "true"); - } //} - for (auto& preset : filaments) + for (auto &preset : filaments) preset.set_visible_from_appconfig(config); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": exit."); } -void PresetBundle::load_installed_sla_materials(AppConfig& config) +void PresetBundle::load_installed_sla_materials(AppConfig &config) { - if (!config.has_section(AppConfig::SECTION_MATERIALS)) { + if (! config.has_section(AppConfig::SECTION_MATERIALS)) { std::unordered_set comp_sla_materials; - // Compatibility with the PrusaSlicer 2.1.1 and older, where the SLA material profiles were not installable yet. - // Find all SLA material profiles, which are compatible with installed printers, and act as if these SLA material profiles - // were installed. - for (const Preset& printer : printers) + // Compatibility with the PrusaSlicer 2.1.1 and older, where the SLA material profiles were not installable yet. + // Find all SLA material profiles, which are compatible with installed printers, and act as if these SLA material profiles + // were installed. + for (const Preset &printer : printers) if (printer.is_visible && printer.printer_technology() == ptSLA) { - const PresetWithVendorProfile printer_with_vendor_profile = printers.get_preset_with_vendor_profile(printer); - for (const Preset& material : sla_materials) - if (material.is_system && - is_compatible_with_printer(sla_materials.get_preset_with_vendor_profile(material), printer_with_vendor_profile)) - comp_sla_materials.insert(&material); - } - // and mark these SLA materials as installed, therefore this code will not be executed at the next start of the application. - for (const auto& material : comp_sla_materials) + const PresetWithVendorProfile printer_with_vendor_profile = printers.get_preset_with_vendor_profile(printer); + for (const Preset &material : sla_materials) + if (material.is_system && is_compatible_with_printer(sla_materials.get_preset_with_vendor_profile(material), printer_with_vendor_profile)) + comp_sla_materials.insert(&material); + } + // and mark these SLA materials as installed, therefore this code will not be executed at the next start of the application. + for (const auto &material: comp_sla_materials) config.set(AppConfig::SECTION_MATERIALS, material->name, "true"); } - for (auto& preset : sla_materials) + for (auto &preset : sla_materials) preset.set_visible_from_appconfig(config); } @@ -2805,10 +2743,11 @@ void PresetBundle::load_installed_sla_materials(AppConfig& config) // indices into exactly that list. Missing keys clear the arrays, so one printer never inherits // another's mixes; fallback_to_global also reads the shared "presets" keys an older config // layout used, which export_selections drops on the next save. -static void load_mixed_filament_settings( - DynamicPrintConfig& project_config, AppConfig& config, const std::string& printer_name, size_t n_filaments, bool fallback_to_global) +static void load_mixed_filament_settings(DynamicPrintConfig &project_config, AppConfig &config, + const std::string &printer_name, size_t n_filaments, + bool fallback_to_global) { - auto raw_value = [&](const char* key, bool& found) -> std::string { + auto raw_value = [&](const char *key, bool &found) -> std::string { if (config.has_printer_setting(printer_name, key)) { found = true; return config.get_printer_setting(printer_name, key); @@ -2821,22 +2760,21 @@ static void load_mixed_filament_settings( return std::string{}; }; std::vector parts; - auto load_bools = [&](const char* key) { - auto& vals = project_config.option(key)->values; + auto load_bools = [&](const char *key) { + auto &vals = project_config.option(key)->values; vals.clear(); - bool found = false; + bool found = false; const std::string s = raw_value(key, found); if (found && !s.empty()) { boost::algorithm::split(parts, s, boost::algorithm::is_any_of(",")); - for (const auto& p : parts) - vals.push_back(p == "1"); + for (const auto &p : parts) vals.push_back(p == "1"); } vals.resize(n_filaments, false); }; - auto load_strings = [&](const char* key) { - auto& vals = project_config.option(key)->values; + auto load_strings = [&](const char *key) { + auto &vals = project_config.option(key)->values; vals.clear(); - bool found = false; + bool found = false; const std::string s = raw_value(key, found); if (found && !s.empty()) { boost::algorithm::split(parts, s, boost::algorithm::is_any_of("|")); @@ -2855,9 +2793,9 @@ static void load_mixed_filament_settings( // The gradient curve is the one array whose values contain '|' themselves (it separates the // control points), so it is stored C-style escaped rather than '|'-joined. { - auto& vals = project_config.option("filament_mixed_gradient_curve")->values; + auto &vals = project_config.option("filament_mixed_gradient_curve")->values; vals.clear(); - bool found = false; + bool found = false; const std::string s = raw_value("filament_mixed_gradient_curve", found); if (found && !s.empty()) { std::vector curves; @@ -2871,12 +2809,12 @@ static void load_mixed_filament_settings( } } -void PresetBundle::update_selections(AppConfig& config) +void PresetBundle::update_selections(AppConfig &config) { - std::string initial_printer_profile_name = printers.get_selected_preset_name(); + std::string initial_printer_profile_name = printers.get_selected_preset_name(); // Orca: load from orca_presets - std::string initial_print_profile_name = config.get_printer_setting(initial_printer_profile_name, PRESET_PRINT_NAME); - std::string initial_filament_profile_name = config.get_printer_setting(initial_printer_profile_name, PRESET_FILAMENT_NAME); + std::string initial_print_profile_name = config.get_printer_setting(initial_printer_profile_name, PRESET_PRINT_NAME); + std::string initial_filament_profile_name = config.get_printer_setting(initial_printer_profile_name, PRESET_FILAMENT_NAME); // Selects the profiles, which were selected at the last application close. prints.select_preset_by_name_strict(initial_print_profile_name); @@ -2886,8 +2824,8 @@ void PresetBundle::update_selections(AppConfig& config) // Load it even if the current printer technology is SLA. // The possibly excessive filament names will be later removed with this->update_multi_material_filament_presets() // once the FFF technology gets selected. - this->filament_presets = {filaments.get_selected_preset_name()}; - for (unsigned int i = 1; i < 1000; ++i) { + this->filament_presets = { filaments.get_selected_preset_name() }; + for (unsigned int i = 1; i < 1000; ++ i) { char name[64]; sprintf(name, "filament_%02u", i); auto f_name = config.get_printer_setting(initial_printer_profile_name, name); @@ -2908,18 +2846,14 @@ void PresetBundle::update_selections(AppConfig& config) std::vector multi_filament_colors; if (config.has_printer_setting(initial_printer_profile_name, "filament_multi_colors")) { - boost::algorithm::split(multi_filament_colors, config.get_printer_setting(initial_printer_profile_name, "filament_multi_colors"), - boost::algorithm::is_any_of(",")); + boost::algorithm::split(multi_filament_colors, config.get_printer_setting(initial_printer_profile_name, "filament_multi_colors"), boost::algorithm::is_any_of(",")); } - if (multi_filament_colors.size() == 0) - project_config.option("filament_multi_colour")->values = filament_colors; - else - project_config.option("filament_multi_colour")->values = multi_filament_colors; + if (multi_filament_colors.size() == 0) project_config.option("filament_multi_colour")->values = filament_colors; + else project_config.option("filament_multi_colour")->values = multi_filament_colors; std::vector filament_color_types; if (config.has_printer_setting(initial_printer_profile_name, "filament_color_types")) { - boost::algorithm::split(filament_color_types, config.get_printer_setting(initial_printer_profile_name, "filament_color_types"), - boost::algorithm::is_any_of(",")); + boost::algorithm::split(filament_color_types, config.get_printer_setting(initial_printer_profile_name, "filament_color_types"), boost::algorithm::is_any_of(",")); } filament_color_types.resize(filament_presets.size(), "1"); project_config.option("filament_colour_type")->values = filament_color_types; @@ -2935,32 +2869,25 @@ void PresetBundle::update_selections(AppConfig& config) std::vector extruder_ams_count_str; if (config.has_printer_setting(initial_printer_profile_name, "extruder_ams_count")) { - boost::algorithm::split(extruder_ams_count_str, config.get_printer_setting(initial_printer_profile_name, "extruder_ams_count"), - boost::algorithm::is_any_of(",")); + boost::algorithm::split(extruder_ams_count_str, config.get_printer_setting(initial_printer_profile_name, "extruder_ams_count"), boost::algorithm::is_any_of(",")); } this->extruder_ams_counts = get_extruder_ams_count(extruder_ams_count_str); std::vector matrix; if (config.has_printer_setting(initial_printer_profile_name, "flush_volumes_matrix")) { - boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_volumes_matrix"), - boost::algorithm::is_any_of("|")); + boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_volumes_matrix"), boost::algorithm::is_any_of("|")); auto flush_volumes_matrix = matrix | boost::adaptors::transformed(boost::lexical_cast); - project_config.option("flush_volumes_matrix")->values = std::vector(flush_volumes_matrix.begin(), - flush_volumes_matrix.end()); + project_config.option("flush_volumes_matrix")->values = std::vector(flush_volumes_matrix.begin(), flush_volumes_matrix.end()); } if (config.has_printer_setting(initial_printer_profile_name, "flush_volumes_vector")) { - boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_volumes_vector"), - boost::algorithm::is_any_of("|")); + boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_volumes_vector"), boost::algorithm::is_any_of("|")); auto flush_volumes_vector = matrix | boost::adaptors::transformed(boost::lexical_cast); - project_config.option("flush_volumes_vector")->values = std::vector(flush_volumes_vector.begin(), - flush_volumes_vector.end()); + project_config.option("flush_volumes_vector")->values = std::vector(flush_volumes_vector.begin(), flush_volumes_vector.end()); } if (config.has_printer_setting(initial_printer_profile_name, "flush_multiplier")) { - boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_multiplier"), - boost::algorithm::is_any_of("|")); + boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_multiplier"), boost::algorithm::is_any_of("|")); auto flush_multipliers = matrix | boost::adaptors::transformed(boost::lexical_cast); - project_config.option("flush_multiplier")->values = std::vector(flush_multipliers.begin(), - flush_multipliers.end()); + project_config.option("flush_multiplier")->values = std::vector(flush_multipliers.begin(), flush_multipliers.end()); } // No global fallback here: on a printer change the legacy shared keys describe another // printer's filament list, so absent per-printer keys must clear the mixes, not revive them. @@ -2974,27 +2901,26 @@ void PresetBundle::update_selections(AppConfig& config) this->update_multi_material_filament_presets(); std::string first_visible_filament_name; - for (auto& fp : filament_presets) { + for (auto & fp : filament_presets) { // Orca: also match the ORCA_DEFAULT_FILAMENT_PLACEHOLDER placeholder. update_compatible_internal // iterates from m_num_default_presets, so the placeholder's is_compatible flag // stays true and the not-found/visible/compatible predicate alone would miss it. - if (auto it = filaments.find_preset_internal(fp); - fp == ORCA_DEFAULT_FILAMENT_PLACEHOLDER || it == filaments.end() || !it->is_visible || !it->is_compatible) { + if (auto it = filaments.find_preset_internal(fp); fp == ORCA_DEFAULT_FILAMENT_PLACEHOLDER || it == filaments.end() || !it->is_visible || !it->is_compatible) { if (first_visible_filament_name.empty()) first_visible_filament_name = filaments.first_compatible().name; fp = first_visible_filament_name; } } + } // Load selections (current print, current filaments, current printer) from config.ini // This is done on application start up or after updates are applied. -void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& preferred_selection /* = PresetPreferences()*/) +void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& preferred_selection/* = PresetPreferences()*/) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": enter, preferred printer_model_id %1%") % preferred_selection.printer_model_id; - // Update visibility of presets based on application vendor / model / variant configuration. - this->load_installed_printers(config); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, preferred printer_model_id %1%")%preferred_selection.printer_model_id; + // Update visibility of presets based on application vendor / model / variant configuration. + this->load_installed_printers(config); // Update visibility of filament and sla material presets this->load_installed_filaments(config); @@ -3003,7 +2929,7 @@ void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& p // Parse the initial print / filament / printer profile names. // std::string initial_sla_print_profile_name = remove_ini_suffix(config.get("presets", PRESET_SLA_PRINT_NAME)); // std::string initial_sla_material_profile_name = remove_ini_suffix(config.get("presets", PRESET_SLA_MATERIALS_NAME)); - std::string initial_printer_profile_name = remove_ini_suffix(config.get("presets", PRESET_PRINTER_NAME)); + std::string initial_printer_profile_name = remove_ini_suffix(config.get("presets", PRESET_PRINTER_NAME)); // Activate print / filament / printer profiles from either the config, // or from the preferred_model_id suggestion passed in by ConfigWizard. @@ -3011,26 +2937,25 @@ void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& p // Do not select alternate profiles for the print / filament profiles as those presets // will be selected by the following call of this->update_compatible(PresetSelectCompatibleType::Always). - const Preset* initial_printer = printers.find_preset(initial_printer_profile_name); + const Preset *initial_printer = printers.find_preset(initial_printer_profile_name); // If executed due to a Config Wizard update, preferred_printer contains the first newly installed printer, otherwise nullptr. - const Preset* preferred_printer = printers.find_system_preset_by_model_and_variant(preferred_selection.printer_model_id, - preferred_selection.printer_variant); + const Preset *preferred_printer = printers.find_system_preset_by_model_and_variant(preferred_selection.printer_model_id, preferred_selection.printer_variant); printers.select_preset_by_name(preferred_printer ? preferred_printer->name : initial_printer_profile_name, true); CNumericLocalesSetter locales_setter; // Orca: load from orca_presets // const auto os_presets = config.get_machine_settings(initial_printer_profile_name); - std::string initial_print_profile_name = config.get_printer_setting(initial_printer_profile_name, PRESET_PRINT_NAME); - std::string initial_filament_profile_name = config.get_printer_setting(initial_printer_profile_name, PRESET_FILAMENT_NAME); + std::string initial_print_profile_name = config.get_printer_setting(initial_printer_profile_name, PRESET_PRINT_NAME); + std::string initial_filament_profile_name = config.get_printer_setting(initial_printer_profile_name, PRESET_FILAMENT_NAME); - // BBS: set default print/filament profiles to BBL's default setting - if (preferred_printer) { + //BBS: set default print/filament profiles to BBL's default setting + if (preferred_printer) + { const std::string& prefered_print_profile = preferred_printer->config.opt_string("default_print_profile"); if ((!initial_print_profile_name.compare("Default Setting")) && (prefered_print_profile.size() > 0)) initial_print_profile_name = prefered_print_profile; - const std::vector& prefered_filament_profiles = - preferred_printer->config.option("default_filament_profile")->values; + const std::vector& prefered_filament_profiles = preferred_printer->config.option("default_filament_profile")->values; if ((!initial_filament_profile_name.compare(ORCA_DEFAULT_FILAMENT_PLACEHOLDER)) && (prefered_filament_profiles.size() > 0)) { // Check if preferred filament is visible const Preset* preferred_preset = this->filaments.find_preset(prefered_filament_profiles[0], false); @@ -3044,15 +2969,15 @@ void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& p // Selects the profile, leaves it to -1 if the initial profile name is empty or if it was not found. prints.select_preset_by_name_strict(initial_print_profile_name); filaments.select_preset_by_name_strict(initial_filament_profile_name); - // sla_prints.select_preset_by_name_strict(initial_sla_print_profile_name); + // sla_prints.select_preset_by_name_strict(initial_sla_print_profile_name); // sla_materials.select_preset_by_name_strict(initial_sla_material_profile_name); // Load the names of the other filament profiles selected for a multi-material printer. // Load it even if the current printer technology is SLA. // The possibly excessive filament names will be later removed with this->update_multi_material_filament_presets() // once the FFF technology gets selected. - this->filament_presets = {filaments.get_selected_preset_name()}; - for (unsigned int i = 1; i < 1000; ++i) { + this->filament_presets = { filaments.get_selected_preset_name() }; + for (unsigned int i = 1; i < 1000; ++ i) { char name[64]; sprintf(name, "filament_%02u", i); auto f_name = config.get_printer_setting(initial_printer_profile_name, name); @@ -3074,18 +2999,14 @@ void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& p std::vector multi_filament_colors; if (config.has_printer_setting(initial_printer_profile_name, "filament_multi_colors")) { - boost::algorithm::split(multi_filament_colors, config.get_printer_setting(initial_printer_profile_name, "filament_multi_colors"), - boost::algorithm::is_any_of(",")); + boost::algorithm::split(multi_filament_colors, config.get_printer_setting(initial_printer_profile_name, "filament_multi_colors"), boost::algorithm::is_any_of(",")); } - if (multi_filament_colors.size() == 0) - project_config.option("filament_multi_colour")->values = filament_colors; - else - project_config.option("filament_multi_colour")->values = multi_filament_colors; + if (multi_filament_colors.size() == 0) project_config.option("filament_multi_colour")->values = filament_colors; + else project_config.option("filament_multi_colour")->values = multi_filament_colors; std::vector filament_color_types; if (config.has_printer_setting(initial_printer_profile_name, "filament_color_types")) { - boost::algorithm::split(filament_color_types, config.get_printer_setting(initial_printer_profile_name, "filament_color_types"), - boost::algorithm::is_any_of(",")); + boost::algorithm::split(filament_color_types, config.get_printer_setting(initial_printer_profile_name, "filament_color_types"), boost::algorithm::is_any_of(",")); } filament_color_types.resize(filament_presets.size(), "1"); project_config.option("filament_colour_type")->values = filament_color_types; @@ -3101,32 +3022,25 @@ void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& p std::vector extruder_ams_count_str; if (config.has_printer_setting(initial_printer_profile_name, "extruder_ams_count")) { - boost::algorithm::split(extruder_ams_count_str, config.get_printer_setting(initial_printer_profile_name, "extruder_ams_count"), - boost::algorithm::is_any_of(",")); + boost::algorithm::split(extruder_ams_count_str, config.get_printer_setting(initial_printer_profile_name, "extruder_ams_count"), boost::algorithm::is_any_of(",")); } this->extruder_ams_counts = get_extruder_ams_count(extruder_ams_count_str); std::vector matrix; if (config.has_printer_setting(initial_printer_profile_name, "flush_volumes_matrix")) { - boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_volumes_matrix"), - boost::algorithm::is_any_of("|")); + boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_volumes_matrix"), boost::algorithm::is_any_of("|")); auto flush_volumes_matrix = matrix | boost::adaptors::transformed(boost::lexical_cast); - project_config.option("flush_volumes_matrix")->values = std::vector(flush_volumes_matrix.begin(), - flush_volumes_matrix.end()); + project_config.option("flush_volumes_matrix")->values = std::vector(flush_volumes_matrix.begin(), flush_volumes_matrix.end()); } if (config.has_printer_setting(initial_printer_profile_name, "flush_volumes_vector")) { - boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_volumes_vector"), - boost::algorithm::is_any_of("|")); + boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_volumes_vector"), boost::algorithm::is_any_of("|")); auto flush_volumes_vector = matrix | boost::adaptors::transformed(boost::lexical_cast); - project_config.option("flush_volumes_vector")->values = std::vector(flush_volumes_vector.begin(), - flush_volumes_vector.end()); + project_config.option("flush_volumes_vector")->values = std::vector(flush_volumes_vector.begin(), flush_volumes_vector.end()); } if (config.has_printer_setting(initial_printer_profile_name, "flush_multiplier")) { - boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_multiplier"), - boost::algorithm::is_any_of("|")); + boost::algorithm::split(matrix, config.get_printer_setting(initial_printer_profile_name, "flush_multiplier"), boost::algorithm::is_any_of("|")); auto flush_multipliers = matrix | boost::adaptors::transformed(boost::lexical_cast); - project_config.option("flush_multiplier")->values = std::vector(flush_multipliers.begin(), - flush_multipliers.end()); + project_config.option("flush_multiplier")->values = std::vector(flush_multipliers.begin(), flush_multipliers.end()); } load_mixed_filament_settings(project_config, config, initial_printer_profile_name, filament_presets.size(), true); @@ -3138,17 +3052,17 @@ void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& p this->update_multi_material_filament_presets(); if (initial_printer != nullptr && (preferred_printer == nullptr || initial_printer == preferred_printer)) { - // Don't run the following code, as we want to activate default filament / SLA material profiles when installing and selecting a new - // printer. Only run this code if just a filament / SLA material was installed by Config Wizard for an active Printer. + // Don't run the following code, as we want to activate default filament / SLA material profiles when installing and selecting a new printer. + // Only run this code if just a filament / SLA material was installed by Config Wizard for an active Printer. auto printer_technology = printers.get_selected_preset().printer_technology(); - if (printer_technology == ptFFF && !preferred_selection.filament.empty()) { + if (printer_technology == ptFFF && ! preferred_selection.filament.empty()) { std::string preferred_preset_name = get_preset_name_by_alias(Preset::Type::TYPE_FILAMENT, preferred_selection.filament); if (auto it = filaments.find_preset_internal(preferred_preset_name); - it != filaments.end() && (it->name == preferred_preset_name) && it->is_visible && it->is_compatible) { + it != filaments.end() && (it->name == preferred_preset_name ) && it->is_visible && it->is_compatible) { filaments.select_preset_by_name_strict(preferred_preset_name); this->filament_presets.front() = filaments.get_selected_preset_name(); } - } else if (printer_technology == ptSLA && !preferred_selection.sla_material.empty()) { + } else if (printer_technology == ptSLA && ! preferred_selection.sla_material.empty()) { std::string preferred_preset_name = get_preset_name_by_alias(Preset::Type::TYPE_SLA_MATERIAL, preferred_selection.sla_material); if (auto it = sla_materials.find_preset_internal(preferred_preset_name); it != sla_materials.end() && it->is_visible && it->is_compatible) @@ -3157,18 +3071,17 @@ void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& p } std::string first_visible_filament_name; - for (auto& fp : filament_presets) { + for (auto & fp : filament_presets) { // Orca: also match the ORCA_DEFAULT_FILAMENT_PLACEHOLDER placeholder — see update_selections. - if (auto it = filaments.find_preset_internal(fp); - fp == ORCA_DEFAULT_FILAMENT_PLACEHOLDER || it == filaments.end() || !it->is_visible || !it->is_compatible) { + if (auto it = filaments.find_preset_internal(fp); fp == ORCA_DEFAULT_FILAMENT_PLACEHOLDER || it == filaments.end() || !it->is_visible || !it->is_compatible) { if (first_visible_filament_name.empty()) first_visible_filament_name = filaments.first_compatible().name; fp = first_visible_filament_name; } } - const Preset& current_printer = printers.get_selected_preset(); - const Preset* base_printer = printers.get_preset_base(current_printer); + const Preset& current_printer = printers.get_selected_preset(); + const Preset* base_printer = printers.get_preset_base(current_printer); bool use_default_nozzle_volume_type = true; if (base_printer) { std::string prev_nozzle_volume_type = config.get_nozzle_volume_types_from_config(base_printer->name); @@ -3181,12 +3094,11 @@ void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& p } if (use_default_nozzle_volume_type) { - project_config.option("nozzle_volume_type")->values = - current_printer.config.option("default_nozzle_volume_type")->values; + project_config.option("nozzle_volume_type")->values = current_printer.config.option("default_nozzle_volume_type")->values; } else { // Orca: make sure `nozzle_volume_type` not shorter than `default_nozzle_volume_type`, otherwise we got array out of bound access // later in `Tab::switch_excluder` - auto& opt = project_config.option("nozzle_volume_type")->values; + auto& opt = project_config.option("nozzle_volume_type")->values; const auto& opt_default = current_printer.config.option("default_nozzle_volume_type")->values; while (opt.size() < opt_default.size()) { opt.emplace_back(opt_default[opt.size()]); @@ -3200,17 +3112,15 @@ void PresetBundle::load_selections(AppConfig& config, const PresetPreferences& p if (!initial_physical_printer_name.empty()) physical_printers.select_printer(initial_physical_printer_name); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": finished, preferred printer_model_id %1%") % preferred_selection.printer_model_id; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": finished, preferred printer_model_id %1%")%preferred_selection.printer_model_id; } // Export selections (current print, current filaments, current printer) into config.ini // BBS: change directories by design -void PresetBundle::export_selections(AppConfig& config) +void PresetBundle::export_selections(AppConfig &config) { - assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() >= 1); - // assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() > 1 || - // filaments.get_selected_preset_name() == filament_presets.front()); + assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() >= 1); + //assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() > 1 || filaments.get_selected_preset_name() == filament_presets.front()); config.clear_section("presets"); auto printer_name = printers.get_selected_preset_name(); config.set("presets", PRESET_PRINTER_NAME, printer_name); @@ -3227,7 +3137,7 @@ void PresetBundle::export_selections(AppConfig& config) config.clear_printer_settings(printer_name); config.set_printer_setting(printer_name, PRESET_PRINTER_NAME, printer_name); config.set_printer_setting(printer_name, PRESET_PRINT_NAME, prints.get_selected_preset_name()); - config.set_printer_setting(printer_name, PRESET_FILAMENT_NAME, filament_presets.front()); + config.set_printer_setting(printer_name, PRESET_FILAMENT_NAME, filament_presets.front()); config.set_printer_setting(printer_name, "curr_bed_type", config.get("curr_bed_type")); for (unsigned i = 1; i < filament_presets.size(); ++i) { char name[64]; @@ -3237,75 +3147,68 @@ void PresetBundle::export_selections(AppConfig& config) } // Load project config data into app config CNumericLocalesSetter locales_setter; - std::string filament_colors = boost::algorithm::join(project_config.option("filament_colour")->values, ","); + std::string filament_colors = boost::algorithm::join(project_config.option("filament_colour")->values, ","); config.set_printer_setting(printer_name, "filament_colors", filament_colors); // Load filament multi color data into app config - std::string filament_multi_colors = boost::algorithm::join(project_config.option("filament_multi_colour")->values, - ","); + std::string filament_multi_colors = boost::algorithm::join(project_config.option("filament_multi_colour")->values, ","); config.set_printer_setting(printer_name, "filament_multi_colors", filament_multi_colors); // Load filament color type data into app config - std::string filament_color_types = boost::algorithm::join(project_config.option("filament_colour_type")->values, - ","); + std::string filament_color_types = boost::algorithm::join(project_config.option("filament_colour_type")->values, ","); config.set_printer_setting(printer_name, "filament_color_types", filament_color_types); // Load ams counts data into app config - std::string extruder_ams_count_str = boost::algorithm::join(save_extruder_ams_count_to_string(this->extruder_ams_counts), ","); + std::string extruder_ams_count_str = boost::algorithm::join(save_extruder_ams_count_to_string(this->extruder_ams_counts), ","); config.set_printer_setting(printer_name, "extruder_ams_count", extruder_ams_count_str); std::string flush_volumes_matrix = boost::algorithm::join(project_config.option("flush_volumes_matrix")->values | - boost::adaptors::transformed( - static_cast(std::to_string)), - "|"); + boost::adaptors::transformed(static_cast(std::to_string)), + "|"); config.set_printer_setting(printer_name, "flush_volumes_matrix", flush_volumes_matrix); std::string flush_volumes_vector = boost::algorithm::join(project_config.option("flush_volumes_vector")->values | - boost::adaptors::transformed( - static_cast(std::to_string)), - "|"); + boost::adaptors::transformed(static_cast(std::to_string)), + "|"); config.set_printer_setting(printer_name, "flush_volumes_vector", flush_volumes_vector); + std::string flush_multiplier_str = boost::algorithm::join(project_config.option("flush_multiplier")->values | - boost::adaptors::transformed( - static_cast(std::to_string)), + boost::adaptors::transformed(static_cast(std::to_string)), "|"); config.set_printer_setting(printer_name, "flush_multiplier", flush_multiplier_str); // Mixed-color filament metadata goes into the per-printer snapshot next to the filament list // it indexes (see load_mixed_filament_settings). Bools are ','-joined and the component, ratio // and range strings '|'-joined; the gradient curve is escaped instead, as it contains '|'. - auto join_bools = [](const std::vector& vals) { + auto join_bools = [](const std::vector &vals) { std::string s; for (size_t i = 0; i < vals.size(); ++i) { - if (i > 0) - s += ","; + if (i > 0) s += ","; s += (vals[i] ? "1" : "0"); } return s; }; - if (auto* opt = project_config.option("filament_is_mixed")) + if (auto *opt = project_config.option("filament_is_mixed")) config.set_printer_setting(printer_name, "filament_is_mixed", join_bools(opt->values)); - if (auto* opt = project_config.option("filament_mixed_components")) + if (auto *opt = project_config.option("filament_mixed_components")) config.set_printer_setting(printer_name, "filament_mixed_components", boost::algorithm::join(opt->values, "|")); - if (auto* opt = project_config.option("filament_mixed_sublayer_ratios")) + if (auto *opt = project_config.option("filament_mixed_sublayer_ratios")) config.set_printer_setting(printer_name, "filament_mixed_sublayer_ratios", boost::algorithm::join(opt->values, "|")); - if (auto* opt = project_config.option("filament_mixed_gradient")) + if (auto *opt = project_config.option("filament_mixed_gradient")) config.set_printer_setting(printer_name, "filament_mixed_gradient", join_bools(opt->values)); - if (auto* opt = project_config.option("filament_mixed_gradient_range")) + if (auto *opt = project_config.option("filament_mixed_gradient_range")) config.set_printer_setting(printer_name, "filament_mixed_gradient_range", boost::algorithm::join(opt->values, "|")); - if (auto* opt = project_config.option("filament_mixed_gradient_curve")) + if (auto *opt = project_config.option("filament_mixed_gradient_curve")) config.set_printer_setting(printer_name, "filament_mixed_gradient_curve", escape_strings_cstyle(opt->values)); - if (auto* opt = project_config.option("filament_mixed_gradient_per_part")) + if (auto *opt = project_config.option("filament_mixed_gradient_per_part")) config.set_printer_setting(printer_name, "filament_mixed_gradient_per_part", join_bools(opt->values)); // BBS - // config.set("presets", "sla_print", sla_prints.get_selected_preset_name()); - // config.set("presets", "sla_material", sla_materials.get_selected_preset_name()); - // config.set("presets", "physical_printer", physical_printers.get_selected_full_printer_name()); - // BBS: add config related log - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": printer %1%, print %2%, filaments[0] %3% ") % printers.get_selected_preset_name() % - prints.get_selected_preset_name() % filament_presets[0]; + //config.set("presets", "sla_print", sla_prints.get_selected_preset_name()); + //config.set("presets", "sla_material", sla_materials.get_selected_preset_name()); + //config.set("presets", "physical_printer", physical_printers.get_selected_full_printer_name()); + //BBS: add config related log + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1%, print %2%, filaments[0] %3% ")%printers.get_selected_preset_name() % prints.get_selected_preset_name() %filament_presets[0]; } void PresetBundle::set_num_filaments(unsigned int n, std::string new_color) @@ -3316,12 +3219,12 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color) else { filament_presets.resize(n); } - ConfigOptionStrings* filament_color = project_config.option("filament_colour"); - ConfigOptionStrings* filament_multi_color = project_config.option("filament_multi_colour"); - ConfigOptionStrings* filament_color_type = project_config.option("filament_colour_type"); - ConfigOptionInts* filament_map = project_config.option("filament_map"); - ConfigOptionInts* filament_nozzle_map = project_config.option("filament_nozzle_map"); - ConfigOptionInts* filament_volume_map = project_config.option("filament_volume_map"); + ConfigOptionStrings* filament_color = project_config.option("filament_colour"); + ConfigOptionStrings *filament_multi_color = project_config.option("filament_multi_colour"); + ConfigOptionStrings* filament_color_type = project_config.option("filament_colour_type"); + ConfigOptionInts* filament_map = project_config.option("filament_map"); + ConfigOptionInts* filament_nozzle_map = project_config.option("filament_nozzle_map"); + ConfigOptionInts* filament_volume_map = project_config.option("filament_volume_map"); // Which slots are new is a fact about the arrays below, not about filament_presets: // update_multi_material_filament_presets() tops that list up to the nozzle count on its own, @@ -3357,12 +3260,12 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color) if (auto* opt = project_config.option("filament_mixed_gradient_per_part")) opt->values.resize(n, false); - // BBS set new filament color to new_color + //BBS set new filament color to new_color if (!new_color.empty()) { for (size_t i = old_slot_count; i < n; i++) { - filament_color->values[i] = new_color; + filament_color->values[i] = new_color; filament_multi_color->values[i] = new_color; - filament_color_type->values[i] = "1"; // default color type + filament_color_type->values[i] = "1"; // default color type } } @@ -3377,8 +3280,8 @@ void PresetBundle::update_num_filaments(unsigned int to_del_flament_id) // update edited_preset { - Preset& edited_preset = filaments.get_edited_preset(); - bool edited_preset_deleted = true; + Preset& edited_preset = filaments.get_edited_preset(); + bool edited_preset_deleted = true; for (std::string filament_preset_name : filament_presets) { if (filament_preset_name == edited_preset.name) { edited_preset_deleted = false; @@ -3389,12 +3292,12 @@ void PresetBundle::update_num_filaments(unsigned int to_del_flament_id) } } - ConfigOptionStrings* filament_color = project_config.option("filament_colour"); - ConfigOptionStrings* filament_multi_color = project_config.option("filament_multi_colour"); - ConfigOptionStrings* filament_color_type = project_config.option("filament_colour_type"); - ConfigOptionInts* filament_map = project_config.option("filament_map"); - ConfigOptionInts* filament_nozzle_map = project_config.option("filament_nozzle_map"); - ConfigOptionInts* filament_volume_map = project_config.option("filament_volume_map"); + ConfigOptionStrings *filament_color = project_config.option("filament_colour"); + ConfigOptionStrings *filament_multi_color = project_config.option("filament_multi_colour"); + ConfigOptionStrings *filament_color_type = project_config.option("filament_colour_type"); + ConfigOptionInts* filament_map = project_config.option("filament_map"); + ConfigOptionInts* filament_nozzle_map = project_config.option("filament_nozzle_map"); + ConfigOptionInts* filament_volume_map = project_config.option("filament_volume_map"); if (filament_color->values.size() > to_del_flament_id) { filament_color->values.erase(filament_color->values.begin() + to_del_flament_id); if (filament_map->values.size() > to_del_flament_id) { @@ -3406,7 +3309,8 @@ void PresetBundle::update_num_filaments(unsigned int to_del_flament_id) if (filament_volume_map->values.size() > to_del_flament_id) { filament_volume_map->values.erase(filament_volume_map->values.begin() + to_del_flament_id); } - } else { + } + else { filament_color->values.resize(to_del_flament_id); filament_map->values.resize(to_del_flament_id, 1); filament_nozzle_map->values.resize(to_del_flament_id, 0); @@ -3430,27 +3334,29 @@ void PresetBundle::update_num_filaments(unsigned int to_del_flament_id) // *physical* filament must be remapped out of every mix before the arrays themselves shrink. // Deleting a mixed slot needs no remap (nothing references a mixed slot as a component). { - auto* is_mixed_opt = project_config.option("filament_is_mixed"); - auto* comp_opt = project_config.option("filament_mixed_components"); + auto *is_mixed_opt = project_config.option("filament_is_mixed"); + auto *comp_opt = project_config.option("filament_mixed_components"); if (is_mixed_opt && comp_opt) { - bool del_is_physical = (to_del_flament_id >= is_mixed_opt->values.size() || !is_mixed_opt->values[to_del_flament_id]); + bool del_is_physical = (to_del_flament_id >= is_mixed_opt->values.size() + || !is_mixed_opt->values[to_del_flament_id]); if (del_is_physical) - remap_mixed_components_on_delete(is_mixed_opt->values, comp_opt->values, to_del_flament_id + 1); + remap_mixed_components_on_delete(is_mixed_opt->values, comp_opt->values, + to_del_flament_id + 1); } if (is_mixed_opt) erase_or_resize(is_mixed_opt->values); if (comp_opt) erase_or_resize(comp_opt->values); } - if (auto* opt = project_config.option("filament_mixed_sublayer_ratios")) + if (auto *opt = project_config.option("filament_mixed_sublayer_ratios")) erase_or_resize(opt->values); - if (auto* opt = project_config.option("filament_mixed_gradient")) + if (auto *opt = project_config.option("filament_mixed_gradient")) erase_or_resize(opt->values); - if (auto* opt = project_config.option("filament_mixed_gradient_range")) + if (auto *opt = project_config.option("filament_mixed_gradient_range")) erase_or_resize(opt->values); - if (auto* opt = project_config.option("filament_mixed_gradient_curve")) + if (auto *opt = project_config.option("filament_mixed_gradient_curve")) erase_or_resize(opt->values); - if (auto* opt = project_config.option("filament_mixed_gradient_per_part")) + if (auto *opt = project_config.option("filament_mixed_gradient_per_part")) erase_or_resize(opt->values); update_multi_material_filament_presets(to_del_flament_id); @@ -3458,13 +3364,13 @@ void PresetBundle::update_num_filaments(unsigned int to_del_flament_id) bool PresetBundle::is_mixed_filament(size_t idx) const { - auto* opt = project_config.option("filament_is_mixed"); + auto *opt = project_config.option("filament_is_mixed"); return opt && idx < opt->values.size() && opt->values[idx]; } size_t PresetBundle::num_mixed_filaments() const { - auto* opt = project_config.option("filament_is_mixed"); + auto *opt = project_config.option("filament_is_mixed"); return opt == nullptr ? 0 : size_t(std::count(opt->values.begin(), opt->values.end(), true)); } @@ -3487,16 +3393,17 @@ std::vector PresetBundle::physical_filament_config_indices() const return indices; } + void PresetBundle::get_ams_cobox_infos(AMSComboInfo& combox_info) { combox_info.clear(); - for (auto& entry : filament_ams_list) { - auto& ams = entry.second; - auto filament_id = ams.opt_string("filament_id", 0u); - auto filament_color = ams.opt_string("filament_colour", 0u); - auto ams_name = ams.opt_string("tray_name", 0u); - auto filament_changed = !ams.has("filament_changed") || ams.opt_bool("filament_changed"); - auto filament_multi_color = ams.opt("filament_multi_colour")->values; + for (auto &entry : filament_ams_list) { + auto &ams = entry.second; + auto filament_id = ams.opt_string("filament_id", 0u); + auto filament_color = ams.opt_string("filament_colour", 0u); + auto ams_name = ams.opt_string("tray_name", 0u); + auto filament_changed = !ams.has("filament_changed") || ams.opt_bool("filament_changed"); + auto filament_multi_color = ams.opt("filament_multi_colour")->values; if (filament_id.empty()) { continue; } @@ -3507,18 +3414,15 @@ void PresetBundle::get_ams_cobox_infos(AMSComboInfo& combox_info) combox_info.ams_names.push_back(ams_name); continue; } - auto iter = std::find_if(filaments.begin(), filaments.end(), [this, &filament_id](auto& f) { - return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == filament_id; - }); + auto iter = std::find_if(filaments.begin(), filaments.end(), + [this, &filament_id](auto &f) { return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == filament_id; }); if (iter == filaments.end()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format(": filament_id %1% not found or system or compatible") % filament_id; + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id; auto filament_type = ams.opt_string("filament_type", 0u); if (!filament_type.empty()) { filament_type = "Generic " + filament_type; - iter = std::find_if(filaments.begin(), filaments.end(), [&filament_type](auto& f) { - return f.is_compatible && f.is_system && boost::algorithm::starts_with(f.name, filament_type); - }); + iter = std::find_if(filaments.begin(), filaments.end(), + [&filament_type](auto &f) { return f.is_compatible && f.is_system && boost::algorithm::starts_with(f.name, filament_type); }); } if (iter == filaments.end()) { // Prefer old selection @@ -3542,18 +3446,13 @@ void PresetBundle::get_ams_cobox_infos(AMSComboInfo& combox_info) } } -unsigned int PresetBundle::sync_ams_list(std::vector>& unknowns, - bool use_map, - std::map& maps, - bool enable_append, - MergeFilamentInfo& merge_info, - bool color_only) +unsigned int PresetBundle::sync_ams_list(std::vector> &unknowns, bool use_map, std::map &maps, bool enable_append, MergeFilamentInfo &merge_info, bool color_only) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "use_map:" << use_map << " enable_append:" << enable_append; std::vector ams_filament_presets; std::vector ams_filament_colors; std::vector ams_filament_color_types; - std::vector ams_array_maps; + std::vector ams_array_maps; ams_multi_color_filment.clear(); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": filament_ams_list size: %1%") % filament_ams_list.size(); struct AmsInfo @@ -3561,24 +3460,24 @@ unsigned int PresetBundle::sync_ams_list(std::vector mutli_filament_color; }; auto is_double_extruder = get_printer_extruder_count() == 2; std::vector ams_infos; - int index = 0; - for (auto& entry : filament_ams_list) { - auto& ams = entry.second; - auto filament_id = ams.opt_string("filament_id", 0u); - auto filament_color = ams.opt_string("filament_colour", 0u); - auto filament_color_type = ams.opt_string("filament_colour_type", 0u); - auto filament_changed = !ams.has("filament_changed") || ams.opt_bool("filament_changed"); + int index = 0; + for (auto &entry : filament_ams_list) { + auto & ams = entry.second; + auto filament_id = ams.opt_string("filament_id", 0u); + auto filament_color = ams.opt_string("filament_colour", 0u); + auto filament_color_type = ams.opt_string("filament_colour_type", 0u); + auto filament_changed = !ams.has("filament_changed") || ams.opt_bool("filament_changed"); auto filament_multi_color = ams.opt("filament_multi_colour")->values; - auto ams_id = ams.opt_string("ams_id", 0u); - auto slot_id = ams.opt_string("slot_id", 0u); - auto is_placeholder = ams.has("filament_slot_placeholder") && ams.opt_bool("filament_slot_placeholder", 0u); + auto ams_id = ams.opt_string("ams_id", 0u); + auto slot_id = ams.opt_string("slot_id", 0u); + auto is_placeholder = ams.has("filament_slot_placeholder") && ams.opt_bool("filament_slot_placeholder", 0u); ams_infos.push_back({filament_id.empty() ? false : true, false, is_placeholder, filament_color}); AMSMapInfo temp = {ams_id, slot_id}; ams_array_maps.push_back(temp); @@ -3590,7 +3489,7 @@ unsigned int PresetBundle::sync_ams_list(std::vectorconfig.opt_string("filament_type", 0u)); if (preset_type.size() > best_len && contains_word(upper_type, preset_type)) { - iter = it; - best_len = preset_type.size(); + iter = it; + best_len = preset_type.size(); filament_type = "Generic " + it->config.opt_string("filament_type", 0u); } } @@ -3665,28 +3564,26 @@ unsigned int PresetBundle::sync_ams_list(std::vectorname, filament_type) ? - (has_type ? - L("The filament may not be compatible with the current machine settings. Generic filament presets will be used.") : - L("The filament model is unknown. Generic filament presets will be used.")) : - (has_type ? - L("The filament may not be compatible with the current machine settings. A random filament preset will be used.") : - L("The filament model is unknown. A random filament preset will be used."))); + unknowns.emplace_back(&ams, boost::algorithm::starts_with(iter->name, filament_type) ? + (has_type ? L("The filament may not be compatible with the current machine settings. Generic filament presets will be used.") : + L("The filament model is unknown. Generic filament presets will be used.")) : + (has_type ? L("The filament may not be compatible with the current machine settings. A random filament preset will be used.") : + L("The filament model is unknown. A random filament preset will be used."))); filament_id = iter->filament_id; } ams_filament_presets.push_back(iter->name); @@ -3697,26 +3594,25 @@ unsigned int PresetBundle::sync_ams_list(std::vector("filament_colour"); - ConfigOptionStrings* filament_color_type = project_config.option("filament_colour_type"); - ConfigOptionInts* filament_map = project_config.option("filament_map"); - ConfigOptionInts* filament_volume_map = project_config.option("filament_volume_map"); + ConfigOptionStrings *filament_color = project_config.option("filament_colour"); + ConfigOptionStrings *filament_color_type = project_config.option("filament_colour_type"); + ConfigOptionInts * filament_map = project_config.option("filament_map"); + ConfigOptionInts * filament_volume_map = project_config.option("filament_volume_map"); // Snapshot and temporarily strip mixed filament slots so AMS sync operates on physical // filaments only. A mixed slot is virtual and has no tray to sync against; leaving it in // would let AMS mapping overwrite it and would break the physical-first slot ordering the // rest of the feature relies on. The slots are re-appended verbatim after the sync. - struct MixedSlotSnapshot - { + struct MixedSlotSnapshot { std::string preset; std::string color; std::string color_type; std::string mixed_components; std::string mixed_sublayer_ratios; - bool mixed_gradient = false; + bool mixed_gradient = false; std::string mixed_gradient_range; std::string mixed_gradient_curve; - bool mixed_gradient_per_part = false; + bool mixed_gradient_per_part = false; }; std::vector mixed_snapshots; auto* is_mixed_opt = project_config.option("filament_is_mixed"); @@ -3732,48 +3628,35 @@ unsigned int PresetBundle::sync_ams_list(std::vectorfilament_presets[i]; - snap.color = (i < filament_color->values.size()) ? filament_color->values[i] : ""; + snap.color = (i < filament_color->values.size()) ? filament_color->values[i] : ""; snap.color_type = (i < filament_color_type->values.size()) ? filament_color_type->values[i] : ""; - if (mixed_comp_opt && i < mixed_comp_opt->values.size()) - snap.mixed_components = mixed_comp_opt->values[i]; - if (mixed_ratios_opt && i < mixed_ratios_opt->values.size()) - snap.mixed_sublayer_ratios = mixed_ratios_opt->values[i]; - if (mixed_gradient_opt && i < mixed_gradient_opt->values.size()) - snap.mixed_gradient = mixed_gradient_opt->values[i]; - if (mixed_grad_range_opt && i < mixed_grad_range_opt->values.size()) - snap.mixed_gradient_range = mixed_grad_range_opt->values[i]; - if (mixed_grad_curve_opt && i < mixed_grad_curve_opt->values.size()) - snap.mixed_gradient_curve = mixed_grad_curve_opt->values[i]; - if (mixed_per_part_opt && i < mixed_per_part_opt->values.size()) - snap.mixed_gradient_per_part = mixed_per_part_opt->values[i]; + if (mixed_comp_opt && i < mixed_comp_opt->values.size()) snap.mixed_components = mixed_comp_opt->values[i]; + if (mixed_ratios_opt && i < mixed_ratios_opt->values.size()) snap.mixed_sublayer_ratios = mixed_ratios_opt->values[i]; + if (mixed_gradient_opt && i < mixed_gradient_opt->values.size()) snap.mixed_gradient = mixed_gradient_opt->values[i]; + if (mixed_grad_range_opt && i < mixed_grad_range_opt->values.size()) snap.mixed_gradient_range = mixed_grad_range_opt->values[i]; + if (mixed_grad_curve_opt && i < mixed_grad_curve_opt->values.size()) snap.mixed_gradient_curve = mixed_grad_curve_opt->values[i]; + if (mixed_per_part_opt && i < mixed_per_part_opt->values.size()) snap.mixed_gradient_per_part = mixed_per_part_opt->values[i]; mixed_snapshots.push_back(snap); } if (!mixed_snapshots.empty()) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": stripping " << mixed_snapshots.size() - << " mixed filament slot(s) before AMS sync"; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": stripping " << mixed_snapshots.size() << " mixed filament slot(s) before AMS sync"; size_t phys_count = this->filament_presets.size() - mixed_snapshots.size(); this->filament_presets.resize(phys_count); filament_color->values.resize(phys_count); filament_color_type->values.resize(phys_count); filament_map->values.resize(phys_count, 1); is_mixed_opt->values.resize(phys_count); - if (mixed_comp_opt) - mixed_comp_opt->values.resize(phys_count); - if (mixed_ratios_opt) - mixed_ratios_opt->values.resize(phys_count); - if (mixed_gradient_opt) - mixed_gradient_opt->values.resize(phys_count); - if (mixed_grad_range_opt) - mixed_grad_range_opt->values.resize(phys_count); - if (mixed_grad_curve_opt) - mixed_grad_curve_opt->values.resize(phys_count); - if (mixed_per_part_opt) - mixed_per_part_opt->values.resize(phys_count); + if (mixed_comp_opt) mixed_comp_opt->values.resize(phys_count); + if (mixed_ratios_opt) mixed_ratios_opt->values.resize(phys_count); + if (mixed_gradient_opt) mixed_gradient_opt->values.resize(phys_count); + if (mixed_grad_range_opt) mixed_grad_range_opt->values.resize(phys_count); + if (mixed_grad_curve_opt) mixed_grad_curve_opt->values.resize(phys_count); + if (mixed_per_part_opt) mixed_per_part_opt->values.resize(phys_count); } } if (color_only) { - auto get_map_index = [&ams_infos](const std::vector& infos, const AMSMapInfo& temp) { + auto get_map_index = [&ams_infos](const std::vector &infos, const AMSMapInfo &temp) { for (int i = 0; i < infos.size(); i++) { if (infos[i].slot_id == temp.slot_id && infos[i].ams_id == temp.ams_id) { ams_infos[i].is_map = true; @@ -3789,7 +3672,7 @@ unsigned int PresetBundle::sync_ams_list(std::vector("filament_multi_colour"); + ConfigOptionStrings *project_multi_color = project_config.option("filament_multi_colour"); if (project_multi_color) { for (size_t i = 0; i < std::min(exist_multi_color_filment.size(), project_multi_color->values.size()); i++) { std::vector colors = split_string(project_multi_color->values[i], ' '); @@ -3808,7 +3691,7 @@ unsigned int PresetBundle::sync_ams_list(std::vector= 0 && valid_index < int(ams_filament_colors.size()) && !ams_filament_colors[valid_index].empty()) { exist_colors[i] = ams_filament_colors[valid_index]; - mapped_any = true; + mapped_any = true; if (valid_index < int(ams_multi_color_filment.size()) && !ams_multi_color_filment[valid_index].empty()) { exist_multi_color_filment[i] = ams_multi_color_filment[valid_index]; } else { @@ -3833,11 +3716,11 @@ unsigned int PresetBundle::sync_ams_list(std::vectorvalues = exist_colors; + filament_color->values = exist_colors; ams_multi_color_filment = exist_multi_color_filment; merge_info.merges.clear(); } else if (use_map) { - auto check_has_merge_info = [](std::map& maps, MergeFilamentInfo& merge_info, int exist_colors_size) { + auto check_has_merge_info = [](std::map &maps, MergeFilamentInfo &merge_info, int exist_colors_size) { std::set done; for (auto it_i = maps.begin(); it_i != maps.end(); ++it_i) { std::vector same_ams; @@ -3846,7 +3729,7 @@ unsigned int PresetBundle::sync_ams_list(std::vectorfirst) != done.end()) { continue; } - if (it_i->second.slot_id == "" || it_i->second.ams_id == "") { + if (it_i->second.slot_id == "" || it_i->second.ams_id == ""){ continue; } if (it_i->second.slot_id == it_j->second.slot_id && it_i->second.ams_id == it_j->second.ams_id) { @@ -3859,8 +3742,8 @@ unsigned int PresetBundle::sync_ams_list(std::vectorvalues.size()); - auto get_map_index = [&ams_infos](const std::vector& infos, const AMSMapInfo& temp) { + check_has_merge_info(maps, merge_info,filament_color->values.size()); + auto get_map_index = [&ams_infos](const std::vector &infos, const AMSMapInfo &temp) { for (int i = 0; i < infos.size(); i++) { if (infos[i].slot_id == temp.slot_id && infos[i].ams_id == temp.ams_id) { ams_infos[i].is_map = true; @@ -3870,8 +3753,8 @@ unsigned int PresetBundle::sync_ams_list(std::vector need_append_colors; - auto exist_colors = filament_color->values; - auto exist_color_types = filament_color_type->values; + auto exist_colors = filament_color->values; + auto exist_color_types = filament_color_type->values; auto exist_filament_presets = this->filament_presets; std::vector> exist_multi_color_filment; exist_multi_color_filment.resize(exist_colors.size()); @@ -3879,57 +3762,54 @@ unsigned int PresetBundle::sync_ams_list(std::vector= 0 && valid_index < ams_filament_presets.size()) { - exist_colors[i] = ams_filament_colors[valid_index]; - exist_color_types[i] = ams_filament_color_types[valid_index]; - exist_filament_presets[i] = ams_filament_presets[valid_index]; + exist_colors[i] = ams_filament_colors[valid_index]; + exist_color_types[i] = ams_filament_color_types[valid_index]; + exist_filament_presets[i] = ams_filament_presets[valid_index]; exist_multi_color_filment[i] = ams_multi_color_filment[valid_index]; } else { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "check error: array bound (mapping exist)"; } } } - for (size_t i = 0; i < ams_infos.size(); i++) { // check append + for (size_t i = 0; i < ams_infos.size(); i++) {// check append if (ams_infos[i].valid) { if (i >= ams_filament_presets.size()) { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "check error: array bound (check append)"; continue; } - ams_infos[i].filament_preset = ams_filament_presets[i]; + ams_infos[i].filament_preset = ams_filament_presets[i]; ams_infos[i].mutli_filament_color = ams_multi_color_filment[i]; if (!ams_infos[i].is_map) { need_append_colors.emplace_back(ams_infos[i]); - ams_filament_colors[i] = ""; + ams_filament_colors[i] = ""; ams_filament_color_types[i] = ""; - ams_filament_presets[i] = ""; - ams_multi_color_filment[i] = std::vector(); + ams_filament_presets[i] = ""; + ams_multi_color_filment[i] = std::vector(); } - } else { - ams_filament_colors[i] = ""; + } + else { + ams_filament_colors[i] = ""; ams_filament_color_types[i] = ""; - ams_filament_presets[i] = ""; - ams_multi_color_filment[i] = std::vector(); + ams_filament_presets[i] = ""; + ams_multi_color_filment[i] = std::vector(); } } - // delete redundant color - ams_filament_colors.erase(std::remove_if(ams_filament_colors.begin(), ams_filament_colors.end(), - [](std::string& value) { return value.empty(); }), + //delete redundant color + ams_filament_colors.erase(std::remove_if(ams_filament_colors.begin(), ams_filament_colors.end(), [](std::string &value) { return value.empty(); }), ams_filament_colors.end()); - ams_filament_color_types.erase(std::remove_if(ams_filament_color_types.begin(), ams_filament_color_types.end(), - [](std::string& value) { return value.empty(); }), + ams_filament_color_types.erase(std::remove_if(ams_filament_color_types.begin(), ams_filament_color_types.end(), [](std::string &value) { return value.empty(); }), ams_filament_color_types.end()); - ams_filament_presets.erase(std::remove_if(ams_filament_presets.begin(), ams_filament_presets.end(), - [](std::string& value) { return value.empty(); }), + ams_filament_presets.erase(std::remove_if(ams_filament_presets.begin(), ams_filament_presets.end(), [](std::string &value) { return value.empty(); }), ams_filament_presets.end()); ams_multi_color_filment.erase(std::remove_if(ams_multi_color_filment.begin(), ams_multi_color_filment.end(), - [](std::vector& value) { return value.empty(); }), + [](std::vector &value) { return value.empty(); }), ams_multi_color_filment.end()); if (need_append_colors.size() > 0 && enable_append) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "need_append_colors.size() > 0 && enable_append"; - auto get_idx_in_array = [](std::vector& presets, std::vector& colors, const std::string& preset, - const std::string& color) -> int { + auto get_idx_in_array = [](std::vector &presets, std::vector &colors, const std::string &preset, const std::string &color) -> int { for (size_t i = 0; i < presets.size(); i++) { if (presets[i] == preset && colors[i] == color) { return i; @@ -3937,12 +3817,11 @@ unsigned int PresetBundle::sync_ams_list(std::vector= MAXIMUM_AMS_SYNC_FILAMENT_NUMBER) { + for (size_t i = 0; i < need_append_colors.size(); i++){ + if (exist_filament_presets.size() >= MAXIMUM_AMS_SYNC_FILAMENT_NUMBER){ break; } - auto idx = get_idx_in_array(exist_filament_presets, exist_colors, need_append_colors[i].filament_preset, - need_append_colors[i].filament_color); + auto idx = get_idx_in_array(exist_filament_presets, exist_colors, need_append_colors[i].filament_preset, need_append_colors[i].filament_color); if (idx >= 0) { continue; } @@ -3952,19 +3831,21 @@ unsigned int PresetBundle::sync_ams_list(std::vectorvalues = exist_colors; + filament_color->values = exist_colors; filament_color_type->values = exist_color_types; - ams_multi_color_filment = exist_multi_color_filment; - this->filament_presets = exist_filament_presets; + ams_multi_color_filment = exist_multi_color_filment; + this->filament_presets = exist_filament_presets; filament_map->values.resize(exist_filament_presets.size(), 1); filament_volume_map->values.resize(exist_filament_presets.size(), static_cast(NozzleVolumeType::nvtStandard)); - } else { // overwrite; - bool has_placeholders = std::any_of(ams_infos.begin(), ams_infos.end(), [](const AmsInfo& a) { return a.is_placeholder; }); + } + else {//overwrite; + bool has_placeholders = std::any_of(ams_infos.begin(), ams_infos.end(), + [](const AmsInfo& a) { return a.is_placeholder; }); if (has_placeholders) { // Orca: merge — keep existing filaments for empty slots - auto exist_colors = filament_color->values; - auto exist_color_types = filament_color_type->values; - auto exist_presets = this->filament_presets; + auto exist_colors = filament_color->values; + auto exist_color_types = filament_color_type->values; + auto exist_presets = this->filament_presets; size_t tray_count = ams_filament_presets.size(); size_t total = std::max(tray_count, exist_presets.size()); @@ -3982,8 +3863,9 @@ unsigned int PresetBundle::sync_ams_list(std::vector{ams_filament_colors[i]}); + result_multi_colors.push_back( + i < ams_multi_color_filment.size() ? ams_multi_color_filment[i] + : std::vector{ams_filament_colors[i]}); } else if (i < exist_presets.size()) { // Empty tray or beyond tray count: keep existing filament result_colors.push_back(exist_colors[i]); @@ -3992,8 +3874,9 @@ unsigned int PresetBundle::sync_ams_list(std::vectorname : filaments.first_visible().name; result_colors.push_back("#CECECE"); @@ -4011,15 +3894,15 @@ unsigned int PresetBundle::sync_ams_list(std::vectorvalues.resize(total, static_cast(NozzleVolumeType::nvtStandard)); } else { // BBL: existing wholesale replace - filament_color->values = ams_filament_colors; + filament_color->values = ams_filament_colors; filament_color_type->values = ams_filament_color_types; - this->filament_presets = ams_filament_presets; + this->filament_presets = ams_filament_presets; filament_map->values.resize(ams_filament_colors.size(), 1); filament_volume_map->values.resize(ams_filament_colors.size(), static_cast(NozzleVolumeType::nvtStandard)); } - auto& print_config = this->prints.get_edited_preset().config; - auto support_filament_opt = print_config.option("support_filament"); + auto& print_config = this->prints.get_edited_preset().config; + auto support_filament_opt = print_config.option("support_filament"); auto support_interface_filament_opt = print_config.option("support_interface_filament"); if (support_filament_opt->value > filament_color_type->values.size()) support_filament_opt->value = 0; @@ -4031,20 +3914,13 @@ unsigned int PresetBundle::sync_ams_list(std::vectorfilament_presets.size(); - if (is_mixed_opt) - is_mixed_opt->values.resize(new_phys_count, (unsigned char) false); - if (mixed_comp_opt) - mixed_comp_opt->values.resize(new_phys_count); - if (mixed_ratios_opt) - mixed_ratios_opt->values.resize(new_phys_count); - if (mixed_gradient_opt) - mixed_gradient_opt->values.resize(new_phys_count, (unsigned char) false); - if (mixed_grad_range_opt) - mixed_grad_range_opt->values.resize(new_phys_count); - if (mixed_grad_curve_opt) - mixed_grad_curve_opt->values.resize(new_phys_count); - if (mixed_per_part_opt) - mixed_per_part_opt->values.resize(new_phys_count, (unsigned char) false); + if (is_mixed_opt) is_mixed_opt->values.resize(new_phys_count, (unsigned char)false); + if (mixed_comp_opt) mixed_comp_opt->values.resize(new_phys_count); + if (mixed_ratios_opt) mixed_ratios_opt->values.resize(new_phys_count); + if (mixed_gradient_opt) mixed_gradient_opt->values.resize(new_phys_count, (unsigned char)false); + if (mixed_grad_range_opt) mixed_grad_range_opt->values.resize(new_phys_count); + if (mixed_grad_curve_opt) mixed_grad_curve_opt->values.resize(new_phys_count); + if (mixed_per_part_opt) mixed_per_part_opt->values.resize(new_phys_count, (unsigned char)false); for (auto& snap : mixed_snapshots) { this->filament_presets.push_back(snap.preset); @@ -4052,20 +3928,13 @@ unsigned int PresetBundle::sync_ams_list(std::vectorvalues.push_back(snap.color_type); ams_multi_color_filment.push_back({snap.color}); filament_map->values.push_back(1); - if (is_mixed_opt) - is_mixed_opt->values.push_back((unsigned char) true); - if (mixed_comp_opt) - mixed_comp_opt->values.push_back(snap.mixed_components); - if (mixed_ratios_opt) - mixed_ratios_opt->values.push_back(snap.mixed_sublayer_ratios); - if (mixed_gradient_opt) - mixed_gradient_opt->values.push_back((unsigned char) snap.mixed_gradient); - if (mixed_grad_range_opt) - mixed_grad_range_opt->values.push_back(snap.mixed_gradient_range); - if (mixed_grad_curve_opt) - mixed_grad_curve_opt->values.push_back(snap.mixed_gradient_curve); - if (mixed_per_part_opt) - mixed_per_part_opt->values.push_back((unsigned char) snap.mixed_gradient_per_part); + if (is_mixed_opt) is_mixed_opt->values.push_back((unsigned char)true); + if (mixed_comp_opt) mixed_comp_opt->values.push_back(snap.mixed_components); + if (mixed_ratios_opt) mixed_ratios_opt->values.push_back(snap.mixed_sublayer_ratios); + if (mixed_gradient_opt) mixed_gradient_opt->values.push_back((unsigned char)snap.mixed_gradient); + if (mixed_grad_range_opt) mixed_grad_range_opt->values.push_back(snap.mixed_gradient_range); + if (mixed_grad_curve_opt) mixed_grad_curve_opt->values.push_back(snap.mixed_gradient_curve); + if (mixed_per_part_opt) mixed_per_part_opt->values.push_back((unsigned char)snap.mixed_gradient_per_part); } } @@ -4079,38 +3948,36 @@ unsigned int PresetBundle::sync_ams_list(std::vector exsit_multi_colors; - for (auto& fil_item : ams_multi_color_filment) { - if (fil_item.empty()) - break; + for (auto &fil_item : ams_multi_color_filment){ + if (fil_item.empty()) break; if (fil_item.size() == 1) exsit_multi_colors.push_back(fil_item[0]); else { std::string colors = ""; - for (auto& color : fil_item) { - colors += color + " "; + for (auto &color : fil_item){ + colors += color + " "; } colors.erase(colors.size() - 1); // remove last space exsit_multi_colors.push_back(colors); } } - ConfigOptionStrings* filament_multi_colour = project_config.option("filament_multi_colour"); + ConfigOptionStrings *filament_multi_colour = project_config.option("filament_multi_colour"); filament_multi_colour->resize(exsit_multi_colors.size()); filament_multi_colour->values = exsit_multi_colors; } -std::vector PresetBundle::get_used_tpu_filaments(const std::vector& used_filaments) +std::vector PresetBundle::get_used_tpu_filaments(const std::vector &used_filaments) { std::vector tpu_filaments; for (size_t i = 0; i < this->filament_presets.size(); ++i) { auto iter = std::find(used_filaments.begin(), used_filaments.end(), i + 1); - if (iter == used_filaments.end()) - continue; + if (iter == used_filaments.end()) continue; std::string filament_name = this->filament_presets[i]; for (int f_index = 0; f_index < this->filaments.size(); f_index++) { - PresetCollection* filament_presets = &this->filaments; - Preset* preset = &filament_presets->preset(f_index); - int size = this->filaments.size(); + PresetCollection *filament_presets = &this->filaments; + Preset *preset = &filament_presets->preset(f_index); + int size = this->filaments.size(); if (preset && filament_name.compare(preset->name) == 0) { std::string display_filament_type; std::string filament_type = preset->config.get_filament_type(display_filament_type); @@ -4131,20 +3998,18 @@ void PresetBundle::set_calibrate_printer(std::string name) } if (!name.empty()) calibrate_printer = printers.find_preset(name); - const Preset& printer_preset = calibrate_printer ? *calibrate_printer : printers.get_edited_preset(); + const Preset & printer_preset = calibrate_printer ? *calibrate_printer : printers.get_edited_preset(); const PresetWithVendorProfile active_printer = printers.get_preset_with_vendor_profile(printer_preset); - DynamicPrintConfig config; + DynamicPrintConfig config; config.set_key_value("printer_preset", new ConfigOptionString(active_printer.preset.name)); - const ConfigOption* opt = active_printer.preset.config.option("nozzle_diameter"); - if (opt) - config.set_key_value("num_extruders", new ConfigOptionInt((int) static_cast(opt)->values.size())); + const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter"); + if (opt) config.set_key_value("num_extruders", new ConfigOptionInt((int) static_cast(opt)->values.size())); calibrate_filaments.clear(); for (size_t i = filaments.num_default_presets(); i < filaments.size(); ++i) { - const Preset& preset = filaments.m_presets[i]; + const Preset & preset = filaments.m_presets[i]; const PresetWithVendorProfile this_preset_with_vendor_profile = filaments.get_preset_with_vendor_profile(preset); - bool is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config); - if (is_compatible) - calibrate_filaments.insert(&preset); + bool is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config); + if (is_compatible) calibrate_filaments.insert(&preset); } } @@ -4165,31 +4030,25 @@ std::vector> PresetBundle::get_extruder_filament return filament_infos; } -std::set PresetBundle::get_printer_names_by_printer_type_and_nozzle(const std::string& printer_type, - std::string nozzle_diameter_str, - bool system_only) +std::set PresetBundle::get_printer_names_by_printer_type_and_nozzle(const std::string &printer_type, std::string nozzle_diameter_str, bool system_only) { std::set printer_names; if ("0.0" == nozzle_diameter_str || nozzle_diameter_str.empty()) { nozzle_diameter_str = "0.4"; } - std::ostringstream stream; + std::ostringstream stream; for (auto printer_it = this->printers.begin(); printer_it != this->printers.end(); printer_it++) { - if (system_only && !printer_it->is_system) - continue; + if (system_only && !printer_it->is_system) continue; - ConfigOption* printer_model_opt = printer_it->config.option("printer_model"); - ConfigOptionString* printer_model_str = dynamic_cast(printer_model_opt); - if (!printer_model_str) - continue; + ConfigOption * printer_model_opt = printer_it->config.option("printer_model"); + ConfigOptionString *printer_model_str = dynamic_cast(printer_model_opt); + if (!printer_model_str) continue; // use printer_model as printer type - if (printer_model_str->value != printer_type) - continue; + if (printer_model_str->value != printer_type) continue; - if (printer_it->name.find(nozzle_diameter_str) != std::string::npos) - printer_names.insert(printer_it->name); + if (printer_it->name.find(nozzle_diameter_str) != std::string::npos) printer_names.insert(printer_it->name); } assert(printer_names.size() == 1); @@ -4201,40 +4060,32 @@ std::set PresetBundle::get_printer_names_by_printer_type_and_nozzle return printer_names; } -bool PresetBundle::check_filament_temp_equation_by_printer_type_and_nozzle_for_mas_tray(const std::string& printer_type, - std::string& nozzle_diameter_str, - std::string& setting_id, - std::string& tag_uid, - std::string& nozzle_temp_min, - std::string& nozzle_temp_max, - std::string& preset_setting_id) +bool PresetBundle::check_filament_temp_equation_by_printer_type_and_nozzle_for_mas_tray( + const std::string &printer_type, std::string& nozzle_diameter_str, std::string &setting_id, std::string &tag_uid, std::string &nozzle_temp_min, std::string &nozzle_temp_max, std::string& preset_setting_id) { bool is_equation = true; - std::map> filament_list = filaments.get_filament_presets(); - std::set printer_names = get_printer_names_by_printer_type_and_nozzle(printer_type, nozzle_diameter_str); + std::map> filament_list = filaments.get_filament_presets(); + std::set printer_names = get_printer_names_by_printer_type_and_nozzle(printer_type, nozzle_diameter_str); - for (const Preset* preset : filament_list.find(setting_id)->second) { - if (tag_uid == "0" || (tag_uid.size() == 16 && tag_uid.substr(12, 2) == "01")) - continue; - if (preset && !preset->is_user()) - continue; - ConfigOption* printer_opt = const_cast(preset)->config.option("compatible_printers"); - ConfigOptionStrings* printer_strs = dynamic_cast(printer_opt); - bool compared = false; - for (const std::string& printer_str : printer_strs->values) { + for (const Preset *preset : filament_list.find(setting_id)->second) { + if (tag_uid == "0" || (tag_uid.size() == 16 && tag_uid.substr(12, 2) == "01")) continue; + if (preset && !preset->is_user()) continue; + ConfigOption * printer_opt = const_cast(preset)->config.option("compatible_printers"); + ConfigOptionStrings *printer_strs = dynamic_cast(printer_opt); + bool compared = false; + for (const std::string &printer_str : printer_strs->values) { if (printer_names.find(printer_str) != printer_names.end()) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << "nozzle temp matching: preset name: " << preset->name - << " printer name: " << printer_str; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << "nozzle temp matching: preset name: " << preset->name << " printer name: " << printer_str; // Compare only once if (!compared) { - compared = true; - bool min_temp_equation = false, max_temp_equation = false; - int min_nozzle_temp = std::stoi(nozzle_temp_min); - int max_nozzle_temp = std::stoi(nozzle_temp_max); - ConfigOption* opt_min = const_cast(preset)->config.option("nozzle_temperature_range_low"); + compared = true; + bool min_temp_equation = false, max_temp_equation = false; + int min_nozzle_temp = std::stoi(nozzle_temp_min); + int max_nozzle_temp = std::stoi(nozzle_temp_max); + ConfigOption *opt_min = const_cast(preset)->config.option("nozzle_temperature_range_low"); if (opt_min) { - ConfigOptionInts* opt_min_ints = dynamic_cast(opt_min); + ConfigOptionInts *opt_min_ints = dynamic_cast(opt_min); min_nozzle_temp = opt_min_ints->get_at(0); if (std::to_string(min_nozzle_temp) == nozzle_temp_min) min_temp_equation = true; @@ -4243,9 +4094,9 @@ bool PresetBundle::check_filament_temp_equation_by_printer_type_and_nozzle_for_m nozzle_temp_min = std::to_string(min_nozzle_temp); } } - ConfigOption* opt_max = const_cast(preset)->config.option("nozzle_temperature_range_high"); + ConfigOption *opt_max = const_cast(preset)->config.option("nozzle_temperature_range_high"); if (opt_max) { - ConfigOptionInts* opt_max_ints = dynamic_cast(opt_max); + ConfigOptionInts *opt_max_ints = dynamic_cast(opt_max); max_nozzle_temp = opt_max_ints->get_at(0); if (std::to_string(max_nozzle_temp) == nozzle_temp_max) max_temp_equation = true; @@ -4255,13 +4106,11 @@ bool PresetBundle::check_filament_temp_equation_by_printer_type_and_nozzle_for_m } } if (min_temp_equation && max_temp_equation) { - BOOST_LOG_TRIVIAL(info) - << __FUNCTION__ << " " << __LINE__ << "Determine if the temperature has changed: no changed"; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << "Determine if the temperature has changed: no changed"; } else { - BOOST_LOG_TRIVIAL(info) - << __FUNCTION__ << " " << __LINE__ << "Determine if the temperature has changed: has changed"; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << "Determine if the temperature has changed: has changed"; preset_setting_id = preset->setting_id; - is_equation = false; + is_equation = false; } } else { assert(false); @@ -4272,7 +4121,7 @@ bool PresetBundle::check_filament_temp_equation_by_printer_type_and_nozzle_for_m return is_equation; } -Preset* PresetBundle::get_similar_printer_preset(std::string printer_model, std::string printer_variant) +Preset *PresetBundle::get_similar_printer_preset(std::string printer_model, std::string printer_variant) { if (printer_model.empty()) printer_model = printers.get_selected_preset().config.opt_string("printer_model"); @@ -4280,7 +4129,7 @@ Preset* PresetBundle::get_similar_printer_preset(std::string printer_model, std: return nullptr; auto printer_variant_old = printers.get_selected_preset().config.opt_string("printer_variant"); std::map printer_presets; - for (auto& preset : printers.m_presets) { + for (auto &preset : printers.m_presets) { if (printer_variant.empty() && !preset.is_system) continue; if (preset.config.opt_string("printer_model") == printer_model) @@ -4288,8 +4137,7 @@ Preset* PresetBundle::get_similar_printer_preset(std::string printer_model, std: } if (printer_presets.empty()) return nullptr; - auto prefer_printer = printers.get_selected_preset().alias; //.name ORCA use alias instead "name" for calling system presets. otherwise - // nozzle combo will not change printer presets if they custom named + auto prefer_printer = printers.get_selected_preset().alias; //.name ORCA use alias instead "name" for calling system presets. otherwise nozzle combo will not change printer presets if they custom named if (!printer_variant.empty()) boost::replace_all(prefer_printer, printer_variant_old, printer_variant); @@ -4307,29 +4155,30 @@ Preset* PresetBundle::get_similar_printer_preset(std::string printer_model, std: return printer_presets.begin()->second; } -// BBS: check whether this is the only edited filament +//BBS: check whether this is the only edited filament bool PresetBundle::is_the_only_edited_filament(unsigned int filament_index) { unsigned n = this->filament_presets.size(); if (filament_index >= n) return false; - std::string name = this->filament_presets[filament_index]; + std::string name = this->filament_presets[filament_index]; Preset& edited_preset = this->filaments.get_edited_preset(); if (edited_preset.name != name) return false; unsigned index = 0; - while (index < n) { + while (index < n) + { if (index == filament_index) { - index++; + index ++; continue; } std::string filament_preset = this->filament_presets[index]; if (edited_preset.name == filament_preset) return false; else - index++; + index ++; } return true; } @@ -4337,8 +4186,7 @@ bool PresetBundle::is_the_only_edited_filament(unsigned int filament_index) void PresetBundle::reset_default_nozzle_volume_type() { Preset& current_printer = this->printers.get_edited_preset(); - this->project_config.option("nozzle_volume_type")->values = - current_printer.config.option("default_nozzle_volume_type")->values; + this->project_config.option("nozzle_volume_type")->values = current_printer.config.option("default_nozzle_volume_type")->values; } int PresetBundle::get_printer_extruder_count() const @@ -4367,7 +4215,9 @@ void PresetBundle::update_filament_count() const size_t num_extruders = static_cast(get_printer_extruder_count()); if (filament_presets.size() >= num_extruders) return; - filament_presets.resize(num_extruders, filament_presets.empty() ? filaments.first_visible().name : filament_presets.back()); + filament_presets.resize(num_extruders, filament_presets.empty() + ? filaments.first_visible().name + : filament_presets.back()); } bool PresetBundle::support_different_extruders() const @@ -4386,7 +4236,8 @@ std::vector PresetBundle::get_default_nozzle_volume_types_for_filaments(std result.resize(filament_count, static_cast(NozzleVolumeType::nvtStandard)); auto opt_nozzle_volume_type = dynamic_cast(this->project_config.option("nozzle_volume_type")); - for (int index = 0; index < filament_count; index++) { + for (int index = 0; index < filament_count; index++) + { if (opt_nozzle_volume_type && opt_nozzle_volume_type->values.size() > (f_maps[index] - 1)) result[index] = opt_nozzle_volume_type->values[f_maps[index] - 1]; } @@ -4394,43 +4245,40 @@ std::vector PresetBundle::get_default_nozzle_volume_types_for_filaments(std return result; } -DynamicPrintConfig PresetBundle::full_config(bool apply_extruder, - std::optional> filament_maps, - std::optional> filament_volume_maps) const +DynamicPrintConfig PresetBundle::full_config(bool apply_extruder, std::optional>filament_maps, std::optional> filament_volume_maps) const { return (this->printers.get_edited_preset().printer_technology() == ptFFF) ? - this->full_fff_config(apply_extruder, filament_maps, filament_volume_maps) : - this->full_sla_config(); + this->full_fff_config(apply_extruder, filament_maps, filament_volume_maps) : + this->full_sla_config(); } -DynamicPrintConfig PresetBundle::full_config_secure(std::optional> filament_maps) const +DynamicPrintConfig PresetBundle::full_config_secure(std::optional>filament_maps) const { DynamicPrintConfig config = this->full_fff_config(false, filament_maps); - // FIXME legacy, the keys should not be there after conversion to a Physical Printer profile. + //FIXME legacy, the keys should not be there after conversion to a Physical Printer profile. config.erase("print_host"); config.erase("print_host_webui"); config.erase("printhost_apikey"); - config.erase("printhost_cafile"); - config.erase("printhost_user"); - config.erase("printhost_password"); + config.erase("printhost_cafile"); + config.erase("printhost_user"); + config.erase("printhost_password"); config.erase("printhost_port"); return config; } std::vector>> PresetBundle::get_full_flush_matrix(bool with_multiplier) const { - auto full_config = this->full_config(); - int extruder_nums = full_config.option("nozzle_diameter")->values.size(); + auto full_config = this->full_config(); + int extruder_nums = full_config.option("nozzle_diameter")->values.size(); std::vector flush_volume_value = full_config.option("flush_volumes_matrix")->values; - int filament_nums = full_config.option("filament_type")->values.size(); + int filament_nums = full_config.option("filament_type")->values.size(); std::vector>> matrix; for (size_t extruder_id = 0; extruder_id < extruder_nums; ++extruder_id) { - std::vector flush_matrix(cast(get_flush_volumes_matrix(flush_volume_value, extruder_id, extruder_nums))); + std::vector flush_matrix(cast(get_flush_volumes_matrix(flush_volume_value, extruder_id, extruder_nums))); std::vector> wipe_volumes; for (unsigned int i = 0; i < filament_nums; ++i) - wipe_volumes.push_back( - std::vector(flush_matrix.begin() + i * filament_nums, flush_matrix.begin() + (i + 1) * filament_nums)); + wipe_volumes.push_back(std::vector(flush_matrix.begin() + i * filament_nums, flush_matrix.begin() + (i + 1) * filament_nums)); matrix.emplace_back(wipe_volumes); } @@ -4438,9 +4286,9 @@ std::vector>> PresetBundle::get_full_flush_matrix if (with_multiplier) { // Fast purge mode uses flush_multiplier_fast; the default prime_volume_mode==Default // (or the key absent) reads flush_multiplier, so this is inert. - auto* mode_opt = project_config.option>("prime_volume_mode"); - const bool use_fast = mode_opt && mode_opt->value == PrimeVolumeMode::pvmFast; - auto* mult_opt = project_config.option(use_fast ? "flush_multiplier_fast" : "flush_multiplier"); + auto* mode_opt = project_config.option>("prime_volume_mode"); + const bool use_fast = mode_opt && mode_opt->value == PrimeVolumeMode::pvmFast; + auto* mult_opt = project_config.option(use_fast ? "flush_multiplier_fast" : "flush_multiplier"); auto flush_multiplies = mult_opt ? mult_opt->values : project_config.option("flush_multiplier")->values; flush_multiplies.resize(extruder_nums, 1); for (size_t extruder_id = 0; extruder_id < extruder_nums; ++extruder_id) { @@ -4454,38 +4302,41 @@ std::vector>> PresetBundle::get_full_flush_matrix return matrix; } -const std::set ignore_settings_list = {"inherits", "print_settings_id", "filament_settings_id", "printer_settings_id"}; +const std::set ignore_settings_list ={ + "inherits", + "print_settings_id", "filament_settings_id", "printer_settings_id" +}; -DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, - std::optional> filament_maps_new, - std::optional> filament_volume_maps_new) const +DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, std::optional> filament_maps_new, std::optional> filament_volume_maps_new) const { DynamicPrintConfig out; out.apply(FullPrintConfig::defaults()); out.apply(this->prints.get_edited_preset().config); // Add the default filament preset to have the "filament_preset_id" defined. - out.apply(this->filaments.default_preset().config); - out.apply(this->printers.get_edited_preset().config); + out.apply(this->filaments.default_preset().config); + out.apply(this->printers.get_edited_preset().config); out.apply(this->project_config); // BBS - size_t num_filaments = this->filament_presets.size(); + size_t num_filaments = this->filament_presets.size(); std::vector filament_maps = out.option("filament_map")->values; - std::vector filament_volume_maps(num_filaments, (int) nvtStandard); + std::vector filament_volume_maps(num_filaments, (int)nvtStandard); ConfigOptionInts* filament_volume_map_opt = out.option("filament_volume_map"); if (filament_maps_new.has_value()) filament_maps = *filament_maps_new; if (filament_volume_maps_new.has_value()) { - filament_volume_maps = *filament_volume_maps_new; + filament_volume_maps = *filament_volume_maps_new; out.option("filament_volume_map", true)->values = filament_volume_maps; - } else if (filament_volume_map_opt && filament_volume_map_opt->values.size() == num_filaments) + } + else if (filament_volume_map_opt && filament_volume_map_opt->values.size() == num_filaments) filament_volume_maps = filament_volume_map_opt->values; - // in some middle state, they may be different + //in some middle state, they may be different if (filament_maps.size() != num_filaments) { filament_maps.resize(num_filaments, 1); - } else { + } + else { assert(filament_maps.size() == num_filaments); } if (filament_volume_maps.size() != num_filaments) { @@ -4499,35 +4350,32 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, std::vector inherits; std::vector filament_ids; std::vector print_compatible_printers; - // BBS: add logic for settings check between different system presets + //BBS: add logic for settings check between different system presets std::vector different_settings; std::string different_print_settings, different_printer_settings; compatible_printers_condition.emplace_back(this->prints.get_edited_preset().compatible_printers_condition()); - const ConfigOptionStrings* compatible_printers = - (const_cast(this))->prints.get_edited_preset().config.option("compatible_printers", false); + const ConfigOptionStrings* compatible_printers = (const_cast(this))->prints.get_edited_preset().config.option("compatible_printers", false); if (compatible_printers) print_compatible_printers = compatible_printers->values; - // BBS: add logic for settings check between different system presets + //BBS: add logic for settings check between different system presets std::string print_inherits = this->prints.get_edited_preset().inherits(); - inherits.emplace_back(print_inherits); - const Preset* print_parent_preset = this->prints.get_selected_preset_parent(); + inherits .emplace_back(print_inherits); + const Preset* print_parent_preset = this->prints.get_selected_preset_parent(); if (print_parent_preset) { - std::vector dirty_options = this->prints.dirty_options_without_option_list(&(this->prints.get_edited_preset()), - print_parent_preset, ignore_settings_list, - false); + std::vector dirty_options = this->prints.dirty_options_without_option_list(&(this->prints.get_edited_preset()), print_parent_preset, ignore_settings_list, false); if (!dirty_options.empty()) { different_print_settings = Slic3r::escape_strings_cstyle(dirty_options); } } different_settings.emplace_back(different_print_settings); - // BBS: update printer config related with variants + //BBS: update printer config related with variants std::vector> nozzle_volume_types; int extruder_count = 1, extruder_volume_type_count = 1; bool different_extruder = false; if (apply_extruder) { - different_extruder = out.support_different_extruders(extruder_count); + different_extruder = out.support_different_extruders(extruder_count); extruder_volume_type_count = out.get_extruder_nozzle_volume_count(extruder_count, nozzle_volume_types); if ((extruder_count > 1) || different_extruder) { @@ -4539,40 +4387,33 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, // per variant (e.g. X2D machine_max_speed_e/machine_max_acceleration_e). The slicing // path composes variant_2 first and is unaffected; changing the order here would alter // long-standing composed values, so any fix must re-baseline them. - out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, - printer_options_with_variant_1, "printer_extruder_id", "printer_extruder_variant"); - out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, - printer_options_with_variant_2, "printer_extruder_id", "printer_extruder_variant", 2); - // update print config related with variants - out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, - print_options_with_variant, "print_extruder_id", "print_extruder_variant"); + out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, printer_options_with_variant_1, "printer_extruder_id", "printer_extruder_variant"); + out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, printer_options_with_variant_2, "printer_extruder_id", "printer_extruder_variant", 2); + //update print config related with variants + out.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, print_options_with_variant, "print_extruder_id", "print_extruder_variant"); } } if (num_filaments <= 1) { - // BBS: update filament config related with variants + //BBS: update filament config related with variants DynamicPrintConfig filament_config = this->filaments.get_edited_preset().config; if (apply_extruder && ((extruder_count > 1) || different_extruder)) - filament_config.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, - filament_options_with_variant, "", "filament_extruder_variant", 1, - filament_maps[0], (NozzleVolumeType) filament_volume_maps[0]); + filament_config.update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, filament_options_with_variant, "", "filament_extruder_variant", 1, filament_maps[0], (NozzleVolumeType)filament_volume_maps[0]); out.apply(filament_config); compatible_printers_condition.emplace_back(this->filaments.get_edited_preset().compatible_printers_condition()); - compatible_prints_condition.emplace_back(this->filaments.get_edited_preset().compatible_prints_condition()); - // BBS: add logic for settings check between different system presets - // std::string filament_inherits = this->filaments.get_edited_preset().inherits(); + compatible_prints_condition .emplace_back(this->filaments.get_edited_preset().compatible_prints_condition()); + //BBS: add logic for settings check between different system presets + //std::string filament_inherits = this->filaments.get_edited_preset().inherits(); std::string current_preset_name = this->filament_presets[0]; - const Preset* preset = this->filaments.find_preset(current_preset_name, true); - std::string filament_inherits = preset->inherits(); - inherits.emplace_back(filament_inherits); + const Preset* preset = this->filaments.find_preset(current_preset_name, true); + std::string filament_inherits = preset->inherits(); + inherits .emplace_back(filament_inherits); filament_ids.emplace_back(this->filaments.get_edited_preset().filament_id); std::string different_filament_settings; - const Preset* filament_parent_preset = this->filaments.get_selected_preset_parent(); + const Preset* filament_parent_preset = this->filaments.get_selected_preset_parent(); if (filament_parent_preset) { - std::vector dirty_options = - this->filaments.dirty_options_without_option_list(&(this->filaments.get_edited_preset()), filament_parent_preset, - ignore_settings_list, false); + std::vector dirty_options = this->filaments.dirty_options_without_option_list(&(this->filaments.get_edited_preset()), filament_parent_preset, ignore_settings_list, false); if (!dirty_options.empty()) { different_filament_settings = Slic3r::escape_strings_cstyle(dirty_options); } @@ -4581,7 +4422,7 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, different_settings.emplace_back(different_filament_settings); std::vector& filament_self_indice = out.option("filament_self_index", true)->values; - int index_size = out.option("filament_extruder_variant")->size(); + int index_size = out.option("filament_extruder_variant")->size(); filament_self_indice.resize(index_size, 1); } else { // Retrieve filament presets and build a single config object for them. @@ -4600,16 +4441,16 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, filament_configs.emplace_back(&(preset->config)); } for (int index = 0; index < num_filaments; index++) { - const DynamicPrintConfig* cfg = filament_configs[index]; - const Preset* preset = filament_presets[index]; + const DynamicPrintConfig *cfg = filament_configs[index]; + const Preset *preset = filament_presets[index]; // The compatible_prints/printers_condition() returns a reference to configuration key, which may not yet exist. - DynamicPrintConfig& cfg_rw = *const_cast(cfg); + DynamicPrintConfig &cfg_rw = *const_cast(cfg); compatible_printers_condition.emplace_back(Preset::compatible_printers_condition(cfg_rw)); - compatible_prints_condition.emplace_back(Preset::compatible_prints_condition(cfg_rw)); + compatible_prints_condition .emplace_back(Preset::compatible_prints_condition(cfg_rw)); - // BBS: add logic for settings check between different system presets + //BBS: add logic for settings check between different system presets std::string filament_inherits = Preset::inherits(cfg_rw); - inherits.emplace_back(filament_inherits); + inherits .emplace_back(filament_inherits); filament_ids.emplace_back(preset->filament_id); std::string different_filament_settings; @@ -4617,13 +4458,15 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, if (preset->is_system || preset->is_default) { bool is_selected = this->filaments.get_selected_preset_name() == preset->name; if (is_selected) { - // use the real preset + //use the real preset filament_parent_preset = const_cast(this)->filaments.find_preset(preset->name, false, true); - } else { + } + else { filament_parent_preset = preset; } - } else if (!filament_inherits.empty()) - filament_parent_preset = const_cast(this)->filaments.find_preset(filament_inherits, false, true); + } + else if (!filament_inherits.empty()) + filament_parent_preset = const_cast(this)->filaments.find_preset(filament_inherits, false, true); if (filament_parent_preset) { std::vector dirty_options = cfg_rw.diff(filament_parent_preset->config); @@ -4632,7 +4475,8 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, while (iter != dirty_options.end()) { if (ignore_settings_list.find(*iter) != ignore_settings_list.end()) { iter = dirty_options.erase(iter); - } else { + } + else { ++iter; } } @@ -4648,22 +4492,19 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, for (size_t i = 0; i < num_filaments; ++i) { filament_temp_configs[i] = *(filament_configs[i]); if (apply_extruder && ((extruder_count > 1) || different_extruder)) - filament_temp_configs[i].update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, - nozzle_volume_types, filament_options_with_variant, "", - "filament_extruder_variant", 1, filament_maps[i], - (NozzleVolumeType) filament_volume_maps[i]); + filament_temp_configs[i].update_values_to_printer_extruders(out, extruder_count, extruder_volume_type_count, nozzle_volume_types, filament_options_with_variant, "", "filament_extruder_variant", 1, filament_maps[i], (NozzleVolumeType)filament_volume_maps[i]); } // loop through options and apply them to the resulting config. std::vector filament_variant_count(num_filaments, 1); - for (const t_config_option_key& key : this->filaments.default_preset().config.keys()) { - if (key == "compatible_prints" || key == "compatible_printers") - continue; + for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) { + if (key == "compatible_prints" || key == "compatible_printers") + continue; // Get a destination option. - ConfigOption* opt_dst = out.option(key, false); + ConfigOption *opt_dst = out.option(key, false); if (opt_dst->is_scalar()) { // Get an option, do not create if it does not exist. - const ConfigOption* opt_src = filament_temp_configs.front().option(key); + const ConfigOption *opt_src = filament_temp_configs.front().option(key); if (opt_src != nullptr) opt_dst->set(opt_src); } else { @@ -4676,10 +4517,10 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, for (size_t i = 0; i < filament_opts.size(); ++i) filament_opts[i] = filament_temp_configs[i].option(key); opt_vec_dst->set(filament_opts); - } else { + } + else { for (size_t i = 0; i < num_filaments; ++i) { - const ConfigOptionVectorBase* filament_option = static_cast( - filament_temp_configs[i].option(key)); + const ConfigOptionVectorBase* filament_option = static_cast(filament_temp_configs[i].option(key)); if (i == 0) opt_vec_dst->set(filament_option); else @@ -4694,9 +4535,9 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, } if (!apply_extruder) { - // append filament_self_index + //append filament_self_index std::vector& filament_self_indice = out.option("filament_self_index", true)->values; - int index_size = out.option("filament_extruder_variant")->size(); + int index_size = out.option("filament_extruder_variant")->size(); filament_self_indice.resize(index_size, 1); int k = 0; for (size_t i = 0; i < num_filaments; i++) { @@ -4707,15 +4548,13 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, } } - // BBS: add logic for settings check between different system presets + //BBS: add logic for settings check between different system presets std::string printer_inherits = this->printers.get_edited_preset().inherits(); // Don't store the "compatible_printers_condition" for the printer profile, there is none. - inherits.emplace_back(printer_inherits); - const Preset* printer_parent_preset = this->printers.get_selected_preset_parent(); + inherits .emplace_back(printer_inherits); + const Preset* printer_parent_preset = this->printers.get_selected_preset_parent(); if (printer_parent_preset) { - std::vector dirty_options = this->printers.dirty_options_without_option_list(&(this->printers.get_edited_preset()), - printer_parent_preset, - ignore_settings_list, false); + std::vector dirty_options = this->printers.dirty_options_without_option_list(&(this->printers.get_edited_preset()), printer_parent_preset, ignore_settings_list, false); if (!dirty_options.empty()) { different_printer_settings = Slic3r::escape_strings_cstyle(dirty_options); } @@ -4728,38 +4567,40 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, out.erase("compatible_printers"); out.erase("compatible_printers_condition"); out.erase("inherits"); - // BBS: add logic for settings check between different system presets + //BBS: add logic for settings check between different system presets out.erase("different_settings_to_system"); static const char* keys[] = {"support_filament", "support_interface_filament", "wipe_tower_filament"}; - for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); ++i) { + for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); ++ i) { std::string key = std::string(keys[i]); - auto* opt = dynamic_cast(out.option(key, false)); + auto *opt = dynamic_cast(out.option(key, false)); assert(opt != nullptr); opt->value = boost::algorithm::clamp(opt->value, 0, int(num_filaments)); } - static const char* keys_with_default[] = {"outer_wall_filament_id", "inner_wall_filament_id", "sparse_infill_filament_id", - "internal_solid_filament_id", "top_surface_filament_id", "bottom_surface_filament_id"}; - for (size_t i = 0; i < sizeof(keys_with_default) / sizeof(keys_with_default[0]); ++i) { + static const char* keys_with_default[] = { + "outer_wall_filament_id", "inner_wall_filament_id", "sparse_infill_filament_id", + "internal_solid_filament_id", "top_surface_filament_id", "bottom_surface_filament_id" + }; + for (size_t i = 0; i < sizeof(keys_with_default) / sizeof(keys_with_default[0]); ++ i) { std::string key = std::string(keys_with_default[i]); - auto* opt = dynamic_cast(out.option(key, false)); + auto *opt = dynamic_cast(out.option(key, false)); assert(opt != nullptr); - if (opt->value < 0 || opt->value > int(num_filaments)) + if(opt->value < 0 || opt->value > int(num_filaments)) opt->value = 0; } - out.option("print_settings_id", true)->value = this->prints.get_selected_preset_name(); + out.option("print_settings_id", true)->value = this->prints.get_selected_preset_name(); out.option("filament_settings_id", true)->values = this->filament_presets; - out.option("printer_settings_id", true)->value = this->printers.get_selected_preset_name(); - out.option("filament_ids", true)->values = filament_ids; - out.option("filament_map", true)->values = filament_maps; + out.option("printer_settings_id", true)->value = this->printers.get_selected_preset_name(); + out.option("filament_ids", true)->values = filament_ids; + out.option("filament_map", true)->values = filament_maps; // Serialize the collected "compatible_printers_condition" and "inherits" fields. // There will be 1 + num_exturders fields for "inherits" and 2 + num_extruders for "compatible_printers_condition" stored. // The vector will not be stored if all fields are empty strings. - auto add_if_some_non_empty = [&out](std::vector&& values, const std::string& key) { + auto add_if_some_non_empty = [&out](std::vector &&values, const std::string &key) { bool nonempty = false; - for (const std::string& v : values) - if (!v.empty()) { + for (const std::string &v : values) + if (! v.empty()) { nonempty = true; break; } @@ -4767,14 +4608,14 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, out.set_key_value(key, new ConfigOptionStrings(std::move(values))); }; add_if_some_non_empty(std::move(compatible_printers_condition), "compatible_machine_expression_group"); - add_if_some_non_empty(std::move(compatible_prints_condition), "compatible_process_expression_group"); - add_if_some_non_empty(std::move(inherits), "inherits_group"); - // BBS: add logic for settings check between different system presets - add_if_some_non_empty(std::move(different_settings), "different_settings_to_system"); - add_if_some_non_empty(std::move(print_compatible_printers), "print_compatible_printers"); - out.option("extruder_ams_count", true)->values = save_extruder_ams_count_to_string(this->extruder_ams_counts); + add_if_some_non_empty(std::move(compatible_prints_condition), "compatible_process_expression_group"); + add_if_some_non_empty(std::move(inherits), "inherits_group"); + //BBS: add logic for settings check between different system presets + add_if_some_non_empty(std::move(different_settings), "different_settings_to_system"); + add_if_some_non_empty(std::move(print_compatible_printers), "print_compatible_printers"); + out.option("extruder_ams_count", true)->values = save_extruder_ams_count_to_string(this->extruder_ams_counts); - out.option("printer_technology", true)->value = ptFFF; + out.option("printer_technology", true)->value = ptFFF; return out; } @@ -4786,36 +4627,35 @@ DynamicPrintConfig PresetBundle::full_sla_config() const out.apply(this->sla_materials.get_edited_preset().config); out.apply(this->printers.get_edited_preset().config); // There are no project configuration values as of now, the project_config is reserved for FFF printers. - // out.apply(this->project_config); +// out.apply(this->project_config); - // Collect the "compatible_printers_condition" and "inherits" values over all presets (sla_prints, sla_materials, printers) into a - // single vector. + // Collect the "compatible_printers_condition" and "inherits" values over all presets (sla_prints, sla_materials, printers) into a single vector. std::vector compatible_printers_condition; - std::vector compatible_prints_condition; + std::vector compatible_prints_condition; std::vector inherits; compatible_printers_condition.emplace_back(this->sla_prints.get_edited_preset().compatible_printers_condition()); - inherits.emplace_back(this->sla_prints.get_edited_preset().inherits()); + inherits .emplace_back(this->sla_prints.get_edited_preset().inherits()); compatible_printers_condition.emplace_back(this->sla_materials.get_edited_preset().compatible_printers_condition()); - compatible_prints_condition.emplace_back(this->sla_materials.get_edited_preset().compatible_prints_condition()); - inherits.emplace_back(this->sla_materials.get_edited_preset().inherits()); - inherits.emplace_back(this->printers.get_edited_preset().inherits()); + compatible_prints_condition .emplace_back(this->sla_materials.get_edited_preset().compatible_prints_condition()); + inherits .emplace_back(this->sla_materials.get_edited_preset().inherits()); + inherits .emplace_back(this->printers.get_edited_preset().inherits()); // These two value types clash between the print and filament profiles. They should be renamed. out.erase("compatible_printers"); out.erase("compatible_printers_condition"); out.erase("inherits"); - out.option("sla_print_settings_id", true)->value = this->sla_prints.get_selected_preset_name(); - out.option("sla_material_settings_id", true)->value = this->sla_materials.get_selected_preset_name(); - out.option("printer_settings_id", true)->value = this->printers.get_selected_preset_name(); + out.option("sla_print_settings_id", true)->value = this->sla_prints.get_selected_preset_name(); + out.option("sla_material_settings_id", true)->value = this->sla_materials.get_selected_preset_name(); + out.option("printer_settings_id", true)->value = this->printers.get_selected_preset_name(); // Serialize the collected "compatible_printers_condition" and "inherits" fields. // There will be 1 + num_exturders fields for "inherits" and 2 + num_extruders for "compatible_printers_condition" stored. // The vector will not be stored if all fields are empty strings. - auto add_if_some_non_empty = [&out](std::vector&& values, const std::string& key) { + auto add_if_some_non_empty = [&out](std::vector &&values, const std::string &key) { bool nonempty = false; - for (const std::string& v : values) - if (!v.empty()) { + for (const std::string &v : values) + if (! v.empty()) { nonempty = true; break; } @@ -4823,49 +4663,48 @@ DynamicPrintConfig PresetBundle::full_sla_config() const out.set_key_value(key, new ConfigOptionStrings(std::move(values))); }; add_if_some_non_empty(std::move(compatible_printers_condition), "compatible_machine_expression_group"); - add_if_some_non_empty(std::move(compatible_prints_condition), "compatible_process_expression_group"); - add_if_some_non_empty(std::move(inherits), "inherits_group"); + add_if_some_non_empty(std::move(compatible_prints_condition), "compatible_process_expression_group"); + add_if_some_non_empty(std::move(inherits), "inherits_group"); - out.option("printer_technology", true)->value = ptSLA; - return out; + out.option("printer_technology", true)->value = ptSLA; + return out; } // Load an external config file containing the print, filament and printer presets. // Instead of a config file, a G-code may be loaded containing the full set of parameters. // In the future the configuration will likely be read from an AMF file as well. // If the file is loaded successfully, its print / filament / printer profiles will be activated. -ConfigSubstitutions PresetBundle::load_config_file(const std::string& path, ForwardCompatibilitySubstitutionRule compatibility_rule) +ConfigSubstitutions PresetBundle::load_config_file(const std::string &path, ForwardCompatibilitySubstitutionRule compatibility_rule) { - if (is_gcode_file(path)) { - DynamicPrintConfig config; - // BBS: add config related logs - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(" enter, gcodefile %1%, compatibility_rule %2%") % path % compatibility_rule; - config.apply(FullPrintConfig::defaults()); + if (is_gcode_file(path)) { + DynamicPrintConfig config; + //BBS: add config related logs + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, gcodefile %1%, compatibility_rule %2%")%path %compatibility_rule; + config.apply(FullPrintConfig::defaults()); ConfigSubstitutions config_substitutions = config.load_from_gcode_file(path, compatibility_rule); Preset::normalize(config); - load_config_file_config(path, true, std::move(config)); - return config_substitutions; - } + load_config_file_config(path, true, std::move(config)); + return config_substitutions; + } - // BBS: add config related logs - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" can not load config file %1% not from gcode") % path; + //BBS: add config related logs + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" can not load config file %1% not from gcode")%path ; throw Slic3r::RuntimeError(std::string("Unknown configuration file: ") + path); - + return ConfigSubstitutions{}; } -// some filament presets split from one to sperate ones -// following map recording these filament presets -// for example: previously ''Bambu PLA Basic @BBL H2D 0.6 nozzle' was saved in ''Bambu PLA Basic @BBL H2D' with 0.4 -static std::map> filament_preset_convert = - {{"Bambu Lab H2D 0.6 nozzle", - {{"Bambu PLA Basic @BBL H2D", "Bambu PLA Basic @BBL H2D 0.6 nozzle"}, - {"Bambu PLA Matte @BBL H2D", "Bambu PLA Matte @BBL H2D 0.6 nozzle"}, - {"Bambu ABS @BBL H2D", "Bambu ABS @BBL H2D 0.6 nozzle"}}}, - {"Bambu Lab H2D 0.8 nozzle", - {{"Bambu PETG HF @BBL H2D 0.6 nozzle", "Bambu PETG HF @BBL H2D 0.8 nozzle"}, - {"Bambu ASA @BBL H2D 0.6 nozzle", "Bambu ASA @BBL H2D 0.8 nozzle"}}}}; + +//some filament presets split from one to sperate ones +//following map recording these filament presets +//for example: previously ''Bambu PLA Basic @BBL H2D 0.6 nozzle' was saved in ''Bambu PLA Basic @BBL H2D' with 0.4 +static std::map> filament_preset_convert = { +{"Bambu Lab H2D 0.6 nozzle", {{"Bambu PLA Basic @BBL H2D", "Bambu PLA Basic @BBL H2D 0.6 nozzle"}, + {"Bambu PLA Matte @BBL H2D", "Bambu PLA Matte @BBL H2D 0.6 nozzle"}, + {"Bambu ABS @BBL H2D", "Bambu ABS @BBL H2D 0.6 nozzle"}}}, +{"Bambu Lab H2D 0.8 nozzle", {{"Bambu PETG HF @BBL H2D 0.6 nozzle", "Bambu PETG HF @BBL H2D 0.8 nozzle"}, + {"Bambu ASA @BBL H2D 0.6 nozzle", "Bambu ASA @BBL H2D 0.8 nozzle"}}} +}; // Relocate the per-slot cells of one mixed-filament project vector inside the imported // config, applying every authored-slot -> destination move at once. Each move reads its @@ -4910,26 +4749,24 @@ static void apply_mixed_config_relocations(DynamicPrintConfig& } } -// convert the old filament preset to new one after split + +//convert the old filament preset to new one after split static void convert_filament_preset_name(std::string& machine_name, std::string& filament_name) { auto machine_iter = filament_preset_convert.find(machine_name); - if (machine_iter != filament_preset_convert.end()) { + if (machine_iter != filament_preset_convert.end()) + { std::map& filament_maps = machine_iter->second; - auto filament_iter = filament_maps.find(filament_name); - if (filament_iter != filament_maps.end()) { + auto filament_iter = filament_maps.find(filament_name); + if (filament_iter != filament_maps.end()) + { filament_name = filament_iter->second; } } } // Load a config file from a boost property_tree. This is a private method called from load_config_file. // is_external == false on if called from ConfigWizard -void PresetBundle::load_config_file_config(const std::string& name_or_path, - bool is_external, - DynamicPrintConfig&& config, - Semver file_version, - bool selected, - PublishedConfig* published_config) +void PresetBundle::load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config, Semver file_version, bool selected, PublishedConfig *published_config) { PrinterTechnology printer_technology = Preset::printer_technology(config); @@ -4937,8 +4774,8 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, // the author-selected published keys onto the edited presets. const bool is_published = published_config != nullptr && published_config->published; - auto clear_compatible_printers = [](DynamicPrintConfig& config) { - ConfigOption* opt_compatible = config.optptr("compatible_printers"); + auto clear_compatible_printers = [](DynamicPrintConfig& config){ + ConfigOption *opt_compatible = config.optptr("compatible_printers"); if (opt_compatible != nullptr) { assert(opt_compatible->type() == coStrings); if (opt_compatible->type() == coStrings) @@ -4960,49 +4797,44 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, #else // BBS: use filament_colour insteadof filament_settings_id, filament_settings_id sometimes is not generated ConfigOptionStrings* filament_colour_option = config.option("filament_colour"); - size_t num_filaments = filament_colour_option ? filament_colour_option->size() : 0; + size_t num_filaments = filament_colour_option?filament_colour_option->size():0; if (num_filaments == 0) throw Slic3r::RuntimeError(std::string("Invalid configuration file: ") + name_or_path); #endif - // BBS: add config related logs - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(": , name_or_path %1%, is_external %2%, num_filaments %3%") % name_or_path % is_external % - num_filaments; + //BBS: add config related logs + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": , name_or_path %1%, is_external %2%, num_filaments %3%") % name_or_path % is_external % num_filaments; // Make a copy of the "compatible_machine_expression_group" and "inherits_group" vectors, which // accumulate values over all presets (print, filaments, printers). // These values will be distributed into their particular presets when loading. - std::vector compatible_printers_condition_values = std::move( - config.option("compatible_machine_expression_group", true)->values); - std::vector compatible_prints_condition_values = std::move( - config.option("compatible_process_expression_group", true)->values); - std::vector inherits_values = std::move(config.option("inherits_group", true)->values); - std::vector filament_ids = std::move(config.option("filament_ids", true)->values); - std::vector print_compatible_printers = std::move( - config.option("print_compatible_printers", true)->values); - // BBS: add different settings check logic - bool has_different_settings_to_system = config.option("different_settings_to_system") ? true : false; - std::vector different_values = std::move(config.option("different_settings_to_system", true)->values); - std::string& compatible_printers_condition = Preset::compatible_printers_condition(config); - std::string& compatible_prints_condition = Preset::compatible_prints_condition(config); - std::string& inherits = Preset::inherits(config); + std::vector compatible_printers_condition_values = std::move(config.option("compatible_machine_expression_group", true)->values); + std::vector compatible_prints_condition_values = std::move(config.option("compatible_process_expression_group", true)->values); + std::vector inherits_values = std::move(config.option("inherits_group", true)->values); + std::vector filament_ids = std::move(config.option("filament_ids", true)->values); + std::vector print_compatible_printers = std::move(config.option("print_compatible_printers", true)->values); + //BBS: add different settings check logic + bool has_different_settings_to_system = config.option("different_settings_to_system")?true:false; + std::vector different_values = std::move(config.option("different_settings_to_system", true)->values); + std::string &compatible_printers_condition = Preset::compatible_printers_condition(config); + std::string &compatible_prints_condition = Preset::compatible_prints_condition(config); + std::string &inherits = Preset::inherits(config); compatible_printers_condition_values.resize(num_filaments + 2, std::string()); compatible_prints_condition_values.resize(num_filaments, std::string()); inherits_values.resize(num_filaments + 2, std::string()); different_values.resize(num_filaments + 2, std::string()); filament_ids.resize(num_filaments, std::string()); // The "default_filament_profile" will be later extracted into the printer profile. - switch (printer_technology) { - case ptFFF: - config.option("default_print_profile", true); + switch (printer_technology) { + case ptFFF: + config.option("default_print_profile", true); config.option("default_filament_profile", true); - break; - case ptSLA: - config.option("default_sla_print_profile", true); - config.option("default_sla_material_profile", true); - break; + break; + case ptSLA: + config.option("default_sla_print_profile", true); + config.option("default_sla_material_profile", true); + break; default: break; - } + } bool process_multi_extruder = false; std::vector filament_variant_index; @@ -5022,15 +4854,13 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, filament_extruder_variant.resize(num_filaments, "Direct Drive Standard"); } if (config.option("extruder_variant_list")) { - // 3mf support multiple extruder logic - size_t extruder_count = config.option("nozzle_diameter")->values.size(); + //3mf support multiple extruder logic + size_t extruder_count = config.option("nozzle_diameter")->values.size(); extruder_variant_count = config.option("filament_extruder_variant", true)->size(); - if ((extruder_variant_count != filament_self_indice.size()) || (extruder_variant_count < num_filaments)) { + if ((extruder_variant_count != filament_self_indice.size()) + || (extruder_variant_count < num_filaments)) { assert(false); - BOOST_LOG_TRIVIAL(error) - << __FUNCTION__ - << boost::format(": invalid config file %1%, can not find suitable filament_extruder_variant or filament_self_index") % - name_or_path; + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(": invalid config file %1%, can not find suitable filament_extruder_variant or filament_self_index") % name_or_path; throw Slic3r::RuntimeError(std::string("Invalid configuration file: ") + name_or_path); } if (num_filaments != extruder_variant_count) { @@ -5048,12 +4878,13 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, } } } - // no need to parse extruder_ams_count + //no need to parse extruder_ams_count std::vector extruder_ams_count = std::move(config.option("extruder_ams_count", true)->values); config.erase("extruder_ams_count"); if (this->extruder_ams_counts.empty()) this->extruder_ams_counts = get_extruder_ams_count(extruder_ams_count); + // 1) Create a name from the file name. // Keep the suffix (.ini, .gcode, .amf, .3mf etc) to differentiate it from the normal profiles. std::string name = is_external ? boost::filesystem::path(name_or_path).filename().string() : name_or_path; @@ -5061,62 +4892,63 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, // 2) If the loading succeeded, split and load the config into print / filament / printer settings. // First load the print and printer presets. - auto load_preset = [&config, &inherits, &inherits_values, &compatible_printers_condition, &compatible_printers_condition_values, - &compatible_prints_condition, &compatible_prints_condition_values, is_external, &name, &name_or_path, file_version, - selected](PresetCollection& presets, size_t idx, const std::string& key, - const std::set& different_keys, std::string filament_id) { - // Split the "compatible_printers_condition" and "inherits" values one by one from a single vector to the print & printer profiles. - inherits = inherits_values[idx]; - compatible_printers_condition = compatible_printers_condition_values[idx]; + auto load_preset = + [&config, &inherits, &inherits_values, + &compatible_printers_condition, &compatible_printers_condition_values, + &compatible_prints_condition, &compatible_prints_condition_values, + is_external, &name, &name_or_path, file_version, selected] + (PresetCollection &presets, size_t idx, const std::string &key, const std::set &different_keys, std::string filament_id) { + // Split the "compatible_printers_condition" and "inherits" values one by one from a single vector to the print & printer profiles. + inherits = inherits_values[idx]; + compatible_printers_condition = compatible_printers_condition_values[idx]; if (idx > 0 && idx - 1 < compatible_prints_condition_values.size()) compatible_prints_condition = compatible_prints_condition_values[idx - 1]; - // BBS: add config related logs - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(": , name %1%, is_external %2%, inherits %3%") % name % is_external % inherits; - if (is_external) - presets.load_external_preset(name_or_path, name, config.opt_string(key, true), config, different_keys, - PresetCollection::LoadAndSelect::Always, file_version, filament_id); - else + //BBS: add config related logs + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": , name %1%, is_external %2%, inherits %3%")%name %is_external %inherits; + if (is_external) + presets.load_external_preset(name_or_path, name, config.opt_string(key, true), config, different_keys, PresetCollection::LoadAndSelect::Always, file_version, filament_id); + else presets.load_preset(presets.path_from_name(name, inherits.empty()), name, config, selected, file_version).save(nullptr); - }; + }; switch (Preset::printer_technology(config)) { - case ptFFF: { + case ptFFF: + { // A "published" 3MF project keeps the user's currently-selected presets, so the // print / printer / filament presets are NOT loaded from the file. Only the // project config values and the published keys are applied below. if (!is_published) { - // BBS: add different settings logic + //BBS: add different settings logic BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": load print preset from print_settings_id"); std::vector print_different_keys_vector; std::string print_different_settings = different_values[0]; Slic3r::unescape_strings_cstyle(print_different_settings, print_different_keys_vector); std::set print_different_keys_set(print_different_keys_vector.begin(), print_different_keys_vector.end()); - // if (!has_different_settings_to_system) { - // print_different_keys_set.clear(); - // } - // else - print_different_keys_set.insert(ignore_settings_list.begin(), ignore_settings_list.end()); + //if (!has_different_settings_to_system) { + // print_different_keys_set.clear(); + //} + //else + print_different_keys_set.insert(ignore_settings_list.begin(), ignore_settings_list.end()); if (!print_compatible_printers.empty()) { ConfigOptionStrings* compatible_printers = config.option("compatible_printers", true); - compatible_printers->values = print_compatible_printers; + compatible_printers->values = print_compatible_printers; } load_preset(this->prints, 0, "print_settings_id", print_different_keys_set, std::string()); - // clear compatible printers + //clear compatible printers clear_compatible_printers(config); std::vector printer_different_keys_vector; std::string printer_different_settings = different_values[num_filaments + 1]; Slic3r::unescape_strings_cstyle(printer_different_settings, printer_different_keys_vector); std::set printer_different_keys_set(printer_different_keys_vector.begin(), printer_different_keys_vector.end()); - // if (!has_different_settings_to_system) { - // printer_different_keys_set.clear(); - // } - // else - printer_different_keys_set.insert(ignore_settings_list.begin(), ignore_settings_list.end()); - // BBS: add config related logs + //if (!has_different_settings_to_system) { + // printer_different_keys_set.clear(); + //} + //else + printer_different_keys_set.insert(ignore_settings_list.begin(), ignore_settings_list.end()); + //BBS: add config related logs BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": load printer preset from printer_settings_id"); load_preset(this->printers, num_filaments + 1, "printer_settings_id", printer_different_keys_set, std::string()); @@ -5130,55 +4962,51 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, // Split the "compatible_printers_condition" and "inherits" values from the cummulative vectors to separate filament presets. inherits = inherits_values[1]; compatible_printers_condition = compatible_printers_condition_values[1]; - compatible_prints_condition = compatible_prints_condition_values.front(); - Preset* loaded = nullptr; + compatible_prints_condition = compatible_prints_condition_values.front(); + Preset *loaded = nullptr; - // BBS: add different settings logic + //BBS: add different settings logic std::vector filament_different_keys_vector; std::string filament_different_settings = different_values[1]; Slic3r::unescape_strings_cstyle(filament_different_settings, filament_different_keys_vector); - std::set filament_different_keys_set(filament_different_keys_vector.begin(), - filament_different_keys_vector.end()); - // if (!has_different_settings_to_system) { - // filament_different_keys_set.clear(); - // } - // else - filament_different_keys_set.insert(ignore_settings_list.begin(), ignore_settings_list.end()); + std::set filament_different_keys_set(filament_different_keys_vector.begin(), filament_different_keys_vector.end()); + //if (!has_different_settings_to_system) { + // filament_different_keys_set.clear(); + //} + //else + filament_different_keys_set.insert(ignore_settings_list.begin(), ignore_settings_list.end()); std::string filament_id = filament_ids[0]; - // BBS: add config related logs + //BBS: add config related logs BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": load single filament preset from filament_settings_id"); if (is_external) { if (inherits.empty()) convert_filament_preset_name(old_machine_profile_name->value, old_filament_profile_names->values.front()); else convert_filament_preset_name(old_machine_profile_name->value, inherits); - loaded = this->filaments - .load_external_preset(name_or_path, name, old_filament_profile_names->values.front(), config, - filament_different_keys_set, PresetCollection::LoadAndSelect::Always, file_version, - filament_id) - .first; - } else { - // called from Config Wizard. - loaded = &this->filaments.load_preset(this->filaments.path_from_name(name, inherits.empty()), name, config, true, - file_version); - loaded->save(nullptr); + loaded = this->filaments.load_external_preset(name_or_path, name, old_filament_profile_names->values.front(), config, filament_different_keys_set, PresetCollection::LoadAndSelect::Always, file_version, filament_id).first; } + else { + // called from Config Wizard. + loaded= &this->filaments.load_preset(this->filaments.path_from_name(name, inherits.empty()), name, config, true, file_version); + loaded->save(nullptr); + } this->filament_presets.clear(); - this->filament_presets.emplace_back(loaded->name); + this->filament_presets.emplace_back(loaded->name); } else { assert(is_external); // Split the filament presets, load each of them separately. std::vector configs(num_filaments, this->filaments.default_preset().config); // loop through options and scatter them into configs. - for (const t_config_option_key& key : this->filaments.default_preset().config.keys()) { - ConfigOption* other_opt = config.option(key); + for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) { + ConfigOption *other_opt = config.option(key); if (other_opt == nullptr) continue; if (other_opt->is_scalar()) { - for (size_t i = 0; i < configs.size(); ++i) + for (size_t i = 0; i < configs.size(); ++ i) configs[i].option(key, false)->set(other_opt); - } else if (key != "compatible_printers" && key != "compatible_prints") { + } + else if (key != "compatible_printers" && key != "compatible_prints") { for (size_t i = 0; i < configs.size(); ++i) { if (process_multi_extruder && (filament_options_with_variant.find(key) != filament_options_with_variant.end())) { ConfigOptionVectorBase* other_opt_vec = static_cast(other_opt); @@ -5186,9 +5014,9 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, other_opt_vec->resize(extruder_variant_count); } size_t next_index = (i < (configs.size() - 1)) ? filament_variant_index[i + 1] : extruder_variant_count; - static_cast(configs[i].option(key, false)) - ->set(other_opt, filament_variant_index[i], next_index - filament_variant_index[i]); - } else + static_cast(configs[i].option(key, false))->set(other_opt, filament_variant_index[i], next_index - filament_variant_index[i]); + } + else static_cast(configs[i].option(key, false))->set_at(other_opt, 0, i); } } @@ -5199,26 +5027,25 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, // in a case when next added preset take a place of previosly selected preset, // we should add presets from last to first bool any_modified = false; - // BBS: add config related logs + //BBS: add config related logs BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": load multiple filament preset from filament_settings_id"); - for (int i = (int) configs.size() - 1; i >= 0; i--) { - DynamicPrintConfig& cfg = configs[i]; + for (int i = (int)configs.size()-1; i >= 0; i--) { + DynamicPrintConfig &cfg = configs[i]; // Split the "compatible_printers_condition" and "inherits" from the cummulative vectors to separate filament presets. cfg.opt_string("compatible_printers_condition", true) = compatible_printers_condition_values[i + 1]; - cfg.opt_string("compatible_prints_condition", true) = compatible_prints_condition_values[i]; + cfg.opt_string("compatible_prints_condition", true) = compatible_prints_condition_values[i]; cfg.opt_string("inherits", true) = inherits_values[i + 1]; - // BBS: add different settings logic + //BBS: add different settings logic std::vector filament_different_keys_vector; - std::string filament_different_settings = different_values[i + 1]; + std::string filament_different_settings = different_values[i+1]; Slic3r::unescape_strings_cstyle(filament_different_settings, filament_different_keys_vector); - std::set filament_different_keys_set(filament_different_keys_vector.begin(), - filament_different_keys_vector.end()); - // if (!has_different_settings_to_system) { - // filament_different_keys_set.clear(); - // } - // else - filament_different_keys_set.insert(ignore_settings_list.begin(), ignore_settings_list.end()); + std::set filament_different_keys_set(filament_different_keys_vector.begin(), filament_different_keys_vector.end()); + //if (!has_different_settings_to_system) { + // filament_different_keys_set.clear(); + //} + //else + filament_different_keys_set.insert(ignore_settings_list.begin(), ignore_settings_list.end()); std::string filament_id = filament_ids[i]; @@ -5229,15 +5056,16 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, else convert_filament_preset_name(old_machine_profile_name->value, filament_inherit); auto [loaded, modified] = this->filaments.load_external_preset(name_or_path, name, - (i < int(old_filament_profile_names->values.size())) ? - old_filament_profile_names->values[i] : - "", - std::move(cfg), filament_different_keys_set, - i == 0 ? PresetCollection::LoadAndSelect::Always : - any_modified ? - PresetCollection::LoadAndSelect::Never : - PresetCollection::LoadAndSelect::OnlyIfModified, - file_version, filament_id); + (i < int(old_filament_profile_names->values.size())) ? old_filament_profile_names->values[i] : "", + std::move(cfg), + filament_different_keys_set, + i == 0 ? + PresetCollection::LoadAndSelect::Always : + any_modified ? + PresetCollection::LoadAndSelect::Never : + PresetCollection::LoadAndSelect::OnlyIfModified, + file_version, + filament_id); any_modified |= modified; this->filament_presets[i] = loaded->name; } @@ -5250,17 +5078,19 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, break; } - case ptSLA: { + case ptSLA: + { /*std::set different_keys_set; load_preset(this->sla_prints, 0, "sla_print_settings_id", different_keys_set); load_preset(this->sla_materials, 1, "sla_material_settings_id", different_keys_set); load_preset(this->printers, 2, "printer_settings_id", different_keys_set);*/ break; } - default: break; + default: + break; } - this->update_compatible(PresetSelectCompatibleType::Never); + this->update_compatible(PresetSelectCompatibleType::Never); this->update_multi_material_filament_presets(); // A "published" 3MF project overlays the author-selected published keys onto the user's @@ -6369,23 +6199,23 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, this->filaments.select_preset_by_name(this->filament_presets.front(), false); } - // BBS - // const std::string &physical_printer = config.option("physical_printer_settings_id", true)->value; + + //BBS + //const std::string &physical_printer = config.option("physical_printer_settings_id", true)->value; const std::string physical_printer; if (!is_published) { if (this->printers.get_edited_preset().is_external || physical_printer.empty()) { this->physical_printers.unselect_printer(); } else { // Activate the physical printer profile if possible. - PhysicalPrinter* pp = this->physical_printers.find_printer(physical_printer, true); - if (pp != nullptr && std::find(pp->preset_names.begin(), pp->preset_names.end(), this->printers.get_edited_preset().name) != - pp->preset_names.end()) + PhysicalPrinter *pp = this->physical_printers.find_printer(physical_printer, true); + if (pp != nullptr && std::find(pp->preset_names.begin(), pp->preset_names.end(), this->printers.get_edited_preset().name) != pp->preset_names.end()) this->physical_printers.select_printer(pp->name, this->printers.get_edited_preset().name); else this->physical_printers.unselect_printer(); } } - // BBS: add config related logs + //BBS: add config related logs BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": finished"); } @@ -6396,31 +6226,27 @@ void PresetBundle::load_config_file_config(const std::string& name_or_path, // (config_maps) or against base_bundle's filament library, flattens, validates // and registers the preset. Returns the reason loading failed, empty on // success. -std::string PresetBundle::load_vendor_preset(const CachedPreset& entry, - const std::string& path, - const std::string& vendor_name, - const PresetBundle* base_bundle, - LoadConfigBundleAttributes flags, - ConfigSubstitutionContext& substitution_context, - PresetsConfigSubstitutions& substitutions, - std::map& config_maps, - std::map& filament_id_maps, - PresetCollection* presets_collection, - size_t& count, - bool is_from_lib, - const std::set* retain_configs) +std::string PresetBundle::load_vendor_preset( + const CachedPreset& entry, + const std::string& path, const std::string& vendor_name, + const PresetBundle* base_bundle, + LoadConfigBundleAttributes flags, + ConfigSubstitutionContext& substitution_context, PresetsConfigSubstitutions& substitutions, + std::map& config_maps, std::map& filament_id_maps, + PresetCollection* presets_collection, size_t& count, bool is_from_lib, + const std::set* retain_configs) { - const VendorProfile* current_vendor_profile = &this->vendors.at(vendor_name); - const std::string subfile = path + "/" + vendor_name + "/" + entry.sub_path; - const std::string& preset_name = entry.name; - std::string alias_name, filament_id = entry.filament_id; - std::vector renamed_from = entry.renamed_from; - DynamicPrintConfig config; + const VendorProfile* current_vendor_profile = &this->vendors.at(vendor_name); + const std::string subfile = path + "/" + vendor_name + "/" + entry.sub_path; + const std::string& preset_name = entry.name; + std::string alias_name, filament_id = entry.filament_id; + std::vector renamed_from = entry.renamed_from; + DynamicPrintConfig config; const DynamicPrintConfig* default_config = nullptr; - std::string reason; + std::string reason; - // check whether it inherits other preset or not - if (!entry.inherits.empty()) { + //check whether it inherits other preset or not + if (! entry.inherits.empty()) { auto it2 = config_maps.find(entry.inherits); if (it2 != config_maps.end()) default_config = &(it2->second); @@ -6442,14 +6268,16 @@ std::string PresetBundle::load_vendor_preset(const CachedPreset& entry, } } } - } else { + } + else { ++m_errors; BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": can not find inherits " << entry.inherits << " for " << preset_name; // throw ConfigurationError(format("can not find inherits %1% for %2%", inherits, preset_name)); reason = "Can not find inherits: " + entry.inherits; return reason; } - } else { + } + else { if (presets_collection->type() == Preset::TYPE_PRINTER) default_config = &presets_collection->default_preset_for(entry.config_src).config; else @@ -6474,7 +6302,7 @@ std::string PresetBundle::load_vendor_preset(const CachedPreset& entry, return reason; } if (config.has("alias")) - alias_name = (dynamic_cast(config.option("alias")))->value; + alias_name = (dynamic_cast(config.option("alias")))->value; Preset::normalize(config); // Report configuration fields, which are misplaced into a wrong group. @@ -6488,36 +6316,37 @@ std::string PresetBundle::load_vendor_preset(const CachedPreset& entry, if (presets_collection->type() == Preset::TYPE_PRINTER) { // Filter out printer presets, which are not mentioned in the vendor profile. // These presets are considered not installed. - auto printer_model = config.opt_string("printer_model"); + auto printer_model = config.opt_string("printer_model"); if (printer_model.empty()) { ++m_errors; - BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << preset_name - << "\" defines no printer model, it will be ignored."; + BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << + preset_name << "\" defines no printer model, it will be ignored."; reason = std::string("can not find printer_model"); return reason; } auto printer_variant = config.opt_string("printer_variant"); if (printer_variant.empty()) { ++m_errors; - BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << preset_name - << "\" defines no printer variant, it will be ignored."; + BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << + preset_name << "\" defines no printer variant, it will be ignored."; reason = std::string("can not find printer_variant"); return reason; } auto it_model = std::find_if(current_vendor_profile->models.cbegin(), current_vendor_profile->models.cend(), - [&](const VendorProfile::PrinterModel& m) { return m.id == printer_model; }); + [&](const VendorProfile::PrinterModel &m) { return m.id == printer_model; } + ); if (it_model == current_vendor_profile->models.end()) { ++m_errors; - BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << preset_name - << "\" defines invalid printer model \"" << printer_model << "\", it will be ignored."; + BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << + preset_name << "\" defines invalid printer model \"" << printer_model << "\", it will be ignored."; reason = std::string("can not find printer model in vendor profile"); return reason; } auto it_variant = it_model->variant(printer_variant); if (it_variant == nullptr) { ++m_errors; - BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << preset_name - << "\" defines invalid printer variant \"" << printer_variant << "\", it will be ignored."; + BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << + preset_name << "\" defines invalid printer variant \"" << printer_variant << "\", it will be ignored."; reason = std::string("can not find printer_variant in vendor profile"); return reason; } @@ -6530,74 +6359,71 @@ std::string PresetBundle::load_vendor_preset(const CachedPreset& entry, // validated, not variant uniqueness. Validation-only so the app keeps loading existing // profiles unchanged. if (validation_mode && entry.instantiation == "true") { - const auto* nd = config.option("nozzle_diameter"); + const auto *nd = config.option("nozzle_diameter"); std::set nozzles, variant_nozzles; if (nd != nullptr) nozzles.insert(nd->values.begin(), nd->values.end()); std::vector variant_tokens; boost::algorithm::split(variant_tokens, printer_variant, boost::algorithm::is_any_of("+")); bool variant_ok = true; // printer_variant is already guaranteed non-empty above - for (const std::string& tok : variant_tokens) { + for (const std::string &tok : variant_tokens) { size_t consumed = 0; - double d = string_to_double_decimal_point(tok, &consumed); + double d = string_to_double_decimal_point(tok, &consumed); // Require a leading numeric diameter; a trailing suffix (e.g. "HF") is allowed. - if (consumed == 0) { - variant_ok = false; - break; - } + if (consumed == 0) { variant_ok = false; break; } variant_nozzles.insert(d); } if (!variant_ok || variant_nozzles != nozzles) { ++m_errors; - BOOST_LOG_TRIVIAL(error) - << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << preset_name - << "\" has printer_variant \"" << printer_variant << "\" that does not match its nozzle_diameter \"" - << (nd ? nd->serialize() : std::string()) - << "\". " - "printer_variant must begin with the nozzle diameter, optionally followed by a non-numeric suffix " - "(e.g. \"0.4\", \"0.8HF\"); for multi-nozzle printers, join the per-nozzle diameters with \"+\" in " - "nozzle order (e.g. \"0.4+0.6\")."; + BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << + preset_name << "\" has printer_variant \"" << printer_variant << + "\" that does not match its nozzle_diameter \"" << (nd ? nd->serialize() : std::string()) << "\". " + "printer_variant must begin with the nozzle diameter, optionally followed by a non-numeric suffix " + "(e.g. \"0.4\", \"0.8HF\"); for multi-nozzle printers, join the per-nozzle diameters with \"+\" in " + "nozzle order (e.g. \"0.4+0.6\")."; } } } - const Preset* preset_existing = presets_collection->find_preset(preset_name, false); + const Preset *preset_existing = presets_collection->find_preset(preset_name, false); if (preset_existing != nullptr) { ++m_errors; - BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << preset_name - << "\" has already been loaded from another Config Bundle."; + BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" << + preset_name << "\" has already been loaded from another Config Bundle."; reason = std::string("duplicated defines"); return reason; } - auto file_path = (boost::filesystem::path(data_dir()) / PRESET_SYSTEM_DIR / vendor_name / entry.sub_path).make_preferred(); - if (validation_mode) + auto file_path = (boost::filesystem::path(data_dir()) /PRESET_SYSTEM_DIR/ vendor_name / entry.sub_path).make_preferred(); + if(validation_mode) file_path = (boost::filesystem::path(data_dir()) / vendor_name / entry.sub_path).make_preferred(); // Load the preset into the list of presets, save it to disk. - Preset& loaded = presets_collection->load_preset(file_path.string(), preset_name, std::move(config), false); + Preset &loaded = presets_collection->load_preset(file_path.string(), preset_name, std::move(config), false); if (flags.has(LoadConfigBundleAttribute::LoadSystem)) { - loaded.is_system = true; - loaded.vendor = current_vendor_profile; - loaded.version = current_vendor_profile->config_version; + loaded.is_system = true; + loaded.vendor = current_vendor_profile; + loaded.version = current_vendor_profile->config_version; loaded.description = entry.description; - loaded.setting_id = entry.setting_id; + loaded.setting_id = entry.setting_id; // Derive the preset setting_id on the fly when a profile ships without one, // matching scripts/assign_vendor_setting_ids.py. Only instantiated presets // carry an id; non-instantiated base profiles return earlier above. This never // touches the per-user cloud-sync setting_id written into user .info files. if (loaded.setting_id.empty() && entry.instantiation == "true") - loaded.setting_id = generate_preset_setting_id(vendor_name, Preset::get_type_string(presets_collection->type()), preset_name); - loaded.filament_id = filament_id; + loaded.setting_id = generate_preset_setting_id( + vendor_name, Preset::get_type_string(presets_collection->type()), preset_name); + loaded.filament_id = filament_id; loaded.m_from_orca_filament_lib = is_from_lib; BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << " " << __LINE__ << ", " << loaded.name << " load filament_id: " << filament_id; if (presets_collection->type() == Preset::TYPE_FILAMENT) { if (filament_id.empty() && "Template" != vendor_name) { ++m_errors; - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": can not find filament_id for " << preset_name; - // throw ConfigurationError(format("can not find inherits %1% for %2%", inherits, preset_name)); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": can not find filament_id for " << preset_name; + //throw ConfigurationError(format("can not find inherits %1% for %2%", inherits, preset_name)); reason = "Can not find filament_id for " + preset_name; return reason; - } else { + } + else { filament_id_maps.emplace(preset_name, filament_id); } } @@ -6621,34 +6447,31 @@ std::string PresetBundle::load_vendor_preset(const CachedPreset& entry, filaments.set_printer_hold_alias(loaded.alias, loaded); } loaded.renamed_from = std::move(renamed_from); - if (!substitution_context.empty()) - substitutions.push_back({preset_name, presets_collection->type(), PresetConfigSubstitutions::Source::ConfigBundle, std::string(), - std::move(substitution_context.substitutions)}); + if (! substitution_context.empty()) + substitutions.push_back({ + preset_name, presets_collection->type(), PresetConfigSubstitutions::Source::ConfigBundle, + std::string(), std::move(substitution_context.substitutions) }); if (retain_configs == nullptr || retain_configs->count(preset_name) != 0) config_maps.emplace(preset_name, loaded.config); ++count; - // BBS: add config related logs - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", got preset %1%, from %2%") % loaded.name % subfile; + //BBS: add config related logs + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", got preset %1%, from %2%")%loaded.name %subfile; return reason; } -// BBS: Load a config bundle file from json +//BBS: Load a config bundle file from json std::pair PresetBundle::load_vendor_configs_from_json( - const std::string& dir, - const std::string& vendor_name, - LoadConfigBundleAttributes flags, - ForwardCompatibilitySubstitutionRule compatibility_rule, - const PresetBundle* base_bundle) + const std::string &dir, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule, const PresetBundle* base_bundle) { // Enable substitutions for user config bundle, throw an exception when loading a system profile. - ConfigSubstitutionContext substitution_context{compatibility_rule}; + ConfigSubstitutionContext substitution_context { compatibility_rule }; PresetsConfigSubstitutions substitutions; // Errors already on this bundle when the load began; the cache stamp below // counts only what this parse adds. const int errors_at_entry = m_errors; - // BBS: add config related logs - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, path %1%, compatibility_rule %2%") % dir.c_str() % compatibility_rule; + //BBS: add config related logs + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, path %1%, compatibility_rule %2%")%dir.c_str()%compatibility_rule; if (flags.has(LoadConfigBundleAttribute::ResetUserProfile) || flags.has(LoadConfigBundleAttribute::LoadSystem)) // Reset this bundle, delete user profile files if SaveImported. this->reset(flags.has(LoadConfigBundleAttribute::SaveImported)); @@ -6656,15 +6479,13 @@ std::pair PresetBundle::load_vendor_configs_ // Orca: only a whole-vendor load has a cache — the vendor-only and filament-only // scans want a slice of one. Validation reads the JSONs whatever is cached. const boost::filesystem::path dir_path(dir); - const bool cacheable = flags.has(LoadConfigBundleAttribute::LoadSystem) && !flags.has(LoadConfigBundleAttribute::LoadFilamentOnly); - if (cacheable && !validation_mode && this->load_vendor_cache(dir_path, vendor_name, base_bundle)) { + const bool cacheable = flags.has(LoadConfigBundleAttribute::LoadSystem) && ! flags.has(LoadConfigBundleAttribute::LoadFilamentOnly); + if (cacheable && ! validation_mode && this->load_vendor_cache(dir_path, vendor_name, base_bundle)) { size_t presets_loaded = 0; - for (const PresetCollection* coll : - std::initializer_list{&this->prints, &this->sla_prints, &this->filaments, &this->sla_materials, - &this->printers}) + for (const PresetCollection* coll : std::initializer_list{ + &this->prints, &this->sla_prints, &this->filaments, &this->sla_materials, &this->printers }) presets_loaded += coll->m_presets.size() - coll->m_num_default_presets; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(", %1% served from its preset cache, %2% presets") % vendor_name % presets_loaded; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", %1% served from its preset cache, %2% presets")%vendor_name%presets_loaded; return std::make_pair(std::move(substitutions), presets_loaded); } @@ -6688,9 +6509,10 @@ std::pair PresetBundle::load_vendor_configs_ } else if (boost::iequals(iter2.key(), BBL_JSON_KEY_SUB_PATH)) { subpath = iter2.value(); } - } else { + } + else { ++m_errors; - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": invalid value type for " << iter2.key(); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": invalid value type for " << iter2.key(); } } if (!name.empty() && !subpath.empty()) @@ -6712,51 +6534,55 @@ std::pair PresetBundle::load_vendor_configs_ boost::nowide::ifstream ifs(root_file); json j; ifs >> j; - // parse the json elements + //parse the json elements for (auto it = j.begin(); it != j.end(); it++) { if (boost::iequals(it.key(), BBL_JSON_KEY_VERSION)) { - // get version + //get version std::string version_str = it.value(); - auto config_version = Semver::parse(version_str); - if (!config_version) { + auto config_version = Semver::parse(version_str); + if (! config_version) { ++m_errors; - throw ConfigurationError( - (boost::format("vendor %1%'s config version: %2% invalid\nSuggest cleaning the directory %3% firstly") % - vendor_name % version_str % dir) - .str()); + throw ConfigurationError((boost::format("vendor %1%'s config version: %2% invalid\nSuggest cleaning the directory %3% firstly") + % vendor_name % version_str % dir).str()); } else { vendor_profile.config_version = std::move(*config_version); } - } else if (boost::iequals(it.key(), BBL_JSON_KEY_URL)) { - // get url + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_URL)) { + //get url vendor_profile.config_update_url = it.value(); - } else if (boost::iequals(it.key(), BBL_JSON_KEY_DESCRIPTION)) { - // get description - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": parse " << root_file << ", got description: " << it.value(); - } else if (boost::iequals(it.key(), BBL_JSON_KEY_NAME)) { - // get name + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_DESCRIPTION)) { + //get description + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": parse "< PresetBundle::load_vendor_configs_ process_subfiles.clear(); } - // 2) paste the machine model - for (auto& machine_model : machine_model_subfiles) { + //2) paste the machine model + for (auto& machine_model : machine_model_subfiles) + { std::string subfile = dir + "/" + vendor_name + "/" + machine_model.second; VendorProfile::PrinterModel model; model.id = machine_model.first; @@ -6774,44 +6601,49 @@ std::pair PresetBundle::load_vendor_configs_ boost::nowide::ifstream ifs(subfile); json j; ifs >> j; - // parse the json elements + //parse the json elements for (auto it = j.begin(); it != j.end(); it++) { if (boost::iequals(it.key(), BBL_JSON_KEY_VERSION)) { - // get version - } else if (boost::iequals(it.key(), BBL_JSON_KEY_URL)) { - // get url - } else if (boost::iequals(it.key(), BBL_JSON_KEY_NAME)) { - // get name + //get version + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_URL)) { + //get url + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_NAME)) { + //get name model.name = it.value(); - } else if (boost::iequals(it.key(), BBL_JSON_KEY_MODEL_ID)) { - // get model_id + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_MODEL_ID)) { + //get model_id model.model_id = it.value(); - } else if (boost::iequals(it.key(), BBL_JSON_KEY_NOZZLE_DIAMETER)) { - // get nozzle diameter + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_NOZZLE_DIAMETER)) { + //get nozzle diameter std::string nozzle_diameters = it.value(); std::vector variants; if (Slic3r::unescape_strings_cstyle(nozzle_diameters, variants)) { - for (const std::string& variant_name : variants) { + for (const std::string &variant_name : variants) { if (model.variant(variant_name) == nullptr) model.variants.emplace_back(VendorProfile::PrinterVariant(variant_name)); } } else { ++m_errors; - BOOST_LOG_TRIVIAL(error) - << __FUNCTION__ - << boost::format(": invalid nozzle_diameters %1% for Vendor %1%") % nozzle_diameters % vendor_name; + BOOST_LOG_TRIVIAL(error)<< __FUNCTION__ << boost::format(": invalid nozzle_diameters %1% for Vendor %1%") % nozzle_diameters % vendor_name; } - } else if (boost::iequals(it.key(), BBL_JSON_KEY_PRINTER_TECH)) { - // get printer tech + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_PRINTER_TECH)) { + //get printer tech if (boost::algorithm::starts_with(it.value(), "SL")) model.technology = ptSLA; else model.technology = ptFFF; - } else if (boost::iequals(it.key(), BBL_JSON_KEY_FAMILY)) { - // get family + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_FAMILY)) { + //get family model.family = it.value(); - } else if (boost::iequals(it.key(), BBL_JSON_KEY_BED_MODEL)) { - // get bed model + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_BED_MODEL)) { + //get bed model model.bed_model = it.value(); } else if (boost::iequals(it.key(), BBL_JSON_KEY_BOTTOM_TEXTURE_END_NAME)) { model.bottom_texture_end_name = it.value(); @@ -6823,26 +6655,28 @@ std::pair PresetBundle::load_vendor_configs_ model.bottom_texture_rect_longer = it.value(); } else if (boost::iequals(it.key(), BBL_JSON_KEY_MIDDLE_TEXTURE_RECT)) { model.middle_texture_rect = it.value(); - } else if (boost::iequals(it.key(), BBL_JSON_KEY_IMAGE_BED_TYPE)) { + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_IMAGE_BED_TYPE)) { model.image_bed_type = it.value(); - } else if (boost::iequals(it.key(), BBL_JSON_KEY_BED_TEXTURE)) { - // get bed texture + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_BED_TEXTURE)) { + //get bed texture model.bed_texture = it.value(); - } else if (boost::iequals(it.key(), BBL_JSON_KEY_HOTEND_MODEL)) { + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_HOTEND_MODEL)) { model.hotend_model = it.value(); - } else if (boost::iequals(it.key(), BBL_JSON_KEY_DEFAULT_MATERIALS)) { - // get machine list + } + else if (boost::iequals(it.key(), BBL_JSON_KEY_DEFAULT_MATERIALS)) { + //get machine list std::string default_materials_field = it.value(); if (Slic3r::unescape_strings_cstyle(default_materials_field, model.default_materials)) { - Slic3r::sort_remove_duplicates(model.default_materials); - if (!model.default_materials.empty() && model.default_materials.front().empty()) + Slic3r::sort_remove_duplicates(model.default_materials); + if (! model.default_materials.empty() && model.default_materials.front().empty()) // An empty material was inserted into the list of default materials. Remove it. model.default_materials.erase(model.default_materials.begin()); } else { ++m_errors; - BOOST_LOG_TRIVIAL(error) - << __FUNCTION__ - << boost::format(": invalid default_materials %1% for Vendor %1%") % default_materials_field % vendor_name; + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(": invalid default_materials %1% for Vendor %1%") % default_materials_field % vendor_name; } } else if (boost::iequals(it.key(), BBL_JSON_KEY_NOT_SUPPORT_BED_TYPE)) { // get machine list @@ -6854,67 +6688,65 @@ std::pair PresetBundle::load_vendor_configs_ model.not_support_bed_types.erase(model.not_support_bed_types.begin()); } else { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ - << boost::format(": invalid not_support_bed_types %1% for Vendor %1%") % - not_support_bed_type_field % vendor_name; + << boost::format(": invalid not_support_bed_types %1% for Vendor %1%") % not_support_bed_type_field % vendor_name; } } } - } catch (nlohmann::detail::parse_error& err) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << subfile - << " got a nlohmann::detail::parse_error, reason = " << err.what(); - throw ConfigurationError( - (boost::format("Failed loading configuration file %1%: %2%\nSuggest cleaning the directory %3% firstly") % subfile % - err.what() % dir) - .str()); + } + catch(nlohmann::detail::parse_error &err) { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "<< subfile <<" got a nlohmann::detail::parse_error, reason = " << err.what(); + throw ConfigurationError((boost::format("Failed loading configuration file %1%: %2%\nSuggest cleaning the directory %3% firstly") + %subfile %err.what() % dir).str()); } - if (!model.id.empty() && !model.variants.empty()) + if (! model.id.empty() && ! model.variants.empty()) vendor_profile.models.push_back(std::move(model)); } - // insert the vendor profile + //insert the vendor profile this->vendors.emplace(vendor_name, vendor_profile); - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(", loaded vendor profile, name %1%, id %2%, version %3%") % vendor_profile.name % - vendor_profile.id % vendor_profile.config_version.to_string(); + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", loaded vendor profile, name %1%, id %2%, version %3%")%vendor_profile.name%vendor_profile.id%vendor_profile.config_version.to_string(); if (flags.has(LoadConfigBundleAttribute::LoadVendorOnly)) return std::make_pair(PresetsConfigSubstitutions{}, 0); // 3) paste the process/filament/print configs - PresetCollection* presets = nullptr; - size_t presets_loaded = 0; + PresetCollection *presets = nullptr; + size_t presets_loaded = 0; // Parse one subfile into a source-form entry — everything the JSON states, // nothing resolved. Loading the entry (load_vendor_preset) is the // same code whether the entry was parsed just now or deserialized from the // vendor's cache. - auto parse_subfile = [this, dir, vendor_name](ConfigSubstitutionContext& substitution_context, - const std::pair& subfile_iter, - CachedPreset& entry) -> std::string { + auto parse_subfile = [this, dir, vendor_name]( + ConfigSubstitutionContext& substitution_context, + const std::pair& subfile_iter, + CachedPreset& entry) -> std::string { + std::string subfile = dir + "/" + vendor_name + "/" + subfile_iter.second; std::string reason; try { std::map key_values; substitution_context.substitutions.clear(); - // parse the json elements + //parse the json elements entry.sub_path = subfile_iter.second; entry.config_src.load_from_json(subfile, substitution_context, false, key_values, reason); if (!reason.empty()) { ++m_errors; - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": load config file " << subfile << " Failed!"; + BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": load config file "< PresetBundle::load_vendor_configs_ << "\" contains invalid \"renamed_from\" key, which is being ignored."; } } - } catch (nlohmann::detail::parse_error& err) { + } + catch(nlohmann::detail::parse_error &err) { ++m_errors; - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << subfile - << " got a nlohmann::detail::parse_error, reason = " << err.what(); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "<< subfile <<" got a nlohmann::detail::parse_error, reason = " << err.what(); reason = std::string("json parse error") + err.what(); return reason; } @@ -6966,8 +6798,8 @@ std::pair PresetBundle::load_vendor_configs_ // so the parse_errors stamped into the cache must hold only what a cache load // will not recount. int install_errors = 0; - auto load_subfiles = [&](std::vector>& subfiles, std::vector& entries, - const char* kind, bool is_from_lib = false) { + auto load_subfiles = [&](std::vector>& subfiles, + std::vector& entries, const char* kind, bool is_from_lib = false) { configs.clear(); filament_id_maps.clear(); for (auto& subfile : subfiles) { @@ -6975,19 +6807,17 @@ std::pair PresetBundle::load_vendor_configs_ std::string reason = parse_subfile(substitution_context, subfile, entry); if (reason.empty()) { const int errors_before_install = m_errors; - reason = load_vendor_preset(entry, dir, vendor_name, base_bundle, flags, substitution_context, substitutions, configs, - filament_id_maps, presets, presets_loaded, is_from_lib); + reason = load_vendor_preset(entry, dir, vendor_name, base_bundle, flags, + substitution_context, substitutions, configs, filament_id_maps, presets, + presets_loaded, is_from_lib); install_errors += m_errors - errors_before_install; } if (!reason.empty()) { ++m_errors; - // parse error + //parse error std::string subfile_path = dir + "/" + vendor_name + "/" + subfile.second; - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ - << boost::format(", got error when parse %1% setting from %2%") % kind % subfile_path; - throw ConfigurationError( - (boost::format("Failed loading configuration file %1%\nSuggest cleaning the directory %2% firstly") % subfile_path % dir) - .str()); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", got error when parse %1% setting from %2%") % kind % subfile_path; + throw ConfigurationError((boost::format("Failed loading configuration file %1%\nSuggest cleaning the directory %2% firstly") % subfile_path % dir).str()); } if (will_cache) entries.emplace_back(std::move(entry)); @@ -6997,12 +6827,12 @@ std::pair PresetBundle::load_vendor_configs_ // The section order below — process, filaments (with the ORCA-lib map copy), // printers — is mirrored by load_vendor_cache's install loops; keep the two // in lockstep. - // 3.1) paste the process + //3.1) paste the process presets = &this->prints; load_subfiles(process_subfiles, cache_data.process_entries, "process"); - // 3.2) paste the filaments - presets = &this->filaments; + //3.2) paste the filaments + presets = &this->filaments; const auto is_orca_lib = vendor_name == ORCA_FILAMENT_LIBRARY; load_subfiles(filament_subfiles, cache_data.filament_entries, "filament", is_orca_lib); if (is_orca_lib) { @@ -7010,7 +6840,7 @@ std::pair PresetBundle::load_vendor_configs_ m_filament_id_maps = filament_id_maps; } - // 3.3) paste the printers + //3.3) paste the printers presets = &this->printers; load_subfiles(machine_subfiles, cache_data.machine_entries, "printer"); @@ -7019,13 +6849,13 @@ std::pair PresetBundle::load_vendor_configs_ // wrapped would be added to every future load of this vendor. cache_data.parse_errors = uint64_t(std::max(0, m_errors - errors_at_entry - install_errors)); cache_data.vendors = this->vendors; - if (!VendorCacheFile::save((dir_path / (vendor_name + ".opc")).string(), vendor_name, vendor_profile.config_version.to_string(), - cache_data)) + if (! VendorCacheFile::save((dir_path / (vendor_name + ".opc")).string(), vendor_name, + vendor_profile.config_version.to_string(), cache_data)) BOOST_LOG_TRIVIAL(warning) << "PresetBundle: failed to save vendor cache for " << vendor_name; } - // BBS: add config related logs - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", finished, presets_loaded %1%") % presets_loaded; + //BBS: add config related logs + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", finished, presets_loaded %1%")%presets_loaded; return std::make_pair(std::move(substitutions), presets_loaded); } @@ -7063,9 +6893,9 @@ void PresetBundle::update_multi_material_filament_presets(size_t to_delete_filam // Now verify if flush_volumes_matrix has proper size (it is used to deduce number of extruders in wipe tower generator): std::vector old_matrix = this->project_config.option("flush_volumes_matrix")->values; - size_t old_nozzle_nums = this->project_config.option("flush_multiplier")->values.size(); + size_t old_nozzle_nums = this->project_config.option("flush_multiplier")->values.size(); size_t old_number_of_filaments = size_t(sqrt(old_matrix.size() / old_nozzle_nums) + EPSILON); - size_t nozzle_nums = get_printer_extruder_count(); + size_t nozzle_nums = get_printer_extruder_count(); if (old_nozzle_nums != nozzle_nums) { std::vector& f_multiplier = this->project_config.option("flush_multiplier")->values; f_multiplier.resize(nozzle_nums, 1.f); @@ -7074,11 +6904,11 @@ void PresetBundle::update_multi_material_filament_presets(size_t to_delete_filam if (old_matrix.size() != num_filaments * num_filaments * nozzle_nums) { // First verify if purging volumes presets for each extruder matches number of extruders std::vector& filaments = this->project_config.option("flush_volumes_vector")->values; - while (filaments.size() < 2 * num_filaments) { - filaments.push_back(filaments.size() > 1 ? filaments[0] : 140.); // copy the values from the first extruder - filaments.push_back(filaments.size() > 1 ? filaments[1] : 140.); + while (filaments.size() < 2* num_filaments) { + filaments.push_back(filaments.size()>1 ? filaments[0] : 140.); // copy the values from the first extruder + filaments.push_back(filaments.size()>1 ? filaments[1] : 140.); } - while (filaments.size() > 2 * num_filaments) { + while (filaments.size() > 2* num_filaments) { filaments.pop_back(); filaments.pop_back(); } @@ -7096,19 +6926,14 @@ void PresetBundle::update_multi_material_filament_presets(size_t to_delete_filam // for this nozzle slot; otherwise initialize from the per-filament // flush volumes the same way the (i,j) out-of-range branch does. if (nozzle_id < old_nozzle_nums) { - new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = - old_matrix[old_i * old_number_of_filaments + old_j + old_matrix_size * nozzle_id]; + new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = old_matrix[old_i * old_number_of_filaments + old_j + old_matrix_size * nozzle_id]; } else { - new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = (i == j ? - 0. : - filaments[2 * i] + filaments[2 * j + 1]); + new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = (i == j ? 0. : filaments[2 * i] + filaments[2 * j + 1]); } } } else { for (size_t nozzle_id = 0; nozzle_id < nozzle_nums; ++nozzle_id) { - new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = (i == j ? - 0. : - filaments[2 * i] + filaments[2 * j + 1]); + new_matrix[i * num_filaments + j + new_matrix_size * nozzle_id] = (i == j ? 0. : filaments[2 * i] + filaments[2 * j + 1]); } } } @@ -7121,15 +6946,15 @@ void PresetBundle::update_multi_material_filament_presets(size_t to_delete_filam // Preset::normalize_inherits: target.find_preset(name, false) resolves "renamed_from" recursively // and returns nullptr for unknown names, so we rewrite only on a positive, changed match and leave // user/deleted names untouched. -static void normalize_compatible_field(Preset& preset, const char* field_key, PresetCollection& target) +static void normalize_compatible_field(Preset &preset, const char *field_key, PresetCollection &target) { - auto* opt = preset.config.option(field_key); + auto *opt = preset.config.option(field_key); if (opt == nullptr) return; - for (std::string& name : opt->values) { + for (std::string &name : opt->values) { if (name.empty()) continue; - if (const Preset* resolved = target.find_preset(name, false); resolved != nullptr && resolved->name != name) + if (const Preset *resolved = target.find_preset(name, false); resolved != nullptr && resolved->name != name) name = resolved->name; } } @@ -7146,59 +6971,56 @@ void PresetBundle::normalize_compatible_presets() // references a process preset. System presets are normalized too: a vendor profile can itself // reference a sibling preset by a name that was later renamed, and the rewrite is in-memory only // (system presets are never persisted back to vendor JSON). (begin()/end() skip defaults.) - auto normalize = [this](PresetCollection& holders, PresetCollection* processes) { - for (Preset& p : holders) { + auto normalize = [this](PresetCollection &holders, PresetCollection *processes) { + for (Preset &p : holders) { normalize_compatible_field(p, "compatible_printers", this->printers); if (processes != nullptr) normalize_compatible_field(p, "compatible_prints", *processes); } }; - normalize(this->prints, nullptr); - normalize(this->filaments, &this->prints); - normalize(this->sla_prints, nullptr); + normalize(this->prints, nullptr); + normalize(this->filaments, &this->prints); + normalize(this->sla_prints, nullptr); normalize(this->sla_materials, &this->sla_prints); } -void PresetBundle::update_compatible(PresetSelectCompatibleType select_other_print_if_incompatible, - PresetSelectCompatibleType select_other_filament_if_incompatible) +void PresetBundle::update_compatible(PresetSelectCompatibleType select_other_print_if_incompatible, PresetSelectCompatibleType select_other_filament_if_incompatible) { - const Preset& printer_preset = this->printers.get_edited_preset(); - const PresetWithVendorProfile printer_preset_with_vendor_profile = this->printers.get_preset_with_vendor_profile(printer_preset); + const Preset &printer_preset = this->printers.get_edited_preset(); + const PresetWithVendorProfile printer_preset_with_vendor_profile = this->printers.get_preset_with_vendor_profile(printer_preset); class PreferedProfileMatch { public: - PreferedProfileMatch(const std::string& prefered_alias, const std::string& prefered_name) - : m_prefered_alias(prefered_alias), m_prefered_name(prefered_name) - {} + PreferedProfileMatch(const std::string &prefered_alias, const std::string &prefered_name) : + m_prefered_alias(prefered_alias), m_prefered_name(prefered_name) {} - int operator()(const Preset& preset) const + int operator()(const Preset &preset) const { - return preset.is_default || preset.is_external ? - // Don't match any properties of the "-- default --" profile or the external profiles when switching printer profile. - 0 : - !m_prefered_alias.empty() && m_prefered_alias == preset.alias ? - // Matching an alias, always take this preset with priority. - std::numeric_limits::max() : - // Otherwise take the prefered profile, or the first compatible. - preset.name == m_prefered_name; + return + preset.is_default || preset.is_external ? + // Don't match any properties of the "-- default --" profile or the external profiles when switching printer profile. + 0 : + ! m_prefered_alias.empty() && m_prefered_alias == preset.alias ? + // Matching an alias, always take this preset with priority. + std::numeric_limits::max() : + // Otherwise take the prefered profile, or the first compatible. + preset.name == m_prefered_name; } private: - const std::string m_prefered_alias; - const std::string& m_prefered_name; + const std::string m_prefered_alias; + const std::string &m_prefered_name; }; // Matching by the layer height in addition. class PreferedPrintProfileMatch : public PreferedProfileMatch { public: - PreferedPrintProfileMatch(const Preset* preset, const std::string& prefered_name) - : PreferedProfileMatch(preset ? preset->alias : std::string(), prefered_name) - , m_prefered_layer_height(preset ? preset->config.opt_float("layer_height") : 0) - {} + PreferedPrintProfileMatch(const Preset *preset, const std::string &prefered_name) : + PreferedProfileMatch(preset ? preset->alias : std::string(), prefered_name), m_prefered_layer_height(preset ? preset->config.opt_float("layer_height") : 0) {} - int operator()(const Preset& preset) const + int operator()(const Preset &preset) const { // Don't match any properties of the "-- default --" profile or the external profiles when switching printer profile. if (preset.is_default || preset.is_external) @@ -7222,12 +7044,11 @@ void PresetBundle::update_compatible(PresetSelectCompatibleType select_other_pri class PreferedFilamentProfileMatch : public PreferedProfileMatch { public: - PreferedFilamentProfileMatch(const Preset* preset, const std::string& prefered_name) - : PreferedProfileMatch(preset ? preset->alias : std::string(), prefered_name) - , m_prefered_filament_type(preset ? preset->config.opt_string("filament_type", 0) : std::string()) - {} + PreferedFilamentProfileMatch(const Preset *preset, const std::string &prefered_name) : + PreferedProfileMatch(preset ? preset->alias : std::string(), prefered_name), + m_prefered_filament_type(preset ? preset->config.opt_string("filament_type", 0) : std::string()) {} - int operator()(const Preset& preset) const + int operator()(const Preset &preset) const { // Don't match any properties of the "-- default --" profile or the external profiles when switching printer profile. if (preset.is_default || preset.is_external) @@ -7235,9 +7056,9 @@ void PresetBundle::update_compatible(PresetSelectCompatibleType select_other_pri int match_quality = PreferedProfileMatch::operator()(preset); if (match_quality < std::numeric_limits::max()) { match_quality += 1; - if (preset.is_visible) + if(preset.is_visible) match_quality += 1; - if (!m_prefered_filament_type.empty() && m_prefered_filament_type == preset.config.opt_string("filament_type", 0)) + if (! m_prefered_filament_type.empty() && m_prefered_filament_type == preset.config.opt_string("filament_type", 0)) match_quality *= 10; } return match_quality; @@ -7251,141 +7072,118 @@ void PresetBundle::update_compatible(PresetSelectCompatibleType select_other_pri class PreferedFilamentsProfileMatch { public: - PreferedFilamentsProfileMatch(const Preset* preset, const std::vector& prefered_names) - : m_prefered_alias(preset ? preset->alias : std::string()) - , m_prefered_filament_type(preset ? preset->config.opt_string("filament_type", 0) : std::string("PLA")) - , // BBS: default choose PLA + PreferedFilamentsProfileMatch(const Preset *preset, const std::vector &prefered_names) : + m_prefered_alias(preset ? preset->alias : std::string()), + m_prefered_filament_type(preset ? preset->config.opt_string("filament_type", 0) : std::string("PLA")), // BBS: default choose PLA m_prefered_names(prefered_names) - {} + {} - int operator()(const Preset& preset) const + int operator()(const Preset &preset) const { // Don't match any properties of the "-- default --" profile or the external profiles when switching printer profile. if (preset.is_default || preset.is_external || !preset.is_visible) return 0; - if (!m_prefered_alias.empty() && m_prefered_alias == preset.alias) + if (! m_prefered_alias.empty() && m_prefered_alias == preset.alias) // Matching an alias, always take this preset with priority. return std::numeric_limits::max(); int match_quality = (std::find(m_prefered_names.begin(), m_prefered_names.end(), preset.name) != m_prefered_names.end()) + 1; - if (!m_prefered_filament_type.empty() && m_prefered_filament_type == preset.config.opt_string("filament_type", 0)) + if (! m_prefered_filament_type.empty() && m_prefered_filament_type == preset.config.opt_string("filament_type", 0)) match_quality *= 10; return match_quality; } private: - const std::string m_prefered_alias; - const std::string m_prefered_filament_type; - const std::vector& m_prefered_names; + const std::string m_prefered_alias; + const std::string m_prefered_filament_type; + const std::vector &m_prefered_names; }; - BOOST_LOG_TRIVIAL(info) << boost::format("update_compatibility for all presets enter, select_other_print_if_incompatible %1%, " - "select_other_filament_if_incompatible %2%") % - (int) select_other_print_if_incompatible % (int) select_other_filament_if_incompatible; - switch (printer_preset.printer_technology()) { - case ptFFF: { - assert(printer_preset.config.has("default_print_profile")); - assert(printer_preset.config.has("default_filament_profile")); - const std::vector& prefered_filament_profiles = - printer_preset.config.option("default_filament_profile")->values; + BOOST_LOG_TRIVIAL(info) << boost::format("update_compatibility for all presets enter, select_other_print_if_incompatible %1%, select_other_filament_if_incompatible %2%")%(int)select_other_print_if_incompatible %(int)select_other_filament_if_incompatible; + switch (printer_preset.printer_technology()) { + case ptFFF: + { + assert(printer_preset.config.has("default_print_profile")); + assert(printer_preset.config.has("default_filament_profile")); + const std::vector &prefered_filament_profiles = printer_preset.config.option("default_filament_profile")->values; this->prints.update_compatible(printer_preset_with_vendor_profile, nullptr, select_other_print_if_incompatible, - PreferedPrintProfileMatch(this->prints.get_selected_idx() == size_t(-1) ? - nullptr : - &this->prints.get_edited_preset(), - printer_preset.config.opt_string("default_print_profile"))); - const PresetWithVendorProfile print_preset_with_vendor_profile = this->prints.get_edited_preset_with_vendor_profile(); + PreferedPrintProfileMatch(this->prints.get_selected_idx() == size_t(-1) ? nullptr : &this->prints.get_edited_preset(), printer_preset.config.opt_string("default_print_profile"))); + const PresetWithVendorProfile print_preset_with_vendor_profile = this->prints.get_edited_preset_with_vendor_profile(); // Remember whether the filament profiles were compatible before updating the filament compatibility. - std::vector filament_preset_was_compatible(this->filament_presets.size(), false); - for (size_t idx = 0; idx < this->filament_presets.size(); ++idx) { - Preset* preset = this->filaments.find_preset(this->filament_presets[idx], false); + std::vector filament_preset_was_compatible(this->filament_presets.size(), false); + for (size_t idx = 0; idx < this->filament_presets.size(); ++ idx) { + Preset *preset = this->filaments.find_preset(this->filament_presets[idx], false); filament_preset_was_compatible[idx] = preset != nullptr && preset->is_compatible; } // First select a first compatible profile for the preset editor. - BOOST_LOG_TRIVIAL(info) << boost::format("prefered filaments: size %1%, previous selected %2%") % - prefered_filament_profiles.size() % this->filaments.get_selected_idx(); - if (this->filaments.get_selected_idx() != size_t(-1)) { + BOOST_LOG_TRIVIAL(info) << boost::format("prefered filaments: size %1%, previous selected %2%") %prefered_filament_profiles.size() % this->filaments.get_selected_idx(); + if (this->filaments.get_selected_idx() != size_t(-1)) + { BOOST_LOG_TRIVIAL(info) << boost::format("previous selected filament: %1%") % this->filaments.get_edited_preset().name; } for (size_t idx = 0; idx < prefered_filament_profiles.size(); ++idx) { BOOST_LOG_TRIVIAL(info) << boost::format("prefered filament: %1%") % prefered_filament_profiles[idx]; } - this->filaments.update_compatible(printer_preset_with_vendor_profile, &print_preset_with_vendor_profile, - select_other_filament_if_incompatible, - PreferedFilamentsProfileMatch(this->filaments.get_selected_idx() == size_t(-1) ? - nullptr : - &this->filaments.get_edited_preset(), - prefered_filament_profiles)); + this->filaments.update_compatible(printer_preset_with_vendor_profile, &print_preset_with_vendor_profile, select_other_filament_if_incompatible, + PreferedFilamentsProfileMatch(this->filaments.get_selected_idx() == size_t(-1) ? nullptr : &this->filaments.get_edited_preset(), prefered_filament_profiles)); if (select_other_filament_if_incompatible != PresetSelectCompatibleType::Never) { // Verify validity of the current filament presets. - const std::string prefered_filament_profile = prefered_filament_profiles.empty() ? std::string() : - prefered_filament_profiles.front(); + const std::string prefered_filament_profile = prefered_filament_profiles.empty() ? std::string() : prefered_filament_profiles.front(); if (this->filament_presets.size() == 1) { // The compatible profile should have been already selected for the preset editor. Just use it. - if (select_other_filament_if_incompatible == PresetSelectCompatibleType::Always || filament_preset_was_compatible.front()) - this->filament_presets.front() = this->filaments.get_edited_preset().name; + if (select_other_filament_if_incompatible == PresetSelectCompatibleType::Always || filament_preset_was_compatible.front()) + this->filament_presets.front() = this->filaments.get_edited_preset().name; } else { - for (size_t idx = 0; idx < this->filament_presets.size(); ++idx) { - std::string& filament_name = this->filament_presets[idx]; - Preset* preset = this->filaments.find_preset(filament_name, false); - if (preset == nullptr || - (!preset->is_compatible && (select_other_filament_if_incompatible == PresetSelectCompatibleType::Always || - filament_preset_was_compatible[idx]))) + for (size_t idx = 0; idx < this->filament_presets.size(); ++ idx) { + std::string &filament_name = this->filament_presets[idx]; + Preset *preset = this->filaments.find_preset(filament_name, false); + if (preset == nullptr || (! preset->is_compatible && (select_other_filament_if_incompatible == PresetSelectCompatibleType::Always || filament_preset_was_compatible[idx]))) // Pick a compatible profile. If there are prefered_filament_profiles, use them. - filament_name = this->filaments - .first_compatible( - PreferedFilamentProfileMatch(preset, (idx < prefered_filament_profiles.size()) ? - prefered_filament_profiles[idx] : - prefered_filament_profile)) - .name; + filament_name = this->filaments.first_compatible( + PreferedFilamentProfileMatch(preset, + (idx < prefered_filament_profiles.size()) ? prefered_filament_profiles[idx] : prefered_filament_profile)).name; } } } - break; + break; } - case ptSLA: { - assert(printer_preset.config.has("default_sla_print_profile")); - assert(printer_preset.config.has("default_sla_material_profile")); - this->sla_prints.update_compatible(printer_preset_with_vendor_profile, nullptr, select_other_print_if_incompatible, - PreferedPrintProfileMatch(this->sla_prints.get_selected_idx() == size_t(-1) ? - nullptr : - &this->sla_prints.get_edited_preset(), - printer_preset.config.opt_string("default_sla_print_profile"))); + case ptSLA: + { + assert(printer_preset.config.has("default_sla_print_profile")); + assert(printer_preset.config.has("default_sla_material_profile")); + this->sla_prints.update_compatible(printer_preset_with_vendor_profile, nullptr, select_other_print_if_incompatible, + PreferedPrintProfileMatch(this->sla_prints.get_selected_idx() == size_t(-1) ? nullptr : &this->sla_prints.get_edited_preset(), printer_preset.config.opt_string("default_sla_print_profile"))); const PresetWithVendorProfile sla_print_preset_with_vendor_profile = this->sla_prints.get_edited_preset_with_vendor_profile(); - this->sla_materials.update_compatible(printer_preset_with_vendor_profile, &sla_print_preset_with_vendor_profile, - select_other_filament_if_incompatible, - PreferedProfileMatch(this->sla_materials.get_selected_idx() == size_t(-1) ? - std::string() : - this->sla_materials.get_edited_preset().alias, - printer_preset.config.opt_string("default_sla_material_profile"))); - break; - } + this->sla_materials.update_compatible(printer_preset_with_vendor_profile, &sla_print_preset_with_vendor_profile, select_other_filament_if_incompatible, + PreferedProfileMatch(this->sla_materials.get_selected_idx() == size_t(-1) ? std::string() : this->sla_materials.get_edited_preset().alias, printer_preset.config.opt_string("default_sla_material_profile"))); + break; + } default: break; } BOOST_LOG_TRIVIAL(info) << boost::format("update_compatibility for all presets exit"); } -std::vector PresetBundle::export_current_configs(const std::string& path, - std::function override_confirm, - bool include_modify, - bool export_system_settings) + +std::vector PresetBundle::export_current_configs(const std::string & path, + std::function override_confirm, + bool include_modify, + bool export_system_settings) { - const Preset& print_preset = include_modify ? prints.get_edited_preset() : prints.get_selected_preset(); - const Preset& printer_preset = include_modify ? printers.get_edited_preset() : printers.get_selected_preset(); - std::set presets{&print_preset, &printer_preset}; - for (auto& f : filament_presets) { + const Preset &print_preset = include_modify ? prints.get_edited_preset() : prints.get_selected_preset(); + const Preset &printer_preset = include_modify ? printers.get_edited_preset() : printers.get_selected_preset(); + std::set presets { &print_preset, &printer_preset }; + for (auto &f : filament_presets) { auto filament_preset = filaments.find_preset(f, include_modify); - if (filament_preset) - presets.insert(filament_preset); + if (filament_preset) presets.insert(filament_preset); } int overwrite = 0; std::vector result; for (auto preset : presets) { - if ((preset->is_system && !export_system_settings) || preset->is_default) + if ((preset->is_system && !export_system_settings) || preset->is_default) continue; std::string file = path + "/" + preset->name + ".json"; - if (overwrite == 0) - overwrite = 1; + if (overwrite == 0) overwrite = 1; if (boost::filesystem::exists(file) && overwrite < 2) { overwrite = override_confirm(preset->name); if (overwrite == 0 || overwrite == 2) @@ -7399,7 +7197,7 @@ std::vector PresetBundle::export_current_configs(const std::string& // Set the filament preset name. As the name could come from the UI selection box, // an optional "(modified)" suffix will be removed from the filament name. -void PresetBundle::set_filament_preset(size_t idx, const std::string& name) +void PresetBundle::set_filament_preset(size_t idx, const std::string &name) { if (idx >= filament_presets.size()) { BOOST_LOG_TRIVIAL(warning) << boost::format("Warning: set_filament_preset out of range %1% - %2%") % idx % filament_presets.size(); @@ -7428,7 +7226,7 @@ bool PresetBundle::has_errors(bool check_duplicate_filament_subtypes) const if (!preset.is_system) continue; // It's per design that the Orca Filament Library can have the empty compatible_printers. - if (preset.vendor->name == PresetBundle::ORCA_FILAMENT_LIBRARY) + if(preset.vendor->name == PresetBundle::ORCA_FILAMENT_LIBRARY) continue; auto* compatible_printers = dynamic_cast(preset.config.option("compatible_printers")); if (compatible_printers == nullptr || compatible_printers->values.empty()) { @@ -7451,7 +7249,7 @@ bool PresetBundle::has_errors(bool check_duplicate_filament_subtypes) const // VS Code integrated terminal (Cmd/Ctrl+click) and macOS Terminal.app // (Cmd+double-click); quotes or literal spaces break link detection in both, so // the characters that would terminate the URI token are percent-encoded. -static std::string preset_file_uri(const std::string& file) +static std::string preset_file_uri(const std::string &file) { std::string path; try { @@ -7467,7 +7265,7 @@ static std::string preset_file_uri(const std::string& file) case ' ': uri += "%20"; break; case '#': uri += "%23"; break; case '%': uri += "%25"; break; - default: uri += c; + default: uri += c; } } return uri; @@ -7489,34 +7287,34 @@ bool PresetBundle::check_preset_references() const // Resolve one reference (an inherits parent or a compatible_* entry) against its target // collection and log if it is dangling (unknown) or uses a renamed preset's old name. - auto report_ref = [&](const Preset& p, const std::string& name, const PresetCollection& target, const char* verb, const char* noun) { - const Preset* resolved = target.find_preset(name, false); + auto report_ref = [&](const Preset &p, const std::string &name, const PresetCollection &target, + const char *verb, const char *noun) { + const Preset *resolved = target.find_preset(name, false); if (resolved == nullptr) { found = true; BOOST_LOG_TRIVIAL(error) << "Preset \"" << p.name << "\" " << verb << " unknown " << noun << " \"" << name << "\":\n" << preset_file_uri(p.file); } else if (resolved->name != name) { found = true; - BOOST_LOG_TRIVIAL(error) << "Preset \"" << p.name << "\" " << verb << " renamed " << noun << " \"" << name << "\" (now \"" - << resolved->name << "\"):\n" - << preset_file_uri(p.file); + BOOST_LOG_TRIVIAL(error) << "Preset \"" << p.name << "\" " << verb << " renamed " << noun << " \"" << name + << "\" (now \"" << resolved->name << "\"):\n" << preset_file_uri(p.file); } }; - auto check_list = [&](const Preset& p, const char* key, const PresetCollection& target) { - const auto* opt = p.config.option(key); + auto check_list = [&](const Preset &p, const char *key, const PresetCollection &target) { + const auto *opt = p.config.option(key); if (opt == nullptr) return; - for (const std::string& name : opt->values) + for (const std::string &name : opt->values) if (!name.empty()) report_ref(p, name, target, "references", key); }; - auto check_collection = [&](const PresetCollection& holders, const PresetCollection* processes) { - for (const Preset& p : holders) { + auto check_collection = [&](const PresetCollection &holders, const PresetCollection *processes) { + for (const Preset &p : holders) { if (!p.is_system) continue; - if (const std::string& inh = p.inherits(); !inh.empty()) + if (const std::string &inh = p.inherits(); !inh.empty()) report_ref(p, inh, holders, "inherits", "parent"); check_list(p, "compatible_printers", this->printers); if (processes != nullptr) @@ -7526,10 +7324,10 @@ bool PresetBundle::check_preset_references() const // Printers carry no compatible_printers/compatible_prints (those name a printer, so a printer // holding them makes no sense); check_list is a no-op for them, so only their inherits is checked. - check_collection(this->printers, nullptr); - check_collection(this->prints, nullptr); - check_collection(this->filaments, &this->prints); - check_collection(this->sla_prints, nullptr); + check_collection(this->printers, nullptr); + check_collection(this->prints, nullptr); + check_collection(this->filaments, &this->prints); + check_collection(this->sla_prints, nullptr); check_collection(this->sla_materials, &this->sla_prints); return found; @@ -7547,15 +7345,15 @@ bool PresetBundle::check_duplicate_filament_subtypes() const // printer against its own vendor's filaments. A vendor's compatible_printers // only names that vendor's printers, so same-vendor scoping is correctness // preserving and avoids an O(all printers x all filaments) sweep. - std::map> filaments_by_vendor; - for (const auto& preset : filaments) { + std::map> filaments_by_vendor; + for (const auto &preset : filaments) { if (!preset.is_system || preset.filament_id.empty() || preset.vendor == nullptr) continue; filaments_by_vendor[preset.vendor->name].push_back(&preset); } bool found_duplicates = false; - for (const auto& printer : printers) { + for (const auto &printer : printers) { if (!printer.is_system || printer.vendor == nullptr) continue; auto vendor_it = filaments_by_vendor.find(printer.vendor->name); @@ -7564,39 +7362,40 @@ bool PresetBundle::check_duplicate_filament_subtypes() const const PresetWithVendorProfile active_printer = printers.get_preset_with_vendor_profile(printer); // std::map keeps the reported errors in a deterministic (sorted) order. - std::map> by_filament_id; - for (const Preset* fil : vendor_it->second) + std::map> by_filament_id; + for (const Preset *fil : vendor_it->second) if (is_compatible_with_printer(filaments.get_preset_with_vendor_profile(*fil), active_printer)) by_filament_id[fil->filament_id].push_back(fil); - for (const auto& entry : by_filament_id) { + for (const auto &entry : by_filament_id) { if (entry.second.size() < 2) continue; found_duplicates = true; // List each conflicting preset with a clickable file:// URI on its own // line, so the profile author can jump straight to the files to fix. std::string presets; - for (const Preset* p : entry.second) + for (const Preset *p : entry.second) presets += "\n - " + p->name + "\n " + preset_file_uri(p->file); - BOOST_LOG_TRIVIAL(error) << "Ambiguous AMS filament match: " << entry.second.size() << " filament presets share filament_id \"" - << entry.first << "\" and are all compatible with printer \"" << printer.name - << "\". When matching an AMS spool the slicer cannot tell them apart and" - " silently picks whichever loads first." - << presets; + BOOST_LOG_TRIVIAL(error) + << "Ambiguous AMS filament match: " << entry.second.size() + << " filament presets share filament_id \"" << entry.first + << "\" and are all compatible with printer \"" << printer.name + << "\". When matching an AMS spool the slicer cannot tell them apart and" + " silently picks whichever loads first." << presets; } } // Print the troubleshooting guidance once, not per error, to keep the log readable. if (found_duplicates) BOOST_LOG_TRIVIAL(error) << "\n========================================\n" - << "How to fix \"Ambiguous AMS filament match\" errors: make sure only ONE filament" - " preset with a given filament_id is compatible with each printer. Either" - "\n (a) remove the overlapping printer from a preset's \"compatible_printers\"" - " list (e.g. a '@printer' preset over-claiming a nozzle that already has its own" - " '@printer 0.x nozzle' preset), or" - "\n (b) if these are genuinely different materials, give each its own" - " \"filament_id\" - a common cause is a wrong \"inherits\" pointing at another" - " material's @base preset."; + << "How to fix \"Ambiguous AMS filament match\" errors: make sure only ONE filament" + " preset with a given filament_id is compatible with each printer. Either" + "\n (a) remove the overlapping printer from a preset's \"compatible_printers\"" + " list (e.g. a '@printer' preset over-claiming a nozzle that already has its own" + " '@printer 0.x nozzle' preset), or" + "\n (b) if these are genuinely different materials, give each its own" + " \"filament_id\" - a common cause is a wrong \"inherits\" pointing at another" + " material's @base preset."; return found_duplicates; } @@ -7612,39 +7411,30 @@ bool BundleMetadata::load_from_json(const std::string& path) json j; ifs >> j; - if (j.contains("id")) - this->id = j["id"].get(); + if (j.contains("id")) this->id = j["id"].get(); - if (j.contains("name")) - this->name = j["name"].get(); - else if (j.contains("bundle_id")) - this->name = j["bundle_id"].get(); // backwards compat w bundle_structure.json + if (j.contains("name")) this->name = j["name"].get(); + else if (j.contains("bundle_id")) this->name = j["bundle_id"].get(); // backwards compat w bundle_structure.json - if (j.contains("version")) - this->version = j["version"].get(); + if (j.contains("version")) this->version = j["version"].get(); - if (j.contains("description")) - this->description = j["description"].get(); - else if (j.contains("bundle_type")) - this->description = j["bundle_type"].get(); // backwards compat w bundle_structure.json + if (j.contains("description")) this->description = j["description"].get(); + else if (j.contains("bundle_type")) this->description = j["bundle_type"].get(); // backwards compat w bundle_structure.json - if (j.contains("author")) - this->author = j["author"].get(); + if (j.contains("author")) this->author = j["author"].get(); - if (j.contains("imported_time")) - this->imported_time = j["imported_time"].get(); + if (j.contains("imported_time")) this->imported_time = j["imported_time"].get(); - if (j.contains("updated_time")) - this->updated_time = j["updated_time"].get(); + if (j.contains("updated_time")) this->updated_time = j["updated_time"].get(); - if (j.contains("print_presets")) - this->print_presets = j["print_presets"].get>(); - - if (j.contains("filament_presets")) - this->filament_presets = j["filament_presets"].get>(); - - if (j.contains("printer_presets")) - this->printer_presets = j["printer_presets"].get>(); + if (j.contains("print_presets")) + this->print_presets = j["print_presets"].get>(); + + if (j.contains("filament_presets")) + this->filament_presets = j["filament_presets"].get>(); + + if (j.contains("printer_presets")) + this->printer_presets = j["printer_presets"].get>(); return true; } catch (const std::exception& e) { @@ -7656,26 +7446,27 @@ bool BundleMetadata::load_from_json(const std::string& path) bool BundleMetadata::save_to_json(const std::string& path) const { auto strip_prefix = [](const std::vector& names) { - json arr = json::array(); - for (const auto& name : names) { - arr.push_back(boost::filesystem::path(name).filename().string()); - std::string test = boost::filesystem::path(name).filename().string(); - } - return arr; - }; + json arr = json::array(); + for (const auto& name : names) + { + arr.push_back(boost::filesystem::path(name).filename().string()); + std::string test = boost::filesystem::path(name).filename().string(); + } + return arr; + }; try { json j; - j["id"] = this->id; - j["name"] = this->name; - j["version"] = this->version; - j["description"] = this->description; - j["author"] = this->author; + j["id"] = this->id; + j["name"] = this->name; + j["version"] = this->version; + j["description"] = this->description; + j["author"] = this->author; j["imported_time"] = this->imported_time; - j["updated_time"] = this->updated_time; + j["updated_time"] = this->updated_time; - j["print_presets"] = strip_prefix(this->print_presets); - j["filament_presets"] = strip_prefix(this->filament_presets); - j["printer_presets"] = strip_prefix(this->printer_presets); + j["print_presets"] = strip_prefix(this->print_presets); + j["filament_presets"] = strip_prefix(this->filament_presets); + j["printer_presets"] = strip_prefix(this->printer_presets); boost::nowide::ofstream ofs(path); ofs << j.dump(4); @@ -7696,14 +7487,13 @@ bool PresetBundle::load_vendor_cache(const boost::filesystem::path& dir, const s // of the installation, against nothing, since nothing on disk can then be // newer than it. That state is Semver::inf(), which no real profile carries. const boost::filesystem::path profile = dir / (vendor_name + ".json"); - const Semver version = boost::filesystem::exists(profile) ? get_version_from_json(profile.string()) : Semver::inf(); + const Semver version = boost::filesystem::exists(profile) ? get_version_from_json(profile.string()) + : Semver::inf(); return this->load_vendor_cache((dir / (vendor_name + ".opc")).string(), vendor_name, version, base_bundle); } -bool PresetBundle::load_vendor_cache(const std::string& cache_path, - const std::string& expected_vendor_name, - const Semver& expected_vendor_version, - const PresetBundle* base_bundle) +bool PresetBundle::load_vendor_cache(const std::string& cache_path, const std::string& expected_vendor_name, + const Semver& expected_vendor_version, const PresetBundle* base_bundle) { // What this bundle had counted before the cache was tried. The caller // measures its own parse against this same baseline, so a rejection must @@ -7712,11 +7502,11 @@ bool PresetBundle::load_vendor_cache(const std::string& cache_path, // Read and validated before this bundle is touched: a rejected file leaves // no state to roll back. VendorCacheData data; - if (!VendorCacheFile::load(cache_path, expected_vendor_name, expected_vendor_version, data)) + if (! VendorCacheFile::load(cache_path, expected_vendor_name, expected_vendor_version, data)) return false; try { - const std::string& vendor_name = expected_vendor_name; // VendorCacheFile::load checked they match - this->vendors = std::move(data.vendors); + const std::string& vendor_name = expected_vendor_name; // VendorCacheFile::load checked they match + this->vendors = std::move(data.vendors); // What the parse counted before install took over; install recounts its // own below, so m_errors comes out as a JSON parse would leave it. @@ -7726,13 +7516,13 @@ bool PresetBundle::load_vendor_cache(const std::string& cache_path, // them straight after parsing — same code, same order. The substitution // context stays empty (the entries were substituted when they were // parsed), so no substitutions are reported, as before. - ConfigSubstitutionContext substitution_context{ForwardCompatibilitySubstitutionRule::EnableSilent}; + ConfigSubstitutionContext substitution_context { ForwardCompatibilitySubstitutionRule::EnableSilent }; PresetsConfigSubstitutions substitutions; std::map configs; std::map filament_id_maps; const std::string path = boost::filesystem::path(cache_path).parent_path().string(); - size_t count = 0; - auto install_entries = [&](const std::vector& entries, PresetCollection* presets, bool is_from_lib) { + size_t count = 0; + auto install_entries = [&](const std::vector& entries, PresetCollection* presets, bool is_from_lib) { configs.clear(); filament_id_maps.clear(); // Only configs of presets that other entries inherit are ever looked @@ -7741,14 +7531,14 @@ bool PresetBundle::load_vendor_cache(const std::string& cache_path, // become the m_config_maps other vendors resolve against. std::set inherited; for (const CachedPreset& entry : entries) - if (!entry.inherits.empty()) + if (! entry.inherits.empty()) inherited.insert(entry.inherits); const std::set* retain_configs = is_from_lib ? nullptr : &inherited; for (const CachedPreset& entry : entries) { - const std::string reason = load_vendor_preset(entry, path, vendor_name, base_bundle, LoadConfigBundleAttribute::LoadSystem, - substitution_context, substitutions, configs, filament_id_maps, presets, - count, is_from_lib, retain_configs); - if (!reason.empty()) + const std::string reason = load_vendor_preset(entry, path, vendor_name, + base_bundle, LoadConfigBundleAttribute::LoadSystem, substitution_context, substitutions, + configs, filament_id_maps, presets, count, is_from_lib, retain_configs); + if (! reason.empty()) throw std::runtime_error("entry " + entry.name + " failed to install: " + reason); } }; diff --git a/src/libslic3r/PublishSettings.cpp b/src/libslic3r/PublishSettings.cpp index c4c71f9436..6d28cc0af3 100644 --- a/src/libslic3r/PublishSettings.cpp +++ b/src/libslic3r/PublishSettings.cpp @@ -19,6 +19,27 @@ std::string publish_base_key(const std::string &key) return pos == std::string::npos ? key : key.substr(0, pos); } +// Parse the trailing "#N" variant index ("retraction_length#2" -> 2). Returns -1 when the key +// carries no '#' separator or its suffix is malformed; mirrors the importer's strict parse +// (PresetBundle.cpp) so the export side rejects the same variants the receiver would skip. +static int publish_variant_index(const std::string &key, const std::string &base_key) +{ + if (key.size() <= base_key.size() || key.compare(0, base_key.size(), base_key) != 0 || key[base_key.size()] != '#') + return -1; + const std::string suffix = key.substr(base_key.size() + 1); + if (suffix.empty()) + return -1; + int idx = 0; + for (const char c : suffix) { + if (c < '0' || c > '9') + return -1; + idx = idx * 10 + (c - '0'); + if (idx > 1000000) // overflow guard; real vector sizes are tiny + return -1; + } + return idx; +} + std::string normalize_filament_type(const std::string& type) { if (type.empty()) @@ -174,8 +195,8 @@ DynamicPrintConfig filter_published_config( DynamicPrintConfig filtered; std::set base_keys_to_include; - // Never masked (whole-vector serialization): identity, plate geometry and process/printer - // keys. + // Never masked (whole-vector serialization): identity, plate geometry, process keys and + // printer keys without a "#N" variant. std::set mask_exempt_keys; // Material entries: base key -> author slots whose values must survive; other slots are // masked to their defaults so a publish (partial or full) does not leak unrelated slot @@ -209,12 +230,23 @@ DynamicPrintConfig filter_published_config( mask_exempt_keys.insert(key); } - // 3. Process and printer published keys + // 3. Process and printer published keys. Printer per-extruder keys carry a "#N" variant + // (e.g. retraction_length#2): mask the base to the author's extruder index so a partial + // publish does not serialize every extruder's value (same slot-masking as the material side). + const std::set &printer_keys = publishable_printer_keys(); for (const std::string &key : published_keys) { const std::string base_key = publish_base_key(key); - if (!base_key.empty()) { - base_keys_to_include.insert(base_key); - mask_exempt_keys.insert(base_key); + if (base_key.empty()) + continue; + base_keys_to_include.insert(base_key); + if (printer_keys.count(base_key) != 0) { + const int variant_idx = publish_variant_index(key, base_key); + if (variant_idx >= 0) + slot_mask_map[base_key].insert(variant_idx); + else + mask_exempt_keys.insert(base_key); // bare printer key or malformed variant: whole vector + } else { + mask_exempt_keys.insert(base_key); // process key: whole vector } } diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index 044771bf7c..2ee875901c 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -3343,17 +3343,7 @@ size_t NotificationManager::get_notification_count() const void NotificationManager::bbl_show_plateinfo_notification(const std::string &text) { NotificationData data{NotificationType::BBLPlateInfo, NotificationLevel::PrintInfoNotificationLevel, BBL_NOTICE_MAX_INTERVAL, text}; - - for (std::unique_ptr ¬ification : m_pop_notifications) { - if (notification->get_type() == NotificationType::BBLPlateInfo) { - notification->reinit(); - notification->update(data); - return; - } - } - - auto notification = std::make_unique(data, m_id_provider, m_evt_handler); - push_notification_data(std::move(notification), 0); + push_notification_data(data, 0); } void NotificationManager::bbl_close_3mf_warn_notification() @@ -3367,17 +3357,7 @@ void NotificationManager::bbl_close_3mf_warn_notification() void NotificationManager::bbl_show_3mf_warn_notification(const std::string &text, NotificationLevel level) { NotificationData data{NotificationType::BBL3MFInfo, level, BBL_NOTICE_MAX_INTERVAL, text}; - - for (std::unique_ptr ¬ification : m_pop_notifications) { - if (notification->get_type() == NotificationType::BBL3MFInfo) { - notification->reinit(); - notification->update(data); - return; - } - } - - auto notification = std::make_unique(data, m_id_provider, m_evt_handler); - push_notification_data(std::move(notification), 0); + push_notification_data(data, 0); } void NotificationManager::bbl_close_plateinfo_notification() @@ -3392,17 +3372,7 @@ void NotificationManager::bbl_close_plateinfo_notification() void NotificationManager::bbl_show_preview_only_notification(const std::string &text) { NotificationData data{NotificationType::BBLPreviewOnlyMode, NotificationLevel::WarningNotificationLevel, 0, text}; - - for (std::unique_ptr ¬ification : m_pop_notifications) { - if (notification->get_type() == NotificationType::BBLPreviewOnlyMode) { - notification->reinit(); - notification->update(data); - return; - } - } - - auto notification = std::make_unique(data, m_id_provider, m_evt_handler); - push_notification_data(std::move(notification), 0); + push_notification_data(data, 0); } void NotificationManager::bbl_close_preview_only_notification() diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 55d10dd95c..cb65524dac 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -1083,7 +1083,10 @@ private: NotificationType::ProgressBar, NotificationType::PrintHostUpload, NotificationType::SimplifySuggestion, - NotificationType::ValidateWarning + NotificationType::ValidateWarning, + // A published file load can produce several distinct 3MF warnings (invalid values, + // skipped settings, changed slots); let them stack rather than clobber each other. + NotificationType::BBL3MFInfo }; //prepared (basic) notifications // non-static so its not loaded too early. If static, the translations wont load correctly. diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 86f3626eaa..0d2c5ac4c9 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -61,7 +61,7 @@ #include "libslic3r/Format/DRC.hpp" #include "libslic3r/Format/STEP.hpp" #include "libslic3r/Format/AMF.hpp" -// #include "libslic3r/Format/3mf.hpp" +//#include "libslic3r/Format/3mf.hpp" #include "libslic3r/Format/bbs_3mf.hpp" #include "libslic3r/GCode/ThumbnailData.hpp" #include "libslic3r/Model.hpp" @@ -128,11 +128,11 @@ #include "NotificationManager.hpp" #include "PresetComboBoxes.hpp" #include "MsgDialog.hpp" -#include "Widgets/MultiNozzleSync.hpp" // NozzleOption, tryPopUpMultiNozzleDialog, setExtruderNozzleCount -#include "DeviceCore/DevNozzleSystem.h" // DevNozzle, GetExtNozzles / GetRackNozzles +#include "Widgets/MultiNozzleSync.hpp" // NozzleOption, tryPopUpMultiNozzleDialog, setExtruderNozzleCount +#include "DeviceCore/DevNozzleSystem.h" // DevNozzle, GetExtNozzles / GetRackNozzles #include "ProjectDirtyStateManager.hpp" #include "Gizmos/GLGizmoSimplify.hpp" // create suggestion notification -#include "Gizmos/GLGizmoSVG.hpp" // Drop SVG file +#include "Gizmos/GLGizmoSVG.hpp" // Drop SVG file #include "Gizmos/GizmoObjectManipulation.hpp" // BBS @@ -155,7 +155,7 @@ #endif // __APPLE__ #include -#include // Needs to be last because reasons :-/ +#include // Needs to be last because reasons :-/ #include #include "WipeTowerDialog.hpp" #include "MixedFilamentDialog.hpp" @@ -195,9 +195,10 @@ using Slic3r::Preset; using Slic3r::GUI::format_wxstr; using namespace nlohmann; -static const std::pair THUMBNAIL_SIZE_3MF = {512, 512}; +static const std::pair THUMBNAIL_SIZE_3MF = { 512, 512 }; -namespace Slic3r { namespace GUI { +namespace Slic3r { +namespace GUI { // A textured mesh is only worth routing through the import dialog when it actually carries // decoded image data; UV-only meshes have nothing to sample. @@ -210,37 +211,37 @@ static bool has_importable_texture(const Slic3r::TexturedMesh& textured_mesh) return true; return std::any_of(textured_mesh.textures.begin(), textured_mesh.textures.end(), - [](const Slic3r::TextureImage& texture) { return !texture.data.empty(); }); + [](const Slic3r::TextureImage& texture) { return !texture.data.empty(); }); } -wxDEFINE_EVENT(EVT_SCHEDULE_BACKGROUND_PROCESS, SimpleEvent); -wxDEFINE_EVENT(EVT_SLICING_UPDATE, SlicingStatusEvent); -wxDEFINE_EVENT(EVT_SLICING_COMPLETED, wxCommandEvent); -wxDEFINE_EVENT(EVT_PROCESS_COMPLETED, SlicingProcessCompletedEvent); -wxDEFINE_EVENT(EVT_EXPORT_BEGAN, wxCommandEvent); -wxDEFINE_EVENT(EVT_EXPORT_FINISHED, wxCommandEvent); -wxDEFINE_EVENT(EVT_IMPORT_MODEL_ID, wxCommandEvent); -wxDEFINE_EVENT(EVT_DOWNLOAD_PROJECT, wxCommandEvent); -wxDEFINE_EVENT(EVT_PUBLISH, wxCommandEvent); -wxDEFINE_EVENT(EVT_OPEN_PLATESETTINGSDIALOG, wxCommandEvent); +wxDEFINE_EVENT(EVT_SCHEDULE_BACKGROUND_PROCESS, SimpleEvent); +wxDEFINE_EVENT(EVT_SLICING_UPDATE, SlicingStatusEvent); +wxDEFINE_EVENT(EVT_SLICING_COMPLETED, wxCommandEvent); +wxDEFINE_EVENT(EVT_PROCESS_COMPLETED, SlicingProcessCompletedEvent); +wxDEFINE_EVENT(EVT_EXPORT_BEGAN, wxCommandEvent); +wxDEFINE_EVENT(EVT_EXPORT_FINISHED, wxCommandEvent); +wxDEFINE_EVENT(EVT_IMPORT_MODEL_ID, wxCommandEvent); +wxDEFINE_EVENT(EVT_DOWNLOAD_PROJECT, wxCommandEvent); +wxDEFINE_EVENT(EVT_PUBLISH, wxCommandEvent); +wxDEFINE_EVENT(EVT_OPEN_PLATESETTINGSDIALOG, wxCommandEvent); wxDEFINE_EVENT(EVT_OPEN_FILAMENT_MAP_SETTINGS_DIALOG, wxCommandEvent); // BBS: backup & restore -wxDEFINE_EVENT(EVT_RESTORE_PROJECT, wxCommandEvent); -wxDEFINE_EVENT(EVT_PRINT_FINISHED, wxCommandEvent); -wxDEFINE_EVENT(EVT_SEND_CALIBRATION_FINISHED, wxCommandEvent); -wxDEFINE_EVENT(EVT_SEND_FINISHED, wxCommandEvent); -wxDEFINE_EVENT(EVT_PUBLISH_FINISHED, wxCommandEvent); -// BBS: repair model -wxDEFINE_EVENT(EVT_REPAIR_MODEL, wxCommandEvent); -wxDEFINE_EVENT(EVT_FILAMENT_COLOR_CHANGED, wxCommandEvent); -wxDEFINE_EVENT(EVT_INSTALL_PLUGIN_NETWORKING, wxCommandEvent); -wxDEFINE_EVENT(EVT_UPDATE_PLUGINS_WHEN_LAUNCH, wxCommandEvent); -wxDEFINE_EVENT(EVT_INSTALL_PLUGIN_HINT, wxCommandEvent); -wxDEFINE_EVENT(EVT_PREVIEW_ONLY_MODE_HINT, wxCommandEvent); -// BBS: change light/dark mode -wxDEFINE_EVENT(EVT_GLCANVAS_COLOR_MODE_CHANGED, SimpleEvent); -// BBS: print -wxDEFINE_EVENT(EVT_PRINT_FROM_SDCARD_VIEW, SimpleEvent); +wxDEFINE_EVENT(EVT_RESTORE_PROJECT, wxCommandEvent); +wxDEFINE_EVENT(EVT_PRINT_FINISHED, wxCommandEvent); +wxDEFINE_EVENT(EVT_SEND_CALIBRATION_FINISHED, wxCommandEvent); +wxDEFINE_EVENT(EVT_SEND_FINISHED, wxCommandEvent); +wxDEFINE_EVENT(EVT_PUBLISH_FINISHED, wxCommandEvent); +//BBS: repair model +wxDEFINE_EVENT(EVT_REPAIR_MODEL, wxCommandEvent); +wxDEFINE_EVENT(EVT_FILAMENT_COLOR_CHANGED, wxCommandEvent); +wxDEFINE_EVENT(EVT_INSTALL_PLUGIN_NETWORKING, wxCommandEvent); +wxDEFINE_EVENT(EVT_UPDATE_PLUGINS_WHEN_LAUNCH, wxCommandEvent); +wxDEFINE_EVENT(EVT_INSTALL_PLUGIN_HINT, wxCommandEvent); +wxDEFINE_EVENT(EVT_PREVIEW_ONLY_MODE_HINT, wxCommandEvent); +//BBS: change light/dark mode +wxDEFINE_EVENT(EVT_GLCANVAS_COLOR_MODE_CHANGED, SimpleEvent); +//BBS: print +wxDEFINE_EVENT(EVT_PRINT_FROM_SDCARD_VIEW, SimpleEvent); wxDEFINE_EVENT(EVT_CREATE_FILAMENT, SimpleEvent); wxDEFINE_EVENT(EVT_MODIFY_FILAMENT, SimpleEvent); @@ -250,31 +251,32 @@ wxDEFINE_EVENT(EVT_ADD_CUSTOM_FILAMENT, ColorEvent); wxDEFINE_EVENT(EVT_NOTICE_CHILDE_SIZE_CHANGED, SimpleEvent); wxDEFINE_EVENT(EVT_NOTICE_FULL_SCREEN_CHANGED, IntEvent); #define PRINTER_THUMBNAIL_SIZE (wxSize(40, 40)) // ORCA -#define PRINTER_PANEL_SIZE (wxSize(70, 60)) // ORCA -#define PRINTER_PANEL_RADIUS (6) // ORCA +#define PRINTER_PANEL_SIZE ( wxSize(70, 60)) // ORCA +#define PRINTER_PANEL_RADIUS (6) // ORCA #define BTN_SYNC_SIZE (wxSize(FromDIP(96), FromDIP(98))) static string get_diameter_string(float diameter) { std::ostringstream stream; // ORCA ensure 0.25 returned as 0.25. previous code returned as 0.2 because of std::setprecision(1) - stream << std::fixed << std::setprecision(2) << diameter; // Use 2 decimals to capture 0.25 / 0.15 reliably + stream << std::fixed << std::setprecision(2) << diameter; // Use 2 decimals to capture 0.25 / 0.15 reliably std::string s = stream.str(); - if (s.find('.') != std::string::npos) { // Remove trailing zeros, but keep at least one decimal if needed + if (s.find('.') != std::string::npos) { // Remove trailing zeros, but keep at least one decimal if needed s.erase(s.find_last_not_of('0') + 1); - if (s.back() == '.') - s += '0'; // Ensure "1." → "1.0" + if (s.back() == '.') s += '0'; // Ensure "1." → "1.0" } return s; } -template static void set_config_values(DynamicPrintConfig* config, const std::string& key, T value) +template +static void set_config_values(DynamicPrintConfig *config, const std::string &key, T value) { auto config_opt = config->option(key); if (config_opt) { for (size_t i = 0; i < config_opt->values.size(); ++i) { config_opt->values[i] = value; } - } else { + } + else { BOOST_LOG_TRIVIAL(info) << "set_config_values: the key" << key << "is empty."; } } @@ -296,22 +298,36 @@ bool Plater::has_illegal_filename_characters(const std::string& name) } void Plater::show_illegal_characters_warning(wxWindow* parent) -{ show_error(parent, _L("Invalid name, the following characters are not allowed:") + " <>:/\\|?*\""); } +{ + show_error(parent, _L("Invalid name, the following characters are not allowed:") + " <>:/\\|?*\""); +} -void Plater::mark_plate_toolbar_image_dirty() { m_b_plate_toolbar_image_dirty = true; } +void Plater::mark_plate_toolbar_image_dirty() +{ + m_b_plate_toolbar_image_dirty = true; +} -bool Plater::is_plate_toolbar_image_dirty() const { return m_b_plate_toolbar_image_dirty; } +bool Plater::is_plate_toolbar_image_dirty() const +{ + return m_b_plate_toolbar_image_dirty; +} -void Plater::clear_plate_toolbar_image_dirty() { m_b_plate_toolbar_image_dirty = false; } +void Plater::clear_plate_toolbar_image_dirty() +{ + m_b_plate_toolbar_image_dirty = false; +} -static std::map bed_type_thumbnails = {{BedType::btPC, "bed_cool"}, - {BedType::btEP, "bed_engineering"}, - {BedType::btPEI, "bed_high_templ"}, - {BedType::btPTE, "bed_pei"}, - {BedType::btPCT, "bed_pei_cool"}, - {BedType::btSuperTack, "bed_cool_supertack"}}; +static std::map bed_type_thumbnails = { + {BedType::btPC, "bed_cool" }, + {BedType::btEP, "bed_engineering" }, + {BedType::btPEI, "bed_high_templ" }, + {BedType::btPTE, "bed_pei" }, + {BedType::btPCT, "bed_pei_cool" }, + {BedType::btSuperTack, "bed_cool_supertack" } +}; -enum SlicedInfoIdx { +enum SlicedInfoIdx +{ siFilament_m, siFilament_mm3, siFilament_g, @@ -331,30 +347,37 @@ enum class LoadFilesType { Multiple3MFOther, }; -enum class LoadType : unsigned char { Unknown, OpenProject, LoadGeometry, LoadConfig }; +enum class LoadType : unsigned char +{ + Unknown, + OpenProject, + LoadGeometry, + LoadConfig +}; class SlicedInfo : public wxStaticBoxSizer { public: - SlicedInfo(wxWindow* parent); - void SetTextAndShow(SlicedInfoIdx idx, const wxString& text, const wxString& new_label = ""); + SlicedInfo(wxWindow *parent); + void SetTextAndShow(SlicedInfoIdx idx, const wxString& text, const wxString& new_label=""); private: std::vector> info_vec; }; -SlicedInfo::SlicedInfo(wxWindow* parent) : wxStaticBoxSizer(new wxStaticBox(parent, wxID_ANY, _L("Sliced Info")), wxVERTICAL) +SlicedInfo::SlicedInfo(wxWindow *parent) : + wxStaticBoxSizer(new wxStaticBox(parent, wxID_ANY, _L("Sliced Info")), wxVERTICAL) { GetStaticBox()->SetFont(wxGetApp().bold_font()); wxGetApp().UpdateDarkUI(GetStaticBox()); - auto* grid_sizer = new wxFlexGridSizer(2, 5, 15); + auto *grid_sizer = new wxFlexGridSizer(2, 5, 15); grid_sizer->SetFlexibleDirection(wxVERTICAL); info_vec.reserve(siCount); auto init_info_label = [this, parent, grid_sizer](wxString text_label) { - auto* text = new wxStaticText(parent, wxID_ANY, text_label); + auto *text = new wxStaticText(parent, wxID_ANY, text_label); text->SetForegroundColour(*wxBLACK); text->SetFont(wxGetApp().small_font()); auto info_label = new wxStaticText(parent, wxID_ANY, "N/A"); @@ -377,7 +400,7 @@ SlicedInfo::SlicedInfo(wxWindow* parent) : wxStaticBoxSizer(new wxStaticBox(pare this->Show(false); } -void SlicedInfo::SetTextAndShow(SlicedInfoIdx idx, const wxString& text, const wxString& new_label /*=""*/) +void SlicedInfo::SetTextAndShow(SlicedInfoIdx idx, const wxString& text, const wxString& new_label/*=""*/) { const bool show = text != "N/A"; if (show) @@ -402,8 +425,9 @@ wxString sanitize_window_layout_for_wayland(const wxString& layout, bool* remove } static const std::regex state_pattern(R"(state=(\d+);)"); - constexpr unsigned int disabled_wayland_flags = static_cast(wxAuiPaneInfo::optionFloating) | - static_cast(wxAuiPaneInfo::optionFloatable); + constexpr unsigned int disabled_wayland_flags = + static_cast(wxAuiPaneInfo::optionFloating) | + static_cast(wxAuiPaneInfo::optionFloatable); const std::string input = layout.utf8_string(); std::string output; @@ -417,9 +441,9 @@ wxString sanitize_window_layout_for_wayland(const wxString& layout, bool* remove output.append(search_start, match[0].first); try { - const unsigned long state = std::stoul(match[1].str()); + const unsigned long state = std::stoul(match[1].str()); const unsigned long sanitized_state = state & ~static_cast(disabled_wayland_flags); - modified = modified || sanitized_state != state; + modified = modified || sanitized_state != state; output += "state=" + std::to_string(sanitized_state) + ";"; } catch (const std::exception&) { @@ -442,7 +466,11 @@ wxString sanitize_window_layout_for_wayland(const wxString& layout, bool* remove // Sidebar / private -enum class ActionButtonType : int { abReslice, abExport, abSendGCode }; +enum class ActionButtonType : int { + abReslice, + abExport, + abSendGCode +}; // Background for the extruder-group title chip and its edit buttons, matching the StaticGroup // interior. macOS keeps a lighter #F7F7F7 tint in light mode; dark mode uses the mapped colour. @@ -461,7 +489,7 @@ static wxColour extruder_group_chip_bg() class HoverLabel : public wxPanel { public: - HoverLabel(wxWindow* parent, const wxString& label) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE) + HoverLabel(wxWindow *parent, const wxString &label) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE) { SetBackgroundColour(extruder_group_chip_bg()); auto sizer = new wxBoxSizer(wxHORIZONTAL); @@ -488,7 +516,7 @@ public: m_hover_btn = new ScalableButton(this, wxID_ANY, "dot"); m_hover_btn->SetMinSize(wxSize(FromDIP(25), -1)); m_hover_btn->SetBackgroundColour(extruder_group_chip_bg()); - m_hover_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](auto& evt) { + m_hover_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](auto &evt) { if (m_enabled && m_hover_on_click) m_hover_on_click(); }); @@ -529,7 +557,7 @@ public: UpdateSizing(); } - void SetTitle(const wxString& title) + void SetTitle(const wxString &title) { m_label->SetLabel(title); UpdateSizing(); @@ -542,7 +570,7 @@ public: { SetBackgroundColour(extruder_group_chip_bg()); m_label->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#6B6B6B"))); - for (wxStaticText* t : {m_brace_left, m_count, m_brace_right}) + for (wxStaticText *t : {m_brace_left, m_count, m_brace_right}) t->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#262E30"))); m_hover_btn->SetBackgroundColour(extruder_group_chip_bg()); Refresh(); @@ -560,36 +588,36 @@ private: GetParent()->Layout(); } - wxStaticText* m_label; - wxStaticText* m_brace_left; - wxStaticText* m_count; - wxStaticText* m_brace_right; - ScalableButton* m_hover_btn; + wxStaticText *m_label; + wxStaticText *m_brace_left; + wxStaticText *m_count; + wxStaticText *m_brace_right; + ScalableButton *m_hover_btn; std::function m_hover_on_click; - bool m_enabled{false}; + bool m_enabled{false}; }; struct ExtruderGroup : StaticGroup { - ExtruderGroup(wxWindow* parent, int index, wxString const& title); - wxStaticBoxSizer* sizer = nullptr; - HoverLabel* hover_label = nullptr; - ScalableButton* btn_edit = nullptr; - ComboBox* combo_diameter = nullptr; - ComboBox* combo_flow = nullptr; - AMSPreview* ams[4] = {nullptr}; - wxStaticText* ams_not_installed_msg{nullptr}; - ScalableButton* btn_up{nullptr}; - ScalableButton* btn_down{nullptr}; - wxBoxSizer* hsizer_ams{nullptr}; - size_t page_cur{0}; - size_t page_num{3}; - size_t ams_n4 = 0; - size_t ams_n1 = 0; + ExtruderGroup(wxWindow * parent, int index, wxString const &title); + wxStaticBoxSizer *sizer = nullptr; + HoverLabel * hover_label = nullptr; + ScalableButton * btn_edit = nullptr; + ComboBox * combo_diameter = nullptr; + ComboBox * combo_flow = nullptr; + AMSPreview * ams[4] = {nullptr}; + wxStaticText *ams_not_installed_msg{nullptr}; + ScalableButton * btn_up{nullptr}; + ScalableButton * btn_down{nullptr}; + wxBoxSizer *hsizer_ams { nullptr }; + size_t page_cur{0}; + size_t page_num{3}; + size_t ams_n4 = 0; + size_t ams_n1 = 0; std::vector ams_4; std::vector ams_1; - wxString diameter; + wxString diameter; void set_ams_count(int n4, int n1) { @@ -604,23 +632,11 @@ struct ExtruderGroup : StaticGroup void update_ams(); void SetTitle(const wxString& title); - void SetCount(int count) - { - if (hover_label) - hover_label->SetCount(count); - } - void SetEditEnabled(bool enable) - { - if (hover_label) - hover_label->EnableEdit(enable); - } - void SetOnHoverClick(std::function on_click) - { - if (hover_label) - hover_label->SetOnHoverClick(std::move(on_click)); - } + void SetCount(int count) { if (hover_label) hover_label->SetCount(count); } + void SetEditEnabled(bool enable) { if (hover_label) hover_label->EnableEdit(enable); } + void SetOnHoverClick(std::function on_click) { if (hover_label) hover_label->SetOnHoverClick(std::move(on_click)); } - void sync_ams(MachineObject const* obj, std::vector const& ams4, std::vector const& ams1); + void sync_ams(MachineObject const *obj, std::vector const &ams4, std::vector const &ams1); void Rescale() { @@ -648,70 +664,70 @@ struct ExtruderGroup : StaticGroup struct Sidebar::priv { - Plater* plater; + Plater *plater; - wxPanel* scrolled = nullptr; - PlaterPresetComboBox* combo_sla_print = nullptr; - PlaterPresetComboBox* combo_sla_material = nullptr; + wxPanel *scrolled = nullptr; + PlaterPresetComboBox *combo_sla_print = nullptr; + PlaterPresetComboBox *combo_sla_material = nullptr; // Printer - wxSizer* vsizer_printer = nullptr; - wxBoxSizer* extruder_dual_sizer = nullptr; - wxBoxSizer* extruder_single_sizer = nullptr; + wxSizer * vsizer_printer = nullptr; + wxBoxSizer * extruder_dual_sizer = nullptr; + wxBoxSizer * extruder_single_sizer = nullptr; // Printer - preset - StaticBox* panel_printer_preset = nullptr; - wxStaticBitmap* image_printer = nullptr; - PlaterPresetComboBox* combo_printer = nullptr; - ScalableButton* btn_edit_printer = nullptr; - ScalableButton* btn_connect_printer = nullptr; + StaticBox * panel_printer_preset = nullptr; + wxStaticBitmap * image_printer = nullptr; + PlaterPresetComboBox *combo_printer = nullptr; + ScalableButton * btn_edit_printer = nullptr; + ScalableButton * btn_connect_printer = nullptr; // Nozzle diameter - StaticBox* panel_nozzle_dia = nullptr; - Label* label_nozzle_title = nullptr; - ComboBox* combo_nozzle_dia = nullptr; - Label* label_nozzle_type = nullptr; + StaticBox * panel_nozzle_dia = nullptr; + Label * label_nozzle_title= nullptr; + ComboBox * combo_nozzle_dia = nullptr; + Label * label_nozzle_type = nullptr; // Printer - bed - StaticBox* panel_printer_bed = nullptr; - wxStaticBitmap* image_printer_bed = nullptr; - ComboBox* combo_printer_bed = nullptr; + StaticBox * panel_printer_bed = nullptr; + wxStaticBitmap *image_printer_bed = nullptr; + ComboBox * combo_printer_bed = nullptr; - ImageDPIFrame* big_bed_image_popup = nullptr; + ImageDPIFrame *big_bed_image_popup = nullptr; // Printer - sync - // Button *btn_sync_printer; + //Button *btn_sync_printer; std::shared_ptr counter_sync_printer = std::make_shared(); - wxTimer* timer_sync_printer = new wxTimer(); + wxTimer * timer_sync_printer = new wxTimer(); // Printer - ams - ExtruderGroup* left_extruder = nullptr; - ExtruderGroup* right_extruder = nullptr; - ExtruderGroup* single_extruder = nullptr; + ExtruderGroup *left_extruder = nullptr; + ExtruderGroup *right_extruder = nullptr; + ExtruderGroup *single_extruder = nullptr; - int FromDIP(int n) { return plater->FromDIP(n); } + int FromDIP(int n) { return plater->FromDIP(n); } void layout_printer(bool isBBL, bool isDual); void flush_printer_sync(bool restart = false); - PlaterPresetComboBox* combo_print = nullptr; + PlaterPresetComboBox *combo_print = nullptr; std::vector combos_filament; - int editing_filament = -1; - wxBoxSizer* sizer_filaments = nullptr; + int editing_filament = -1; + wxBoxSizer *sizer_filaments = nullptr; - // BBS Sidebar widgets + //BBS Sidebar widgets wxPanel* m_panel_print_title; wxStaticText* m_staticText_print_title; wxPanel* m_panel_print_content; - wxBoxSizer* sizer_params; + wxBoxSizer *sizer_params; - // wxComboBox * m_comboBox_print_preset; - wxStaticLine* m_staticline1; + //wxComboBox * m_comboBox_print_preset; + wxStaticLine * m_staticline1; StaticBox* m_panel_filament_title; - wxPanel* m_panel_filament_separator; + wxPanel* m_panel_filament_separator; wxStaticText* m_staticText_filament_settings; wxStaticText* m_staticText_filament_count; - ScalableButton* m_bpButton_add_filament; - ScalableButton* m_bpButton_del_filament; - ScalableButton* m_bpButton_ams_filament; - ScalableButton* m_bpButton_set_filament; + ScalableButton * m_bpButton_add_filament; + ScalableButton * m_bpButton_del_filament; + ScalableButton * m_bpButton_ams_filament; + ScalableButton * m_bpButton_set_filament; int m_menu_filament_id = -1; wxPanel* m_filament_area_wrapper; @@ -721,63 +737,63 @@ struct Sidebar::priv // Mixed-color filament section. Sits directly under the physical filament list in // scrolled_sizer. BBS hosts the equivalent widgets inside an m_filament_area_wrapper // that Orca's sidebar has no counterpart for, so these are parented to p->scrolled. - wxPanel* m_btn_add_mixed_filament{nullptr}; // "+ Add Mixed Filament" full-width button - wxPanel* m_panel_mixed_title{nullptr}; // title row: "Mixed Filament" + add/del buttons - wxStaticText* m_text_mixed_title{nullptr}; - ScalableButton* m_btn_mixed_add{nullptr}; - ScalableButton* m_btn_mixed_del{nullptr}; - wxScrolledWindow* m_mixed_scroll_area{nullptr}; // independent scrollbar for mixed rows - wxPanel* m_panel_mixed_content{nullptr}; - wxBoxSizer* m_sizer_mixed_filaments{nullptr}; // two-column, mirrors sizer_filaments - wxPanel* m_panel_mixed_warning{nullptr}; // red bar for broken/mismatched mixes - wxStaticText* m_text_mixed_warning{nullptr}; - bool m_mixed_filament_broken{false}; + wxPanel* m_btn_add_mixed_filament{nullptr}; // "+ Add Mixed Filament" full-width button + wxPanel* m_panel_mixed_title{nullptr}; // title row: "Mixed Filament" + add/del buttons + wxStaticText* m_text_mixed_title{nullptr}; + ScalableButton* m_btn_mixed_add{nullptr}; + ScalableButton* m_btn_mixed_del{nullptr}; + wxScrolledWindow* m_mixed_scroll_area{nullptr}; // independent scrollbar for mixed rows + wxPanel* m_panel_mixed_content{nullptr}; + wxBoxSizer* m_sizer_mixed_filaments{nullptr}; // two-column, mirrors sizer_filaments + wxPanel* m_panel_mixed_warning{nullptr}; // red bar for broken/mismatched mixes + wxStaticText* m_text_mixed_warning{nullptr}; + bool m_mixed_filament_broken{false}; wxScrolledWindow* m_scrolledWindow_filament_content; wxStaticLine* m_staticline2; wxPanel* m_panel_project_title; ScalableButton* m_filament_icon = nullptr; - Button* m_purge_mode_btn = nullptr; - Button* m_flushing_volume_btn = nullptr; - TextInput* m_search_item = nullptr; - StaticBox* m_search_bar = nullptr; + Button * m_purge_mode_btn = nullptr; + Button * m_flushing_volume_btn = nullptr; + TextInput* m_search_item = nullptr; + StaticBox* m_search_bar = nullptr; Search::SearchObjectDialog* dia = nullptr; // BBS printer config - StaticBox* m_panel_printer_title = nullptr; - wxPanel* m_panel_printer_separator = nullptr; - ScalableButton* m_printer_icon = nullptr; - ScalableButton* m_printer_connect = nullptr; - ScalableButton* m_printer_bbl_sync = nullptr; - ScalableButton* m_printer_setting = nullptr; - wxStaticText* m_text_printer_settings = nullptr; - wxPanel* m_panel_printer_content = nullptr; + StaticBox* m_panel_printer_title = nullptr; + wxPanel* m_panel_printer_separator = nullptr; + ScalableButton* m_printer_icon = nullptr; + ScalableButton* m_printer_connect = nullptr; + ScalableButton* m_printer_bbl_sync = nullptr; + ScalableButton* m_printer_setting = nullptr; + wxStaticText * m_text_printer_settings = nullptr; + wxPanel* m_panel_printer_content = nullptr; // Filament Track Switch status overlay: an icon floated over the left/single extruder AMS area, // shown only when the switch is installed (green when ready, red when not calibrated). wxStaticBitmap* extruder_separator_icon = nullptr; - ObjectList* m_object_list{nullptr}; - ObjectSettings* object_settings{nullptr}; - ObjectLayers* object_layers{nullptr}; + ObjectList *m_object_list{ nullptr }; + ObjectSettings *object_settings{ nullptr }; + ObjectLayers *object_layers{ nullptr }; - wxButton* btn_export_gcode; - wxButton* btn_reslice; - ScalableButton* btn_send_gcode; - // ScalableButton *btn_eject_device; - ScalableButton* btn_export_gcode_removable; // exports to removable drives (appears only if removable drive is connected) + wxButton *btn_export_gcode; + wxButton *btn_reslice; + ScalableButton *btn_send_gcode; + //ScalableButton *btn_eject_device; + ScalableButton* btn_export_gcode_removable; //exports to removable drives (appears only if removable drive is connected) - bool is_switching_diameter{false}; - Search::OptionsSearcher searcher; + bool is_switching_diameter{false}; + Search::OptionsSearcher searcher; std::string ams_list_device; - priv(Plater* plater) : plater(plater) {} + priv(Plater *plater) : plater(plater) {} ~priv(); void show_preset_comboboxes(); void jump_to_object(ObjectDataViewModelNode* item); void can_search(); - bool sync_extruder_list(bool& only_external_material, bool is_manual = false); + bool sync_extruder_list(bool &only_external_material, bool is_manual = false); // Resolve the nozzle option for a multi-nozzle machine. Returns nullopt (and is a no-op) unless // extruder_count >= 2 && support_multi_nozzle. When is_manual, always pops the MultiNozzleSyncDialog; // otherwise reuses the app_config-cached option when the machine's nozzle config is unchanged. @@ -808,16 +824,17 @@ struct Sidebar::priv void Sidebar::priv::layout_printer(bool isBBL, bool isDual) { // Printer - preset - if (auto sizer = static_cast(panel_printer_preset->GetSizer()); - sizer == nullptr /*|| isBBL != (sizer->GetOrientation() == wxVERTICAL)*/) { - // if (isBBL) { - wxBoxSizer* hsizer = new wxBoxSizer(wxHORIZONTAL); - hsizer->Add(image_printer, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, FromDIP(10)); - hsizer->Add(combo_printer, 1, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(2)); // 1 already triggers wxEXPAND - hsizer->AddSpacer(FromDIP(2)); - hsizer->Add(btn_edit_printer, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(SidebarProps::IconSpacing())); - // hsizer->Add(btn_connect_printer, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(SidebarProps::IconSpacing())); - panel_printer_preset->SetSizer(hsizer); + if (auto sizer = static_cast(panel_printer_preset->GetSizer()); + sizer == nullptr /*|| isBBL != (sizer->GetOrientation() == wxVERTICAL)*/) { + + //if (isBBL) { + wxBoxSizer *hsizer = new wxBoxSizer(wxHORIZONTAL); + hsizer->Add(image_printer, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, FromDIP(10)); + hsizer->Add(combo_printer, 1, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(2)); // 1 already triggers wxEXPAND + hsizer->AddSpacer(FromDIP(2)); + hsizer->Add(btn_edit_printer, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(SidebarProps::IconSpacing())); + //hsizer->Add(btn_connect_printer, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, FromDIP(SidebarProps::IconSpacing())); + panel_printer_preset->SetSizer(hsizer); //} else { // wxBoxSizer *hsizer = new wxBoxSizer(wxHORIZONTAL); // hsizer->Add(image_printer, 0, wxLEFT | wxALIGN_CENTER, FromDIP(4)); @@ -829,11 +846,11 @@ void Sidebar::priv::layout_printer(bool isBBL, bool isDual) } if (vsizer_printer->GetItemCount() == 0) { - wxBoxSizer* hsizer_printer = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *hsizer_printer = new wxBoxSizer(wxHORIZONTAL); hsizer_printer->Add(panel_printer_preset, 1, wxEXPAND, 0); - hsizer_printer->Add(panel_nozzle_dia, 0, wxLEFT, FromDIP(4)); + hsizer_printer->Add(panel_nozzle_dia , 0, wxLEFT, FromDIP(4)); hsizer_printer->Add(panel_printer_bed, 0, wxLEFT, FromDIP(4)); - // hsizer_printer->Add(btn_sync_printer , 0, wxLEFT, FromDIP(4)); + //hsizer_printer->Add(btn_sync_printer , 0, wxLEFT, FromDIP(4)); vsizer_printer->AddSpacer(FromDIP(SidebarProps::ContentMarginV())); vsizer_printer->Add(hsizer_printer, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(SidebarProps::ContentMargin())); @@ -848,9 +865,8 @@ void Sidebar::priv::layout_printer(bool isBBL, bool isDual) // Filament Track Switch status icon, floated over the extruder AMS area (positioned in // update_extruder_separator_icon). Created hidden; a click re-shows the ready/not-ready tip. if (!extruder_separator_icon) { - auto bitmap = ScalableBitmap(m_panel_printer_content, "fila_switch", 10); - extruder_separator_icon = new wxStaticBitmap(m_panel_printer_content, wxID_ANY, bitmap.bmp(), wxDefaultPosition, - bitmap.GetBmpSize()); + auto bitmap = ScalableBitmap(m_panel_printer_content, "fila_switch", 10); + extruder_separator_icon = new wxStaticBitmap(m_panel_printer_content, wxID_ANY, bitmap.bmp(), wxDefaultPosition, bitmap.GetBmpSize()); extruder_separator_icon->Hide(); extruder_separator_icon->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& evt) { show_fila_switch_msg(is_fila_switch_ready()); @@ -859,9 +875,9 @@ void Sidebar::priv::layout_printer(bool isBBL, bool isDual) } // single - extruder_single_sizer = single_extruder->sizer; - wxBoxSizer* extruder_sizer = new wxBoxSizer(wxVERTICAL); - extruder_sizer->Add(extruder_dual_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(SidebarProps::ContentMargin())); + extruder_single_sizer = single_extruder->sizer; + wxBoxSizer * extruder_sizer = new wxBoxSizer(wxVERTICAL); + extruder_sizer->Add(extruder_dual_sizer , 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(SidebarProps::ContentMargin())); extruder_sizer->Add(extruder_single_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(SidebarProps::ContentMargin())); vsizer_printer->Add(extruder_sizer, 1, wxEXPAND | wxTOP, FromDIP(2)); @@ -869,14 +885,14 @@ void Sidebar::priv::layout_printer(bool isBBL, bool isDual) vsizer_printer->AddSpacer(FromDIP(SidebarProps::ContentMarginV())); } - // btn_connect_printer->Show(!isBBL); + //btn_connect_printer->Show(!isBBL); m_printer_connect->Show(!isBBL); - // btn_sync_printer->Show(isBBL); + //btn_sync_printer->Show(isBBL); m_printer_bbl_sync->Show(isBBL); // ORCA show plate type combo box only when its supported - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; - const auto& cfg = preset_bundle.printers.get_edited_preset().config; + PresetBundle &preset_bundle = *wxGetApp().preset_bundle; + const auto& cfg = preset_bundle.printers.get_edited_preset().config; // Orca: we use preset_bundle.is_bbl_vendor() instead of isBBL to determine if the plate type combo box should be shown // ref: https://github.com/OrcaSlicer/OrcaSlicer/pull/11610#discussion_r2607411847 panel_printer_bed->Show(preset_bundle.is_bbl_vendor() || cfg.opt_bool("support_multi_bed_types")); @@ -887,7 +903,7 @@ void Sidebar::priv::layout_printer(bool isBBL, bool isDual) // Single nozzle & non ams if (!isDual) { // Orca: for printer without flow variant, we do not show flow combo - int extruder_count = 0; + int extruder_count = 0; const bool has_flow_variant = cfg.support_different_extruders(extruder_count); panel_nozzle_dia->Show(!has_flow_variant); @@ -899,9 +915,9 @@ void Sidebar::priv::layout_printer(bool isBBL, bool isDual) // ORCA ensure printer section is visible after changing printer from printer selection dialog // this will inform user on printer change when printer section is collapsed - if (m_panel_printer_content) { + if (m_panel_printer_content){ bool isShown = m_panel_printer_content->IsShown(); - if (!isShown && m_text_printer_settings) { + if(!isShown && m_text_printer_settings){ m_text_printer_settings->SetLabel(_L("Printer")); // ensure title returns to default state m_panel_printer_content->Show(); } @@ -914,7 +930,7 @@ void Sidebar::priv::flush_printer_sync(bool restart) *counter_sync_printer = 6; timer_sync_printer->Start(500); } - // btn_sync_printer->SetBackgroundColorNormal((*counter_sync_printer & 1) ? "#F8F8F8" :"#009688"); + //btn_sync_printer->SetBackgroundColorNormal((*counter_sync_printer & 1) ? "#F8F8F8" :"#009688"); m_printer_bbl_sync->SetBitmap_((*counter_sync_printer & 1) ? "printer_sync_not" : "printer_sync_ok"); if (--*counter_sync_printer <= 0) timer_sync_printer->Stop(); @@ -923,7 +939,7 @@ void Sidebar::priv::flush_printer_sync(bool restart) Sidebar::priv::~priv() { // BBS - // delete object_manipulation; + //delete object_manipulation; delete object_settings; // BBS #if 0 @@ -935,7 +951,7 @@ void Sidebar::priv::show_preset_comboboxes() { const bool showSLA = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA; -// BBS +//BBS #if 0 for (size_t i = 0; i < 4; ++i) sizer_presets->Show(i, !showSLA); @@ -952,7 +968,10 @@ void Sidebar::priv::show_preset_comboboxes() scrolled->Refresh(); } -void Sidebar::priv::jump_to_object(ObjectDataViewModelNode* item) { m_object_list->selected_object(item); } +void Sidebar::priv::jump_to_object(ObjectDataViewModelNode* item) +{ + m_object_list->selected_object(item); +} void Sidebar::priv::can_search() { @@ -1003,75 +1022,61 @@ void Sidebar::priv::hide_rich_tip(wxButton* btn) } #endif -std::vector get_min_flush_volumes(const DynamicPrintConfig& full_config, size_t nozzle_id) +std::vector get_min_flush_volumes(const DynamicPrintConfig &full_config, size_t nozzle_id) { - std::vector extra_flush_volumes; - // const auto& full_config = wxGetApp().preset_bundle->full_config(); - // auto& printer_config = wxGetApp().preset_bundle->printers.get_edited_preset().config; + std::vectorextra_flush_volumes; + //const auto& full_config = wxGetApp().preset_bundle->full_config(); + //auto& printer_config = wxGetApp().preset_bundle->printers.get_edited_preset().config; const ConfigOptionFloatsNullable* nozzle_volume_opt = full_config.option("nozzle_volume"); - int nozzle_volume_val = nozzle_volume_opt ? (int) nozzle_volume_opt->get_at(nozzle_id) : 0; + int nozzle_volume_val = nozzle_volume_opt ? (int)nozzle_volume_opt->get_at(nozzle_id) : 0; const ConfigOptionInt* enable_long_retraction_when_cut_opt = full_config.option("enable_long_retraction_when_cut"); - int machine_enabled_level = 0; + int machine_enabled_level = 0; if (enable_long_retraction_when_cut_opt) { machine_enabled_level = enable_long_retraction_when_cut_opt->value; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": get enable_long_retraction_when_cut from config, value=%1%") % machine_enabled_level; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get enable_long_retraction_when_cut from config, value=%1%")%machine_enabled_level; } const ConfigOptionBools* long_retractions_when_cut_opt = full_config.option("long_retractions_when_cut"); - bool machine_activated = false; + bool machine_activated = false; if (long_retractions_when_cut_opt) { machine_activated = long_retractions_when_cut_opt->values[nozzle_id] == 1; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": get long_retractions_when_cut from config, value=%1%, activated=%2%") % - long_retractions_when_cut_opt->values[0] % machine_activated; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get long_retractions_when_cut from config, value=%1%, activated=%2%")%long_retractions_when_cut_opt->values[0] %machine_activated; } size_t filament_size = full_config.option("filament_diameter")->values.size(); - std::vector filament_retraction_distance_when_cut(filament_size, 18.0f), - printer_retraction_distance_when_cut(filament_size, 18.0f); + std::vector filament_retraction_distance_when_cut(filament_size, 18.0f), printer_retraction_distance_when_cut(filament_size, 18.0f); std::vector filament_long_retractions_when_cut(filament_size, 0); - const ConfigOptionFloats* filament_retraction_distances_when_cut_opt = full_config.option( - "filament_retraction_distances_when_cut"); + const ConfigOptionFloats* filament_retraction_distances_when_cut_opt = full_config.option("filament_retraction_distances_when_cut"); if (filament_retraction_distances_when_cut_opt) { filament_retraction_distance_when_cut = filament_retraction_distances_when_cut_opt->values; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": get filament_retraction_distance_when_cut from config, size=%1%, values=%2%") % - filament_retraction_distance_when_cut.size() % - filament_retraction_distances_when_cut_opt->serialize(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get filament_retraction_distance_when_cut from config, size=%1%, values=%2%")%filament_retraction_distance_when_cut.size() %filament_retraction_distances_when_cut_opt->serialize(); } - const ConfigOptionFloats* printer_retraction_distance_when_cut_opt = full_config.option( - "retraction_distances_when_cut"); + const ConfigOptionFloats* printer_retraction_distance_when_cut_opt = full_config.option("retraction_distances_when_cut"); if (printer_retraction_distance_when_cut_opt) { printer_retraction_distance_when_cut = printer_retraction_distance_when_cut_opt->values; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": get retraction_distances_when_cut from config, size=%1%, values=%2%") % - printer_retraction_distance_when_cut.size() % printer_retraction_distance_when_cut_opt->serialize(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get retraction_distances_when_cut from config, size=%1%, values=%2%")%printer_retraction_distance_when_cut.size() %printer_retraction_distance_when_cut_opt->serialize(); } - const ConfigOptionBools* filament_long_retractions_when_cut_opt = full_config.option( - "filament_long_retractions_when_cut"); + const ConfigOptionBools* filament_long_retractions_when_cut_opt = full_config.option("filament_long_retractions_when_cut"); if (filament_long_retractions_when_cut_opt) { filament_long_retractions_when_cut = filament_long_retractions_when_cut_opt->values; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": get filament_long_retractions_when_cut from config, size=%1%, values=%2%") % - filament_long_retractions_when_cut.size() % filament_long_retractions_when_cut_opt->serialize(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": get filament_long_retractions_when_cut from config, size=%1%, values=%2%")%filament_long_retractions_when_cut.size() %filament_long_retractions_when_cut_opt->serialize(); } for (size_t idx = 0; idx < filament_size; ++idx) { int extra_flush_volume = nozzle_volume_val; - int retract_length = machine_enabled_level && machine_activated ? printer_retraction_distance_when_cut[nozzle_id] : 0; + int retract_length = machine_enabled_level && machine_activated ? printer_retraction_distance_when_cut[nozzle_id] : 0; unsigned char filament_activated = filament_long_retractions_when_cut[idx]; - double filament_retract_length = filament_retraction_distance_when_cut[idx]; + double filament_retract_length = filament_retraction_distance_when_cut[idx]; if (filament_activated == 0) retract_length = 0; else if (filament_activated == 1 && machine_enabled_level == LongRectrationLevel::EnableFilament) { if (!std::isnan(filament_retract_length)) - retract_length = (int) filament_retraction_distance_when_cut[idx]; + retract_length = (int)filament_retraction_distance_when_cut[idx]; else retract_length = printer_retraction_distance_when_cut[nozzle_id]; } @@ -1092,20 +1097,20 @@ struct DynamicFilamentList : DynamicList // physical-only list for all of its keys. explicit DynamicFilamentList(bool physical_only = false) : physical_only(physical_only) {} bool physical_only; - std::vector> items; + std::vector> items; std::vector slot_map{0}; // combo index -> 1-based filament slot; slot_map[0] = 0 is "Default" - void apply_on(Choice* c) override + void apply_on(Choice *c) override { if (!c) return; if (items.empty()) update(true); - auto cb = dynamic_cast(c->window); + auto cb = dynamic_cast(c->window); if (!cb) return; wxString old_selection = cb->GetStringSelection(); - int old_index = cb->GetSelection(); + int old_index = cb->GetSelection(); // slot_map is already rebuilt here: restoring through it keeps the index of every slot // still listed and sends a vanished slot to the fallback below. int old_slot = old_index >= 0 && old_index < int(slot_map.size()) ? slot_map[old_index] : -1; @@ -1152,7 +1157,7 @@ struct DynamicFilamentList : DynamicList slot_map.assign(1, 0); if (!force && m_choices.empty()) return; - auto icons = get_extruder_color_icons(true); + auto icons = get_extruder_color_icons(true); auto presets = wxGetApp().preset_bundle->filament_presets; for (int i = 0; i < presets.size(); ++i) { if (physical_only && wxGetApp().preset_bundle->is_mixed_filament(i)) @@ -1176,7 +1181,10 @@ static bool has_junction_deviation(const DynamicPrintConfig* printer_config) } const auto gcode_flavor = printer_config->option>("gcode_flavor"); const auto junction_dev = printer_config->option("machine_max_junction_deviation"); - return gcode_flavor && gcode_flavor->value == GCodeFlavor::gcfMarlinFirmware && junction_dev && !junction_dev->values.empty() && + return gcode_flavor && + gcode_flavor->value == GCodeFlavor::gcfMarlinFirmware && + junction_dev && + !junction_dev->values.empty() && junction_dev->values.front() > 0.0; } @@ -1186,22 +1194,21 @@ static DynamicFilamentList dynamic_physical_filament_list(true); // physical slo class AMSCountPopupWindow : public PopupWindow { public: - AMSCountPopupWindow(ExtruderGroup* extruder, int index) : PopupWindow(extruder, wxBORDER_NONE | wxPU_CONTAINS_CONTROLS) + AMSCountPopupWindow(ExtruderGroup *extruder, int index) + : PopupWindow(extruder, wxBORDER_NONE | wxPU_CONTAINS_CONTROLS) { SetBackgroundColour(*wxWHITE); - auto msg = new wxStaticText(this, wxID_ANY, _L("Set the number of AMS installed on the nozzle.")); + auto msg = new wxStaticText(this, wxID_ANY, _L("Set the number of AMS installed on the nozzle.")); msg->SetFont(Label::Body_14); msg->SetForegroundColour("#262E30"); msg->Wrap(FromDIP(280)); auto box = new StaticBox(this, wxID_ANY); box->SetBackgroundColor(0xF8F8F8); box->SetBorderWidth(0); - auto img4 = new ScalableButton(box, wxID_ANY, "ams_4_tray", {}, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, - false, 44); - // img4->SetBackgroundColour(*wxWHITE); - auto img1 = new ScalableButton(box, wxID_ANY, "ams_1_tray", {}, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, - false, 44); - // img1->SetBackgroundColour(*wxWHITE); + auto img4 = new ScalableButton(box, wxID_ANY, "ams_4_tray", {}, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, false, 44); + //img4->SetBackgroundColour(*wxWHITE); + auto img1 = new ScalableButton(box, wxID_ANY, "ams_1_tray", {}, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, false, 44); + //img1->SetBackgroundColour(*wxWHITE); auto txt4 = new wxStaticText(box, wxID_ANY, _L("AMS(4 slots)")); txt4->SetFont(Label::Body_14); txt4->SetBackgroundColour(0xF8F8F8); @@ -1216,28 +1223,28 @@ public: GetAMSCount(1 - index, oth4, oth1); auto val4 = new SpinInput(box, {}, {}, wxDefaultPosition, {FromDIP(60), -1}, 0, 0, 4 - oth4, ams4); auto val1 = new SpinInput(box, {}, {}, wxDefaultPosition, {FromDIP(60), -1}, 0, 0, 8 - oth1, ams1); - auto event_handler = [index, val4, val1, extruder](auto& evt) { + auto event_handler = [index, val4, val1, extruder](auto &evt) { SetAMSCount(index, val4->GetValue(), val1->GetValue()); UpdateAMSCount(index, extruder); }; val4->Bind(wxEVT_SPINCTRL, event_handler); val1->Bind(wxEVT_SPINCTRL, event_handler); - wxSizer* sizer = new wxBoxSizer(wxVERTICAL); + wxSizer * sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(msg, 0, wxTOP | wxLEFT | wxRIGHT, FromDIP(10)); - wxSizer* sizer2 = new wxBoxSizer(wxVERTICAL); - wxSizer* sizer21 = new wxBoxSizer(wxHORIZONTAL); - sizer21->Add(img4, 0, wxALIGN_CENTRE); - sizer21->Add(txt4, 2, wxLEFT | wxALIGN_CENTRE, FromDIP(10)); - sizer21->Add(val4, 1, wxLEFT | wxALIGN_CENTRE, FromDIP(10)); - sizer2->Add(sizer21, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, FromDIP(14)); - sizer2->AddSpacer(FromDIP(6)); - wxSizer* sizer22 = new wxBoxSizer(wxHORIZONTAL); - sizer22->Add(img1, 0, wxALIGN_CENTRE); - sizer22->Add(txt1, 2, wxLEFT | wxALIGN_CENTRE, FromDIP(10)); - sizer22->Add(val1, 1, wxLEFT | wxALIGN_CENTRE, FromDIP(10)); - sizer2->Add(sizer22, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, FromDIP(14)); - box->SetSizer(sizer2); + wxSizer *sizer2 = new wxBoxSizer(wxVERTICAL); + wxSizer *sizer21 = new wxBoxSizer(wxHORIZONTAL); + sizer21->Add(img4, 0, wxALIGN_CENTRE); + sizer21->Add(txt4, 2, wxLEFT | wxALIGN_CENTRE, FromDIP(10)); + sizer21->Add(val4, 1, wxLEFT | wxALIGN_CENTRE, FromDIP(10)); + sizer2->Add(sizer21, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, FromDIP(14)); + sizer2->AddSpacer(FromDIP(6)); + wxSizer *sizer22 = new wxBoxSizer(wxHORIZONTAL); + sizer22->Add(img1, 0, wxALIGN_CENTRE); + sizer22->Add(txt1, 2, wxLEFT | wxALIGN_CENTRE, FromDIP(10)); + sizer22->Add(val1, 1, wxLEFT | wxALIGN_CENTRE, FromDIP(10)); + sizer2->Add(sizer22, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, FromDIP(14)); + box->SetSizer(sizer2); sizer->Add(box, 0, wxTOP | wxBOTTOM | wxLEFT | wxRIGHT | wxEXPAND, FromDIP(14)); SetSizer(sizer); @@ -1245,11 +1252,11 @@ public: Fit(); Bind(wxEVT_PAINT, [this](wxPaintEvent& evt) { - wxPaintDC dc(this); - dc.SetPen(StateColor::darkModeColorFor(wxColour("#DBDBDB"))); // ORCA match popup border color - dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.DrawRoundedRectangle(0, 0, GetSize().x, GetSize().y, 0); - }); + wxPaintDC dc(this); + dc.SetPen(StateColor::darkModeColorFor(wxColour("#DBDBDB"))); // ORCA match popup border color + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRoundedRectangle(0, 0, GetSize().x, GetSize().y, 0); + }); SetBackgroundColour(*wxWHITE); wxGetApp().UpdateDarkUIWin(this); @@ -1257,34 +1264,35 @@ public: static void SetAMSCount(int index, int ams4, int ams1) { - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; + PresetBundle &preset_bundle = *wxGetApp().preset_bundle; preset_bundle.extruder_ams_counts.resize(2); - auto& ams_map = preset_bundle.extruder_ams_counts[index]; - ams_map[4] = ams4; - ams_map[1] = ams1; + auto &ams_map = preset_bundle.extruder_ams_counts[index]; + ams_map[4] = ams4; + ams_map[1] = ams1; - std::vector extruder_ams_count = save_extruder_ams_count_to_string(preset_bundle.extruder_ams_counts); - std::string extruder_ams_count_str = boost::algorithm::join(extruder_ams_count, ","); + std::vector extruder_ams_count = save_extruder_ams_count_to_string(preset_bundle.extruder_ams_counts); + std::string extruder_ams_count_str = boost::algorithm::join(extruder_ams_count, ","); wxGetApp().app_config->set("presets", "extruder_ams_count", extruder_ams_count_str); wxGetApp().plater()->update(); // update slice status } - static void GetAMSCount(int index, int& ams4, int& ams1) + static void GetAMSCount(int index, int & ams4, int & ams1) { - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; + PresetBundle &preset_bundle = *wxGetApp().preset_bundle; if (preset_bundle.extruder_ams_counts.empty()) { ams4 = 0; ams1 = 0; - } else { + } + else { assert(preset_bundle.extruder_ams_counts.size() == 2); ams4 = preset_bundle.extruder_ams_counts[index][4]; ams1 = preset_bundle.extruder_ams_counts[index][1]; } } - static void UpdateAMSCount(int index, ExtruderGroup* extruder) + static void UpdateAMSCount(int index, ExtruderGroup *extruder) { - std::vector>& ams_counts = wxGetApp().preset_bundle->extruder_ams_counts; + std::vector> &ams_counts = wxGetApp().preset_bundle->extruder_ams_counts; ams_counts.resize(2); std::map& ams_map = ams_counts[index]; if (ams_map.find(4) == ams_map.end()) { @@ -1298,7 +1306,8 @@ public: } }; -ExtruderGroup::ExtruderGroup(wxWindow* parent, int index, wxString const& title) : StaticGroup(parent, wxID_ANY, wxString()) +ExtruderGroup::ExtruderGroup(wxWindow * parent, int index, wxString const &title) + : StaticGroup(parent, wxID_ANY, wxString()) { SetFont(Label::Body_10); SetForegroundColour(wxColour("#CECECE")); @@ -1311,18 +1320,16 @@ ExtruderGroup::ExtruderGroup(wxWindow* parent, int index, wxString const& title) hover_label = new HoverLabel(this, title); // Nozzle - wxStaticText* label_diameter = new wxStaticText(this, wxID_ANY, _L("Diameter")); + wxStaticText *label_diameter = new wxStaticText(this, wxID_ANY, _L("Diameter")); label_diameter->SetFont(Label::Body_14); label_diameter->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#262E30"))); - if (index >= 0) - label_diameter->SetMinSize({FromDIP(80), -1}); - auto combo_diameter = new ComboBox(this, wxID_ANY, wxString(""), wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY); - this->combo_diameter = combo_diameter; - wxStaticText* label_flow = new wxStaticText(this, wxID_ANY, _L("Flow")); + if (index >= 0) label_diameter->SetMinSize({FromDIP(80), -1}); + auto combo_diameter = new ComboBox(this, wxID_ANY, wxString(""), wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY); + this->combo_diameter = combo_diameter; + wxStaticText *label_flow = new wxStaticText(this, wxID_ANY, _L("Flow")); label_flow->SetFont(Label::Body_14); label_flow->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#262E30"))); - if (index >= 0) - label_flow->SetMinSize({FromDIP(80), -1}); + if (index >= 0) label_flow->SetMinSize({FromDIP(80), -1}); auto combo_flow = new ComboBox(this, wxID_ANY, wxString(""), wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY); combo_flow->GetDropDown().SetUseContentWidth(true); combo_flow->Bind(wxEVT_COMBOBOX, [index, combo_flow](wxCommandEvent &evt) { @@ -1341,36 +1348,27 @@ ExtruderGroup::ExtruderGroup(wxWindow* parent, int index, wxString const& title) this->combo_flow = combo_flow; // AMS - wxStaticText* label_ams = new wxStaticText(this, wxID_ANY, _L("AMS")); + wxStaticText *label_ams = new wxStaticText(this, wxID_ANY, _L("AMS")); label_ams->SetFont(Label::Body_14); label_ams->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#262E30"))); - // label_ams->SetMinSize({FromDIP(70), -1}); + //label_ams->SetMinSize({FromDIP(70), -1}); if (index >= 0) { btn_edit = new ScalableButton(this, wxID_ANY, "dot"); btn_edit->SetBackgroundColour(extruder_group_chip_bg()); btn_edit->Hide(); - btn_edit->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this, index](auto& evt) { - PopupWindow* window = new AMSCountPopupWindow(this, index); - auto size = GetSize(); - auto pos = ClientToScreen({0, size.y + 12}); + btn_edit->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this, index](auto &evt) { + PopupWindow *window = new AMSCountPopupWindow(this, index); + auto size = GetSize(); + auto pos = ClientToScreen({0, size.y + 12}); size.SetWidth(size.GetWidth() + FromDIP(10)); window->Position(pos, {0, 0}); window->Popup(); }); - auto hovered = std::make_shared(); - for (wxWindow* w : - std::initializer_list{this, label_diameter, combo_diameter, label_flow, combo_flow, btn_edit, label_ams}) { - w->Bind(wxEVT_ENTER_WINDOW, [w, hovered, this](wxMouseEvent& evt) { - *hovered = w; - btn_edit->SetBitmap_("edit"); - }); - w->Bind(wxEVT_LEAVE_WINDOW, [w, hovered, this](wxMouseEvent& evt) { - if (*hovered == w) { - btn_edit->SetBitmap_("dot"); - *hovered = nullptr; - } - }); + auto hovered = std::make_shared(); + for (wxWindow *w : std::initializer_list{this, label_diameter, combo_diameter, label_flow, combo_flow, btn_edit, label_ams}) { + w->Bind(wxEVT_ENTER_WINDOW, [w, hovered, this](wxMouseEvent &evt) { *hovered = w; btn_edit->SetBitmap_("edit"); }); + w->Bind(wxEVT_LEAVE_WINDOW, [w, hovered, this](wxMouseEvent &evt) { if (*hovered == w) { btn_edit->SetBitmap_("dot"); *hovered = nullptr; } }); } } @@ -1392,8 +1390,7 @@ ExtruderGroup::ExtruderGroup(wxWindow* parent, int index, wxString const& title) hsizer_ams->Add(btn_edit, 0, wxLEFT | wxALIGN_CENTER, FromDIP(2)); hsizer_ams->Add(ams_not_installed_msg, 0, wxALIGN_CENTER); - btn_up = new ScalableButton(this, wxID_ANY, "page_up", "", {FromDIP(14), FromDIP(14)}, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, - false, 14); + btn_up = new ScalableButton(this, wxID_ANY, "page_up", "", {FromDIP(14), FromDIP(14)}, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, false, 14); btn_up->SetBackgroundColour(*wxWHITE); btn_up->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](auto &evt) { if (page_cur > 0) @@ -1401,8 +1398,7 @@ ExtruderGroup::ExtruderGroup(wxWindow* parent, int index, wxString const& title) update_ams(); }); btn_up->Hide(); - btn_down = new ScalableButton(this, wxID_ANY, "page_down", "", {FromDIP(14), FromDIP(14)}, wxDefaultPosition, - wxBU_EXACTFIT | wxNO_BORDER, false, 14); + btn_down = new ScalableButton(this, wxID_ANY, "page_down", "", {FromDIP(14), FromDIP(14)}, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, false, 14); btn_down->SetBackgroundColour(*wxWHITE); btn_down->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](auto &evt) { if (page_cur + 1 < page_num) @@ -1411,25 +1407,25 @@ ExtruderGroup::ExtruderGroup(wxWindow* parent, int index, wxString const& title) }); btn_down->Hide(); - wxBoxSizer* hsizer_diameter = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *hsizer_diameter = new wxBoxSizer(wxHORIZONTAL); hsizer_diameter->Add(label_diameter, 0, wxALIGN_CENTER); hsizer_diameter->Add(combo_diameter, 1, wxEXPAND); - wxBoxSizer* hsizer_nozzle = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer * hsizer_nozzle = new wxBoxSizer(wxHORIZONTAL); hsizer_nozzle->Add(label_flow, 0, wxALIGN_CENTER); hsizer_nozzle->Add(combo_flow, 1, wxEXPAND); if (index < 0) { label_ams->Hide(); ams_not_installed_msg->Hide(); - wxStaticBoxSizer* vsizer = new wxStaticBoxSizer(this, wxVERTICAL); - wxBoxSizer* hsizer = new wxBoxSizer(wxHORIZONTAL); - hsizer->Add(hsizer_diameter, 1, wxEXPAND | wxTOP | wxBOTTOM, FromDIP(8)); + wxStaticBoxSizer *vsizer = new wxStaticBoxSizer(this, wxVERTICAL); + wxBoxSizer *hsizer = new wxBoxSizer(wxHORIZONTAL); + hsizer->Add(hsizer_diameter, 1, wxEXPAND | wxTOP| wxBOTTOM, FromDIP(8)); hsizer->Add(hsizer_nozzle, 1, wxEXPAND | wxALL, FromDIP(8)); hsizer->AddSpacer(FromDIP(2)); // Avoid badge vsizer->Add(hover_label, 0, wxLEFT | wxALL, FromDIP(2)); vsizer->Add(hsizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(2)); this->sizer = vsizer; } else { - wxStaticBoxSizer* vsizer = new wxStaticBoxSizer(this, wxVERTICAL); + wxStaticBoxSizer *vsizer = new wxStaticBoxSizer(this, wxVERTICAL); vsizer->Add(hover_label, 0, wxLEFT | wxALL, FromDIP(2)); vsizer->Add(hsizer_ams, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, FromDIP(2)); vsizer->Add(hsizer_diameter, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, FromDIP(2)); @@ -1444,8 +1440,7 @@ void ExtruderGroup::update_ams() static AMSinfo info4; static AMSinfo info1; if (info4.cans.empty()) { - for (size_t i = 0; i < 4; ++i) - info4.cans.push_back({}); + for (size_t i = 0; i < 4; ++i) info4.cans.push_back({}); info1.ams_type = AMSModel::N3S_AMS; info1.cans.push_back({}); } @@ -1496,7 +1491,7 @@ void ExtruderGroup::update_ams() hsizer_ams->AddStretchSpacer(1); if (btn_up->IsShown() && btn_down->IsShown()) { auto vsizer_btn = new wxBoxSizer(wxVERTICAL); - auto size = btn_up->GetSize(); + auto size = btn_up->GetSize(); vsizer_btn->Add(btn_up, 0); vsizer_btn->Add(btn_down, 0); hsizer_ams->Add(vsizer_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(2)); @@ -1510,16 +1505,16 @@ void ExtruderGroup::update_ams() sizer->Layout(); } -void ExtruderGroup::sync_ams(MachineObject const* obj, std::vector const& ams4, std::vector const& ams1) +void ExtruderGroup::sync_ams(MachineObject const *obj, std::vector const &ams4, std::vector const &ams1) { - if (ams_4.empty() && ams4.empty() && ams_1.empty() && ams1.empty()) + if (ams_4.empty() && ams4.empty() + && ams_1.empty() && ams1.empty()) return; - auto sync = [obj](std::vector& infos, std::vector const& ams) -> bool { + auto sync = [obj](std::vector &infos, std::vector const &ams) -> bool { std::vector infos2; for (auto a : ams) { AMSinfo ams_info; - ams_info.parse_ams_info(const_cast(obj), a, obj->GetFilaSystem()->IsDetectRemainEnabled(), - obj->is_support_ams_humidity); + ams_info.parse_ams_info(const_cast(obj), a, obj->GetFilaSystem()->IsDetectRemainEnabled(), obj->is_support_ams_humidity); infos2.push_back(ams_info); } if (infos == infos2) @@ -1543,14 +1538,12 @@ bool Sidebar::priv::switch_diameter(bool single) if (single) { diameter = single_extruder->combo_diameter->GetValue(); } else { - auto diameter_left = left_extruder->combo_diameter->GetValue(); + auto diameter_left = left_extruder->combo_diameter->GetValue(); auto diameter_right = right_extruder->combo_diameter->GetValue(); if (diameter_left != diameter_right) { std::string printer_type = wxGetApp().preset_bundle->printers.get_edited_preset().get_printer_type(wxGetApp().preset_bundle); - auto left_name = _L(DevPrinterConfigUtil::get_toolhead_display_name(printer_type, DEPUTY_EXTRUDER_ID, ToolHeadComponent::Nozzle, - ToolHeadNameCase::SentenceCase)); - auto right_name = _L(DevPrinterConfigUtil::get_toolhead_display_name(printer_type, MAIN_EXTRUDER_ID, ToolHeadComponent::Nozzle, - ToolHeadNameCase::SentenceCase)); + auto left_name = _L(DevPrinterConfigUtil::get_toolhead_display_name(printer_type, DEPUTY_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::SentenceCase)); + auto right_name = _L(DevPrinterConfigUtil::get_toolhead_display_name(printer_type, MAIN_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::SentenceCase)); MessageDialog dlg(this->plater, _L("The software does not support using different diameter of nozzles for one print. " "If the left and right nozzles are inconsistent, we can only proceed with single-head printing. " @@ -1565,14 +1558,15 @@ bool Sidebar::priv::switch_diameter(bool single) diameter = diameter_right; else return false; - } else { + } + else { diameter = diameter_left; } } - + // ORCA: Check if the selected diameter matches the current nozzle diameter in the config Preset& printer_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); - auto* nozzle_diameter = dynamic_cast(printer_preset.config.option("nozzle_diameter")); + auto* nozzle_diameter = dynamic_cast(printer_preset.config.option("nozzle_diameter")); if (nozzle_diameter && nozzle_diameter->size() > 0) { auto current_nozzle_dia = get_diameter_string(nozzle_diameter->values[0]); // If the selected diameter is the same as current nozzle, don't switch profiles @@ -1580,8 +1574,8 @@ bool Sidebar::priv::switch_diameter(bool single) return true; } } - - auto preset = wxGetApp().preset_bundle->get_similar_printer_preset({}, diameter.ToStdString()); + + auto preset = wxGetApp().preset_bundle->get_similar_printer_preset({}, diameter.ToStdString()); if (preset == nullptr) { // ORCA add a text. this appears when user tries to change nozzle value but config doesnt have a inherited or compatible preset MessageDialog dlg(this->plater, _L("Configuration incompatible"), _L("Warning"), wxICON_WARNING | wxOK); @@ -1594,7 +1588,9 @@ bool Sidebar::priv::switch_diameter(bool single) static bool is_skip_high_flow_printer(const std::string& printer) { - static const std::set invalidate_list = {"Bambu Lab X1E"}; + static const std::set invalidate_list = { + "Bambu Lab X1E" + }; return invalidate_list.count(printer); }; @@ -1619,8 +1615,7 @@ static std::string serialize_nozzle_config(const std::map 0) - oss << ";"; + if (i > 0) oss << ";"; oss << std::fixed << std::setprecision(1) << deputy_nozzles[i].GetNozzleDiameter() << "," << static_cast(deputy_nozzles[i].GetNozzleFlowType()); } @@ -1628,8 +1623,7 @@ static std::string serialize_nozzle_config(const std::map 0) - oss << ";"; + if (i > 0) oss << ";"; oss << std::fixed << std::setprecision(1) << main_nozzles[i].GetNozzleDiameter() << "," << static_cast(main_nozzles[i].GetNozzleFlowType()); } @@ -1637,11 +1631,10 @@ static std::string serialize_nozzle_config(const std::map> deserialize_nozzle_config(const std::string& config_str) +static std::map> deserialize_nozzle_config(const std::string &config_str) { std::map> nozzle_cfg_map; - if (config_str.empty()) - return nozzle_cfg_map; + if (config_str.empty()) return nozzle_cfg_map; std::vector extruder_parts; boost::split(extruder_parts, config_str, boost::is_any_of("|")); @@ -1650,12 +1643,12 @@ static std::map> deserialize_nozzle_config(const std std::vector nozzles; std::vector parts; boost::split(parts, part_str, boost::is_any_of(";")); - for (const auto& part : parts) { + for (const auto &part : parts) { std::vector values; boost::split(values, part, boost::is_any_of(",")); if (values.size() == 2) { DevNozzle nozzle; - nozzle.m_diameter = std::stof(values[0]); + nozzle.m_diameter = std::stof(values[0]); nozzle.m_nozzle_flow = static_cast(std::stoi(values[1])); nozzles.push_back(nozzle); } @@ -1664,42 +1657,39 @@ static std::map> deserialize_nozzle_config(const std }; if (extruder_parts.size() != 2) { - auto nozzles = get_nozzles_from_string(config_str); - nozzle_cfg_map[MAIN_EXTRUDER_ID] = nozzles; - nozzle_cfg_map[DEPUTY_EXTRUDER_ID] = {DevNozzle()}; + auto nozzles = get_nozzles_from_string(config_str); + nozzle_cfg_map[MAIN_EXTRUDER_ID] = nozzles; + nozzle_cfg_map[DEPUTY_EXTRUDER_ID] = { DevNozzle() }; return nozzle_cfg_map; } if (!extruder_parts[0].empty()) { - auto nozzles = get_nozzles_from_string(extruder_parts[0]); + auto nozzles = get_nozzles_from_string(extruder_parts[0]); nozzle_cfg_map[DEPUTY_EXTRUDER_ID] = nozzles; } if (!extruder_parts[1].empty()) { - auto nozzles = get_nozzles_from_string(extruder_parts[1]); + auto nozzles = get_nozzles_from_string(extruder_parts[1]); nozzle_cfg_map[MAIN_EXTRUDER_ID] = nozzles; } return nozzle_cfg_map; } -static bool is_same_nozzle_config(const std::map>& config1, const std::map>& config2) +static bool is_same_nozzle_config(const std::map> &config1, const std::map> &config2) { - if (config1.size() != config2.size()) - return false; + if (config1.size() != config2.size()) return false; for (const auto& [eid, nozzles1] : config1) { auto it = config2.find(eid); - if (it == config2.end()) - return false; + if (it == config2.end()) return false; - const auto& nozzles2 = it->second; - if (nozzles1.size() != nozzles2.size()) - return false; + const auto &nozzles2 = it->second; + if (nozzles1.size() != nozzles2.size()) return false; auto sorted_nozzles1 = nozzles1; auto sorted_nozzles2 = nozzles2; - auto compare_nozzle = [](const DevNozzle& a, const DevNozzle& b) { + auto compare_nozzle = [](const DevNozzle &a, const DevNozzle &b) { float dia_a = a.GetNozzleDiameter(); float dia_b = b.GetNozzleDiameter(); if (std::abs(dia_a - dia_b) > EPSILON) { @@ -1722,22 +1712,19 @@ static bool is_same_nozzle_config(const std::map>& c return true; } -static std::string serialize_nozzle_option(const NozzleOption& option) -{ +static std::string serialize_nozzle_option(const NozzleOption& option) { std::ostringstream oss; oss << option.diameter << "|"; bool first = true; for (const auto& pair : option.extruder_nozzle_stats) { - if (!first) - oss << ";"; + if (!first) oss << ";"; first = false; oss << pair.first << ":"; bool first_stat = true; for (const auto& stat_pair : pair.second) { - if (!first_stat) - oss << ","; + if (!first_stat) oss << ","; first_stat = false; oss << static_cast(stat_pair.first) << "#" << stat_pair.second; } @@ -1745,15 +1732,12 @@ static std::string serialize_nozzle_option(const NozzleOption& option) return oss.str(); } -static std::optional deserialize_nozzle_option(const std::string& option_str) -{ - if (option_str.empty()) - return std::nullopt; +static std::optional deserialize_nozzle_option(const std::string& option_str) { + if (option_str.empty()) return std::nullopt; std::vector parts; boost::split(parts, option_str, boost::is_any_of("|")); - if (parts.size() != 2) - return std::nullopt; + if (parts.size() != 2) return std::nullopt; NozzleOption option; option.diameter = parts[0]; @@ -1762,13 +1746,11 @@ static std::optional deserialize_nozzle_option(const std::string& boost::split(extruder_parts, parts[1], boost::is_any_of(";")); for (const auto& extruder_part : extruder_parts) { - if (extruder_part.empty()) - continue; + if (extruder_part.empty()) continue; std::vector extruder_data; boost::split(extruder_data, extruder_part, boost::is_any_of(":")); - if (extruder_data.size() != 2) - continue; + if (extruder_data.size() != 2) continue; int extruder_id = std::stoi(extruder_data[0]); std::unordered_map stats; @@ -1781,8 +1763,8 @@ static std::optional deserialize_nozzle_option(const std::string& boost::split(kv, stat_part, boost::is_any_of("#")); if (kv.size() == 2) { NozzleVolumeType type = static_cast(std::stoi(kv[0])); - int count = std::stoi(kv[1]); - stats[type] = count; + int count = std::stoi(kv[1]); + stats[type] = count; } } @@ -1792,21 +1774,16 @@ static std::optional deserialize_nozzle_option(const std::string& return option; } -std::optional Sidebar::priv::get_nozzle_options(MachineObject* obj, - int extruder_count, - bool support_multi_nozzle, - bool is_manual) +std::optional Sidebar::priv::get_nozzle_options(MachineObject* obj, int extruder_count, bool support_multi_nozzle, bool is_manual) { if (extruder_count < 2 || !support_multi_nozzle) { return std::nullopt; } - if (!obj || !obj->GetNozzleSystem()) - return std::nullopt; + if (!obj || !obj->GetNozzleSystem()) return std::nullopt; auto nozzle_system = obj->GetNozzleSystem(); - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - if (!preset_bundle) - return std::nullopt; + PresetBundle *preset_bundle = wxGetApp().preset_bundle; + if (!preset_bundle) return std::nullopt; std::string curr_dev_id = obj->get_dev_id(); std::map> curr_nozzle_cfg; @@ -1820,8 +1797,8 @@ std::optional Sidebar::priv::get_nozzle_options(MachineObject* obj curr_nozzle_cfg[MAIN_EXTRUDER_ID].emplace_back(rack_nozzle.second); } - AppConfig* app_config = wxGetApp().app_config; - std::string saved_dev_id = app_config->get("sync_extruder", "dev_id"); + AppConfig *app_config = wxGetApp().app_config; + std::string saved_dev_id = app_config->get("sync_extruder", "dev_id"); std::string saved_nozzle_config_str = app_config->get("sync_extruder", "nozzle_config"); std::string saved_nozzle_option_str = app_config->get("sync_extruder", "nozzle_option"); std::optional nozzle_option; @@ -1833,20 +1810,20 @@ std::optional Sidebar::priv::get_nozzle_options(MachineObject* obj if (!saved_dev_id.empty() && !saved_nozzle_config_str.empty() && !saved_nozzle_option_str.empty() && saved_dev_id == curr_dev_id) { auto saved_nozzle_config = deserialize_nozzle_config(saved_nozzle_config_str); if (is_same_nozzle_config(saved_nozzle_config, curr_nozzle_cfg)) { - nozzle_option = deserialize_nozzle_option(saved_nozzle_option_str); + nozzle_option = deserialize_nozzle_option(saved_nozzle_option_str); can_reuse_saved_option = nozzle_option.has_value(); } if (can_reuse_saved_option) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Reusing saved nozzle option for dev_id: " << curr_dev_id; - auto& project_config = preset_bundle->project_config; - ConfigOptionEnumsGeneric* nozzle_volume_type_opt = project_config.option("nozzle_volume_type"); + auto &project_config = preset_bundle->project_config; + ConfigOptionEnumsGeneric *nozzle_volume_type_opt = project_config.option("nozzle_volume_type"); // Write to preset bundle config for (int extruder_id = 0; extruder_id < extruder_count; ++extruder_id) { NozzleVolumeType volume_type; - int nozzle_count; - bool clear_all = true; + int nozzle_count; + bool clear_all = true; if (!nozzle_option->extruder_nozzle_stats.count(extruder_id)) { nozzle_count = 0; @@ -1863,7 +1840,7 @@ std::optional Sidebar::priv::get_nozzle_options(MachineObject* obj clear_all = false; } } else { - for (auto& stat : nozzle_option->extruder_nozzle_stats[extruder_id]) { + for (auto &stat : nozzle_option->extruder_nozzle_stats[extruder_id]) { volume_type = stat.first; nozzle_count = stat.second; setExtruderNozzleCount(preset_bundle, extruder_id, volume_type, nozzle_count, clear_all); @@ -1875,8 +1852,7 @@ std::optional Sidebar::priv::get_nozzle_options(MachineObject* obj // a manual flow switch, and refresh the sidebar badges. setNozzleStatsFromMachine(true); if (nozzle_volume_type_opt) { - for (int extruder_id = 0; extruder_id < extruder_count && extruder_id < (int) nozzle_volume_type_opt->values.size(); - ++extruder_id) + for (int extruder_id = 0; extruder_id < extruder_count && extruder_id < (int) nozzle_volume_type_opt->values.size(); ++extruder_id) updateNozzleCountDisplay(preset_bundle, extruder_id, NozzleVolumeType(nozzle_volume_type_opt->values[extruder_id])); } } @@ -1930,7 +1906,7 @@ void Sidebar::priv::show_fila_switch_msg(bool ready) long style = ready ? (wxICON_INFORMATION | wxOK) : (wxICON_WARNING | wxOK); // Orca: drop the vendor "Learn more" tracking link; there is no Orca help page for the switch yet. - MessageDialog dlg(static_cast(wxGetApp().mainframe), msg, _L("Tips"), style); + MessageDialog dlg(static_cast(wxGetApp().mainframe), msg, _L("Tips"), style); dlg.CenterOnParent(); dlg.ShowModal(); } @@ -1980,12 +1956,12 @@ void Sidebar::priv::update_extruder_separator_icon(bool show, bool ready) // left_extruder->GetPosition() and the icon position live in the same coordinate space. wxPoint left_box_pos = left_extruder->GetPosition(); wxPoint ams_local_pos = left_extruder->hsizer_ams->GetPosition(); - wxSize left_size = left_extruder->sizer->GetSize(); - wxSize ams_size = left_extruder->hsizer_ams->GetSize(); - wxSize icon_size = extruder_separator_icon->GetSize(); - int ams_abs_y = left_box_pos.y + ams_local_pos.y + FromDIP(4); - int center_x = left_size.GetWidth() + FromDIP(6); - int center_y = ams_abs_y + (ams_size.GetHeight() - icon_size.GetHeight()) / 2; + wxSize left_size = left_extruder->sizer->GetSize(); + wxSize ams_size = left_extruder->hsizer_ams->GetSize(); + wxSize icon_size = extruder_separator_icon->GetSize(); + int ams_abs_y = left_box_pos.y + ams_local_pos.y + FromDIP(4); + int center_x = left_size.GetWidth() + FromDIP(6); + int center_y = ams_abs_y + (ams_size.GetHeight() - icon_size.GetHeight()) / 2; center_x -= icon_size.GetWidth() / 2; center_y -= icon_size.GetHeight() / 2; extruder_separator_icon->SetPosition(wxPoint(center_x, center_y)); @@ -2004,19 +1980,19 @@ void Sidebar::priv::update_extruder_separator_icon(bool show, bool ready) m_panel_printer_content->Refresh(); } -bool Sidebar::priv::sync_extruder_list(bool& only_external_material, bool is_manual) +bool Sidebar::priv::sync_extruder_list(bool &only_external_material, bool is_manual) { - MachineObject* obj = wxGetApp().getDeviceManager()->get_selected_machine(); - auto printer_name = plater->get_selected_printer_name_in_combox(); + MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine(); + auto printer_name = plater->get_selected_printer_name_in_combox(); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " begin sync_extruder_list"; if (obj == nullptr) { plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, _L("Sync printer information")); return false; } - // if (obj->get_extder_system()->extders.size() != 2) {//wxString(obj->get_preset_printer_model_name(machine_print_name)) - // plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::INCONSISTENT, _L("Sync printer - // information")); return false; - // } + //if (obj->get_extder_system()->extders.size() != 2) {//wxString(obj->get_preset_printer_model_name(machine_print_name)) + // plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::INCONSISTENT, _L("Sync printer information")); + // return false; + //} if (!plater->check_printer_initialized(obj)) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " check_printer_initialized fail"; @@ -2024,18 +2000,16 @@ bool Sidebar::priv::sync_extruder_list(bool& only_external_material, bool is_man } std::string machine_print_name = obj->get_show_printer_type(); - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - std::string target_model_id = preset_bundle->printers.get_selected_preset().get_printer_type(preset_bundle); - Preset* machine_preset = get_printer_preset(obj); + PresetBundle *preset_bundle = wxGetApp().preset_bundle; + std::string target_model_id = preset_bundle->printers.get_selected_preset().get_printer_type(preset_bundle); + Preset* machine_preset = get_printer_preset(obj); if (!machine_preset) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "check error: machine_preset empty"; return false; } if (machine_print_name != target_model_id) { - MessageDialog dlg(this->plater, - _L("The currently selected machine preset is inconsistent with the connected printer type.\n" - "Are you sure to continue syncing?"), - _L("Sync printer information"), wxICON_WARNING | wxYES | wxNO); + MessageDialog dlg(this->plater, _L("The currently selected machine preset is inconsistent with the connected printer type.\n" + "Are you sure to continue syncing?"), _L("Sync printer information"), wxICON_WARNING | wxYES | wxNO); if (dlg.ShowModal() == wxID_NO) { return false; } @@ -2049,11 +2023,11 @@ bool Sidebar::priv::sync_extruder_list(bool& only_external_material, bool is_man }); } BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " go on sync_extruder_list"; - const Preset& cur_preset = preset_bundle->printers.get_selected_preset(); - int extruder_nums = preset_bundle->get_printer_extruder_count(); + const Preset &cur_preset = preset_bundle->printers.get_selected_preset(); + int extruder_nums = preset_bundle->get_printer_extruder_count(); std::vector extruder_map(extruder_nums); std::iota(extruder_map.begin(), extruder_map.end(), 0); - const ConfigOptionInts* physical_extruder_map = cur_preset.config.option("physical_extruder_map"); + const ConfigOptionInts *physical_extruder_map = cur_preset.config.option("physical_extruder_map"); if (physical_extruder_map != nullptr) { assert(physical_extruder_map->values.size() == extruder_nums); extruder_map = physical_extruder_map->values; @@ -2065,12 +2039,11 @@ bool Sidebar::priv::sync_extruder_list(bool& only_external_material, bool is_man // value > 1 (nil-guarded, matching the manual/ToolOrdering gates), which no shipping single-nozzle or // dual-extruder profile sets. When the machine is multi-nozzle but no option resolves (e.g. user cancelled), // abort the sync. - const ConfigOptionIntsNullable* extruder_max_nozzle_count = cur_preset.config.option( - "extruder_max_nozzle_count"); + const ConfigOptionIntsNullable *extruder_max_nozzle_count = cur_preset.config.option("extruder_max_nozzle_count"); bool support_multi_nozzle = extruder_max_nozzle_count != nullptr && std::any_of(extruder_max_nozzle_count->values.begin(), extruder_max_nozzle_count->values.end(), [](int val) { return val > 1 && val != ConfigOptionIntsNullable::nil_value(); }); - auto nozzle_option = get_nozzle_options(obj, extruder_nums, support_multi_nozzle, is_manual); + auto nozzle_option = get_nozzle_options(obj, extruder_nums, support_multi_nozzle, is_manual); if (!nozzle_option && support_multi_nozzle) return false; @@ -2078,13 +2051,12 @@ bool Sidebar::priv::sync_extruder_list(bool& only_external_material, bool is_man nozzle_diameters.resize(extruder_nums); std::vector target_types(extruder_nums, NozzleVolumeType::nvtStandard); for (size_t index = 0; index < extruder_nums; ++index) { - int extruder_id = extruder_map[index]; - nozzle_diameters[extruder_id] = nozzle_option ? atof(nozzle_option->diameter.c_str()) : - obj->GetExtderSystem()->GetNozzleDiameter(index); - NozzleVolumeType target_type = NozzleVolumeType::nvtStandard; + int extruder_id = extruder_map[index]; + nozzle_diameters[extruder_id] = nozzle_option ? atof(nozzle_option->diameter.c_str()) : obj->GetExtderSystem()->GetNozzleDiameter(index); + NozzleVolumeType target_type = NozzleVolumeType::nvtStandard; std::optional select_type; if (nozzle_option && nozzle_option->extruder_nozzle_stats.count(index)) { - const auto& stats = nozzle_option->extruder_nozzle_stats[index]; + const auto &stats = nozzle_option->extruder_nozzle_stats[index]; if (stats.size() > 1) // The extruder holds nozzles of several flow types: select the mixed-flow mode. select_type = NozzleVolumeType::nvtHybrid; @@ -2093,8 +2065,7 @@ bool Sidebar::priv::sync_extruder_list(bool& only_external_material, bool is_man } if (obj->is_nozzle_flow_type_supported()) { if (obj->GetExtderSystem()->GetNozzleFlowType(index) == NozzleFlowType::NONE_FLOWTYPE) { - MessageDialog dlg(this->plater, - _L("There are unset nozzle types. Please set the nozzle types of all extruders before synchronizing."), + MessageDialog dlg(this->plater, _L("There are unset nozzle types. Please set the nozzle types of all extruders before synchronizing."), _L("Sync extruder infomation"), wxICON_WARNING | wxOK); dlg.ShowModal(); continue; @@ -2122,29 +2093,23 @@ bool Sidebar::priv::sync_extruder_list(bool& only_external_material, bool is_man auto switcher_pos = ams.second->GetSwitcherPos(); if (!switcher_pos) continue; - int switcher_id = obj->is_main_extruder_on_left() ? (1 - static_cast(switcher_pos.value())) : - static_cast(switcher_pos.value()); + int switcher_id = obj->is_main_extruder_on_left() ? (1 - static_cast(switcher_pos.value())) + : static_cast(switcher_pos.value()); if (extruder_id != switcher_id) continue; } const bool is_n3s = ams.second->GetAmsType() == DevAms::N3S; // Main (first) extruder is id 0, deputy is id 1. if (extruder_id == 0) { - if (is_n3s) - ++main_1; - else - ++main_4; + if (is_n3s) ++main_1; else ++main_4; } else if (extruder_id == 1) { - if (is_n3s) - ++deputy_1; - else - ++deputy_4; + if (is_n3s) ++deputy_1; else ++deputy_4; } } } only_external_material = !obj->GetFilaSystem()->HasAms(); - int main_index = obj->is_main_extruder_on_left() ? 0 : 1; - int deputy_index = obj->is_main_extruder_on_left() ? 1 : 0; + int main_index = obj->is_main_extruder_on_left() ? 0 : 1; + int deputy_index = obj->is_main_extruder_on_left() ? 1 : 0; if (extruder_nums > 1) { int left_index = left_extruder->combo_diameter->FindString(get_diameter_string(nozzle_diameters[0])); @@ -2169,7 +2134,7 @@ bool Sidebar::priv::sync_extruder_list(bool& only_external_material, bool is_man } // set nozzle volume type after switching prset, so this value can override the old value stored in conf - auto printer_tab = dynamic_cast(wxGetApp().get_tab(Preset::TYPE_PRINTER)); + auto printer_tab = dynamic_cast(wxGetApp().get_tab(Preset::TYPE_PRINTER)); for (size_t idx = 0; idx < target_types.size(); ++idx) { printer_tab->set_extruder_volume_type(idx, target_types[idx]); } @@ -2184,17 +2149,17 @@ bool Sidebar::priv::sync_extruder_list(bool& only_external_material, bool is_man // Copy the live switch state into the project so slicing and the send dialog honor it. Both // resolve to false unless the switch is installed and calibrated, so nothing changes without one. - auto& project_config = wxGetApp().preset_bundle->project_config; - if (auto* dynamic_filament = project_config.opt("enable_filament_dynamic_map")) + auto &project_config = wxGetApp().preset_bundle->project_config; + if (auto *dynamic_filament = project_config.opt("enable_filament_dynamic_map")) dynamic_filament->value = is_fila_switch_ready(); - if (auto* has_switcher = project_config.opt("has_filament_switcher")) + if (auto *has_switcher = project_config.opt("has_filament_switcher")) has_switcher->value = is_fila_switch_ready(); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " finish sync_extruder_list"; return true; } -void Sidebar::priv::update_sync_status(const MachineObject* obj) +void Sidebar::priv::update_sync_status(const MachineObject *obj) { StateColor not_synced_colour(std::pair(wxColour("#009688"), StateColor::Normal)); auto clear_all_sync_status = [this]() { @@ -2208,8 +2173,8 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) single_extruder->ShowBadge(false); single_extruder->sync_ams(nullptr, {}, {}); update_extruder_separator_icon(false, false); - // btn_sync_printer->SetBorderColor(not_synced_colour); - // btn_sync_printer->SetIcon("printer_sync"); + //btn_sync_printer->SetBorderColor(not_synced_colour); + //btn_sync_printer->SetIcon("printer_sync"); m_printer_bbl_sync->SetBitmap_("printer_sync_not"); }; @@ -2228,7 +2193,7 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) fila_switch_warning_shown = false; } - PresetBundle* preset_bundle = wxGetApp().preset_bundle; + PresetBundle *preset_bundle = wxGetApp().preset_bundle; if (!preset_bundle) { clear_all_sync_status(); return; @@ -2236,7 +2201,7 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) bool printer_synced = false; // 1. update printer status - const Preset& cur_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); + const Preset &cur_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); if (preset_bundle && preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle) == obj->get_show_printer_type()) { panel_printer_preset->ShowBadge(true); printer_synced = true; @@ -2252,23 +2217,25 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) struct ExtruderInfo { float diameter{0.4}; - // int nozzle_volue_type{0}; - int ams_4{0}; - int ams_1{0}; - std::vector ams_v4; - std::vector ams_v1; + //int nozzle_volue_type{0}; + int ams_4{0}; + int ams_1{0}; + std::vector ams_v4; + std::vector ams_v1; - bool operator==(const ExtruderInfo& other) const + bool operator==(const ExtruderInfo &other) const { - return abs(diameter - other.diameter) < EPSILON && /*nozzle_volue_type == other.nozzle_volue_type - &&*/ ams_4 == other.ams_4 && ams_1 == other.ams_1; + return abs(diameter - other.diameter) < EPSILON + && /*nozzle_volue_type == other.nozzle_volue_type + &&*/ ams_4 == other.ams_4 + && ams_1 == other.ams_1; } }; - auto is_same_nozzle_info = [obj](const ExtruderInfo& left, const ExtruderInfo& right) { + auto is_same_nozzle_info = [obj](const ExtruderInfo &left, const ExtruderInfo &right) { bool is_same_nozzle_type = true; if (obj->is_nozzle_flow_type_supported()) - is_same_nozzle_type = true; // left.nozzle_volue_type == right.nozzle_volue_type; // TODO: Orca hack + is_same_nozzle_type = true;//left.nozzle_volue_type == right.nozzle_volue_type; // TODO: Orca hack return abs(left.diameter - right.diameter) < EPSILON && is_same_nozzle_type; }; @@ -2293,11 +2260,10 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) } std::vector extruder_infos(extruder_nums); - std::vector nozzle_volume_types = - wxGetApp().preset_bundle->project_config.option("nozzle_volume_type")->values; - // for (size_t i = 0; i < nozzle_volume_types.size(); ++i) { - // extruder_infos[i].nozzle_volue_type = nozzle_volume_types[i]; - // } + std::vector nozzle_volume_types = wxGetApp().preset_bundle->project_config.option("nozzle_volume_type")->values; + //for (size_t i = 0; i < nozzle_volume_types.size(); ++i) { + // extruder_infos[i].nozzle_volue_type = nozzle_volume_types[i]; + //} std::vector> extruder_ams_counts = wxGetApp().preset_bundle->extruder_ams_counts; if (extruder_ams_counts.size() >= extruder_nums) { @@ -2315,11 +2281,12 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) double value = 0.0; single_extruder->diameter.ToDouble(&value); extruder_infos[0].diameter = float(value); - } else if (extruder_nums == 2) { + } + else if(extruder_nums == 2){ double value = 0.0; left_extruder->diameter.ToDouble(&value); extruder_infos[0].diameter = float(value); - + value = 0.0; right_extruder->diameter.ToDouble(&value); extruder_infos[1].diameter = float(value); @@ -2328,11 +2295,11 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) std::vector machine_extruder_infos(obj->GetExtderSystem()->GetTotalExtderCount()); const auto& extruders = obj->GetExtderSystem()->GetExtruders(); - for (const DevExtder& extruder : extruders) { - // machine_extruder_infos[extruder.GetExtId()].nozzle_volue_type = int(extruder.GetNozzleFlowType()) - 1; - machine_extruder_infos[extruder.GetExtId()].diameter = extruder.GetNozzleDiameter(); + for (const DevExtder &extruder : extruders) { + //machine_extruder_infos[extruder.GetExtId()].nozzle_volue_type = int(extruder.GetNozzleFlowType()) - 1; + machine_extruder_infos[extruder.GetExtId()].diameter = extruder.GetNozzleDiameter(); } - for (auto& item : obj->GetFilaSystem()->GetAmsList()) { + for (auto &item : obj->GetFilaSystem()->GetAmsList()) { int extruder_id; // With the switch ready every AMS feeds both extruders, so attribute each to the extruder its // input track feeds. Without a switch the binding is a single extruder @@ -2342,10 +2309,10 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) auto switcher_pos = item.second->GetSwitcherPos(); if (!switcher_pos) continue; - extruder_id = obj->is_main_extruder_on_left() ? (1 - static_cast(switcher_pos.value())) : - static_cast(switcher_pos.value()); + extruder_id = obj->is_main_extruder_on_left() ? (1 - static_cast(switcher_pos.value())) + : static_cast(switcher_pos.value()); } else { - const auto& uniq_extruder_id = item.second->GetUniqueBindedExtruderId(); + const auto &uniq_extruder_id = item.second->GetUniqueBindedExtruderId(); if (!uniq_extruder_id) continue; extruder_id = uniq_extruder_id.value(); @@ -2354,7 +2321,8 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) if (extruder_id >= machine_extruder_infos.size()) continue; - if (item.second->GetAmsType() == DevAms::N3S) { // N3S + if (item.second->GetAmsType() == DevAms::N3S) + { // N3S machine_extruder_infos[extruder_id].ams_1++; machine_extruder_infos[extruder_id].ams_v1.push_back(item.second); } else { @@ -2372,17 +2340,20 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) panel_nozzle_dia->ShowBadge(true); // ORCA add support for nozzle sync single_extruder->sync_ams(obj, machine_extruder_infos[0].ams_v4, machine_extruder_infos[0].ams_v1); extruder_synced[0] = true; - } else { + } + else { single_extruder->ShowBadge(false); panel_nozzle_dia->ShowBadge(false); // ORCA add support for nozzle sync single_extruder->sync_ams(obj, {}, {}); } - } else if (extruder_nums == 2) { + } + else if (extruder_nums == 2) { if (extruder_infos[0] == machine_extruder_infos[0]) { left_extruder->ShowBadge(true); left_extruder->sync_ams(obj, machine_extruder_infos[0].ams_v4, machine_extruder_infos[0].ams_v1); extruder_synced[0] = true; - } else { + } + else { left_extruder->ShowBadge(false); left_extruder->sync_ams(obj, {}, {}); } @@ -2391,7 +2362,8 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) right_extruder->ShowBadge(true); right_extruder->sync_ams(obj, machine_extruder_infos[1].ams_v4, machine_extruder_infos[1].ams_v1); extruder_synced[1] = true; - } else { + } + else { right_extruder->ShowBadge(false); right_extruder->sync_ams(obj, {}, {}); } @@ -2400,12 +2372,13 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) StateColor synced_colour(std::pair(wxColour("#CECECE"), StateColor::Normal)); bool all_extruder_synced = std::all_of(extruder_synced.begin(), extruder_synced.end(), [](bool value) { return value; }); if (printer_synced && all_extruder_synced) { - // btn_sync_printer->SetBorderColor(synced_colour); - // btn_sync_printer->SetIcon("ams_nozzle_sync"); + // btn_sync_printer->SetBorderColor(synced_colour); + // btn_sync_printer->SetIcon("ams_nozzle_sync"); m_printer_bbl_sync->SetBitmap_("printer_sync_ok"); - } else { - // btn_sync_printer->SetBorderColor(not_synced_colour); - // btn_sync_printer->SetIcon("printer_sync"); + } + else { + // btn_sync_printer->SetBorderColor(not_synced_colour); + // btn_sync_printer->SetIcon("printer_sync"); m_printer_bbl_sync->SetBitmap_("printer_sync_not"); } @@ -2418,24 +2391,25 @@ void Sidebar::priv::update_sync_status(const MachineObject* obj) last_filament_ams_list = wxGetApp().preset_bundle->filament_ams_list; const auto print_tech = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology(); if (print_tech == ptFFF && !is_same_ams_list) { - for (PlaterPresetComboBox* cb : combos_filament) + for (PlaterPresetComboBox *cb : combos_filament) cb->update(); } } -} + } -void Sidebar::update_sync_ams_btn_enable(wxUpdateUIEvent& e) -{ - if (m_last_slice_state != p->plater->is_background_process_slicing()) { - m_last_slice_state = p->plater->is_background_process_slicing(); - // btn_sync->Enable(!m_last_slice_state); - p->m_printer_bbl_sync->Enable(!m_last_slice_state); - ams_btn->Enable(!m_last_slice_state); - Refresh(); - } -} +void Sidebar::update_sync_ams_btn_enable(wxUpdateUIEvent &e) + { + if (m_last_slice_state != p->plater->is_background_process_slicing()) { + m_last_slice_state = p->plater->is_background_process_slicing(); + //btn_sync->Enable(!m_last_slice_state); + p->m_printer_bbl_sync->Enable(!m_last_slice_state); + ams_btn->Enable(!m_last_slice_state); + Refresh(); + } + } -Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(39 * wxGetApp().em_unit(), -1)), p(new priv(parent)) +Sidebar::Sidebar(Plater *parent) + : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(39 * wxGetApp().em_unit(), -1)), p(new priv(parent)) { Choice::register_dynamic_list("support_filament", &dynamic_physical_filament_list); Choice::register_dynamic_list("support_interface_filament", &dynamic_physical_filament_list); @@ -2452,9 +2426,10 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, // but this cause the bad layout of the sidebar, when all infoboxes appear. // As a result we can see the empty block at the bottom of the sidebar // But if we set this value to 5, layout will be better - // p->scrolled->SetScrollRate(0, 5); + //p->scrolled->SetScrollRate(0, 5); p->scrolled->SetBackgroundColour(*wxWHITE); + SetFont(wxGetApp().normal_font()); #ifndef __APPLE__ #ifdef _WIN32 @@ -2466,14 +2441,14 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, #endif int em = wxGetApp().em_unit(); - // BBS refine layout and styles - // Sizer in the scrolled area + //BBS refine layout and styles + // Sizer in the scrolled area auto* scrolled_sizer = m_scrolled_sizer = new wxBoxSizer(wxVERTICAL); p->scrolled->SetSizer(scrolled_sizer); - wxColour title_bg = wxColour(248, 248, 248); - wxColour inactive_text = wxColour(86, 86, 86); - wxColour active_text = wxColour(0, 0, 0); + wxColour title_bg = wxColour(248, 248, 248); + wxColour inactive_text = wxColour(86, 86, 86); + wxColour active_text = wxColour(0, 0, 0); wxColour static_line_col = wxColour(166, 169, 170); #ifdef __WINDOWS__ @@ -2488,7 +2463,7 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, p->m_panel_printer_title->SetBackgroundColor(title_bg); p->m_panel_printer_title->SetBackgroundColor2(0xF1F1F1); - p->m_printer_icon = new ScalableButton(p->m_panel_printer_title, wxID_ANY, "printer"); + p->m_printer_icon = new ScalableButton(p->m_panel_printer_title, wxID_ANY, "printer"); p->m_text_printer_settings = new Label(p->m_panel_printer_title, _L("Printer"), LB_PROPAGATE_MOUSE_EVENT | wxST_ELLIPSIZE_END); p->m_printer_icon->Bind(wxEVT_BUTTON, [](wxCommandEvent& e) { @@ -2499,7 +2474,7 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, // ORCA use connect button on titlebar p->m_printer_connect = new ScalableButton(p->m_panel_printer_title, wxID_ANY, "monitor_signal_strong"); p->m_printer_connect->SetToolTip(_L("Connection")); - p->m_printer_connect->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) { + p->m_printer_connect->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { PhysicalPrinterDialog dlg(this->GetParent()); dlg.ShowModal(); }); @@ -2507,7 +2482,9 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, // ORCA use sync button on titlebar p->m_printer_bbl_sync = new ScalableButton(p->m_panel_printer_title, wxID_ANY, "printer_sync_not"); p->m_printer_bbl_sync->SetToolTip(_L("Synchronize nozzle information and the number of AMS")); - p->m_printer_bbl_sync->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) { deal_btn_sync(); }); + p->m_printer_bbl_sync->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { + deal_btn_sync(); + }); p->m_printer_setting = new ScalableButton(p->m_panel_printer_title, wxID_ANY, "settings"); p->m_printer_setting->Bind(wxEVT_BUTTON, [](wxCommandEvent &e) { @@ -2515,17 +2492,15 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, // wxGetApp().params_dialog()->Popup(); // wxGetApp().get_tab(Preset::TYPE_FILAMENT)->restore_last_select_item(); wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); - }); + }); wxBoxSizer* h_sizer_title = new wxBoxSizer(wxHORIZONTAL); h_sizer_title->Add(p->m_printer_icon, 0, wxALIGN_CENTRE | wxLEFT, FromDIP(SidebarProps::TitlebarMargin())); h_sizer_title->AddSpacer(FromDIP(SidebarProps::ElementSpacing())); h_sizer_title->Add(p->m_text_printer_settings, 1, wxALIGN_CENTER | wxRIGHT, FromDIP(SidebarProps::WideSpacing())); - // h_sizer_title->AddStretchSpacer(); - h_sizer_title->Add(p->m_printer_connect, 0, wxALIGN_CENTER | wxRIGHT, - FromDIP(SidebarProps::WideSpacing())); // used larger margin to prevent accidental clicks - h_sizer_title->Add(p->m_printer_bbl_sync, 0, wxALIGN_CENTER | wxRIGHT, - FromDIP(SidebarProps::WideSpacing())); // used larger margin to prevent accidental clicks + //h_sizer_title->AddStretchSpacer(); + h_sizer_title->Add(p->m_printer_connect , 0, wxALIGN_CENTER | wxRIGHT, FromDIP(SidebarProps::WideSpacing())); // used larger margin to prevent accidental clicks + h_sizer_title->Add(p->m_printer_bbl_sync, 0, wxALIGN_CENTER | wxRIGHT, FromDIP(SidebarProps::WideSpacing())); // used larger margin to prevent accidental clicks h_sizer_title->Add(p->m_printer_setting, 0, wxALIGN_CENTER); h_sizer_title->AddSpacer(FromDIP(SidebarProps::TitlebarMargin())); h_sizer_title->SetMinSize(-1, 3 * em); @@ -2537,20 +2512,19 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, // add printer title scrolled_sizer->Add(p->m_panel_printer_title, 0, wxEXPAND | wxALL, 0); - p->m_panel_printer_title->Bind(wxEVT_LEFT_UP, [this](auto& e) { + p->m_panel_printer_title->Bind(wxEVT_LEFT_UP, [this] (auto & e) { if (!p || !p->combo_printer || !p->m_text_printer_settings || !p->m_panel_printer_content || !m_scrolled_sizer) return; // ORCA Show printer name on title when its folded to inform user without expanding it again - bool isShown = p->m_panel_printer_content->IsShown(); - wxString title = _L("Printer") + wxString(!isShown ? "" : (" | " + p->combo_printer->GetValue())); + bool isShown = p->m_panel_printer_content->IsShown(); + wxString title = _L("Printer") + wxString(!isShown ? "" : (" | " + p->combo_printer->GetValue())); p->m_text_printer_settings->SetLabel(title); p->m_panel_printer_content->Show(!isShown); p->m_panel_printer_separator->Show(isShown); m_scrolled_sizer->Layout(); }); // ORCA add bottom border for seperation wile sections folded - p->m_panel_printer_separator = new wxPanel(p->scrolled, wxID_ANY, wxDefaultPosition, - wxSize(-1, FromDIP(2))); // ORCA staticline class not works without string + p->m_panel_printer_separator = new wxPanel(p->scrolled, wxID_ANY, wxDefaultPosition, wxSize(-1, FromDIP(2))); // ORCA staticline class not works without string p->m_panel_printer_separator->SetBackgroundColour("#FFFFFF"); scrolled_sizer->Add(p->m_panel_printer_separator, 0, wxEXPAND); @@ -2559,8 +2533,7 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, p->m_panel_printer_content = new wxPanel(p->scrolled, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); p->m_panel_printer_content->SetBackgroundColour(wxColour(255, 255, 255)); - struct PanelColors - { + struct PanelColors { wxColour bg_normal = "#FFFFFF"; wxColour bg_focus = "#E5F0EE"; wxColour bd_normal = "#DBDBDB"; @@ -2573,17 +2546,18 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, p->panel_printer_preset->SetCornerRadius(FromDIP(PRINTER_PANEL_RADIUS)); p->panel_printer_preset->SetBorderColor(panel_color.bd_normal); p->panel_printer_preset->SetMinSize(FromDIP(PRINTER_PANEL_SIZE)); - p->panel_printer_preset->Bind(wxEVT_LEFT_DOWN, [this](auto& evt) { p->combo_printer->wxEvtHandler::ProcessEvent(evt); }); + p->panel_printer_preset->Bind(wxEVT_LEFT_DOWN, [this](auto & evt) { + p->combo_printer->wxEvtHandler::ProcessEvent(evt); + }); // ORCA Hide Cover automatically if there is not enough space - p->panel_printer_preset->Bind(wxEVT_SIZE, [this](auto& e) { + p->panel_printer_preset->Bind(wxEVT_SIZE, [this](auto & e) { auto current_width = e.GetSize().GetWidth(); auto narrow_width = FromDIP(235); - auto label_width = p->combo_printer->GetTextExtent(p->combo_printer->GetStringSelection()).GetWidth(); - auto min_width = label_width + FromDIP(25 + PRINTER_PANEL_SIZE.GetWidth()); - if (((min_width < narrow_width && min_width > current_width) || (current_width < narrow_width && min_width > narrow_width)) && - p->image_printer->IsShown()) + auto label_width = p->combo_printer->GetTextExtent(p->combo_printer->GetStringSelection()).GetWidth(); + auto min_width = label_width + FromDIP(25 + PRINTER_PANEL_SIZE.GetWidth()); + if(((min_width < narrow_width && min_width > current_width) || (current_width < narrow_width && min_width > narrow_width)) && p->image_printer->IsShown()) p->image_printer->Hide(); - else if ((current_width > min_width || !(current_width < narrow_width)) && !p->image_printer->IsShown()) + else if((current_width > min_width || !(current_width < narrow_width)) && !p->image_printer->IsShown()) p->image_printer->Show(); e.Skip(); }); @@ -2594,18 +2568,16 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, p->btn_edit_printer = new ScalableButton(p->panel_printer_preset, wxID_ANY, "edit"); p->btn_edit_printer->SetToolTip(_L("Click to edit preset")); p->btn_edit_printer->Hide(); // hide for first launch - p->btn_edit_printer->Bind(wxEVT_BUTTON, [this, panel_color, printer_preset_hovered](wxCommandEvent) { + p->btn_edit_printer->Bind(wxEVT_BUTTON, [this, panel_color, printer_preset_hovered](wxCommandEvent){ p->editing_filament = -1; if (p->combo_printer->switch_to_tab()) p->editing_filament = 0; - // ORCA: FIX crash on wxGTK, directly modifying UI (self->Hide() / parent->Layout()) inside a button event can crash because - // callbacks are not re-entrant, leaving widgets in an inconsistent state + // ORCA: FIX crash on wxGTK, directly modifying UI (self->Hide() / parent->Layout()) inside a button event can crash because callbacks are not re-entrant, leaving widgets in an inconsistent state wxGetApp().CallAfter([this, panel_color, printer_preset_hovered]() { - // ORCA clicking edit button not triggers wxEVT_KILL_FOCUS wxEVT_LEAVE_WINDOW make changes manually to prevent stucked - // colors when opening printer settings + // ORCA clicking edit button not triggers wxEVT_KILL_FOCUS wxEVT_LEAVE_WINDOW make changes manually to prevent stucked colors when opening printer settings if (!p || !p->panel_printer_preset || !p->btn_edit_printer) return; - p->panel_printer_preset->SetBorderColor(panel_color.bd_normal); + p->panel_printer_preset->SetBorderColor(panel_color.bd_normal); printer_preset_hovered->clear(); p->btn_edit_printer->Hide(); p->panel_printer_preset->Layout(); @@ -2613,15 +2585,16 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, }); ScalableBitmap bitmap_printer(p->panel_printer_preset, "printer_placeholder", PRINTER_THUMBNAIL_SIZE.GetHeight()); - p->image_printer = new wxStaticBitmap(p->panel_printer_preset, wxID_ANY, bitmap_printer.bmp(), wxDefaultPosition, - FromDIP(PRINTER_THUMBNAIL_SIZE), 0); - p->image_printer->Bind(wxEVT_LEFT_DOWN, [this](auto& evt) { p->combo_printer->wxEvtHandler::ProcessEvent(evt); }); + p->image_printer = new wxStaticBitmap(p->panel_printer_preset, wxID_ANY, bitmap_printer.bmp(), wxDefaultPosition, FromDIP(PRINTER_THUMBNAIL_SIZE), 0); + p->image_printer->Bind(wxEVT_LEFT_DOWN, [this](auto &evt) { + p->combo_printer->wxEvtHandler::ProcessEvent(evt); + }); p->combo_printer = new PlaterPresetComboBox(p->panel_printer_preset, Preset::TYPE_PRINTER); p->combo_printer->SetBorderWidth(0); p->combo_printer->SetMaxSize(wxSize(-1, FromDIP(30))); // limiting height makes badge visible // ORCA paint whole combobox on focus - auto printer_focus_bg = [this, panel_color](bool focused) { + auto printer_focus_bg = [this, panel_color](bool focused){ auto bg_color = StateColor::darkModeColorFor(focused ? panel_color.bg_focus : panel_color.bg_normal); p->panel_printer_preset->SetBackgroundColor(bg_color); p->panel_printer_preset->SetBorderColor(focused ? panel_color.bd_focus : panel_color.bd_normal); @@ -2643,15 +2616,14 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, }); */ // ORCA use Show/Hide to gain text area instead using blank icon. also manages hover effect for border - for (wxWindow* w : - std::initializer_list{p->panel_printer_preset, p->btn_edit_printer, p->image_printer, p->combo_printer}) { - w->Bind(wxEVT_ENTER_WINDOW, [this, w, panel_color, printer_preset_hovered](wxMouseEvent& e) { + for (wxWindow *w : std::initializer_list{p->panel_printer_preset, p->btn_edit_printer, p->image_printer, p->combo_printer}) { + w->Bind(wxEVT_ENTER_WINDOW, [this, w, panel_color, printer_preset_hovered](wxMouseEvent &e) { printer_preset_hovered->insert(w); - if (!p->combo_printer->HasFocus()) + if(!p->combo_printer->HasFocus()) p->panel_printer_preset->SetBorderColor(panel_color.bd_hover); e.Skip(); }); - w->Bind(wxEVT_LEAVE_WINDOW, [this, w, panel_color, printer_preset_hovered](wxMouseEvent& e) { + w->Bind(wxEVT_LEAVE_WINDOW, [this, w, panel_color, printer_preset_hovered](wxMouseEvent &e) { printer_preset_hovered->erase(w); if (printer_preset_hovered->empty() && !p->combo_printer->HasFocus()) p->panel_printer_preset->SetBorderColor(panel_color.bd_normal); @@ -2661,7 +2633,7 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, // Perform show/hide in wxEVT_IDLE after enter/leave events have settled. // This prevents the extraneous enter/leave events generated by the // layout change itself from causing a feedback loop. - Bind(wxEVT_IDLE, [this, printer_preset_hovered](wxIdleEvent& e) { + Bind(wxEVT_IDLE, [this, printer_preset_hovered](wxIdleEvent &e) { auto hovered = !printer_preset_hovered->empty(); if (p->btn_edit_printer->IsShown() != hovered) { if (hovered) { @@ -2678,18 +2650,19 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, p->panel_nozzle_dia->SetCornerRadius(FromDIP(PRINTER_PANEL_RADIUS)); p->panel_nozzle_dia->SetBorderColor(panel_color.bd_normal); p->panel_nozzle_dia->SetMinSize(FromDIP(PRINTER_PANEL_SIZE)); - p->panel_nozzle_dia->Bind(wxEVT_LEFT_DOWN, [this](auto& evt) { p->combo_nozzle_dia->wxEvtHandler::ProcessEvent(evt); }); + p->panel_nozzle_dia->Bind(wxEVT_LEFT_DOWN, [this](auto & evt) { + p->combo_nozzle_dia->wxEvtHandler::ProcessEvent(evt); + }); p->label_nozzle_title = new Label(p->panel_nozzle_dia, _L("Nozzle"), LB_PROPAGATE_MOUSE_EVENT); p->label_nozzle_title->SetFont(Label::Body_10); - p->combo_nozzle_dia = new ComboBox(p->panel_nozzle_dia, wxID_ANY, wxString(""), wxDefaultPosition, wxDefaultSize, 0, nullptr, - wxCB_READONLY); + p->combo_nozzle_dia = new ComboBox(p->panel_nozzle_dia, wxID_ANY, wxString(""), wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY); p->combo_nozzle_dia->SetBorderWidth(0); p->combo_nozzle_dia->GetDropDown().SetUseContentWidth(true); p->combo_nozzle_dia->SetMinSize(FromDIP(wxSize(PRINTER_PANEL_SIZE.GetWidth() - 4, 26))); // requires a static value in here p->combo_nozzle_dia->SetMaxSize(FromDIP(wxSize(PRINTER_PANEL_SIZE.GetWidth() - 4, 26))); // using -1 with wxEXPAND has issues - p->combo_nozzle_dia->Bind(wxEVT_COMBOBOX, [this](auto& e) { + p->combo_nozzle_dia->Bind(wxEVT_COMBOBOX, [this](auto &e) { auto evt_combo = (*p->single_extruder).combo_diameter; evt_combo->SetSelection(e.GetSelection()); wxCommandEvent evt(wxEVT_COMBOBOX, evt_combo->GetId()); @@ -2699,7 +2672,7 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, e.Skip(); }); // ORCA paint whole combobox on focus - auto nozzle_focus_bg = [this, panel_color](bool focused) { + auto nozzle_focus_bg = [this, panel_color](bool focused){ auto bg_color = StateColor::darkModeColorFor(focused ? panel_color.bg_focus : panel_color.bg_normal); p->panel_nozzle_dia->SetBackgroundColor(bg_color); p->panel_nozzle_dia->SetBorderColor(focused ? panel_color.bd_focus : panel_color.bd_normal); @@ -2710,23 +2683,21 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, p->combo_nozzle_dia->Bind(wxEVT_SET_FOCUS, [nozzle_focus_bg](auto& e) {nozzle_focus_bg(true ); e.Skip();}); p->combo_nozzle_dia->Bind(wxEVT_KILL_FOCUS, [nozzle_focus_bg](auto& e) {nozzle_focus_bg(false); e.Skip();}); - p->label_nozzle_type = new Label(p->panel_nozzle_dia, "Brass", - LB_PROPAGATE_MOUSE_EVENT | wxST_ELLIPSIZE_END | wxALIGN_CENTRE_HORIZONTAL); + p->label_nozzle_type = new Label(p->panel_nozzle_dia, "Brass", LB_PROPAGATE_MOUSE_EVENT | wxST_ELLIPSIZE_END | wxALIGN_CENTRE_HORIZONTAL); p->label_nozzle_type->SetFont(Label::Body_10); p->label_nozzle_type->SetMinSize(FromDIP(wxSize(56, -1))); p->label_nozzle_type->SetMaxSize(FromDIP(wxSize(56, -1))); // highlight border on hover auto nozzle_dia_hovered = std::make_shared>(); - for (wxWindow* w : - std::initializer_list{p->panel_nozzle_dia, p->label_nozzle_title, p->label_nozzle_type, p->combo_nozzle_dia}) { - w->Bind(wxEVT_ENTER_WINDOW, [this, w, panel_color, nozzle_dia_hovered](wxMouseEvent& e) { + for (wxWindow *w : std::initializer_list{p->panel_nozzle_dia, p->label_nozzle_title, p->label_nozzle_type, p->combo_nozzle_dia}) { + w->Bind(wxEVT_ENTER_WINDOW, [this, w, panel_color, nozzle_dia_hovered](wxMouseEvent &e) { nozzle_dia_hovered->insert(w); - if (!p->combo_nozzle_dia->HasFocus()) + if(!p->combo_nozzle_dia->HasFocus()) p->panel_nozzle_dia->SetBorderColor(panel_color.bd_hover); e.Skip(); }); - w->Bind(wxEVT_LEAVE_WINDOW, [this, w, panel_color, nozzle_dia_hovered](wxMouseEvent& e) { + w->Bind(wxEVT_LEAVE_WINDOW, [this, w, panel_color, nozzle_dia_hovered](wxMouseEvent &e) { nozzle_dia_hovered->erase(w); if (nozzle_dia_hovered->empty() && !p->combo_nozzle_dia->HasFocus()) p->panel_nozzle_dia->SetBorderColor(panel_color.bd_normal); @@ -2734,10 +2705,10 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, }); } - wxGridSizer* nozzle_dia_sizer = new wxGridSizer(3, 1, FromDIP(2), 0); - nozzle_dia_sizer->Add(p->label_nozzle_title, 1, wxALIGN_CENTER | wxTOP, FromDIP(2)); - nozzle_dia_sizer->Add(p->combo_nozzle_dia, 0, wxALIGN_CENTER); - nozzle_dia_sizer->Add(p->label_nozzle_type, 1, wxALIGN_CENTER | wxBOTTOM, FromDIP(1)); + wxGridSizer *nozzle_dia_sizer = new wxGridSizer(3, 1, FromDIP(2), 0); + nozzle_dia_sizer->Add(p->label_nozzle_title, 1, wxALIGN_CENTER | wxTOP , FromDIP(2)); + nozzle_dia_sizer->Add(p->combo_nozzle_dia , 0, wxALIGN_CENTER); + nozzle_dia_sizer->Add(p->label_nozzle_type , 1, wxALIGN_CENTER | wxBOTTOM, FromDIP(1)); p->panel_nozzle_dia->SetSizer(nozzle_dia_sizer); @@ -2746,39 +2717,38 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, p->panel_printer_bed->SetCornerRadius(FromDIP(PRINTER_PANEL_RADIUS)); p->panel_printer_bed->SetBorderColor(panel_color.bd_normal); p->panel_printer_bed->SetMinSize(FromDIP(PRINTER_PANEL_SIZE)); - p->panel_printer_bed->Bind(wxEVT_LEFT_DOWN, [this](auto& evt) { + p->panel_printer_bed->Bind(wxEVT_LEFT_DOWN, [this](auto &evt) { on_leave_image_printer_bed(evt); p->combo_printer_bed->wxEvtHandler::ProcessEvent(evt); }); - // ScalableButton *wiki_bed = new ScalableButton(p->panel_printer_bed, wxID_ANY, "help"); - // wiki_bed->Bind(wxEVT_BUTTON, [](wxCommandEvent) { - // wxLaunchDefaultBrowser("https://wiki.bambulab.com/en/x1/manual/compatibility-and-parameter-settings-of-filaments"); - // }); + //ScalableButton *wiki_bed = new ScalableButton(p->panel_printer_bed, wxID_ANY, "help"); + //wiki_bed->Bind(wxEVT_BUTTON, [](wxCommandEvent) { + // wxLaunchDefaultBrowser("https://wiki.bambulab.com/en/x1/manual/compatibility-and-parameter-settings-of-filaments"); + //}); ScalableBitmap bitmap_bed(p->panel_printer_bed, "printer_placeholder", PRINTER_THUMBNAIL_SIZE.GetHeight()); p->image_printer_bed = new wxStaticBitmap(p->panel_printer_bed, wxID_ANY, bitmap_bed.bmp(), wxDefaultPosition, wxDefaultSize, 0); - p->image_printer_bed->Bind(wxEVT_LEFT_DOWN, [this](auto& evt) { + p->image_printer_bed->Bind(wxEVT_LEFT_DOWN, [this](auto &evt) { on_leave_image_printer_bed(evt); p->combo_printer_bed->wxEvtHandler::ProcessEvent(evt); }); - p->combo_printer_bed = new ComboBox(p->panel_printer_bed, wxID_ANY, wxString(""), wxDefaultPosition, wxDefaultSize, 0, nullptr, - wxCB_READONLY); + p->combo_printer_bed = new ComboBox(p->panel_printer_bed, wxID_ANY, wxString(""), wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY); p->combo_printer_bed->SetBorderWidth(0); p->combo_printer_bed->GetDropDown().SetUseContentWidth(true); - p->combo_printer_bed->SetMinSize(FromDIP(wxSize(18, -1))); // ORCA show only arrow - p->combo_printer_bed->SetMaxSize(FromDIP(wxSize(18, -1))); // ORCA show only arrow + p->combo_printer_bed->SetMinSize(FromDIP(wxSize(18,-1))); // ORCA show only arrow + p->combo_printer_bed->SetMaxSize(FromDIP(wxSize(18,-1))); // ORCA show only arrow reset_bed_type_combox_choices(true); - p->combo_printer_bed->Bind(wxEVT_COMBOBOX, [this](auto& e) { - auto image_path = get_cur_select_bed_image(); + p->combo_printer_bed->Bind(wxEVT_COMBOBOX, [this](auto &e) { + auto image_path = get_cur_select_bed_image(); p->image_printer_bed->SetBitmap(create_scaled_bitmap(image_path, this, PRINTER_THUMBNAIL_SIZE.GetHeight())); e.Skip(); }); // ORCA paint whole combobox on focus - auto bed_focus_bg = [this, panel_color](bool focused) { + auto bed_focus_bg = [this, panel_color](bool focused){ auto bg_color = StateColor::darkModeColorFor(focused ? panel_color.bg_focus : panel_color.bg_normal); p->panel_printer_bed->SetBackgroundColor(bg_color); p->panel_printer_bed->SetBorderColor(focused ? panel_color.bd_focus : panel_color.bd_normal); @@ -2790,34 +2760,34 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, // highlight border on hover auto printer_bed_hovered = std::make_shared>(); - for (wxWindow* w : std::initializer_list{p->panel_printer_bed, p->image_printer_bed, p->combo_printer_bed}) { - w->Bind(wxEVT_ENTER_WINDOW, [this, w, panel_color, printer_bed_hovered](wxMouseEvent& e) { + for (wxWindow *w : std::initializer_list{p->panel_printer_bed, p->image_printer_bed, p->combo_printer_bed}) { + w->Bind(wxEVT_ENTER_WINDOW, [this, w, panel_color, printer_bed_hovered](wxMouseEvent &e) { printer_bed_hovered->insert(w); - if (!p->combo_printer_bed->HasFocus()) + if(!p->combo_printer_bed->HasFocus()) p->panel_printer_bed->SetBorderColor(panel_color.bd_hover); - if (w == p->image_printer_bed && !p->combo_printer_bed->is_drop_down()) // dont trigger while combo open + if(w == p->image_printer_bed && !p->combo_printer_bed->is_drop_down()) // dont trigger while combo open on_enter_image_printer_bed(e); e.Skip(); }); - w->Bind(wxEVT_LEAVE_WINDOW, [this, w, panel_color, printer_bed_hovered](wxMouseEvent& e) { + w->Bind(wxEVT_LEAVE_WINDOW, [this, w, panel_color, printer_bed_hovered](wxMouseEvent &e) { printer_bed_hovered->erase(w); if (printer_bed_hovered->empty() && !p->combo_printer_bed->HasFocus()) p->panel_printer_bed->SetBorderColor(panel_color.bd_normal); - if (w == p->image_printer_bed) + if(w == p->image_printer_bed) on_leave_image_printer_bed(e); e.Skip(); }); } - wxBoxSizer* bed_type_sizer = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *bed_type_sizer = new wxBoxSizer(wxHORIZONTAL); bed_type_sizer->Add(p->combo_printer_bed, 0, wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(2)); bed_type_sizer->Add(p->image_printer_bed, 0, wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(2)); p->panel_printer_bed->SetSizer(bed_type_sizer); - AppConfig* app_config = wxGetApp().app_config; + AppConfig *app_config = wxGetApp().app_config; std::string str_bed_type = app_config->get("curr_bed_type"); - int bed_type_value = atoi(str_bed_type.c_str()); + int bed_type_value = atoi(str_bed_type.c_str()); // hotfix: btDefault is added as the first one in BedType, and app_config should not be btDefault if (bed_type_value == 0) { app_config->set("curr_bed_type", "1"); @@ -2834,7 +2804,7 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, if (item.first == str_bed_type) bed_type = (BedType)item.second; }*/ - BedType bed_type = (BedType) bed_type_value; + BedType bed_type = (BedType)bed_type_value; project_config.set_key_value("curr_bed_type", new ConfigOptionEnum(bed_type)); /* ORCA THIS PART MOVED TO TITLEBAR @@ -2864,10 +2834,13 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, }); p->btn_sync_printer = btn_sync; */ - p->timer_sync_printer->Bind(wxEVT_TIMER, [this](wxTimerEvent& e) { p->flush_printer_sync(); }); + p->timer_sync_printer->Bind(wxEVT_TIMER, [this] (wxTimerEvent & e) { + p->flush_printer_sync(); + }); + - p->left_extruder = new ExtruderGroup(p->m_panel_printer_content, 0, _L("Left Nozzle")); - p->right_extruder = new ExtruderGroup(p->m_panel_printer_content, 1, _L("Right Nozzle")); + p->left_extruder = new ExtruderGroup(p->m_panel_printer_content, 0, _L("Left Nozzle")); + p->right_extruder = new ExtruderGroup(p->m_panel_printer_content, 1, _L("Right Nozzle")); p->single_extruder = new ExtruderGroup(p->m_panel_printer_content, -1, _L("Nozzle")); // manuallySetNozzleCount refreshes the badge and the plater itself; it is a no-op unless the // printer has a multi-nozzle extruder (and the edit button is only enabled then, see @@ -2877,24 +2850,24 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, p->single_extruder->SetEditEnabled(false); // Orca: keep the floating switcher icon aligned with the left extruder's AMS row when the // extruder card is resized (the overlay is absolutely positioned, not managed by a sizer). - p->left_extruder->Bind(wxEVT_SIZE, [this](wxSizeEvent& evt) { + p->left_extruder->Bind(wxEVT_SIZE, [this](wxSizeEvent &evt) { if (p->extruder_separator_icon && p->extruder_separator_icon->IsShown()) { wxPoint left_box_pos = p->left_extruder->GetPosition(); wxPoint ams_local_pos = p->left_extruder->hsizer_ams->GetPosition(); - wxSize left_size = p->left_extruder->sizer->GetSize(); - wxSize ams_size = p->left_extruder->hsizer_ams->GetSize(); - wxSize icon_size = p->extruder_separator_icon->GetSize(); - int ams_abs_y = left_box_pos.y + ams_local_pos.y + FromDIP(4); - int center_x = left_size.GetWidth() + FromDIP(6) - icon_size.GetWidth() / 2; - int center_y = ams_abs_y + (ams_size.GetHeight() - icon_size.GetHeight()) / 2 - icon_size.GetHeight() / 2; + wxSize left_size = p->left_extruder->sizer->GetSize(); + wxSize ams_size = p->left_extruder->hsizer_ams->GetSize(); + wxSize icon_size = p->extruder_separator_icon->GetSize(); + int ams_abs_y = left_box_pos.y + ams_local_pos.y + FromDIP(4); + int center_x = left_size.GetWidth() + FromDIP(6) - icon_size.GetWidth() / 2; + int center_y = ams_abs_y + (ams_size.GetHeight() - icon_size.GetHeight()) / 2 - icon_size.GetHeight() / 2; p->extruder_separator_icon->SetPosition(wxPoint(center_x, center_y)); if (p->m_panel_printer_content) p->m_panel_printer_content->Refresh(); } evt.Skip(); }); - auto switch_diameter = [this](wxCommandEvent& evt) { - auto extruder = dynamic_cast(dynamic_cast(evt.GetEventObject())->GetParent()); + auto switch_diameter = [this](wxCommandEvent & evt) { + auto extruder = dynamic_cast(dynamic_cast(evt.GetEventObject())->GetParent()); p->is_switching_diameter = true; p->switch_diameter(extruder == p->single_extruder); p->is_switching_diameter = false; @@ -2911,394 +2884,379 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, } { - // Orca: Sidebar - Filament titlebar UI - // add filament title - p->m_panel_filament_title = new StaticBox(p->scrolled, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxBORDER_NONE); - p->m_panel_filament_title->SetBackgroundColor(title_bg); - p->m_panel_filament_title->SetBackgroundColor2(0xF1F1F1); - p->m_panel_filament_title->Bind(wxEVT_LEFT_UP, [this](wxMouseEvent& e) { - if (!p || !p->m_filament_area_wrapper || !m_scrolled_sizer || !p->m_bpButton_set_filament || !p->m_purge_mode_btn || - !p->m_flushing_volume_btn || !p->m_bpButton_add_filament || !ams_btn) - return; - // ORCA exclude area of del button from titlebar collapse/expand feature to fix undesired collapse when user spams del filament - // button also block fold/unfold feature when user clicks to spacing between icons - int exclude_pt = p->m_bpButton_set_filament->GetPosition().x; // maximum fixed item - if (p->m_purge_mode_btn->IsShown()) - exclude_pt = p->m_purge_mode_btn->GetPosition().x; - else if (p->m_flushing_volume_btn->IsShown()) - exclude_pt = p->m_flushing_volume_btn->GetPosition().x; - else if (p->m_bpButton_add_filament->IsShown()) - exclude_pt = p->m_bpButton_add_filament->GetPosition().x - FromDIP(30); // reserve spacing for delete button - else if (ams_btn->IsShown()) - exclude_pt = ams_btn->GetPosition().x; - if (e.GetPosition().x > exclude_pt) - return; - bool isShown = p->m_filament_area_wrapper->IsShown(); - p->m_filament_area_wrapper->Show(!isShown); - p->m_panel_filament_separator->Show(isShown); - m_scrolled_sizer->Layout(); - CallAfter([this] { update_filaments_counter(true); }); // call after all UI processing done - }); + // Orca: Sidebar - Filament titlebar UI + // add filament title + p->m_panel_filament_title = new StaticBox(p->scrolled, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxBORDER_NONE); + p->m_panel_filament_title->SetBackgroundColor(title_bg); + p->m_panel_filament_title->SetBackgroundColor2(0xF1F1F1); + p->m_panel_filament_title->Bind(wxEVT_LEFT_UP, [this](wxMouseEvent &e) { + if (!p || !p->m_filament_area_wrapper || !m_scrolled_sizer || !p->m_bpButton_set_filament || !p->m_purge_mode_btn || !p->m_flushing_volume_btn || !p->m_bpButton_add_filament || !ams_btn) + return; + // ORCA exclude area of del button from titlebar collapse/expand feature to fix undesired collapse when user spams del filament button + // also block fold/unfold feature when user clicks to spacing between icons + int exclude_pt = p->m_bpButton_set_filament->GetPosition().x; // maximum fixed item + if (p->m_purge_mode_btn->IsShown()) exclude_pt = p->m_purge_mode_btn->GetPosition().x; + else if (p->m_flushing_volume_btn->IsShown()) exclude_pt = p->m_flushing_volume_btn->GetPosition().x; + else if (p->m_bpButton_add_filament->IsShown()) exclude_pt = p->m_bpButton_add_filament->GetPosition().x - FromDIP(30); // reserve spacing for delete button + else if (ams_btn->IsShown()) exclude_pt = ams_btn->GetPosition().x; + if (e.GetPosition().x > exclude_pt) + return; + bool isShown = p->m_filament_area_wrapper->IsShown(); + p->m_filament_area_wrapper->Show(!isShown); + p->m_panel_filament_separator->Show(isShown); + m_scrolled_sizer->Layout(); - wxBoxSizer* bSizer39; - bSizer39 = new wxBoxSizer(wxHORIZONTAL); - p->m_filament_icon = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "filament"); - p->m_staticText_filament_settings = new Label(p->m_panel_filament_title, _L("Project Filaments"), LB_PROPAGATE_MOUSE_EVENT); - bSizer39->Add(p->m_filament_icon, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::TitlebarMargin())); - bSizer39->Add(p->m_staticText_filament_settings, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, FromDIP(SidebarProps::ElementSpacing())); - bSizer39->SetMinSize(-1, FromDIP(30)); + CallAfter([this]{update_filaments_counter(true);}); // call after all UI processing done + }); - p->m_staticText_filament_count = new Label(p->m_panel_filament_title, "(0)", LB_PROPAGATE_MOUSE_EVENT); - bSizer39->Add(p->m_staticText_filament_count, 0, wxALIGN_CENTER); - bSizer39->Add(FromDIP(10), 0, 0, 0, 0); + wxBoxSizer* bSizer39; + bSizer39 = new wxBoxSizer( wxHORIZONTAL ); + p->m_filament_icon = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "filament"); + p->m_staticText_filament_settings = new Label(p->m_panel_filament_title, _L("Project Filaments"), LB_PROPAGATE_MOUSE_EVENT); + bSizer39->Add(p->m_filament_icon, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::TitlebarMargin())); + bSizer39->Add(p->m_staticText_filament_settings, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, FromDIP(SidebarProps::ElementSpacing())); + bSizer39->SetMinSize(-1, FromDIP(30)); - p->m_panel_filament_title->SetSizer(bSizer39); - p->m_panel_filament_title->Layout(); - scrolled_sizer->Add(p->m_panel_filament_title, 0, wxEXPAND | wxALL, 0); - // ORCA add bottom border for seperation wile sections folded - p->m_panel_filament_separator = new wxPanel(p->scrolled, wxID_ANY, wxDefaultPosition, - wxSize(-1, FromDIP(2))); // ORCA staticline class not works without string - p->m_panel_filament_separator->SetBackgroundColour("#FFFFFF"); - scrolled_sizer->Add(p->m_panel_filament_separator, 0, wxEXPAND); + p->m_staticText_filament_count = new Label(p->m_panel_filament_title, "(0)", LB_PROPAGATE_MOUSE_EVENT); + bSizer39->Add(p->m_staticText_filament_count, 0, wxALIGN_CENTER ); + bSizer39->Add(FromDIP(10), 0, 0, 0, 0); - bSizer39->AddStretchSpacer(1); + p->m_panel_filament_title->SetSizer( bSizer39 ); + p->m_panel_filament_title->Layout(); + scrolled_sizer->Add(p->m_panel_filament_title, 0, wxEXPAND | wxALL, 0); + // ORCA add bottom border for seperation wile sections folded + p->m_panel_filament_separator = new wxPanel(p->scrolled, wxID_ANY, wxDefaultPosition, wxSize(-1, FromDIP(2))); // ORCA staticline class not works without string + p->m_panel_filament_separator->SetBackgroundColour("#FFFFFF"); + scrolled_sizer->Add(p->m_panel_filament_separator, 0, wxEXPAND); - p->m_purge_mode_btn = new Button(p->m_panel_filament_title, _L("Purge mode")); - p->m_purge_mode_btn->SetStyle(ButtonStyle::Confirm, ButtonType::Compact); + bSizer39->AddStretchSpacer(1); - p->m_purge_mode_btn->Bind(wxEVT_BUTTON, [](wxCommandEvent& e) { - auto& preset_bundle = *wxGetApp().preset_bundle; - auto support_fast_purge_opt = preset_bundle.printers.get_edited_preset().config.option( - "support_fast_purge_mode"); - bool support_fast_purge = support_fast_purge_opt ? support_fast_purge_opt->value : false; - auto dlg_type = support_fast_purge ? PurgeModeDialogType::FastMode : PurgeModeDialogType::MultiNozzle; - PurgeModeDialog dlg(static_cast(wxGetApp().mainframe), dlg_type); - if (dlg.ShowModal() == wxID_OK) { - preset_bundle.project_config.set_key_value("prime_volume_mode", - new ConfigOptionEnum(dlg.get_selected_mode())); - wxGetApp().plater()->update(); - } - }); + p->m_purge_mode_btn = new Button(p->m_panel_filament_title, _L("Purge mode")); + p->m_purge_mode_btn->SetStyle(ButtonStyle::Confirm, ButtonType::Compact); - bSizer39->Add(p->m_purge_mode_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(4)); - bSizer39->Hide(p->m_purge_mode_btn); // hidden on launch; shown only for printers that support purge mode selection - - // BBS - // add wiping dialog - // wiping_dialog_button->SetFont(wxGetApp().normal_font()); - p->m_flushing_volume_btn = new Button(p->m_panel_filament_title, _L("Flushing volumes")); - p->m_flushing_volume_btn->SetStyle(ButtonStyle::Confirm, ButtonType::Compact); - p->m_flushing_volume_btn->SetId(wxID_RESET); - auto has_modify = is_flush_config_modified(); - set_flushing_volume_warning(has_modify); - - p->m_flushing_volume_btn->Bind(wxEVT_BUTTON, ([parent, this](wxCommandEvent& e) { - open_flushing_dialog(parent, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, parent)); - p->plater->get_view3D_canvas3D()->reload_scene(true); - p->plater->update(); - })); - - bSizer39->Add(p->m_flushing_volume_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(4)); - bSizer39->Hide(p->m_flushing_volume_btn); // ORCA Ensure button is hidden on launch while 1 filament exist - - ScalableButton* add_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "add_filament"); - add_btn->SetToolTip(_L("Add one filament")); - add_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent& e) { - add_filament(); - update_filaments_counter(); - }); - p->m_bpButton_add_filament = add_btn; - - // ORCA Moved add button after delete button to prevent add button position change when remove icon automatically hidden - - ScalableButton* del_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "delete_filament"); - del_btn->SetToolTip(_L("Remove last filament")); - del_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent& e) { - delete_filament(); - update_filaments_counter(); - }); - p->m_bpButton_del_filament = del_btn; - - bSizer39->Add(del_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::IconSpacing())); - bSizer39->Add(add_btn, 0, wxALIGN_CENTER | wxLEFT, - FromDIP(SidebarProps::IconSpacing())); // ORCA Moved add button after delete button to prevent add button position - // change when remove icon automatically hidden - - bSizer39->Hide(p->m_bpButton_del_filament); // ORCA Ensure button is hidden on launch while 1 filament exist - - ams_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "ams_fila_sync", wxEmptyString, wxDefaultSize, wxDefaultPosition, - wxBU_EXACTFIT | wxNO_BORDER, false, 16); // ORCA match icon size with other icons as 16x16 - ams_btn->SetToolTip(_L("Synchronize filament list from AMS")); - ams_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent& e) { sync_ams_list(); }); - - ams_btn->Bind(wxEVT_UPDATE_UI, &Sidebar::update_sync_ams_btn_enable, this); - p->m_bpButton_ams_filament = ams_btn; - - bSizer39->Add(ams_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::WideSpacing())); - // bSizer39->Add(FromDIP(10), 0, 0, 0, 0 ); - - ScalableButton* set_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "settings"); - set_btn->SetToolTip(_L("Set filaments to use")); - set_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) { - p->editing_filament = -1; - // wxGetApp().params_dialog()->Popup(); - // wxGetApp().get_tab(Preset::TYPE_FILAMENT)->restore_last_select_item(); - wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_FILAMENTS); - }); - p->m_bpButton_set_filament = set_btn; - - bSizer39->Add(set_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::WideSpacing())); - bSizer39->AddSpacer(FromDIP(SidebarProps::TitlebarMargin())); - - // ---- Wrapper panel for collapse/expand of all filament content ---- - p->m_filament_area_wrapper = new wxPanel(p->scrolled, wxID_ANY); - p->m_filament_area_wrapper->SetBackgroundColour(*wxWHITE); - auto* wrapper_sizer = new wxBoxSizer(wxVERTICAL); - - // add filament content - p->m_panel_filament_content = new wxScrolledWindow(p->m_filament_area_wrapper, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxTAB_TRAVERSAL); - p->m_panel_filament_content->SetScrollbars(0, 100, 1, 2); - p->m_panel_filament_content->SetScrollRate(0, 5); - // p->m_panel_filament_content->SetMaxSize(wxSize{-1, FromDIP(174)}); - p->m_panel_filament_content->SetBackgroundColour(wxColour(255, 255, 255)); - - // wxBoxSizer* bSizer_filament_content; - // bSizer_filament_content = new wxBoxSizer( wxHORIZONTAL ); - - // Orca: Sidebar - Filament content UI: setup filament selection combos panel layout - // Creates a two-column grid layout for filament selection dropdowns within the scrollable panel - p->sizer_filaments = new wxBoxSizer(wxHORIZONTAL); - p->sizer_filaments->Add(new wxBoxSizer(wxVERTICAL), 1, wxEXPAND); - p->sizer_filaments->Add(new wxBoxSizer(wxVERTICAL), 1, wxEXPAND); - - p->combos_filament.push_back(nullptr); - - /* first filament item */ - init_filament_combo(&p->combos_filament[0], 0); - - // bSizer_filament_content->Add(p->sizer_filaments, 1, wxALIGN_CENTER | wxALL); - wxSizer* sizer_filaments2 = new wxBoxSizer(wxVERTICAL); - sizer_filaments2->Add(p->sizer_filaments, 0, wxEXPAND, 0); - p->m_panel_filament_content->SetSizer(sizer_filaments2); - p->m_panel_filament_content->Layout(); - - update_filaments_area_height(); // ORCA - - wrapper_sizer->Add(p->m_panel_filament_content, 0, wxEXPAND); - - // ---- Mixed-color filament section ---- - // A mixed filament is a virtual slot realized from 2-3 physical filaments at slicing time. - // Everything here stays hidden until at least two physical filaments exist, so a single - // filament setup looks exactly as before. - { - // 1) "+ Add Mixed Filament" button, shown only while no mixed filament exists yet. - p->m_btn_add_mixed_filament = new wxPanel(p->m_filament_area_wrapper, wxID_ANY); - p->m_btn_add_mixed_filament->SetBackgroundColour(StateColor::darkModeColorFor(wxColour("#F8F8F8"))); - p->m_btn_add_mixed_filament->SetMinSize(wxSize(-1, FromDIP(23))); - { - auto* btn_sizer = new wxBoxSizer(wxHORIZONTAL); - auto* icon_add = new ScalableButton(p->m_btn_add_mixed_filament, wxID_ANY, "add_filament", wxEmptyString, wxDefaultSize, - wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, false, 16); - auto* add_label = new wxStaticText(p->m_btn_add_mixed_filament, wxID_ANY, _L("Add Mixed Filament"), wxDefaultPosition, - wxDefaultSize, 0); - add_label->SetFont(::Label::Body_13); - btn_sizer->AddStretchSpacer(); - btn_sizer->Add(icon_add, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(4)); - btn_sizer->Add(add_label, 0, wxALIGN_CENTER_VERTICAL); - btn_sizer->AddStretchSpacer(); - p->m_btn_add_mixed_filament->SetSizer(btn_sizer); - p->m_btn_add_mixed_filament->SetCursor(wxCursor(wxCURSOR_HAND)); - // Whole panel is the hit target, so forward clicks from the children too. - auto on_click = [this](wxMouseEvent&) { add_mixed_filament(); }; - p->m_btn_add_mixed_filament->Bind(wxEVT_LEFT_UP, on_click); - add_label->Bind(wxEVT_LEFT_UP, on_click); - icon_add->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { add_mixed_filament(); }); - } - wrapper_sizer->Add(p->m_btn_add_mixed_filament, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM, FromDIP(8)); - - // 2) Title row with add / remove buttons, shown once a mixed filament exists. - p->m_panel_mixed_title = new wxPanel(p->m_filament_area_wrapper, wxID_ANY); - p->m_panel_mixed_title->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); - { - auto* title_sizer = new wxBoxSizer(wxHORIZONTAL); - p->m_text_mixed_title = new wxStaticText(p->m_panel_mixed_title, wxID_ANY, _L("Mixed Filament")); - p->m_text_mixed_title->SetFont(::Label::Head_14); - title_sizer->Add(p->m_text_mixed_title, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(SidebarProps::TitlebarMargin())); - title_sizer->AddStretchSpacer(); - - p->m_btn_mixed_del = new ScalableButton(p->m_panel_mixed_title, wxID_ANY, "delete_filament"); - p->m_btn_mixed_del->SetToolTip(_L("Remove last mixed filament")); - p->m_btn_mixed_del->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { - auto* plater_ptr = dynamic_cast(GetParent()); - if (!plater_ptr) - return; - auto mixed_indices = plater_ptr->mixed_filament_config_indices(); - if (!mixed_indices.empty()) - delete_mixed_filament_at(mixed_indices.size() - 1); - }); - title_sizer->Add(p->m_btn_mixed_del, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(SidebarProps::IconSpacing())); - - p->m_btn_mixed_add = new ScalableButton(p->m_panel_mixed_title, wxID_ANY, "add_filament"); - p->m_btn_mixed_add->SetToolTip(_L("Add mixed filament")); - p->m_btn_mixed_add->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { add_mixed_filament(); }); - title_sizer->Add(p->m_btn_mixed_add, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(SidebarProps::IconSpacing())); - title_sizer->AddSpacer(FromDIP(SidebarProps::TitlebarMargin())); - - p->m_panel_mixed_title->SetSizer(title_sizer); - } - wrapper_sizer->Add(p->m_panel_mixed_title, 0, wxEXPAND | wxTOP | wxBOTTOM, FromDIP(8)); - - // 3) Mixed filament rows, in their own scroll area so a long mixed list does not - // push the physical filament list off screen. - p->m_mixed_scroll_area = new wxScrolledWindow(p->m_filament_area_wrapper, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxTAB_TRAVERSAL); - p->m_mixed_scroll_area->SetScrollbars(0, 100, 1, 2); - p->m_mixed_scroll_area->SetScrollRate(0, 5); - p->m_mixed_scroll_area->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); - { - auto* mix_scroll_sizer = new wxBoxSizer(wxVERTICAL); - p->m_panel_mixed_content = new wxPanel(p->m_mixed_scroll_area, wxID_ANY); - p->m_panel_mixed_content->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); - - // Two columns, same idiom as sizer_filaments. - p->m_sizer_mixed_filaments = new wxBoxSizer(wxHORIZONTAL); - p->m_sizer_mixed_filaments->Add(new wxBoxSizer(wxVERTICAL), 1, wxEXPAND); - p->m_sizer_mixed_filaments->Add(new wxBoxSizer(wxVERTICAL), 1, wxEXPAND); - - auto* sizer_mixed2 = new wxBoxSizer(wxVERTICAL); - sizer_mixed2->Add(p->m_sizer_mixed_filaments, 0, wxEXPAND, 0); - p->m_panel_mixed_content->SetSizer(sizer_mixed2); - mix_scroll_sizer->Add(p->m_panel_mixed_content, 0, wxEXPAND | wxBOTTOM, FromDIP(8)); - p->m_mixed_scroll_area->SetSizer(mix_scroll_sizer); - } - p->m_mixed_scroll_area->EnableScrolling(false, true); - p->m_mixed_scroll_area->ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_DEFAULT); - p->m_mixed_scroll_area->Bind(wxEVT_SIZE, [this](wxSizeEvent& e) { - int w = p->m_mixed_scroll_area->GetClientSize().GetWidth(); - if (w > 0) - p->m_mixed_scroll_area->SetVirtualSize(w, p->m_mixed_scroll_area->GetVirtualSize().GetHeight()); - e.Skip(); - }); - wrapper_sizer->Add(p->m_mixed_scroll_area, 0, wxEXPAND, 0); - - // 4) Warning bar for mixes whose components were deleted or whose types disagree. - p->m_panel_mixed_warning = new wxPanel(p->m_filament_area_wrapper, wxID_ANY); - p->m_panel_mixed_warning->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); - { - auto* warn_sizer = new wxBoxSizer(wxHORIZONTAL); - p->m_text_mixed_warning = - new wxStaticText(p->m_panel_mixed_warning, wxID_ANY, - _L("Mixed filament has invalid or mismatched components. Please re-edit affected entries.")); - p->m_text_mixed_warning->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#D01B1B"))); - p->m_text_mixed_warning->SetFont(::Label::Body_12); - p->m_text_mixed_warning->Wrap(FromDIP(360)); - warn_sizer->Add(p->m_text_mixed_warning, 1, wxALL, FromDIP(6)); - p->m_panel_mixed_warning->SetSizer(warn_sizer); - } - wrapper_sizer->Add(p->m_panel_mixed_warning, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(8)); - - // Hidden until update_mixed_filament_list() decides otherwise. - p->m_btn_add_mixed_filament->Hide(); - p->m_panel_mixed_title->Hide(); - p->m_mixed_scroll_area->Hide(); - p->m_panel_mixed_content->Hide(); - p->m_panel_mixed_warning->Hide(); + p->m_purge_mode_btn->Bind(wxEVT_BUTTON, [](wxCommandEvent &e) { + auto &preset_bundle = *wxGetApp().preset_bundle; + auto support_fast_purge_opt = preset_bundle.printers.get_edited_preset().config.option("support_fast_purge_mode"); + bool support_fast_purge = support_fast_purge_opt ? support_fast_purge_opt->value : false; + auto dlg_type = support_fast_purge ? PurgeModeDialogType::FastMode : PurgeModeDialogType::MultiNozzle; + PurgeModeDialog dlg(static_cast(wxGetApp().mainframe), dlg_type); + if (dlg.ShowModal() == wxID_OK) { + preset_bundle.project_config.set_key_value("prime_volume_mode", new ConfigOptionEnum(dlg.get_selected_mode())); + wxGetApp().plater()->update(); } - // ---- End mixed-color filament section ---- + }); - p->m_filament_area_wrapper->SetSizer(wrapper_sizer); - p->m_filament_area_wrapper->Layout(); - scrolled_sizer->Add( - p->m_filament_area_wrapper, 0, wxEXPAND | wxTOP | wxBOTTOM, - FromDIP(SidebarProps::ContentMarginV())); // ORCA use vertical margin on parent otherwise it shows scrollbar even on 1 filament - // ---- End filament area ---- + bSizer39->Add(p->m_purge_mode_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(4)); + bSizer39->Hide(p->m_purge_mode_btn); // hidden on launch; shown only for printers that support purge mode selection + + // BBS + // add wiping dialog + //wiping_dialog_button->SetFont(wxGetApp().normal_font()); + p->m_flushing_volume_btn = new Button(p->m_panel_filament_title, _L("Flushing volumes")); + p->m_flushing_volume_btn->SetStyle(ButtonStyle::Confirm, ButtonType::Compact); + p->m_flushing_volume_btn->SetId(wxID_RESET); + auto has_modify = is_flush_config_modified(); + set_flushing_volume_warning(has_modify); + + p->m_flushing_volume_btn->Bind(wxEVT_BUTTON, ([parent, this](wxCommandEvent &e) { + open_flushing_dialog(parent, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, parent)); + p->plater->get_view3D_canvas3D()->reload_scene(true); + p->plater->update(); + })); + + bSizer39->Add(p->m_flushing_volume_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(4)); + bSizer39->Hide(p->m_flushing_volume_btn); // ORCA Ensure button is hidden on launch while 1 filament exist + + ScalableButton* add_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "add_filament"); + add_btn->SetToolTip(_L("Add one filament")); + add_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e){ + add_filament(); + update_filaments_counter(); + }); + p->m_bpButton_add_filament = add_btn; + + // ORCA Moved add button after delete button to prevent add button position change when remove icon automatically hidden + + ScalableButton* del_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "delete_filament"); + del_btn->SetToolTip(_L("Remove last filament")); + del_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { + delete_filament(); + update_filaments_counter(); + }); + p->m_bpButton_del_filament = del_btn; + + bSizer39->Add(del_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::IconSpacing())); + bSizer39->Add(add_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::IconSpacing())); // ORCA Moved add button after delete button to prevent add button position change when remove icon automatically hidden + + bSizer39->Hide(p->m_bpButton_del_filament); // ORCA Ensure button is hidden on launch while 1 filament exist + + ams_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "ams_fila_sync", wxEmptyString, wxDefaultSize, wxDefaultPosition, + wxBU_EXACTFIT | wxNO_BORDER, false, 16); // ORCA match icon size with other icons as 16x16 + ams_btn->SetToolTip(_L("Synchronize filament list from AMS")); + ams_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { + sync_ams_list(); + }); + + ams_btn->Bind(wxEVT_UPDATE_UI, &Sidebar::update_sync_ams_btn_enable, this); + p->m_bpButton_ams_filament = ams_btn; + + bSizer39->Add(ams_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::WideSpacing())); + //bSizer39->Add(FromDIP(10), 0, 0, 0, 0 ); + + ScalableButton* set_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "settings"); + set_btn->SetToolTip(_L("Set filaments to use")); + set_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { + p->editing_filament = -1; + // wxGetApp().params_dialog()->Popup(); + // wxGetApp().get_tab(Preset::TYPE_FILAMENT)->restore_last_select_item(); + wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_FILAMENTS); + }); + p->m_bpButton_set_filament = set_btn; + + bSizer39->Add(set_btn, 0, wxALIGN_CENTER | wxLEFT, FromDIP(SidebarProps::WideSpacing())); + bSizer39->AddSpacer(FromDIP(SidebarProps::TitlebarMargin())); + + // ---- Wrapper panel for collapse/expand of all filament content ---- + p->m_filament_area_wrapper = new wxPanel(p->scrolled, wxID_ANY); + p->m_filament_area_wrapper->SetBackgroundColour(*wxWHITE); + auto* wrapper_sizer = new wxBoxSizer(wxVERTICAL); + + // add filament content + p->m_panel_filament_content = new wxScrolledWindow(p->m_filament_area_wrapper, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); + p->m_panel_filament_content->SetScrollbars(0, 100, 1, 2); + p->m_panel_filament_content->SetScrollRate(0, 5); + //p->m_panel_filament_content->SetMaxSize(wxSize{-1, FromDIP(174)}); + p->m_panel_filament_content->SetBackgroundColour(wxColour(255, 255, 255)); + + //wxBoxSizer* bSizer_filament_content; + //bSizer_filament_content = new wxBoxSizer( wxHORIZONTAL ); + + // Orca: Sidebar - Filament content UI: setup filament selection combos panel layout + // Creates a two-column grid layout for filament selection dropdowns within the scrollable panel + p->sizer_filaments = new wxBoxSizer(wxHORIZONTAL); + p->sizer_filaments->Add(new wxBoxSizer(wxVERTICAL), 1, wxEXPAND); + p->sizer_filaments->Add(new wxBoxSizer(wxVERTICAL), 1, wxEXPAND); + + p->combos_filament.push_back(nullptr); + + /* first filament item */ + init_filament_combo(&p->combos_filament[0], 0); + + //bSizer_filament_content->Add(p->sizer_filaments, 1, wxALIGN_CENTER | wxALL); + wxSizer *sizer_filaments2 = new wxBoxSizer(wxVERTICAL); + sizer_filaments2->Add(p->sizer_filaments, 0, wxEXPAND, 0); + p->m_panel_filament_content->SetSizer(sizer_filaments2); + p->m_panel_filament_content->Layout(); + + update_filaments_area_height(); // ORCA + + wrapper_sizer->Add(p->m_panel_filament_content, 0, wxEXPAND); + + // ---- Mixed-color filament section ---- + // A mixed filament is a virtual slot realized from 2-3 physical filaments at slicing time. + // Everything here stays hidden until at least two physical filaments exist, so a single + // filament setup looks exactly as before. + { + // 1) "+ Add Mixed Filament" button, shown only while no mixed filament exists yet. + p->m_btn_add_mixed_filament = new wxPanel(p->m_filament_area_wrapper, wxID_ANY); + p->m_btn_add_mixed_filament->SetBackgroundColour(StateColor::darkModeColorFor(wxColour("#F8F8F8"))); + p->m_btn_add_mixed_filament->SetMinSize(wxSize(-1, FromDIP(23))); + { + auto* btn_sizer = new wxBoxSizer(wxHORIZONTAL); + auto* icon_add = new ScalableButton(p->m_btn_add_mixed_filament, wxID_ANY, "add_filament", wxEmptyString, + wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, false, 16); + auto* add_label = new wxStaticText(p->m_btn_add_mixed_filament, wxID_ANY, _L("Add Mixed Filament"), + wxDefaultPosition, wxDefaultSize, 0); + add_label->SetFont(::Label::Body_13); + btn_sizer->AddStretchSpacer(); + btn_sizer->Add(icon_add, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(4)); + btn_sizer->Add(add_label, 0, wxALIGN_CENTER_VERTICAL); + btn_sizer->AddStretchSpacer(); + p->m_btn_add_mixed_filament->SetSizer(btn_sizer); + p->m_btn_add_mixed_filament->SetCursor(wxCursor(wxCURSOR_HAND)); + // Whole panel is the hit target, so forward clicks from the children too. + auto on_click = [this](wxMouseEvent&) { add_mixed_filament(); }; + p->m_btn_add_mixed_filament->Bind(wxEVT_LEFT_UP, on_click); + add_label->Bind(wxEVT_LEFT_UP, on_click); + icon_add->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { add_mixed_filament(); }); + } + wrapper_sizer->Add(p->m_btn_add_mixed_filament, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM, FromDIP(8)); + + // 2) Title row with add / remove buttons, shown once a mixed filament exists. + p->m_panel_mixed_title = new wxPanel(p->m_filament_area_wrapper, wxID_ANY); + p->m_panel_mixed_title->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); + { + auto* title_sizer = new wxBoxSizer(wxHORIZONTAL); + p->m_text_mixed_title = new wxStaticText(p->m_panel_mixed_title, wxID_ANY, _L("Mixed Filament")); + p->m_text_mixed_title->SetFont(::Label::Head_14); + title_sizer->Add(p->m_text_mixed_title, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(SidebarProps::TitlebarMargin())); + title_sizer->AddStretchSpacer(); + + p->m_btn_mixed_del = new ScalableButton(p->m_panel_mixed_title, wxID_ANY, "delete_filament"); + p->m_btn_mixed_del->SetToolTip(_L("Remove last mixed filament")); + p->m_btn_mixed_del->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { + auto* plater_ptr = dynamic_cast(GetParent()); + if (!plater_ptr) return; + auto mixed_indices = plater_ptr->mixed_filament_config_indices(); + if (!mixed_indices.empty()) + delete_mixed_filament_at(mixed_indices.size() - 1); + }); + title_sizer->Add(p->m_btn_mixed_del, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(SidebarProps::IconSpacing())); + + p->m_btn_mixed_add = new ScalableButton(p->m_panel_mixed_title, wxID_ANY, "add_filament"); + p->m_btn_mixed_add->SetToolTip(_L("Add mixed filament")); + p->m_btn_mixed_add->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { add_mixed_filament(); }); + title_sizer->Add(p->m_btn_mixed_add, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(SidebarProps::IconSpacing())); + title_sizer->AddSpacer(FromDIP(SidebarProps::TitlebarMargin())); + + p->m_panel_mixed_title->SetSizer(title_sizer); + } + wrapper_sizer->Add(p->m_panel_mixed_title, 0, wxEXPAND | wxTOP | wxBOTTOM, FromDIP(8)); + + // 3) Mixed filament rows, in their own scroll area so a long mixed list does not + // push the physical filament list off screen. + p->m_mixed_scroll_area = new wxScrolledWindow(p->m_filament_area_wrapper, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + p->m_mixed_scroll_area->SetScrollbars(0, 100, 1, 2); + p->m_mixed_scroll_area->SetScrollRate(0, 5); + p->m_mixed_scroll_area->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); + { + auto* mix_scroll_sizer = new wxBoxSizer(wxVERTICAL); + p->m_panel_mixed_content = new wxPanel(p->m_mixed_scroll_area, wxID_ANY); + p->m_panel_mixed_content->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); + + // Two columns, same idiom as sizer_filaments. + p->m_sizer_mixed_filaments = new wxBoxSizer(wxHORIZONTAL); + p->m_sizer_mixed_filaments->Add(new wxBoxSizer(wxVERTICAL), 1, wxEXPAND); + p->m_sizer_mixed_filaments->Add(new wxBoxSizer(wxVERTICAL), 1, wxEXPAND); + + auto* sizer_mixed2 = new wxBoxSizer(wxVERTICAL); + sizer_mixed2->Add(p->m_sizer_mixed_filaments, 0, wxEXPAND, 0); + p->m_panel_mixed_content->SetSizer(sizer_mixed2); + mix_scroll_sizer->Add(p->m_panel_mixed_content, 0, wxEXPAND | wxBOTTOM, FromDIP(8)); + p->m_mixed_scroll_area->SetSizer(mix_scroll_sizer); + } + p->m_mixed_scroll_area->EnableScrolling(false, true); + p->m_mixed_scroll_area->ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_DEFAULT); + p->m_mixed_scroll_area->Bind(wxEVT_SIZE, [this](wxSizeEvent& e) { + int w = p->m_mixed_scroll_area->GetClientSize().GetWidth(); + if (w > 0) + p->m_mixed_scroll_area->SetVirtualSize(w, p->m_mixed_scroll_area->GetVirtualSize().GetHeight()); + e.Skip(); + }); + wrapper_sizer->Add(p->m_mixed_scroll_area, 0, wxEXPAND, 0); + + // 4) Warning bar for mixes whose components were deleted or whose types disagree. + p->m_panel_mixed_warning = new wxPanel(p->m_filament_area_wrapper, wxID_ANY); + p->m_panel_mixed_warning->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); + { + auto* warn_sizer = new wxBoxSizer(wxHORIZONTAL); + p->m_text_mixed_warning = new wxStaticText(p->m_panel_mixed_warning, wxID_ANY, + _L("Mixed filament has invalid or mismatched components. Please re-edit affected entries.")); + p->m_text_mixed_warning->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#D01B1B"))); + p->m_text_mixed_warning->SetFont(::Label::Body_12); + p->m_text_mixed_warning->Wrap(FromDIP(360)); + warn_sizer->Add(p->m_text_mixed_warning, 1, wxALL, FromDIP(6)); + p->m_panel_mixed_warning->SetSizer(warn_sizer); + } + wrapper_sizer->Add(p->m_panel_mixed_warning, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(8)); + + // Hidden until update_mixed_filament_list() decides otherwise. + p->m_btn_add_mixed_filament->Hide(); + p->m_panel_mixed_title->Hide(); + p->m_mixed_scroll_area->Hide(); + p->m_panel_mixed_content->Hide(); + p->m_panel_mixed_warning->Hide(); + } + // ---- End mixed-color filament section ---- + + p->m_filament_area_wrapper->SetSizer(wrapper_sizer); + p->m_filament_area_wrapper->Layout(); + scrolled_sizer->Add(p->m_filament_area_wrapper, 0, wxEXPAND | wxTOP | wxBOTTOM, FromDIP(SidebarProps::ContentMarginV())); // ORCA use vertical margin on parent otherwise it shows scrollbar even on 1 filament + // ---- End filament area ---- } { - // add project title - auto params_panel = ((MainFrame*) parent->GetParent())->m_param_panel; - if (params_panel) { - params_panel->get_top_panel()->Reparent(p->scrolled); - auto spliter_1 = new ::StaticLine(p->scrolled); - spliter_1->SetLineColour("#A6A9AA"); - scrolled_sizer->Add(spliter_1, 0, wxEXPAND); - scrolled_sizer->Add(params_panel->get_top_panel(), 0, wxEXPAND); - auto spliter_2 = new ::StaticLine(p->scrolled); - spliter_2->SetLineColour("#CECECE"); - scrolled_sizer->Add(spliter_2, 0, wxEXPAND); + //add project title + auto params_panel = ((MainFrame*)parent->GetParent())->m_param_panel; + if (params_panel) { + params_panel->get_top_panel()->Reparent(p->scrolled); + auto spliter_1 = new ::StaticLine(p->scrolled); + spliter_1->SetLineColour("#A6A9AA"); + scrolled_sizer->Add(spliter_1, 0, wxEXPAND); + scrolled_sizer->Add(params_panel->get_top_panel(), 0, wxEXPAND); + auto spliter_2 = new ::StaticLine(p->scrolled); + spliter_2->SetLineColour("#CECECE"); + scrolled_sizer->Add(spliter_2, 0, wxEXPAND); + } + + //add project content + p->sizer_params = new wxBoxSizer(wxVERTICAL); + + // ORCA: Update search box to modern style + p->m_search_bar = new StaticBox(p->scrolled); + p->m_search_bar->SetCornerRadius(0); + p->m_search_bar->SetBorderColor(wxColour("#CECECE")); + + p->m_search_item = new TextInput(p->m_search_bar, wxEmptyString, wxEmptyString, "", wxDefaultPosition, wxDefaultSize, 0 | wxBORDER_NONE); + p->m_search_item->SetIcon(*BitmapCache().load_svg("search", FromDIP(16), FromDIP(16))); // ORCA: Add search icon to search box + + wxTextCtrl* text_ctrl = p->m_search_item->GetTextCtrl(); + text_ctrl->SetHint(_L("Search plate, object and part.")); + text_ctrl->SetForegroundColour(wxColour("#262E30")); + text_ctrl->SetFont(Label::Body_13); + text_ctrl->SetSize(wxSize(-1, FromDIP(16))); // Centers text vertically + + text_ctrl->Bind(wxEVT_SET_FOCUS, [this](wxFocusEvent& e) { + if (p->dia->IsShown()) { + e.Skip(); + return; } - - // add project content - p->sizer_params = new wxBoxSizer(wxVERTICAL); - - // ORCA: Update search box to modern style - p->m_search_bar = new StaticBox(p->scrolled); - p->m_search_bar->SetCornerRadius(0); - p->m_search_bar->SetBorderColor(wxColour("#CECECE")); - - p->m_search_item = new TextInput(p->m_search_bar, wxEmptyString, wxEmptyString, "", wxDefaultPosition, wxDefaultSize, - 0 | wxBORDER_NONE); - p->m_search_item->SetIcon(*BitmapCache().load_svg("search", FromDIP(16), FromDIP(16))); // ORCA: Add search icon to search box - - wxTextCtrl* text_ctrl = p->m_search_item->GetTextCtrl(); - text_ctrl->SetHint(_L("Search plate, object and part.")); - text_ctrl->SetForegroundColour(wxColour("#262E30")); - text_ctrl->SetFont(Label::Body_13); - text_ctrl->SetSize(wxSize(-1, FromDIP(16))); // Centers text vertically - - text_ctrl->Bind(wxEVT_SET_FOCUS, [this](wxFocusEvent& e) { - if (p->dia->IsShown()) { - e.Skip(); - return; - } - p->m_search_bar->SetBorderColor(wxColour("#009688")); - wxPoint pos = this->p->m_search_bar->ClientToScreen(wxPoint(0, 0)); + p->m_search_bar->SetBorderColor(wxColour("#009688")); + wxPoint pos = this->p->m_search_bar->ClientToScreen(wxPoint(0, 0)); #ifndef __WXGTK__ - pos.y += this->p->m_search_bar->GetRect().height; + pos.y += this->p->m_search_bar->GetRect().height; #else this->p->m_search_item->Enable(false); #endif - p->dia->SetPosition(pos); - p->dia->Popup(); - e.Skip(); // required to show caret - }); + p->dia->SetPosition(pos); + p->dia->Popup(); + e.Skip(); // required to show caret + }); - auto search_sizer = new wxBoxSizer(wxHORIZONTAL); - search_sizer->Add(new wxWindow(p->m_search_bar, wxID_ANY, wxDefaultPosition, wxSize(0, 0)), 0, wxEXPAND | wxLEFT | wxRIGHT, - FromDIP(1)); - search_sizer->Add(p->m_search_item, 1, wxEXPAND | wxALL, FromDIP(2)); - p->m_search_bar->SetSizer(search_sizer); - p->m_search_bar->Layout(); - search_sizer->Fit(p->m_search_bar); + auto search_sizer = new wxBoxSizer(wxHORIZONTAL); + search_sizer->Add(new wxWindow(p->m_search_bar, wxID_ANY, wxDefaultPosition, wxSize(0, 0)), 0, wxEXPAND|wxLEFT|wxRIGHT, FromDIP(1)); + search_sizer->Add(p->m_search_item, 1, wxEXPAND | wxALL, FromDIP(2)); + p->m_search_bar->SetSizer(search_sizer); + p->m_search_bar->Layout(); + search_sizer->Fit(p->m_search_bar); - p->m_object_list = new ObjectList(p->scrolled); - p->m_object_list->Bind(wxCUSTOMEVT_EXIT_SEARCH, [this](wxCommandEvent&) { + p->m_object_list = new ObjectList(p->scrolled); + p->m_object_list->Bind(wxCUSTOMEVT_EXIT_SEARCH, [this](wxCommandEvent&) { #ifdef __WXGTK__ - this->p->m_search_item->Enable(true); + this->p->m_search_item->Enable(true); #endif - this->p->m_search_bar->SetBorderColor(wxColour("#CECECE")); - this->p->m_search_item->GetTextCtrl()->SetValue(""); // reset value when close - }); + this->p->m_search_bar->SetBorderColor(wxColour("#CECECE")); + this->p->m_search_item->GetTextCtrl()->SetValue(""); // reset value when close + }); - p->sizer_params->Add(p->m_search_bar, 0, wxALL | wxEXPAND, 0); - p->sizer_params->Add(p->m_object_list, 1, wxEXPAND | wxTOP, 0); - scrolled_sizer->Add(p->sizer_params, 2, wxEXPAND | wxLEFT, 0); - p->m_object_list->Hide(); - p->m_search_bar->Hide(); - // Frequently Object Settings - p->object_settings = new ObjectSettings(p->scrolled); + p->sizer_params->Add(p->m_search_bar, 0, wxALL | wxEXPAND, 0); + p->sizer_params->Add(p->m_object_list, 1, wxEXPAND | wxTOP, 0); + scrolled_sizer->Add(p->sizer_params, 2, wxEXPAND | wxLEFT, 0); + p->m_object_list->Hide(); + p->m_search_bar->Hide(); + // Frequently Object Settings + p->object_settings = new ObjectSettings(p->scrolled); - p->dia = new Search::SearchObjectDialog(p->m_object_list, p->scrolled->GetParent(), p->m_search_item); + p->dia = new Search::SearchObjectDialog(p->m_object_list, p->scrolled->GetParent(), p->m_search_item); #if !NEW_OBJECT_SETTING - p->object_settings->Hide(); - p->sizer_params->Add(p->object_settings->get_sizer(), 0, wxEXPAND | wxTOP, 5 * em / 10); + p->object_settings->Hide(); + p->sizer_params->Add(p->object_settings->get_sizer(), 0, wxEXPAND | wxTOP, 5 * em / 10); #else - if (params_panel) { - params_panel->Reparent(p->scrolled); - scrolled_sizer->Add(params_panel, 3, wxEXPAND); - } + if (params_panel) { + params_panel->Reparent(p->scrolled); + scrolled_sizer->Add(params_panel, 3, wxEXPAND); + } #endif } @@ -3306,71 +3264,67 @@ Sidebar::Sidebar(Plater* parent) : wxPanel(parent, wxID_ANY, wxDefaultPosition, p->object_layers->Hide(); p->sizer_params->Add(p->object_layers->get_sizer(), 0, wxEXPAND | wxTOP, 0); - auto* sizer = new wxBoxSizer(wxVERTICAL); + auto *sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(p->scrolled, 1, wxEXPAND); SetSizer(sizer); } Sidebar::~Sidebar() {} -void Sidebar::on_enter_image_printer_bed(wxMouseEvent& evt) -{ - // p->image_printer_bed->Bind(wxEVT_LEAVE_WINDOW, &Sidebar::on_leave_image_printer_bed, this); - auto pos = p->panel_printer_bed->GetScreenPosition(); - auto rect = p->panel_printer_bed->GetRect(); - wxPoint temp_pos(pos.x + rect.GetWidth() + FromDIP(3), pos.y); +void Sidebar::on_enter_image_printer_bed(wxMouseEvent &evt) { + //p->image_printer_bed->Bind(wxEVT_LEAVE_WINDOW, &Sidebar::on_leave_image_printer_bed, this); + auto pos = p->panel_printer_bed->GetScreenPosition(); + auto rect = p->panel_printer_bed->GetRect(); + wxPoint temp_pos(pos.x + rect.GetWidth() + FromDIP(3), pos.y); if (p->big_bed_image_popup == nullptr) p->big_bed_image_popup = new ImageDPIFrame(); - auto image_path = get_cur_select_bed_image(); - p->big_bed_image_popup->set_bitmap( - create_scaled_bitmap("big_" + image_path, p->big_bed_image_popup, p->big_bed_image_popup->get_image_px())); + auto image_path = get_cur_select_bed_image(); + p->big_bed_image_popup->set_bitmap(create_scaled_bitmap("big_" + image_path, p->big_bed_image_popup, p->big_bed_image_popup->get_image_px())); p->big_bed_image_popup->set_title(p->combo_printer_bed->GetString(p->combo_printer_bed->GetSelection())); p->big_bed_image_popup->SetCanFocus(false); p->big_bed_image_popup->SetPosition(temp_pos); p->big_bed_image_popup->on_show(); } -void Sidebar::on_leave_image_printer_bed(wxMouseEvent& evt) -{ - // auto pos_x = evt.GetX(); - // auto pos_y = evt.GetY(); - // auto rect = p->image_printer_bed->GetRect(); - // if ((pos_x <= 0 || pos_y <= 0 || pos_x >= rect.GetWidth()) && p->big_bed_image_popup) { +void Sidebar::on_leave_image_printer_bed(wxMouseEvent &evt) { + //auto pos_x = evt.GetX(); + //auto pos_y = evt.GetY(); + //auto rect = p->image_printer_bed->GetRect(); + //if ((pos_x <= 0 || pos_y <= 0 || pos_x >= rect.GetWidth()) && p->big_bed_image_popup) { if (p->big_bed_image_popup) { bool was_visible = p->big_bed_image_popup->IsShown(); p->big_bed_image_popup->on_hide(); - if (!p->combo_printer_bed->is_drop_down() && was_visible) - p->combo_printer_bed->SetFocus(); // set focus back to bed type combo. this prevents weird look if focus on other item + if(!p->combo_printer_bed->is_drop_down() && was_visible) + p->combo_printer_bed->SetFocus(); // set focus back to bed type combo. this prevents weird look if focus on other item } } -void Sidebar::on_change_color_mode(bool is_dark) -{ - const ModelObjectPtrs& mos = wxGetApp().model().objects; +void Sidebar::on_change_color_mode(bool is_dark) { + const ModelObjectPtrs &mos = wxGetApp().model().objects; for (int i = 0; i < mos.size(); i++) { - wxGetApp().obj_list()->update_info_items(i, nullptr, false, true); + wxGetApp().obj_list()->update_info_items(i,nullptr,false,true); } + } void Sidebar::create_printer_preset() { CreatePrinterPresetDialog dlg(wxGetApp().mainframe); - int res = dlg.ShowModal(); + int res = dlg.ShowModal(); if (wxID_OK == res) { wxGetApp().load_current_presets(); wxGetApp().mainframe->update_side_preset_ui(); update_ui_from_settings(); update_all_preset_comboboxes(); CreatePresetSuccessfulDialog success_dlg(wxGetApp().mainframe, SuccessType::PRINTER); - int res = success_dlg.ShowModal(); + int res = success_dlg.ShowModal(); if (res == wxID_OK) { p->editing_filament = -1; - if (p->combo_printer->switch_to_tab()) - p->editing_filament = 0; + if (p->combo_printer->switch_to_tab()) p->editing_filament = 0; } } } -void Sidebar::init_filament_combo(PlaterPresetComboBox** combo, const int filament_idx) +void Sidebar::init_filament_combo(PlaterPresetComboBox **combo, const int filament_idx) { *combo = new PlaterPresetComboBox(p->m_panel_filament_content, Slic3r::Preset::TYPE_FILAMENT); (*combo)->set_filament_idx(filament_idx); @@ -3384,10 +3338,8 @@ void Sidebar::init_filament_combo(PlaterPresetComboBox** combo, const int filame combo_and_btn_sizer->AddSpacer(FromDIP((filament_idx % 2) == 0 ? 12 : 3)); // Content Margin (*combo)->clr_picker->SetLabel(wxString::Format("%d", filament_idx + 1)); - combo_and_btn_sizer->Add((*combo)->clr_picker, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, - FromDIP(SidebarProps::ElementSpacing()) - FromDIP(2)); // ElementSpacing - 2 (from combo box)) - combo_and_btn_sizer->Add(*combo, 1, wxALL | wxEXPAND, FromDIP(2)) - ->SetMinSize({-1, 30 * wxGetApp().em_unit() / 10}); // ORCA ensure height matches with PlaterPresetComboBox + combo_and_btn_sizer->Add((*combo)->clr_picker, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(SidebarProps::ElementSpacing()) - FromDIP(2)); // ElementSpacing - 2 (from combo box)) + combo_and_btn_sizer->Add(*combo, 1, wxALL | wxEXPAND, FromDIP(2))->SetMinSize({-1, 30 * wxGetApp().em_unit() / 10}); // ORCA ensure height matches with PlaterPresetComboBox /* BBS hide del_btn ScalableButton* del_btn = new ScalableButton(p->m_panel_filament_content, wxID_ANY, "delete_filament"); @@ -3410,15 +3362,16 @@ void Sidebar::init_filament_combo(PlaterPresetComboBox** combo, const int filame edit_btn->Bind(wxEVT_BUTTON, [this, edit_btn, combobox, filament_idx](wxCommandEvent) { bool single_or_bbl = should_show_SEMM_buttons(); bool is_multi_material = p->combos_filament.size() > 1; - if (single_or_bbl && is_multi_material) { - // MULTI MATERIAL Show menu + if(single_or_bbl && is_multi_material) { + // MULTI MATERIAL Show menu auto menu = p->plater->filament_action_menu(filament_idx); - wxPoint pt{0, edit_btn->GetSize().GetHeight() + FromDIP(2)}; - pt = edit_btn->ClientToScreen(pt); - pt = wxGetApp().mainframe->ScreenToClient(pt); + wxPoint pt { 0, edit_btn->GetSize().GetHeight() + FromDIP(2) }; + pt = edit_btn->ClientToScreen(pt); + pt = wxGetApp().mainframe->ScreenToClient(pt); p->m_menu_filament_id = filament_idx; p->plater->PopupMenu(menu, (int) pt.x, pt.y); - } else { + } + else { // SINGLE MATERIAL / MULTI EXTRUDER / TOOLCHANGER / IDEX Opens Dialog directly p->editing_filament = filament_idx; combobox->switch_to_tab(); @@ -3426,16 +3379,14 @@ void Sidebar::init_filament_combo(PlaterPresetComboBox** combo, const int filame }); combobox->edit_btn = edit_btn; - combo_and_btn_sizer->Add(edit_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, - FromDIP(SidebarProps::ElementSpacing()) - FromDIP(2)); // ElementSpacing - 2 (from combo box)) + combo_and_btn_sizer->Add(edit_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(SidebarProps::ElementSpacing()) - FromDIP(2)); // ElementSpacing - 2 (from combo box)) combo_and_btn_sizer->AddSpacer(FromDIP(SidebarProps::ContentMargin())); // BBS: filament double columns - auto side = filament_idx % 2; - auto /***/ sizer_filaments = this->p->sizer_filaments->GetItem(side)->GetSizer(); - if (side == 1 && filament_idx > 1) - sizer_filaments->Remove(filament_idx / 2); + auto side = filament_idx % 2; + auto /***/sizer_filaments = this->p->sizer_filaments->GetItem(side)->GetSizer(); + if (side == 1 && filament_idx > 1) sizer_filaments->Remove(filament_idx / 2); sizer_filaments->Add(combo_and_btn_sizer, 1, wxEXPAND); if (side == 0 && filament_idx > 0) { sizer_filaments = this->p->sizer_filaments->GetItem(1)->GetSizer(); @@ -3448,14 +3399,14 @@ void Sidebar::remove_unused_filament_combos(const size_t current_extruder_count) if (current_extruder_count >= p->combos_filament.size()) return; while (p->combos_filament.size() > current_extruder_count) { - const int last = p->combos_filament.size() - 1; + const int last = p->combos_filament.size() - 1; auto sizer_filaments = this->p->sizer_filaments->GetItem(last % 2)->GetSizer(); sizer_filaments->Remove(last / 2); (*p->combos_filament[last]).Destroy(); p->combos_filament.pop_back(); } // BBS: filament double columns - auto sizer_filaments0 = this->p->sizer_filaments->GetItem((size_t) 0)->GetSizer(); + auto sizer_filaments0 = this->p->sizer_filaments->GetItem((size_t)0)->GetSizer(); auto sizer_filaments1 = this->p->sizer_filaments->GetItem(1)->GetSizer(); if (current_extruder_count < 2) { sizer_filaments1->Clear(); @@ -3471,27 +3422,27 @@ void Sidebar::remove_unused_filament_combos(const size_t current_extruder_count) void Sidebar::update_all_preset_comboboxes() { - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; - const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology(); + PresetBundle &preset_bundle = *wxGetApp().preset_bundle; + const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology(); bool is_bbl_vendor = preset_bundle.is_bbl_vendor(); - auto p_mainframe = wxGetApp().mainframe; - auto cfg = preset_bundle.printers.get_edited_preset().config; - const bool use_printer_agents = wxGetApp().app_config->get_bool("use_printer_agents"); + auto p_mainframe = wxGetApp().mainframe; + auto cfg = preset_bundle.printers.get_edited_preset().config; + const bool use_printer_agents = wxGetApp().app_config->get_bool("use_printer_agents"); const bool use_native_device_tab = preset_bundle.use_bbl_device_tab() || use_printer_agents; if (preset_bundle.use_bbl_network()) { - // only show connection button for not-BBL printer - // p->btn_connect_printer->Hide(); + //only show connection button for not-BBL printer + //p->btn_connect_printer->Hide(); p->m_printer_connect->Hide(); - // only show sync-ams button for BBL printer + //only show sync-ams button for BBL printer p->m_bpButton_ams_filament->Show(); - // update print button default value for bbl or third-party printer + //update print button default value for bbl or third-party printer p_mainframe->set_print_button_to_default(MainFrame::PrintSelectType::ePrintPlate); } else { - // p->btn_connect_printer->Show(); - // ORCA: hide the physical-printer connection button when printer agents are enabled + //p->btn_connect_printer->Show(); + // ORCA: hide the physical-printer connection button when printer agents are enabled p->m_printer_connect->Show(!use_printer_agents); // ORCA: show/hide sync-ams button based on filament sync mode @@ -3504,19 +3455,19 @@ void Sidebar::update_all_preset_comboboxes() // Orca: with "Support 3MF as gcode" (use_3mf) the local export is a .gcode.3mf bundle, so when no // printer host/IP is configured the default action is "Export plate sliced file" (mirrors the // print dropdown) instead of "Export G-code file". - auto print_btn_type = cfg.opt_bool("use_3mf") ? MainFrame::PrintSelectType::eExportSlicedFile : - MainFrame::PrintSelectType::eExportGcode; - wxString url = from_u8(PrintHost::get_print_host_webui(&cfg)); + auto print_btn_type = cfg.opt_bool("use_3mf") ? MainFrame::PrintSelectType::eExportSlicedFile + : MainFrame::PrintSelectType::eExportGcode; + wxString url = from_u8(PrintHost::get_print_host_webui(&cfg)); wxString apikey; - if (url.empty()) + if(url.empty()) url = wxString::Format("file://%s/web/orca/missing_connection.html", from_u8(resources_dir())); else { const auto host_type = cfg.option>("host_type")->value; if (cfg.has("printhost_apikey") && (host_type != htSimplyPrint)) apikey = cfg.opt_string("printhost_apikey"); - print_btn_type = (preset_bundle.is_bbl_vendor() || wxGetApp().app_config->get_bool("use_printer_agents")) ? - MainFrame::PrintSelectType::ePrintPlate : - MainFrame::PrintSelectType::eSendGcode; + print_btn_type = (preset_bundle.is_bbl_vendor() || wxGetApp().app_config->get_bool("use_printer_agents")) + ? MainFrame::PrintSelectType::ePrintPlate + : MainFrame::PrintSelectType::eSendGcode; } if (use_printer_agents) @@ -3524,27 +3475,29 @@ void Sidebar::update_all_preset_comboboxes() else if (!use_native_device_tab) p_mainframe->load_printer_url(url, apikey); + p_mainframe->set_print_button_to_default(print_btn_type); + } if (cfg.opt_bool("pellet_modded_printer")) { - p->m_staticText_filament_settings->SetLabel(_L("Pellets")); + p->m_staticText_filament_settings->SetLabel(_L("Pellets")); p->m_filament_icon->SetBitmap_("pellets"); } else { - p->m_staticText_filament_settings->SetLabel(_L("Filament")); + p->m_staticText_filament_settings->SetLabel(_L("Filament")); p->m_filament_icon->SetBitmap_("filament"); } show_SEMM_buttons(); - // p->m_staticText_filament_settings->Update(); + //p->m_staticText_filament_settings->Update(); if (is_bbl_vendor || cfg.opt_bool("support_multi_bed_types")) { p->combo_printer_bed->Enable(); // Orca: don't update bed type if loading project if (!p->plater->is_loading_project()) { bool has_changed = reset_bed_type_combox_choices(); - bool flag = m_begin_sync_printer_status && !has_changed; + bool flag = m_begin_sync_printer_status && !has_changed; if (!(flag)) { auto str_bed_type = wxGetApp().app_config->get_printer_setting(wxGetApp().preset_bundle->printers.get_selected_preset_name(), "curr_bed_type"); @@ -3554,7 +3507,7 @@ void Sidebar::update_all_preset_comboboxes() bed_type_value = preset_bundle.printers.get_edited_preset().get_default_bed_type(&preset_bundle); } - set_bed_type_accord_combox((BedType) bed_type_value); + set_bed_type_accord_combox((BedType) bed_type_value); } else { BedType bed_type = preset_bundle.printers.get_edited_preset().get_default_bed_type(&preset_bundle); set_bed_type_accord_combox(bed_type); @@ -3574,10 +3527,10 @@ void Sidebar::update_all_preset_comboboxes() p->panel_printer_bed->Show(is_bbl_vendor || cfg.opt_bool("support_multi_bed_types")); // Update the print choosers to only contain the compatible presets, update the dirty flags. - // BBS + //BBS // Update the printer choosers, update the dirty flags. - // p->combo_printer->update(); + //p->combo_printer->update(); // Update the filament choosers to only contain the compatible presets, update the color preview, // update the dirty flags. if (print_tech == ptFFF) { @@ -3596,12 +3549,13 @@ void Sidebar::update_all_preset_comboboxes() void Sidebar::update_presets(Preset::Type preset_type) { - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; - const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology(); + PresetBundle &preset_bundle = *wxGetApp().preset_bundle; + const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology(); - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": enter, preset_type %1%") % preset_type; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": enter, preset_type %1%")%preset_type; switch (preset_type) { - case Preset::TYPE_FILAMENT: { + case Preset::TYPE_FILAMENT: + { // BBS #if 0 const size_t extruder_cnt = print_tech != ptFFF ? 1 : @@ -3610,16 +3564,16 @@ void Sidebar::update_presets(Preset::Type preset_type) #else const size_t filament_cnt = p->combos_filament.size(); #endif - const std::string& name = preset_bundle.filaments.get_selected_preset_name(); + const std::string &name = preset_bundle.filaments.get_selected_preset_name(); if (p->editing_filament >= 0) { preset_bundle.set_filament_preset(p->editing_filament, name); } else if (filament_cnt == 1) { // Single filament printer, synchronize the filament presets. - Preset* preset = preset_bundle.filaments.find_preset(name, false); + Preset *preset = preset_bundle.filaments.find_preset(name, false); if (preset) { - if (preset->is_compatible) - preset_bundle.set_filament_preset(0, name); + if (preset->is_compatible) preset_bundle.set_filament_preset(0, name); } + } for (size_t i = 0; i < filament_cnt; i++) @@ -3630,22 +3584,25 @@ void Sidebar::update_presets(Preset::Type preset_type) } case Preset::TYPE_PRINT: - // wxGetApp().mainframe->m_param_panel; - // p->combo_print->update(); + //wxGetApp().mainframe->m_param_panel; + //p->combo_print->update(); { - Tab* print_tab = wxGetApp().get_tab(Preset::TYPE_PRINT); - if (print_tab) { - print_tab->get_combo_box()->update(); - } - break; + Tab* print_tab = wxGetApp().get_tab(Preset::TYPE_PRINT); + if (print_tab) { + print_tab->get_combo_box()->update(); } - case Preset::TYPE_SLA_PRINT:; // p->combo_sla_print->update(); + break; + } + case Preset::TYPE_SLA_PRINT: + ;// p->combo_sla_print->update(); break; - case Preset::TYPE_SLA_MATERIAL:; // p->combo_sla_material->update(); + case Preset::TYPE_SLA_MATERIAL: + ;// p->combo_sla_material->update(); break; - case Preset::TYPE_PRINTER: { + case Preset::TYPE_PRINTER: + { update_all_preset_comboboxes(); p->show_preset_comboboxes(); @@ -3659,17 +3616,17 @@ void Sidebar::update_presets(Preset::Type preset_type) Preset& printer_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); if (auto printer_structure_opt = printer_preset.config.option>("printer_structure")) { - wxGetApp().plater()->get_current_canvas3D()->get_arrange_settings().align_to_y_axis = (printer_structure_opt->value == - PrinterStructure::psI3); - } else + wxGetApp().plater()->get_current_canvas3D()->get_arrange_settings().align_to_y_axis = (printer_structure_opt->value == PrinterStructure::psI3); + } + else wxGetApp().plater()->get_current_canvas3D()->get_arrange_settings().align_to_y_axis = false; // Update dual extrudes - auto* nozzle_diameter = dynamic_cast(printer_preset.config.option("nozzle_diameter")); - auto extruder_variants = printer_preset.config.option("extruder_variant_list"); + auto* nozzle_diameter = dynamic_cast(printer_preset.config.option("nozzle_diameter")); + auto extruder_variants = printer_preset.config.option("extruder_variant_list"); std::string printer_model = printer_preset.config.option("printer_model")->value; - bool isBBL = preset_bundle.is_bbl_vendor(); + bool isBBL = preset_bundle.is_bbl_vendor(); bool is_dual_extruder = extruder_variants->size() == 2; // why: agent mode drives the native device tab, so the sidebar lays out like BBL // (no physical-printer connect button). @@ -3680,40 +3637,36 @@ void Sidebar::update_presets(Preset::Type preset_type) // UI left = DEPUTY_EXTRUDER_ID(1), UI right = MAIN_EXTRUDER_ID(0) if (is_dual_extruder) { std::string printer_type = printer_preset.get_printer_type(wxGetApp().preset_bundle); - auto left_title = DevPrinterConfigUtil::get_toolhead_display_name(printer_type, DEPUTY_EXTRUDER_ID, ToolHeadComponent::Nozzle, - ToolHeadNameCase::TitleCase); - auto right_title = DevPrinterConfigUtil::get_toolhead_display_name(printer_type, MAIN_EXTRUDER_ID, ToolHeadComponent::Nozzle, - ToolHeadNameCase::TitleCase); + auto left_title = DevPrinterConfigUtil::get_toolhead_display_name(printer_type, DEPUTY_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::TitleCase); + auto right_title = DevPrinterConfigUtil::get_toolhead_display_name(printer_type, MAIN_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::TitleCase); p->left_extruder->SetTitle(_L(left_title)); p->right_extruder->SetTitle(_L(right_title)); } - auto extruders_def = printer_preset.config.def()->get("extruder_type"); - auto extruders = printer_preset.config.option("extruder_type"); - auto nozzle_volumes_def = wxGetApp().preset_bundle->project_config.def()->get("nozzle_volume_type"); - auto nozzle_volumes = wxGetApp().preset_bundle->project_config.option("nozzle_volume_type"); - auto diameters = wxGetApp().preset_bundle->printers.diameters_of_selected_printer(); - auto diameter = printer_preset.config.opt_string("printer_variant"); + auto extruders_def = printer_preset.config.def()->get("extruder_type"); + auto extruders = printer_preset.config.option("extruder_type"); + auto nozzle_volumes_def = wxGetApp().preset_bundle->project_config.def()->get("nozzle_volume_type"); + auto nozzle_volumes = wxGetApp().preset_bundle->project_config.option("nozzle_volume_type"); + auto diameters = wxGetApp().preset_bundle->printers.diameters_of_selected_printer(); + auto diameter = printer_preset.config.opt_string("printer_variant"); auto extruder_max_nozzle_count = printer_preset.config.option("extruder_max_nozzle_count"); - auto update_extruder_variant = [printer_model, extruders_def, extruders, nozzle_volumes_def, nozzle_volumes, extruder_variants, - diameter, extruder_max_nozzle_count](ExtruderGroup& extruder, int index) { + auto update_extruder_variant = [printer_model, extruders_def, extruders, nozzle_volumes_def, nozzle_volumes, extruder_variants,diameter,extruder_max_nozzle_count](ExtruderGroup & extruder, int index) { extruder.combo_flow->Clear(); - auto type = extruders_def->enum_labels[extruders->values[index]]; + auto type = extruders_def->enum_labels[extruders->values[index]]; int select = -1; for (size_t i = 0; i < nozzle_volumes_def->enum_labels.size(); ++i) { // get_at falls back to the first entry when a profile defines no per-extruder value, // so extruders without an explicit sub-nozzle count never offer Hybrid. A nullable-int // nil is INT_MAX (> 1) and would otherwise falsely pass the gate, so exclude it too. if (boost::algorithm::contains(extruder_variants->values[index], type + " " + nozzle_volumes_def->enum_labels[i]) || - extruder_max_nozzle_count->get_at(index) > 1 && - extruder_max_nozzle_count->get_at(index) != ConfigOptionIntsNullable::nil_value() && - nozzle_volumes_def->enum_keys_map->at(nozzle_volumes_def->enum_values[i]) == nvtHybrid) { - if (nozzle_volumes_def->enum_keys_map->at(nozzle_volumes_def->enum_values[i]) == NozzleVolumeType::nvtHighFlow && - (diameter == "0.2" || is_skip_high_flow_printer(printer_model))) + extruder_max_nozzle_count->get_at(index) > 1 && extruder_max_nozzle_count->get_at(index) != ConfigOptionIntsNullable::nil_value() && + nozzle_volumes_def->enum_keys_map->at(nozzle_volumes_def->enum_values[i]) == nvtHybrid) { + if (nozzle_volumes_def->enum_keys_map->at(nozzle_volumes_def->enum_values[i]) == NozzleVolumeType::nvtHighFlow &&(diameter == "0.2" || + is_skip_high_flow_printer(printer_model))) continue; if (nozzle_volumes->values[index] == i) select = extruder.combo_flow->GetCount(); - extruder.combo_flow->Append(_L(nozzle_volumes_def->enum_labels[i]), {}, (void*) i); + extruder.combo_flow->Append(_L(nozzle_volumes_def->enum_labels[i]), {}, (void*)i); } } if (select == -1) @@ -3727,7 +3680,7 @@ void Sidebar::update_presets(Preset::Type preset_type) // ORCA get the actual nozzle diameter from printer config auto nozzle_dia = get_diameter_string(nozzle_diameter->values[extruder_index]); // ORCA try to add nozzle diameter from config if list is empty. fixes blank nozzle combo box when preset has no alias - if (diameters[0].empty() && !nozzle_dia.empty()) { + if(diameters[0].empty() && !nozzle_dia.empty()){ diameters[0] = nozzle_dia; } // Orca: Check if the actual nozzle diameter exists in the list, if not add it as a custom option @@ -3745,38 +3698,34 @@ void Sidebar::update_presets(Preset::Type preset_type) auto image_path = get_cur_select_bed_image(); if (is_dual_extruder) { std::string printer_type = printer_preset.get_printer_type(wxGetApp().preset_bundle); - p->left_extruder->SetTitle( - _L(DevPrinterConfigUtil::get_toolhead_display_name(printer_type, DEPUTY_EXTRUDER_ID, ToolHeadComponent::Nozzle, - ToolHeadNameCase::TitleCase))); - p->right_extruder->SetTitle( - _L(DevPrinterConfigUtil::get_toolhead_display_name(printer_type, MAIN_EXTRUDER_ID, ToolHeadComponent::Nozzle, - ToolHeadNameCase::TitleCase))); + p->left_extruder->SetTitle(_L(DevPrinterConfigUtil::get_toolhead_display_name(printer_type, DEPUTY_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::TitleCase))); + p->right_extruder->SetTitle(_L(DevPrinterConfigUtil::get_toolhead_display_name(printer_type, MAIN_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::TitleCase))); AMSCountPopupWindow::UpdateAMSCount(0, p->left_extruder); AMSCountPopupWindow::UpdateAMSCount(1, p->right_extruder); update_extruder_variant(*p->left_extruder, 0); update_extruder_variant(*p->right_extruder, 1); - // if (!p->is_switching_diameter) { - update_extruder_diameter(0, *p->left_extruder); - update_extruder_diameter(1, *p->right_extruder); + //if (!p->is_switching_diameter) { + update_extruder_diameter(0, *p->left_extruder); + update_extruder_diameter(1, *p->right_extruder); //} p->image_printer_bed->SetBitmap(create_scaled_bitmap(image_path, this, PRINTER_THUMBNAIL_SIZE.GetHeight())); } else { AMSCountPopupWindow::UpdateAMSCount(0, p->single_extruder); update_extruder_variant(*p->single_extruder, 0); - // if (!p->is_switching_diameter) - update_extruder_diameter(0, *p->single_extruder); + //if (!p->is_switching_diameter) + update_extruder_diameter(0, *p->single_extruder); // ORCA sync unified nozzle combo box p->combo_nozzle_dia->Clear(); for (size_t i = 0; i < diameters.size(); ++i) p->combo_nozzle_dia->Append(diameters[i], {}); p->combo_nozzle_dia->SetSelection((*p->single_extruder).combo_diameter->GetSelection()); - + // ORCA update nozzle type - const auto& full_config = wxGetApp().preset_bundle->full_config(); - wxString nozzle_type = "-"; + const auto& full_config = wxGetApp().preset_bundle->full_config(); + wxString nozzle_type = "-"; const ConfigOptionEnumsGenericNullable* cfg_nozzle_type = full_config.option("nozzle_type"); - if (cfg_nozzle_type != nullptr) { + if(cfg_nozzle_type != nullptr){ std::vector nozzle_types(cfg_nozzle_type->size()); for (size_t idx = 0; idx < cfg_nozzle_type->size(); ++idx) nozzle_types[idx] = NozzleType(cfg_nozzle_type->values[idx]); @@ -3784,8 +3733,8 @@ void Sidebar::update_presets(Preset::Type preset_type) nozzle_types[0] == ntHardenedSteel ? "Hardened Steel" : nozzle_types[0] == ntStainlessSteel ? "Stainless Steel" : nozzle_types[0] == ntTungstenCarbide ? "Tungsten Carbide" : - nozzle_types[0] == ntBrass ? "Brass" : - "-" // Undefined + nozzle_types[0] == ntBrass ? "Brass" + : "-" // Undefined ); } p->label_nozzle_type->SetLabel(nozzle_type); @@ -3811,17 +3760,19 @@ void Sidebar::update_presets(Preset::Type preset_type) BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": exit."); } -// BBS +//BBS void Sidebar::update_presets_from_to(Slic3r::Preset::Type preset_type, std::string from, std::string to) { - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; + PresetBundle &preset_bundle = *wxGetApp().preset_bundle; - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": enter, preset_type %1%, from %2% to %3%") % preset_type % from % to; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": enter, preset_type %1%, from %2% to %3%")%preset_type %from %to; switch (preset_type) { - case Preset::TYPE_FILAMENT: { + case Preset::TYPE_FILAMENT: + { const size_t filament_cnt = p->combos_filament.size(); - for (auto it = preset_bundle.filament_presets.begin(); it != preset_bundle.filament_presets.end(); it++) { + for (auto it = preset_bundle.filament_presets.begin(); it != preset_bundle.filament_presets.end(); it++) + { if ((*it).compare(from) == 0) { (*it) = to; } @@ -3840,8 +3791,7 @@ void Sidebar::update_presets_from_to(Slic3r::Preset::Type preset_type, std::stri BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": exit!"); } -BedType Sidebar::get_cur_select_bed_type() -{ +BedType Sidebar::get_cur_select_bed_type() { int selection = p->combo_printer_bed->GetSelection(); if (selection < 0 && selection >= m_cur_combox_bed_types.size()) { p->combo_printer_bed->SetSelection(0); @@ -3853,14 +3803,13 @@ BedType Sidebar::get_cur_select_bed_type() std::string Sidebar::get_cur_select_bed_image() { - auto select_bed_type = get_cur_select_bed_type(); - // auto series_suffix_str = m_cur_image_bed_type.empty() ? "" : ("_" + m_cur_image_bed_type); - auto image_path = bed_type_thumbnails[select_bed_type]; // + series_suffix_str; + auto select_bed_type = get_cur_select_bed_type(); + //auto series_suffix_str = m_cur_image_bed_type.empty() ? "" : ("_" + m_cur_image_bed_type); + auto image_path = bed_type_thumbnails[select_bed_type];// + series_suffix_str; return image_path; } -void Sidebar::set_bed_type_accord_combox(BedType bed_type) -{ +void Sidebar::set_bed_type_accord_combox(BedType bed_type) { for (size_t i = 0; i < m_cur_combox_bed_types.size(); i++) { if (m_cur_combox_bed_types[i] == bed_type) { p->combo_printer_bed->SelectAndNotify(i); @@ -3884,28 +3833,28 @@ bool Sidebar::reset_bed_type_combox_choices(bool is_sidebar_init) } if (m_last_combo_bedtype_count != 0 && pm) { auto cur_count = (int) BedType::btCount - 1 - pm->not_support_bed_types.size(); - if (cur_count == m_last_combo_bedtype_count) { // no change + if (cur_count == m_last_combo_bedtype_count) {//no change return false; } } - const ConfigOptionDef* bed_type_def = print_config_def.get("curr_bed_type"); + const ConfigOptionDef *bed_type_def = print_config_def.get("curr_bed_type"); p->combo_printer_bed->Clear(); m_cur_combox_bed_types.clear(); - if (pm && bed_type_def && bed_type_def->enum_keys_map) { + if (pm &&bed_type_def && bed_type_def->enum_keys_map) { int index = 0; for (auto item : bed_type_def->enum_labels) { index++; - bool find = std::find(pm->not_support_bed_types.begin(), pm->not_support_bed_types.end(), item) != - pm->not_support_bed_types.end(); + bool find = std::find(pm->not_support_bed_types.begin(), pm->not_support_bed_types.end(), item) != pm->not_support_bed_types.end(); if (find) { continue; } - m_cur_combox_bed_types.emplace_back(BedType(index)); // BedType //btPC =1 + m_cur_combox_bed_types.emplace_back(BedType(index));//BedType //btPC =1 p->combo_printer_bed->AppendString(_L(item)); } - } else { + } + else { m_cur_image_bed_type = ""; - int index = 0; + int index = 0; for (auto item : bed_type_def->enum_labels) { index++; m_cur_combox_bed_types.emplace_back(BedType(index)); // BedType //btPC =1 @@ -3930,6 +3879,7 @@ void Sidebar::change_top_border_for_mode_sizer(bool increase_border) #endif } + // ---- Mixed-color filament sidebar support ---- // The mixed rows get their own scroll area, capped by Orca's filaments_area_preferred_count // row budget rather than BBS's fixed 3-row / 12-filament limit. @@ -3939,11 +3889,11 @@ void Sidebar::recalc_filament_scroll_sizes() return; // Same preferred-row budget the physical list uses, so both lists cap consistently. - auto left_sizer = p->sizer_filaments->GetItem((size_t) 0)->GetSizer(); - auto combo_sizer = left_sizer->GetItem((size_t) 0)->GetSizer(); - const int row_h = combo_sizer ? combo_sizer->GetSize().GetHeight() : 0; + auto left_sizer = p->sizer_filaments->GetItem((size_t) 0)->GetSizer(); + auto combo_sizer = left_sizer->GetItem((size_t) 0)->GetSizer(); + const int row_h = combo_sizer ? combo_sizer->GetSize().GetHeight() : 0; int preferred_rows = std::ceil(0.5 * std::stoi(wxGetApp().app_config->get("filaments_area_preferred_count"))); - const int max_h = (row_h > 0) ? preferred_rows * row_h : -1; + const int max_h = (row_h > 0) ? preferred_rows * row_h : -1; auto content_size = p->m_mixed_scroll_area->GetSizer()->GetMinSize(); if (max_h > 0 && content_size.y > max_h) { @@ -3954,9 +3904,9 @@ void Sidebar::recalc_filament_scroll_sizes() } p->m_mixed_scroll_area->SetMinSize({0, content_size.y}); } -static std::string blend_mixed_color(const std::vector& comp_ids, - const std::vector& ratios, - const std::vector& color_strs) +static std::string blend_mixed_color(const std::vector &comp_ids, + const std::vector &ratios, + const std::vector &color_strs) { std::vector hex_colors; hex_colors.reserve(comp_ids.size()); @@ -3968,8 +3918,7 @@ static std::string blend_mixed_color(const std::vector& comp_ids, void Sidebar::update_mixed_filament_list() { auto* plater = dynamic_cast(GetParent()); - if (!plater) - return; + if (!plater) return; wxWindowUpdateLocker noUpdates(this); @@ -3979,17 +3928,17 @@ void Sidebar::update_mixed_filament_list() const wxColour mc_dim = StateColor::darkModeColorFor(wxColour("#ACACAC")); auto& project_config = wxGetApp().preset_bundle->project_config; - auto mixed_indices = plater->mixed_filament_config_indices(); - size_t num_physical = p->combos_filament.size(); + auto mixed_indices = plater->mixed_filament_config_indices(); + size_t num_physical = p->combos_filament.size(); - auto* is_mixed_opt = project_config.option("filament_is_mixed"); - auto* components_opt = project_config.option("filament_mixed_components"); - auto* ratios_opt = project_config.option("filament_mixed_sublayer_ratios"); - auto* colours_opt = project_config.option("filament_colour"); - auto* grad_opt = project_config.option("filament_mixed_gradient"); - auto* grad_range_opt = project_config.option("filament_mixed_gradient_range"); + auto* is_mixed_opt = project_config.option("filament_is_mixed"); + auto* components_opt = project_config.option("filament_mixed_components"); + auto* ratios_opt = project_config.option("filament_mixed_sublayer_ratios"); + auto* colours_opt = project_config.option("filament_colour"); + auto* grad_opt = project_config.option("filament_mixed_gradient"); + auto* grad_range_opt = project_config.option("filament_mixed_gradient_range"); - bool can_mix = (num_physical >= 2); + bool can_mix = (num_physical >= 2); bool has_mixed = can_mix && !mixed_indices.empty(); // Check integrity of mixed filament component references @@ -4011,11 +3960,11 @@ void Sidebar::update_mixed_filament_list() ft = preset->config.get_filament_type(display_type); } } - if (ft.empty()) - ft = "PLA"; + if (ft.empty()) ft = "PLA"; physical_types.push_back(ft); } - auto type_mismatch_slots = check_mixed_filament_type_consistency(is_mixed_opt->values, components_opt->values, physical_types); + auto type_mismatch_slots = check_mixed_filament_type_consistency( + is_mixed_opt->values, components_opt->values, physical_types); for (size_t s : type_mismatch_slots) broken_set.insert(s); broken_slots.insert(broken_slots.end(), type_mismatch_slots.begin(), type_mismatch_slots.end()); @@ -4035,8 +3984,8 @@ void Sidebar::update_mixed_filament_list() auto* notify = wxGetApp().plater()->get_notification_manager(); if (notify) notify->push_notification(NotificationType::BBLMixedFilamentBroken, - NotificationManager::NotificationLevel::ErrorNotificationLevel, - _u8L("Mixed filament has invalid or mismatched components. Please re-edit affected entries.")); + NotificationManager::NotificationLevel::ErrorNotificationLevel, + _u8L("Mixed filament has invalid or mismatched components. Please re-edit affected entries.")); } else { auto* notify = wxGetApp().plater()->get_notification_manager(); if (notify) @@ -4057,7 +4006,7 @@ void Sidebar::update_mixed_filament_list() auto make_swatch_panel = [this](wxWindow* parent, const wxColour& col, unsigned int num) -> wxPanel* { int swatch_sz = FromDIP(20); - auto* panel = new wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(swatch_sz, swatch_sz)); + auto* panel = new wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(swatch_sz, swatch_sz)); panel->SetMinSize(wxSize(swatch_sz, swatch_sz)); bool is_dark = wxGetApp().dark_mode(); panel->Bind(wxEVT_PAINT, [panel, col, num, is_dark](wxPaintEvent&) { @@ -4079,13 +4028,14 @@ void Sidebar::update_mixed_filament_list() dc.SetFont(::Label::Body_14); wxSize txt_sz = dc.GetTextExtent(txt); dc.SetTextForeground(col.GetLuminance() > 0.5 ? wxColour(50, 58, 61) : *wxWHITE); - dc.DrawText(txt, (sz.GetWidth() - txt_sz.GetWidth()) / 2, (sz.GetHeight() - txt_sz.GetHeight()) / 2); + dc.DrawText(txt, (sz.GetWidth() - txt_sz.GetWidth()) / 2, + (sz.GetHeight() - txt_sz.GetHeight()) / 2); }); return panel; }; for (size_t i = 0; i < mixed_indices.size(); ++i) { - size_t cfg_idx = mixed_indices[i]; + size_t cfg_idx = mixed_indices[i]; auto* combo_and_btn_sizer = new wxBoxSizer(wxHORIZONTAL); combo_and_btn_sizer->Add(FromDIP(10), 0, 0, 0, 0); @@ -4109,13 +4059,15 @@ void Sidebar::update_mixed_filament_list() while (std::getline(iss, tok, ',')) { float v = 0; if (std::sscanf(tok.c_str(), "%f", &v) == 1) - comp_ratios.push_back((int) (v * 100 + 0.5f)); + comp_ratios.push_back((int)(v * 100 + 0.5f)); } } if (!comp_ids.empty() && comp_ratios.size() != comp_ids.size()) { - BOOST_LOG_TRIVIAL(warning) << "Mixed filament slot " << cfg_idx << ": ratio count (" << comp_ratios.size() - << ") != component count (" << comp_ids.size() << "), resetting to even distribution"; - int n = (int) comp_ids.size(); + BOOST_LOG_TRIVIAL(warning) << "Mixed filament slot " << cfg_idx + << ": ratio count (" << comp_ratios.size() + << ") != component count (" << comp_ids.size() + << "), resetting to even distribution"; + int n = (int)comp_ids.size(); comp_ratios.assign(n, 100 / n); comp_ratios[0] += 100 - (100 / n) * n; } @@ -4136,8 +4088,8 @@ void Sidebar::update_mixed_filament_list() } } - bool is_gradient = false; - int gradient_direction = 0; + bool is_gradient = false; + int gradient_direction = 0; if (grad_opt && cfg_idx < grad_opt->values.size()) is_gradient = grad_opt->values[cfg_idx]; if (is_gradient && grad_range_opt && cfg_idx < grad_range_opt->values.size()) { @@ -4147,18 +4099,20 @@ void Sidebar::update_mixed_filament_list() gradient_direction = (v0 > v1) ? 0 : 1; } - std::string mix_color_str = (colours_opt && cfg_idx < colours_opt->values.size()) ? colours_opt->values[cfg_idx] : "#888888"; + std::string mix_color_str = (colours_opt && cfg_idx < colours_opt->values.size()) + ? colours_opt->values[cfg_idx] : "#888888"; wxColour mix_col(mix_color_str); - unsigned int mix_num = (unsigned int) (cfg_idx + 1); + unsigned int mix_num = (unsigned int)(cfg_idx + 1); // The swatch fades bottom to top over the model's height, sampled the same way // the slicer builds the sublayers, so it matches the editor's Effect Preview. The // ramp comes back empty for every slot that is not a two component gradient mix. - const int swatch_sz = FromDIP(20); + const int swatch_sz = FromDIP(20); const std::vector gradient_ramp = mixed_gradient_ramp(project_config, cfg_idx, swatch_sz); if (!gradient_ramp.empty()) { - auto* grad_panel = new wxPanel(p->m_panel_mixed_content, wxID_ANY, wxDefaultPosition, wxSize(swatch_sz, swatch_sz)); + auto* grad_panel = new wxPanel(p->m_panel_mixed_content, wxID_ANY, + wxDefaultPosition, wxSize(swatch_sz, swatch_sz)); grad_panel->SetMinSize(wxSize(swatch_sz, swatch_sz)); grad_panel->SetBackgroundStyle(wxBG_STYLE_PAINT); grad_panel->Bind(wxEVT_PAINT, [grad_panel, gradient_ramp, mix_num](wxPaintEvent&) { @@ -4171,12 +4125,13 @@ void Sidebar::update_mixed_filament_list() // The number sits at the swatch's middle, so take its contrast from the // colour printed at mid height rather than from either endpoint. dc.SetTextForeground(gradient_ramp[gradient_ramp.size() / 2].GetLuminance() > 0.5 ? wxColour(50, 58, 61) : *wxWHITE); - dc.DrawText(txt, (sz.GetWidth() - txt_sz.GetWidth()) / 2, (sz.GetHeight() - txt_sz.GetHeight()) / 2); + dc.DrawText(txt, (sz.GetWidth() - txt_sz.GetWidth()) / 2, + (sz.GetHeight() - txt_sz.GetHeight()) / 2); }); combo_and_btn_sizer->Add(grad_panel, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(4)); } else { - combo_and_btn_sizer->Add(make_swatch_panel(p->m_panel_mixed_content, mix_col, mix_num), 0, - wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(4)); + combo_and_btn_sizer->Add(make_swatch_panel(p->m_panel_mixed_content, mix_col, mix_num), + 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(4)); } auto* content_panel = new wxPanel(p->m_panel_mixed_content, wxID_ANY); @@ -4194,11 +4149,11 @@ void Sidebar::update_mixed_filament_list() // Build per-component colour list for the lambda std::vector cp_colours; - std::vector cp_valid; + std::vector cp_valid; std::vector cp_ids = comp_ids; - std::vector cp_ratios = comp_ratios; - bool cp_is_gradient = is_gradient; - int cp_gradient_dir = gradient_direction; + std::vector cp_ratios = comp_ratios; + bool cp_is_gradient = is_gradient; + int cp_gradient_dir = gradient_direction; for (size_t ci = 0; ci < comp_ids.size(); ++ci) { bool valid = (comp_ids[ci] >= 1 && comp_ids[ci] <= physical_colors.size()); cp_valid.push_back(valid); @@ -4207,16 +4162,17 @@ void Sidebar::update_mixed_filament_list() // Reorder for gradient display: from -> to std::vector draw_ids; - std::vector draw_ratios; - std::vector draw_colours; - std::vector draw_valid; + std::vector draw_ratios; + std::vector draw_colours; + std::vector draw_valid; if (cp_is_gradient && cp_ids.size() == 2) { - int fi = (cp_gradient_dir == 0) ? 0 : 1; - int ti = 1 - fi; - draw_ids = {cp_ids[fi], cp_ids[ti]}; - draw_ratios = {cp_ratios.size() > (size_t) fi ? cp_ratios[fi] : 0, cp_ratios.size() > (size_t) ti ? cp_ratios[ti] : 0}; - draw_colours = {cp_colours[fi], cp_colours[ti]}; - draw_valid = {cp_valid[fi], cp_valid[ti]}; + int fi = (cp_gradient_dir == 0) ? 0 : 1; + int ti = 1 - fi; + draw_ids = { cp_ids[fi], cp_ids[ti] }; + draw_ratios = { cp_ratios.size() > (size_t)fi ? cp_ratios[fi] : 0, + cp_ratios.size() > (size_t)ti ? cp_ratios[ti] : 0 }; + draw_colours = { cp_colours[fi], cp_colours[ti] }; + draw_valid = { cp_valid[fi], cp_valid[ti] }; } else { draw_ids = cp_ids; draw_ratios = cp_ratios; @@ -4224,9 +4180,11 @@ void Sidebar::update_mixed_filament_list() draw_valid = cp_valid; } - content_panel->Bind(wxEVT_PAINT, [content_panel, mc_bg, mc_border, mc_text, mc_dim, cp_pad, cp_swatch_sz, cp_sep_margin, - cp_pct_left, cp_gap, cp_pct_gap, cp_is_dark, cp_is_gradient, draw_ids, draw_ratios, - draw_colours, draw_valid](wxPaintEvent&) { + content_panel->Bind(wxEVT_PAINT, [content_panel, mc_bg, mc_border, mc_text, mc_dim, + cp_pad, cp_swatch_sz, cp_sep_margin, cp_pct_left, + cp_gap, cp_pct_gap, cp_is_dark, + cp_is_gradient, + draw_ids, draw_ratios, draw_colours, draw_valid](wxPaintEvent&) { wxBufferedPaintDC dc(content_panel); wxSize sz = content_panel->GetClientSize(); @@ -4235,22 +4193,24 @@ void Sidebar::update_mixed_filament_list() dc.DrawRectangle(0, 0, sz.GetWidth(), sz.GetHeight()); dc.SetFont(::Label::Body_13); - int x = cp_pad; - int y_swatch = (sz.GetHeight() - cp_swatch_sz) / 2; - int text_h = dc.GetTextExtent(wxT("A")).GetHeight(); - int y_text = y_swatch + (cp_swatch_sz - text_h) / 2; - int avail = sz.GetWidth() - cp_pad; + int x = cp_pad; + int y_swatch = (sz.GetHeight() - cp_swatch_sz) / 2; + int text_h = dc.GetTextExtent(wxT("A")).GetHeight(); + int y_text = y_swatch + (cp_swatch_sz - text_h) / 2; + int avail = sz.GetWidth() - cp_pad; wxString ellipsis = wxT("..."); - int ellipsis_w = dc.GetTextExtent(ellipsis).GetWidth(); + int ellipsis_w = dc.GetTextExtent(ellipsis).GetWidth(); - auto fits = [&](int needed) -> bool { return (x + needed) <= (avail - ellipsis_w); }; + auto fits = [&](int needed) -> bool { + return (x + needed) <= (avail - ellipsis_w); + }; size_t n = draw_ids.size(); for (size_t ci = 0; ci < n; ++ci) { // Separator: "+" or arrow if (ci > 0) { wxString sep = cp_is_gradient ? wxT("\u2192") : wxT("+"); - int sep_w = dc.GetTextExtent(sep).GetWidth() + cp_sep_margin * 2; + int sep_w = dc.GetTextExtent(sep).GetWidth() + cp_sep_margin * 2; if (!fits(sep_w + cp_swatch_sz)) { dc.SetTextForeground(mc_text); dc.DrawText(ellipsis, x, y_text); @@ -4284,27 +4244,29 @@ void Sidebar::update_mixed_filament_list() dc.DrawRectangle(x, y_swatch, cp_swatch_sz, cp_swatch_sz); } dc.SetFont(::Label::Body_14); - wxString num = wxString::Format("%u", draw_ids[ci]); + wxString num = wxString::Format("%u", draw_ids[ci]); wxSize num_sz = dc.GetTextExtent(num); dc.SetTextForeground(col.GetLuminance() > 0.5 ? wxColour(50, 58, 61) : *wxWHITE); - dc.DrawText(num, x + (cp_swatch_sz - num_sz.GetWidth()) / 2, y_swatch + (cp_swatch_sz - num_sz.GetHeight()) / 2); + dc.DrawText(num, x + (cp_swatch_sz - num_sz.GetWidth()) / 2, + y_swatch + (cp_swatch_sz - num_sz.GetHeight()) / 2); dc.SetFont(::Label::Body_13); } else { dc.SetBrush(wxBrush(mc_bg)); dc.SetPen(wxPen(mc_dim, 1)); dc.DrawRectangle(x, y_swatch, cp_swatch_sz, cp_swatch_sz); - wxString dash = wxT("\u2014"); + wxString dash = wxT("\u2014"); wxSize dash_sz = dc.GetTextExtent(dash); dc.SetTextForeground(mc_dim); - dc.DrawText(dash, x + (cp_swatch_sz - dash_sz.GetWidth()) / 2, y_swatch + (cp_swatch_sz - dash_sz.GetHeight()) / 2); + dc.DrawText(dash, x + (cp_swatch_sz - dash_sz.GetWidth()) / 2, + y_swatch + (cp_swatch_sz - dash_sz.GetHeight()) / 2); } x += cp_swatch_sz + cp_gap; // Ratio text (skip for gradient) if (!cp_is_gradient) { - int r = (ci < draw_ratios.size()) ? draw_ratios[ci] : 0; + int r = (ci < draw_ratios.size()) ? draw_ratios[ci] : 0; wxString pct = wxString::Format("%d%%", r); - int pct_w = dc.GetTextExtent(pct).GetWidth(); + int pct_w = dc.GetTextExtent(pct).GetWidth(); if (!fits(pct_w)) { dc.SetTextForeground(mc_text); dc.DrawText(ellipsis, x, y_text); @@ -4321,8 +4283,7 @@ void Sidebar::update_mixed_filament_list() { wxString tip; for (size_t ci = 0; ci < draw_ids.size(); ++ci) { - if (ci > 0) - tip += cp_is_gradient ? wxT(" \u2192 ") : wxT(" + "); + if (ci > 0) tip += cp_is_gradient ? wxT(" \u2192 ") : wxT(" + "); int r = (ci < draw_ratios.size()) ? draw_ratios[ci] : 0; tip += wxString::Format("%u (%d%%)", draw_ids[ci], r); } @@ -4341,19 +4302,22 @@ void Sidebar::update_mixed_filament_list() combo_and_btn_sizer->Add(content_panel, 1, wxALL | wxEXPAND, FromDIP(2))->SetMinSize({-1, FromDIP(30)}); - auto* menu_btn = new ScalableButton(p->m_panel_mixed_content, wxID_ANY, is_broken ? "error" : "menu_filament"); + auto* menu_btn = new ScalableButton(p->m_panel_mixed_content, wxID_ANY, + is_broken ? "error" : "menu_filament"); menu_btn->SetToolTip(is_broken ? _L("Mixed filament has broken component references") : _L("Edit / Delete / Merge")); menu_btn->Bind(wxEVT_BUTTON, [this, panel_idx, cfg_idx](wxCommandEvent&) { wxMenu menu; auto* edit_item = menu.Append(wxID_ANY, _L("Edit")); - menu.Bind(wxEVT_MENU, [this, panel_idx](wxCommandEvent&) { edit_mixed_filament(panel_idx); }, edit_item->GetId()); + menu.Bind(wxEVT_MENU, [this, panel_idx](wxCommandEvent&) { + edit_mixed_filament(panel_idx); + }, edit_item->GetId()); - wxMenu* sub_menu = new wxMenu(); + wxMenu* sub_menu = new wxMenu(); std::vector icons = get_extruder_color_icons(true); - int filaments_cnt = icons.size(); + int filaments_cnt = icons.size(); for (int j = 0; j < filaments_cnt; ++j) { - if ((size_t) j == cfg_idx) + if ((size_t)j == cfg_idx) continue; wxString item_name; @@ -4361,8 +4325,10 @@ void Sidebar::update_mixed_filament_list() if (is_target_mixed) { item_name = wxString::Format(_L("Filament %d"), j + 1); } else { - auto preset = wxGetApp().preset_bundle->filaments.find_preset(wxGetApp().preset_bundle->filament_presets[j]); - item_name = preset ? from_u8(preset->label(false)) : wxString::Format(_L("Filament %d"), j + 1); + auto preset = wxGetApp().preset_bundle->filaments.find_preset( + wxGetApp().preset_bundle->filament_presets[j]); + item_name = preset ? from_u8(preset->label(false)) + : wxString::Format(_L("Filament %d"), j + 1); } auto* mi = new wxMenuItem(sub_menu, wxID_ANY, item_name); @@ -4370,7 +4336,9 @@ void Sidebar::update_mixed_filament_list() mi->SetBitmap(*icons[j]); #endif sub_menu->Append(mi); - sub_menu->Bind(wxEVT_MENU, [this, cfg_idx, j](wxCommandEvent&) { change_filament(cfg_idx, j); }, mi->GetId()); + sub_menu->Bind(wxEVT_MENU, [this, cfg_idx, j](wxCommandEvent&) { + change_filament(cfg_idx, j); + }, mi->GetId()); } if (filaments_cnt > 1) menu.AppendSubMenu(sub_menu, _L("Merge with")); @@ -4381,7 +4349,9 @@ void Sidebar::update_mixed_filament_list() // ORCA use delete item on end of menu to prevent accidental clicks. clicking to submenus(merge) already not allowed by OS auto* del_item = menu.Append(wxID_ANY, _L("Delete")); - menu.Bind(wxEVT_MENU, [this, panel_idx](wxCommandEvent&) { delete_mixed_filament_at(panel_idx); }, del_item->GetId()); + menu.Bind(wxEVT_MENU, [this, panel_idx](wxCommandEvent&) { + delete_mixed_filament_at(panel_idx); + }, del_item->GetId()); PopupMenu(&menu); }); @@ -4389,10 +4359,9 @@ void Sidebar::update_mixed_filament_list() combo_and_btn_sizer->Add(FromDIP(16), 0, 0, 0, 0); - int side = i % 2; + int side = i % 2; auto* col = (side == 0) ? left_col : right_col; - if (side == 1 && i > 1) - col->Remove(i / 2); + if (side == 1 && i > 1) col->Remove(i / 2); col->Add(combo_and_btn_sizer, 1, wxEXPAND); if (side == 0 && i > 0) { right_col->AddStretchSpacer(1); @@ -4421,8 +4390,7 @@ void Sidebar::update_mixed_filament_list() p->m_mixed_filament_broken = false; if (!broken_slots.empty()) { std::set broken_1based; - for (size_t s : broken_slots) - broken_1based.insert(s + 1); + for (size_t s : broken_slots) broken_1based.insert(s + 1); auto* curr_plate = plater->get_partplate_list().get_curr_plate(); if (curr_plate) { @@ -4431,7 +4399,7 @@ void Sidebar::update_mixed_filament_list() continue; // Check object-level extruder int obj_ext = obj->config.has("extruder") ? obj->config.extruder() : 1; - if (broken_1based.count((size_t) obj_ext)) { + if (broken_1based.count((size_t)obj_ext)) { p->m_mixed_filament_broken = true; break; } @@ -4439,40 +4407,26 @@ void Sidebar::update_mixed_filament_list() for (auto* vol : obj->volumes) { // Check volume-level extruder int vol_ext = vol->config.has("extruder") ? vol->config.extruder() : obj_ext; - if (broken_1based.count((size_t) vol_ext)) { - found = true; - break; - } + if (broken_1based.count((size_t)vol_ext)) { found = true; break; } // Check color painting data (mmu segmentation facets) if (vol->is_model_part() && !vol->mmu_segmentation_facets.empty()) { for (size_t broken_slot : broken_1based) { - if (vol->mmu_segmentation_facets.has_facets(*vol, EnforcerBlockerType(broken_slot))) { - found = true; - break; - } + if (vol->mmu_segmentation_facets.has_facets(*vol, EnforcerBlockerType(broken_slot))) + { found = true; break; } } - if (found) - break; + if (found) break; } } - if (found) { - p->m_mixed_filament_broken = true; - break; - } + if (found) { p->m_mixed_filament_broken = true; break; } // Check height range modifier extruder overrides for (auto& [range, cfg] : obj->layer_config_ranges) { if (cfg.has("extruder")) { int layer_ext = cfg.option("extruder")->getInt(); - if (layer_ext > 0 && broken_1based.count((size_t) layer_ext)) { - found = true; - break; - } + if (layer_ext > 0 && broken_1based.count((size_t)layer_ext)) + { found = true; break; } } } - if (found) { - p->m_mixed_filament_broken = true; - break; - } + if (found) { p->m_mixed_filament_broken = true; break; } } } } @@ -4488,34 +4442,31 @@ void Sidebar::update_mixed_filament_list() mf->update_slice_print_status(MainFrame::eEventObjectUpdate, false); } - if (auto* tab = dynamic_cast(wxGetApp().plate_tab)) + if (auto *tab = dynamic_cast(wxGetApp().plate_tab)) tab->update_mixed_filament_seq_state(); + } bool Sidebar::has_broken_mixed_filament() const { auto* plater = dynamic_cast(GetParent()); - if (!plater) - return false; + if (!plater) return false; return has_broken_mixed_filament(plater->get_partplate_list().get_curr_plate()); } bool Sidebar::has_broken_mixed_filament(const PartPlate* plate) const { - if (!plate) - return false; + if (!plate) return false; auto* plater = dynamic_cast(GetParent()); - if (!plater) - return false; + if (!plater) return false; auto& project_config = wxGetApp().preset_bundle->project_config; - auto* is_mixed_opt = project_config.option("filament_is_mixed"); - auto* comp_strs_opt = project_config.option("filament_mixed_components"); - if (!is_mixed_opt || !comp_strs_opt) - return false; + auto* is_mixed_opt = project_config.option("filament_is_mixed"); + auto* comp_strs_opt = project_config.option("filament_mixed_components"); + if (!is_mixed_opt || !comp_strs_opt) return false; size_t num_physical = p->combos_filament.size(); - auto broken_slots = check_mixed_filament_integrity(is_mixed_opt->values, comp_strs_opt->values, num_physical); + auto broken_slots = check_mixed_filament_integrity(is_mixed_opt->values, comp_strs_opt->values, num_physical); // Type consistency check { @@ -4530,20 +4481,18 @@ bool Sidebar::has_broken_mixed_filament(const PartPlate* plate) const ft = preset->config.get_filament_type(display_type); } } - if (ft.empty()) - ft = "PLA"; + if (ft.empty()) ft = "PLA"; physical_types.push_back(ft); } - auto type_mismatch_slots = check_mixed_filament_type_consistency(is_mixed_opt->values, comp_strs_opt->values, physical_types); + auto type_mismatch_slots = check_mixed_filament_type_consistency( + is_mixed_opt->values, comp_strs_opt->values, physical_types); broken_slots.insert(broken_slots.end(), type_mismatch_slots.begin(), type_mismatch_slots.end()); } - if (broken_slots.empty()) - return false; + if (broken_slots.empty()) return false; std::set broken_1based; - for (size_t s : broken_slots) - broken_1based.insert(s + 1); + for (size_t s : broken_slots) broken_1based.insert(s + 1); // Scan model objects on the given plate for raw extruder assignments // (don't use get_extruders() which expands mixed slots) @@ -4552,12 +4501,12 @@ bool Sidebar::has_broken_mixed_filament(const PartPlate* plate) const continue; // Check object-level extruder int obj_ext = entry->config.has("extruder") ? entry->config.extruder() : 1; - if (broken_1based.count((size_t) obj_ext)) + if (broken_1based.count((size_t)obj_ext)) return true; for (auto* vol : entry->volumes) { // Check volume-level extruder int vol_ext = vol->config.has("extruder") ? vol->config.extruder() : obj_ext; - if (broken_1based.count((size_t) vol_ext)) + if (broken_1based.count((size_t)vol_ext)) return true; // Check color painting data (mmu segmentation facets) if (vol->is_model_part() && !vol->mmu_segmentation_facets.empty()) { @@ -4571,7 +4520,7 @@ bool Sidebar::has_broken_mixed_filament(const PartPlate* plate) const for (auto& [range, cfg] : entry->layer_config_ranges) { if (cfg.has("extruder")) { int layer_ext = cfg.option("extruder")->getInt(); - if (layer_ext > 0 && broken_1based.count((size_t) layer_ext)) + if (layer_ext > 0 && broken_1based.count((size_t)layer_ext)) return true; } } @@ -4581,9 +4530,9 @@ bool Sidebar::has_broken_mixed_filament(const PartPlate* plate) const } void Sidebar::collect_physical_filament_info(std::vector& color_strs, - std::vector& names, - std::vector& types, - std::vector* config_indices) + std::vector& names, + std::vector& types, + std::vector* config_indices) { color_strs.clear(); names.clear(); @@ -4591,9 +4540,9 @@ void Sidebar::collect_physical_filament_info(std::vector& color_str if (config_indices) config_indices->clear(); - size_t num_physical = p->combos_filament.size(); + size_t num_physical = p->combos_filament.size(); auto& project_config = wxGetApp().preset_bundle->project_config; - auto* is_mixed_opt = project_config.option("filament_is_mixed"); + auto* is_mixed_opt = project_config.option("filament_is_mixed"); std::vector physical_indices; const size_t total = wxGetApp().preset_bundle->filament_presets.size(); physical_indices.reserve(num_physical); @@ -4623,7 +4572,7 @@ void Sidebar::collect_physical_filament_info(std::vector& color_str auto& preset_bundle = *wxGetApp().preset_bundle; for (size_t i = 0; i < num_physical; ++i) { const size_t cfg_idx = physical_indices[i]; - Preset* preset = nullptr; + Preset* preset = nullptr; if (cfg_idx < preset_bundle.filament_presets.size()) preset = preset_bundle.filaments.find_preset(preset_bundle.filament_presets[cfg_idx]); std::string ft; @@ -4631,8 +4580,7 @@ void Sidebar::collect_physical_filament_info(std::vector& color_str std::string display_type; ft = preset->config.get_filament_type(display_type); } - if (ft.empty()) - ft = "PLA"; + if (ft.empty()) ft = "PLA"; types.push_back(ft); } } @@ -4648,19 +4596,22 @@ static std::string serialize_mixed_gradient_curve_if_custom(const MixedFilamentR if (!(result.components.size() == 2 && !result.gradient_curve.empty())) return {}; - const double y0 = (result.gradient_direction == 0) ? kGradientMaxRatio : kGradientMinRatio; - const double y1 = (result.gradient_direction == 0) ? kGradientMinRatio : kGradientMaxRatio; + const double y0 = (result.gradient_direction == 0) ? kGradientMaxRatio : kGradientMinRatio; + const double y1 = (result.gradient_direction == 0) ? kGradientMinRatio : kGradientMaxRatio; const double eps = 1e-4; if (result.gradient_curve.size() == 2) { const auto& a0 = result.gradient_curve[0]; const auto& a1 = result.gradient_curve[1]; // Default curve also requires no tangent overrides; any finite tangent // means the user bent the segment, so we must serialize it. - const bool is_default = std::abs(a0.x - 0.0) < eps && std::abs(a1.x - 1.0) < eps && std::abs(a0.y - y0) < eps && - std::abs(a1.y - y1) < eps && !std::isfinite(a0.m_in) && !std::isfinite(a0.m_out) && - !std::isfinite(a1.m_in) && !std::isfinite(a1.m_out); - if (is_default) - return {}; + const bool is_default = + std::abs(a0.x - 0.0) < eps + && std::abs(a1.x - 1.0) < eps + && std::abs(a0.y - y0) < eps + && std::abs(a1.y - y1) < eps + && !std::isfinite(a0.m_in) && !std::isfinite(a0.m_out) + && !std::isfinite(a1.m_in) && !std::isfinite(a1.m_out); + if (is_default) return {}; } Slic3r::GradientCurve gc; @@ -4668,9 +4619,10 @@ static std::string serialize_mixed_gradient_curve_if_custom(const MixedFilamentR return Slic3r::serialize_gradient_curve(gc); } -static bool create_mixed_filament_from_result(Sidebar* sidebar, - const MixedFilamentResult& result, - const std::vector& color_strs) +static bool create_mixed_filament_from_result( + Sidebar* sidebar, + const MixedFilamentResult& result, + const std::vector& color_strs) { if (!sidebar || result.components.size() < 2 || result.ratios.size() < 2) return false; @@ -4684,16 +4636,15 @@ static bool create_mixed_filament_from_result(Sidebar* sidebar, return false; auto& project_config = wxGetApp().preset_bundle->project_config; - size_t total = wxGetApp().preset_bundle->filament_presets.size(); - size_t new_idx = total; + size_t total = wxGetApp().preset_bundle->filament_presets.size(); + size_t new_idx = total; std::string mixed_color = blend_mixed_color(result.components, result.ratios, color_strs); wxGetApp().preset_bundle->set_num_filaments(total + 1, mixed_color); auto* multi_colour_opt = project_config.option("filament_multi_colour"); if (multi_colour_opt) { - while (multi_colour_opt->values.size() <= new_idx) - multi_colour_opt->values.push_back(""); + while (multi_colour_opt->values.size() <= new_idx) multi_colour_opt->values.push_back(""); multi_colour_opt->values[new_idx] = mixed_color; } @@ -4701,69 +4652,60 @@ static bool create_mixed_filament_from_result(Sidebar* sidebar, // size-guarded so a sizing bug degrades into a no-op rather than a heap overwrite. { auto* is_mixed_opt = project_config.option("filament_is_mixed"); - while (is_mixed_opt->values.size() <= new_idx) - is_mixed_opt->values.push_back(false); + while (is_mixed_opt->values.size() <= new_idx) is_mixed_opt->values.push_back(false); is_mixed_opt->values[new_idx] = true; } std::string comp_str; for (size_t i = 0; i < result.components.size(); ++i) { - if (i > 0) - comp_str += ","; + if (i > 0) comp_str += ","; comp_str += std::to_string(result.components[i]); } { auto* comp_opt = project_config.option("filament_mixed_components"); - while (comp_opt->values.size() <= new_idx) - comp_opt->values.push_back(std::string{}); + while (comp_opt->values.size() <= new_idx) comp_opt->values.push_back(std::string{}); comp_opt->values[new_idx] = comp_str; } int ratio_sum = 0; - for (int r : result.ratios) - ratio_sum += r; - if (ratio_sum <= 0) - ratio_sum = 100; + for (int r : result.ratios) ratio_sum += r; + if (ratio_sum <= 0) ratio_sum = 100; std::string ratio_str; { CNumericLocalesSetter c_locale_setter; for (size_t i = 0; i < result.ratios.size(); ++i) { - if (i > 0) - ratio_str += ","; + if (i > 0) ratio_str += ","; char buf[32]; - std::snprintf(buf, sizeof(buf), "%.4f", (float) result.ratios[i] / ratio_sum); + std::snprintf(buf, sizeof(buf), "%.4f", (float)result.ratios[i] / ratio_sum); ratio_str += buf; } } { auto* ratios_opt = project_config.option("filament_mixed_sublayer_ratios"); - while (ratios_opt->values.size() <= new_idx) - ratios_opt->values.push_back(std::string{}); + while (ratios_opt->values.size() <= new_idx) ratios_opt->values.push_back(std::string{}); ratios_opt->values[new_idx] = ratio_str; } if (!project_config.option("filament_mixed_gradient")) project_config.set_key_value("filament_mixed_gradient", new ConfigOptionBools({false})); if (!project_config.option("filament_mixed_gradient_range")) - project_config.set_key_value("filament_mixed_gradient_range", new ConfigOptionStrings({""})); + project_config.set_key_value("filament_mixed_gradient_range", new ConfigOptionStrings({""}) ); if (!project_config.option("filament_mixed_gradient_curve")) - project_config.set_key_value("filament_mixed_gradient_curve", new ConfigOptionStrings({""})); + project_config.set_key_value("filament_mixed_gradient_curve", new ConfigOptionStrings({""}) ); if (!project_config.option("filament_mixed_gradient_per_part")) project_config.set_key_value("filament_mixed_gradient_per_part", new ConfigOptionBools({false})); { auto* grad_opt = project_config.option("filament_mixed_gradient"); - while (grad_opt->values.size() <= new_idx) - grad_opt->values.push_back(false); + while (grad_opt->values.size() <= new_idx) grad_opt->values.push_back(false); grad_opt->values[new_idx] = result.gradient_enabled; } { auto* grad_range_opt = project_config.option("filament_mixed_gradient_range"); - while (grad_range_opt->values.size() <= new_idx) - grad_range_opt->values.push_back(""); + while (grad_range_opt->values.size() <= new_idx) grad_range_opt->values.push_back(""); if (result.gradient_enabled && result.components.size() == 2) { - const char* fmt = (result.gradient_direction == 0) ? "0.9000,0.1000" : "0.1000,0.9000"; + const char* fmt = (result.gradient_direction == 0) ? "0.9000,0.1000" : "0.1000,0.9000"; grad_range_opt->values[new_idx] = fmt; } else { grad_range_opt->values[new_idx] = ""; @@ -4771,14 +4713,12 @@ static bool create_mixed_filament_from_result(Sidebar* sidebar, } { auto* grad_curve_opt = project_config.option("filament_mixed_gradient_curve"); - while (grad_curve_opt->values.size() <= new_idx) - grad_curve_opt->values.push_back(""); + while (grad_curve_opt->values.size() <= new_idx) grad_curve_opt->values.push_back(""); grad_curve_opt->values[new_idx] = serialize_mixed_gradient_curve_if_custom(result); } { auto* per_part_opt = project_config.option("filament_mixed_gradient_per_part"); - while (per_part_opt->values.size() <= new_idx) - per_part_opt->values.push_back(false); + while (per_part_opt->values.size() <= new_idx) per_part_opt->values.push_back(false); per_part_opt->values[new_idx] = result.gradient_enabled && result.per_part_gradient; } @@ -4801,14 +4741,11 @@ static bool create_mixed_filament_from_result(Sidebar* sidebar, void Sidebar::add_mixed_filament() { auto* plater = dynamic_cast(GetParent()); - if (!plater) - return; + if (!plater) return; size_t num_physical = p->combos_filament.size(); - if (num_physical < 2) - return; - if (wxGetApp().preset_bundle->filament_presets.size() >= size_t(EnforcerBlockerType::ExtruderMax)) - return; + if (num_physical < 2) return; + if (wxGetApp().preset_bundle->filament_presets.size() >= size_t(EnforcerBlockerType::ExtruderMax)) return; std::vector color_strs, names, types; collect_physical_filament_info(color_strs, names, types); @@ -4823,12 +4760,10 @@ void Sidebar::add_mixed_filament() void Sidebar::edit_mixed_filament(size_t panel_idx) { auto* plater = dynamic_cast(GetParent()); - if (!plater) - return; + if (!plater) return; auto mixed_indices = plater->mixed_filament_config_indices(); - if (panel_idx >= mixed_indices.size()) - return; + if (panel_idx >= mixed_indices.size()) return; size_t cfg_idx = mixed_indices[panel_idx]; std::vector color_strs, names, types; @@ -4837,7 +4772,7 @@ void Sidebar::edit_mixed_filament(size_t panel_idx) auto& project_config = wxGetApp().preset_bundle->project_config; MixedFilamentResult existing; auto* components_opt = project_config.option("filament_mixed_components"); - auto* ratios_opt = project_config.option("filament_mixed_sublayer_ratios"); + auto* ratios_opt = project_config.option("filament_mixed_sublayer_ratios"); // Parse existing components if (components_opt && cfg_idx < components_opt->values.size()) { @@ -4859,16 +4794,18 @@ void Sidebar::edit_mixed_filament(size_t panel_idx) while (std::getline(iss, tok, ',')) { float v = 0; if (std::sscanf(tok.c_str(), "%f", &v) == 1) - existing.ratios.push_back((int) (v * 100 + 0.5f)); + existing.ratios.push_back((int)(v * 100 + 0.5f)); } } if (existing.components.size() < 2) { existing.components = {1, 2}; - existing.ratios = {50, 50}; + existing.ratios = {50, 50}; } else if (existing.ratios.size() != existing.components.size()) { - BOOST_LOG_TRIVIAL(warning) << "Mixed filament edit: ratio count (" << existing.ratios.size() << ") != component count (" - << existing.components.size() << "), resetting to even distribution"; - int n = (int) existing.components.size(); + BOOST_LOG_TRIVIAL(warning) << "Mixed filament edit: ratio count (" + << existing.ratios.size() << ") != component count (" + << existing.components.size() + << "), resetting to even distribution"; + int n = (int)existing.components.size(); existing.ratios.assign(n, 100 / n); existing.ratios[0] += 100 - (100 / n) * n; } @@ -4886,7 +4823,7 @@ void Sidebar::edit_mixed_filament(size_t panel_idx) } auto* grad_curve_opt = project_config.option("filament_mixed_gradient_curve"); if (existing.gradient_enabled && grad_curve_opt && cfg_idx < grad_curve_opt->values.size()) { - auto curve = Slic3r::parse_gradient_curve(grad_curve_opt->values[cfg_idx]); + auto curve = Slic3r::parse_gradient_curve(grad_curve_opt->values[cfg_idx]); existing.gradient_curve = curve.points; } auto* per_part_opt = project_config.option("filament_mixed_gradient_per_part"); @@ -4896,33 +4833,28 @@ void Sidebar::edit_mixed_filament(size_t panel_idx) MixedFilamentDialog dlg(this, existing, color_strs, names, types); if (dlg.ShowModal() == wxID_OK) { auto result = dlg.get_result(); - if (result.components.size() < 2 || result.ratios.size() < 2) - return; + if (result.components.size() < 2 || result.ratios.size() < 2) return; // Serialize components std::string comp_str; for (size_t i = 0; i < result.components.size(); ++i) { - if (i > 0) - comp_str += ","; + if (i > 0) comp_str += ","; comp_str += std::to_string(result.components[i]); } components_opt->values[cfg_idx] = comp_str; // Serialize ratios int ratio_sum = 0; - for (int r : result.ratios) - ratio_sum += r; - if (ratio_sum <= 0) - ratio_sum = 100; + for (int r : result.ratios) ratio_sum += r; + if (ratio_sum <= 0) ratio_sum = 100; std::string ratio_str; { CNumericLocalesSetter c_locale_setter; for (size_t i = 0; i < result.ratios.size(); ++i) { - if (i > 0) - ratio_str += ","; + if (i > 0) ratio_str += ","; char buf[32]; - std::snprintf(buf, sizeof(buf), "%.4f", (float) result.ratios[i] / ratio_sum); + std::snprintf(buf, sizeof(buf), "%.4f", (float)result.ratios[i] / ratio_sum); ratio_str += buf; } } @@ -4932,24 +4864,22 @@ void Sidebar::edit_mixed_filament(size_t panel_idx) if (!project_config.option("filament_mixed_gradient")) project_config.set_key_value("filament_mixed_gradient", new ConfigOptionBools({false})); if (!project_config.option("filament_mixed_gradient_range")) - project_config.set_key_value("filament_mixed_gradient_range", new ConfigOptionStrings({""})); + project_config.set_key_value("filament_mixed_gradient_range", new ConfigOptionStrings({""}) ); if (!project_config.option("filament_mixed_gradient_curve")) - project_config.set_key_value("filament_mixed_gradient_curve", new ConfigOptionStrings({""})); + project_config.set_key_value("filament_mixed_gradient_curve", new ConfigOptionStrings({""}) ); if (!project_config.option("filament_mixed_gradient_per_part")) project_config.set_key_value("filament_mixed_gradient_per_part", new ConfigOptionBools({false})); { auto* grad_opt = project_config.option("filament_mixed_gradient"); - while (grad_opt->values.size() <= cfg_idx) - grad_opt->values.push_back(false); + while (grad_opt->values.size() <= cfg_idx) grad_opt->values.push_back(false); grad_opt->values[cfg_idx] = result.gradient_enabled; } { auto* grad_range_opt = project_config.option("filament_mixed_gradient_range"); - while (grad_range_opt->values.size() <= cfg_idx) - grad_range_opt->values.push_back(""); + while (grad_range_opt->values.size() <= cfg_idx) grad_range_opt->values.push_back(""); if (result.gradient_enabled && result.components.size() == 2) { - const char* fmt = (result.gradient_direction == 0) ? "0.9000,0.1000" : "0.1000,0.9000"; + const char* fmt = (result.gradient_direction == 0) ? "0.9000,0.1000" : "0.1000,0.9000"; grad_range_opt->values[cfg_idx] = fmt; } else { grad_range_opt->values[cfg_idx] = ""; @@ -4957,20 +4887,18 @@ void Sidebar::edit_mixed_filament(size_t panel_idx) } { auto* grad_curve_opt = project_config.option("filament_mixed_gradient_curve"); - while (grad_curve_opt->values.size() <= cfg_idx) - grad_curve_opt->values.push_back(""); + while (grad_curve_opt->values.size() <= cfg_idx) grad_curve_opt->values.push_back(""); grad_curve_opt->values[cfg_idx] = serialize_mixed_gradient_curve_if_custom(result); } { auto* per_part_opt = project_config.option("filament_mixed_gradient_per_part"); - while (per_part_opt->values.size() <= cfg_idx) - per_part_opt->values.push_back(false); + while (per_part_opt->values.size() <= cfg_idx) per_part_opt->values.push_back(false); per_part_opt->values[cfg_idx] = result.gradient_enabled && result.per_part_gradient; } // Compute blended color std::string blended = blend_mixed_color(result.components, result.ratios, color_strs); - auto* colours_opt = project_config.option("filament_colour"); + auto* colours_opt = project_config.option("filament_colour"); if (colours_opt && cfg_idx < colours_opt->values.size()) colours_opt->values[cfg_idx] = blended; @@ -4990,12 +4918,10 @@ void Sidebar::edit_mixed_filament(size_t panel_idx) void Sidebar::delete_mixed_filament_at(size_t panel_idx) { auto* plater = dynamic_cast(GetParent()); - if (!plater) - return; + if (!plater) return; auto mixed_indices = plater->mixed_filament_config_indices(); - if (panel_idx >= mixed_indices.size()) - return; + if (panel_idx >= mixed_indices.size()) return; size_t cfg_idx = mixed_indices[panel_idx]; delete_filament(cfg_idx, -1); @@ -5009,7 +4935,7 @@ void Sidebar::decompose_filament_color(int filament_idx) return; auto& project_config = wxGetApp().preset_bundle->project_config; - auto* colours_opt = project_config.option("filament_colour"); + auto* colours_opt = project_config.option("filament_colour"); if (!colours_opt || static_cast(filament_idx) >= colours_opt->values.size()) return; @@ -5027,7 +4953,8 @@ void Sidebar::decompose_filament_color(int filament_idx) auto& pb = *wxGetApp().preset_bundle; for (size_t i = 0; i < physical_config_indices.size(); ++i) { const size_t ci = physical_config_indices[i]; - Preset* pr = (ci < pb.filament_presets.size()) ? pb.filaments.find_preset(pb.filament_presets[ci]) : nullptr; + Preset* pr = (ci < pb.filament_presets.size()) + ? pb.filaments.find_preset(pb.filament_presets[ci]) : nullptr; decompose_types.push_back(filament_type_for_color_decompose(pr)); } } @@ -5040,16 +4967,19 @@ void Sidebar::decompose_filament_color(int filament_idx) } } - ColorDecomposeDialog dlg(this, source_physical_idx == size_t(-1) ? -1 : static_cast(source_physical_idx), target_color, color_strs, - names, decompose_types, wxGetApp().preset_bundle->filament_presets.size(), - static_cast(EnforcerBlockerType::ExtruderMax), physical_config_indices); + ColorDecomposeDialog dlg(this, + source_physical_idx == size_t(-1) ? -1 : static_cast(source_physical_idx), + target_color, color_strs, names, decompose_types, + wxGetApp().preset_bundle->filament_presets.size(), + static_cast(EnforcerBlockerType::ExtruderMax), + physical_config_indices); int modal_res = dlg.ShowModal(); if (modal_res == wxID_OK) { ColorDecomposeResult dialog_result = dlg.get_result(); MixedFilamentResult mixed_result; std::vector missing_components; - if (!prepare_decompose_mixed_result(dialog_result, static_cast(filament_idx), source_physical_idx, color_strs, - decompose_types, physical_config_indices, mixed_result, missing_components)) + if (!prepare_decompose_mixed_result(dialog_result, static_cast(filament_idx), source_physical_idx, + color_strs, decompose_types, physical_config_indices, mixed_result, missing_components)) return; if (!confirm_create_decompose_missing_components(this, missing_components)) @@ -5080,7 +5010,7 @@ void Sidebar::update_filaments_area_height() // ORCA use a height with user preference auto left_sizer = p->sizer_filaments->GetItem((size_t) 0)->GetSizer(); auto combo_sizer = left_sizer->GetItem((size_t) 0)->GetSizer(); - int preferred_rows = std::ceil(0.5 * std::stoi(wxGetApp().app_config->get("filaments_area_preferred_count"))); + int preferred_rows = std::ceil(0.5 * std::stoi(wxGetApp().app_config->get("filaments_area_preferred_count"))); auto height_with_borders = combo_sizer->GetSize().GetHeight(); // gets height from sizer instead static numbers p->m_panel_filament_content->SetMaxSize(wxSize{-1, preferred_rows * height_with_borders}); @@ -5096,18 +5026,18 @@ void Sidebar::update_filaments_area_height() void Sidebar::update_filaments_counter(bool force_layout) // ORCA { - int current_count = p->combos_filament.size(); - int preferred_count = std::stoi(wxGetApp().app_config->get("filaments_area_preferred_count")); - bool isShown = p->m_panel_filament_content->IsShown(); - auto counter = p->m_staticText_filament_count; + int current_count = p->combos_filament.size(); + int preferred_count = std::stoi(wxGetApp().app_config->get("filaments_area_preferred_count")); + bool isShown = p->m_panel_filament_content->IsShown(); + auto counter = p->m_staticText_filament_count; counter->SetLabel("(" + std::to_string(current_count) + ")"); // update counter on every change - if (current_count > preferred_count || !isShown) + if(current_count > preferred_count || !isShown) counter->Show(); else if (isShown) // hide when list is visible and short enough counter->Hide(); - if (force_layout) + if(force_layout) m_scrolled_sizer->Layout(); } @@ -5115,7 +5045,8 @@ void Sidebar::msw_rescale() { SetMinSize(wxSize(39 * wxGetApp().em_unit(), -1)); p->m_panel_printer_title->GetSizer()->SetMinSize(-1, 3 * wxGetApp().em_unit()); - p->m_panel_filament_title->GetSizer()->SetMinSize(-1, 3 * wxGetApp().em_unit()); + p->m_panel_filament_title->GetSizer() + ->SetMinSize(-1, 3 * wxGetApp().em_unit()); p->m_printer_icon->msw_rescale(); p->m_printer_connect->msw_rescale(); p->m_printer_bbl_sync->msw_rescale(); @@ -5137,15 +5068,14 @@ void Sidebar::msw_rescale() p->panel_printer_bed->SetMinSize(FromDIP(PRINTER_PANEL_SIZE)); p->panel_printer_bed->SetCornerRadius(FromDIP(PRINTER_PANEL_RADIUS)); p->combo_printer_bed->Rescale(); - p->combo_printer_bed->SetMinSize(FromDIP(wxSize(18, -1))); // ORCA show only arrow - p->combo_printer_bed->SetMaxSize(FromDIP(wxSize(18, -1))); // ORCA show only arrow - bool isDual = static_cast(p->panel_printer_preset->GetSizer())->GetOrientation() == wxVERTICAL; + p->combo_printer_bed->SetMinSize(FromDIP(wxSize(18,-1))); // ORCA show only arrow + p->combo_printer_bed->SetMaxSize(FromDIP(wxSize(18,-1))); // ORCA show only arrow + bool isDual = static_cast(p->panel_printer_preset->GetSizer())->GetOrientation() == wxVERTICAL; auto image_path = get_cur_select_bed_image(); p->image_printer_bed->SetBitmap(create_scaled_bitmap(image_path, this, PRINTER_THUMBNAIL_SIZE.GetHeight())); - if (p->big_bed_image_popup) { // ORCA force rebuild frame. current wxwidget version not supports wxBITMAP_SCALE_FILL flag on - // wxStaticBitmap also wxImage scaledImage = bit_map.ConvertToImage(); - // scaledImage.Rescale(FromDIP(m_image_px), FromDIP(m_image_px), wxIMAGE_QUALITY_HIGH); didnt worked as - // expected and it requires use on set_bitmap. so that will try to scale everytime + if (p->big_bed_image_popup){ // ORCA force rebuild frame. current wxwidget version not supports wxBITMAP_SCALE_FILL flag on wxStaticBitmap + // also wxImage scaledImage = bit_map.ConvertToImage(); scaledImage.Rescale(FromDIP(m_image_px), FromDIP(m_image_px), wxIMAGE_QUALITY_HIGH); + // didnt worked as expected and it requires use on set_bitmap. so that will try to scale everytime p->big_bed_image_popup->Destroy(); p->big_bed_image_popup = nullptr; } @@ -5159,25 +5089,25 @@ void Sidebar::msw_rescale() p->m_flushing_volume_btn->Rescale(); set_flushing_volume_warning(is_flush_config_modified()); // ORCA reapply appearance - // BBS + //BBS p->left_extruder->Rescale(); p->right_extruder->Rescale(); p->single_extruder->Rescale(); - // p->btn_sync_printer->SetPaddingSize({FromDIP(6), FromDIP(12)}); - // p->btn_sync_printer->SetMinSize(BTN_SYNC_SIZE); - // p->btn_sync_printer->Rescale(); + //p->btn_sync_printer->SetPaddingSize({FromDIP(6), FromDIP(12)}); + //p->btn_sync_printer->SetMinSize(BTN_SYNC_SIZE); + //p->btn_sync_printer->Rescale(); #if 0 if (p->mode_sizer) p->mode_sizer->msw_rescale(); #endif - // for (PlaterPresetComboBox* combo : std::vector { p->combo_print, - // //p->combo_sla_print, - // //p->combo_sla_material, - // //p->combo_printer - // } ) - // combo->msw_rescale(); + //for (PlaterPresetComboBox* combo : std::vector { p->combo_print, + // //p->combo_sla_print, + // //p->combo_sla_material, + // //p->combo_printer + // } ) + // combo->msw_rescale(); for (PlaterPresetComboBox* combo : p->combos_filament) combo->msw_rescale(); @@ -5186,11 +5116,11 @@ void Sidebar::msw_rescale() update_filaments_area_height(); // ORCA resize after combos scaled // BBS - // p->frequently_changed_parameters->msw_rescale(); - // obj_list()->msw_rescale(); + //p->frequently_changed_parameters->msw_rescale(); + //obj_list()->msw_rescale(); // BBS TODO: add msw_rescale for newly added windows // BBS - // p->object_manipulation->msw_rescale(); + //p->object_manipulation->msw_rescale(); p->object_settings->msw_rescale(); p->m_search_item->Rescale(); p->m_search_item->GetTextCtrl()->SetSize(wxSize(-1, FromDIP(16))); @@ -5228,7 +5158,7 @@ void Sidebar::sys_color_changed() for (wxWindow* win : std::vector{ p->scrolled, p->presets_panel }) wxGetApp().UpdateAllStaticTextDarkUI(win); #endif - // p->btn_sync_printer->SetIcon("printer_sync"); + //p->btn_sync_printer->SetIcon("printer_sync"); p->m_printer_bbl_sync->msw_rescale(); p->m_printer_connect->msw_rescale(); // for (wxWindow* btn : std::vector{ p->btn_reslice, p->btn_export_gcode }) @@ -5253,7 +5183,7 @@ void Sidebar::sys_color_changed() #endif p->object_settings->sys_color_changed(); - // BBS: remove print related combos + //BBS: remove print related combos #if 0 for (PlaterPresetComboBox* combo : std::vector{ p->combo_print, p->combo_sla_print, @@ -5272,12 +5202,12 @@ void Sidebar::sys_color_changed() p->image_printer->SetSize(FromDIP(PRINTER_THUMBNAIL_SIZE)); p->image_printer_bed->SetSize(FromDIP(PRINTER_THUMBNAIL_SIZE)); - for (ExtruderGroup* ext : {p->left_extruder, p->right_extruder, p->single_extruder}) + for (ExtruderGroup *ext : {p->left_extruder, p->right_extruder, p->single_extruder}) if (ext) ext->sys_color_changed(); // call a kill focus event to ensure new colors applied - for (ComboBox* combo : std::vector{p->combo_printer, p->combo_nozzle_dia, p->combo_printer_bed}) { + for (ComboBox* combo : std::vector{p->combo_printer, p->combo_nozzle_dia, p->combo_printer_bed}){ wxFocusEvent fakeEvent(wxEVT_KILL_FOCUS); fakeEvent.SetEventObject(combo); combo->HandleWindowEvent(fakeEvent); @@ -5287,12 +5217,12 @@ void Sidebar::sys_color_changed() obj_list()->sys_color_changed(); obj_layers()->sys_color_changed(); // BBS - // p->object_manipulation->sys_color_changed(); + //p->object_manipulation->sys_color_changed(); // btn...->msw_rescale() updates icon on button, so use it - // p->btn_send_gcode->msw_rescale(); - // p->btn_eject_device->msw_rescale(); - // p->btn_export_gcode_removable->msw_rescale(); + //p->btn_send_gcode->msw_rescale(); +// p->btn_eject_device->msw_rescale(); + //p->btn_export_gcode_removable->msw_rescale(); p->scrolled->Layout(); @@ -5302,11 +5232,14 @@ void Sidebar::sys_color_changed() p->searcher.dlg_sys_color_changed(); } -void Sidebar::search() { p->searcher.search(); } +void Sidebar::search() +{ + p->searcher.search(); +} void Sidebar::jump_to_option(const std::string& opt_key, Preset::Type type, const std::wstring& category) { - // const Search::Option& opt = p->searcher.get_option(opt_key, type); + //const Search::Option& opt = p->searcher.get_option(opt_key, type); if (type == Preset::TYPE_PRINT) { auto tab = dynamic_cast(wxGetApp().params_panel()->get_current_tab()); if (tab && tab->has_key(opt_key)) { @@ -5324,7 +5257,7 @@ void Sidebar::jump_to_option(size_t selected) jump_to_option(opt.opt_key(), opt.type, opt.category); // Switch to the Settings NotePad - // wxGetApp().mainframe->select_tab(); +// wxGetApp().mainframe->select_tab(); } // BBS. Move logic from Plater::on_extruders_change() to Sidebar::on_filament_count_change(). @@ -5334,7 +5267,7 @@ void Sidebar::on_filament_count_change(size_t num_filaments) // their own (they are rendered by update_mixed_filament_list instead), so the physical // subset drives the combo list. auto& project_config = wxGetApp().preset_bundle->project_config; - auto* is_mixed_opt = project_config.option("filament_is_mixed"); + auto* is_mixed_opt = project_config.option("filament_is_mixed"); std::vector physical_indices; for (size_t i = 0; i < num_filaments; ++i) { @@ -5362,8 +5295,9 @@ void Sidebar::on_filament_count_change(size_t num_filaments) wxWindowUpdateLocker noUpdates_scrolled_panel(this); size_t i = choices.size(); - while (i < num_physical) { - PlaterPresetComboBox* choice /*{ nullptr }*/; + while (i < num_physical) + { + PlaterPresetComboBox* choice/*{ nullptr }*/; init_filament_combo(&choice, physical_indices[i]); int last_selection = choices.back()->GetSelection(); choices.push_back(choice); @@ -5379,7 +5313,7 @@ void Sidebar::on_filament_count_change(size_t num_filaments) show_SEMM_buttons(); // ORCA - update_filaments_area_height(); // ORCA + update_filaments_area_height(); // ORCA recalc_filament_scroll_sizes(); update_mixed_filament_list(); @@ -5391,7 +5325,7 @@ void Sidebar::on_filament_count_change(size_t num_filaments) void Sidebar::on_filaments_delete(size_t filament_id) { - auto& choices = combos_filament(); + auto &choices = combos_filament(); // A mixed (virtual) slot has no combo of its own, so there is no combo UI to remove — // but the shared refresh below must still run so the mixed filament panel drops its row. @@ -5403,8 +5337,8 @@ void Sidebar::on_filaments_delete(size_t filament_id) // delete UI item { - const int last = p->combos_filament.size() - 1; - auto sizer_filaments = this->p->sizer_filaments->GetItem(last % 2)->GetSizer(); + const int last = p->combos_filament.size() - 1; + auto sizer_filaments = this->p->sizer_filaments->GetItem(last % 2)->GetSizer(); sizer_filaments->Remove(last / 2); PlaterPresetComboBox* to_delete_combox = p->combos_filament[filament_id]; @@ -5428,7 +5362,7 @@ void Sidebar::on_filaments_delete(size_t filament_id) show_SEMM_buttons(); // ORCA - for (size_t idx = filament_id; idx < p->combos_filament.size(); ++idx) { + for (size_t idx = filament_id ; idx < p->combos_filament.size(); ++idx) { p->combos_filament[idx]->update(); } } @@ -5443,28 +5377,22 @@ void Sidebar::on_filaments_delete(size_t filament_id) update_dynamic_filament_list(); } -void Sidebar::add_filament() -{ - if (p->combos_filament.size() >= MAXIMUM_EXTRUDER_NUMBER) - return; - wxColour new_col = Plater::get_next_color_for_filament(); +void Sidebar::add_filament() { + if (p->combos_filament.size() >= MAXIMUM_EXTRUDER_NUMBER) return; + wxColour new_col = Plater::get_next_color_for_filament(); add_custom_filament(new_col); auto filament_list = p->m_panel_filament_content; - if (!filament_list->IsShown()) { + if(!filament_list->IsShown()){ filament_list->Show(); // ORCA show list if its folded m_scrolled_sizer->Layout(); } filament_list->Scroll(-1, INT_MAX); // ORCA scroll to end of list on changes to inform user about filament count } -void Sidebar::delete_filament(size_t filament_id, int replace_filament_id) -{ - if (is_new_project_in_gcode3mf()) { - return; - } - if (p->combos_filament.size() <= 1) - return; +void Sidebar::delete_filament(size_t filament_id, int replace_filament_id) { + if (is_new_project_in_gcode3mf()) { return; } + if (p->combos_filament.size() <= 1) return; size_t filament_count = p->combos_filament.size() - 1; if (filament_id == size_t(-2)) { @@ -5505,16 +5433,14 @@ void Sidebar::delete_filament(size_t filament_id, int replace_filament_id) // new number of slots; recompute from the shrunk preset list for the downstream updates. size_t total_after_delete = wxGetApp().preset_bundle->filament_presets.size(); wxGetApp().plater()->get_partplate_list().on_filament_deleted(total_after_delete, filament_id); - wxGetApp().plater()->on_filaments_delete(total_after_delete, filament_id, - replace_filament_id > (int) filament_id ? (replace_filament_id - 1) : replace_filament_id, - is_mixed_snapshot); + wxGetApp().plater()->on_filaments_delete(total_after_delete, filament_id, replace_filament_id > (int)filament_id ? (replace_filament_id - 1) : replace_filament_id, is_mixed_snapshot); wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config); wxGetApp().plater()->update(); auto filament_list = p->m_panel_filament_content; - if (!filament_list->IsShown()) { + if(!filament_list->IsShown()){ filament_list->Show(); // ORCA show list if its folded m_scrolled_sizer->Layout(); } @@ -5526,16 +5452,16 @@ void Sidebar::change_filament(size_t from_id, size_t to_id) { // Merging a physical filament into a mixed one that lists it as a component would delete // the very filament the mix depends on, leaving it broken. Warn before doing so. - auto& pb = *wxGetApp().preset_bundle; + auto& pb = *wxGetApp().preset_bundle; bool from_is_physical = !pb.is_mixed_filament(from_id); - bool to_is_mixed = pb.is_mixed_filament(to_id); + bool to_is_mixed = pb.is_mixed_filament(to_id); if (from_is_physical && to_is_mixed) { auto* comp_opt = pb.project_config.option("filament_mixed_components"); if (comp_opt && to_id < comp_opt->values.size()) { - auto comps = Slic3r::parse_mixed_components(comp_opt->values[to_id]); - unsigned int from_1based = (unsigned int) from_id + 1; - bool target_uses_source = false; + auto comps = Slic3r::parse_mixed_components(comp_opt->values[to_id]); + unsigned int from_1based = (unsigned int)from_id + 1; + bool target_uses_source = false; for (unsigned int c : comps) { if (c == from_1based) { target_uses_source = true; @@ -5543,9 +5469,11 @@ void Sidebar::change_filament(size_t from_id, size_t to_id) } } if (target_uses_source) { - int ret = wxMessageBox(_L("The target mixed filament uses this physical filament as a component. " - "Merging will remove this physical filament and may invalidate the mixed filament. Continue?"), - _L("Warning"), wxOK | wxCANCEL | wxICON_WARNING); + int ret = wxMessageBox( + _L("The target mixed filament uses this physical filament as a component. " + "Merging will remove this physical filament and may invalidate the mixed filament. Continue?"), + _L("Warning"), + wxOK | wxCANCEL | wxICON_WARNING); if (ret != wxOK) return; } @@ -5558,31 +5486,26 @@ void Sidebar::change_filament(size_t from_id, size_t to_id) void Sidebar::edit_filament() { p->editing_filament = -1; - if (p->m_menu_filament_id >= 0 && p->m_menu_filament_id < p->combos_filament.size() && - p->combos_filament[p->m_menu_filament_id]->switch_to_tab()) + if (p->m_menu_filament_id >= 0 && p->m_menu_filament_id < p->combos_filament.size() + && p->combos_filament[p->m_menu_filament_id]->switch_to_tab()) p->editing_filament = p->m_menu_filament_id; // sync with TabPresetComboxBox's m_filament_idx } -void Sidebar::add_custom_filament(wxColour new_col, const std::string& preset_name, bool /*skip_preset_validation*/) -{ - if (is_new_project_in_gcode3mf()) { - return; - } - if (p->combos_filament.size() >= MAXIMUM_EXTRUDER_NUMBER) - return; - if (wxGetApp().preset_bundle->filament_presets.size() >= MAXIMUM_EXTRUDER_NUMBER) - return; +void Sidebar::add_custom_filament(wxColour new_col, const std::string& preset_name, bool /*skip_preset_validation*/) { + if (is_new_project_in_gcode3mf()) { return; } + if (p->combos_filament.size() >= MAXIMUM_EXTRUDER_NUMBER) return; + if (wxGetApp().preset_bundle->filament_presets.size() >= MAXIMUM_EXTRUDER_NUMBER) return; // Mixed-color slots are kept at the tail of the filament arrays, so a new physical // filament has to be inserted just after the last physical one rather than appended. // Count off filament_is_mixed, not filament_presets or the combos: the extruder-count spinner // reaches this before the sidebar has rebuilt, and update_multi_material_filament_presets() // can have grown filament_presets alone. - auto* bundle = wxGetApp().preset_bundle; - size_t insert_pos = bundle->num_physical_filaments(); - size_t total = insert_pos + bundle->num_mixed_filaments(); - int filament_count = (int) (total + 1); - std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); + auto *bundle = wxGetApp().preset_bundle; + size_t insert_pos = bundle->num_physical_filaments(); + size_t total = insert_pos + bundle->num_mixed_filaments(); + int filament_count = (int)(total + 1); + std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); bundle->set_num_filaments(filament_count, new_color); // Maintain physical-first ordering: rotate the new slot from end to insert_pos. @@ -5592,7 +5515,7 @@ void Sidebar::add_custom_filament(wxColour new_col, const std::string& preset_na std::rotate(presets.begin() + insert_pos, presets.begin() + total, presets.end()); auto& project_config = wxGetApp().preset_bundle->project_config; - auto& ams_mc = wxGetApp().preset_bundle->ams_multi_color_filment; + auto& ams_mc = wxGetApp().preset_bundle->ams_multi_color_filment; auto rotate_strings = [&](const char* key) { if (auto* opt = project_config.option(key)) @@ -5628,8 +5551,8 @@ void Sidebar::add_custom_filament(wxColour new_col, const std::string& preset_na std::rotate(ams_mc.begin() + insert_pos, ams_mc.begin() + total, ams_mc.end()); // Remap object/volume extruder IDs and paint data: anything >= insert_pos+1 (1-based) shifts up by 1 - int threshold_1based = (int) (insert_pos + 1); - auto ebt_threshold = EnforcerBlockerType(threshold_1based); + int threshold_1based = (int)(insert_pos + 1); + auto ebt_threshold = EnforcerBlockerType(threshold_1based); for (auto* obj : wxGetApp().plater()->model().objects) { if (obj->config.has("extruder")) { int ext = obj->config.extruder(); @@ -5647,7 +5570,8 @@ void Sidebar::add_custom_filament(wxColour new_col, const std::string& preset_na } } - if (!preset_name.empty() && wxGetApp().preset_bundle->filaments.find_preset(preset_name, false) && + if (!preset_name.empty() && + wxGetApp().preset_bundle->filaments.find_preset(preset_name, false) && insert_pos < wxGetApp().preset_bundle->filament_presets.size()) { wxGetApp().preset_bundle->filament_presets[insert_pos] = preset_name; } @@ -5662,9 +5586,10 @@ void Sidebar::add_custom_filament(wxColour new_col, const std::string& preset_na bool Sidebar::is_new_project_in_gcode3mf() { if (p->plater->using_exported_file()) { - auto filename = p->plater->get_preview_only_filename(); - auto text = wxString::Format(_L("After completing your operation, %s project will be closed and create a new project."), filename); - MessageDialog dlg(wxGetApp().plater(), text, _L("Warning"), wxOK | wxICON_WARNING); + auto filename = p->plater->get_preview_only_filename(); + auto text = wxString::Format(_L("After completing your operation, %s project will be closed and create a new project."), filename); + MessageDialog dlg(wxGetApp().plater(), text, _L("Warning"), + wxOK | wxICON_WARNING); dlg.ShowModal(); p->plater->new_project(); return true; @@ -5725,8 +5650,7 @@ void Sidebar::on_bed_type_change(BedType bed_type) std::map Sidebar::build_filament_ams_list(MachineObject* obj) { std::map filament_ams_list; - if (!obj) - return filament_ams_list; + if (!obj) return filament_ams_list; // For pull-mode agents (e.g., HTTP REST API), refresh DevFilaSystem first auto* agent = wxGetApp().getDeviceManager()->get_agent(); @@ -5736,18 +5660,17 @@ std::map Sidebar::build_filament_ams_list(MachineObject } } - auto build_tray_config = [](DevAmsTray const& tray, std::string const& name, std::string ams_id, std::string slot_id) { - BOOST_LOG_TRIVIAL(info) << boost::format("build_filament_ams_list: name %1% setting_id %2% type %3% color %4%") % name % - tray.setting_id % tray.m_fila_type % tray.color; + auto build_tray_config = [](DevAmsTray const &tray, std::string const &name, std::string ams_id, std::string slot_id) { + BOOST_LOG_TRIVIAL(info) << boost::format("build_filament_ams_list: name %1% setting_id %2% type %3% color %4%") + % name % tray.setting_id % tray.m_fila_type % tray.color; DynamicPrintConfig tray_config; tray_config.set_key_value("filament_id", new ConfigOptionStrings{tray.setting_id}); tray_config.set_key_value("tag_uid", new ConfigOptionStrings{tray.tag_uid}); tray_config.set_key_value("ams_id", new ConfigOptionStrings{ams_id}); tray_config.set_key_value("slot_id", new ConfigOptionStrings{slot_id}); tray_config.set_key_value("filament_type", new ConfigOptionStrings{tray.m_fila_type}); - tray_config.set_key_value("tray_name", new ConfigOptionStrings{name}); - tray_config.set_key_value("filament_colour", - new ConfigOptionStrings{into_u8(wxColour("#" + tray.color).GetAsString(wxC2S_HTML_SYNTAX))}); + tray_config.set_key_value("tray_name", new ConfigOptionStrings{ name }); + tray_config.set_key_value("filament_colour", new ConfigOptionStrings{into_u8(wxColour("#" + tray.color).GetAsString(wxC2S_HTML_SYNTAX))}); tray_config.set_key_value("filament_multi_colour", new ConfigOptionStrings{}); tray_config.set_key_value("filament_colour_type", new ConfigOptionStrings{std::to_string(tray.ctype)}); tray_config.set_key_value("filament_exist", new ConfigOptionBools{tray.is_exists}); @@ -5756,23 +5679,22 @@ std::map Sidebar::build_filament_ams_list(MachineObject if (wxGetApp().preset_bundle) { info = wxGetApp().preset_bundle->get_filament_by_filament_id(tray.setting_id); } - tray_config.set_key_value("filament_is_support", new ConfigOptionBools{info.has_value() ? info->is_support : false}); + tray_config.set_key_value("filament_is_support", new ConfigOptionBools{ info.has_value() ? info->is_support : false}); for (int i = 0; i < tray.cols.size(); ++i) { - tray_config.opt("filament_multi_colour") - ->values.push_back(into_u8(wxColour("#" + tray.cols[i]).GetAsString(wxC2S_HTML_SYNTAX))); + tray_config.opt("filament_multi_colour")->values.push_back(into_u8(wxColour("#" + tray.cols[i]).GetAsString(wxC2S_HTML_SYNTAX))); } return tray_config; }; if (obj->ams_support_virtual_tray) { int extruder = 0x10000; // Main (first) extruder at right - for (auto& vt_tray : obj->vt_slot) { - filament_ams_list.emplace(extruder + stoi(vt_tray.id), build_tray_config(vt_tray, "Ext", vt_tray.id, "0")); // 254 or 255 + for (auto & vt_tray : obj->vt_slot) { + filament_ams_list.emplace(extruder + stoi(vt_tray.id), build_tray_config(vt_tray, "Ext",vt_tray.id, "0"));//254 or 255 extruder = 0; } } - auto get_ams_name = [](int ams_id, int slot_id) -> std::string { + auto get_ams_name = [](int ams_id, int slot_id)->std::string { if (ams_id >= 0 && ams_id < 26) { char slot_name = slot_id + '1'; return std::string(1, 'A' + ams_id) + std::string(1, slot_name); @@ -5789,9 +5711,9 @@ std::map Sidebar::build_filament_ams_list(MachineObject int ams_id = std::stoi(ams.first); int extruder = ams.second->GetExtruderId() ? 0 : 0x10000; // Main (first) extruder at right for (auto tray : ams.second->GetTrays()) { - int slot_id = std::stoi(tray.first); - filament_ams_list.emplace(extruder + (ams_id * 4 + slot_id), build_tray_config(*tray.second, get_ams_name(ams_id, slot_id), - std::to_string(ams_id), std::to_string(slot_id))); + int slot_id = std::stoi(tray.first); + filament_ams_list.emplace(extruder + (ams_id * 4 + slot_id), + build_tray_config(*tray.second, get_ams_name(ams_id, slot_id), std::to_string(ams_id), std::to_string(slot_id))); } } return filament_ams_list; @@ -5803,18 +5725,24 @@ bool Sidebar::sync_extruder_list() return p->sync_extruder_list(only_external_material); } -bool Sidebar::is_fila_switch_ready() { return p->is_fila_switch_ready(); } - -void Sidebar::reset_fila_switch() { p->update_extruder_separator_icon(false, false); } - -bool Sidebar::need_auto_sync_extruder_list_after_connect_priner(const MachineObject* obj) +bool Sidebar::is_fila_switch_ready() { - if (!obj) + return p->is_fila_switch_ready(); +} + +void Sidebar::reset_fila_switch() +{ + p->update_extruder_separator_icon(false, false); +} + +bool Sidebar::need_auto_sync_extruder_list_after_connect_priner(const MachineObject *obj) +{ + if(!obj) return false; - std::string machine_print_name = obj->get_show_printer_type(); - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - std::string target_model_id = preset_bundle->printers.get_selected_preset().get_printer_type(preset_bundle); + std::string machine_print_name = obj->get_show_printer_type(); + PresetBundle *preset_bundle = wxGetApp().preset_bundle; + std::string target_model_id = preset_bundle->printers.get_selected_preset().get_printer_type(preset_bundle); if (machine_print_name != target_model_id) { return false; } @@ -5825,12 +5753,17 @@ bool Sidebar::need_auto_sync_extruder_list_after_connect_priner(const MachineObj return true; } -void Sidebar::update_sync_status(const MachineObject* obj) { p->update_sync_status(obj); } - -int Sidebar::get_sidebar_pos_right_x() { return this->GetScreenPosition().x + this->GetSize().x; } - -void Sidebar::on_size(SimpleEvent& e) +void Sidebar::update_sync_status(const MachineObject *obj) { + p->update_sync_status(obj); +} + +int Sidebar::get_sidebar_pos_right_x() +{ + return this->GetScreenPosition().x + this->GetSize().x; +} + +void Sidebar::on_size(SimpleEvent &e) { if (m_sna_dialog && m_sna_dialog->IsShown()) { pop_sync_nozzle_and_ams_dialog(); } @@ -5839,24 +5772,18 @@ void Sidebar::on_size(SimpleEvent& e) } } -void Sidebar::on_full_screen(IntEvent& e) -{ - if (m_sna_dialog) { - m_sna_dialog->on_full_screen(e); - } - if (m_fna_dialog) { - m_fna_dialog->on_full_screen(e); - } +void Sidebar::on_full_screen(IntEvent &e) { + if (m_sna_dialog) { m_sna_dialog->on_full_screen(e); } + if (m_fna_dialog) { m_fna_dialog->on_full_screen(e); } } -void Sidebar::get_big_btn_sync_pos_size(wxPoint& pt, wxSize& size) +void Sidebar::get_big_btn_sync_pos_size(wxPoint &pt, wxSize &size) { size = p->m_printer_bbl_sync->GetSize(); - pt = p->m_printer_bbl_sync->GetScreenPosition(); + pt = p->m_printer_bbl_sync->GetScreenPosition(); } -void Sidebar::get_small_btn_sync_pos_size(wxPoint& pt, wxSize& size) -{ +void Sidebar::get_small_btn_sync_pos_size(wxPoint &pt, wxSize &size) { size = ams_btn->GetSize(); pt = ams_btn->GetScreenPosition(); } @@ -5872,22 +5799,23 @@ void Sidebar::load_ams_list(MachineObject* obj) filament_ams_list = build_filament_ams_list(obj); } - bool device_change = false; + bool device_change = false; const std::string& device = obj ? obj->get_dev_id() : ""; if (p->ams_list_device != device) { p->ams_list_device = device; device_change = true; } BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1% items") % filament_ams_list.size(); - if (wxGetApp().preset_bundle->filament_ams_list == filament_ams_list && !device_change) { + if (wxGetApp().preset_bundle->filament_ams_list == filament_ams_list && !device_change) + { return; } wxGetApp().preset_bundle->filament_ams_list = filament_ams_list; - for (auto c : p->combos_filament) { + for (auto c : p->combos_filament){ c->update(); if (device_change) { - c->ShowBadge(false); // change printer,then clear badge + c->ShowBadge(false);//change printer,then clear badge } } @@ -5903,15 +5831,14 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) return; GUI::wxGetApp().sidebar().load_ams_list(obj); - auto& list = wxGetApp().preset_bundle->filament_ams_list; + auto & list = wxGetApp().preset_bundle->filament_ams_list; if (list.empty()) { auto printer_name = p->plater->get_selected_printer_name_in_combox(); - p->plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, - _L("Sync printer information")); + p->plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, _L("Sync printer information")); return; } - bool exist_at_list_one_filament = false; - for (auto& cur : list) { + bool exist_at_list_one_filament =false; + for (auto &cur : list) { auto temp_config = cur.second; auto filament_type = temp_config.opt_string("filament_type", 0u); auto filament_color = temp_config.opt_string("filament_colour", 0u); @@ -5936,9 +5863,9 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) if (!ams_filament_ids.empty()) { boost::algorithm::split(list2, ams_filament_ids, boost::algorithm::is_any_of(",")); } - wxGetApp().plater()->update_all_plate_thumbnails(true); // preview thumbnail for sync_dlg + wxGetApp().plater()->update_all_plate_thumbnails(true);//preview thumbnail for sync_dlg SyncAmsInfoDialog::SyncInfo temp_info; - temp_info.use_dialog_pos = false; + temp_info.use_dialog_pos = false; temp_info.cancel_text_to_later = is_from_big_sync_btn; if (m_sync_dlg == nullptr) { m_sync_dlg = new SyncAmsInfoDialog(this, temp_info); @@ -5956,7 +5883,7 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) m_sync_dlg->set_check_dirty_fialment(false); dlg_res = m_sync_dlg->ShowModal(); } else { - dlg_res = (int) wxID_YES; + dlg_res =(int) wxID_YES; } if (dlg_res == wxID_CANCEL) return; @@ -5968,7 +5895,7 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) list2.resize(list.size()); auto iter = list.begin(); for (int i = 0; i < list.size(); ++i, ++iter) { - auto& ams = iter->second; + auto & ams = iter->second; auto filament_id = ams.opt_string("filament_id", 0u); ams.set_key_value("filament_changed", new ConfigOptionBool{dlg_res == wxID_YES || list2[i] != filament_id}); list2[i] = filament_id; @@ -5976,49 +5903,47 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) // BBS:Record consumables information before synchronization std::vector color_before_sync; - std::vector is_support_before; + std::vector is_support_before; DynamicPrintConfig& project_config = wxGetApp().preset_bundle->project_config; - ConfigOptionStrings* color_opt = project_config.option("filament_colour"); + ConfigOptionStrings* color_opt = project_config.option("filament_colour"); for (int i = 0; i < p->combos_filament.size(); ++i) { is_support_before.push_back(is_support_filament(i)); color_before_sync.push_back(color_opt->values[i]); } MergeFilamentInfo merge_info; - std::vector> unknowns; - auto enable_append = wxGetApp().app_config->get_bool("enable_append_color_by_sync_ams"); + std::vector> unknowns; + auto enable_append = wxGetApp().app_config->get_bool("enable_append_color_by_sync_ams"); auto sync_color_only = wxGetApp().app_config->get("sync_ams_filament_mode") == "1"; - auto n = wxGetApp().preset_bundle->sync_ams_list(unknowns, !sync_result.direct_sync, sync_result.sync_maps, enable_append, merge_info, - sync_color_only); + auto n = wxGetApp().preset_bundle->sync_ams_list(unknowns, !sync_result.direct_sync, sync_result.sync_maps, enable_append, merge_info, sync_color_only); wxString detail; - for (auto& uk : unknowns) { + for (auto & uk : unknowns) { auto tray_name = uk.first->opt_string("tray_name", 0u); auto filament_type = uk.first->opt_string("filament_type", 0u); detail += from_u8("\n- " + tray_name + "(" + filament_type + ") ") + _L(uk.second); } if (n == 0) { - MessageDialog dlg(this, _L("There are no compatible filaments, and sync is not performed.") + detail, _L("Sync filaments with AMS"), - wxOK); + MessageDialog dlg(this, + _L("There are no compatible filaments, and sync is not performed.") + detail, + _L("Sync filaments with AMS"), wxOK); dlg.ShowModal(); return; } // Replace unknown filament IDs with the resolved preset's filament_id - auto& filaments = wxGetApp().preset_bundle->filaments; - auto& filament_presets = wxGetApp().preset_bundle->filament_presets; + auto &filaments = wxGetApp().preset_bundle->filaments; + auto &filament_presets = wxGetApp().preset_bundle->filament_presets; for (size_t i = 0; i < list2.size() && i < filament_presets.size(); ++i) { if (list2[i] == UNKNOWN_FILAMENT_ID) { - const Preset* resolved = filaments.find_preset(filament_presets[i]); + const Preset *resolved = filaments.find_preset(filament_presets[i]); if (resolved) list2[i] = resolved->filament_id; } } ams_filament_ids = boost::algorithm::join(list2, ","); - wxGetApp().app_config->set("ams_filament_ids", p->ams_list_device, ams_filament_ids); + wxGetApp().app_config ->set("ams_filament_ids", p->ams_list_device, ams_filament_ids); if (!unknowns.empty()) { MessageDialog dlg(this, - _L("There are some unknown or incompatible filaments mapped to generic preset.\nPlease update Orca Slicer or " - "restart Orca Slicer to check if there is an update to system presets.") + - detail, - _L("Sync filaments with AMS"), wxOK); + _L("There are some unknown or incompatible filaments mapped to generic preset.\nPlease update Orca Slicer or restart Orca Slicer to check if there is an update to system presets.") + detail, + _L("Sync filaments with AMS"), wxOK); dlg.ShowModal(); } if (!sync_color_only) { @@ -6036,9 +5961,11 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) for (int i = 0; i < p->combos_filament.size(); ++i) { if (i >= color_before_sync.size()) { auto_calc_flushing_volumes(i); - } else if (color_before_sync[i] != color_opt->values[i] && wxGetApp().app_config->get("auto_calculate_flush") != "disabled") { + } + else if(color_before_sync[i] != color_opt->values[i] && wxGetApp().app_config->get("auto_calculate_flush") != "disabled"){ auto_calc_flushing_volumes(i); - } else if (is_support_filament(i) != is_support_before[i] && wxGetApp().app_config->get("auto_calculate_flush") == "all") { + } + else if(is_support_filament(i) !=is_support_before[i] && wxGetApp().app_config->get("auto_calculate_flush") == "all"){ auto_calc_flushing_volumes(i); } } @@ -6052,16 +5979,15 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) update_dynamic_filament_list(); } else { wxGetApp().plater()->update_filament_colors_in_full_config(); - for (auto& c : p->combos_filament) + for (auto &c : p->combos_filament) c->update(); obj_list()->update_filament_colors(); update_dynamic_filament_list(); } - auto badge_combox_filament = [sync_color_only](PlaterPresetComboBox* c) { - auto tip = sync_color_only ? - _L("Only filament color information has been synchronized from printer.") : - _L("Filament type and color information have been synchronized, but slot information is not included."); + auto badge_combox_filament = [sync_color_only](PlaterPresetComboBox *c) { + auto tip = sync_color_only ? _L("Only filament color information has been synchronized from printer.") : + _L("Filament type and color information have been synchronized, but slot information is not included."); c->SetToolTip(tip); c->ShowBadge(true); }; @@ -6073,17 +5999,16 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) // empty trays are skipped), so every resulting combo is AMS-sourced and gets a badge. The // previous per-tray index walked the full filament_ams_list (including the skipped empties), // so an empty slot before a loaded one dropped the badge for the trailing filaments. - for (auto& c : p->combos_filament) { + for (auto &c : p->combos_filament) { badge_combox_filament(c); } } } BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "prepare enable_merge_color_by_sync_ams"; - if (!merge_info.is_empty() && - wxGetApp().app_config->get_bool("enable_merge_color_by_sync_ams")) { // merge same color and preset filament//use same ams - auto reduce_index = [](MergeFilamentInfo& merge_info, int value) { + if (!merge_info.is_empty() && wxGetApp().app_config->get_bool("enable_merge_color_by_sync_ams")) { // merge same color and preset filament//use same ams + auto reduce_index = [](MergeFilamentInfo &merge_info,int value) { for (size_t i = 0; i < merge_info.merges.size(); i++) { - auto& cur = merge_info.merges[i]; + auto &cur = merge_info.merges[i]; for (size_t j = 0; j < cur.size(); j++) { if (value < cur[j]) { cur[j] = cur[j] - 1; @@ -6102,7 +6027,7 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) for (size_t i = 0; i < merge_info.merges.size(); i++) { auto& cur = merge_info.merges[i]; - for (int j = cur.size() - 1; j >= 1; j--) { + for (int j = cur.size() -1; j >= 1 ; j--) { auto last_index = cur[j]; change_filament(last_index, cur[0]); cur.erase(cur.begin() + j); @@ -6113,7 +6038,7 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) for (size_t i = 0; i < sync_ams_badges.size(); i++) { if (sync_ams_badges[i] == true) { if (i < p->combos_filament.size()) { - auto& c = p->combos_filament[i]; + auto &c = p->combos_filament[i]; badge_combox_filament(c); } else { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "check error: p->combos_filament array out of bound"; @@ -6127,7 +6052,7 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) } auto temp_index = iter.first; if (temp_index < p->combos_filament.size() && temp_index >= 0) { - auto& c = p->combos_filament[temp_index]; + auto &c = p->combos_filament[temp_index]; badge_combox_filament(c); } } @@ -6137,11 +6062,12 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "finish pop_finsish_sync_ams_dialog"; } + bool Sidebar::should_show_SEMM_buttons() { - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; - bool is_bbl_vendor = preset_bundle.is_bbl_vendor(); - auto cfg = preset_bundle.printers.get_edited_preset().config; + PresetBundle &preset_bundle = *wxGetApp().preset_bundle; + bool is_bbl_vendor = preset_bundle.is_bbl_vendor(); + auto cfg = preset_bundle.printers.get_edited_preset().config; return cfg.opt_bool("single_extruder_multi_material") || is_bbl_vendor; } @@ -6151,22 +6077,23 @@ void Sidebar::show_SEMM_buttons() // ORCA if (!p || p->combos_filament.empty() || !p->m_bpButton_add_filament || !p->m_bpButton_del_filament || !p->m_flushing_volume_btn) return; - + bool is_multi_material = p->combos_filament.size() > 1; bool single_or_bbl = should_show_SEMM_buttons(); - bool is_single = single_or_bbl && !is_multi_material; // SINGLE EXTRUDER / BBL WITH 1 MATERIAL - bool is_multi = single_or_bbl && is_multi_material; // MULTI MATERIAL WITH SINGLE EXTRUDER - bool is_fixed = !is_single && !is_multi; // MULTI EXTRUDER / TOOLCHANGER / IDEX WITH FIXED MATERIAL + bool is_single = single_or_bbl && !is_multi_material; // SINGLE EXTRUDER / BBL WITH 1 MATERIAL + bool is_multi = single_or_bbl && is_multi_material; // MULTI MATERIAL WITH SINGLE EXTRUDER + bool is_fixed = !is_single && !is_multi; // MULTI EXTRUDER / TOOLCHANGER / IDEX WITH FIXED MATERIAL p->m_bpButton_add_filament->Show(single_or_bbl); p->m_bpButton_del_filament->Show(is_multi); - p->m_flushing_volume_btn->Show(is_multi); + p->m_flushing_volume_btn->Show( is_multi); if (is_multi) { - for (auto& c : p->combos_filament) + for (auto &c : p->combos_filament) c->edit_btn->SetBitmap_("menu_filament"); - } else if (is_single || is_fixed) { - for (auto& c : p->combos_filament) + } + else if (is_single || is_fixed) { + for (auto &c : p->combos_filament) c->edit_btn->SetBitmap_("edit"); } @@ -6210,24 +6137,42 @@ void Sidebar::update_dynamic_filament_list() dynamic_physical_filament_list.update(); } -PlaterPresetComboBox* Sidebar::printer_combox() { return p->combo_printer; } +PlaterPresetComboBox* Sidebar::printer_combox() +{ + return p->combo_printer; +} ObjectList* Sidebar::obj_list() { // BBS - // return obj_list(); + //return obj_list(); return p->m_object_list; } -ObjectSettings* Sidebar::obj_settings() { return p->object_settings; } +ObjectSettings* Sidebar::obj_settings() +{ + return p->object_settings; +} -ObjectLayers* Sidebar::obj_layers() { return p->object_layers; } +ObjectLayers* Sidebar::obj_layers() +{ + return p->object_layers; +} -wxPanel* Sidebar::scrolled_panel() { return p->scrolled; } +wxPanel* Sidebar::scrolled_panel() +{ + return p->scrolled; +} -wxPanel* Sidebar::print_panel() { return p->m_panel_print_content; } +wxPanel* Sidebar::print_panel() +{ + return p->m_panel_print_content; +} -wxPanel* Sidebar::filament_panel() { return p->m_panel_filament_content; } +wxPanel* Sidebar::filament_panel() +{ + return p->m_panel_filament_content; +} ConfigOptionsGroup* Sidebar::og_freq_chng_params(const bool is_fff) { @@ -6248,10 +6193,11 @@ wxButton* Sidebar::get_wiping_dialog_button() void Sidebar::set_flushing_volume_warning(const bool flushing_volume_modify) { - if (flushing_volume_modify) { + if(flushing_volume_modify){ p->m_flushing_volume_btn->SetStyle(ButtonStyle::Regular, ButtonType::Compact); p->m_flushing_volume_btn->SetBorderColor(wxColour("#FF6F00")); - } else + } + else p->m_flushing_volume_btn->SetStyle(ButtonStyle::Confirm, ButtonType::Compact); } @@ -6266,17 +6212,19 @@ void Sidebar::enable_buttons(bool enable) #endif } -bool Sidebar::show_reslice(bool show) const { return p->btn_reslice->Show(show); } -bool Sidebar::show_export(bool show) const { return p->btn_export_gcode->Show(show); } -bool Sidebar::show_send(bool show) const { return p->btn_send_gcode->Show(show); } +bool Sidebar::show_reslice(bool show) const { return p->btn_reslice->Show(show); } +bool Sidebar::show_export(bool show) const { return p->btn_export_gcode->Show(show); } +bool Sidebar::show_send(bool show) const { return p->btn_send_gcode->Show(show); } bool Sidebar::show_export_removable(bool show) const { return p->btn_export_gcode_removable->Show(show); } -// bool Sidebar::show_eject(bool show) const { return p->btn_eject_device->Show(show); } -// bool Sidebar::get_eject_shown() const { return p->btn_eject_device->IsShown(); } +//bool Sidebar::show_eject(bool show) const { return p->btn_eject_device->Show(show); } +//bool Sidebar::get_eject_shown() const { return p->btn_eject_device->IsShown(); } -bool Sidebar::is_multifilament() { return p->combos_filament.size() > 1; } - -void Sidebar::deal_btn_sync() +bool Sidebar::is_multifilament() { + return p->combos_filament.size() > 1; +} + +void Sidebar::deal_btn_sync() { m_begin_sync_printer_status = true; bool only_external_material; // Manual "sync machine" button: is_manual=true so an H2C pops the MultiNozzleSyncDialog to pick a nozzle option. @@ -6290,10 +6238,10 @@ void Sidebar::deal_btn_sync() template void setup_dialog_position(T& info) { - auto plater = wxGetApp().plater(); - auto& sidebar = plater->sidebar(); - auto docking = plater->get_sidebar_docking_state(); - bool on_right = true; + auto plater = wxGetApp().plater(); + auto& sidebar = plater->sidebar(); + auto docking = plater->get_sidebar_docking_state(); + bool on_right = true; if (docking == Sidebar::Left) { on_right = true; @@ -6318,27 +6266,23 @@ template void setup_dialog_position(T& info) } } -void Sidebar::pop_sync_nozzle_and_ams_dialog() -{ +void Sidebar::pop_sync_nozzle_and_ams_dialog() { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " begin pop_sync_nozzle_and_ams_dialog"; wxTheApp->CallAfter([this]() { SyncNozzleAndAmsDialog::InputInfo temp_na_info; - wxPoint big_btn_pt; - wxSize big_btn_size; + wxPoint big_btn_pt; + wxSize big_btn_size; wxGetApp().plater()->sidebar().get_big_btn_sync_pos_size(big_btn_pt, big_btn_size); - temp_na_info.dialog_pos = big_btn_pt + wxPoint(big_btn_size.x, big_btn_size.y) + - wxPoint(FromDIP(big_btn_size.x / 10.f - 5), FromDIP(big_btn_size.y / 10.f)); + temp_na_info.dialog_pos = big_btn_pt + wxPoint(big_btn_size.x, big_btn_size.y) + wxPoint(FromDIP(big_btn_size.x / 10.f - 5), FromDIP(big_btn_size.y / 10.f)); temp_na_info.dialog_pos.y += FromDIP(2); setup_dialog_position(temp_na_info); wxPoint small_btn_pt; - wxSize small_btn_size; + wxSize small_btn_size; get_small_btn_sync_pos_size(small_btn_pt, small_btn_size); temp_na_info.ams_btn_pos = small_btn_pt + wxPoint(small_btn_size.x / 2, small_btn_size.y / 2); - if (m_fna_dialog) { - m_fna_dialog->on_hide(); - } + if (m_fna_dialog) { m_fna_dialog->on_hide(); } if (m_sna_dialog) { m_sna_dialog->Destroy(); m_sna_dialog = nullptr; @@ -6352,16 +6296,14 @@ void Sidebar::pop_finsish_sync_ams_dialog() { wxTheApp->CallAfter([this]() { wxPoint small_btn_pt; - wxSize small_btn_size; + wxSize small_btn_size; get_small_btn_sync_pos_size(small_btn_pt, small_btn_size); FinishSyncAmsDialog::InputInfo temp_fsa_info; - temp_fsa_info.dialog_pos.y = small_btn_pt.y; + temp_fsa_info.dialog_pos.y = small_btn_pt.y; setup_dialog_position(temp_fsa_info); - temp_fsa_info.ams_btn_pos = small_btn_pt + wxPoint(small_btn_size.x / 2, small_btn_size.y / 2); - if (m_sna_dialog) { - m_sna_dialog->on_hide(); - } + temp_fsa_info.ams_btn_pos = small_btn_pt + wxPoint(small_btn_size.x / 2, small_btn_size.y / 2); + if (m_sna_dialog) { m_sna_dialog->on_hide(); } if (m_fna_dialog) { m_fna_dialog->Destroy(); m_fna_dialog = nullptr; @@ -6369,38 +6311,42 @@ void Sidebar::pop_finsish_sync_ams_dialog() m_fna_dialog = new FinishSyncAmsDialog(temp_fsa_info); m_fna_dialog->on_show(); }); + } static std::vector get_search_inputs(ConfigOptionMode mode) { - std::vector ret{}; + std::vector ret {}; auto& tabs_list = wxGetApp().tabs_list; auto print_tech = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology(); for (auto tab : tabs_list) if (tab->supports_printer_technology(print_tech)) - ret.emplace_back(Search::InputInfo{tab->get_config(), tab->type(), mode}); + ret.emplace_back(Search::InputInfo {tab->get_config(), tab->type(), mode}); return ret; } -void Sidebar::update_searcher() { p->searcher.init(get_search_inputs(m_mode)); } +void Sidebar::update_searcher() +{ + p->searcher.init(get_search_inputs(m_mode)); +} void Sidebar::update_mode() { m_mode = wxGetApp().get_mode(); - // BBS: remove print related combos + //BBS: remove print related combos update_searcher(); wxWindowUpdateLocker noUpdates(this); // BBS - // obj_list()->get_sizer()->Show(m_mode > comSimple); + //obj_list()->get_sizer()->Show(m_mode > comSimple); obj_list()->unselect_objects(); obj_list()->update_selections(); - // obj_list()->update_object_menu(); +// obj_list()->update_object_menu(); Layout(); } @@ -6412,14 +6358,14 @@ void Sidebar::collapse(bool collapse) { p->plater->collapse_sidebar(collapse); } #ifdef _MSW_DARK_MODE void Sidebar::show_mode_sizer(bool show) { - // p->mode_sizer->Show(show); + //p->mode_sizer->Show(show); } #endif void Sidebar::update_ui_from_settings() { // BBS - // p->object_manipulation->update_ui_from_settings(); + //p->object_manipulation->update_ui_from_settings(); // update Cut gizmo, if it's open p->plater->canvas3D()->update_gizmos_on_off_state(); p->plater->set_current_canvas_as_dirty(); @@ -6444,38 +6390,47 @@ bool Sidebar::show_object_list(bool show) const void Sidebar::finish_param_edit() { p->editing_filament = -1; } -std::vector& Sidebar::combos_filament() { return p->combos_filament; } +std::vector& Sidebar::combos_filament() +{ + return p->combos_filament; +} void Sidebar::clear_combos_filament_badge() { - auto& combos_filament = p->combos_filament; - for (auto& c : combos_filament) { // clear flag + auto &combos_filament = p->combos_filament; + for (auto &c : combos_filament) { // clear flag c->ShowBadge(false); } } -void Sidebar::udpate_combos_filament_badge() -{ - auto& combos_filament = p->combos_filament; - for (auto& c : combos_filament) { +void Sidebar::udpate_combos_filament_badge() { + auto &combos_filament = p->combos_filament; + for (auto &c : combos_filament) { auto selection = c->GetSelection(); auto select_flag = c->GetFlag(selection); auto ok = select_flag == (int) PresetComboBox::FilamentAMSType::FROM_AMS; c->ShowBadge(ok); } + } -Search::OptionsSearcher& Sidebar::get_searcher() { return p->searcher; } +Search::OptionsSearcher& Sidebar::get_searcher() +{ + return p->searcher; +} -std::string& Sidebar::get_search_line() { return p->searcher.search_string(); } +std::string& Sidebar::get_search_line() +{ + return p->searcher.search_string(); +} static std::map printer_thumbnails = {}; void Sidebar::update_printer_thumbnail() { - auto& preset_bundle = wxGetApp().preset_bundle; - Preset& selected_preset = preset_bundle->printers.get_edited_preset(); - std::string printer_type = selected_preset.get_current_printer_type(preset_bundle); + auto& preset_bundle = wxGetApp().preset_bundle; + Preset & selected_preset = preset_bundle->printers.get_edited_preset(); + std::string printer_type = selected_preset.get_current_printer_type(preset_bundle); if (printer_thumbnails.find(printer_type) != printer_thumbnails.end()) // Use known cache first p->image_printer->SetBitmap(create_scaled_bitmap(printer_thumbnails[printer_type], this, PRINTER_THUMBNAIL_SIZE.GetHeight())); else { @@ -6491,7 +6446,7 @@ void Sidebar::update_printer_thumbnail() */ // Orca: try to use the printer model cover as the thumbnail - const auto model_name = selected_preset.config.opt_string("printer_model"); + const auto model_name = selected_preset.config.opt_string("printer_model"); std::string cover_file = model_name + "_cover.png"; for (auto vendor_profile : preset_bundle->vendors) { for (auto vendor_model : vendor_profile.second.models) { @@ -6515,27 +6470,29 @@ void Sidebar::update_printer_thumbnail() } } -void Sidebar::auto_calc_flushing_volumes(const int filament_idx, const int extruder_id) -{ +void Sidebar::auto_calc_flushing_volumes(const int filament_idx, const int extruder_id) { + std::vector filament_indices; std::vector extruder_indices; auto& preset_bundle = wxGetApp().preset_bundle; - auto filament_ptr = preset_bundle->project_config.option("filament_colour"); - int filament_count = filament_ptr ? filament_ptr->size() : 0; - int extruder_count = preset_bundle->get_printer_extruder_count(); + auto filament_ptr = preset_bundle->project_config.option("filament_colour"); + int filament_count = filament_ptr ? filament_ptr->size() : 0; + int extruder_count = preset_bundle->get_printer_extruder_count(); if (filament_idx < 0) { filament_indices.resize(filament_count); std::iota(filament_indices.begin(), filament_indices.end(), 0); - } else { + } + else { filament_indices.emplace_back(filament_idx); } if (extruder_id < 0) { extruder_indices.resize(extruder_count); std::iota(extruder_indices.begin(), extruder_indices.end(), 0); - } else { + } + else { extruder_indices.emplace_back(extruder_id); } @@ -6553,28 +6510,28 @@ void Sidebar::auto_calc_flushing_volumes(const int filament_idx, const int extru p->plater->update(); } + void Sidebar::auto_calc_flushing_volumes_internal(const int modify_id, const int extruder_id) { auto& preset_bundle = wxGetApp().preset_bundle; // A mixed-colour slot is virtual and is never flushed to or from: leave its row and column // alone (the flushing dialog hides them and only compares physical slots). - if (modify_id >= 0 && preset_bundle->is_mixed_filament((size_t) modify_id)) + if (modify_id >= 0 && preset_bundle->is_mixed_filament((size_t)modify_id)) return; - auto& project_config = preset_bundle->project_config; - const auto& full_config = wxGetApp().preset_bundle->full_config(); - auto& ams_multi_color_filament = preset_bundle->ams_multi_color_filment; - size_t extruder_nums = preset_bundle->get_printer_extruder_count(); - int nozzle_flush_dataset = full_config.option("nozzle_flush_dataset")->values[extruder_id]; - std::vector init_matrix = get_flush_volumes_matrix((project_config.option("flush_volumes_matrix"))->values, - extruder_id, extruder_nums); + auto& project_config = preset_bundle->project_config; + const auto& full_config = wxGetApp().preset_bundle->full_config(); + auto& ams_multi_color_filament = preset_bundle->ams_multi_color_filment; + size_t extruder_nums = preset_bundle->get_printer_extruder_count(); + int nozzle_flush_dataset = full_config.option("nozzle_flush_dataset")->values[extruder_id]; + std::vector init_matrix = get_flush_volumes_matrix((project_config.option("flush_volumes_matrix"))->values, extruder_id, extruder_nums); const std::vector& min_flush_volumes = get_min_flush_volumes(full_config, extruder_id); - const auto* flush_multi_opt = project_config.option("flush_multiplier"); - float flush_multiplier = flush_multi_opt ? (float) flush_multi_opt->get_at(extruder_id) : 1.f; - std::vector matrix = init_matrix; - int m_max_flush_volume = Slic3r::g_max_flush_volume; - unsigned int m_number_of_extruders = (int) (sqrt(init_matrix.size()) + 0.001); + const auto* flush_multi_opt = project_config.option("flush_multiplier"); + float flush_multiplier = flush_multi_opt ? (float)flush_multi_opt->get_at(extruder_id) : 1.f; + std::vector matrix = init_matrix; + int m_max_flush_volume = Slic3r::g_max_flush_volume; + unsigned int m_number_of_extruders = (int)(sqrt(init_matrix.size()) + 0.001); const std::vector extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config(); std::vector> multi_colours; @@ -6599,25 +6556,25 @@ void Sidebar::auto_calc_flushing_volumes_internal(const int modify_id, const int if (modify_id >= 0 && modify_id < multi_colours.size()) { for (int i = 0; i < multi_colours.size(); ++i) { - if (preset_bundle->is_mixed_filament((size_t) i)) + if (preset_bundle->is_mixed_filament((size_t)i)) continue; // from to modify int from_idx = i; if (from_idx != modify_id) { Slic3r::FlushVolCalculator calculator(min_flush_volumes[from_idx], m_max_flush_volume, nozzle_flush_dataset); - int flushing_volume = 0; + int flushing_volume = 0; bool is_from_support = is_support_filament(from_idx); - bool is_to_support = is_support_filament(modify_id); + bool is_to_support = is_support_filament(modify_id); if (is_to_support) { flushing_volume = Slic3r::g_flush_volume_to_support; - } else { + } + else { for (int j = 0; j < multi_colours[from_idx].size(); ++j) { const wxColour& from = multi_colours[from_idx][j]; for (int k = 0; k < multi_colours[modify_id].size(); ++k) { const wxColour& to = multi_colours[modify_id][k]; - int volume = calculator.calc_flush_vol(from.Alpha(), from.Red(), from.Green(), from.Blue(), to.Alpha(), - to.Red(), to.Green(), to.Blue()); - flushing_volume = std::max(flushing_volume, volume); + int volume = calculator.calc_flush_vol(from.Alpha(), from.Red(), from.Green(), from.Blue(), to.Alpha(), to.Red(), to.Green(), to.Blue()); + flushing_volume = std::max(flushing_volume, volume); } } if (is_from_support) @@ -6631,18 +6588,18 @@ void Sidebar::auto_calc_flushing_volumes_internal(const int modify_id, const int if (to_idx != modify_id) { Slic3r::FlushVolCalculator calculator(min_flush_volumes[modify_id], m_max_flush_volume, nozzle_flush_dataset); bool is_from_support = is_support_filament(modify_id); - bool is_to_support = is_support_filament(to_idx); - int flushing_volume = 0; + bool is_to_support = is_support_filament(to_idx); + int flushing_volume = 0; if (is_to_support) { flushing_volume = Slic3r::g_flush_volume_to_support; - } else { + } + else { for (int j = 0; j < multi_colours[modify_id].size(); ++j) { const wxColour& from = multi_colours[modify_id][j]; for (int k = 0; k < multi_colours[to_idx].size(); ++k) { const wxColour& to = multi_colours[to_idx][k]; - int volume = calculator.calc_flush_vol(from.Alpha(), from.Red(), from.Green(), from.Blue(), to.Alpha(), - to.Red(), to.Green(), to.Blue()); - flushing_volume = std::max(flushing_volume, volume); + int volume = calculator.calc_flush_vol(from.Alpha(), from.Red(), from.Green(), from.Blue(), to.Alpha(), to.Red(), to.Green(), to.Blue()); + flushing_volume = std::max(flushing_volume, volume); } } if (is_from_support) @@ -6653,21 +6610,27 @@ void Sidebar::auto_calc_flushing_volumes_internal(const int modify_id, const int } } } - set_flush_volumes_matrix((project_config.option("flush_volumes_matrix"))->values, matrix, extruder_id, - extruder_nums); + set_flush_volumes_matrix((project_config.option("flush_volumes_matrix"))->values, matrix, extruder_id, extruder_nums); } -void Sidebar::jump_to_object(ObjectDataViewModelNode* item) { p->jump_to_object(item); } +void Sidebar::jump_to_object(ObjectDataViewModelNode* item) +{ + p->jump_to_object(item); +} -void Sidebar::can_search() { p->can_search(); } +void Sidebar::can_search() +{ + p->can_search(); +} class PlaterDropTarget : public wxFileDropTarget { public: - PlaterDropTarget(MainFrame& mainframe, Plater& plater) : m_mainframe(mainframe), m_plater(plater) - { this->SetDefaultAction(wxDragCopy); } + PlaterDropTarget(MainFrame& mainframe, Plater& plater) : m_mainframe(mainframe), m_plater(plater) { + this->SetDefaultAction(wxDragCopy); + } - virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); + virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames); private: MainFrame& m_mainframe; @@ -6675,16 +6638,16 @@ private: }; namespace { -bool emboss_svg(Plater& plater, const wxString& svg_file, const Vec2d& mouse_drop_position) +bool emboss_svg(Plater& plater, const wxString &svg_file, const Vec2d& mouse_drop_position) { std::string svg_file_str = into_u8(svg_file); - GLCanvas3D* canvas = plater.canvas3D(); + GLCanvas3D* canvas = plater.canvas3D(); if (canvas == nullptr) return false; auto base_svg = canvas->get_gizmos_manager().get_gizmo(GLGizmosManager::Svg); if (base_svg == nullptr) return false; - GLGizmoSVG* svg = dynamic_cast(base_svg); + GLGizmoSVG* svg = dynamic_cast(base_svg); if (svg == nullptr) return false; @@ -6695,42 +6658,51 @@ bool emboss_svg(Plater& plater, const wxString& svg_file, const Vec2d& mouse_dro return svg->create_volume(svg_file_str, mouse_drop_position, ModelVolumeType::MODEL_PART); } -} // namespace +} // State to manage showing after export notifications and device ejecting -enum ExportingStatus { NOT_EXPORTING, EXPORTING_TO_REMOVABLE, EXPORTING_TO_LOCAL }; +enum ExportingStatus{ + NOT_EXPORTING, + EXPORTING_TO_REMOVABLE, + EXPORTING_TO_LOCAL +}; + // TODO: listen on dark ui change class FloatFrame : public wxAuiFloatingFrame { public: FloatFrame(wxWindow* parent, wxAuiManager* ownerMgr, const wxAuiPaneInfo& pane) : wxAuiFloatingFrame(parent, ownerMgr, pane) - { wxGetApp().UpdateFrameDarkUI(this); } + { + wxGetApp().UpdateFrameDarkUI(this); + } }; class AuiMgr : public wxAuiManager { public: - AuiMgr() : wxAuiManager() {} + AuiMgr() : wxAuiManager(){} virtual wxAuiFloatingFrame* CreateFloatingFrame(wxWindow* parent, const wxAuiPaneInfo& p) override - { return new FloatFrame(parent, this, p); } + { + return new FloatFrame(parent, this, p); + } }; // Plater / private struct Plater::priv { // PIMPL back pointer ("Q-Pointer") - Plater* q; - Sidebar* sidebar; - MainFrame* main_frame; + Plater *q; + Sidebar * sidebar; + MainFrame *main_frame; MenuFactory menus; SelectMachineDialog* m_select_machine_dlg = nullptr; - SendMultiMachinePage* m_send_multi_dlg = nullptr; + SendMultiMachinePage* m_send_multi_dlg = nullptr; SendToPrinterDialog* m_send_to_sdcard_dlg = nullptr; - PublishDialog* m_publish_dlg = nullptr; + PublishDialog *m_publish_dlg = nullptr; // Session-level stash of the last published selection. Written on publish and on // loading a published 3MF; read when the Publish dialog is opened. @@ -6739,33 +6711,33 @@ struct Plater::priv std::vector m_pending_material_keys; // Data - Slic3r::DynamicPrintConfig* config; // FIXME: leak? - Slic3r::Print fff_print; - Slic3r::SLAPrint sla_print; - Slic3r::Model model; - PrinterTechnology printer_technology = ptFFF; + Slic3r::DynamicPrintConfig *config; // FIXME: leak? + Slic3r::Print fff_print; + Slic3r::SLAPrint sla_print; + Slic3r::Model model; + PrinterTechnology printer_technology = ptFFF; Slic3r::GCodeProcessorResult gcode_result; // GUI elements AuiMgr m_aui_mgr; wxString m_default_window_layout; - wxPanel* current_panel{nullptr}; + wxPanel* current_panel{ nullptr }; std::vector panels; struct SidebarLayout { - bool is_enabled{false}; - bool is_collapsed{false}; - bool show{false}; + bool is_enabled{false}; + bool is_collapsed{false}; + bool show{false}; } sidebar_layout; Bed3D bed; Camera camera; - // BBS: partplate related structure + //BBS: partplate related structure PartPlateList partplate_list; - // BBS: add a flag to ignore cancel event + //BBS: add a flag to ignore cancel event bool m_ignore_event{false}; bool m_slice_all{false}; - bool m_is_slicing{false}; + bool m_is_slicing {false}; // Missing-plugin set signatures (sorted full refs joined by '\n'), one per notification. They // gate plugin-load re-validation and avoid needlessly recreating the notification when the set // is unchanged. Whether missing plugins block slicing is derived directly from PluginResolver @@ -6774,17 +6746,17 @@ struct Plater::priv std::string m_cloud_missing_shown_sig; std::string m_inactive_shown_sig; std::string m_broken_shown_sig; - bool auto_reslice_pending{false}; - bool auto_reslice_after_cancel{false}; - bool m_is_publishing{false}; + bool auto_reslice_pending {false}; + bool auto_reslice_after_cancel {false}; + bool m_is_publishing {false}; int m_is_RightClickInLeftUI{-1}; int m_cur_slice_plate; - // BBS: m_slice_all in .gcode.3mf file case, set true when slice all - bool m_slice_all_only_has_gcode{false}; + //BBS: m_slice_all in .gcode.3mf file case, set true when slice all + bool m_slice_all_only_has_gcode{ false }; bool m_need_update{false}; - // BBS: add popup object table logic - // ObjectTableDialog* m_popup_table{ nullptr }; + //BBS: add popup object table logic + //ObjectTableDialog* m_popup_table{ nullptr }; #if ENABLE_ENVIRONMENT_MAP GLTexture environment_texture; @@ -6792,17 +6764,17 @@ struct Plater::priv Mouse3DController mouse3d_controller; View3D* view3D; // BBS - // GLToolbar view_toolbar; + //GLToolbar view_toolbar; GLToolbar collapse_toolbar; - Preview* preview; - AssembleView* assemble_view{nullptr}; - bool first_enter_assemble{true}; + Preview *preview; + AssembleView* assemble_view { nullptr }; + bool first_enter_assemble{ true }; std::unique_ptr notification_manager; ProjectDirtyStateManager dirty_state; - BackgroundSlicingProcess background_process; - bool suppressed_backround_processing_update{false}; + BackgroundSlicingProcess background_process; + bool suppressed_backround_processing_update { false }; // TODO: A mechanism would be useful for blocking the plater interactions: // objects would be frozen for the user. In case of arrange, an animation @@ -6812,22 +6784,22 @@ struct Plater::priv // UIThreadWorker can be used as a replacement for BoostThreadWorker if // no additional worker threads are desired (useful for debugging or profiling) PlaterWorker m_worker; - SLAImportDialog* m_sla_import_dlg; + SLAImportDialog * m_sla_import_dlg; - int m_job_prepare_state; + int m_job_prepare_state; - bool delayed_scene_refresh; - std::string delayed_error_message; + bool delayed_scene_refresh; + std::string delayed_error_message; - wxTimer background_process_timer; - wxTimer auto_reslice_timer; + wxTimer background_process_timer; + wxTimer auto_reslice_timer; - std::string label_btn_export; - std::string label_btn_send; + std::string label_btn_export; + std::string label_btn_send; - bool show_render_statistic_dialog{false}; - bool show_wireframe{false}; - bool wireframe_enabled{true}; + bool show_render_statistic_dialog{ false }; + bool show_wireframe{ false }; + bool wireframe_enabled{ true }; static const std::regex pattern_bundle; static const std::regex pattern_3mf; @@ -6837,9 +6809,10 @@ struct Plater::priv bool m_is_dark = false; - priv(Plater* q, MainFrame* main_frame); + priv(Plater *q, MainFrame *main_frame); ~priv(); + bool need_update() const { return m_need_update; } void set_need_update(bool need_update) { m_need_update = need_update; } @@ -6852,8 +6825,7 @@ struct Plater::priv Slic3r::put_other_changes(); dirty_state.update_from_presets(); } - int save_project_if_dirty(const wxString& reason) - { + int save_project_if_dirty(const wxString& reason) { int res = wxID_NO; if (dirty_state.is_dirty()) { MainFrame* mainframe = wxGetApp().mainframe; @@ -6861,13 +6833,11 @@ struct Plater::priv wxString suggested_project_name; wxString project_name = suggested_project_name = get_project_filename(".3mf"); if (suggested_project_name.IsEmpty()) { - fs::path output_file = get_export_file_path(FT_3MF); + fs::path output_file = get_export_file_path(FT_3MF); suggested_project_name = output_file.empty() ? _L("Untitled") : from_u8(output_file.stem().string()); } - res = MessageDialog(mainframe, - reason + "\n" + format_wxstr(_L("Do you want to save changes to \"%1%\"?"), suggested_project_name), - wxString(SLIC3R_APP_FULL_NAME), wxYES_NO | wxCANCEL) - .ShowModal(); + res = MessageDialog(mainframe, reason + "\n" + format_wxstr(_L("Do you want to save changes to \"%1%\"?"), suggested_project_name), + wxString(SLIC3R_APP_FULL_NAME), wxYES_NO | wxCANCEL).ShowModal(); if (res == wxID_YES) if (!mainframe->save_project_as(project_name)) res = wxID_CANCEL; @@ -6875,11 +6845,7 @@ struct Plater::priv } return res; } - void reset_project_dirty_after_save() - { - m_undo_redo_stack_main.mark_current_as_saved(); - dirty_state.reset_after_save(); - } + void reset_project_dirty_after_save() { m_undo_redo_stack_main.mark_current_as_saved(); dirty_state.reset_after_save(); } void reset_project_dirty_initial_presets() { dirty_state.reset_initial_presets(); } #if ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW @@ -6893,7 +6859,7 @@ struct Plater::priv }; void update(unsigned int flags = 0); void select_view(const std::string& direction); - // BBS: add no_slice option + //BBS: add no_slice option void select_view_3D(const std::string& name, bool no_slice = true); void select_next_view_3D(); @@ -6905,7 +6871,7 @@ struct Plater::priv bool are_view3D_labels_shown() const { return (current_panel == view3D) && view3D->get_canvas3d()->are_labels_shown(); } void show_view3D_labels(bool show) { - if (current_panel == view3D) { + if (current_panel == view3D) { view3D->get_canvas3d()->show_labels(show); wxGetApp().app_config->set_bool("show_labels", show); } @@ -6914,7 +6880,7 @@ struct Plater::priv bool is_view3D_overhang_shown() const { return (current_panel == view3D) && view3D->get_canvas3d()->is_overhang_shown(); } void show_view3D_overhang(bool show) { - if (current_panel == view3D) { + if (current_panel == view3D) { view3D->get_canvas3d()->show_overhang(show); wxGetApp().app_config->set_bool("show_overhang", show); } @@ -6926,15 +6892,14 @@ struct Plater::priv void reset_window_layout(); Sidebar::DockingState get_sidebar_docking_state(); - bool is_view3D_layers_editing_enabled() const - { return (current_panel == view3D) && view3D->get_canvas3d()->is_layers_editing_enabled(); } + bool is_view3D_layers_editing_enabled() const { return (current_panel == view3D) && view3D->get_canvas3d()->is_layers_editing_enabled(); } void set_current_canvas_as_dirty(); GLCanvas3D* get_current_canvas3D(bool exclude_preview = false); void unbind_canvas_event_handlers(); void reset_canvas_volumes(); - bool check_ams_status_impl(bool is_slice_all); // Check whether the printer and ams status are consistent, for grouping algorithm - bool get_machine_sync_status(); // check whether the printer is linked and the printer type is same as selected profile + bool check_ams_status_impl(bool is_slice_all); // Check whether the printer and ams status are consistent, for grouping algorithm + bool get_machine_sync_status(); // check whether the printer is linked and the printer type is same as selected profile // BBS bool init_collapse_toolbar(); @@ -6963,7 +6928,7 @@ struct Plater::priv void update_ui_from_settings(); // BBS std::shared_ptr statusbar(); - std::string get_config(const std::string& key) const; + std::string get_config(const std::string &key) const; BoundingBoxf bed_shape_bb() const; BoundingBox scaled_bed_shape_bb() const; @@ -6973,37 +6938,31 @@ struct Plater::priv LoadStrategy strategy, bool ask_multi = false, bool* published_out = nullptr); - std::vector load_model_objects(const ModelObjectPtrs& model_objects, - bool allow_negative_z = false, - bool split_object = false, - bool auto_drop = true); + std::vector load_model_objects(const ModelObjectPtrs& model_objects, bool allow_negative_z = false, bool split_object = false, bool auto_drop = true); // Texture-to-color import: a mesh loaded with UVs + a texture map gets its faces clustered // into printable colours, which are then matched against (or added to) the filament list. - struct TextureImportResult - { - Slic3r::PaintedMesh painted; - std::vector matches; - std::vector> new_filament_colors; - std::vector new_filament_preset_names; + struct TextureImportResult { + Slic3r::PaintedMesh painted; + std::vector matches; + std::vector> new_filament_colors; + std::vector new_filament_preset_names; std::vector new_mixed_filaments; - std::vector filament_entries; - size_t existing_filament_count = 0; - bool skipped = false; - bool fallback_to_geometry_only = false; - wxString fallback_warning; + std::vector filament_entries; + size_t existing_filament_count = 0; + bool skipped = false; + bool fallback_to_geometry_only = false; + wxString fallback_warning; }; - bool run_textured_mesh_import_dialog(Slic3r::Model& loaded_model, - TextureImportResult& result, - std::function cancel_callback = {}, + bool run_textured_mesh_import_dialog(Slic3r::Model& loaded_model, TextureImportResult& result, + std::function cancel_callback = {}, std::function progress_callback = {}); - void apply_textured_mesh_import_result(Slic3r::Model& loaded_model, - const std::vector& obj_idxs, + void apply_textured_mesh_import_result(Slic3r::Model& loaded_model, const std::vector& obj_idxs, const TextureImportResult& result, - LoadProgressCallback progress_callback = {}, - bool update_scene = true); - void handle_textured_mesh_import(Slic3r::Model& model, const std::vector& obj_idxs, std::function cancel_callback = {}); + LoadProgressCallback progress_callback = {}, bool update_scene = true); + void handle_textured_mesh_import(Slic3r::Model& model, const std::vector& obj_idxs, + std::function cancel_callback = {}); fs::path get_export_file_path(GUI::FileType file_type); wxString get_export_file(GUI::FileType file_type, const wxString& title = {}, bool published = false); @@ -7028,7 +6987,7 @@ struct Plater::priv void deselect_all(); void exit_gizmo(); void remove(size_t obj_idx); - bool delete_object_from_model(size_t obj_idx, bool refresh_immediately = true); // BBS + bool delete_object_from_model(size_t obj_idx, bool refresh_immediately = true); //BBS void delete_all_objects_from_model(); void reset(bool apply_presets_change = false); void center_selection(); @@ -7040,11 +6999,7 @@ struct Plater::priv void scale_selection_to_fit_print_volume(); // Return the active Undo/Redo stack. It may be either the main stack or the Gimzo stack. - Slic3r::UndoRedo::Stack& undo_redo_stack() - { - assert(m_undo_redo_stack_active != nullptr); - return *m_undo_redo_stack_active; - } + Slic3r::UndoRedo::Stack& undo_redo_stack() { assert(m_undo_redo_stack_active != nullptr); return *m_undo_redo_stack_active; } Slic3r::UndoRedo::Stack& undo_redo_stack_main() { return m_undo_redo_stack_main; } void enter_gizmos_stack(); bool leave_gizmos_stack(); @@ -7052,7 +7007,7 @@ struct Plater::priv void take_snapshot(const std::string& snapshot_name, UndoRedo::SnapshotType snapshot_type = UndoRedo::SnapshotType::Action); /*void take_snapshot(const wxString& snapshot_name, UndoRedo::SnapshotType snapshot_type = UndoRedo::SnapshotType::Action) { this->take_snapshot(std::string(snapshot_name.ToUTF8().data()), snapshot_type); }*/ - int get_active_snapshot_index(); + int get_active_snapshot_index(); void undo(); void redo(); @@ -7061,25 +7016,22 @@ struct Plater::priv // BBS: backup bool up_to_date(bool saved, bool backup); - void suppress_snapshots() { m_prevent_snapshots++; } - void allow_snapshots() { m_prevent_snapshots--; } + void suppress_snapshots() { m_prevent_snapshots++; } + void allow_snapshots() { m_prevent_snapshots--; } // BBS: single snapshot - void single_snapshots_enter(SingleSnapshot* single) + void single_snapshots_enter(SingleSnapshot *single) { - if (m_single == nullptr) - m_single = single; + if (m_single == nullptr) m_single = single; } - void single_snapshots_leave(SingleSnapshot* single) + void single_snapshots_leave(SingleSnapshot *single) { - if (m_single == single) - m_single = nullptr; + if (m_single == single) m_single = nullptr; } - void process_validation_warning(StringObjectException const& warning) const; - void process_validation_warnings(const std::vector& warnings) const; + void process_validation_warning(StringObjectException const &warning) const; + void process_validation_warnings(const std::vector &warnings) const; - bool background_processing_enabled() const - { + bool background_processing_enabled() const { #ifdef SUPPORT_BACKGROUND_PROCESSING return this->get_config("background_processing") == "1"; #else @@ -7091,7 +7043,7 @@ struct Plater::priv void schedule_background_process(); void schedule_auto_reslice_if_needed(); void trigger_auto_reslice_now(); - int auto_slice_delay_seconds() const; + int auto_slice_delay_seconds() const; // Update background processing thread from the current config and Model. enum UpdateBackgroundProcessReturnState { // update_background_process() reports, that the Print / SLAPrint was updated in a way, @@ -7114,8 +7066,7 @@ struct Plater::priv bool restart_background_process(unsigned int state); // returns bit mask of UpdateBackgroundProcessReturnState unsigned int update_restart_background_process(bool force_scene_update, bool force_preview_update); - void show_delayed_error_message() - { + void show_delayed_error_message() { if (!this->delayed_error_message.empty()) { std::string msg = std::move(this->delayed_error_message); this->delayed_error_message.clear(); @@ -7131,7 +7082,7 @@ struct Plater::priv void replace_all_with_stl(); void reload_all_from_disk(); - // BBS: add no_slice option + //BBS: add no_slice option void set_current_panel(wxPanel* panel, bool no_slice = true); void on_combobox_select(wxCommandEvent&); @@ -7145,9 +7096,9 @@ struct Plater::priv void on_slicing_began(); void clear_warnings(); - void add_warning(const Slic3r::PrintStateBase::Warning& warning, size_t oid); + void add_warning(const Slic3r::PrintStateBase::Warning &warning, size_t oid); // Update notification manager with the current state of warnings produced by the background process (slicing). - void actualize_slicing_warnings(const PrintBase& print); + void actualize_slicing_warnings(const PrintBase &print); void actualize_object_warnings(const PrintBase& print); // Displays dialog window with list of warnings. // Returns true if user clicks OK. @@ -7160,32 +7111,32 @@ struct Plater::priv void on_action_split_objects(SimpleEvent&); void on_action_split_volumes(SimpleEvent&); void on_action_layersediting(SimpleEvent&); - void on_create_filament(SimpleEvent&); - void on_modify_filament(SimpleEvent&); - void on_add_filament(SimpleEvent&); - void on_delete_filament(SimpleEvent&); - void on_add_custom_filament(ColorEvent&); + void on_create_filament(SimpleEvent &); + void on_modify_filament(SimpleEvent &); + void on_add_filament(SimpleEvent &); + void on_delete_filament(SimpleEvent &); + void on_add_custom_filament(ColorEvent &); void on_object_select(SimpleEvent&); - void show_right_click_menu(Vec2d mouse_position, wxMenu* menu); + void show_right_click_menu(Vec2d mouse_position, wxMenu *menu); void on_right_click(RBtnEvent&); - // BBS: add model repair - void on_repair_model(wxCommandEvent& event); - void on_filament_color_changed(wxCommandEvent& event); - void show_install_plugin_hint(wxCommandEvent& event); - void install_network_plugin(wxCommandEvent& event); - void show_preview_only_hint(wxCommandEvent& event); - // BBS: add part plate related logic + //BBS: add model repair + void on_repair_model(wxCommandEvent &event); + void on_filament_color_changed(wxCommandEvent &event); + void show_install_plugin_hint(wxCommandEvent &event); + void install_network_plugin(wxCommandEvent &event); + void show_preview_only_hint(wxCommandEvent &event); + //BBS: add part plate related logic void on_plate_right_click(RBtnPlateEvent&); void on_plate_selected(SimpleEvent&); void on_action_request_model_id(wxCommandEvent& evt); void on_action_download_project(wxCommandEvent& evt); void on_slice_button_status(bool enable); - // BBS: GUI refactor: GLToolbar + //BBS: GUI refactor: GLToolbar void on_action_open_project(SimpleEvent&); void on_action_slice_plate(SimpleEvent&); void on_action_slice_all(SimpleEvent&); - void on_action_publish(wxCommandEvent& evt); + void on_action_publish(wxCommandEvent &evt); void on_action_print_plate(SimpleEvent&); void open_machine_select_dialog(int plate_idx, PrintFromType print_type = PrintFromType::FROM_NORMAL); void on_action_print_all(SimpleEvent&); @@ -7194,7 +7145,7 @@ struct Plater::priv void on_action_export_sliced_file(SimpleEvent&); void on_action_export_all_sliced_file(SimpleEvent&); void on_action_select_sliced_plate(wxCommandEvent& evt); - // BBS: change dark/light mode + //BBS: change dark/light mode void on_change_color_mode(SimpleEvent& evt); void on_apple_change_color_mode(wxSysColourChangedEvent& evt); void apply_color_mode(); @@ -7202,9 +7153,9 @@ struct Plater::priv void on_3dcanvas_mouse_dragging_started(SimpleEvent&); void on_3dcanvas_mouse_dragging_finished(SimpleEvent&); - // void show_action_buttons(const bool is_ready_to_slice) const; + //void show_action_buttons(const bool is_ready_to_slice) const; bool show_publish_dlg(bool show = true); - void update_publish_dialog_status(wxString& msg, int percent = -1); + void update_publish_dialog_status(wxString &msg, int percent = -1); void on_action_print_plate_from_sdcard(SimpleEvent&); void on_tab_selection_changing(wxBookCtrlEvent&); @@ -7213,16 +7164,16 @@ struct Plater::priv // triangulate the bed and store the triangles into m_bed.m_triangles, // fills the m_bed.m_grid_lines and sets m_bed.m_origin. // Sets m_bed.m_polygon to limit the object placement. - // BBS: add bed exclude area - void set_bed_shape(const Pointfs& shape, - const Pointfs& exclude_areas, - const Pointfs& wrapping_exclude_areas, - const double printable_height, + //BBS: add bed exclude area + void set_bed_shape(const Pointfs &shape, + const Pointfs &exclude_areas, + const Pointfs &wrapping_exclude_areas, + const double printable_height, std::vector extruder_areas, - std::vector extruder_heights, - const std::string& custom_texture, - const std::string& custom_model, - bool force_as_custom = false); + std::vector extruder_heights, + const std::string &custom_texture, + const std::string &custom_model, + bool force_as_custom = false); bool can_delete() const; bool can_delete_all() const; @@ -7240,7 +7191,7 @@ struct Plater::priv bool can_set_instance_to_object() const; bool can_mirror() const; bool can_reload_from_disk() const; - // BBS: + //BBS: bool can_fillcolor() const; bool has_assemble_view() const; bool can_replace_with_stl() const; @@ -7250,15 +7201,12 @@ struct Plater::priv bool can_scale_to_print_volume() const; #endif // ENABLE_ENHANCED_PRINT_VOLUME_FIT - // BBS: add plate_id for thumbnail - void generate_thumbnail(ThumbnailData& data, - unsigned int w, - unsigned int h, - const ThumbnailsParams& thumbnail_params, - Camera::EType camera_type, - Camera::ViewAngleType camera_view_angle_type = Camera::ViewAngleType::Iso, - bool for_picking = false, - bool ban_light = false); + //BBS: add plate_id for thumbnail + void generate_thumbnail(ThumbnailData& data, unsigned int w, unsigned int h, const ThumbnailsParams& thumbnail_params, + Camera::EType camera_type, + Camera::ViewAngleType camera_view_angle_type = Camera::ViewAngleType::Iso, + bool for_picking = false, + bool ban_light = false); ThumbnailsList generate_thumbnails(const ThumbnailsParams& params, Camera::EType camera_type); PlateBBoxData generate_first_layer_bbox(); @@ -7270,7 +7218,7 @@ struct Plater::priv wxString get_export_gcode_filename(const wxString& extension = wxEmptyString, bool only_filename = false, bool export_all = false) const; void set_project_filename(const wxString& filename); - // BBS store bbs project name + //BBS store bbs project name wxString get_project_name(); void set_project_name(const wxString& project_name); void update_title_dirty_status(); @@ -7280,34 +7228,27 @@ struct Plater::priv void update_objects_position_when_select_preset(const std::function& select_prest); - // Caching last value of show_action_buttons parameter for show_action_buttons(), so that a callback which does not know this state will - // not override it. - // mutable bool ready_to_slice = { false }; - // Flag indicating that the G-code export targets a removable device, therefore the show_action_buttons() needs to be called at any case - // when the background processing finishes. - ExportingStatus exporting_status{NOT_EXPORTING}; - std::string last_output_path; - std::string last_output_dir_path; - // BBS store machine_sn and 3mf_path for PrintJob - PrintPrepareData m_print_job_data; - bool inside_snapshot_capture() { return m_prevent_snapshots != 0; } - int process_completed_with_error{-1}; //-1 means no error + // Caching last value of show_action_buttons parameter for show_action_buttons(), so that a callback which does not know this state will not override it. + //mutable bool ready_to_slice = { false }; + // Flag indicating that the G-code export targets a removable device, therefore the show_action_buttons() needs to be called at any case when the background processing finishes. + ExportingStatus exporting_status { NOT_EXPORTING }; + std::string last_output_path; + std::string last_output_dir_path; + //BBS store machine_sn and 3mf_path for PrintJob + PrintPrepareData m_print_job_data; + bool inside_snapshot_capture() { return m_prevent_snapshots != 0; } + int process_completed_with_error { -1 }; //-1 means no error - // BBS: project - BBLProject project; + //BBS: project + BBLProject project; - // BBS: add print project related logic + //BBS: add print project related logic void update_fff_scene_only_shells(bool only_shells = true); - // BBS: add popup object table logic + //BBS: add popup object table logic bool PopupObjectTable(int object_id, int volume_id, const wxPoint& position); void on_action_send_to_printer(bool isall = false); void on_action_send_to_multi_machine(SimpleEvent&); - int update_print_required_data(Slic3r::DynamicPrintConfig config, - Slic3r::Model model, - Slic3r::PlateDataPtrs plate_data_list, - std::string file_name, - std::string file_path); - + int update_print_required_data(Slic3r::DynamicPrintConfig config, Slic3r::Model model, Slic3r::PlateDataPtrs plate_data_list, std::string file_name, std::string file_path); private: bool layers_height_allowed() const; @@ -7320,30 +7261,30 @@ private: void on_action_export_to_sdcard_all(SimpleEvent&); void update_plugin_when_launch(wxCommandEvent& event); // path to project folder stored with no extension - boost::filesystem::path m_project_folder; + boost::filesystem::path m_project_folder; /* display project name */ - wxString m_project_name; + wxString m_project_name; - Slic3r::UndoRedo::Stack m_undo_redo_stack_main; - Slic3r::UndoRedo::Stack m_undo_redo_stack_gizmos; - Slic3r::UndoRedo::Stack* m_undo_redo_stack_active = &m_undo_redo_stack_main; - int m_prevent_snapshots = 0; /* Used for avoid of excess "snapshoting". - * Like for "delete selected" or "set numbers of copies" - * we should call tack_snapshot just ones - * instead of calls for each action separately - * */ + Slic3r::UndoRedo::Stack m_undo_redo_stack_main; + Slic3r::UndoRedo::Stack m_undo_redo_stack_gizmos; + Slic3r::UndoRedo::Stack *m_undo_redo_stack_active = &m_undo_redo_stack_main; + int m_prevent_snapshots = 0; /* Used for avoid of excess "snapshoting". + * Like for "delete selected" or "set numbers of copies" + * we should call tack_snapshot just ones + * instead of calls for each action separately + * */ // BBS: single snapshot - Plater::SingleSnapshot* m_single = nullptr; + Plater::SingleSnapshot *m_single = nullptr; // BBS: backup - size_t m_saved_timestamp = 0; + size_t m_saved_timestamp = 0; size_t m_backup_timestamp = 0; - std::string m_last_fff_printer_profile_name; - std::string m_last_sla_printer_profile_name; + std::string m_last_fff_printer_profile_name; + std::string m_last_sla_printer_profile_name; // vector of all warnings generated by last slicing std::vector> current_warnings; - bool show_warning_dialog{false}; + bool show_warning_dialog { false }; }; Plater::~Plater() = default; @@ -7354,7 +7295,7 @@ const std::regex Plater::priv::pattern_zip_amf(".*[.]zip[.]amf", std::regex::ica const std::regex Plater::priv::pattern_any_amf(".*[.](amf|amf[.]xml|zip[.]amf)", std::regex::icase); const std::regex Plater::priv::pattern_prusa(".*bbl", std::regex::icase); -bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) +bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames) { #ifdef WIN32 // hides the system icon @@ -7368,14 +7309,14 @@ bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& fi // When only one .svg file is dropped on scene if (filenames.size() == 1) { - const wxString& filename = filenames.Last(); - const wxString file_extension = filename.substr(filename.length() - 4); + const wxString &filename = filenames.Last(); + const wxString file_extension = filename.substr(filename.length() - 4); if (file_extension.CmpNoCase(".svg") == 0) { // BBS: GUI refactor: move sidebar to the left - const wxPoint offset = m_plater.GetPosition() + m_plater.p->current_panel->GetPosition(); + const wxPoint offset = m_plater.GetPosition() + m_plater.p->current_panel->GetPosition(); Vec2d mouse_position(x - offset.x, y - offset.y); // Scale for retina displays - const GLCanvas3D* canvas = m_plater.canvas3D(); + const GLCanvas3D *canvas = m_plater.canvas3D(); canvas->apply_retina_scale(mouse_position); return emboss_svg(m_plater, filename, mouse_position); } @@ -7385,26 +7326,29 @@ bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& fi return res; } -Plater::priv::priv(Plater* q, MainFrame* main_frame) +Plater::priv::priv(Plater *q, MainFrame *main_frame) : q(q) , main_frame(main_frame) - // BBS: add bed_exclude_area - , config(Slic3r::DynamicPrintConfig::new_from_defaults_keys( - {"printable_area", "bed_exclude_area", "wrapping_exclude_area", "extruder_printable_area", "bed_custom_texture", - "bed_custom_model", "print_sequence", "extruder_clearance_radius", "extruder_clearance_height_to_lid", - "extruder_clearance_height_to_rod", "nozzle_height", "skirt_type", "skirt_loops", "skirt_speed", "min_skirt_length", - "skirt_distance", "skirt_start_angle", "brim_width", "brim_object_gap", "brim_flow_ratio", "brim_use_efc_outline", - "combine_brims", "brim_type", "nozzle_diameter", "single_extruder_multi_material", "preferred_orientation", "enable_prime_tower", - "wipe_tower_x", "wipe_tower_y", "prime_tower_width", "prime_tower_brim_width", "prime_tower_skip_points", - "prime_tower_enable_framework", "prime_tower_infill_gap", "prime_volume", "extruder_colour", "filament_colour", "filament_type", - "filament_is_support", "material_colour", "printable_height", "extruder_printable_height", "printer_model", "printer_technology", - // These values are necessary to construct SlicingParameters by the Canvas3D variable layer height editor. - "layer_height", "initial_layer_print_height", "min_layer_height", "max_layer_height", "wall_loops", "outer_wall_filament_id", - "inner_wall_filament_id", "sparse_infill_density", "sparse_infill_filament_id", "top_shell_layers", "enable_support", - "support_filament", "support_interface_filament", "support_top_z_distance", "support_bottom_z_distance", "raft_layers", - "wipe_tower_rotation_angle", "wipe_tower_cone_angle", "wipe_tower_extra_spacing", "wipe_tower_extra_flow", - "wipe_tower_max_purge_speed", "wipe_tower_wall_type", "wipe_tower_extra_rib_length", "wipe_tower_rib_width", - "wipe_tower_fillet_wall", "wipe_tower_filament", "best_object_pos", "master_extruder_id"})) + //BBS: add bed_exclude_area + , config(Slic3r::DynamicPrintConfig::new_from_defaults_keys({ + "printable_area", "bed_exclude_area", "wrapping_exclude_area", "extruder_printable_area", "bed_custom_texture", "bed_custom_model", "print_sequence", + "extruder_clearance_radius", + "extruder_clearance_height_to_lid", "extruder_clearance_height_to_rod", + "nozzle_height", "skirt_type", "skirt_loops", "skirt_speed","min_skirt_length", "skirt_distance", "skirt_start_angle", + "brim_width", "brim_object_gap", "brim_flow_ratio", "brim_use_efc_outline", "combine_brims", "brim_type", "nozzle_diameter", "single_extruder_multi_material", "preferred_orientation", + "enable_prime_tower", "wipe_tower_x", "wipe_tower_y", "prime_tower_width", "prime_tower_brim_width", "prime_tower_skip_points", "prime_tower_enable_framework", + "prime_tower_infill_gap", "prime_volume", + "extruder_colour", "filament_colour", "filament_type", "filament_is_support", "material_colour", "printable_height", "extruder_printable_height", "printer_model", "printer_technology", + // These values are necessary to construct SlicingParameters by the Canvas3D variable layer height editor. + "layer_height", "initial_layer_print_height", "min_layer_height", "max_layer_height", + "wall_loops", "outer_wall_filament_id", "inner_wall_filament_id", "sparse_infill_density", "sparse_infill_filament_id", "top_shell_layers", + "enable_support", "support_filament", "support_interface_filament", + "support_top_z_distance", "support_bottom_z_distance", "raft_layers", + "wipe_tower_rotation_angle", "wipe_tower_cone_angle", "wipe_tower_extra_spacing", "wipe_tower_extra_flow", "wipe_tower_max_purge_speed", + "wipe_tower_wall_type", "wipe_tower_extra_rib_length","wipe_tower_rib_width","wipe_tower_fillet_wall", + "wipe_tower_filament", + "best_object_pos", "master_extruder_id" + })) , sidebar(new Sidebar(q)) , notification_manager(std::make_unique(q)) , m_worker{q, std::make_unique(notification_manager.get()), "ui_worker"} @@ -7412,7 +7356,7 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) , m_job_prepare_state(Job::JobPrepareState::PREPARE_STATE_DEFAULT) , delayed_scene_refresh(false) , collapse_toolbar(GLToolbar::Normal, "Collapse") - // BBS :partplatelist construction + //BBS :partplatelist construction , partplate_list(this->q, &model) { m_is_dark = wxGetApp().app_config->get("dark_color_mode") == "1"; @@ -7427,21 +7371,21 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) if (disable_wayland_floating) m_aui_mgr.SetFlags(m_aui_mgr.GetFlags() & ~wxAUI_MGR_ALLOW_FLOATING); #endif - // m_aui_mgr.GetArtProvider()->SetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE, 0); - // m_aui_mgr.GetArtProvider()->SetMetric(wxAUI_DOCKART_SASH_SIZE, 2); + //m_aui_mgr.GetArtProvider()->SetMetric(wxAUI_DOCKART_PANE_BORDER_SIZE, 0); + //m_aui_mgr.GetArtProvider()->SetMetric(wxAUI_DOCKART_SASH_SIZE, 2); m_aui_mgr.GetArtProvider()->SetMetric(wxAUI_DOCKART_CAPTION_SIZE, 18); m_aui_mgr.GetArtProvider()->SetMetric(wxAUI_DOCKART_GRADIENT_TYPE, wxAUI_GRADIENT_NONE); this->q->SetFont(Slic3r::GUI::wxGetApp().normal_font()); - // BBS: use the first partplate's print for background process + //BBS: use the first partplate's print for background process partplate_list.update_slice_context_to_current_plate(background_process); /* background_process.set_fff_print(&fff_print); background_process.set_sla_print(&sla_print); background_process.set_gcode_result(&gcode_result); - background_process.set_thumbnail_cb([this](const ThumbnailsParams& params) { return this->generate_thumbnails(params, - Camera::EType::Ortho); }); background_process.set_slicing_completed_event(EVT_SLICING_COMPLETED); + background_process.set_thumbnail_cb([this](const ThumbnailsParams& params) { return this->generate_thumbnails(params, Camera::EType::Ortho); }); + background_process.set_slicing_completed_event(EVT_SLICING_COMPLETED); background_process.set_finished_event(EVT_PROCESS_COMPLETED); background_process.set_export_began_event(EVT_EXPORT_BEGAN); // Default printer technology for default config. @@ -7455,8 +7399,7 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) sla_print.set_status_callback(statuscb); */ // BBS: to be checked. Not follow patch. - background_process.set_thumbnail_cb( - [this](const ThumbnailsParams& params) { return this->generate_thumbnails(params, Camera::EType::Ortho); }); + background_process.set_thumbnail_cb([this](const ThumbnailsParams& params) { return this->generate_thumbnails(params, Camera::EType::Ortho); }); background_process.set_slicing_completed_event(EVT_SLICING_COMPLETED); background_process.set_finished_event(EVT_PROCESS_COMPLETED); background_process.set_export_began_event(EVT_EXPORT_BEGAN); @@ -7479,17 +7422,16 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) main_frame->m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGING, &priv::on_tab_selection_changing, this); auto* panel_3d = new wxPanel(q); - view3D = new View3D(panel_3d, bed, &model, config, &background_process); - // BBS: use partplater's gcode - preview = new Preview(panel_3d, bed, &model, config, &background_process, partplate_list.get_current_slice_result(), - [this]() { schedule_background_process(); }); + view3D = new View3D(panel_3d, bed, &model, config, &background_process); + //BBS: use partplater's gcode + preview = new Preview(panel_3d, bed, &model, config, &background_process, partplate_list.get_current_slice_result(), [this]() { schedule_background_process(); }); assemble_view = new AssembleView(panel_3d, bed, &model, config, &background_process); #ifdef __APPLE__ // BBS // set default view_toolbar icons size equal to GLGizmosManager::Default_Icons_Size - // view_toolbar.set_icons_size(GLGizmosManager::Default_Icons_Size); + //view_toolbar.set_icons_size(GLGizmosManager::Default_Icons_Size); #endif // __APPLE__ panels.push_back(view3D); @@ -7498,7 +7440,8 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) this->background_process_timer.SetOwner(this->q, 0); this->auto_reslice_timer.SetOwner(this->q, 0); - this->q->Bind(wxEVT_TIMER, [this](wxTimerEvent& evt) { + this->q->Bind(wxEVT_TIMER, [this](wxTimerEvent &evt) + { if (&evt.GetTimer() == &this->background_process_timer) { if (!this->suppressed_backround_processing_update) this->update_restart_background_process(false, false); @@ -7513,8 +7456,13 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) update(); // Orca: Make sidebar dockable - m_aui_mgr.AddPane(sidebar, wxAuiPaneInfo().Name("sidebar").Left().CloseButton(false).TopDockable(false).BottomDockable(false).BestSize( - wxSize(39 * wxGetApp().em_unit(), 90 * wxGetApp().em_unit()))); + m_aui_mgr.AddPane(sidebar, wxAuiPaneInfo() + .Name("sidebar") + .Left() + .CloseButton(false) + .TopDockable(false) + .BottomDockable(false) + .BestSize(wxSize(39 * wxGetApp().em_unit(), 90 * wxGetApp().em_unit()))); auto* panel_sizer = new wxBoxSizer(wxHORIZONTAL); panel_sizer->Add(view3D, 1, wxEXPAND | wxALL, 0); @@ -7529,8 +7477,8 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) auto& sidebar = m_aui_mgr.GetPane(this->sidebar); // Load previous window layout - const auto cfg = wxGetApp().app_config; - wxString layout = wxString::FromUTF8(cfg->get("window_layout")); + const auto cfg = wxGetApp().app_config; + wxString layout = wxString::FromUTF8(cfg->get("window_layout")); if (!layout.empty()) { bool removed_floating_state = false; #ifdef __WXGTK__ @@ -7564,6 +7512,7 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) menus.init(main_frame); + // Events: if (wxGetApp().is_editor()) { @@ -7575,14 +7524,15 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) // jump to found option from SearchDialog q->Bind(wxCUSTOMEVT_JUMP_TO_OPTION, [this](wxCommandEvent& evt) { sidebar->jump_to_option(evt.GetInt()); }); q->Bind(wxCUSTOMEVT_JUMP_TO_OBJECT, [this](wxCommandEvent& evt) { - auto client_data = evt.GetClientData(); + auto client_data = evt.GetClientData(); ObjectDataViewModelNode* data = static_cast(client_data); sidebar->jump_to_object(data); - }); + } + ); } wxGLCanvas* view3D_canvas = view3D->get_wxglcanvas(); - // BBS: GUI refactor + //BBS: GUI refactor wxGLCanvas* preview_canvas = preview->get_wxglcanvas(); if (wxGetApp().is_editor()) { @@ -7590,34 +7540,30 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) view3D_canvas->Bind(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS, [this](SimpleEvent&) { delayed_error_message.clear(); this->background_process_timer.Start(500, wxTIMER_ONE_SHOT); - }); + }); view3D_canvas->Bind(EVT_GLCANVAS_OBJECT_SELECT, &priv::on_object_select, this); view3D_canvas->Bind(EVT_GLCANVAS_RIGHT_CLICK, &priv::on_right_click, this); - // BBS: add part plate related logic + //BBS: add part plate related logic view3D_canvas->Bind(EVT_GLCANVAS_PLATE_RIGHT_CLICK, &priv::on_plate_right_click, this); view3D_canvas->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); }); view3D_canvas->Bind(EVT_GLCANVAS_ARRANGE, [this](SimpleEvent& evt) { - // BBS arrange from EVT set default state. + //BBS arrange from EVT set default state. this->q->set_prepare_state(Job::PREPARE_STATE_DEFAULT); - this->q->arrange(); - }); + this->q->arrange(); }); view3D_canvas->Bind(EVT_GLCANVAS_ARRANGE_PARTPLATE, [this](SimpleEvent& evt) { - // BBS arrange from EVT set default state. + //BBS arrange from EVT set default state. this->q->set_prepare_state(Job::PREPARE_STATE_MENU); - this->q->arrange(); - }); + this->q->arrange(); }); view3D_canvas->Bind(EVT_GLCANVAS_ORIENT, [this](SimpleEvent& evt) { - // BBS orient from EVT set default state. + //BBS orient from EVT set default state. this->q->set_prepare_state(Job::PREPARE_STATE_DEFAULT); - this->q->orient(); - }); + this->q->orient(); }); view3D_canvas->Bind(EVT_GLCANVAS_ORIENT_PARTPLATE, [this](SimpleEvent& evt) { - // BBS orient from EVT set default state. + //BBS orient from EVT set default state. this->q->set_prepare_state(Job::PREPARE_STATE_MENU); - this->q->orient(); - }); - // BBS - view3D_canvas->Bind(EVT_GLCANVAS_SELECT_CURR_PLATE_ALL, [this](SimpleEvent&) { this->q->select_curr_plate_all(); }); + this->q->orient(); }); + //BBS + view3D_canvas->Bind(EVT_GLCANVAS_SELECT_CURR_PLATE_ALL, [this](SimpleEvent&) {this->q->select_curr_plate_all(); }); view3D_canvas->Bind(EVT_GLCANVAS_PRINTABLE, [this](SimpleEvent& evt) { this->sidebar->obj_list()->toggle_printable_state(); }); view3D_canvas->Bind(EVT_GLCANVAS_SELECT_ALL, [this](SimpleEvent&) { this->q->select_all(); }); @@ -7626,18 +7572,14 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) if (this->q->is_view3D_shown()) wxGetApp().open_speed_dial(); }); - view3D_canvas->Bind(EVT_GLCANVAS_INCREASE_INSTANCES, [this](Event& evt) { - if (evt.data == 1) - this->q->increase_instances(); - else if (this->can_decrease_instances()) - this->q->decrease_instances(); - }); + view3D_canvas->Bind(EVT_GLCANVAS_INCREASE_INSTANCES, [this](Event& evt) + { if (evt.data == 1) this->q->increase_instances(); else if (this->can_decrease_instances()) this->q->decrease_instances(); }); view3D_canvas->Bind(EVT_GLCANVAS_INSTANCE_MOVED, [this](SimpleEvent&) { update(); }); view3D_canvas->Bind(EVT_GLCANVAS_FORCE_UPDATE, [this](SimpleEvent&) { update(); }); view3D_canvas->Bind(EVT_GLCANVAS_INSTANCE_ROTATED, [this](SimpleEvent&) { update(); }); view3D_canvas->Bind(EVT_GLCANVAS_INSTANCE_SCALED, [this](SimpleEvent&) { update(); }); // BBS - // view3D_canvas->Bind(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, [this](Event& evt) { this->sidebar->enable_buttons(evt.data); }); + //view3D_canvas->Bind(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, [this](Event& evt) { this->sidebar->enable_buttons(evt.data); }); view3D_canvas->Bind(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, [this](Event& evt) { on_slice_button_status(evt.data); }); view3D_canvas->Bind(EVT_GLCANVAS_UPDATE_GEOMETRY, &priv::on_update_geometry, this); view3D_canvas->Bind(EVT_GLCANVAS_MOUSE_DRAGGING_STARTED, &priv::on_3dcanvas_mouse_dragging_started, this); @@ -7646,89 +7588,83 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) view3D_canvas->Bind(EVT_GLCANVAS_RESETGIZMOS, [this](SimpleEvent&) { reset_all_gizmos(); }); view3D_canvas->Bind(EVT_GLCANVAS_UNDO, [this](SimpleEvent&) { this->undo(); }); view3D_canvas->Bind(EVT_GLCANVAS_REDO, [this](SimpleEvent&) { this->redo(); }); - view3D_canvas->Bind(EVT_GLCANVAS_COLLAPSE_SIDEBAR, - [this](SimpleEvent&) { this->q->collapse_sidebar(!this->q->is_sidebar_collapsed()); }); - view3D_canvas->Bind(EVT_GLCANVAS_RESET_LAYER_HEIGHT_PROFILE, - [this](SimpleEvent&) { this->view3D->get_canvas3d()->reset_layer_height_profile(); }); - view3D_canvas->Bind(EVT_GLCANVAS_ADAPTIVE_LAYER_HEIGHT_PROFILE, - [this](Event& evt) { this->view3D->get_canvas3d()->adaptive_layer_height_profile(evt.data); }); - view3D_canvas->Bind(EVT_GLCANVAS_SMOOTH_LAYER_HEIGHT_PROFILE, - [this](HeightProfileSmoothEvent& evt) { this->view3D->get_canvas3d()->smooth_layer_height_profile(evt.data); }); + view3D_canvas->Bind(EVT_GLCANVAS_COLLAPSE_SIDEBAR, [this](SimpleEvent&) { this->q->collapse_sidebar(!this->q->is_sidebar_collapsed()); }); + view3D_canvas->Bind(EVT_GLCANVAS_RESET_LAYER_HEIGHT_PROFILE, [this](SimpleEvent&) { this->view3D->get_canvas3d()->reset_layer_height_profile(); }); + view3D_canvas->Bind(EVT_GLCANVAS_ADAPTIVE_LAYER_HEIGHT_PROFILE, [this](Event& evt) { this->view3D->get_canvas3d()->adaptive_layer_height_profile(evt.data); }); + view3D_canvas->Bind(EVT_GLCANVAS_SMOOTH_LAYER_HEIGHT_PROFILE, [this](HeightProfileSmoothEvent& evt) { this->view3D->get_canvas3d()->smooth_layer_height_profile(evt.data); }); view3D_canvas->Bind(EVT_GLCANVAS_RELOAD_FROM_DISK, [this](SimpleEvent&) { this->reload_all_from_disk(); }); // 3DScene/Toolbar: view3D_canvas->Bind(EVT_GLTOOLBAR_ADD, &priv::on_action_add, this); view3D_canvas->Bind(EVT_GLTOOLBAR_DELETE, [q](SimpleEvent&) { q->remove_selected(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_DELETE_ALL, [this](SimpleEvent&) { delete_all_objects_from_model(); }); - // view3D_canvas->Bind(EVT_GLTOOLBAR_DELETE_ALL, [q](SimpleEvent&) { q->reset_with_confirm(); }); +// view3D_canvas->Bind(EVT_GLTOOLBAR_DELETE_ALL, [q](SimpleEvent&) { q->reset_with_confirm(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_ADD_PLATE, &priv::on_action_add_plate, this); view3D_canvas->Bind(EVT_GLTOOLBAR_DEL_PLATE, &priv::on_action_del_plate, this); view3D_canvas->Bind(EVT_GLTOOLBAR_ORIENT, [this](SimpleEvent&) { - // BBS arrange from EVT set default state. + //BBS arrange from EVT set default state. this->q->set_prepare_state(Job::PREPARE_STATE_DEFAULT); - this->q->orient(); - }); + this->q->orient(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_ARRANGE, [this](SimpleEvent&) { - // BBS arrange from EVT set default state. + //BBS arrange from EVT set default state. this->q->set_prepare_state(Job::PREPARE_STATE_DEFAULT); this->q->arrange(); - }); + }); view3D_canvas->Bind(EVT_GLTOOLBAR_CUT, [q](SimpleEvent&) { q->cut_selection_to_clipboard(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_COPY, [q](SimpleEvent&) { q->copy_selection_to_clipboard(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_PASTE, [q](SimpleEvent&) { q->paste_from_clipboard(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_LAYERSEDITING, &priv::on_action_layersediting, this); - // BBS: add clone + //BBS: add clone view3D_canvas->Bind(EVT_GLTOOLBAR_CLONE, [q](SimpleEvent&) { q->clone_selection(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_MORE, [q](SimpleEvent&) { q->increase_instances(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_FEWER, [q](SimpleEvent&) { q->decrease_instances(); }); view3D_canvas->Bind(EVT_GLTOOLBAR_SPLIT_OBJECTS, &priv::on_action_split_objects, this); view3D_canvas->Bind(EVT_GLTOOLBAR_SPLIT_VOLUMES, &priv::on_action_split_volumes, this); - // BBS: GUI refactor: GLToolbar + //BBS: GUI refactor: GLToolbar view3D_canvas->Bind(EVT_GLTOOLBAR_OPEN_PROJECT, &priv::on_action_open_project, this); - // view3D_canvas->Bind(EVT_GLTOOLBAR_SLICE_PLATE, &priv::on_action_slice_plate, this); - // view3D_canvas->Bind(EVT_GLTOOLBAR_SLICE_ALL, &priv::on_action_slice_all, this); - // view3D_canvas->Bind(EVT_GLTOOLBAR_PRINT_PLATE, &priv::on_action_print_plate, this); - // view3D_canvas->Bind(EVT_GLTOOLBAR_PRINT_ALL, &priv::on_action_print_all, this); - // view3D_canvas->Bind(EVT_GLTOOLBAR_EXPORT_GCODE, &priv::on_action_export_gcode, this); + //view3D_canvas->Bind(EVT_GLTOOLBAR_SLICE_PLATE, &priv::on_action_slice_plate, this); + //view3D_canvas->Bind(EVT_GLTOOLBAR_SLICE_ALL, &priv::on_action_slice_all, this); + //view3D_canvas->Bind(EVT_GLTOOLBAR_PRINT_PLATE, &priv::on_action_print_plate, this); + //view3D_canvas->Bind(EVT_GLTOOLBAR_PRINT_ALL, &priv::on_action_print_all, this); + //view3D_canvas->Bind(EVT_GLTOOLBAR_EXPORT_GCODE, &priv::on_action_export_gcode, this); view3D_canvas->Bind(EVT_GLVIEWTOOLBAR_ASSEMBLE, [q](SimpleEvent&) { q->select_view_3D("Assemble"); }); - // preview also send these events - // preview_canvas->Bind(EVT_GLTOOLBAR_SLICE_PLATE, &priv::on_action_slice_plate, this); - // preview_canvas->Bind(EVT_GLTOOLBAR_PRINT_PLATE, &priv::on_action_print_plate, this); - // preview_canvas->Bind(EVT_GLTOOLBAR_PRINT_ALL, &priv::on_action_print_all, this); - // review_canvas->Bind(EVT_GLTOOLBAR_EXPORT_GCODE, &priv::on_action_export_gcode, this); + //preview also send these events + //preview_canvas->Bind(EVT_GLTOOLBAR_SLICE_PLATE, &priv::on_action_slice_plate, this); + //preview_canvas->Bind(EVT_GLTOOLBAR_PRINT_PLATE, &priv::on_action_print_plate, this); + //preview_canvas->Bind(EVT_GLTOOLBAR_PRINT_ALL, &priv::on_action_print_all, this); + //review_canvas->Bind(EVT_GLTOOLBAR_EXPORT_GCODE, &priv::on_action_export_gcode, this); view3D_canvas->Bind(EVT_GLCANVAS_SWITCH_TO_OBJECT, [main_frame](SimpleEvent&) { - if (main_frame->m_param_panel) { - main_frame->m_param_panel->switch_to_object(false); - } - }); + if (main_frame->m_param_panel) { + main_frame->m_param_panel->switch_to_object(false); + } + }); view3D_canvas->Bind(EVT_GLCANVAS_SWITCH_TO_GLOBAL, [main_frame](SimpleEvent&) { - if (main_frame->m_param_panel) { - main_frame->m_param_panel->switch_to_global(); - } - }); + if (main_frame->m_param_panel) { + main_frame->m_param_panel->switch_to_global(); + } + }); } view3D_canvas->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [q](SimpleEvent&) { q->set_bed_shape(); }); // Preview events: preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_QUESTION_MARK, [](SimpleEvent&) { wxGetApp().keyboard_shortcuts(); }); preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [q](SimpleEvent&) { q->set_bed_shape(); }); - preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_UPDATE, [this](SimpleEvent&) { preview->get_canvas3d()->set_as_dirty(); }); + preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_UPDATE, [this](SimpleEvent &) { + preview->get_canvas3d()->set_as_dirty(); + }); if (wxGetApp().is_editor()) { preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_TAB, [this](SimpleEvent&) { select_next_view_3D(); }); - preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_COLLAPSE_SIDEBAR, - [this](SimpleEvent&) { this->q->collapse_sidebar(!this->q->is_sidebar_collapsed()); }); + preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_COLLAPSE_SIDEBAR, [this](SimpleEvent&) { this->q->collapse_sidebar(!this->q->is_sidebar_collapsed()); }); preview->get_wxglcanvas()->Bind(EVT_CUSTOMEVT_TICKSCHANGED, [this](wxCommandEvent& event) { - Type tick_event_type = (Type) event.GetInt(); - Model& model = wxGetApp().plater()->model(); - // BBS: replace model custom gcode with current plate custom gcode - model.plates_custom_gcodes[model.curr_plate_index] = - preview->get_canvas3d()->get_gcode_viewer().get_layers_slider()->GetTicksValues(); + Type tick_event_type = (Type)event.GetInt(); + Model& model = wxGetApp().plater()->model(); + //BBS: replace model custom gcode with current plate custom gcode + model.plates_custom_gcodes[model.curr_plate_index] = preview->get_canvas3d()->get_gcode_viewer().get_layers_slider()->GetTicksValues(); // BBS set to invalid state only - if (tick_event_type == Type::ToolChange || tick_event_type == Type::Custom || tick_event_type == Type::Template || - tick_event_type == Type::PausePrint) { - PartPlate* plate = this->q->get_partplate_list().get_curr_plate(); + if (tick_event_type == Type::ToolChange || tick_event_type == Type::Custom || tick_event_type == Type::Template || tick_event_type == Type::PausePrint) { + PartPlate *plate = this->q->get_partplate_list().get_curr_plate(); if (plate) { plate->update_slice_result_valid_state(false); } @@ -7745,7 +7681,7 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) if (wxGetApp().is_gcode_viewer()) preview->Bind(EVT_GLCANVAS_RELOAD_FROM_DISK, [this](SimpleEvent&) { this->q->reload_gcode_from_disk(); }); - // BBS + //BBS wxGLCanvas* assemble_canvas = assemble_view->get_wxglcanvas(); if (wxGetApp().is_editor()) { assemble_canvas->Bind(EVT_GLTOOLBAR_FILLCOLOR, [q](IntEvent& evt) { q->fill_color(evt.get_data()); }); @@ -7763,7 +7699,7 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) q->Bind(EVT_EXPORT_BEGAN, &priv::on_export_began, this); q->Bind(EVT_EXPORT_FINISHED, &priv::on_export_finished, this); q->Bind(EVT_GLVIEWTOOLBAR_3D, [q](SimpleEvent&) { q->select_view_3D("3D"); }); - // BBS: set on_slice to false + //BBS: set on_slice to false q->Bind(EVT_GLVIEWTOOLBAR_PREVIEW, [q](SimpleEvent&) { q->select_view_3D("Preview", false); }); q->Bind(EVT_GLTOOLBAR_SLICE_PLATE, &priv::on_action_slice_plate, this); q->Bind(EVT_GLTOOLBAR_SLICE_ALL, &priv::on_action_slice_all, this); @@ -7784,14 +7720,14 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) q->Bind(EVT_PRINT_FINISHED, [q](wxCommandEvent& evt) { q->print_job_finished(evt); }); q->Bind(EVT_SEND_CALIBRATION_FINISHED, [q](wxCommandEvent& evt) { q->send_calibration_job_finished(evt); }); q->Bind(EVT_SEND_FINISHED, [q](wxCommandEvent& evt) { q->send_job_finished(evt); }); - q->Bind(EVT_PUBLISH_FINISHED, [q](wxCommandEvent& evt) { q->publish_job_finished(evt); }); - q->Bind(EVT_OPEN_PLATESETTINGSDIALOG, [q](wxCommandEvent& evt) { q->open_platesettings_dialog(evt); }); - q->Bind(EVT_OPEN_FILAMENT_MAP_SETTINGS_DIALOG, [q](wxCommandEvent& evt) { q->open_filament_map_setting_dialog(evt); }); - // q->Bind(EVT_GLVIEWTOOLBAR_ASSEMBLE, [q](SimpleEvent&) { q->select_view_3D("Assemble"); }); + q->Bind(EVT_PUBLISH_FINISHED, [q](wxCommandEvent& evt) { q->publish_job_finished(evt);}); + q->Bind(EVT_OPEN_PLATESETTINGSDIALOG, [q](wxCommandEvent& evt) { q->open_platesettings_dialog(evt);}); + q->Bind(EVT_OPEN_FILAMENT_MAP_SETTINGS_DIALOG, [q](wxCommandEvent &evt) { q->open_filament_map_setting_dialog(evt); }); + //q->Bind(EVT_GLVIEWTOOLBAR_ASSEMBLE, [q](SimpleEvent&) { q->select_view_3D("Assemble"); }); } // Drop target: - q->SetDropTarget(new PlaterDropTarget(*main_frame, *q)); // if my understanding is right, wxWindow takes the owenership + q->SetDropTarget(new PlaterDropTarget(*main_frame, *q)); // if my understanding is right, wxWindow takes the owenership q->Layout(); apply_color_mode(); @@ -7817,41 +7753,43 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) // Register an USB HID (Human Interface Device) attach event. evt contains Win32 path to the USB device containing VID, PID and other info. // This event wakes up the Mouse3DController's background thread to enumerate HID devices, if the VID of the callback event // is one of the 3D Mouse vendors (3DConnexion or Logitech). - this->q->Bind(EVT_HID_DEVICE_ATTACHED, [this](HIDDeviceAttachedEvent& evt) { mouse3d_controller.device_attached(evt.data); }); - this->q->Bind(EVT_HID_DEVICE_DETACHED, [this](HIDDeviceAttachedEvent& evt) { mouse3d_controller.device_detached(evt.data); }); + this->q->Bind(EVT_HID_DEVICE_ATTACHED, [this](HIDDeviceAttachedEvent &evt) { + mouse3d_controller.device_attached(evt.data); + }); + this->q->Bind(EVT_HID_DEVICE_DETACHED, [this](HIDDeviceAttachedEvent& evt) { + mouse3d_controller.device_detached(evt.data); + }); #endif /* _WIN32 */ - // notification_manager = new NotificationManager(this->q); + //notification_manager = new NotificationManager(this->q); if (wxGetApp().is_editor()) { this->q->Bind(EVT_EJECT_DRIVE_NOTIFICAION_CLICKED, [this](EjectDriveNotificationClickedEvent&) { this->q->eject_drive(); }); this->q->Bind(EVT_EXPORT_GCODE_NOTIFICAION_CLICKED, [this](ExportGcodeNotificationClickedEvent&) { this->q->export_gcode(true); }); - this->q->Bind(EVT_PRESET_UPDATE_AVAILABLE_CLICKED, - [](PresetUpdateAvailableClickedEvent&) { wxGetApp().get_preset_updater()->on_update_notification_confirm(); }); + this->q->Bind(EVT_PRESET_UPDATE_AVAILABLE_CLICKED, [](PresetUpdateAvailableClickedEvent&) { wxGetApp().get_preset_updater()->on_update_notification_confirm(); }); this->q->Bind(EVT_PRINTER_CONFIG_UPDATE_AVAILABLE_CLICKED, [](PrinterConfigUpdateAvailableClickedEvent&) { wxGetApp().get_preset_updater()->do_printer_config_update(); - wxGetApp().getDeviceManager()->reload_printer_settings(); - }); + wxGetApp().getDeviceManager()->reload_printer_settings(); }); /* BBS do not handle removeable driver event */ - this->q->Bind(EVT_REMOVABLE_DRIVE_EJECTED, [this](RemovableDriveEjectEvent& evt) { + this->q->Bind(EVT_REMOVABLE_DRIVE_EJECTED, [this](RemovableDriveEjectEvent &evt) { if (evt.data.second) { // BBS - // this->show_action_buttons(this->ready_to_slice); + //this->show_action_buttons(this->ready_to_slice); notification_manager->close_notification_of_type(NotificationType::ExportFinished); - notification_manager->push_notification( - NotificationType::CustomNotification, NotificationManager::NotificationLevel::RegularNotificationLevel, - format(_L("Successfully unmounted. The device %s (%s) can now be safely removed from the computer."), - evt.data.first.name, evt.data.first.path)); + notification_manager->push_notification(NotificationType::CustomNotification, + NotificationManager::NotificationLevel::RegularNotificationLevel, + format(_L("Successfully unmounted. The device %s (%s) can now be safely removed from the computer."), evt.data.first.name, evt.data.first.path) + ); } else { notification_manager->push_notification(NotificationType::CustomNotification, NotificationManager::NotificationLevel::ErrorNotificationLevel, - format(_L("Ejecting of device %s (%s) has failed."), evt.data.first.name, - evt.data.first.path)); + format(_L("Ejecting of device %s (%s) has failed."), evt.data.first.name, evt.data.first.path) + ); } }); - this->q->Bind(EVT_REMOVABLE_DRIVES_CHANGED, [this](RemovableDrivesChangedEvent&) { + this->q->Bind(EVT_REMOVABLE_DRIVES_CHANGED, [this](RemovableDrivesChangedEvent &) { // BBS - // this->show_action_buttons(this->ready_to_slice); + //this->show_action_buttons(this->ready_to_slice); // Close notification ExportingFinished but only if last export was to removable notification_manager->device_ejected(); }); @@ -7865,12 +7803,12 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) } // Initialize the Undo / Redo stack with a first snapshot. - // this->take_snapshot("New Project", UndoRedo::SnapshotType::ProjectSeparator); + //this->take_snapshot("New Project", UndoRedo::SnapshotType::ProjectSeparator); // Reset the "dirty project" flag. m_undo_redo_stack_main.mark_current_as_saved(); dirty_state.update_from_undo_redo_stack(false); - // this->take_snapshot("New Project"); - // BBS: save project confirm + //this->take_snapshot("New Project"); + // BBS: save project confirm up_to_date(true, false); up_to_date(true, true); model.set_need_backup(); @@ -7882,9 +7820,7 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) std::string last_backup = last; std::string originfile; if (Slic3r::has_restore_data(last_backup, originfile)) { - auto result = MessageDialog(this->q, _L("Previously unsaved items have been detected. Do you want to restore them\?"), - wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Restore"), wxYES_NO | wxYES_DEFAULT | wxCENTRE) - .ShowModal(); + auto result = MessageDialog(this->q, _L("Previously unsaved items have been detected. Do you want to restore them\?"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Restore"), wxYES_NO | wxYES_DEFAULT | wxCENTRE).ShowModal(); if (result == wxID_YES) { this->q->load_project(from_path(last_backup), from_path(originfile)); Slic3r::backup_soon(); @@ -7898,13 +7834,13 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) } catch (...) {} - + if (this->q->get_project_filename().IsEmpty() && this->q->is_empty_project()) { int skip_confirm = e.GetInt(); this->q->new_project(skip_confirm, true); } }); - // wxPostEvent(this->q, wxCommandEvent{EVT_RESTORE_PROJECT}); + //wxPostEvent(this->q, wxCommandEvent{EVT_RESTORE_PROJECT}); } this->q->Bind(EVT_LOAD_MODEL_OTHER_INSTANCE, [this](LoadFromOtherInstanceEvent& evt) { @@ -7917,7 +7853,7 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) wxGetApp().mainframe->Raise(); this->q->load_files(input_files); }); - + this->q->Bind(EVT_START_DOWNLOAD_OTHER_INSTANCE, [](StartDownloadOtherInstanceEvent& evt) { BOOST_LOG_TRIVIAL(trace) << "Received url from other instance event."; wxGetApp().mainframe->Show(); @@ -7925,12 +7861,15 @@ Plater::priv::priv(Plater* q, MainFrame* main_frame) for (size_t i = 0; i < evt.data.size(); ++i) { wxGetApp().start_download(evt.data[i]); } + + }); + this->q->Bind(EVT_INSTANCE_GO_TO_FRONT, [this](InstanceGoToFrontEvent &) { + bring_instance_forward(); }); - this->q->Bind(EVT_INSTANCE_GO_TO_FRONT, [this](InstanceGoToFrontEvent&) { bring_instance_forward(); }); wxGetApp().other_instance_message_handler()->init(this->q); // collapse sidebar according to saved value - // if (wxGetApp().is_editor()) { + //if (wxGetApp().is_editor()) { // bool is_collapsed = wxGetApp().app_config->get("collapsed_sidebar") == "1"; // sidebar->collapse(is_collapsed); //} @@ -7955,18 +7894,16 @@ void Plater::priv::update(unsigned int flags) model.center_instances_around_point(this->bed.build_volume().bed_center()); #endif - unsigned int update_status = 0; - const bool force_background_processing_restart = this->printer_technology == ptSLA || - (flags & (unsigned int) UpdateParams::FORCE_BACKGROUND_PROCESSING_UPDATE); + unsigned int update_status = 0; + const bool force_background_processing_restart = this->printer_technology == ptSLA || (flags & (unsigned int)UpdateParams::FORCE_BACKGROUND_PROCESSING_UPDATE); if (force_background_processing_restart) // Update the SLAPrint from the current Model, so that the reload_scene() // pulls the correct data. - update_status = this->update_background_process(false, flags & (unsigned int) UpdateParams::POSTPONE_VALIDATION_ERROR_MESSAGE); - // BBS TODO reload_scene - this->view3D->reload_scene(false, flags & (unsigned int) UpdateParams::FORCE_FULL_SCREEN_REFRESH); - if (is_preview_shown()) - this->preview->reload_print(); - // BBS assemble view + update_status = this->update_background_process(false, flags & (unsigned int)UpdateParams::POSTPONE_VALIDATION_ERROR_MESSAGE); + //BBS TODO reload_scene + this->view3D->reload_scene(false, flags & (unsigned int)UpdateParams::FORCE_FULL_SCREEN_REFRESH); + if (is_preview_shown()) this->preview->reload_print(); + //BBS assemble view this->assemble_view->reload_scene(false, flags); // todo: better to mark thumbnail dirty here @@ -7992,23 +7929,25 @@ void Plater::priv::select_view(const std::string& direction) BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "select view3D"; view3D->select_view(direction); wxGetApp().update_ui_from_settings(); - } else if (current_panel == preview) { + } + else if (current_panel == preview) { BOOST_LOG_TRIVIAL(info) << "select preview"; preview->select_view(direction); wxGetApp().update_ui_from_settings(); - } else if (current_panel == assemble_view) { + } + else if (current_panel == assemble_view) { BOOST_LOG_TRIVIAL(info) << "select assemble view"; assemble_view->select_view(direction); } } -const VendorProfile::PrinterModel* Plater::get_curr_printer_model() +const VendorProfile::PrinterModel *Plater::get_curr_printer_model() { auto bundle = wxGetApp().preset_bundle; if (bundle) { - const Preset* curr = &bundle->printers.get_selected_preset(); + const Preset *curr = &bundle->printers.get_selected_preset(); if (curr) { - const VendorProfile::PrinterModel* pm = PresetUtils::system_printer_model(*curr); + const VendorProfile::PrinterModel *pm = PresetUtils::system_printer_model(*curr); if (!pm) { auto curr_parent = bundle->printers.get_selected_preset_parent(); if (curr_parent) { @@ -8048,9 +7987,9 @@ std::map Plater::get_bed_texture_maps() bool Plater::get_enable_wrapping_detection() { - const DynamicPrintConfig& print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config; - const ConfigOptionBool* wrapping_detection = print_config.option("enable_wrapping_detection"); - return (wrapping_detection != nullptr) && wrapping_detection->value; + const DynamicPrintConfig & print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config; + const ConfigOptionBool * wrapping_detection = print_config.option("enable_wrapping_detection"); + return (wrapping_detection != nullptr) && wrapping_detection->value; } wxColour Plater::get_next_color_for_filament() @@ -8059,9 +7998,22 @@ wxColour Plater::get_next_color_for_filament() // refs to https://www.ebaomonthly.com/window/photo/lesson/colorList.htm wxColour colors[FILAMENT_SYSTEM_COLORS_NUM] = { // ORCA updated all color palette - wxColour("#00C1AE"), wxColour("#F4E2C1"), wxColour("#ED1C24"), wxColour("#00FF7F"), wxColour("#F26722"), wxColour("#FFEB31"), - wxColour("#7841CE"), wxColour("#115877"), wxColour("#ED1E79"), wxColour("#2EBDEF"), wxColour("#345B2F"), wxColour("#800080"), - wxColour("#FA8173"), wxColour("#800000"), wxColour("#F7B763"), wxColour("#A4C41E"), + wxColour("#00C1AE"), + wxColour("#F4E2C1"), + wxColour("#ED1C24"), + wxColour("#00FF7F"), + wxColour("#F26722"), + wxColour("#FFEB31"), + wxColour("#7841CE"), + wxColour("#115877"), + wxColour("#ED1E79"), + wxColour("#2EBDEF"), + wxColour("#345B2F"), + wxColour("#800080"), + wxColour("#FA8173"), + wxColour("#800000"), + wxColour("#F7B763"), + wxColour("#A4C41E"), }; return colors[curr_color_filamenet++ % FILAMENT_SYSTEM_COLORS_NUM]; } @@ -8069,25 +8021,22 @@ wxColour Plater::get_next_color_for_filament() wxString Plater::get_slice_warning_string(GCodeProcessorResult::SliceWarning& warning) { if (warning.msg == BED_TEMP_TOO_HIGH_THAN_FILAMENT) { - return _L("The current heatbed temperature is relatively high. The nozzle may clog when printing this filament in a closed " - "environment. Please open the front door and/or remove the upper glass."); + return _L("The current heatbed temperature is relatively high. The nozzle may clog when printing this filament in a closed environment. Please open the front door and/or remove the upper glass."); } else if (warning.msg == NOZZLE_HRC_CHECKER) { - return _L("The nozzle hardness required by the filament is higher than the default nozzle hardness of the printer. Please replace " - "the hardened nozzle or filament, otherwise, the nozzle will be worn down or damaged."); + return _L("The nozzle hardness required by the filament is higher than the default nozzle hardness of the printer. Please replace the hardened nozzle or filament, otherwise, the nozzle will be worn down or damaged."); } else if (warning.msg == NOT_SUPPORT_TRADITIONAL_TIMELAPSE) { - return _L( - "Enabling traditional timelapse photography may cause surface imperfections. It is recommended to change to smooth mode."); + return _L("Enabling traditional timelapse photography may cause surface imperfections. It is recommended to change to smooth mode."); } else if (warning.msg == NOT_GENERATE_TIMELAPSE) { return wxString(); } else if (warning.msg == SMOOTH_TIMELAPSE_WITHOUT_PRIME_TOWER) { - return _L("Smooth mode for timelapse is enabled, but the prime tower is off, which may cause print defects. Please enable the " - "prime tower, re-slice and print again."); - } else { + return _L("Smooth mode for timelapse is enabled, but the prime tower is off, which may cause print defects. Please enable the prime tower, re-slice and print again."); + } + else { return wxString(warning.msg); } } -void Plater::priv::apply_free_camera_correction(bool apply /* = true*/) +void Plater::priv::apply_free_camera_correction(bool apply/* = true*/) { bool use_perspective_camera = get_config("use_perspective_camera").compare("true") == 0; if (use_perspective_camera) @@ -8098,7 +8047,7 @@ void Plater::priv::apply_free_camera_correction(bool apply /* = true*/) camera.recover_from_free_camera(); } -// BBS: add no slice option +//BBS: add no slice option void Plater::priv::select_view_3D(const std::string& name, bool no_slice) { if (name == "3D") { @@ -8107,23 +8056,25 @@ void Plater::priv::select_view_3D(const std::string& name, bool no_slice) BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("goto preview page when loading gcode/exported_3mf"); } set_current_panel(view3D, no_slice); - } else if (name == "Preview") { + } + else if (name == "Preview") { BOOST_LOG_TRIVIAL(info) << "select preview"; - // BBS update extruder params and speed table before slicing + //BBS update extruder params and speed table before slicing const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config(); - auto& print = q->get_partplate_list().get_current_fff_print(); - auto print_config = print.config(); - int numExtruders = wxGetApp().preset_bundle->filament_presets.size(); + auto& print = q->get_partplate_list().get_current_fff_print(); + auto print_config = print.config(); + int numExtruders = wxGetApp().preset_bundle->filament_presets.size(); Model::setExtruderParams(config, numExtruders); Model::setPrintSpeedTable(config, print_config); set_current_panel(preview, no_slice); - } else if (name == "Assemble") { + } + else if (name == "Assemble") { BOOST_LOG_TRIVIAL(info) << "select assemble view"; set_current_panel(assemble_view, no_slice); } - // BBS update selection + //BBS update selection wxGetApp().obj_list()->update_selections(); selection_changed(); @@ -8132,12 +8083,13 @@ void Plater::priv::select_view_3D(const std::string& name, bool no_slice) void Plater::priv::select_next_view_3D() { + if (current_panel == view3D) wxGetApp().mainframe->select_tab(TAB_ID_PREVIEW); else if (current_panel == preview) wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); - // else if (current_panel == assemble_view) - // set_current_panel(view3D); +// else if (current_panel == assemble_view) +// set_current_panel(view3D); } void Plater::priv::enable_sidebar(bool enabled) @@ -8157,7 +8109,9 @@ void Plater::priv::collapse_sidebar(bool collapse) sidebar_layout.is_collapsed = collapse; // Now update the tooltip in the toolbar. - std::string new_tooltip = collapse ? _u8L("Expand sidebar") : _u8L("Collapse sidebar"); + std::string new_tooltip = collapse + ? _u8L("Expand sidebar") + : _u8L("Collapse sidebar"); new_tooltip += " [" + _u8L("Shift+") + _u8L("Tab") + "]"; int id = collapse_toolbar.get_item_id("collapse_sidebar"); collapse_toolbar.set_tooltip(id, new_tooltip); @@ -8165,13 +8119,12 @@ void Plater::priv::collapse_sidebar(bool collapse) update_sidebar(); } -void Plater::priv::update_sidebar(bool force_update) -{ +void Plater::priv::update_sidebar(bool force_update) { auto& sidebar = m_aui_mgr.GetPane(this->sidebar); if (!sidebar.IsOk() || this->current_panel == nullptr) { return; } - bool needs_update = force_update; + bool needs_update = force_update; if (!sidebar_layout.is_enabled) { if (sidebar.IsShown()) { @@ -8201,21 +8154,23 @@ void Plater::priv::reset_window_layout() update_sidebar(true); } -Sidebar::DockingState Plater::priv::get_sidebar_docking_state() -{ +Sidebar::DockingState Plater::priv::get_sidebar_docking_state() { if (!sidebar_layout.is_enabled) { return Sidebar::None; } const auto& sidebar = m_aui_mgr.GetPane(this->sidebar); - if (sidebar.IsFloating()) { + if(sidebar.IsFloating()) { return Sidebar::None; } return sidebar.dock_direction == wxAUI_DOCK_RIGHT ? Sidebar::Right : Sidebar::Left; } -void Plater::priv::reset_all_gizmos() { view3D->get_canvas3d()->reset_all_gizmos(); } +void Plater::priv::reset_all_gizmos() +{ + view3D->get_canvas3d()->reset_all_gizmos(); +} // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. @@ -8230,9 +8185,15 @@ void Plater::priv::update_ui_from_settings() } // BBS -std::shared_ptr Plater::priv::statusbar() { return nullptr; } +std::shared_ptr Plater::priv::statusbar() +{ + return nullptr; +} -std::string Plater::priv::get_config(const std::string& key) const { return wxGetApp().app_config->get(key); } +std::string Plater::priv::get_config(const std::string &key) const +{ + return wxGetApp().app_config->get(key); +} BoundingBoxf Plater::priv::bed_shape_bb() const { @@ -8242,14 +8203,14 @@ BoundingBoxf Plater::priv::bed_shape_bb() const BoundingBox Plater::priv::scaled_bed_shape_bb() const { - const auto* bed_shape_opt = config->opt("printable_area"); + const auto *bed_shape_opt = config->opt("printable_area"); const auto printable_area = Slic3r::Polygon::new_scale(bed_shape_opt->values); return printable_area.bounding_box(); } -void read_binary_stl(const std::string& filename, std::string& model_id, std::string& code) -{ - std::ifstream file(encode_path(filename.c_str()), std::ios::binary); + +void read_binary_stl(const std::string& filename, std::string& model_id, std::string& code) { + std::ifstream file( encode_path(filename.c_str()), std::ios::binary); if (!file) { return; } @@ -8268,7 +8229,7 @@ void read_binary_stl(const std::string& filename, std::string& model_id, std::st return; } - char magic[2] = {data[0], data[1]}; + char magic[2] = { data[0], data[1] }; if (magic[0] != 'M' || magic[1] != 'W') { file.close(); return; @@ -8279,9 +8240,9 @@ void read_binary_stl(const std::string& filename, std::string& model_id, std::st return; } - char protocol_version[3] = {data[3], data[4], data[5]}; + char protocol_version[3] = { data[3], data[4], data[5] }; - // version + //version if (protocol_version[0] != '1' || protocol_version[1] != '.' || protocol_version[2] != '0') { file.close(); return; @@ -8296,16 +8257,18 @@ void read_binary_stl(const std::string& filename, std::string& model_id, std::st tokens.push_back(tokenPtr); } - // model id + //model id if (tokens.size() < 4) { file.close(); return; } model_id = tokens[2]; - code = tokens[3]; + code = tokens[3]; file.close(); - } catch (...) {} + } + catch (...) { + } return; } @@ -8316,25 +8279,26 @@ std::vector Plater::priv::load_files(const std::vector& input_ bool* published_out) { std::vector empty_result; - bool dlg_cont = true; + bool dlg_cont = true; bool is_user_cancel = false; - bool translate_old = false; + bool translate_old = false; int current_width = 0, current_depth = 0, current_height = 0, project_filament_count = 1; if (input_files.empty()) return std::vector(); if (!input_files.empty()) - q->m_3mf_path = input_files[0].string(); - + q->m_3mf_path = input_files[0].string(); + // SoftFever: ugly fix so we can exist pa calib mode background_process.fff_print()->calib_mode() = CalibMode::Calib_None; + // BBS int filaments_cnt = config->opt("filament_colour")->values.size(); - bool one_by_one = input_files.size() == 1 || printer_technology == ptSLA /* || filaments_cnt <= 1*/; - if (!one_by_one) { - for (const auto& path : input_files) { + bool one_by_one = input_files.size() == 1 || printer_technology == ptSLA/* || filaments_cnt <= 1*/; + if (! one_by_one) { + for (const auto &path : input_files) { if (std::regex_match(path.string(), pattern_bundle)) { one_by_one = true; break; @@ -8342,74 +8306,75 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } - bool load_model = strategy & LoadStrategy::LoadModel; - bool load_config = strategy & LoadStrategy::LoadConfig; + bool load_model = strategy & LoadStrategy::LoadModel; + bool load_config = strategy & LoadStrategy::LoadConfig; bool imperial_units = strategy & LoadStrategy::ImperialUnits; - bool silence = strategy & LoadStrategy::Silence; + bool silence = strategy & LoadStrategy::Silence; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": load_model %1%, load_config %2%, input_files size %3%") % load_model % load_config % - input_files.size(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": load_model %1%, load_config %2%, input_files size %3%")%load_model %load_config %input_files.size(); const auto loading = _L("Loading") + dots; ProgressDialog dlg(loading, "", 100, find_toplevel_parent(q), wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_APP_MODAL); wxBusyCursor busy; - auto* new_model = (!load_model || one_by_one) ? nullptr : new Slic3r::Model(); + auto *new_model = (!load_model || one_by_one) ? nullptr : new Slic3r::Model(); std::vector obj_idxs; - std::string designer_model_id; - std::string designer_country_code; + std::string designer_model_id; + std::string designer_country_code; - int answer_convert_from_meters = wxOK_DEFAULT; - int answer_convert_from_imperial_units = wxOK_DEFAULT; - int tolal_model_count = 0; + int answer_convert_from_meters = wxOK_DEFAULT; + int answer_convert_from_imperial_units = wxOK_DEFAULT; + int tolal_model_count = 0; - int progress_percent = 0; - int total_files = input_files.size(); - const int stage_percent[IMPORT_STAGE_MAX + 1] = {5, // IMPORT_STAGE_RESTORE - 10, // IMPORT_STAGE_OPEN - 30, // IMPORT_STAGE_READ_FILES - 50, // IMPORT_STAGE_EXTRACT - 60, // IMPORT_STAGE_LOADING_OBJECTS - 70, // IMPORT_STAGE_LOADING_PLATES - 80, // IMPORT_STAGE_FINISH - 85, // IMPORT_STAGE_ADD_INSTANCE - 90, // IMPORT_STAGE_UPDATE_GCODE - 92, // IMPORT_STAGE_CHECK_MODE_GCODE - 95, // UPDATE_GCODE_RESULT - 98, // IMPORT_LOAD_CONFIG - 99, // IMPORT_LOAD_MODEL_OBJECTS - 100}; - const int step_percent[LOAD_STEP_STAGE_NUM + 1] = {5, // LOAD_STEP_STAGE_READ_FILE - 30, // LOAD_STEP_STAGE_GET_SOLID - 60, // LOAD_STEP_STAGE_GET_MESH - 100}; + int progress_percent = 0; + int total_files = input_files.size(); + const int stage_percent[IMPORT_STAGE_MAX+1] = { + 5, // IMPORT_STAGE_RESTORE + 10, // IMPORT_STAGE_OPEN + 30, // IMPORT_STAGE_READ_FILES + 50, // IMPORT_STAGE_EXTRACT + 60, // IMPORT_STAGE_LOADING_OBJECTS + 70, // IMPORT_STAGE_LOADING_PLATES + 80, // IMPORT_STAGE_FINISH + 85, // IMPORT_STAGE_ADD_INSTANCE + 90, // IMPORT_STAGE_UPDATE_GCODE + 92, // IMPORT_STAGE_CHECK_MODE_GCODE + 95, // UPDATE_GCODE_RESULT + 98, // IMPORT_LOAD_CONFIG + 99, // IMPORT_LOAD_MODEL_OBJECTS + 100 + }; + const int step_percent[LOAD_STEP_STAGE_NUM+1] = { + 5, // LOAD_STEP_STAGE_READ_FILE + 30, // LOAD_STEP_STAGE_GET_SOLID + 60, // LOAD_STEP_STAGE_GET_MESH + 100 + }; - const float INPUT_FILES_RATIO = 0.7; - const float INIT_MODEL_RATIO = 0.75; - const float CENTER_AROUND_ORIGIN_RATIO = 0.8; - const float LOAD_MODEL_RATIO = 0.9; + const float INPUT_FILES_RATIO = 0.7; + const float INIT_MODEL_RATIO = 0.75; + const float CENTER_AROUND_ORIGIN_RATIO = 0.8; + + const float LOAD_MODEL_RATIO = 0.9; for (size_t i = 0; i < input_files.size(); ++i) { #ifdef _WIN32 auto path = input_files[i]; - // On Windows, we swap slashes to back slashes, see GH #6803 as read_from_file() does not understand slashes on Windows thus it - // assignes full path to names of loaded objects. + // On Windows, we swap slashes to back slashes, see GH #6803 as read_from_file() does not understand slashes on Windows thus it assignes full path to names of loaded objects. path.make_preferred(); #else // _WIN32 // Don't make a copy on Posix. Slash is a path separator, back slashes are not accepted as a substitute. - const auto& path = input_files[i]; + const auto &path = input_files[i]; #endif // _WIN32 - const auto filename = path.filename(); - int progress_percent = static_cast(100.0f * static_cast(i) / static_cast(input_files.size())); - const auto real_filename = (strategy & LoadStrategy::Restore) ? input_files[++i].filename() : filename; - const auto dlg_info = _L("Loading file") + ": " + from_path(real_filename); + const auto filename = path.filename(); + int progress_percent = static_cast(100.0f * static_cast(i) / static_cast(input_files.size())); + const auto real_filename = (strategy & LoadStrategy::Restore) ? input_files[++i].filename() : filename; + const auto dlg_info = _L("Loading file") + ": " + from_path(real_filename); BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << boost::format(": load file %1%") % filename; dlg_cont = dlg.Update(progress_percent, dlg_info); - if (!dlg_cont) - return empty_result; + if (!dlg_cont) return empty_result; const bool type_3mf = std::regex_match(path.string(), pattern_3mf); // const bool type_zip_amf = !type_3mf && std::regex_match(path.string(), pattern_zip_amf); @@ -8423,15 +8388,14 @@ std::vector Plater::priv::load_files(const std::vector& input_ load_aux = true; strategy = strategy | LoadStrategy::LoadAuxiliary; } - if (load_config) - strategy = strategy | LoadStrategy::CheckVersion; + if (load_config) strategy = strategy | LoadStrategy::CheckVersion; bool is_project_file = false; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": is_project_file %1%, type_3mf %2%") % is_project_file % type_3mf; try { if (type_3mf) { DynamicPrintConfig config; - Semver file_version; - En3mfType en_3mf_file_type = En3mfType::From_BBS; + Semver file_version; + En3mfType en_3mf_file_type = En3mfType::From_BBS; // BBS: a "published" 3MF carries a flag plus the author-selected setting keys; // on load keep the user's current presets and overlay only those keys. Declared // here (outside the config block below) so it stays alive for the embedded-preset @@ -8441,9 +8405,9 @@ std::vector Plater::priv::load_files(const std::vector& input_ DynamicPrintConfig config_loaded; // BBS: add part plate related logic - PlateDataPtrs plate_data; + PlateDataPtrs plate_data; ConfigSubstitutionContext config_substitutions{ForwardCompatibilitySubstitutionRule::Enable}; - std::vector project_presets; + std::vector project_presets; // BBS: backup & restore q->skip_thumbnail_invalid = true; model = Slic3r::Model::read_from_archive(path.string(), &config_loaded, &config_substitutions, en_3mf_file_type, strategy, &plate_data, &project_presets, @@ -8460,12 +8424,9 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (cancel) is_user_cancel = cancel; }); - BOOST_LOG_TRIVIAL(info) - << __FUNCTION__ << ":" << __LINE__ - << boost::format(", plate_data.size %1%, project_preset.size %2%, is_bbs_or_orca_3mf %3%, file_version %4% \n") % - plate_data.size() % project_presets.size() % - (en_3mf_file_type == En3mfType::From_BBS || en_3mf_file_type == En3mfType::From_Orca) % - file_version.to_string(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ + << boost::format(", plate_data.size %1%, project_preset.size %2%, is_bbs_or_orca_3mf %3%, file_version %4% \n") % plate_data.size() % + project_presets.size() % (en_3mf_file_type == En3mfType::From_BBS || en_3mf_file_type == En3mfType::From_Orca) % file_version.to_string(); // BBS: a "published" 3MF carries a flag plus the author-selected setting keys; // on load keep the user's current presets and overlay only those keys. Parsed @@ -8572,24 +8533,20 @@ std::vector Plater::priv::load_files(const std::vector& input_ // 2. add extruder for BBS or Other model if only import geometry if (en_3mf_file_type == En3mfType::From_Prusa || (load_model && !load_config)) { std::set extruderIds; - for (ModelObject* o : model.objects) { - if (o->config.option("extruder")) - extruderIds.insert(o->config.extruder()); + for (ModelObject *o : model.objects) { + if (o->config.option("extruder")) extruderIds.insert(o->config.extruder()); for (auto volume : o->volumes) { - if (volume->config.option("extruder")) - extruderIds.insert(volume->config.extruder()); - for (int extruder : volume->get_extruders()) { - extruderIds.insert(extruder); - } + if (volume->config.option("extruder")) extruderIds.insert(volume->config.extruder()); + for (int extruder : volume->get_extruders()) { extruderIds.insert(extruder); } } } int size = extruderIds.size() == 0 ? 0 : *(extruderIds.rbegin()); int filament_size = sidebar->combos_filament().size(); while (filament_size < MAXIMUM_EXTRUDER_NUMBER && filament_size < size) { - int filament_count = filament_size + 1; - wxColour new_col = Plater::get_next_color_for_filament(); - std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); + int filament_count = filament_size + 1; + wxColour new_col = Plater::get_next_color_for_filament(); + std::string new_color = new_col.GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); wxGetApp().preset_bundle->set_num_filaments(filament_count, new_color); wxGetApp().plater()->on_filament_count_change(filament_count); ++filament_size; @@ -8602,22 +8559,21 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (import_project_action.empty()) load_type = LoadType::Unknown; else - load_type = static_cast(std::stoi(import_project_action)); + load_type = static_cast(std::stoi(import_project_action)); // BBS: version check - Semver app_version = *(Semver::parse(SoftFever_VERSION)); - const wxString load_3mf_title = _L("Load 3MF"); - const wxString newer_3mf_title = _L("Newer 3MF version"); - const wxString bambu_project_title = _L("BambuStudio Project"); - const wxString msg_unsupported_geometry = _L("The 3MF is not supported by OrcaSlicer, loading geometry data only."); - const wxString msg_old_orca_geometry = _L( - "The 3MF file was generated by an old OrcaSlicer version, loading geometry data only."); - const wxString msg_older_geometry = _L("The 3MF file was generated by an older version, loading geometry data only."); - const wxString msg_bambu_geometry = _L("The 3MF file was generated by BambuStudio, loading geometry data only."); - auto log_and_show_3mf_info = [&](const wxString& text, const wxString& title) { - BOOST_LOG_TRIVIAL(info) - << __FUNCTION__ << ":" << __LINE__ << " " - << boost::format("3MF import message [%1%]: %2% | file: %3%") % into_u8(title) % into_u8(text) % path.string(); + Semver app_version = *(Semver::parse(SoftFever_VERSION)); + const wxString load_3mf_title = _L("Load 3MF"); + const wxString newer_3mf_title = _L("Newer 3MF version"); + const wxString bambu_project_title = _L("BambuStudio Project"); + const wxString msg_unsupported_geometry = _L("The 3MF is not supported by OrcaSlicer, loading geometry data only."); + const wxString msg_old_orca_geometry = _L("The 3MF file was generated by an old OrcaSlicer version, loading geometry data only."); + const wxString msg_older_geometry = _L("The 3MF file was generated by an older version, loading geometry data only."); + const wxString msg_bambu_geometry = _L("The 3MF file was generated by BambuStudio, loading geometry data only."); + auto log_and_show_3mf_info = [&](const wxString& text, const wxString& title) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ + << " " + << boost::format("3MF import message [%1%]: %2% | file: %3%") % into_u8(title) % into_u8(text) % path.string(); show_info(q, text, title); }; if (en_3mf_file_type == En3mfType::From_Prusa) { @@ -8625,7 +8581,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ load_config = false; if (load_type != LoadType::LoadGeometry) log_and_show_3mf_info(msg_unsupported_geometry, load_3mf_title); - } else if (en_3mf_file_type == En3mfType::From_Orca) { + } + else if (en_3mf_file_type == En3mfType::From_Orca) { // OrcaSlicer file (has OrcaSlicer tag) - compare file_version with SoftFever_VERSION // Migration fix for OrcaSlicer 2.3.1-alpha sparse infill rotation template if (load_config && (file_version < app_version) && file_version == Semver("2.3.1-alpha")) { @@ -8640,8 +8597,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ L("This project was created with an OrcaSlicer 2.3.1-alpha and uses " "infill rotation template settings that may not work properly with your current infill pattern. " "This could result in weak support or print quality issues.")); - msg_text += "\n\n" + _(L("Would you like OrcaSlicer to automatically fix this by clearing the rotation " - "template settings?")); + msg_text += "\n\n" + + _(L("Would you like OrcaSlicer to automatically fix this by clearing the rotation template settings?")); MessageDialog dialog(wxGetApp().plater(), msg_text, "", wxICON_WARNING | wxYES | wxNO); dialog.SetButtonLabel(wxID_YES, _L("Yes")); dialog.SetButtonLabel(wxID_NO, _L("No")); @@ -8652,30 +8609,31 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } else if (load_config && (file_version > app_version)) { if (config_substitutions.unrecogized_keys.size() > 0) { - wxString text = wxString::Format( - _L("The 3MF file version %s is newer than %s's version %s, found the following unrecognized keys:"), - file_version.to_string_sf(), std::string(SLIC3R_APP_FULL_NAME), app_version.to_string_sf()); + wxString text = wxString::Format(_L("The 3MF file version %s is newer than %s's version %s, found the following unrecognized keys:"), + file_version.to_string_sf(), std::string(SLIC3R_APP_FULL_NAME), app_version.to_string_sf()); text += "\n"; wxString context = text; - wxString append = _L("You should update your software.\n"); + wxString append = _L("You should update your software.\n"); context += "\n\n"; context += append; log_and_show_3mf_info(context, newer_3mf_title); - } else { - // if the minor version is not matched + } + else { + //if the minor version is not matched if (file_version.min() != app_version.min()) { - wxString text = wxString::Format( - _L("The 3MF file version %s is newer than %s's version %s, we suggest to upgrade your software."), - file_version.to_string_sf(), std::string(SLIC3R_APP_FULL_NAME), app_version.to_string_sf()); + wxString text = wxString::Format(_L("The 3MF file version %s is newer than %s's version %s, we suggest to upgrade your software."), + file_version.to_string_sf(), std::string(SLIC3R_APP_FULL_NAME), app_version.to_string_sf()); text += "\n"; log_and_show_3mf_info(text, newer_3mf_title); } } - } else if (load_config && config_loaded.empty()) { + } + else if (load_config && config_loaded.empty()) { load_config = false; log_and_show_3mf_info(msg_old_orca_geometry, load_3mf_title); } - } else if (en_3mf_file_type == En3mfType::From_BBS) { + } + else if (en_3mf_file_type == En3mfType::From_BBS) { // No OrcaSlicer tag - check Bambu/Application version Semver orca_tag_start_version(2, 3, 2); if (file_version <= orca_tag_start_version) { @@ -8690,12 +8648,12 @@ std::vector Plater::priv::load_files(const std::vector& input_ _sparse_infill_pattern == ipZigZag || _sparse_infill_pattern == ipCrossZag || _sparse_infill_pattern == ipLockedZag; if (!is_safe_to_rotate) { - wxString msg_text = _(L("This project was created with an OrcaSlicer 2.3.1-alpha and uses " - "infill rotation template settings that may not work properly with your " - "current infill pattern. " - "This could result in weak support or print quality issues.")); - msg_text += "\n\n" + _(L("Would you like OrcaSlicer to automatically fix this by clearing the " - "rotation template settings?")); + wxString msg_text = _( + L("This project was created with an OrcaSlicer 2.3.1-alpha and uses " + "infill rotation template settings that may not work properly with your current infill pattern. " + "This could result in weak support or print quality issues.")); + msg_text += "\n\n" + + _(L("Would you like OrcaSlicer to automatically fix this by clearing the rotation template settings?")); MessageDialog dialog(wxGetApp().plater(), msg_text, "", wxICON_WARNING | wxYES | wxNO); dialog.SetButtonLabel(wxID_YES, _L("Yes")); dialog.SetButtonLabel(wxID_NO, _L("No")); @@ -8704,7 +8662,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } } - } else if (load_config && config_loaded.empty()) { + } + else if (load_config && config_loaded.empty()) { load_config = false; log_and_show_3mf_info(msg_older_geometry, load_3mf_title); } @@ -8715,23 +8674,21 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (load_config && config_loaded.empty()) { load_config = false; log_and_show_3mf_info(msg_bambu_geometry, load_3mf_title); - } else if (load_config && (file_version > slic3r_version)) { + } + else if (load_config && (file_version > slic3r_version)) { // BambuStudio file version is newer than our compatible SLIC3R_VERSION if (config_substitutions.unrecogized_keys.size() > 0) { - wxString text = wxString::Format(_L("The 3MF was created by BambuStudio (version %s), which is newer " - "than the compatible version %s. Found unrecognized settings:"), + wxString text = wxString::Format(_L("The 3MF was created by BambuStudio (version %s), which is newer than the compatible version %s. Found unrecognized settings:"), file_version.to_string(), slic3r_version.to_string()); text += "\n"; wxString context = text; - wxString append = _L("You should update your software.\n"); + wxString append = _L("You should update your software.\n"); context += "\n\n"; context += append; log_and_show_3mf_info(context, bambu_project_title); } else { - wxString text = - wxString::Format(_L("The 3MF was created by BambuStudio (version %s), which is newer than the " - "compatible version %s. Some settings may not be fully compatible."), - file_version.to_string(), slic3r_version.to_string()); + wxString text = wxString::Format(_L("The 3MF was created by BambuStudio (version %s), which is newer than the compatible version %s. Some settings may not be fully compatible."), + file_version.to_string(), slic3r_version.to_string()); text += "\n"; log_and_show_3mf_info(text, bambu_project_title); } @@ -8741,46 +8698,41 @@ std::vector Plater::priv::load_files(const std::vector& input_ log_and_show_3mf_info(text, bambu_project_title); } } - } else if (en_3mf_file_type == En3mfType::From_Other) { + } + else if (en_3mf_file_type == En3mfType::From_Other) { // Generic CAD/other 3MF without slicer metadata: import geometry silently. if (load_config && config_loaded.empty()) { - BOOST_LOG_TRIVIAL(info) - << __FUNCTION__ << ":" << __LINE__ << " " - << boost::format("3MF has no slicer metadata/project config, importing geometry only: %1%") % path.string(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ + << " " + << boost::format("3MF has no slicer metadata/project config, importing geometry only: %1%") % path.string(); load_config = false; } - } else if (load_config && config_loaded.empty()) { + } + else if (load_config && config_loaded.empty()) { load_config = false; log_and_show_3mf_info(msg_old_orca_geometry, load_3mf_title); - } else if (!load_config) { + } + else if (!load_config) { // reset config except color - for (ModelObject* model_object : model.objects) { + for (ModelObject *model_object : model.objects) { bool has_extruder = model_object->config.has("extruder"); - int extruder_id = -1; + int extruder_id = -1; // save the extruder information before reset - if (has_extruder) { - extruder_id = model_object->config.extruder(); - } + if (has_extruder) { extruder_id = model_object->config.extruder(); } model_object->config.reset(); // restore the extruder after reset - if (has_extruder) { - model_object->config.set("extruder", extruder_id); - } + if (has_extruder) { model_object->config.set("extruder", extruder_id); } // Is there any modifier or advanced config data? - for (ModelVolume* model_volume : model_object->volumes) { + for (ModelVolume *model_volume : model_object->volumes) { has_extruder = model_volume->config.has("extruder"); - if (has_extruder) { - extruder_id = model_volume->config.extruder(); - } + if (has_extruder) { extruder_id = model_volume->config.extruder(); } model_volume->config.reset(); - if (has_extruder) { - model_volume->config.set("extruder", extruder_id); - } + if (has_extruder) { model_volume->config.set("extruder", extruder_id); } } } } @@ -8800,17 +8752,15 @@ std::vector Plater::priv::load_files(const std::vector& input_ } Semver old_version(1, 5, 9); - if ((en_3mf_file_type == En3mfType::From_BBS || en_3mf_file_type == En3mfType::From_Orca) && - (file_version < old_version) && load_model && load_config && !config_loaded.empty()) { + if ((en_3mf_file_type == En3mfType::From_BBS || en_3mf_file_type == En3mfType::From_Orca) && (file_version < old_version) && load_model && load_config && !config_loaded.empty()) { translate_old = true; partplate_list.get_plate_size(current_width, current_depth, current_height); } if (load_config) { if (translate_old) { - // set the size back - partplate_list.reset_size(current_width + Bed3D::Axes::DefaultTipRadius, - current_depth + Bed3D::Axes::DefaultTipRadius, current_height, false); + //set the size back + partplate_list.reset_size(current_width + Bed3D::Axes::DefaultTipRadius, current_depth + Bed3D::Axes::DefaultTipRadius, current_height, false); } project_filament_count = config_loaded.option("filament_colour")->size(); partplate_list.load_from_3mf_structure(plate_data, project_filament_count); @@ -8830,16 +8780,12 @@ std::vector Plater::priv::load_files(const std::vector& input_ if ((project_presets.size() > 0) && load_config && !published_config.published) { // load project embedded presets PresetsConfigSubstitutions preset_substitutions; - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; - preset_substitutions = preset_bundle.load_project_embedded_presets(project_presets, - ForwardCompatibilitySubstitutionRule::Enable); - if (!preset_substitutions.empty()) - show_substitutions_info(preset_substitutions); + PresetBundle & preset_bundle = *wxGetApp().preset_bundle; + preset_substitutions = preset_bundle.load_project_embedded_presets(project_presets, ForwardCompatibilitySubstitutionRule::Enable); + if (!preset_substitutions.empty()) show_substitutions_info(preset_substitutions); } if (project_presets.size() > 0) { - for (unsigned int i = 0; i < project_presets.size(); i++) { - delete project_presets[i]; - } + for (unsigned int i = 0; i < project_presets.size(); i++) { delete project_presets[i]; } project_presets.clear(); } @@ -8855,37 +8801,35 @@ std::vector Plater::priv::load_files(const std::vector& input_ // Based on the printer technology field found in the loaded config, select the base for the config, PrinterTechnology printer_technology = Preset::printer_technology(config_loaded); - config.apply(static_cast(FullPrintConfig::defaults())); + config.apply(static_cast(FullPrintConfig::defaults())); // and place the loaded config over the base. config += std::move(config_loaded); std::map validity = config.validate(); if (!validity.empty()) { - BOOST_LOG_TRIVIAL(info) - << __FUNCTION__ << ":" << __LINE__ << " " << boost::format("Param values in 3mf error: "); - for (std::map::iterator it = validity.begin(); it != validity.end(); ++it) - BOOST_LOG_TRIVIAL(info) - << __FUNCTION__ << ":" << __LINE__ << " " << boost::format("%1%: %2%") % it->first % it->second; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << " " << boost::format("Param values in 3mf error: "); + for (std::map::iterator it=validity.begin(); it!=validity.end(); ++it) + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << " " << boost::format("%1%: %2%")%it->first %it->second; // - NotificationManager* notify_manager = q->get_notification_manager(); - std::string error_message = _u8L("Invalid values found in the 3MF:"); + NotificationManager *notify_manager = q->get_notification_manager(); + std::string error_message = _u8L("Invalid values found in the 3MF:"); error_message += "\n"; - for (std::map::iterator it = validity.begin(); it != validity.end(); ++it) + for (std::map::iterator it=validity.begin(); it!=validity.end(); ++it) error_message += "-" + it->first + ": " + it->second + "\n"; error_message += "\n"; error_message += _u8L("Please correct them in the Param tabs"); notify_manager->bbl_show_3mf_warn_notification(error_message); } } - if (!config_substitutions.empty()) - show_substitutions_info(config_substitutions.substitutions, filename.string()); + if (!config_substitutions.empty()) show_substitutions_info(config_substitutions.substitutions, filename.string()); // BBS if (load_model && !load_config) { ; - } else { + } + else { this->model.plates_custom_gcodes = model.plates_custom_gcodes; - this->model.design_info = model.design_info; - this->model.model_info = model.model_info; + this->model.design_info = model.design_info; + this->model.model_info = model.model_info; } } @@ -8905,60 +8849,52 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (load_config) { if (!config.empty()) { Preset::normalize(config); - PresetBundle* preset_bundle = wxGetApp().preset_bundle; + PresetBundle *preset_bundle = wxGetApp().preset_bundle; { // BBS: modify the prime tower params for old version file Semver old_version3(2, 0, 0); - if ((en_3mf_file_type == En3mfType::From_BBS || en_3mf_file_type == En3mfType::From_Orca) && - file_version < old_version3) { + if ((en_3mf_file_type == En3mfType::From_BBS || en_3mf_file_type == En3mfType::From_Orca) && file_version < old_version3) { double old_filament_prime_volume = 0.; - int filament_count = 0; + int filament_count = 0; { - ConfigOptionFloats* filament_prime_volume_option = config.option( - "filament_prime_volume"); - ConfigOptionStrings* filament_colors_option = config.option("filament_colour", - true); - filament_count = filament_colors_option->values.size(); + ConfigOptionFloats *filament_prime_volume_option = config.option("filament_prime_volume"); + ConfigOptionStrings *filament_colors_option = config.option("filament_colour", true); + filament_count = filament_colors_option->values.size(); if (filament_prime_volume_option) { - std::vector& filament_prime_volume_values = filament_prime_volume_option->values; + std::vector &filament_prime_volume_values = filament_prime_volume_option->values; if (!filament_prime_volume_values.empty()) { old_filament_prime_volume = filament_prime_volume_values[0]; - if (filament_count > 1) - filament_prime_volume_values.resize(filament_count, old_filament_prime_volume); + if (filament_count > 1) filament_prime_volume_values.resize(filament_count, old_filament_prime_volume); } } } - ConfigOptionEnum* prime_tower_rib_wall_option = - config.option>("wipe_tower_wall_type", true); - prime_tower_rib_wall_option->value = WipeTowerWallType::wtwRectangle; + ConfigOptionEnum *prime_tower_rib_wall_option = config.option>("wipe_tower_wall_type", true); + prime_tower_rib_wall_option->value = WipeTowerWallType::wtwRectangle; - ConfigOptionPercent* prime_tower_infill_gap_option = - config.option("prime_tower_infill_gap", true); - prime_tower_infill_gap_option->value = 100; + ConfigOptionPercent *prime_tower_infill_gap_option = config.option("prime_tower_infill_gap", true); + prime_tower_infill_gap_option->value = 100; - ConfigOptionInts* filament_adhesiveness_category_option = - config.option("filament_adhesiveness_category", true); - std::vector& filament_adhesiveness_category_values = filament_adhesiveness_category_option->values; + ConfigOptionInts *filament_adhesiveness_category_option = config.option("filament_adhesiveness_category", true); + std::vector &filament_adhesiveness_category_values = filament_adhesiveness_category_option->values; filament_adhesiveness_category_values.resize(filament_count); for (int index = 0; index < filament_count; index++) filament_adhesiveness_category_values[index] = 100; - std::vector& diff_settings = - config.option("different_settings_to_system", true)->values; + std::vector &diff_settings = config.option("different_settings_to_system", true)->values; diff_settings.resize(filament_count + 2); std::vector diff_process_keys; - std::string diff_process_settings = diff_settings[0]; + std::string diff_process_settings = diff_settings[0]; Slic3r::unescape_strings_cstyle(diff_process_settings, diff_process_keys); diff_process_keys.emplace_back("wipe_tower_wall_type"); diff_process_keys.emplace_back("prime_tower_infill_gap"); diff_process_settings = Slic3r::escape_strings_cstyle(diff_process_keys); - diff_settings[0] = diff_process_settings; + diff_settings[0] = diff_process_settings; for (int index = 0; index < filament_count; index++) { std::vector diff_filament_keys; - std::string diff_filament_settings = diff_settings[index + 1]; + std::string diff_filament_settings = diff_settings[index + 1]; Slic3r::unescape_strings_cstyle(diff_filament_settings, diff_filament_keys); diff_filament_keys.emplace_back("filament_adhesiveness_category"); diff_filament_settings = Slic3r::escape_strings_cstyle(diff_filament_keys); @@ -8976,51 +8912,38 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (validated == VALIDATE_PRESETS_MODIFIED_GCODES) { std::string warning_message; warning_message += "\n"; - for (std::set::iterator it = modified_gcodes.begin(); it != modified_gcodes.end(); ++it) + for (std::set::iterator it=modified_gcodes.begin(); it!=modified_gcodes.end(); ++it) warning_message += "-" + *it + "\n"; warning_message += "\n"; - // show_info(q, _L("The 3MF has the following modified G-code in filament or printer presets:") + - // warning_message + _L("Please confirm that all modified G-code is safe to prevent any damage to the - // machine!"), _L("Modified G-code")); - MessageDialog - dlg(q, - _L("The 3MF has the following modified G-code in filament or printer presets:") + warning_message + - _L("Please confirm that all modified G-code is safe to prevent any damage to the machine!"), - _L("Modified G-code")); + //show_info(q, _L("The 3MF has the following modified G-code in filament or printer presets:") + warning_message + _L("Please confirm that all modified G-code is safe to prevent any damage to the machine!"), _L("Modified G-code")); + MessageDialog dlg(q, _L("The 3MF has the following modified G-code in filament or printer presets:") + warning_message + _L("Please confirm that all modified G-code is safe to prevent any damage to the machine!"), _L("Modified G-code")); dlg.show_dsa_button(); - auto res = dlg.ShowModal(); + auto res = dlg.ShowModal(); if (dlg.get_checkbox_state()) wxGetApp().app_config->set("no_warn_when_modified_gcodes", "true"); - } else if ((validated == VALIDATE_PRESETS_PRINTER_NOT_FOUND) || - (validated == VALIDATE_PRESETS_FILAMENTS_NOT_FOUND)) { + } + else if ((validated == VALIDATE_PRESETS_PRINTER_NOT_FOUND) || (validated == VALIDATE_PRESETS_FILAMENTS_NOT_FOUND)) { std::string warning_message; warning_message += "\n"; - for (std::set::iterator it = modified_gcodes.begin(); it != modified_gcodes.end(); ++it) + for (std::set::iterator it=modified_gcodes.begin(); it!=modified_gcodes.end(); ++it) warning_message += "-" + *it + "\n"; warning_message += "\n"; - // show_info(q, _L("The 3MF has the following customized filament or printer presets:") + warning_message + - // _L("Please confirm that the G-code within these presets is safe to prevent any damage to the machine!"), - // _L("Customized Preset")); - MessageDialog dlg(q, - _L("The 3MF has the following customized filament or printer presets:") + - from_u8(warning_message) + - _L("Please confirm that the G-code within these presets is safe to prevent any " - "damage to the machine!"), - _L("Customized Preset")); + //show_info(q, _L("The 3MF has the following customized filament or printer presets:") + warning_message + _L("Please confirm that the G-code within these presets is safe to prevent any damage to the machine!"), _L("Customized Preset")); + MessageDialog dlg(q, _L("The 3MF has the following customized filament or printer presets:") + from_u8(warning_message)+ _L("Please confirm that the G-code within these presets is safe to prevent any damage to the machine!"), _L("Customized Preset")); dlg.show_dsa_button(); - auto res = dlg.ShowModal(); + auto res = dlg.ShowModal(); if (dlg.get_checkbox_state()) wxGetApp().app_config->set("no_warn_when_modified_gcodes", "true"); } } - // always load config + //always load config { // BBS: save the wipe tower pos in file here, will be used later ConfigOptionFloats* wipe_tower_x_opt = config.opt("wipe_tower_x"); ConfigOptionFloats* wipe_tower_y_opt = config.opt("wipe_tower_y"); - std::optional file_wipe_tower_x; - std::optional file_wipe_tower_y; + std::optionalfile_wipe_tower_x; + std::optionalfile_wipe_tower_y; if (wipe_tower_x_opt) file_wipe_tower_x = *wipe_tower_x_opt; if (wipe_tower_y_opt) @@ -9073,7 +8996,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ ConfigOption* bed_type_opt = preset_bundle->project_config.option("curr_bed_type"); if (bed_type_opt != nullptr) { - BedType bed_type = (BedType) bed_type_opt->getInt(); + BedType bed_type = (BedType)bed_type_opt->getInt(); // update app config for bed type bool is_bbl_preset = preset_bundle->is_bbl_vendor(); if (is_bbl_preset) { @@ -9121,10 +9044,9 @@ std::vector Plater::priv::load_files(const std::vector& input_ // // show notification about temporarily installed presets // if (!names.empty()) { - // std::string notif_text = into_u8(_L_PLURAL("The preset below was temporarily installed on the active - // instance of PrusaSlicer", - // "The presets below were temporarily installed on the active - // instance of PrusaSlicer", names.size())) + ":"; + // std::string notif_text = into_u8(_L_PLURAL("The preset below was temporarily installed on the active instance of PrusaSlicer", + // "The presets below were temporarily installed on the active instance of PrusaSlicer", + // names.size())) + ":"; // for (std::string& name : names) // notif_text += "\n - " + name; // notification_manager->push_notification(NotificationType::CustomNotification, @@ -9134,11 +9056,11 @@ std::vector Plater::priv::load_files(const std::vector& input_ // BBS // if (printer_technology == ptFFF) - // CustomGCode::update_custom_gcode_per_print_z_from_config(model.custom_gcode_per_print_z, - // &preset_bundle->project_config); + // CustomGCode::update_custom_gcode_per_print_z_from_config(model.custom_gcode_per_print_z, &preset_bundle->project_config); - // For exporting from the amf/3mf we shouldn't check printer_presets for the containing information about "Print - // Host upload" BBS: add preset combo box re-active logic currently found only needs re-active here + // For exporting from the amf/3mf we shouldn't check printer_presets for the containing information about "Print Host upload" + // BBS: add preset combo box re-active logic + // currently found only needs re-active here wxGetApp().load_current_presets(false, false); // Update filament colors for the MM-printer profile in the full config // to avoid black (default) colors for Extruders in the ObjectList, @@ -9149,8 +9071,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ DynamicConfig& proj_cfg = preset_bundle->project_config; // do some post process after loading config { - // BBS: rewrite wipe tower pos stored in 3mf file , the code above should be seriously reconsidered - ConfigOptionFloats* wipe_tower_x = proj_cfg.opt("wipe_tower_x"); + //BBS: rewrite wipe tower pos stored in 3mf file , the code above should be seriously reconsidered + ConfigOptionFloats* wipe_tower_x = proj_cfg.opt("wipe_tower_x"); ConfigOptionFloats* wipe_tower_y = proj_cfg.opt("wipe_tower_y"); if (file_wipe_tower_x) *wipe_tower_x = *file_wipe_tower_x; @@ -9178,22 +9100,19 @@ std::vector Plater::priv::load_files(const std::vector& input_ } // Sync filament multi colour - ConfigOptionStrings* filament_multi_color = proj_cfg.opt("filament_multi_colour", - true); + ConfigOptionStrings* filament_multi_color = proj_cfg.opt("filament_multi_colour", true); if (filament_multi_color->size() != filament_count) { filament_multi_color->values.resize(filament_count); } // If there is no multi-color data or color is not match, use single color as default value for (size_t i = 0; i < filament_count; i++) { std::vector colors = Slic3r::split_string(filament_multi_color->values[i], ' '); - if (i >= filament_multi_color->values.size() || colors.empty() || - colors[0] != filament_color->values[i]) { + if (i >= filament_multi_color->values.size() || colors.empty() || colors[0] != filament_color->values[i] ) { filament_multi_color->values[i] = filament_color->values[i]; } } // Sync filament colour type - ConfigOptionStrings* filament_color_type = proj_cfg.opt("filament_colour_type", - true); + ConfigOptionStrings* filament_color_type = proj_cfg.opt("filament_colour_type", true); if (filament_color_type && filament_color_type->size() != filament_count) { filament_color_type->values.resize(filament_count); @@ -9223,33 +9142,29 @@ std::vector Plater::priv::load_files(const std::vector& input_ } // The loaded project supplies nozzle_volume_type; refresh the sidebar // nozzle-count badges against it. - if (auto* nozzle_volumes = wxGetApp().preset_bundle->project_config.option( - "nozzle_volume_type")) { + if (auto *nozzle_volumes = wxGetApp().preset_bundle->project_config.option("nozzle_volume_type")) { const int extruder_count = wxGetApp().preset_bundle->get_printer_extruder_count(); - for (int extruder_id = 0; extruder_id < extruder_count && extruder_id < (int) nozzle_volumes->values.size(); - ++extruder_id) - updateNozzleCountDisplay(wxGetApp().preset_bundle, extruder_id, - NozzleVolumeType(nozzle_volumes->values[extruder_id])); + for (int extruder_id = 0; extruder_id < extruder_count && extruder_id < (int) nozzle_volumes->values.size(); ++extruder_id) + updateNozzleCountDisplay(wxGetApp().preset_bundle, extruder_id, NozzleVolumeType(nozzle_volumes->values[extruder_id])); } } } - if (!silence) - wxGetApp().app_config->update_config_dir(path.parent_path().string()); + if (!silence) wxGetApp().app_config->update_config_dir(path.parent_path().string()); } } else { // BBS: add plate data related logic PlateDataPtrs plate_data; // BBS: project embedded settings - std::vector project_presets; - bool is_xxx; - Semver file_version; + std::vector project_presets; + bool is_xxx; + Semver file_version; //ObjImportColorFn obj_color_fun=nullptr; auto obj_color_fun = [&path](ObjDialogInOut &in_out) { if (!boost::iends_with(path.string(), ".obj")) { return; } const std::vector extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config(); - ObjColorDialog color_dlg(nullptr, in_out, extruder_colours, Sidebar::should_show_SEMM_buttons()); + ObjColorDialog color_dlg(nullptr, in_out, extruder_colours, Sidebar::should_show_SEMM_buttons()); if (color_dlg.ShowModal() != wxID_OK) { in_out.filament_ids.clear(); } @@ -9295,10 +9210,10 @@ std::vector Plater::priv::load_files(const std::vector& input_ is_split = mesh_dlg.get_split_compound_value(); return 1; } - } else { + }else { linear_value = linear; - angle_value = angle; - is_split = split_compound; + angle_value = angle; + is_split = split_compound; return 1; } is_user_cancel = true; @@ -9312,25 +9227,22 @@ std::vector Plater::priv::load_files(const std::vector& input_ designer_model_id = mode_id; designer_country_code = code; - bool cont = true; - float percent_float = (100.0f * (float) i / (float) total_files) + - INPUT_FILES_RATIO * 100.0f * ((float) current / (float) total) / (float) total_files; - BOOST_LOG_TRIVIAL(trace) - << "load_stl_file: percent(float)=" << percent_float << ", curr = " << current << ", total = " << total; - progress_percent = (int) percent_float; - wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); - cont = dlg.Update(progress_percent, msg); - cancel = !cont; - }, - nullptr, 0, obj_color_fun); + bool cont = true; + float percent_float = (100.0f * (float)i / (float)total_files) + INPUT_FILES_RATIO * 100.0f * ((float)current / (float)total) / (float)total_files; + BOOST_LOG_TRIVIAL(trace) << "load_stl_file: percent(float)=" << percent_float << ", curr = " << current << ", total = " << total; + progress_percent = (int)percent_float; + wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); + cont = dlg.Update(progress_percent, msg); + cancel = !cont; + }, + nullptr, 0, obj_color_fun); } if (designer_model_id.empty() && boost::algorithm::iends_with(path.string(), ".stl")) { read_binary_stl(path.string(), designer_model_id, designer_country_code); } - if (type_any_amf && is_xxx) - imperial_units = true; + if (type_any_amf && is_xxx) imperial_units = true; for (auto obj : model.objects) { if (obj->name.empty()) { @@ -9351,31 +9263,26 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (project_presets.size() > 0) { // load project embedded presets PresetsConfigSubstitutions preset_substitutions; - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; - preset_substitutions = preset_bundle.load_project_embedded_presets(project_presets, - ForwardCompatibilitySubstitutionRule::Enable); - if (!preset_substitutions.empty()) - show_substitutions_info(preset_substitutions); + PresetBundle & preset_bundle = *wxGetApp().preset_bundle; + preset_substitutions = preset_bundle.load_project_embedded_presets(project_presets, ForwardCompatibilitySubstitutionRule::Enable); + if (!preset_substitutions.empty()) show_substitutions_info(preset_substitutions); - for (unsigned int i = 0; i < project_presets.size(); i++) { - delete project_presets[i]; - } + for (unsigned int i = 0; i < project_presets.size(); i++) { delete project_presets[i]; } project_presets.clear(); } } - } catch (const ConfigurationError& e) { - std::string message = GUI::format(_L("Failed loading file \"%1%\". An invalid configuration was found."), filename.string()) + - "\n\n" + e.what(); + } catch (const ConfigurationError &e) { + std::string message = GUI::format(_L("Failed loading file \"%1%\". An invalid configuration was found."), filename.string()) + "\n\n" + e.what(); GUI::show_error(q, message); continue; - } catch (const std::exception& e) { + } catch (const std::exception &e) { if (!is_user_cancel) GUI::show_error(q, e.what()); continue; } - progress_percent = 100.0f * (float) i / (float) total_files + INIT_MODEL_RATIO * 100.0f / (float) total_files; - dlg_cont = dlg.Update(progress_percent); + progress_percent = 100.0f * (float)i / (float)total_files + INIT_MODEL_RATIO * 100.0f / (float)total_files; + dlg_cont = dlg.Update(progress_percent); if (!dlg_cont) { q->skip_thumbnail_invalid = false; return empty_result; @@ -9383,17 +9290,13 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (load_model) { // The model should now be initialized - auto convert_from_imperial_units = [](Model& model, bool only_small_volumes) { - model.convert_from_imperial_units(only_small_volumes); - }; + auto convert_from_imperial_units = [](Model &model, bool only_small_volumes) { model.convert_from_imperial_units(only_small_volumes); }; // BBS: add load_old_project logic if ((!is_project_file) && (!load_old_project)) { // if (!is_project_file) { if (int deleted_objects = model.removed_objects_with_zero_volume(); deleted_objects > 0) { - MessageDialog(q, _L("Objects with zero volume removed"), _L("The volume of the object is zero"), - wxICON_INFORMATION | wxOK) - .ShowModal(); + MessageDialog(q, _L("Objects with zero volume removed"), _L("The volume of the object is zero"), wxICON_INFORMATION | wxOK).ShowModal(); } if (imperial_units) // Convert even if the object is big. @@ -9404,18 +9307,16 @@ std::vector Plater::priv::load_files(const std::vector& input_ format_wxstr(_L("The object from file %s is too small, and may be in meters or inches.\nDo you want to scale to millimeters\?"), from_path(filename)), _L("Object too small"), wxICON_QUESTION | wxYES_NO); - int answer = dlg.ShowModal(); - if (answer == wxID_YES) - model.convert_from_meters(true); + int answer = dlg.ShowModal(); + if (answer == wxID_YES) model.convert_from_meters(true); } else if (model.looks_like_imperial_units()) { // BBS do not handle look like in meters MessageDialog dlg(q, format_wxstr(_L("The object from file %s is too small, and may be in meters or inches.\nDo you want to scale to millimeters\?"), from_path(filename)), _L("Object too small"), wxICON_QUESTION | wxYES_NO); - int answer = dlg.ShowModal(); - if (answer == wxID_YES) - convert_from_imperial_units(model, true); + int answer = dlg.ShowModal(); + if (answer == wxID_YES) convert_from_imperial_units(model, true); } // else if (model.looks_like_imperial_units()) { // BBS do not handle look like in imperial @@ -9429,8 +9330,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ // "The dimensions of the object from file %s seem to be defined in inches.\n" // "The internal unit of PrusaSlicer is a millimeter. Do you want to recalculate the dimensions of the object?", // "The dimensions of some objects from file %s seem to be defined in inches.\n" - // "The internal unit of PrusaSlicer is a millimeter. Do you want to recalculate the dimensions of these objects?", - // model.objects.size()), from_path(filename)) + // "The internal unit of PrusaSlicer is a millimeter. Do you want to recalculate the dimensions of these objects?", model.objects.size()), from_path(filename)) // + "\n", _L("The object is too small"), wxICON_QUESTION | wxYES_NO); // dlg.ShowCheckBox(_L("Apply to all the remaining small objects being loaded.")); // int answer = dlg.ShowModal(); @@ -9442,12 +9342,9 @@ std::vector Plater::priv::load_files(const std::vector& input_ // convert_model_if(model, answer_convert_from_imperial_units == wxID_YES); } - if (!is_project_file && model.looks_like_multipart_object()) { - MessageDialog msg_dlg(q, - _L("This file contains several objects positioned at multiple heights.\nInstead of considering them " - "as multiple objects, should \nthe file be loaded as a single object with multiple parts\?") + - "\n", - _L("Multi-part object detected"), wxICON_WARNING | wxYES | wxNO); + if (!is_project_file && model.looks_like_multipart_object()) { + MessageDialog msg_dlg(q, _L("This file contains several objects positioned at multiple heights.\nInstead of considering them as multiple objects, should \nthe file be loaded as a single object with multiple parts\?") + "\n", + _L("Multi-part object detected"), wxICON_WARNING | wxYES | wxNO); if (msg_dlg.ShowModal() == wxID_YES) { model.convert_multipart_object(filaments_cnt); } @@ -9464,15 +9361,15 @@ std::vector Plater::priv::load_files(const std::vector& input_ // return obj_idxs; //} - progress_percent = 100.0f * (float) i / (float) total_files + CENTER_AROUND_ORIGIN_RATIO * 100.0f / (float) total_files; - dlg_cont = dlg.Update(progress_percent); + progress_percent = 100.0f * (float)i / (float)total_files + CENTER_AROUND_ORIGIN_RATIO * 100.0f / (float)total_files; + dlg_cont = dlg.Update(progress_percent); if (!dlg_cont) { q->skip_thumbnail_invalid = false; return empty_result; } int model_idx = 0; - for (ModelObject* model_object : model.objects) { + for (ModelObject *model_object : model.objects) { if (!type_3mf && !type_any_amf) model_object->center_around_origin(false); @@ -9492,8 +9389,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ tolal_model_count += model_idx; - progress_percent = 100.0f * (float) i / (float) total_files + LOAD_MODEL_RATIO * 100.0f / (float) total_files; - dlg_cont = dlg.Update(progress_percent); + progress_percent = 100.0f * (float)i / (float)total_files + LOAD_MODEL_RATIO * 100.0f / (float)total_files; + dlg_cont = dlg.Update(progress_percent); if (!dlg_cont) { q->skip_thumbnail_invalid = false; return empty_result; @@ -9518,7 +9415,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ auto cancel_cb = [&dlg, &dlg_cont]() { return !dlg_cont || dlg.WasCancelled(); }; auto progress_cb = [&dlg, &dlg_cont, &progress_percent](int percent) { progress_percent = std::clamp(percent, 0, 100); - dlg_cont = dlg.Update(progress_percent, _L("Matching textures to filaments")); + dlg_cont = dlg.Update(progress_percent, _L("Matching textures to filaments")); return dlg_cont; }; if (!run_textured_mesh_import_dialog(model, texture_import_result, cancel_cb, progress_cb)) { @@ -9526,7 +9423,9 @@ std::vector Plater::priv::load_files(const std::vector& input_ return empty_result; } if (texture_import_result.fallback_to_geometry_only && !texture_import_result.fallback_warning.empty()) { - MessageDialog(q, texture_import_result.fallback_warning, _L("Texture Import Warning"), wxOK | wxICON_WARNING).ShowModal(); + MessageDialog(q, texture_import_result.fallback_warning, + _L("Texture Import Warning"), + wxOK | wxICON_WARNING).ShowModal(); } if (!texture_import_result.painted.face_colors.empty()) { std::vector texture_object_idxs(model.objects.size()); @@ -9535,12 +9434,12 @@ std::vector Plater::priv::load_files(const std::vector& input_ dlg.Update(std::clamp(percent, 0, 100), msg); return true; }; - apply_textured_mesh_import_result(model, texture_object_idxs, texture_import_result, apply_progress_cb, false); + apply_textured_mesh_import_result(model, texture_object_idxs, texture_import_result, + apply_progress_cb, false); } } - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ - << boost::format(", before load_model_objects, count %1%") % model.objects.size(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format(", before load_model_objects, count %1%")%model.objects.size(); auto loaded_idxs = load_model_objects(model.objects, is_project_file); obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end()); @@ -9553,10 +9452,10 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } else { // This must be an .stl or .obj file, which may contain a maximum of one volume. - for (const ModelObject* model_object : model.objects) { + for (const ModelObject *model_object : model.objects) { new_model->add_object(*model_object); - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":" << __LINE__ << boost::format(", added object %1%") % model_object->name; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":" << __LINE__ << boost::format(", added object %1%")%model_object->name; wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); dlg_cont = dlg.Update(progress_percent, msg); if (!dlg_cont) { @@ -9568,18 +9467,18 @@ std::vector Plater::priv::load_files(const std::vector& input_ } if (new_model != nullptr && new_model->objects.size() > 1) { - // BBS do not popup this dialog + //BBS do not popup this dialog bool new_model_auto_drop = true; int single_object_answer = false; if (ask_multi) { RichMessageDialog dlg(q, _L("Load these files as a single object with multiple parts?\n"), - _L("An object with multiple parts was detected"), wxICON_QUESTION | wxYES_NO); + _L("An object with multiple parts was detected"), wxICON_QUESTION | wxYES_NO); dlg.ShowCheckBox(_L("Auto-Drop"), true); single_object_answer = dlg.ShowModal(); - if (dlg.IsCheckBoxChecked() == false) + if (dlg.IsCheckBoxChecked() == false) new_model_auto_drop = false; // convert to multipart and split after load_model_objects @@ -9591,9 +9490,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ // TODO // DONE always convert to multipart, split afterwards to retain relative position // DONE if !auto_drop move all objects over the z-position 0, so that none are clipped by the bed. - // DONE retain auto_drop (and printable) state when assembling or splitting objects. - // DONE when manually split to object ask users if looks_like_multipart and none have auto_drob disabled if they want to disable - // auto_drop for all resulting objects. + // DONE retain auto_drop (and printable) state when assembling or splitting objects. + // DONE when manually split to object ask users if looks_like_multipart and none have auto_drob disabled if they want to disable auto_drop for all resulting objects. // - add icon in object list, similar to fuzzy painting, etc. auto loaded_idxs = load_model_objects(new_model->objects, false, false, new_model_auto_drop); @@ -9605,48 +9503,41 @@ std::vector Plater::priv::load_files(const std::vector& input_ } if (load_config) { - DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); if (dev) { - MachineObject* obj = dev->get_selected_machine(); + MachineObject *obj = dev->get_selected_machine(); if (obj && obj->is_info_ready()) { if (obj->GetExtderSystem()->GetTotalExtderCount() > 0) { - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - Preset& printer_preset = preset_bundle->printers.get_selected_preset(); + PresetBundle *preset_bundle = wxGetApp().preset_bundle; + Preset &printer_preset = preset_bundle->printers.get_selected_preset(); - double preset_nozzle_diameter = 0.4; - const ConfigOption* opt = printer_preset.config.option("nozzle_diameter"); - if (opt) - preset_nozzle_diameter = static_cast(opt)->values[0]; + double preset_nozzle_diameter = 0.4; + const ConfigOption *opt = printer_preset.config.option("nozzle_diameter"); + if (opt) preset_nozzle_diameter = static_cast(opt)->values[0]; std::string machine_type = obj->printer_type; - if (obj->is_support_upgrade_kit && obj->installed_upgrade_kit) - machine_type = "C12"; + if (obj->is_support_upgrade_kit && obj->installed_upgrade_kit) machine_type = "C12"; bool nozzle_mismatch = !obj->GetExtderSystem()->NozzleDiameterMatchesOrUnknown(0, (float) preset_nozzle_diameter); if (printer_preset.get_current_printer_type(preset_bundle) != machine_type || nozzle_mismatch) { - Preset* machine_preset = get_printer_preset(obj); + Preset *machine_preset = get_printer_preset(obj); if (machine_preset != nullptr) { std::string printer_model = machine_preset->config.option("printer_model")->value; - bool sync_printer_info = false; + bool sync_printer_info = false; if (!wxGetApp().app_config->has("sync_after_load_file_show_flag")) { - wxString tips = from_u8( - (boost::format(_u8L("Connected printer is %s. It must match the project preset for printing.\n")) % - printer_model) - .str()); + wxString tips = from_u8((boost::format(_u8L("Connected printer is %s. It must match the project preset for printing.\n")) % printer_model).str()); tips += _L("Do you want to sync the printer information and automatically switch the preset?"); TipsDialog dlg(wxGetApp().mainframe, _L("Tips"), tips, "sync_after_load_file_show_flag", wxYES_NO); - if (dlg.ShowModal() == wxID_YES) { - sync_printer_info = true; - } - } else { + if (dlg.ShowModal() == wxID_YES) { sync_printer_info = true; } + } + else { sync_printer_info = wxGetApp().app_config->get("sync_after_load_file_show_flag") == "true"; } if (sync_printer_info) { - Tab* printer_tab = GUI::wxGetApp().get_tab(Preset::Type::TYPE_PRINTER); + Tab *printer_tab = GUI::wxGetApp().get_tab(Preset::Type::TYPE_PRINTER); printer_tab->select_preset(machine_preset->name); - if (obj->is_multi_extruders()) - GUI::wxGetApp().sidebar().sync_extruder_list(); + if (obj->is_multi_extruders()) GUI::wxGetApp().sidebar().sync_extruder_list(); } } } @@ -9655,15 +9546,14 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } - if (new_model) - delete new_model; + if (new_model) delete new_model; - // BBS: translate old 3mf to correct positions + //BBS: translate old 3mf to correct positions if (translate_old) { - // translate the objects + //translate the objects int plate_count = partplate_list.get_plate_count(); - for (int index = 1; index < plate_count; index++) { - PartPlate* cur_plate = (PartPlate*) partplate_list.get_plate(index); + for (int index = 1; index < plate_count; index ++) { + PartPlate* cur_plate = (PartPlate *)partplate_list.get_plate(index); Vec3d cur_origin = cur_plate->get_origin(); Vec3d new_origin = partplate_list.compute_origin_using_new_size(index, current_width, current_depth); @@ -9675,46 +9565,50 @@ std::vector Plater::priv::load_files(const std::vector& input_ partplate_list.register_raycasters_for_picking(*view3D->get_canvas3d()); } - // BBS: add gcode loading logic in the end - q->m_exported_file = false; + //BBS: add gcode loading logic in the end + q->m_exported_file = false; q->skip_thumbnail_invalid = false; if (load_model && load_config) { if (model.objects.empty()) { partplate_list.load_gcode_files(); - PartPlate *first_plate = nullptr, *cur_plate = nullptr; + PartPlate * first_plate = nullptr, *cur_plate = nullptr; int plate_cnt = partplate_list.get_plate_count(); int index = 0, first_plate_index = 0; q->m_valid_plates_count = 0; - for (index = 0; index < plate_cnt; index++) { + for (index = 0; index < plate_cnt; index ++) + { cur_plate = partplate_list.get_plate(index); if (!first_plate && cur_plate->is_slice_result_valid()) { - first_plate = cur_plate; + first_plate = cur_plate; first_plate_index = index; } if (cur_plate->is_slice_result_valid()) - q->m_valid_plates_count++; + q->m_valid_plates_count ++; } - if (first_plate && first_plate->is_slice_result_valid()) { + if (first_plate&&first_plate->is_slice_result_valid()) { q->m_exported_file = true; - // select plate 0 as default + //select plate 0 as default q->select_plate(first_plate_index); - // set to 3d tab + //set to 3d tab q->select_view_3D("Preview"); wxGetApp().mainframe->select_tab(TAB_ID_PREVIEW); - } else { - // set to 3d tab + } + else { + //set to 3d tab q->select_view_3D("3D"); - // select plate 0 as default + //select plate 0 as default q->select_plate(0); } - } else { - // set to 3d tab + } + else { + //set to 3d tab q->select_view_3D("3D"); - // select plate 0 as default + //select plate 0 as default q->select_plate(0); } - } else { - // always set to 3D after loading files + } + else { + //always set to 3D after loading files q->select_view_3D("3D"); wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); } @@ -9726,8 +9620,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ view3D->reload_scene(true); view3D->set_as_dirty(); } - if (!silence) - wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().make_preferred().string()); + if (!silence) wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().make_preferred().string()); // XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames... } @@ -9740,7 +9633,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ Selection& selection = view3D->get_canvas3d()->get_selection(); selection.clear(); for (size_t idx : obj_idxs) { - selection.add_object((unsigned int) idx, false); + selection.add_object((unsigned int)idx, false); } } // BBS: update object list selection @@ -9751,25 +9644,25 @@ std::vector Plater::priv::load_files(const std::vector& input_ view3D->get_canvas3d()->update_gizmos_on_off_state(); } - GLGizmoSimplify::add_simplify_suggestion_notification(obj_idxs, model.objects, *notification_manager); + GLGizmoSimplify::add_simplify_suggestion_notification( + obj_idxs, model.objects, *notification_manager); - // set designer_model_id - q->model().stl_design_id = designer_model_id; + //set designer_model_id + q->model().stl_design_id = designer_model_id; q->model().stl_design_country = designer_country_code; - // if (!designer_model_id.empty() && q->model().stl_design_id.empty() && !designer_country_code.empty()) { - // q->model().stl_design_id = designer_model_id; - // q->model().stl_design_country = designer_country_code; - // } - // else { - // q->model().stl_design_id = ""; - // q->model().stl_design_country = ""; - // } + //if (!designer_model_id.empty() && q->model().stl_design_id.empty() && !designer_country_code.empty()) { + // q->model().stl_design_id = designer_model_id; + // q->model().stl_design_country = designer_country_code; + //} + //else { + // q->model().stl_design_id = ""; + // q->model().stl_design_country = ""; + //} if (tolal_model_count <= 0 && !q->m_exported_file) { dlg.Hide(); if (!is_user_cancel) { - MessageDialog msg(wxGetApp().mainframe, _L("The file does not contain any geometry data."), _L("Warning"), - wxYES | wxICON_WARNING); + MessageDialog msg(wxGetApp().mainframe, _L("The file does not contain any geometry data."), _L("Warning"), wxYES | wxICON_WARNING); if (msg.ShowModal() == wxID_YES) {} } } @@ -9778,12 +9671,9 @@ std::vector Plater::priv::load_files(const std::vector& input_ return obj_idxs; } -#define AUTOPLACEMENT_ON_LOAD + #define AUTOPLACEMENT_ON_LOAD -std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& model_objects, - bool allow_negative_z, - bool split_object, - bool auto_drop) +std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& model_objects, bool allow_negative_z, bool split_object, bool auto_drop) { const Vec3d bed_size = Slic3r::to_3d(this->bed.build_volume().bounding_volume2d().size(), 1.0) - 2.0 * Vec3d::Ones(); @@ -9797,8 +9687,8 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& mode #ifdef AUTOPLACEMENT_ON_LOAD ModelInstancePtrs new_instances; #endif /* AUTOPLACEMENT_ON_LOAD */ - for (ModelObject* model_object : model_objects) { - auto* object = model.add_object(*model_object); + for (ModelObject *model_object : model_objects) { + auto *object = model.add_object(*model_object); object->sort_volumes(true); std::string object_name = object->name.empty() ? fs::path(object->input_file).filename().string() : object->name; obj_idxs.push_back(obj_count++); @@ -9807,30 +9697,29 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& mode #ifdef AUTOPLACEMENT_ON_LOAD object->center_around_origin(); new_instances.emplace_back(object->add_instance()); -#else /* AUTOPLACEMENT_ON_LOAD */ +#else /* AUTOPLACEMENT_ON_LOAD */ // if object has no defined position(s) we need to rearrange everything after loading // need_arrange = true; - // add a default instance and center object around origin - object->center_around_origin(); // also aligns object to Z = 0 + // add a default instance and center object around origin + object->center_around_origin(); // also aligns object to Z = 0 ModelInstance* instance = object->add_instance(); - // BBS calc transformation + //BBS calc transformation Geometry::Transformation t = instance->get_transformation(); instance->set_offset(Slic3r::to_3d(this->bed.build_volume().bed_center(), -object->origin_translation(2))); #endif /* AUTOPLACEMENT_ON_LOAD */ } - - // BBS: when the object is too large, let the user choose whether to scale it down + + //BBS: when the object is too large, let the user choose whether to scale it down for (size_t i = 0; i < object->instances.size(); ++i) { ModelInstance* instance = object->instances[i]; - const Vec3d size = object->instance_bounding_box(i).size(); - const Vec3d ratio = size.cwiseQuotient(bed_size); - const double max_ratio = std::max(ratio(0), ratio(1)); + const Vec3d size = object->instance_bounding_box(i).size(); + const Vec3d ratio = size.cwiseQuotient(bed_size); + const double max_ratio = std::max(ratio(0), ratio(1)); if (max_ratio > 10000) { - MessageDialog - dlg(q, _L("Your object appears to be too large, do you want to scale it down to fit the print bed automatically?"), - _L("Object too large"), wxICON_QUESTION | wxYES); - int answer = dlg.ShowModal(); + MessageDialog dlg(q, _L("Your object appears to be too large, do you want to scale it down to fit the print bed automatically?"), _L("Object too large"), + wxICON_QUESTION | wxYES); + int answer = dlg.ShowModal(); // the size of the object is too big -> this could lead to overflow when moving to clipper coordinates, // so scale down the mesh object->scale_mesh_after_creation(1. / max_ratio); @@ -9838,11 +9727,11 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& mode object->center_around_origin(); scaled_down = true; break; - } else if (max_ratio > 10) { - MessageDialog - dlg(q, _L("Your object appears to be too large, do you want to scale it down to fit the print bed automatically?"), - _L("Object too large"), wxICON_QUESTION | wxYES_NO); - int answer = dlg.ShowModal(); + } + else if (max_ratio > 10) { + MessageDialog dlg(q, _L("Your object appears to be too large, do you want to scale it down to fit the print bed automatically?"), _L("Object too large"), + wxICON_QUESTION | wxYES_NO); + int answer = dlg.ShowModal(); if (answer == wxID_YES) { instance->set_scaling_factor(instance->get_scaling_factor() / max_ratio); scaled_down = true; @@ -9852,27 +9741,28 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& mode if (!auto_drop) { for (size_t i = 0; i < object->instances.size(); ++i) { - ModelInstance* instance = object->instances[i]; - instance->auto_drop = auto_drop; + ModelInstance* instance = object->instances[i]; + instance->auto_drop = auto_drop; } // if under the bed, move over the bed double dist_to_bed = std::min(object->min_z(), double(0)); object->translate_instances(Vec3d(0, 0, -dist_to_bed)); - } else { + } + else { object->ensure_on_bed(allow_negative_z); } if (!split_object) { - // BBS initial assemble transformation + //BBS initial assemble transformation for (ModelObject* model_object : model.objects) { - // BBS initialize assemble transformation + //BBS initialize assemble transformation for (int i = 0; i < model_object->instances.size(); i++) { if (!model_object->instances[i]->is_assemble_initialized()) { model_object->instances[i]->set_assemble_transformation(model_object->instances[i]->get_transformation()); } } - } + } } } @@ -9898,7 +9788,7 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& mode #else // BBS: find an empty cell to put the copied object for (auto& instance : new_instances) { - auto offset = instance->get_offset(); + auto offset = instance->get_offset(); auto start_point = this->bed.build_volume().bounding_volume2d().center(); bool plate_empty = partplate_list.get_curr_plate()->empty(); Vec3d displacement; @@ -9914,22 +9804,23 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& mode #endif /* AUTOPLACEMENT_ON_LOAD */ - // BBS: remove the auto scaled_down logic when load models - // if (scaled_down) { - // GUI::show_info(q, - // _L("Your object appears to be too large, so it was automatically scaled down to fit your print bed."), - // _L("Object too large?")); - // } + //BBS: remove the auto scaled_down logic when load models + //if (scaled_down) { + // GUI::show_info(q, + // _L("Your object appears to be too large, so it was automatically scaled down to fit your print bed."), + // _L("Object too large?")); + //} BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format(", finished auto placement, before add_objects_to_list"); notification_manager->close_notification_of_type(NotificationType::UpdatedItemsInfo); if (obj_idxs.size() > 1) { - std::vector obj_idxs_1(obj_idxs.begin(), obj_idxs.end() - 1); + std::vector obj_idxs_1 (obj_idxs.begin(), obj_idxs.end() - 1); wxGetApp().obj_list()->add_objects_to_list(obj_idxs_1, false); wxGetApp().obj_list()->add_object_to_list(obj_idxs[obj_idxs.size() - 1]); - } else + } + else wxGetApp().obj_list()->add_objects_to_list(obj_idxs); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format(", after add_objects_to_list"); @@ -9938,7 +9829,7 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& mode // which is updated after a view3D->reload_scene(false, flags & (unsigned int)UpdateParams::FORCE_FULL_SCREEN_REFRESH) call for (const size_t idx : obj_idxs) wxGetApp().obj_list()->update_info_items(idx); - + object_list_changed(); this->schedule_background_process(); @@ -9950,7 +9841,7 @@ std::vector Plater::priv::load_model_objects(const ModelObjectPtrs& mode void Plater::priv::load_auxiliary_files() { std::string auxiliary_path = encode_path(q->model().get_auxiliary_file_temp_path().c_str()); - // wxGetApp().mainframe->m_project->Reload(auxiliary_path); + //wxGetApp().mainframe->m_project->Reload(auxiliary_path); } fs::path Plater::priv::get_export_file_path(GUI::FileType file_type) @@ -9959,7 +9850,7 @@ fs::path Plater::priv::get_export_file_path(GUI::FileType file_type) this->update_print_volume_state(); const Selection& selection = get_selection(); - int obj_idx = selection.get_object_idx(); + int obj_idx = selection.get_object_idx(); fs::path output_file; if (file_type == FT_3MF) @@ -9968,20 +9859,22 @@ fs::path Plater::priv::get_export_file_path(GUI::FileType file_type) else if (file_type == FT_STL) { if (obj_idx > 0 && obj_idx < this->model.objects.size() && selection.is_single_full_object()) { output_file = this->model.objects[obj_idx]->get_export_filename(); - } else { + } + else { output_file = into_path(get_project_name()); } } - // bbs name the project using the part name + //bbs name the project using the part name if (output_file.empty()) { if (get_project_name() != _L("Untitled")) { output_file = into_path(get_project_name() + ".3mf"); } } - if (output_file.empty()) { + if (output_file.empty()) + { // first try to get the file name from the current selection - if ((0 <= obj_idx) && (obj_idx < (int) this->model.objects.size())) + if ((0 <= obj_idx) && (obj_idx < (int)this->model.objects.size())) output_file = this->model.objects[obj_idx]->get_export_filename(); if (output_file.empty()) @@ -10003,56 +9896,65 @@ wxString Plater::priv::get_export_file(GUI::FileType file_type, const wxString& { wxString wildcard; switch (file_type) { - case FT_STL: - case FT_DRC: - case FT_AMF: - case FT_3MF: - case FT_GCODE: - case FT_OBJ: wildcard = file_wildcards(file_type); break; - default: wildcard = file_wildcards(FT_MODEL); break; + case FT_STL: + case FT_DRC: + case FT_AMF: + case FT_3MF: + case FT_GCODE: + case FT_OBJ: + wildcard = file_wildcards(file_type); + break; + default: + wildcard = file_wildcards(FT_MODEL); + break; } fs::path output_file = get_export_file_path(file_type); wxString dlg_title; switch (file_type) { - case FT_STL: { - output_file.replace_extension("stl"); - dlg_title = _L("Export STL file:"); - break; - } - case FT_DRC: { - output_file.replace_extension("drc"); - dlg_title = _L("Export Draco file:"); - break; - } - case FT_AMF: { - // XXX: Problem on OS X with double extension? - output_file.replace_extension("zip.amf"); - dlg_title = _L("Export AMF file:"); - break; - } - case FT_3MF: { + case FT_STL: + { + output_file.replace_extension("stl"); + dlg_title = _L("Export STL file:"); + break; + } + case FT_DRC: + { + output_file.replace_extension("drc"); + dlg_title = _L("Export Draco file:"); + break; + } + case FT_AMF: + { + // XXX: Problem on OS X with double extension? + output_file.replace_extension("zip.amf"); + dlg_title = _L("Export AMF file:"); + break; + } + case FT_3MF: + { // A published export is suggested as ".published.3mf" so the role is visible in the // dialog and in the recent-files list. This is only a pre-filled suggestion; the user's // typed filename wins, keeping a plain ".3mf" output fully valid. output_file.replace_extension(published ? "published.3mf" : "3mf"); dlg_title = title.empty() ? _L("Save file as") : title; - break; - } - case FT_OBJ: { - output_file.replace_extension("obj"); - dlg_title = _L("Export OBJ file:"); - break; - } - default: break; + break; + } + case FT_OBJ: + { + output_file.replace_extension("obj"); + dlg_title = _L("Export OBJ file:"); + break; + } + default: break; } std::string out_dir = (boost::filesystem::path(output_file).parent_path()).string(); wxFileDialog dlg(q, dlg_title, - is_shapes_dir(out_dir) ? from_u8(wxGetApp().app_config->get_last_dir()) : from_path(output_file.parent_path()), - from_path(output_file.filename()), wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxPD_APP_MODAL); + is_shapes_dir(out_dir) ? from_u8(wxGetApp().app_config->get_last_dir()) : from_path(output_file.parent_path()), from_path(output_file.filename()), + wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxPD_APP_MODAL); int result = dlg.ShowModal(); if (result == wxID_CANCEL) @@ -10068,8 +9970,9 @@ wxString Plater::priv::get_export_file(GUI::FileType file_type, const wxString& boost::system::error_code ec; if (boost::filesystem::exists(into_u8(out_path), ec)) { auto result = MessageBox(q->GetHandle(), - wxString::Format(_L("The file %s already exists.\nDo you want to replace it\?"), out_path), - _L("Confirm Save As"), MB_YESNO | MB_ICONWARNING); + wxString::Format(_L("The file %s already exists.\nDo you want to replace it\?"), out_path), + _L("Confirm Save As"), + MB_YESNO | MB_ICONWARNING); if (result != IDYES) return wxEmptyString; } @@ -10080,11 +9983,20 @@ wxString Plater::priv::get_export_file(GUI::FileType file_type, const wxString& return out_path; } -const Selection& Plater::priv::get_selection() const { return view3D->get_canvas3d()->get_selection(); } +const Selection& Plater::priv::get_selection() const +{ + return view3D->get_canvas3d()->get_selection(); +} -Selection& Plater::priv::get_selection() { return view3D->get_canvas3d()->get_selection(); } +Selection& Plater::priv::get_selection() +{ + return view3D->get_canvas3d()->get_selection(); +} -Selection& Plater::priv::get_curr_selection() { return get_current_canvas3D()->get_selection(); } +Selection& Plater::priv::get_curr_selection() +{ + return get_current_canvas3D()->get_selection(); +} int Plater::priv::get_selected_object_idx() const { @@ -10095,9 +10007,9 @@ int Plater::priv::get_selected_object_idx() const int Plater::priv::get_selected_volume_idx() const { auto& selection = get_selection(); - int idx = selection.get_object_idx(); + int idx = selection.get_object_idx(); if ((0 > idx) || (idx > 1000)) - return -1; + return-1; const GLVolume* v = selection.get_first_volume(); if (model.objects[idx]->volumes.size() > 1) return v->volume_idx(); @@ -10124,22 +10036,21 @@ void Plater::priv::object_list_changed() { const bool export_in_progress = this->background_process.is_export_scheduled(); // || ! send_gcode_file.empty()); // XXX: is this right? - // const bool model_fits = view3D->get_canvas3d()->check_volumes_outside_state() == ModelInstancePVS_Inside; + //const bool model_fits = view3D->get_canvas3d()->check_volumes_outside_state() == ModelInstancePVS_Inside; ObjectFilamentResults object_results; bool model_fits = view3D->get_canvas3d()->check_volumes_outside_state(&object_results) != ModelInstancePVS_Partly_Outside; - model_fits = model_fits && object_results.filaments.empty(); + model_fits = model_fits && object_results.filaments.empty(); PartPlate* part_plate = partplate_list.get_curr_plate(); // BBS - // sidebar->enable_buttons(!model.objects.empty() && !export_in_progress && model_fits && part_plate->has_printable_instances()); + //sidebar->enable_buttons(!model.objects.empty() && !export_in_progress && model_fits && part_plate->has_printable_instances()); // A mixed filament with deleted or type-mismatched components cannot be resolved at slicing // time, so block the slice buttons the same way MainFrame::get_enable_slice_status() does. bool mixed_broken = sidebar->has_broken_mixed_filament(); - bool can_slice = !model.objects.empty() && !export_in_progress && model_fits && part_plate->has_printable_instances() && !mixed_broken; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": can_slice %1%, model_fits= %2%, export_in_progress %3%, has_printable_instances %4% ") % - can_slice % model_fits % export_in_progress % part_plate->has_printable_instances(); + bool can_slice = !model.objects.empty() && !export_in_progress && model_fits && part_plate->has_printable_instances() + && !mixed_broken; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": can_slice %1%, model_fits= %2%, export_in_progress %3%, has_printable_instances %4% ")%can_slice %model_fits %export_in_progress %part_plate->has_printable_instances(); main_frame->update_slice_print_status(MainFrame::eEventObjectUpdate, can_slice); wxGetApp().params_panel()->notify_object_config_changed(); @@ -10166,9 +10077,15 @@ void Plater::priv::select_all() this->sidebar->obj_list()->update_selections(); } -void Plater::priv::deselect_all() { view3D->deselect_all(); } +void Plater::priv::deselect_all() +{ + view3D->deselect_all(); +} -void Plater::priv::exit_gizmo() { view3D->exit_gizmo(); } +void Plater::priv::exit_gizmo() +{ + view3D->exit_gizmo(); +} void Plater::priv::remove(size_t obj_idx) { @@ -10177,7 +10094,7 @@ void Plater::priv::remove(size_t obj_idx) m_worker.cancel_all(); model.delete_object(obj_idx); - // BBS: notify partplate the instance removed + //BBS: notify partplate the instance removed partplate_list.notify_instance_removed(obj_idx, -1); update(); // Delete object from Sidebar list. Do it after update, so that the GLScene selection is updated with the modified model. @@ -10185,15 +10102,15 @@ void Plater::priv::remove(size_t obj_idx) object_list_changed(); } + bool Plater::priv::delete_object_from_model(size_t obj_idx, bool refresh_immediately) { // check if object isn't cut // show warning message that "cut consistancy" will not be supported any more - ModelObject* obj = model.objects[obj_idx]; + ModelObject *obj = model.objects[obj_idx]; if (obj->is_cut()) { InfoDialog dialog(q, _L("Delete object which is a part of cut object"), - _L("You are trying to delete an object which is a part of a cut object.\nThis action will break a cut " - "correspondence.\nAfter that, model consistency can\'t be guaranteed."), + _L("You are trying to delete an object which is a part of a cut object.\nThis action will break a cut correspondence.\nAfter that, model consistency can\'t be guaranteed."), false, wxYES | wxCANCEL | wxCANCEL_DEFAULT | wxICON_WARNING); dialog.SetButtonLabel(wxID_YES, _L("Delete")); if (dialog.ShowModal() == wxID_CANCEL) @@ -10210,10 +10127,10 @@ bool Plater::priv::delete_object_from_model(size_t obj_idx, bool refresh_immedia sidebar->obj_list()->invalidate_cut_info_for_object(obj_idx); model.delete_object(obj_idx); - // BBS: notify partplate the instance removed + //BBS: notify partplate the instance removed partplate_list.notify_instance_removed(obj_idx, -1); - // BBS + //BBS if (refresh_immediately) { update(); object_list_changed(); @@ -10239,7 +10156,7 @@ void Plater::priv::delete_all_objects_from_model() // Stop and reset the Print content. background_process.reset(); - // BBS: update partplate + //BBS: update partplate partplate_list.clear(); model.clear_objects(); @@ -10248,7 +10165,7 @@ void Plater::priv::delete_all_objects_from_model() sidebar->obj_list()->delete_all_objects_from_list(); object_list_changed(); - // BBS + //BBS model.calib_pa_pattern.reset(); model.plates_custom_gcodes.clear(); } @@ -10272,16 +10189,16 @@ void Plater::priv::reset(bool apply_presets_change) view3D->get_canvas3d()->reset_all_gizmos(); reset_gcode_toolpaths(); - // BBS: update gcode to current partplate's - // GCodeProcessorResult* current_result = this->background_process.get_current_plate()->get_slice_result(); - // current_result->reset(); - // gcode_result.reset(); + //BBS: update gcode to current partplate's + //GCodeProcessorResult* current_result = this->background_process.get_current_plate()->get_slice_result(); + //current_result->reset(); + //gcode_result.reset(); view3D->get_canvas3d()->reset_sequential_print_clearance(); m_worker.cancel_all(); - // BBS: clear the partplate list's object before object cleared + //BBS: clear the partplate list's object before object cleared partplate_list.reinit(); partplate_list.update_slice_context_to_current_plate(background_process); preview->update_gcode_result(partplate_list.get_current_slice_result()); @@ -10292,7 +10209,7 @@ void Plater::priv::reset(bool apply_presets_change) assemble_view->get_canvas3d()->reset_explosion_ratio(); update(); - // BBS + //BBS if (wxGetApp().is_editor()) { // Delete object from Sidebar list. Do it after update, so that the GLScene selection is updated with the modified model. sidebar->obj_list()->delete_all_objects_from_list(); @@ -10302,14 +10219,14 @@ void Plater::priv::reset(bool apply_presets_change) project.reset(); wxGetApp().sidebar().printer_combox()->clear_selected_dev_id(); - // BBS: reset all project embedded presets + //BBS: reset all project embedded presets wxGetApp().preset_bundle->reset_project_embedded_presets(); if (apply_presets_change) wxGetApp().apply_keeped_preset_modifications(); else wxGetApp().load_current_presets(false, false); - // BBS + //BBS model.calib_pa_pattern.reset(); model.plates_custom_gcodes.clear(); @@ -10328,19 +10245,28 @@ void Plater::priv::reset(bool apply_presets_change) } } -void Plater::priv::center_selection() { view3D->center_selected(); } +void Plater::priv::center_selection() +{ + view3D->center_selected(); +} -void Plater::priv::drop_selection() { view3D->drop_selected(); } +void Plater::priv::drop_selection() +{ + view3D->drop_selected(); +} -void Plater::priv::mirror(Axis axis) { view3D->mirror_selection(axis); } +void Plater::priv::mirror(Axis axis) +{ + view3D->mirror_selection(axis); +} -void Plater::find_new_position(const ModelInstancePtrs& instances) +void Plater::find_new_position(const ModelInstancePtrs &instances) { arrangement::ArrangePolygons movable, fixed; arrangement::ArrangeParams arr_params = init_arrange_params(this); - for (const ModelObject* mo : p->model.objects) - for (ModelInstance* inst : mo->instances) { + for (const ModelObject *mo : p->model.objects) + for (ModelInstance *inst : mo->instances) { auto it = std::find(instances.begin(), instances.end(), inst); arrangement::ArrangePolygon arrpoly; inst->get_arrange_polygon(&arrpoly); @@ -10348,7 +10274,7 @@ void Plater::find_new_position(const ModelInstancePtrs& instances) if (it == instances.end()) fixed.emplace_back(std::move(arrpoly)); else { - arrpoly.setter = [it](const arrangement::ArrangePolygon& p) { + arrpoly.setter = [it](const arrangement::ArrangePolygon &p) { if (p.is_arranged() && p.bed_idx == 0) { Vec2d t = p.translation.cast(); (*it)->apply_arrange_result(t, p.rotation); @@ -10363,13 +10289,13 @@ void Plater::find_new_position(const ModelInstancePtrs& instances) arrangement::arrange(movable, fixed, this->build_volume().polygon(), arr_params); - for (auto& m : movable) + for (auto & m : movable) m.apply(); } // split selected object into multiple objects by its volumes void Plater::priv::split_object(bool auto_drop /* = true */) -{ +{ int obj_idx = get_selected_object_idx(); priv::split_object(obj_idx, auto_drop); } @@ -10382,7 +10308,7 @@ void Plater::priv::split_object(int obj_idx, bool auto_drop /* = true */) // we clone model object because split_object() adds the split volumes // into the same model object, thus causing duplicates when we call load_model_objects() - Model new_model = model; + Model new_model = model; ModelObject* current_model_object = new_model.objects[obj_idx]; wxBusyCursor wait; @@ -10391,10 +10317,11 @@ void Plater::priv::split_object(int obj_idx, bool auto_drop /* = true */) if (new_objects.size() == 1) // #ysFIXME use notification Slic3r::GUI::warning_catcher(q, _L("The selected object couldn't be split.")); - else { + else + { // BBS no solid parts removed // If we splited object which is contain some parts/modifiers then all non-solid parts (modifiers) were deleted - // if (current_model_object->volumes.size() > 1 && current_model_object->volumes.size() != new_objects.size()) + //if (current_model_object->volumes.size() > 1 && current_model_object->volumes.size() != new_objects.size()) // notification_manager->push_notification(NotificationType::CustomNotification, // NotificationManager::NotificationLevel::PrintInfoNotificationLevel, // _u8L("All non-solid parts (modifiers) were deleted")); @@ -10403,15 +10330,15 @@ void Plater::priv::split_object(int obj_idx, bool auto_drop /* = true */) auto is_atleast_one_floating = [new_objects]() { for (ModelObject* new_object : new_objects) { - if (new_object->get_instance_min_z(0) >= SINKING_MIN_Z_THRESHOLD) + if (new_object->get_instance_min_z(0) >= SINKING_MIN_Z_THRESHOLD) return true; } return false; }; bool split_auto_drop = auto_drop; if (current_model_object->instances[0]->auto_drop && is_atleast_one_floating()) { - MessageDialog dlg(q, _L("Disable Auto-Drop to preserve Z positioning?\n"), _L("Object with floating parts was detected"), - wxICON_QUESTION | wxYES_NO); + MessageDialog dlg(q, _L("Disable Auto-Drop to preserve Z positioning?\n"), + _L("Object with floating parts was detected"), wxICON_QUESTION | wxYES_NO); if (dlg.ShowModal() == wxID_YES) split_auto_drop = false; @@ -10421,19 +10348,23 @@ void Plater::priv::split_object(int obj_idx, bool auto_drop /* = true */) // load all model objects at once, otherwise the plate would be rearranged after each one // causing original positions not to be kept - // BBS: set split_object to true to avoid re-compute assemble matrix + //BBS: set split_object to true to avoid re-compute assemble matrix std::vector idxs = load_model_objects(new_objects, false, true, split_auto_drop); wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_objects(idxs); // select newly added objects - for (size_t idx : idxs) { - get_selection().add_object((unsigned int) idx, false); + for (size_t idx : idxs) + { + get_selection().add_object((unsigned int)idx, false); } } } -void Plater::priv::split_volume() { wxGetApp().obj_list()->split(); } +void Plater::priv::split_volume() +{ + wxGetApp().obj_list()->split(); +} void Plater::priv::scale_selection_to_fit_print_volume() { @@ -10546,11 +10477,11 @@ int Plater::priv::auto_slice_delay_seconds() const std::vector> Plater::priv::get_extruder_filament_info() { std::vector> filament_infos; - DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); if (!dev) return filament_infos; - MachineObject* obj_ = dev->get_selected_machine(); + MachineObject *obj_ = dev->get_selected_machine(); if (obj_ == nullptr) return filament_infos; @@ -10563,97 +10494,90 @@ std::vector> Plater::priv::get_extruder_filament void Plater::priv::update_print_volume_state() { - // BBS: use the plate's bounding box instead of the bed's + //BBS: use the plate's bounding box instead of the bed's PartPlate* pp = partplate_list.get_curr_plate(); - BuildVolume build_volume(pp->get_shape(), this->bed.build_volume().printable_height(), this->bed.build_volume().extruder_areas(), - this->bed.build_volume().extruder_heights()); + BuildVolume build_volume(pp->get_shape(), this->bed.build_volume().printable_height(), this->bed.build_volume().extruder_areas(), this->bed.build_volume().extruder_heights()); this->model.update_print_volume_state(build_volume); } -void Plater::priv::process_validation_warning(StringObjectException const& warning) const +void Plater::priv::process_validation_warning(StringObjectException const &warning) const { if (warning.string.empty()) notification_manager->close_notification_of_type(NotificationType::ValidateWarning); else { std::string text = warning.string; - auto po = dynamic_cast(warning.object); - auto mo = po ? po->model_object() : dynamic_cast(warning.object); - // ORCA: Update process_validation_warning to handle ModelInstance selection and include fallback - auto mi = dynamic_cast(warning.object); + auto po = dynamic_cast(warning.object); + auto mo = po ? po->model_object() : dynamic_cast(warning.object); + //ORCA: Update process_validation_warning to handle ModelInstance selection and include fallback + auto mi = dynamic_cast(warning.object); - auto action_fn = (mo || mi || !warning.opt_key.empty()) ? - [id = mo ? mo->id() : (mi ? mi->id() : 0), parent_id = mi ? mi->get_object()->id() : 0, - is_inst = (mi != nullptr), opt = warning.opt_key](wxEvtHandler*) { - auto& objects = wxGetApp().model().objects; + auto action_fn = (mo || mi || !warning.opt_key.empty()) ? [id = mo ? mo->id() : (mi ? mi->id() : 0), + parent_id = mi ? mi->get_object()->id() : 0, + is_inst = (mi != nullptr), + opt = warning.opt_key](wxEvtHandler *) { + auto & objects = wxGetApp().model().objects; - if (is_inst) { - bool selected = false; - auto iter = std::find_if(objects.begin(), objects.end(), - [parent_id](auto o) { return o->id() == parent_id; }); - if (iter != objects.end()) { - ModelObject* obj = *iter; - int inst_idx = -1; - for (size_t i = 0; i < obj->instances.size(); ++i) { - if (obj->instances[i]->id() == id) { - inst_idx = i; - break; - } - } + if (is_inst) { + bool selected = false; + auto iter = std::find_if(objects.begin(), objects.end(), [parent_id](auto o) { return o->id() == parent_id; }); + if (iter != objects.end()) { + ModelObject* obj = *iter; + int inst_idx = -1; + for(size_t i=0; iinstances.size(); ++i) { + if (obj->instances[i]->id() == id) { + inst_idx = i; + break; + } + } - wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); + wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); - if (inst_idx != -1) { - auto* model = wxGetApp().obj_list()->GetModel(); - wxDataViewItem item; - wxDataViewItem objItem = model->GetObjectItem(obj); - if (objItem.IsOk()) { - int vm_obj_idx = model->GetIdByItem(objItem); - if (vm_obj_idx != -1) { - item = model->GetItemByInstanceId(vm_obj_idx, inst_idx); - } - } - if (item.IsOk()) { - wxDataViewItemArray sel_items; - sel_items.Add(item); - wxGetApp().obj_list()->select_items(sel_items); - wxGetApp().obj_list()->update_selections_on_canvas(); - selected = true; - } - } + if (inst_idx != -1) { + auto* model = wxGetApp().obj_list()->GetModel(); + wxDataViewItem item; + wxDataViewItem objItem = model->GetObjectItem(obj); + if (objItem.IsOk()) { + int vm_obj_idx = model->GetIdByItem(objItem); + if (vm_obj_idx != -1) { + item = model->GetItemByInstanceId(vm_obj_idx, inst_idx); + } + } + if (item.IsOk()) { + wxDataViewItemArray sel_items; + sel_items.Add(item); + wxGetApp().obj_list()->select_items(sel_items); + wxGetApp().obj_list()->update_selections_on_canvas(); + selected = true; + } + } - if (!selected) { - wxGetApp().obj_list()->select_items({{obj, nullptr}}); - wxGetApp().obj_list()->update_selections_on_canvas(); - } - } - } else { - auto iter = id.id ? - std::find_if(objects.begin(), objects.end(), [id](auto o) { return o->id() == id; }) : - objects.end(); - if (iter != objects.end()) { - wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); - wxGetApp().obj_list()->select_items({{*iter, nullptr}}); - wxGetApp().obj_list()->update_selections_on_canvas(); - } - } - if (!opt.empty()) { - if ((!is_inst && id.id) || (is_inst && parent_id.id)) - wxGetApp().params_panel()->switch_to_object(); - wxGetApp().sidebar().jump_to_option(opt, Preset::TYPE_PRINT, L""); - } - return false; - } : - std::function(); + if (!selected) { + wxGetApp().obj_list()->select_items({ {obj, nullptr} }); + wxGetApp().obj_list()->update_selections_on_canvas(); + } + } + } else { + auto iter = id.id ? std::find_if(objects.begin(), objects.end(), [id](auto o) { return o->id() == id; }) : objects.end(); + if (iter != objects.end()) { + wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); + wxGetApp().obj_list()->select_items({{*iter, nullptr}}); + wxGetApp().obj_list()->update_selections_on_canvas(); + } + } + if (!opt.empty()) { + if ((!is_inst && id.id) || (is_inst && parent_id.id)) + wxGetApp().params_panel()->switch_to_object(); + wxGetApp().sidebar().jump_to_option(opt, Preset::TYPE_PRINT, L""); + } + return false; + } : std::function(); auto hypertext = (mo || mi || !warning.opt_key.empty()) ? _u8L("Jump to") : ""; - if (mo) - hypertext += std::string(" [") + mo->name + "]"; - if (mi) - hypertext += std::string(" [") + mi->get_object()->name + "]"; - if (!warning.opt_key.empty()) - hypertext += std::string(" (") + warning.opt_key + ")"; + if (mo) hypertext += std::string(" [") + mo->name + "]"; + if (mi) hypertext += std::string(" [") + mi->get_object()->name + "]"; + if (!warning.opt_key.empty()) hypertext += std::string(" (") + warning.opt_key + ")"; // BBS disable support enforcer - // if (text == "_SUPPORTS_OFF") { + //if (text == "_SUPPORTS_OFF") { // text = _u8L("An object has custom support enforcers which will not be used " // "because supports are disabled.")+"\n"; // hypertext = _u8L("Enable supports for enforcers only"); @@ -10670,21 +10594,24 @@ void Plater::priv::process_validation_warning(StringObjectException const& warni // }; //} - notification_manager->push_notification(NotificationType::ValidateWarning, - NotificationManager::NotificationLevel::WarningNotificationLevel, - _u8L("WARNING:") + "\n" + text, hypertext, action_fn); + notification_manager->push_notification( + NotificationType::ValidateWarning, + NotificationManager::NotificationLevel::WarningNotificationLevel, + _u8L("WARNING:") + "\n" + text, hypertext, action_fn + ); } } -void Plater::priv::process_validation_warnings(const std::vector& warnings) const +void Plater::priv::process_validation_warnings(const std::vector &warnings) const { // ValidateWarning stacks by text (m_multiple_types), so clear the stale set before re-adding. notification_manager->close_notification_of_type(NotificationType::ValidateWarning); - for (const StringObjectException& warning : warnings) + for (const StringObjectException &warning : warnings) if (!warning.string.empty()) process_validation_warning(warning); } + // Update background processing thread from the current config and Model. // Returns a bitmask of UpdateBackgroundProcessReturnState. unsigned int Plater::priv::update_background_process(bool force_validation, bool postpone_error_messages, bool switch_print) @@ -10698,52 +10625,50 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool // Update the "out of print bed" state of ModelInstances. update_print_volume_state(); // Apply new config to the possibly running background task. - bool was_running = background_process.running(); - // BBS: add the switch print logic before Print::Apply - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format( - ": enter, force_validation=%1% postpone_error_messages=%2%, switch_print=%3%, was_running=%4%") % - force_validation % postpone_error_messages % switch_print % was_running; - if (switch_print) { - // BBS: update the current print to the current plate + bool was_running = background_process.running(); + //BBS: add the switch print logic before Print::Apply + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, force_validation=%1% postpone_error_messages=%2%, switch_print=%3%, was_running=%4%")%force_validation %postpone_error_messages %switch_print %was_running; + if (switch_print) + { + //BBS: update the current print to the current plate this->partplate_list.update_slice_context_to_current_plate(background_process); this->preview->update_gcode_result(partplate_list.get_current_slice_result()); } - background_process.fff_print()->set_check_multi_filaments_compatibility( - wxGetApp().app_config->get("enable_high_low_temp_mixed_printing") == "false"); + background_process.fff_print()->set_check_multi_filaments_compatibility(wxGetApp().app_config->get("enable_high_low_temp_mixed_printing") == "false"); Print::ApplyStatus invalidated; const auto& preset_bundle = wxGetApp().preset_bundle; if (preset_bundle->get_printer_extruder_count() > 1) { - PartPlate* cur_plate = background_process.get_current_plate(); - std::vector f_maps = cur_plate->get_real_filament_maps(preset_bundle->project_config); + PartPlate* cur_plate = background_process.get_current_plate(); + std::vector f_maps = cur_plate->get_real_filament_maps(preset_bundle->project_config); std::vector f_volume_maps = cur_plate->get_filament_volume_maps(); if (f_volume_maps.empty()) { f_volume_maps = preset_bundle->get_default_nozzle_volume_types_for_filaments(f_maps); } invalidated = background_process.apply(this->model, preset_bundle->full_config(false, f_maps, f_volume_maps)); background_process.fff_print()->set_extruder_filament_info(get_extruder_filament_info()); - } else + } + else invalidated = background_process.apply(this->model, preset_bundle->full_config(false)); if ((invalidated == Print::APPLY_STATUS_CHANGED) || (invalidated == Print::APPLY_STATUS_INVALIDATED)) // BBS: add only gcode mode q->set_only_gcode(false); - // BBS: add slicing related logs - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": background process apply result=%1%") % invalidated; + //BBS: add slicing related logs + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": background process apply result=%1%")%invalidated; if (background_process.empty()) view3D->get_canvas3d()->reset_sequential_print_clearance(); if (invalidated == Print::APPLY_STATUS_INVALIDATED) { - // BBS: update current plater's slicer result to invalid + //BBS: update current plater's slicer result to invalid this->background_process.get_current_plate()->update_slice_result_valid_state(false); - // no need, should be done in background_process.apply - // this->background_process.get_current_gcode_result()->reset(); - // Reset preview canvases. If the print has been invalidated, the preview canvases will be cleared. - // Otherwise they will be just refreshed. + //no need, should be done in background_process.apply + //this->background_process.get_current_gcode_result()->reset(); + // Reset preview canvases. If the print has been invalidated, the preview canvases will be cleared. + // Otherwise they will be just refreshed. if (preview != nullptr) { // If the preview is not visible, the following line just invalidates the preview, // but the G-code paths or SLA preview are calculated first once the preview is made visible. @@ -10756,27 +10681,28 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool return_state |= UPDATE_BACKGROUND_PROCESS_REFRESH_SCENE; notification_manager->set_slicing_progress_hidden(); - } else { + } + else { if (preview && preview->get_reload_paint_after_background_process_apply()) { preview->set_reload_paint_after_background_process_apply(false); preview->reload_print(); } } - if ((invalidated != Print::APPLY_STATUS_UNCHANGED || force_validation) && !background_process.empty()) { + if ((invalidated != Print::APPLY_STATUS_UNCHANGED || force_validation) && ! background_process.empty()) { // The delayed error message is no more valid. delayed_error_message.clear(); // The state of the Print changed, and it is non-zero. Let's validate it and give the user feedback on errors. - // BBS: add is_warning logic + //BBS: add is_warning logic std::vector warnings; - // BBS: refine seq-print logic + //BBS: refine seq-print logic Polygons polygons; std::vector> height_polygons; StringObjectException err = background_process.validate(&warnings, &polygons, &height_polygons); // update string by type q->post_process_string_object_exception(err); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": validate err=%1%, warnings=%2%") % err.string % warnings.size(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": validate err=%1%, warnings=%2%")%err.string%warnings.size(); if (err.string.empty()) { this->partplate_list.get_curr_plate()->update_apply_result_invalid(false); @@ -10793,88 +10719,92 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool view3D->get_canvas3d()->set_as_dirty(); view3D->get_canvas3d()->request_extra_frame(); } - } else { + } + else { this->partplate_list.get_curr_plate()->update_apply_result_invalid(true); // The print is not valid. // Show error as notification. notification_manager->push_validate_error_notification(err); - // also update the warnings + //also update the warnings process_validation_warnings(warnings); return_state |= UPDATE_BACKGROUND_PROCESS_INVALID; if (printer_technology == ptFFF) { const Print* print = background_process.fff_print(); - // Polygons polygons; - // if (print->config().print_sequence == PrintSequence::ByObject) - // Print::sequential_print_clearance_valid(*print, &polygons); + //Polygons polygons; + //if (print->config().print_sequence == PrintSequence::ByObject) + // Print::sequential_print_clearance_valid(*print, &polygons); view3D->get_canvas3d()->set_sequential_print_clearance_visible(true); view3D->get_canvas3d()->set_sequential_print_clearance_render_fill(true); view3D->get_canvas3d()->set_sequential_print_clearance_polygons(polygons, height_polygons); } } - } else if (!this->delayed_error_message.empty()) { + } + else if (! this->delayed_error_message.empty()) { // Reusing the old state. return_state |= UPDATE_BACKGROUND_PROCESS_INVALID; } - // actualizate warnings + //actualizate warnings if (invalidated != Print::APPLY_STATUS_UNCHANGED || background_process.empty()) { if (background_process.empty()) process_validation_warning({}); actualize_slicing_warnings(*this->background_process.current_print()); actualize_object_warnings(*this->background_process.current_print()); - show_warning_dialog = false; + show_warning_dialog = false; process_completed_with_error = -1; } - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format( - ", Line %1%: was_running = %2%, running %3%, invalidated=%4%, return_state=%5%, internal_cancel=%6%") % - __LINE__ % was_running % this->background_process.running() % invalidated % return_state % - this->background_process.is_internal_cancelled(); - if (was_running && !this->background_process.running() && (return_state & UPDATE_BACKGROUND_PROCESS_RESTART) == 0) { - if (invalidated != Print::APPLY_STATUS_UNCHANGED || this->background_process.is_internal_cancelled()) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: was_running = %2%, running %3%, invalidated=%4%, return_state=%5%, internal_cancel=%6%") + % __LINE__ % was_running % this->background_process.running() % invalidated % return_state % this->background_process.is_internal_cancelled(); + if (was_running && ! this->background_process.running() && (return_state & UPDATE_BACKGROUND_PROCESS_RESTART) == 0) { + if (invalidated != Print::APPLY_STATUS_UNCHANGED || this->background_process.is_internal_cancelled()) + { // The background processing was killed and it will not be restarted. // Post the "canceled" callback message, so that it will be processed after any possible pending status bar update messages. - SlicingProcessCompletedEvent evt(EVT_PROCESS_COMPLETED, 0, SlicingProcessCompletedEvent::Cancelled, nullptr); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(" %1%, post an EVT_PROCESS_COMPLETED to main, status %2%") % __LINE__ % evt.status(); + SlicingProcessCompletedEvent evt(EVT_PROCESS_COMPLETED, 0, + SlicingProcessCompletedEvent::Cancelled, nullptr); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%, post an EVT_PROCESS_COMPLETED to main, status %2%")%__LINE__ %evt.status(); wxQueueEvent(q, evt.Clone()); } } - if ((return_state & UPDATE_BACKGROUND_PROCESS_INVALID) != 0) { + if ((return_state & UPDATE_BACKGROUND_PROCESS_INVALID) != 0) + { // Validation of the background data failed. - // BBS: add slice&&print status update logic + //BBS: add slice&&print status update logic this->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, false); process_completed_with_error = partplate_list.get_curr_plate_index(); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(", Line %1%: set to process_completed_with_error, return_state=%2%") % __LINE__ % - return_state; - } else { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: set to process_completed_with_error, return_state=%2%")%__LINE__%return_state; + } + else + { // Background data is valid. - if ((return_state & UPDATE_BACKGROUND_PROCESS_RESTART) != 0 || (return_state & UPDATE_BACKGROUND_PROCESS_REFRESH_SCENE) != 0) + if ((return_state & UPDATE_BACKGROUND_PROCESS_RESTART) != 0 || + (return_state & UPDATE_BACKGROUND_PROCESS_REFRESH_SCENE) != 0 ) notification_manager->set_slicing_progress_hidden(); - // BBS: add slice&&print status update logic - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(", Line %1%: background data valid, return_state=%2%") % __LINE__ % return_state; + //BBS: add slice&&print status update logic + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: background data valid, return_state=%2%")%__LINE__%return_state; PartPlate* cur_plate = background_process.get_current_plate(); - if (background_process.finished() && cur_plate && cur_plate->is_slice_result_valid()) { - // ready_to_slice = false; + if (background_process.finished() && cur_plate && cur_plate->is_slice_result_valid()) + { + //ready_to_slice = false; this->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, false); - } else if (!background_process.empty() && - !background_process.running()) /* Do not update buttons if background process is running - * This condition is important for SLA mode especially, - * when this function is called several times during calculations - * */ + } + else if (!background_process.empty() && + !background_process.running()) /* Do not update buttons if background process is running + * This condition is important for SLA mode especially, + * when this function is called several times during calculations + * */ { if (cur_plate->can_slice()) { - // ready_to_slice = true; + //ready_to_slice = true; this->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, true); process_completed_with_error = -1; - } else { - // ready_to_slice = false; + } + else { + //ready_to_slice = false; this->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, false); process_completed_with_error = partplate_list.get_curr_plate_index(); } @@ -10898,7 +10828,7 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool #endif } - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: exit, return_state=%2%") % __LINE__ % return_state; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: exit, return_state=%2%")%__LINE__%return_state; return return_state; } @@ -10907,33 +10837,36 @@ bool Plater::priv::restart_background_process(unsigned int state) { if (!m_worker.is_idle()) { // Avoid a race condition - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: ui jobs running, return false") % __LINE__; + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: ui jobs running, return false")%__LINE__; return false; } - if (!this->background_process.empty() && (state & priv::UPDATE_BACKGROUND_PROCESS_INVALID) == 0 && - (((state & UPDATE_BACKGROUND_PROCESS_FORCE_RESTART) != 0 && !this->background_process.finished()) || - (state & UPDATE_BACKGROUND_PROCESS_FORCE_EXPORT) != 0 || (state & UPDATE_BACKGROUND_PROCESS_RESTART) != 0)) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: print is valid, try to start it now") % __LINE__; + if ( ! this->background_process.empty() && + (state & priv::UPDATE_BACKGROUND_PROCESS_INVALID) == 0 && + ( ((state & UPDATE_BACKGROUND_PROCESS_FORCE_RESTART) != 0 && ! this->background_process.finished()) || + (state & UPDATE_BACKGROUND_PROCESS_FORCE_EXPORT) != 0 || + (state & UPDATE_BACKGROUND_PROCESS_RESTART) != 0 ) ) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: print is valid, try to start it now")%__LINE__; // The print is valid and it can be started. if (this->background_process.start()) { if (!show_warning_dialog) on_slicing_began(); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: start successfully") % __LINE__; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: start successfully")%__LINE__; return true; } - } else if (this->background_process.empty()) { + } + else if (this->background_process.empty()) { PartPlate* cur_plate = background_process.get_current_plate(); if (cur_plate->is_slice_result_valid() && ((state & UPDATE_BACKGROUND_PROCESS_FORCE_RESTART) != 0)) { if (this->background_process.start()) { if (!show_warning_dialog) on_slicing_began(); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: start successfully") % __LINE__; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: start successfully")%__LINE__; return true; } } } - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: not started") % __LINE__; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: not started")%__LINE__; return false; } @@ -10941,7 +10874,7 @@ void Plater::priv::export_gcode(fs::path output_path, bool output_path_on_remova { wxCHECK_RET(!(output_path.empty()), "export_gcode: output_path and upload_job empty"); - BOOST_LOG_TRIVIAL(trace) << boost::format("export_gcode: output_path %1%") % output_path.string(); + BOOST_LOG_TRIVIAL(trace) << boost::format("export_gcode: output_path %1%")%output_path.string(); if (model.objects.empty()) return; @@ -10959,9 +10892,9 @@ void Plater::priv::export_gcode(fs::path output_path, bool output_path_on_remova return; show_warning_dialog = true; - if (!output_path.empty()) { + if (! output_path.empty()) { background_process.schedule_export(output_path.string(), output_path_on_removable_media); - notification_manager->push_delayed_notification(NotificationType::ExportOngoing, []() { return true; }, 1000, 0); + notification_manager->push_delayed_notification(NotificationType::ExportOngoing, []() {return true; }, 1000, 0); } else { BOOST_LOG_TRIVIAL(info) << "output_path is empty"; } @@ -10991,9 +10924,9 @@ void Plater::priv::export_gcode(fs::path output_path, bool output_path_on_remova return; show_warning_dialog = true; - if (!output_path.empty()) { + if (! output_path.empty()) { background_process.schedule_export(output_path.string(), output_path_on_removable_media); - notification_manager->push_delayed_notification(NotificationType::ExportOngoing, []() { return true; }, 1000, 0); + notification_manager->push_delayed_notification(NotificationType::ExportOngoing, []() {return true; }, 1000, 0); } else { background_process.schedule_upload(std::move(upload_job)); } @@ -11005,9 +10938,10 @@ void Plater::priv::export_gcode(fs::path output_path, bool output_path_on_remova unsigned int Plater::priv::update_restart_background_process(bool force_update_scene, bool force_update_preview) { bool switch_print = true; - // BBS: judge whether can switch print or not - if ((partplate_list.get_plate_count() > 1) && !this->background_process.can_switch_print()) { - // can not switch print currently + //BBS: judge whether can switch print or not + if ((partplate_list.get_plate_count() > 1) && !this->background_process.can_switch_print()) + { + //can not switch print currently BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": plate count %1%, can not switch") % partplate_list.get_plate_count(); switch_print = false; } @@ -11028,19 +10962,21 @@ void Plater::priv::update_fff_scene() this->preview->reload_print(); // In case this was MM print, wipe tower bounding box on 3D tab might need redrawing with exact depth: view3D->reload_scene(true); - // BBS: add assemble view related logic + //BBS: add assemble view related logic assemble_view->reload_scene(true); q->mark_plate_toolbar_image_dirty(); } -// BBS: add print project related logic +//BBS: add print project related logic void Plater::priv::update_fff_scene_only_shells(bool only_shells) { - if (this->preview != nullptr) { + if (this->preview != nullptr) + { const Print* current_print = this->background_process.fff_print(); - if (current_print) { - // this->preview->reset_shells(); + if (current_print) + { + //this->preview->reset_shells(); this->preview->load_shells(*current_print); } } @@ -11068,14 +11004,13 @@ bool Plater::priv::replace_volume_with_stl(int object_idx, int volume_idx, const try { const bool is_step = boost::algorithm::iends_with(path, ".stp") || boost::algorithm::iends_with(path, ".step"); if (is_step) { - auto config = wxGetApp().app_config; - double linear = std::max(0.003, string_to_double_decimal_point(config->get("linear_deflection"))); - double angle = std::max(0.5, string_to_double_decimal_point(config->get("angle_deflection"))); + auto config = wxGetApp().app_config; + double linear = std::max(0.003, string_to_double_decimal_point(config->get("linear_deflection"))); + double angle = std::max(0.5, string_to_double_decimal_point(config->get("angle_deflection"))); bool split_compound = config->get_bool("is_split_compound"); bool is_user_cancel = false; - auto callback = [&is_user_cancel, linear, angle, split_compound](Slic3r::Step& file, double& linear_value, double& angle_value, - bool& is_split) -> int { + auto callback = [&is_user_cancel, linear, angle, split_compound](Slic3r::Step &file, double &linear_value, double &angle_value, bool &is_split) -> int { if (wxGetApp().app_config->get_bool("enable_step_mesh_setting")) { StepMeshDialog mesh_dlg(nullptr, file, linear, angle); if (mesh_dlg.ShowModal() == wxID_OK) { @@ -11094,10 +11029,8 @@ bool Plater::priv::replace_volume_with_stl(int object_idx, int volume_idx, const return -1; }; - new_model = Model::read_from_step(path, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, nullptr, nullptr, callback, - linear, angle, split_compound); - if (is_user_cancel) - return false; + new_model = Model::read_from_step(path, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, nullptr, nullptr, callback, linear, angle, split_compound); + if (is_user_cancel) return false; } else { new_model = Model::read_from_file(path, nullptr, nullptr, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel); } @@ -11105,14 +11038,14 @@ bool Plater::priv::replace_volume_with_stl(int object_idx, int volume_idx, const model_object->center_around_origin(); model_object->ensure_on_bed(); } - } catch (std::exception&) { + } + catch (std::exception&) { // error while loading return false; } if (new_model.objects.size() > 1 || new_model.objects.front()->volumes.size() > 1) { - MessageDialog dlg(q, _L("Unable to replace with more than one volume"), _L("Error during replacement"), - wxOK | wxOK_DEFAULT | wxICON_WARNING); + MessageDialog dlg(q, _L("Unable to replace with more than one volume"), _L("Error during replacement"), wxOK | wxOK_DEFAULT | wxICON_WARNING); dlg.ShowModal(); return false; } @@ -11123,7 +11056,7 @@ bool Plater::priv::replace_volume_with_stl(int object_idx, int volume_idx, const q->take_snapshot(snapshot); ModelObject* old_model_object = model.objects[object_idx]; - ModelVolume* old_volume = old_model_object->volumes[volume_idx]; + ModelVolume* old_volume = old_model_object->volumes[volume_idx]; bool sinking = old_model_object->min_z() < SINKING_Z_THRESHOLD; @@ -11135,8 +11068,7 @@ bool Plater::priv::replace_volume_with_stl(int object_idx, int volume_idx, const new_volume->set_type(old_volume->type()); new_volume->set_material_id(old_volume->material_id()); new_volume->set_transformation(old_volume->get_transformation()); - new_volume->translate(new_volume->get_transformation().get_matrix_no_offset() * - (new_volume->source.mesh_offset - old_volume->source.mesh_offset)); + new_volume->translate(new_volume->get_transformation().get_matrix_no_offset() * (new_volume->source.mesh_offset - old_volume->source.mesh_offset)); assert(!old_volume->source.is_converted_from_inches || !old_volume->source.is_converted_from_meters); if (old_volume->source.is_converted_from_inches) new_volume->convert_from_imperial_units(); @@ -11176,7 +11108,7 @@ bool Plater::priv::replace_volume_with_stl(int object_idx, int volume_idx, const void Plater::priv::replace_with_stl() { - if (!q->get_view3D_canvas3D()->get_gizmos_manager().check_gizmos_closed_except(GLGizmosManager::EType::Undefined)) + if (! q->get_view3D_canvas3D()->get_gizmos_manager().check_gizmos_closed_except(GLGizmosManager::EType::Undefined)) return; const Selection& selection = get_selection(); @@ -11185,8 +11117,8 @@ void Plater::priv::replace_with_stl() return; const GLVolume* v = selection.get_first_volume(); - int object_idx = v->object_idx(); - int volume_idx = v->volume_idx(); + int object_idx = v->object_idx(); + int volume_idx = v->volume_idx(); // collects paths of files to load @@ -11205,8 +11137,7 @@ void Plater::priv::replace_with_stl() fs::path out_path = dialog.GetPath().ToUTF8().data(); if (out_path.empty()) { - MessageDialog dlg(q, _L("File for the replacement wasn\'t selected"), _L("Error during replacement"), - wxOK | wxOK_DEFAULT | wxICON_WARNING); + MessageDialog dlg(q, _L("File for the replacement wasn\'t selected"), _L("Error during replacement"), wxOK | wxOK_DEFAULT | wxICON_WARNING); dlg.ShowModal(); return; } @@ -11225,7 +11156,7 @@ void Plater::priv::replace_with_stl() void Plater::priv::replace_all_with_stl() { - if (!q->get_view3D_canvas3D()->get_gizmos_manager().check_gizmos_closed_except(GLGizmosManager::EType::Undefined)) + if (! q->get_view3D_canvas3D()->get_gizmos_manager().check_gizmos_closed_except(GLGizmosManager::EType::Undefined)) return; const Selection& selection = get_selection(); @@ -11249,7 +11180,7 @@ void Plater::priv::replace_all_with_stl() Slic3r::GUI::ItemType item_type = wxGetApp().obj_list()->GetModel()->GetItemType(item); if (item_type & itPlate) { if (item.IsOk()) { - ObjectDataViewModelNode* node = static_cast(item.GetID()); + ObjectDataViewModelNode *node = static_cast(item.GetID()); selected_plate_idxs.push_back(node->GetPlateIdx()); } } @@ -11270,8 +11201,8 @@ void Plater::priv::replace_all_with_stl() for (unsigned int idx : volume_idxs) { const GLVolume* v = selection.get_volume(idx); - int object_idx = v->object_idx(); - int volume_idx = v->volume_idx(); + int object_idx = v->object_idx(); + int volume_idx = v->volume_idx(); const ModelObject* object = model.objects[object_idx]; const ModelVolume* volume = object->volumes[volume_idx]; @@ -11290,8 +11221,7 @@ void Plater::priv::replace_all_with_stl() fs::path out_path = dialog.GetPath().ToUTF8().data(); if (out_path.empty()) { - MessageDialog dlg(q, _L("Directory for the replace wasn't selected"), _L("Error during replacement"), - wxOK | wxOK_DEFAULT | wxICON_WARNING); + MessageDialog dlg(q, _L("Directory for the replace wasn't selected"), _L("Error during replacement"), wxOK | wxOK_DEFAULT | wxICON_WARNING); dlg.ShowModal(); return; } @@ -11300,8 +11230,8 @@ void Plater::priv::replace_all_with_stl() for (unsigned int idx : volume_idxs) { const GLVolume* v = selection.get_volume(idx); - int object_idx = v->object_idx(); - int volume_idx = v->volume_idx(); + int object_idx = v->object_idx(); + int volume_idx = v->volume_idx(); const ModelObject* object = model.objects[object_idx]; const ModelVolume* volume = object->volumes[volume_idx]; @@ -11351,20 +11281,19 @@ void Plater::priv::replace_all_with_stl() } #if ENABLE_RELOAD_FROM_DISK_REWORK -static std::vector> reloadable_volumes(const Model& model, const Selection& selection) +static std::vector> reloadable_volumes(const Model &model, const Selection &selection) { std::vector> ret; - const std::set& selected_volumes_idxs = selection.get_volume_idxs(); + const std::set & selected_volumes_idxs = selection.get_volume_idxs(); for (unsigned int idx : selected_volumes_idxs) { - const GLVolume& v = *selection.get_volume(idx); - const int o_idx = v.object_idx(); + const GLVolume &v = *selection.get_volume(idx); + const int o_idx = v.object_idx(); if (0 <= o_idx && o_idx < int(model.objects.size())) { - const ModelObject* obj = model.objects[o_idx]; - const int v_idx = v.volume_idx(); + const ModelObject *obj = model.objects[o_idx]; + const int v_idx = v.volume_idx(); if (0 <= v_idx && v_idx < int(obj->volumes.size())) { - const ModelVolume* vol = obj->volumes[v_idx]; - if (!vol->source.is_from_builtin_objects && !vol->source.input_file.empty() && - !fs::path(vol->source.input_file).extension().string().empty()) + const ModelVolume *vol = obj->volumes[v_idx]; + if (!vol->source.is_from_builtin_objects && !vol->source.input_file.empty() && !fs::path(vol->source.input_file).extension().string().empty()) ret.push_back({o_idx, v_idx}); } } @@ -11383,14 +11312,12 @@ void Plater::priv::reload_from_disk() if (selected_volumes.empty()) return; - std::sort(selected_volumes.begin(), selected_volumes.end(), [](const std::pair& v1, const std::pair& v2) { + std::sort(selected_volumes.begin(), selected_volumes.end(), [](const std::pair &v1, const std::pair &v2) { return (v1.first < v2.first) || (v1.first == v2.first && v1.second < v2.second); - }); - selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end(), - [](const std::pair& v1, const std::pair& v2) { - return (v1.first == v2.first) && (v1.second == v2.second); - }), - selected_volumes.end()); + }); + selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end(), [](const std::pair &v1, const std::pair &v2) { + return (v1.first == v2.first) && (v1.second == v2.second); + }), selected_volumes.end()); #else Plater::TakeSnapshot snapshot(q, _u8L("Reload from disk")); @@ -11406,9 +11333,8 @@ void Plater::priv::reload_from_disk() int volume_idx; // operators needed by std::algorithms - bool operator<(const SelectedVolume& other) const - { return object_idx < other.object_idx || (object_idx == other.object_idx && volume_idx < other.volume_idx); } - bool operator==(const SelectedVolume& other) const { return object_idx == other.object_idx && volume_idx == other.volume_idx; } + bool operator < (const SelectedVolume& other) const { return object_idx < other.object_idx || (object_idx == other.object_idx && volume_idx < other.volume_idx); } + bool operator == (const SelectedVolume& other) const { return object_idx == other.object_idx && volume_idx == other.volume_idx; } }; std::vector selected_volumes; @@ -11416,11 +11342,11 @@ void Plater::priv::reload_from_disk() const std::set& selected_volumes_idxs = selection.get_volume_idxs(); for (unsigned int idx : selected_volumes_idxs) { const GLVolume* v = selection.get_volume(idx); - int v_idx = v->volume_idx(); + int v_idx = v->volume_idx(); if (v_idx >= 0) { int o_idx = v->object_idx(); - if (0 <= o_idx && o_idx < (int) model.objects.size()) - selected_volumes.push_back({o_idx, v_idx}); + if (0 <= o_idx && o_idx < (int)model.objects.size()) + selected_volumes.push_back({ o_idx, v_idx }); } } std::sort(selected_volumes.begin(), selected_volumes.end()); @@ -11433,8 +11359,8 @@ void Plater::priv::reload_from_disk() #if ENABLE_RELOAD_FROM_DISK_REWORK std::vector> replace_paths; for (auto [obj_idx, vol_idx] : selected_volumes) { - const ModelObject* object = model.objects[obj_idx]; - const ModelVolume* volume = object->volumes[vol_idx]; + const ModelObject *object = model.objects[obj_idx]; + const ModelVolume *volume = object->volumes[vol_idx]; if (fs::exists(volume->source.input_file)) input_paths.push_back(volume->source.input_file); else { @@ -11480,8 +11406,8 @@ void Plater::priv::reload_from_disk() if (!found) missing_input_paths.push_back(volume->source.input_file); } - } else if (!object->input_file.empty() && volume->is_model_part() && !volume->name.empty() && - !volume->source.is_from_builtin_objects) + } + else if (!object->input_file.empty() && volume->is_model_part() && !volume->name.empty() && !volume->source.is_from_builtin_objects) missing_input_paths.push_back(volume->name); } #endif // ENABLE_RELOAD_FROM_DISK_REWORK @@ -11492,7 +11418,7 @@ void Plater::priv::reload_from_disk() while (!missing_input_paths.empty()) { // ask user to select the missing file fs::path search = missing_input_paths.back(); - wxString title = _L("Please select a file"); + wxString title = _L("Please select a file"); #if defined(__APPLE__) title += " (" + from_u8(search.filename().string()) + ")"; #endif // __APPLE__ @@ -11502,7 +11428,7 @@ void Plater::priv::reload_from_disk() return; std::string sel_filename_path = dialog.GetPath().ToUTF8().data(); - std::string sel_filename = fs::path(sel_filename_path).filename().string(); + std::string sel_filename = fs::path(sel_filename_path).filename().string(); if (boost::algorithm::iequals(search.filename().string(), sel_filename)) { input_paths.push_back(sel_filename_path); missing_input_paths.pop_back(); @@ -11517,11 +11443,13 @@ void Plater::priv::reload_from_disk() if (fs::exists(repathed_filename)) { input_paths.push_back(repathed_filename.string()); it = missing_input_paths.erase(it); - } else + } + else ++it; } - } else { - wxString message = _L("Do you want to replace it") + " ?"; + } + else { + wxString message = _L("Do you want to replace it") + " ?"; MessageDialog dlg(q, message, _L("Message"), wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION); if (dlg.ShowModal() == wxID_YES) #if ENABLE_RELOAD_FROM_DISK_REWORK @@ -11551,7 +11479,7 @@ void Plater::priv::reload_from_disk() auto obj_color_fun = [&path](ObjDialogInOut &in_out) { if (!boost::iends_with(path, ".obj")) { return; } const std::vector extruder_colours = wxGetApp().plater()->get_extruder_colors_from_plater_config(); - ObjColorDialog color_dlg(nullptr, in_out, extruder_colours, Sidebar::should_show_SEMM_buttons()); + ObjColorDialog color_dlg(nullptr, in_out, extruder_colours, Sidebar::should_show_SEMM_buttons()); if (color_dlg.ShowModal() != wxID_OK) { in_out.filament_ids.clear(); } @@ -11560,68 +11488,72 @@ void Plater::priv::reload_from_disk() wxBusyInfo info(_L("Reload from:") + " " + from_u8(path), q->get_current_canvas3D()->get_wxglcanvas()); Model new_model; - try { - // BBS: add plate data related logic + try + { + //BBS: add plate data related logic PlateDataPtrs plate_data; - // BBS: project embedded settings + //BBS: project embedded settings std::vector project_presets; // BBS: backup - if (boost::iends_with(path, ".stp") || boost::iends_with(path, ".step")) { + if (boost::iends_with(path, ".stp") || + boost::iends_with(path, ".step")) { double linear = string_to_double_decimal_point(wxGetApp().app_config->get("linear_deflection")); - double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_deflection")); - bool is_split = wxGetApp().app_config->get_bool("is_split_compound"); - new_model = Model::read_from_step(path, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, nullptr, nullptr, - nullptr, linear, angle, is_split); - } else { - new_model = Model::read_from_file(path, nullptr, nullptr, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, - &plate_data, &project_presets, nullptr, nullptr, nullptr, nullptr, nullptr, 0, - obj_color_fun); + double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_deflection")); + bool is_split = wxGetApp().app_config->get_bool("is_split_compound"); + new_model = Model::read_from_step(path, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, nullptr, nullptr, nullptr, linear, angle, is_split); + }else { + new_model = Model::read_from_file(path, nullptr, nullptr, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, &plate_data, &project_presets, nullptr, nullptr, nullptr, nullptr, nullptr, 0, obj_color_fun); } - for (ModelObject* model_object : new_model.objects) { + + for (ModelObject* model_object : new_model.objects) + { model_object->center_around_origin(); model_object->ensure_on_bed(); } - if (plate_data.size() > 0) { - // partplate_list.load_from_3mf_structure(plate_data); + if (plate_data.size() > 0) + { + //partplate_list.load_from_3mf_structure(plate_data); partplate_list.update_slice_context_to_current_plate(background_process); this->preview->update_gcode_result(partplate_list.get_current_slice_result()); release_PlateData_list(plate_data); sidebar->obj_list()->reload_all_plates(); } - } catch (std::exception&) { + } + catch (std::exception&) + { // error while loading return; } #if ENABLE_RELOAD_FROM_DISK_REWORK for (auto [obj_idx, vol_idx] : selected_volumes) { - ModelObject* old_model_object = model.objects[obj_idx]; - ModelVolume* old_volume = old_model_object->volumes[vol_idx]; + ModelObject *old_model_object = model.objects[obj_idx]; + ModelVolume *old_volume = old_model_object->volumes[vol_idx]; bool sinking = old_model_object->min_z() < SINKING_Z_THRESHOLD; bool has_source = !old_volume->source.input_file.empty() && - boost::algorithm::iequals(fs::path(old_volume->source.input_file).filename().string(), - fs::path(path).filename().string()); - bool has_name = !old_volume->name.empty() && boost::algorithm::iequals(old_volume->name, fs::path(path).filename().string()); + boost::algorithm::iequals(fs::path(old_volume->source.input_file).filename().string(), fs::path(path).filename().string()); + bool has_name = !old_volume->name.empty() && boost::algorithm::iequals(old_volume->name, fs::path(path).filename().string()); if (has_source || has_name) { - int new_volume_idx = -1; - int new_object_idx = -1; - bool match_found = false; + int new_volume_idx = -1; + int new_object_idx = -1; + bool match_found = false; // take idxs from the matching volume if (has_source && old_volume->source.object_idx < int(new_model.objects.size())) { - const ModelObject* obj = new_model.objects[old_volume->source.object_idx]; + const ModelObject *obj = new_model.objects[old_volume->source.object_idx]; if (old_volume->source.volume_idx < int(obj->volumes.size())) { - const std::string& new_input_file = obj->volumes[old_volume->source.volume_idx]->source.input_file; - const std::string& old_input_file = old_volume->source.input_file; + const std::string &new_input_file = obj->volumes[old_volume->source.volume_idx]->source.input_file; + const std::string &old_input_file = old_volume->source.input_file; // Orca: match on the exact source path first, then fall back to filename-only so reload // still matches when the project stored a bare filename and the file was found next to // the project (same-folder fallback) or picked via the locate dialog (#12992). - if (new_input_file == old_input_file || boost::algorithm::iequals(fs::path(new_input_file).filename().string(), - fs::path(old_input_file).filename().string())) { + if (new_input_file == old_input_file || + boost::algorithm::iequals(fs::path(new_input_file).filename().string(), + fs::path(old_input_file).filename().string())) { new_volume_idx = old_volume->source.volume_idx; new_object_idx = old_volume->source.object_idx; match_found = true; @@ -11632,8 +11564,8 @@ void Plater::priv::reload_from_disk() if (!match_found && has_name) { // take idxs from the 1st matching volume for (size_t o = 0; o < new_model.objects.size(); ++o) { - ModelObject* obj = new_model.objects[o]; - bool found = false; + ModelObject *obj = new_model.objects[o]; + bool found = false; for (size_t v = 0; v < obj->volumes.size(); ++v) { if (obj->volumes[v]->name == old_volume->name) { new_volume_idx = (int) v; @@ -11642,8 +11574,7 @@ void Plater::priv::reload_from_disk() break; } } - if (found) - break; + if (found) break; // BBS: step model,object loaded as a volume. GUI_ObfectList.cpp load_modifier() if (obj->name == old_volume->name) { new_object_idx = (int) o; @@ -11656,24 +11587,24 @@ void Plater::priv::reload_from_disk() fail_list.push_back(from_u8(has_source ? old_volume->source.input_file : old_volume->name)); continue; } - ModelObject* new_model_object = new_model.objects[new_object_idx]; + ModelObject *new_model_object = new_model.objects[new_object_idx]; if (int(new_model_object->volumes.size()) <= new_volume_idx) { fail_list.push_back(from_u8(has_source ? old_volume->source.input_file : old_volume->name)); continue; } - ModelVolume* new_volume = nullptr; + ModelVolume *new_volume = nullptr; // BBS: step model if (new_volume_idx < 0 && new_object_idx >= 0) { - TriangleMesh mesh = new_model_object->mesh(); - new_volume = old_model_object->add_volume(std::move(mesh)); - new_volume->name = new_model_object->name; + TriangleMesh mesh = new_model_object->mesh(); + new_volume = old_model_object->add_volume(std::move(mesh)); + new_volume->name = new_model_object->name; new_volume->source.input_file = new_model_object->input_file; - } else { + }else { new_volume = old_model_object->add_volume(*new_model_object->volumes[new_volume_idx]); // new_volume = old_model_object->volumes.back(); } - + new_volume->set_new_unique_id(); new_volume->config.apply(old_volume->config); new_volume->set_type(old_volume->type()); @@ -11701,8 +11632,7 @@ void Plater::priv::reload_from_disk() std::swap(old_model_object->volumes[vol_idx], old_model_object->volumes.back()); old_model_object->delete_volume(old_model_object->volumes.size() - 1); - if (!sinking) - old_model_object->ensure_on_bed(); + if (!sinking) old_model_object->ensure_on_bed(); old_model_object->sort_volumes(wxGetApp().app_config->get("order_volumes") == "1"); sla::reproject_points_and_holes(old_model_object); @@ -11715,39 +11645,37 @@ void Plater::priv::reload_from_disk() // update the selected volumes whose source is the current file for (const SelectedVolume& sel_v : selected_volumes) { ModelObject* old_model_object = model.objects[sel_v.object_idx]; - ModelVolume* old_volume = old_model_object->volumes[sel_v.volume_idx]; + ModelVolume* old_volume = old_model_object->volumes[sel_v.volume_idx]; bool sinking = old_model_object->bounding_box().min.z() < SINKING_Z_THRESHOLD; - bool has_source = !old_volume->source.input_file.empty() && - boost::algorithm::iequals(fs::path(old_volume->source.input_file).filename().string(), - fs::path(path).filename().string()); - bool has_name = !old_volume->name.empty() && boost::algorithm::iequals(old_volume->name, fs::path(path).filename().string()); + bool has_source = !old_volume->source.input_file.empty() && boost::algorithm::iequals(fs::path(old_volume->source.input_file).filename().string(), fs::path(path).filename().string()); + bool has_name = !old_volume->name.empty() && boost::algorithm::iequals(old_volume->name, fs::path(path).filename().string()); if (has_source || has_name) { int new_volume_idx = -1; int new_object_idx = -1; - // if (has_source) { - // // take idxs from source - // new_volume_idx = old_volume->source.volume_idx; - // new_object_idx = old_volume->source.object_idx; - // } - // else { - // take idxs from the 1st matching volume - for (size_t o = 0; o < new_model.objects.size(); ++o) { - ModelObject* obj = new_model.objects[o]; - bool found = false; - for (size_t v = 0; v < obj->volumes.size(); ++v) { - if (obj->volumes[v]->name == old_volume->name) { - new_volume_idx = (int) v; - new_object_idx = (int) o; - found = true; - break; +// if (has_source) { +// // take idxs from source +// new_volume_idx = old_volume->source.volume_idx; +// new_object_idx = old_volume->source.object_idx; +// } +// else { + // take idxs from the 1st matching volume + for (size_t o = 0; o < new_model.objects.size(); ++o) { + ModelObject* obj = new_model.objects[o]; + bool found = false; + for (size_t v = 0; v < obj->volumes.size(); ++v) { + if (obj->volumes[v]->name == old_volume->name) { + new_volume_idx = (int)v; + new_object_idx = (int)o; + found = true; + break; + } } + if (found) + break; } - if (found) - break; - } - // } +// } if (new_object_idx < 0 || int(new_model.objects.size()) <= new_object_idx) { fail_list.push_back(from_u8(has_source ? old_volume->source.input_file : old_volume->name)); @@ -11766,11 +11694,10 @@ void Plater::priv::reload_from_disk() new_volume->set_type(old_volume->type()); new_volume->set_material_id(old_volume->material_id()); new_volume->set_transformation(old_volume->get_transformation()); - new_volume->translate(new_volume->get_transformation().get_matrix_no_offset() * - (new_volume->source.mesh_offset - old_volume->source.mesh_offset)); + new_volume->translate(new_volume->get_transformation().get_matrix_no_offset() * (new_volume->source.mesh_offset - old_volume->source.mesh_offset)); new_volume->source.object_idx = old_volume->source.object_idx; new_volume->source.volume_idx = old_volume->source.volume_idx; - assert(!old_volume->source.is_converted_from_inches || !old_volume->source.is_converted_from_meters); + assert(! old_volume->source.is_converted_from_inches || ! old_volume->source.is_converted_from_meters); if (old_volume->source.is_converted_from_inches) new_volume->convert_from_imperial_units(); else if (old_volume->source.is_converted_from_meters) @@ -11791,10 +11718,8 @@ void Plater::priv::reload_from_disk() for (auto [src, dest] : replace_paths) { for (auto [obj_idx, vol_idx] : selected_volumes) { if (boost::algorithm::iequals(model.objects[obj_idx]->volumes[vol_idx]->source.input_file, src.string())) - // When an error occurs, either the dest parsing error occurs, or the number of objects in the dest is greater than 1 and - // cannot be replaced, and cannot be replaced in this loop. - if (!replace_volume_with_stl(obj_idx, vol_idx, dest, "")) - break; + // When an error occurs, either the dest parsing error occurs, or the number of objects in the dest is greater than 1 and cannot be replaced, and cannot be replaced in this loop. + if (!replace_volume_with_stl(obj_idx, vol_idx, dest, "")) break; } } #else @@ -11802,10 +11727,8 @@ void Plater::priv::reload_from_disk() const auto& path = replace_paths[i].string(); for (const SelectedVolume& sel_v : selected_volumes) { ModelObject* old_model_object = model.objects[sel_v.object_idx]; - ModelVolume* old_volume = old_model_object->volumes[sel_v.volume_idx]; - bool has_source = !old_volume->source.input_file.empty() && - boost::algorithm::iequals(fs::path(old_volume->source.input_file).filename().string(), - fs::path(path).filename().string()); + ModelVolume* old_volume = old_model_object->volumes[sel_v.volume_idx]; + bool has_source = !old_volume->source.input_file.empty() && boost::algorithm::iequals(fs::path(old_volume->source.input_file).filename().string(), fs::path(path).filename().string()); if (!replace_volume_with_stl(sel_v.object_idx, sel_v.volume_idx, path, "")) { fail_list.push_back(from_u8(has_source ? old_volume->source.input_file : old_volume->name)); } @@ -11841,7 +11764,7 @@ void Plater::priv::reload_all_from_disk() Plater::TakeSnapshot snapshot(q, _u8L("Reload all")); Plater::SuppressSnapshots suppress(q); - Selection& selection = get_selection(); + Selection& selection = get_selection(); Selection::IndicesList curr_idxs = selection.get_volume_idxs(); // reload from disk uses selection select_all(); @@ -11853,88 +11776,92 @@ void Plater::priv::reload_all_from_disk() } } -// BBS: add no_slice logic +//BBS: add no_slice logic void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) { if (std::find(panels.begin(), panels.end(), panel) == panels.end()) return; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": current_panel %1%, new_panel %2%") % current_panel % panel; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": current_panel %1%, new_panel %2%")%current_panel%panel; #ifdef __WXMAC__ bool force_render = (current_panel != nullptr); #endif // __WXMAC__ - // BBS: add slice logic when switch to preview page + //BBS: add slice logic when switch to preview page auto do_reslice = [this, no_slice]() { - // see: Plater::priv::object_list_changed() - // FIXME: it may be better to have a single function making this check and let it be called wherever needed - bool export_in_progress = this->background_process.is_export_scheduled(); - ObjectFilamentResults object_results; - bool model_fits = this->view3D->get_canvas3d()->check_volumes_outside_state(&object_results) != ModelInstancePVS_Partly_Outside; - model_fits = model_fits && object_results.filaments.empty(); - // BBS: add partplate logic - PartPlate* current_plate = this->partplate_list.get_curr_plate(); - bool only_has_gcode_need_preview = false; - bool current_has_print_instances = current_plate->has_printable_instances(); - if (current_plate->is_slice_result_valid() && this->model.objects.empty() && !current_has_print_instances) - only_has_gcode_need_preview = true; + // see: Plater::priv::object_list_changed() + // FIXME: it may be better to have a single function making this check and let it be called wherever needed + bool export_in_progress = this->background_process.is_export_scheduled(); + ObjectFilamentResults object_results; + bool model_fits = this->view3D->get_canvas3d()->check_volumes_outside_state(&object_results) != ModelInstancePVS_Partly_Outside; + model_fits = model_fits&&object_results.filaments.empty(); + //BBS: add partplate logic + PartPlate * current_plate = this->partplate_list.get_curr_plate(); + bool only_has_gcode_need_preview = false; + bool current_has_print_instances = current_plate->has_printable_instances(); + if (current_plate->is_slice_result_valid() && this->model.objects.empty() && !current_has_print_instances) + only_has_gcode_need_preview = true; - bool mixed_broken = sidebar->has_broken_mixed_filament(); + bool mixed_broken = sidebar->has_broken_mixed_filament(); - BOOST_LOG_TRIVIAL(info) - << __FUNCTION__ - << boost::format( - ": from set_current_panel, no_slice %1%, export_in_progress %2%, model_fits %3%, m_is_slicing %4%, mixed_broken %5%") % - no_slice % export_in_progress % model_fits % m_is_slicing % mixed_broken; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": from set_current_panel, no_slice %1%, export_in_progress %2%, model_fits %3%, m_is_slicing %4%, mixed_broken %5%")%no_slice%export_in_progress%model_fits%m_is_slicing%mixed_broken; - if (!no_slice && !this->model.objects.empty() && !export_in_progress && model_fits && current_has_print_instances && !mixed_broken) { - // if already running in background, not relice here - // BBS: add more judge for slicing - if (!this->background_process.running() && !this->m_is_slicing) { + if (!no_slice && !this->model.objects.empty() && !export_in_progress && model_fits && current_has_print_instances && !mixed_broken) + { + //if already running in background, not relice here + //BBS: add more judge for slicing + if (!this->background_process.running() && !this->m_is_slicing) + { + this->m_slice_all = false; + this->q->reslice(); + } + else { + //reset current plate to the slicing plate + int plate_index = this->background_process.get_current_plate()->get_index(); + this->partplate_list.select_plate(plate_index); + } + } + else if (only_has_gcode_need_preview) + { this->m_slice_all = false; this->q->reslice(); - } else { - // reset current plate to the slicing plate - int plate_index = this->background_process.get_current_plate()->get_index(); - this->partplate_list.select_plate(plate_index); } - } else if (only_has_gcode_need_preview) { - this->m_slice_all = false; - this->q->reslice(); - } - // BBS: process empty plate, reset previous toolpath - else { - // if (!this->m_slice_all) - if (!current_has_print_instances) - reset_gcode_toolpaths(); - // this->q->refresh_print(); - if (!preview->get_canvas3d()->is_initialized()) { - preview->get_canvas3d()->render(true); - } - } - // TODO: turn off this switch currently - /*auto canvas_w = float(preview->get_canvas3d()->get_canvas_size().get_width()); - auto canvas_h = float(preview->get_canvas3d()->get_canvas_size().get_height()); - Point screen_center(canvas_w/2, canvas_h/2); - auto center_point = preview->get_canvas3d()->_mouse_to_3d(screen_center); - center_point(2) = 0.f; - if (!current_plate->contains(center_point)) - this->partplate_list.select_plate_view();*/ - - // keeps current gcode preview, if any - if (this->m_slice_all) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": slicing all, just reload shells"); - this->update_fff_scene_only_shells(); - } else { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": single slice, reload print"); - if (model_fits) - this->preview->reload_print(); // TODO + //BBS: process empty plate, reset previous toolpath else - this->update_fff_scene_only_shells(); - } + { + //if (!this->m_slice_all) + if (!current_has_print_instances) + reset_gcode_toolpaths(); + //this->q->refresh_print(); + if (!preview->get_canvas3d()->is_initialized()) + { + preview->get_canvas3d()->render(true); + } + } + //TODO: turn off this switch currently + /*auto canvas_w = float(preview->get_canvas3d()->get_canvas_size().get_width()); + auto canvas_h = float(preview->get_canvas3d()->get_canvas_size().get_height()); + Point screen_center(canvas_w/2, canvas_h/2); + auto center_point = preview->get_canvas3d()->_mouse_to_3d(screen_center); + center_point(2) = 0.f; + if (!current_plate->contains(center_point)) + this->partplate_list.select_plate_view();*/ - preview->set_as_dirty(); - }; + // keeps current gcode preview, if any + if (this->m_slice_all) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": slicing all, just reload shells"); + this->update_fff_scene_only_shells(); + } + else { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": single slice, reload print"); + if (model_fits) + this->preview->reload_print(); // TODO + else + this->update_fff_scene_only_shells(); + } + + preview->set_as_dirty(); + }; // Add sidebar and toolbar collapse logic if (panel == view3D || panel == preview) { @@ -11950,7 +11877,8 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) } } - if (current_panel == panel) { + if (current_panel == panel) + { if (panel == view3D) { if (view3D->is_reload_delayed()) { // Delayed loading of the 3D scene when caller requests the already active tab. @@ -11965,8 +11893,8 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) if (notification_manager != nullptr) notification_manager->set_in_preview(false); } - // BBS: add slice logic when switch to preview page - // BBS: add only gcode mode + //BBS: add slice logic when switch to preview page + //BBS: add only gcode mode if (!q->only_gcode_mode() && (current_panel == preview) && (wxGetApp().is_editor())) { do_reslice(); } @@ -11974,17 +11902,17 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) return; } - // BBS: wish to reset all plates stats item selected state when back to View3D Tab + //BBS: wish to reset all plates stats item selected state when back to View3D Tab preview->get_canvas3d()->reset_select_plate_toolbar_selection(); wxPanel* old_panel = current_panel; - // #if BBL_HAS_FIRST_PAGE +//#if BBL_HAS_FIRST_PAGE if (!old_panel) { // Wayland may report the first canvas as not yet shown while the frame is still mapping. // Keep the panel switch anyway so handlers are bound and the first paint can initialize GL later. panel->Show(); } - // #endif +//#endif current_panel = panel; // to reduce flickering when changing view, first set as visible the new current panel @@ -12019,7 +11947,8 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) } if (current_panel == view3D || current_panel == preview) { cam.load_camera_view(view3D->get_canvas3d()->get_camera()); - } else if (current_panel == assemble_view) { + } + else if (current_panel == assemble_view) { cam.load_camera_view(assemble_view->get_canvas3d()->get_camera()); } } @@ -12030,12 +11959,12 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) else if (old_panel == assemble_view) { assemble_view->get_canvas3d()->unbind_event_handlers(); - GLCanvas3D* assemble_canvas = assemble_view->get_canvas3d(); + GLCanvas3D* assemble_canvas = assemble_view->get_canvas3d(); Selection::IndicesList select_idxs = assemble_canvas->get_selection().get_volume_idxs(); - Selection& view3d_selection = view3D->get_canvas3d()->get_selection(); + Selection& view3d_selection = view3D->get_canvas3d()->get_selection(); view3d_selection.clear(); for (unsigned int idx : select_idxs) { - auto v = assemble_canvas->get_selection().get_volume(idx); + auto v = assemble_canvas->get_selection().get_volume(idx); auto real_idx = view3d_selection.query_real_volume_idx_from_other_view(v->object_idx(), v->instance_idx(), v->volume_idx()); if (real_idx >= 0) { view3d_selection.add(real_idx, false); @@ -12060,10 +11989,11 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) // reset cached size to force a resize on next call to render() to keep imgui in synch with canvas size view3D->get_canvas3d()->reset_old_size(); // BBS - // view_toolbar.select_item("3D"); + //view_toolbar.select_item("3D"); if (notification_manager != nullptr) notification_manager->set_in_preview(false); - } else if (current_panel == preview) { + } + else if (current_panel == preview) { q->invalid_all_plate_thumbnails(); if (old_panel == view3D) view3D->get_canvas3d()->unbind_event_handlers(); @@ -12106,27 +12036,28 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) // reset cached size to force a resize on next call to render() to keep imgui in synch with canvas size preview->get_canvas3d()->reset_old_size(); // BBS - // view_toolbar.select_item("Preview"); + //view_toolbar.select_item("Preview"); if (notification_manager != nullptr) notification_manager->set_in_preview(true); - } else if (current_panel == assemble_view) { + } + else if (current_panel == assemble_view) { if (old_panel == view3D) { view3D->get_canvas3d()->unbind_event_handlers(); - } else if (old_panel == preview) + } + else if (old_panel == preview) preview->get_canvas3d()->unbind_event_handlers(); assemble_view->get_canvas3d()->bind_event_handlers(); assemble_view->reload_scene(true); if (old_panel == view3D) { - GLCanvas3D* view3D_canvas = view3D->get_canvas3d(); + GLCanvas3D* view3D_canvas = view3D->get_canvas3d(); Selection::IndicesList select_idxs = view3D_canvas->get_selection().get_volume_idxs(); - Selection& assemble_selection = assemble_view->get_canvas3d()->get_selection(); + Selection& assemble_selection = assemble_view->get_canvas3d()->get_selection(); assemble_selection.clear(); for (unsigned int idx : select_idxs) { auto v = view3D_canvas->get_selection().get_volume(idx); - auto real_idx = assemble_selection.query_real_volume_idx_from_other_view(v->object_idx(), v->instance_idx(), - v->volume_idx()); + auto real_idx = assemble_selection.query_real_volume_idx_from_other_view(v->object_idx(), v->instance_idx(), v->volume_idx()); if (real_idx >= 0) { assemble_selection.add(real_idx, false); } @@ -12136,12 +12067,12 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) // BBS set default view and zoom if (first_enter_assemble) { wxGetApp().plater()->get_camera().requires_zoom_to_volumes = true; - first_enter_assemble = false; + first_enter_assemble = false; } assemble_view->set_as_dirty(); // BBS - // view_toolbar.select_item("Assemble"); + //view_toolbar.select_item("Assemble"); } current_panel->SetFocusFromKbd(); @@ -12150,32 +12081,33 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice) } // BBS -void Plater::priv::on_combobox_select(wxCommandEvent& evt) +void Plater::priv::on_combobox_select(wxCommandEvent &evt) { PlaterPresetComboBox* preset_combo_box = dynamic_cast(evt.GetEventObject()); if (preset_combo_box) { this->on_select_preset(evt); sidebar->update_printer_thumbnail(); - } else { + } + else { this->on_select_bed_type(evt); } } -void Plater::priv::on_select_bed_type(wxCommandEvent& evt) +void Plater::priv::on_select_bed_type(wxCommandEvent &evt) { - ComboBox* combo = static_cast(evt.GetEventObject()); - auto select_bed_type = sidebar->get_cur_select_bed_type(); - std::string bed_type_name = print_config_def.get("curr_bed_type")->enum_values[(int) select_bed_type - 1]; + ComboBox* combo = static_cast(evt.GetEventObject()); + auto select_bed_type = sidebar->get_cur_select_bed_type(); + std::string bed_type_name = print_config_def.get("curr_bed_type")->enum_values[(int)select_bed_type - 1]; - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; - DynamicPrintConfig& proj_config = wxGetApp().preset_bundle->project_config; + PresetBundle& preset_bundle = *wxGetApp().preset_bundle; + DynamicPrintConfig& proj_config = wxGetApp().preset_bundle->project_config; const t_config_enum_values* keys_map = print_config_def.get("curr_bed_type")->enum_keys_map; if (keys_map) { BedType new_bed_type = btCount; for (auto item : *keys_map) { if (item.first == bed_type_name) { - new_bed_type = (BedType) item.second; + new_bed_type = (BedType)item.second; break; } } @@ -12193,10 +12125,10 @@ void Plater::priv::on_select_bed_type(wxCommandEvent& evt) // update app_config AppConfig* app_config = wxGetApp().app_config; app_config->set("curr_bed_type", std::to_string(int(new_bed_type))); - app_config->set_printer_setting(wxGetApp().preset_bundle->printers.get_selected_preset_name(), "curr_bed_type", - std::to_string(int(new_bed_type))); + app_config->set_printer_setting(wxGetApp().preset_bundle->printers.get_selected_preset_name(), + "curr_bed_type", std::to_string(int(new_bed_type))); - // update slice status + //update slice status auto plate_list = partplate_list.get_plate_list(); for (auto plate : plate_list) { if (plate->get_bed_type() == btDefault) { @@ -12212,7 +12144,7 @@ void Plater::priv::on_select_bed_type(wxCommandEvent& evt) } } -void Plater::priv::on_select_preset(wxCommandEvent& evt) +void Plater::priv::on_select_preset(wxCommandEvent &evt) { PlaterPresetComboBox* combo = static_cast(evt.GetEventObject()); Preset::Type preset_type = combo->get_type(); @@ -12232,11 +12164,11 @@ void Plater::priv::on_select_preset(wxCommandEvent& evt) // BBS:Save the plate parameters before switching PartPlateList& old_plate_list = this->partplate_list; - PartPlate* old_plate = old_plate_list.get_selected_plate(); - Vec3d old_plate_pos = old_plate->get_center_origin(); + PartPlate* old_plate = old_plate_list.get_selected_plate(); + Vec3d old_plate_pos = old_plate->get_center_origin(); // BBS: Save the model in the current platelist - std::vector> plate_object; + std::vector > plate_object; for (size_t i = 0; i < old_plate_list.get_plate_count(); ++i) { PartPlate* plate = old_plate_list.get_plate(i); std::vector obj_idxs; @@ -12264,8 +12196,8 @@ void Plater::priv::on_select_preset(wxCommandEvent& evt) preset_name = Preset::remove_suffix_modified(wx_stored_name.ToUTF8().data()); } else { wxString wx_name = combo->GetString(selection); - preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type, - Preset::remove_suffix_modified(wx_name.ToUTF8().data())); + preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type, + Preset::remove_suffix_modified(wx_name.ToUTF8().data())); } if (preset_type == Preset::TYPE_FILAMENT) { @@ -12278,7 +12210,7 @@ void Plater::priv::on_select_preset(wxCommandEvent& evt) sidebar->auto_calc_flushing_volumes(idx); } auto select_flag = combo->GetFlag(selection); - combo->ShowBadge(select_flag == (int) PresetComboBox::FilamentAMSType::FROM_AMS); + combo->ShowBadge(select_flag == (int)PresetComboBox::FilamentAMSType::FROM_AMS); q->on_filament_change(idx); } bool select_preset = !combo->selection_is_changed_according_to_physical_printers(); @@ -12286,10 +12218,11 @@ void Plater::priv::on_select_preset(wxCommandEvent& evt) if (preset_type == Preset::TYPE_FILAMENT && sidebar->is_multifilament()) { // Only update the plater UI for the 2nd and other filaments. combo->update(); - } else if (select_preset) { + } + else if (select_preset) { if (preset_type == Preset::TYPE_PRINTER) { PhysicalPrinterCollection& physical_printers = wxGetApp().preset_bundle->physical_printers; - if (combo->is_selected_physical_printer()) + if(combo->is_selected_physical_printer()) preset_name = physical_printers.get_selected_printer_preset_name(); else physical_printers.unselect_printer(); @@ -12301,7 +12234,7 @@ void Plater::priv::on_select_preset(wxCommandEvent& evt) dlg.ShowModal(); } preset->is_visible = true; // force visible - preset_name = preset->name; + preset_name = preset->name; } std::string old_preset_name = wxGetApp().preset_bundle->printers.get_edited_preset().name; @@ -12312,24 +12245,24 @@ void Plater::priv::on_select_preset(wxCommandEvent& evt) q->on_config_change(wxGetApp().preset_bundle->full_config()); }); + if (old_preset_name != preset_name && wxGetApp().app_config->get("auto_calculate_flush") == "all") { wxGetApp().plater()->sidebar().auto_calc_flushing_volumes(-1); } // sync extruder info when select multi_extruder preset - if (Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager()) { - MachineObject* obj = dev->get_selected_machine(); + if (Slic3r::DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager()) { + MachineObject *obj = dev->get_selected_machine(); if (obj && obj->is_multi_extruders()) { - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - Preset& cur_preset = preset_bundle->printers.get_edited_preset(); + PresetBundle *preset_bundle = wxGetApp().preset_bundle; + Preset& cur_preset = preset_bundle->printers.get_edited_preset(); if (cur_preset.get_printer_type(preset_bundle) == obj->get_show_printer_type()) { double preset_nozzle_diameter = cur_preset.config.option("nozzle_diameter")->values[0]; - bool same_nozzle_diameter = true; + bool same_nozzle_diameter = true; const auto& extruders = obj->GetExtderSystem()->GetExtruders(); - for (const DevExtder& extruder : extruders) { - if (!obj->GetExtderSystem()->NozzleDiameterMatchesOrUnknown(extruder.GetExtId(), - float(preset_nozzle_diameter))) { + for (const DevExtder &extruder : extruders) { + if (!obj->GetExtderSystem()->NozzleDiameterMatchesOrUnknown(extruder.GetExtId(), float(preset_nozzle_diameter))) { same_nozzle_diameter = false; } } @@ -12359,17 +12292,17 @@ void Plater::priv::on_select_preset(wxCommandEvent& evt) // update plater with new config q->on_config_change(wxGetApp().preset_bundle->full_config()); if (preset_type == Preset::TYPE_PRINTER) { - /* Settings list can be changed after printer preset changing, so - * update all settings items for all item had it. - * Furthermore, Layers editing is implemented only for FFF printers - * and for SLA presets they should be deleted - */ + /* Settings list can be changed after printer preset changing, so + * update all settings items for all item had it. + * Furthermore, Layers editing is implemented only for FFF printers + * and for SLA presets they should be deleted + */ wxGetApp().obj_list()->update_object_list_by_printer_technology(); // BBS:Model reset by plate center PartPlateList& cur_plate_list = this->partplate_list; - PartPlate* cur_plate = cur_plate_list.get_curr_plate(); - Vec3d cur_plate_pos = cur_plate->get_center_origin(); + PartPlate* cur_plate = cur_plate_list.get_curr_plate(); + Vec3d cur_plate_pos = cur_plate->get_center_origin(); if (old_plate_pos.x() != cur_plate_pos.x() || old_plate_pos.y() != cur_plate_pos.y()) { for (int i = 0; i < plate_object.size(); ++i) { @@ -12380,15 +12313,16 @@ void Plater::priv::on_select_preset(wxCommandEvent& evt) view3D->deselect_all(); } -#if 0 // do not toggle auto calc when change printer - // update flush matrix +#if 0 // do not toggle auto calc when change printer + // update flush matrix size_t filament_size = wxGetApp().plater()->get_extruder_colors_from_plater_config().size(); for (size_t idx = 0; idx < filament_size; ++idx) wxGetApp().plater()->sidebar().auto_calc_flushing_volumes(idx); #endif // Show shared profiles notification for the newly selected printer - if (wxGetApp().app_config->get_bool("show_shared_profiles_notification")) { + if (wxGetApp().app_config->get_bool("show_shared_profiles_notification")) + { std::string printer_name = wxGetApp().preset_bundle->printers.get_selected_preset_base().name; std::string encoded_name = Http::url_encode(printer_name); @@ -12423,29 +12357,27 @@ void Plater::priv::on_select_preset(wxCommandEvent& evt) // update slice state and set bedtype default for 3rd-party printer auto plate_list = partplate_list.get_plate_list(); for (auto plate : plate_list) { - plate->update_slice_result_valid_state(false); + plate->update_slice_result_valid_state(false); } } -void Plater::priv::on_slicing_update(SlicingStatusEvent& evt) +void Plater::priv::on_slicing_update(SlicingStatusEvent &evt) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format(": event_type %1%, percent %2%, text %3%") % evt.GetEventType() % evt.status.percent % - evt.status.text; - // BBS: add slice project logic + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": event_type %1%, percent %2%, text %3%") % evt.GetEventType() % evt.status.percent % evt.status.text; + //BBS: add slice project logic std::string title_text = _u8L("Slicing"); - evt.status.text = title_text + evt.status.text; + evt.status.text = title_text + evt.status.text; if (evt.status.percent >= 0) { - if (!m_worker.is_idle()) { + if (!m_worker.is_idle()) { // Avoid a race condition return; } - notification_manager->set_slicing_progress_percentage(evt.status.text, (float) evt.status.percent / 100.0f); + notification_manager->set_slicing_progress_percentage(evt.status.text, (float)evt.status.percent / 100.0f); // update slicing percent PartPlateList& plate_list = wxGetApp().plater()->get_partplate_list(); - // slicing parallel, only update if percent is greater than before + //slicing parallel, only update if percent is greater than before if (evt.status.percent > plate_list.get_curr_plate()->get_slicing_percent()) plate_list.get_curr_plate()->update_slicing_percent(evt.status.percent); } @@ -12453,9 +12385,9 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent& evt) if (evt.status.flags & (PrintBase::SlicingStatus::RELOAD_SCENE | PrintBase::SlicingStatus::RELOAD_SLA_SUPPORT_POINTS)) { switch (this->printer_technology) { case ptFFF: - // BBS: add slice project logic, only display shells at the beginning + //BBS: add slice project logic, only display shells at the beginning if (!m_slice_all || (m_cur_slice_plate == (partplate_list.get_plate_count() - 1))) - // this->update_fff_scene(); + //this->update_fff_scene(); this->update_fff_scene_only_shells(); break; case ptSLA: @@ -12472,29 +12404,28 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent& evt) this->preview->reload_print(); } - if (evt.status.flags & - (PrintBase::SlicingStatus::UPDATE_PRINT_STEP_WARNINGS | PrintBase::SlicingStatus::UPDATE_PRINT_OBJECT_STEP_WARNINGS)) { + if (evt.status.flags & (PrintBase::SlicingStatus::UPDATE_PRINT_STEP_WARNINGS | PrintBase::SlicingStatus::UPDATE_PRINT_OBJECT_STEP_WARNINGS)) { // Update notification center with warnings of object_id and its warning_step. ObjectID object_id = evt.status.warning_object_id; - int warning_step = evt.status.warning_step; + int warning_step = evt.status.warning_step; PrintStateBase::StateWithWarnings state; - ModelObject const* model_object = nullptr; + ModelObject const * model_object = nullptr; - // BBS: add partplate related logic, use the print in background process + //BBS: add partplate related logic, use the print in background process if (evt.status.flags & PrintBase::SlicingStatus::UPDATE_PRINT_STEP_WARNINGS) { state = this->printer_technology == ptFFF ? - this->background_process.m_fff_print->step_state_with_warnings(static_cast(warning_step)) : - this->background_process.m_sla_print->step_state_with_warnings(static_cast(warning_step)); + this->background_process.m_fff_print->step_state_with_warnings(static_cast(warning_step)) : + this->background_process.m_sla_print->step_state_with_warnings(static_cast(warning_step)); } else if (this->printer_technology == ptFFF) { - const PrintObject* print_object = this->background_process.m_fff_print->get_object(object_id); + const PrintObject *print_object = this->background_process.m_fff_print->get_object(object_id); if (print_object) { - state = print_object->step_state_with_warnings(static_cast(warning_step)); + state = print_object->step_state_with_warnings(static_cast(warning_step)); model_object = print_object->model_object(); } } else { - const SLAPrintObject* print_object = this->background_process.m_sla_print->get_object(object_id); + const SLAPrintObject *print_object = this->background_process.m_sla_print->get_object(object_id); if (print_object) { - state = print_object->step_state_with_warnings(static_cast(warning_step)); + state = print_object->step_state_with_warnings(static_cast(warning_step)); model_object = print_object->model_object(); } } @@ -12502,12 +12433,10 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent& evt) for (auto const& warning : state.warnings) { if (warning.current) { NotificationManager::NotificationLevel notif_level = NotificationManager::NotificationLevel::WarningNotificationLevel; - if (evt.status.message_type == PrintStateBase::SlicingNotificationType::SlicingReplaceInitEmptyLayers || - evt.status.message_type == PrintStateBase::SlicingNotificationType::SlicingEmptyGcodeLayers) { + if (evt.status.message_type == PrintStateBase::SlicingNotificationType::SlicingReplaceInitEmptyLayers || evt.status.message_type == PrintStateBase::SlicingNotificationType::SlicingEmptyGcodeLayers) { notif_level = NotificationManager::NotificationLevel::SeriousWarningNotificationLevel; } - notification_manager->push_slicing_warning_notification(warning.message, false, model_object, object_id, warning_step, - warning.message_id, notif_level); + notification_manager->push_slicing_warning_notification(warning.message, false, model_object, object_id, warning_step, warning.message_id, notif_level); add_warning(warning, object_id.id); } } @@ -12515,13 +12444,12 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent& evt) BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format("exit."); } -void Plater::priv::on_slicing_completed(wxCommandEvent& evt) +void Plater::priv::on_slicing_completed(wxCommandEvent & evt) { BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": event_type %1%, string %2%") % evt.GetEventType() % evt.GetString(); - // BBS: add slice project logic + //BBS: add slice project logic if (m_slice_all && (m_cur_slice_plate < (partplate_list.get_plate_count() - 1))) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ - << boost::format("slicing all, finished plate %1%, will continue next.") % m_cur_slice_plate; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format("slicing all, finished plate %1%, will continue next.")%m_cur_slice_plate; return; } @@ -12529,10 +12457,11 @@ void Plater::priv::on_slicing_completed(wxCommandEvent& evt) delayed_scene_refresh = true; else { if (this->printer_technology == ptFFF) { - // BBS: only reload shells + //BBS: only reload shells this->update_fff_scene_only_shells(false); - // this->update_fff_scene(); - } else + //this->update_fff_scene(); + } + else this->update_sla_scene(); } BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format("exit."); @@ -12562,8 +12491,8 @@ void Plater::priv::on_slicing_began() clear_warnings(); notification_manager->close_notification_of_type(NotificationType::SignDetected); notification_manager->close_notification_of_type(NotificationType::ExportFinished); - bool is_first_plate = m_cur_slice_plate == 0; - bool slice_all = q->m_only_gcode ? m_slice_all_only_has_gcode : m_slice_all; + bool is_first_plate = m_cur_slice_plate == 0; + bool slice_all = q->m_only_gcode ? m_slice_all_only_has_gcode : m_slice_all; bool need_change_dailytips = !(slice_all && !is_first_plate); notification_manager->set_slicing_progress_began(); notification_manager->update_slicing_notif_dailytips(need_change_dailytips); @@ -12572,7 +12501,8 @@ void Plater::priv::add_warning(const Slic3r::PrintStateBase::Warning& warning, s { for (auto& it : current_warnings) { if (warning.message_id == it.first.message_id) { - if (warning.message_id != 0 || (warning.message_id == 0 && warning.message == it.first.message)) { + if (warning.message_id != 0 || (warning.message_id == 0 && warning.message == it.first.message)) + { if (warning.message_id != 0) it.first.message = warning.message; return; @@ -12581,7 +12511,7 @@ void Plater::priv::add_warning(const Slic3r::PrintStateBase::Warning& warning, s } current_warnings.emplace_back(std::pair(warning, oid)); } -void Plater::priv::actualize_slicing_warnings(const PrintBase& print) +void Plater::priv::actualize_slicing_warnings(const PrintBase &print) { std::vector ids = print.print_object_ids(); if (ids.empty()) { @@ -12596,7 +12526,8 @@ void Plater::priv::actualize_slicing_warnings(const PrintBase& print) void Plater::priv::actualize_object_warnings(const PrintBase& print) { std::vector ids; - for (const ModelObject* object : print.model().objects) { + for (const ModelObject* object : print.model().objects ) + { ids.push_back(object->id()); } std::sort(ids.begin(), ids.end()); @@ -12620,29 +12551,31 @@ bool Plater::priv::warnings_dialog() else text += it.first.message; } - // text += "\n\nDo you still wish to export?"; + //text += "\n\nDo you still wish to export?"; MessageDialog msg_window(this->q, from_u8(text), _L("warnings"), wxOK); - const auto res = msg_window.ShowModal(); + const auto res = msg_window.ShowModal(); return res == wxID_OK; + } -// BBS: add project slice logic -void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) +//BBS: add project slice logic +void Plater::priv::on_process_completed(SlicingProcessCompletedEvent &evt) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": enter, m_ignore_event %1%, status %2%") % m_ignore_event % evt.status(); - // BBS:ignore cancel event for some special case - if (m_ignore_event) { + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(": enter, m_ignore_event %1%, status %2%")%m_ignore_event %evt.status(); + //BBS:ignore cancel event for some special case + if (m_ignore_event) + { m_ignore_event = false; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": ignore this event %1%") % evt.status(); return; } - // BBS: add project slice logic + //BBS: add project slice logic bool is_finished = !m_slice_all || (m_cur_slice_plate == (partplate_list.get_plate_count() - 1)); - // BBS: slice .gcode.3mf file related logic, assign is_finished again + //BBS: slice .gcode.3mf file related logic, assign is_finished again bool only_has_gcode_need_preview = false; - auto plate_list = this->partplate_list.get_plate_list(); - bool has_print_instances = false; + auto plate_list = this->partplate_list.get_plate_list(); + bool has_print_instances = false; for (auto plate : plate_list) has_print_instances = has_print_instances || plate->has_printable_instances(); if (this->model.objects.empty() && !has_print_instances) @@ -12675,26 +12608,25 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) notification_manager->set_slicing_progress_hidden(); } } else { - std::vector ptrs; - for (auto oid : message.second) { - const PrintObject* print_object = this->background_process.m_fff_print->get_object(ObjectID(oid)); - if (print_object) { - ptrs.push_back(print_object->model_object()); - } + std::vector ptrs; + for (auto oid : message.second) + { + const PrintObject *print_object = this->background_process.m_fff_print->get_object(ObjectID(oid)); + if (print_object) { ptrs.push_back(print_object->model_object()); } } notification_manager->push_slicing_error_notification(message.first, ptrs); } - if (evt.invalidate_plater()) { + if (evt.invalidate_plater()) + { // BBS #if 0 const wxString invalid_str = _L("Invalid data"); for (auto btn : { ActionButtonType::abReslice, ActionButtonType::abSendGCode, ActionButtonType::abExport }) sidebar->set_btn_label(btn, invalid_str); #endif - process_completed_with_error = partplate_list.get_curr_plate_index(); - ; + process_completed_with_error = partplate_list.get_curr_plate_index();; } - has_error = true; + has_error = true; is_finished = true; } if (evt.cancelled()) { @@ -12703,11 +12635,11 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) is_finished = true; } - // BBS: set the current plater's slice result to valid + //BBS: set the current plater's slice result to valid if (!this->background_process.empty()) this->background_process.get_current_plate()->update_slice_result_valid_state(evt.success()); - // BBS: update the action button according to the current plate's status + //BBS: update the action button according to the current plate's status bool ready_to_slice = !this->partplate_list.get_curr_plate()->is_slice_result_valid(); // BBS @@ -12718,8 +12650,8 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) // This updates the "Slice now", "Export G-code", "Arrange" buttons status. // Namely, it refreshes the "Out of print bed" property of all the ModelObjects, and it enables // the "Slice now" and "Export G-code" buttons based on their "out of bed" status. - // BBS: remove this update here, will be updated in update_fff_scene later - // this->object_list_changed(); + //BBS: remove this update here, will be updated in update_fff_scene later + //this->object_list_changed(); // refresh preview if (view3D->is_dragging()) // updating scene now would interfere with the gizmo dragging @@ -12728,27 +12660,28 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) if (this->printer_technology == ptFFF) { if (is_finished) this->update_fff_scene(); - } else + } + else this->update_sla_scene(); } - // BBS: add slice&&print status update logic + //BBS: add slice&&print status update logic if (evt.cancelled()) { /*if (wxGetApp().get_mode() == comSimple) sidebar->set_btn_label(ActionButtonType::abReslice, "Slice now"); show_action_buttons(true);*/ ready_to_slice = true; - // this->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, true, true); + //this->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, true, true); - // BBS + //BBS if (m_is_publishing) { m_publish_dlg->cancel(); } } else { - if ((ready_to_slice) || (wxGetApp().get_mode() == comSimple)) { - // this means the current plate is not the slicing plate - // show_action_buttons(ready_to_slice); - // this->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, ready_to_slice, true); + if((ready_to_slice) || (wxGetApp().get_mode() == comSimple)) { + //this means the current plate is not the slicing plate + //show_action_buttons(ready_to_slice); + //this->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, ready_to_slice, true); } if (exporting_status != ExportingStatus::NOT_EXPORTING && !has_error) { notification_manager->stop_delayed_notifications_of_type(NotificationType::ExportOngoing); @@ -12756,14 +12689,14 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) } // If writing to removable drive was scheduled, show notification with eject button if (exporting_status == ExportingStatus::EXPORTING_TO_REMOVABLE && !has_error) { - // show_action_buttons(ready_to_slice); + //show_action_buttons(ready_to_slice); this->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, ready_to_slice, true); - notification_manager - ->push_exporting_finished_notification(last_output_path, last_output_dir_path, - // Don't offer the "Eject" button on ChromeOS, the Linux side has no control over it. - platform_flavor() != PlatformFlavor::LinuxOnChromium); + notification_manager->push_exporting_finished_notification(last_output_path, last_output_dir_path, + // Don't offer the "Eject" button on ChromeOS, the Linux side has no control over it. + platform_flavor() != PlatformFlavor::LinuxOnChromium); wxGetApp().removable_drive_manager()->set_exporting_finished(true); - } else if (exporting_status == ExportingStatus::EXPORTING_TO_LOCAL && !has_error) + }else + if (exporting_status == ExportingStatus::EXPORTING_TO_LOCAL && !has_error) notification_manager->push_exporting_finished_notification(last_output_path, last_output_dir_path, false); // BBS, Generate calibration thumbnail for current plate @@ -12773,19 +12706,20 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) preview->reload_print(); ThumbnailData* calibration_data = &partplate_list.get_curr_plate()->cali_thumbnail_data; const ThumbnailsParams calibration_params = { {}, false, true, true, true, partplate_list.get_curr_plate_index() }; - generate_calibration_thumbnail(*calibration_data, PartPlate::cali_thumbnail_width, PartPlate::cali_thumbnail_height, - calibration_params); preview->get_canvas3d()->reset_gcode_toolpaths();*/ + generate_calibration_thumbnail(*calibration_data, PartPlate::cali_thumbnail_width, PartPlate::cali_thumbnail_height, calibration_params); + preview->get_canvas3d()->reset_gcode_toolpaths();*/ // generate bbox data PlateBBoxData* plate_bbox_data = &partplate_list.get_curr_plate()->cali_bboxes_data; - *plate_bbox_data = generate_first_layer_bbox(); + *plate_bbox_data = generate_first_layer_bbox(); } } exporting_status = ExportingStatus::NOT_EXPORTING; + // BBS stop publishing if error occur - // if (m_is_publishing) { + //if (m_is_publishing) { // GCodeProcessorResult *gcode_result = background_process.get_current_gcode_result(); // m_publish_dlg->UpdateStatus(_L("Error occurred during slicing"), -1, false); // // if toolpath is outside @@ -12794,7 +12728,9 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) // } //} - if (is_finished) { + + if (is_finished) + { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(":finished, reload print soon"); m_is_slicing = false; this->preview->reload_print(false); @@ -12810,9 +12746,10 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) } } q->SetDropTarget(new PlaterDropTarget(*main_frame, *q)); - } else { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(":slicing all, plate %1% finished, start next slice...") % m_cur_slice_plate; + } + else + { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(":slicing all, plate %1% finished, start next slice...")%m_cur_slice_plate; m_cur_slice_plate++; q->Freeze(); @@ -12820,11 +12757,10 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) partplate_list.select_plate_view(); int ret = q->start_next_slice(); if (ret) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(":slicing all, plate %1% can not be sliced, will stop") % m_cur_slice_plate; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(":slicing all, plate %1% can not be sliced, will stop")%m_cur_slice_plate; m_is_slicing = false; } - // not the last plate + //not the last plate update_fff_scene_only_shells(); q->Thaw(); if (m_is_publishing) { @@ -12846,13 +12782,13 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent& evt) void Plater::priv::on_action_add(SimpleEvent&) { if (q != nullptr) { - // q->add_model(); - // BBS open file in toolbar add + //q->add_model(); + //BBS open file in toolbar add q->add_file(); } } -// BBS: add plate from toolbar +//BBS: add plate from toolbar void Plater::priv::on_action_add_plate(SimpleEvent&) { if (q != nullptr) { @@ -12863,22 +12799,22 @@ void Plater::priv::on_action_add_plate(SimpleEvent&) update(); // BBS set default view - // q->get_camera().select_view("topfront"); + //q->get_camera().select_view("topfront"); q->get_camera().requires_zoom_to_plate = REQUIRES_ZOOM_TO_ALL_PLATE; } } -// BBS: remove plate from toolbar +//BBS: remove plate from toolbar void Plater::priv::on_action_del_plate(SimpleEvent&) { if (q != nullptr) { q->delete_plate(); - // q->get_camera().select_view("topfront"); - // q->get_camera().requires_zoom_to_plate = REQUIRES_ZOOM_TO_ALL_PLATE; + //q->get_camera().select_view("topfront"); + //q->get_camera().requires_zoom_to_plate = REQUIRES_ZOOM_TO_ALL_PLATE; } } -// BBS: GUI refactor: GLToolbar +//BBS: GUI refactor: GLToolbar void Plater::priv::on_action_open_project(SimpleEvent&) { if (q != nullptr) { @@ -12886,16 +12822,16 @@ void Plater::priv::on_action_open_project(SimpleEvent&) } } -// BBS: GUI refactor: slice plate +//BBS: GUI refactor: slice plate void Plater::priv::on_action_slice_plate(SimpleEvent&) { if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received slice plate event\n"; - // BBS update extruder params and speed table before slicing + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received slice plate event\n" ; + //BBS update extruder params and speed table before slicing const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config(); - auto& print = q->get_partplate_list().get_current_fff_print(); - auto print_config = print.config(); - int numExtruders = wxGetApp().preset_bundle->filament_presets.size(); + auto& print = q->get_partplate_list().get_current_fff_print(); + auto print_config = print.config(); + int numExtruders = wxGetApp().preset_bundle->filament_presets.size(); Model::setExtruderParams(config, numExtruders); Model::setPrintSpeedTable(config, print_config); @@ -12905,33 +12841,33 @@ void Plater::priv::on_action_slice_plate(SimpleEvent&) } } -// BBS: GUI refactor: slice all +//BBS: GUI refactor: slice all void Plater::priv::on_action_slice_all(SimpleEvent&) { if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received slice project event\n"; - // BBS update extruder params and speed table before slicing + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received slice project event\n" ; + //BBS update extruder params and speed table before slicing const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config(); - auto& print = q->get_partplate_list().get_current_fff_print(); - auto print_config = print.config(); - int numExtruders = wxGetApp().preset_bundle->filament_presets.size(); + auto& print = q->get_partplate_list().get_current_fff_print(); + auto print_config = print.config(); + int numExtruders = wxGetApp().preset_bundle->filament_presets.size(); Model::setExtruderParams(config, numExtruders); Model::setPrintSpeedTable(config, print_config); - m_slice_all = true; + m_slice_all = true; m_slice_all_only_has_gcode = true; - m_cur_slice_plate = 0; - // select plate + m_cur_slice_plate = 0; + //select plate q->select_plate(m_cur_slice_plate); q->reslice(); if (!m_is_publishing) q->select_view_3D("Preview"); - // BBS: wish to select all plates stats item + //BBS: wish to select all plates stats item preview->get_canvas3d()->_update_select_plate_toolbar_stats_item(true); } } -void Plater::priv::on_action_publish(wxCommandEvent& event) +void Plater::priv::on_action_publish(wxCommandEvent &event) { if (q != nullptr) { if (event.GetInt() == EVT_PUBLISHING_START) { @@ -12961,7 +12897,7 @@ void Plater::priv::on_action_publish(wxCommandEvent& event) void Plater::priv::on_action_print_plate(SimpleEvent&) { if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received print plate event\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received print plate event\n" ; } PresetBundle& preset_bundle = *wxGetApp().preset_bundle; @@ -12996,7 +12932,7 @@ void Plater::priv::on_action_print_plate_from_sdcard(SimpleEvent&) BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received print plate event\n"; } - // BBS + //BBS open_machine_select_dialog(0, PrintFromType::FROM_SDCARD_VIEW); } @@ -13015,11 +12951,12 @@ void Plater::priv::on_tab_selection_changing(wxBookCtrlEvent& e) return; } const wxString new_name = main_frame->m_tabpanel->GetPageName(new_sel); - sidebar_layout.show = new_name == TAB_ID_PREPARE || new_name == TAB_ID_PREVIEW; + sidebar_layout.show = new_name == TAB_ID_PREPARE || new_name == TAB_ID_PREVIEW; update_sidebar(); - int old_sel = e.GetOldSelection(); - const bool use_printer_agents = wxGetApp().app_config->get_bool("use_printer_agents"); - const bool use_native_device_tab = wxGetApp().preset_bundle && (wxGetApp().preset_bundle->use_bbl_device_tab() || use_printer_agents); + int old_sel = e.GetOldSelection(); + const bool use_printer_agents = wxGetApp().app_config->get_bool("use_printer_agents"); + const bool use_native_device_tab = wxGetApp().preset_bundle && + (wxGetApp().preset_bundle->use_bbl_device_tab() || use_printer_agents); if (use_native_device_tab && new_name == TAB_ID_MONITOR) { // BBL network module is only required for BBL-vendor printers. // Non-BBL Python plugins (e.g. moonraker) drive the Device tab without it. @@ -13036,12 +12973,12 @@ void Plater::priv::on_tab_selection_changing(wxBookCtrlEvent& e) // while the native Device tab holds TAB_ID_MONITOR, and in legacy-web mode it holds // TAB_ID_MONITOR itself. const bool selecting_web_device_tab = main_frame->m_printer_view && - main_frame->m_tabpanel->GetPage(new_sel) == main_frame->m_printer_view; + main_frame->m_tabpanel->GetPage(new_sel) == main_frame->m_printer_view; if (selecting_web_device_tab) { // Use the selected discovered machine when the preset has no host. main_frame->load_printer_url(); } else if (new_name == TAB_ID_MONITOR && wxGetApp().preset_bundle != nullptr) { - auto cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config; + auto cfg = wxGetApp().preset_bundle->printers.get_edited_preset().config; wxString url = from_u8(PrintHost::get_print_host_webui(&cfg)); if (main_frame->m_printer_view && url.empty()) { // It's missing_connection page, reload so that we can replay the gif image @@ -13051,34 +12988,30 @@ void Plater::priv::on_tab_selection_changing(wxBookCtrlEvent& e) } } -int Plater::priv::update_print_required_data(Slic3r::DynamicPrintConfig config, - Slic3r::Model model, - Slic3r::PlateDataPtrs plate_data_list, - std::string file_name, - std::string file_path) +int Plater::priv::update_print_required_data(Slic3r::DynamicPrintConfig config, Slic3r::Model model, Slic3r::PlateDataPtrs plate_data_list, std::string file_name, std::string file_path) { - if (!m_select_machine_dlg) - m_select_machine_dlg = new SelectMachineDialog(q); + if (!m_select_machine_dlg) m_select_machine_dlg = new SelectMachineDialog(q); return m_select_machine_dlg->update_print_required_data(config, model, plate_data_list, file_name, file_path); } void Plater::priv::on_action_send_to_printer(bool isall) { - if (!m_send_to_sdcard_dlg) - m_send_to_sdcard_dlg = new SendToPrinterDialog(q); + if (!m_send_to_sdcard_dlg) m_send_to_sdcard_dlg = new SendToPrinterDialog(q); if (isall) { m_send_to_sdcard_dlg->prepare(PLATE_ALL_IDX); - } else { + } + else { m_send_to_sdcard_dlg->prepare(partplate_list.get_curr_plate_index()); } - m_send_to_sdcard_dlg->ShowModal(); + m_send_to_sdcard_dlg->ShowModal(); } -void Plater::priv::on_action_select_sliced_plate(wxCommandEvent& evt) + +void Plater::priv::on_action_select_sliced_plate(wxCommandEvent &evt) { if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received select sliced plate event\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received select sliced plate event\n" ; } bool skip_zoom = evt.GetExtraLong() == 1; q->select_sliced_plate(evt.GetInt(), skip_zoom); @@ -13087,7 +13020,7 @@ void Plater::priv::on_action_select_sliced_plate(wxCommandEvent& evt) void Plater::priv::on_action_print_all(SimpleEvent&) { if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received print all event\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received print all event\n" ; } PresetBundle& preset_bundle = *wxGetApp().preset_bundle; @@ -13101,7 +13034,7 @@ void Plater::priv::on_action_print_all(SimpleEvent&) void Plater::priv::on_action_export_gcode(SimpleEvent&) { if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export gcode event\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export gcode event\n" ; q->export_gcode(false); } } @@ -13109,7 +13042,7 @@ void Plater::priv::on_action_export_gcode(SimpleEvent&) void Plater::priv::on_action_send_gcode(SimpleEvent&) { if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export gcode event\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export gcode event\n" ; q->send_gcode_legacy(); } } @@ -13117,12 +13050,12 @@ void Plater::priv::on_action_send_gcode(SimpleEvent&) void Plater::priv::on_action_export_sliced_file(SimpleEvent&) { if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export sliced file event\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export sliced file event\n" ; q->export_gcode_3mf(); } } -void Plater::priv::on_action_export_all_sliced_file(SimpleEvent&) +void Plater::priv::on_action_export_all_sliced_file(SimpleEvent &) { if (q != nullptr) { BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export all sliced file event\n"; @@ -13132,10 +13065,10 @@ void Plater::priv::on_action_export_all_sliced_file(SimpleEvent&) void Plater::priv::on_action_export_to_sdcard(SimpleEvent&) { - if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export sliced file event\n"; - q->send_to_printer(); - } + if (q != nullptr) { + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received export sliced file event\n"; + q->send_to_printer(); + } } void Plater::priv::on_action_export_to_sdcard_all(SimpleEvent&) @@ -13146,16 +13079,16 @@ void Plater::priv::on_action_export_to_sdcard_all(SimpleEvent&) } } -// BBS: add plate select logic +//BBS: add plate select logic void Plater::priv::on_plate_selected(SimpleEvent&) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received plate selected event\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received plate selected event\n" ; sidebar->obj_list()->on_plate_selected(partplate_list.get_curr_plate_index()); } void Plater::priv::on_action_request_model_id(wxCommandEvent& evt) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received import model id event\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received import model id event\n" ; if (q != nullptr) { q->import_model_id(evt.GetString()); } @@ -13163,23 +13096,29 @@ void Plater::priv::on_action_request_model_id(wxCommandEvent& evt) void Plater::priv::on_action_download_project(wxCommandEvent& evt) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received download project event\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":received download project event\n" ; if (q != nullptr) { q->download_project(evt.GetString()); } } -// BBS: add slice button status update logic +//BBS: add slice button status update logic void Plater::priv::on_slice_button_status(bool enable) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ": enable = " << enable << "\n"; + BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ": enable = "<update_slice_print_status(MainFrame::eEventObjectUpdate, enable); } -void Plater::priv::on_action_split_objects(SimpleEvent&) { split_object(); } +void Plater::priv::on_action_split_objects(SimpleEvent&) +{ + split_object(); +} -void Plater::priv::on_action_split_volumes(SimpleEvent&) { split_volume(); } +void Plater::priv::on_action_split_volumes(SimpleEvent&) +{ + split_volume(); +} void Plater::priv::on_object_select(SimpleEvent& evt) { @@ -13190,13 +13129,16 @@ void Plater::priv::on_object_select(SimpleEvent& evt) selection_changed(); } -// BBS: repair model through cgal -void Plater::priv::on_repair_model(wxCommandEvent& event) { wxGetApp().obj_list()->fix_through_cgal(); } - -void Plater::priv::on_filament_color_changed(wxCommandEvent& event) +//BBS: repair model through cgal +void Plater::priv::on_repair_model(wxCommandEvent &event) { - // q->update_all_plate_thumbnails(true); - // q->get_preview_canvas3D()->update_plate_thumbnails(); + wxGetApp().obj_list()->fix_through_cgal(); +} + +void Plater::priv::on_filament_color_changed(wxCommandEvent &event) +{ + //q->update_all_plate_thumbnails(true); + //q->get_preview_canvas3D()->update_plate_thumbnails(); int modify_id = event.GetInt(); auto& ams_multi_color_filment = wxGetApp().preset_bundle->ams_multi_color_filment; @@ -13211,17 +13153,17 @@ void Plater::priv::on_filament_color_changed(wxCommandEvent& event) sidebar->update_mixed_filament_list(); } -void Plater::priv::install_network_plugin(wxCommandEvent& event) +void Plater::priv::install_network_plugin(wxCommandEvent &event) { wxGetApp().ShowDownNetPluginDlg(); return; } -void Plater::priv::update_plugin_when_launch(wxCommandEvent& event) +void Plater::priv::update_plugin_when_launch(wxCommandEvent &event) { std::string data_dir_str = data_dir(); boost::filesystem::path data_dir_path(data_dir_str); - auto cache_folder = data_dir_path / "ota"; + auto cache_folder = data_dir_path / "ota"; std::string changelog_file = cache_folder.string() + "/plugins/network_plugins.json"; UpdatePluginDialog dlg(wxGetApp().mainframe); @@ -13229,8 +13171,7 @@ void Plater::priv::update_plugin_when_launch(wxCommandEvent& event) auto result = dlg.ShowModal(); auto app_config = wxGetApp().app_config; - if (!app_config) - return; + if (!app_config) return; if (result == wxID_OK) { // Apply the downloaded update right away and hot-reload the plug-in, the same @@ -13241,36 +13182,32 @@ void Plater::priv::update_plugin_when_launch(wxCommandEvent& event) notification_manager->close_notification_of_type(NotificationType::BBLPluginUpdateAvailable); app_config->set("update_network_plugin", "false"); if (wxGetApp().hot_reload_network_plugin()) { - MessageDialog dlg_ok(wxGetApp().mainframe, _L("Network plug-in switched successfully."), _L("Success"), - wxOK | wxICON_INFORMATION); + MessageDialog dlg_ok(wxGetApp().mainframe, _L("Network plug-in switched successfully."), _L("Success"), wxOK | wxICON_INFORMATION); dlg_ok.ShowModal(); } else { - MessageDialog dlg_fail(wxGetApp().mainframe, _L("Failed to load network plug-in. Please restart the application."), - _L("Restart Required"), wxOK | wxICON_WARNING); + MessageDialog dlg_fail(wxGetApp().mainframe, _L("Failed to load network plug-in. Please restart the application."), _L("Restart Required"), wxOK | wxICON_WARNING); dlg_fail.ShowModal(); } } else { app_config->set("update_network_plugin", had_cache ? "true" : "false"); } - } else if (result == wxID_NO) { + } + else if (result == wxID_NO) { app_config->set("update_network_plugin", "false"); } } -void Plater::priv::show_install_plugin_hint(wxCommandEvent& event) +void Plater::priv::show_install_plugin_hint(wxCommandEvent &event) { - notification_manager->bbl_show_plugin_install_notification( - into_u8(_L("The network plug-in was not detected. Network related features are unavailable."))); + notification_manager->bbl_show_plugin_install_notification(into_u8(_L("The network plug-in was not detected. Network related features are unavailable."))); } -void Plater::priv::show_preview_only_hint(wxCommandEvent& event) +void Plater::priv::show_preview_only_hint(wxCommandEvent &event) { - notification_manager->bbl_show_preview_only_notification( - into_u8(_L("Preview only mode:\nThe loaded file contains G-code only, cannot enter the Prepare page."))); + notification_manager->bbl_show_preview_only_notification(into_u8(_L("Preview only mode:\nThe loaded file contains G-code only, cannot enter the Prepare page."))); } -void Plater::priv::on_apple_change_color_mode(wxSysColourChangedEvent& evt) -{ +void Plater::priv::on_apple_change_color_mode(wxSysColourChangedEvent& evt) { m_is_dark = wxSystemSettings::GetAppearance().IsDark(); if (view3D->get_canvas3d() && view3D->get_canvas3d()->is_initialized()) { view3D->get_canvas3d()->on_change_color_mode(m_is_dark); @@ -13281,25 +13218,22 @@ void Plater::priv::on_apple_change_color_mode(wxSysColourChangedEvent& evt) apply_color_mode(); } -void Plater::priv::on_change_color_mode(SimpleEvent& evt) -{ +void Plater::priv::on_change_color_mode(SimpleEvent& evt) { m_is_dark = wxGetApp().app_config->get("dark_color_mode") == "1"; sidebar->on_change_color_mode(m_is_dark); view3D->get_canvas3d()->on_change_color_mode(m_is_dark); preview->get_canvas3d()->on_change_color_mode(m_is_dark); assemble_view->get_canvas3d()->on_change_color_mode(m_is_dark); - if (m_send_to_sdcard_dlg) - m_send_to_sdcard_dlg->on_change_color_mode(); + if (m_send_to_sdcard_dlg) m_send_to_sdcard_dlg->on_change_color_mode(); apply_color_mode(); } void Plater::priv::apply_color_mode() { - const bool is_dark = wxGetApp().dark_mode(); - wxColour orca_color = wxColour(59, 68, - 70); // wxColour(ColorRGBA::ORCA().r_uchar(), ColorRGBA::ORCA().g_uchar(), ColorRGBA::ORCA().b_uchar()); - orca_color = is_dark ? StateColor::darkModeColorFor(orca_color) : StateColor::lightModeColorFor(orca_color); + const bool is_dark = wxGetApp().dark_mode(); + wxColour orca_color = wxColour(59, 68, 70);//wxColour(ColorRGBA::ORCA().r_uchar(), ColorRGBA::ORCA().g_uchar(), ColorRGBA::ORCA().b_uchar()); + orca_color = is_dark ? StateColor::darkModeColorFor(orca_color) : StateColor::lightModeColorFor(orca_color); wxColour sash_color = is_dark ? wxColour(38, 46, 48) : wxColour(206, 206, 206); m_aui_mgr.GetArtProvider()->SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_COLOUR, sash_color); m_aui_mgr.GetArtProvider()->SetColour(wxAUI_DOCKART_INACTIVE_CAPTION_TEXT_COLOUR, *wxWHITE); @@ -13307,8 +13241,7 @@ void Plater::priv::apply_color_mode() m_aui_mgr.GetArtProvider()->SetColour(wxAUI_DOCKART_BORDER_COLOUR, is_dark ? *wxBLACK : wxColour(165, 165, 165)); } -static void get_position(wxWindowBase* child, wxWindowBase* until_parent, int& x, int& y) -{ +static void get_position(wxWindowBase* child, wxWindowBase* until_parent, int& x, int& y) { int res_x = 0, res_y = 0; while (child != until_parent && child != nullptr) { @@ -13324,7 +13257,7 @@ static void get_position(wxWindowBase* child, wxWindowBase* until_parent, int& x y = res_y; } -void Plater::priv::show_right_click_menu(Vec2d mouse_position, wxMenu* menu) +void Plater::priv::show_right_click_menu(Vec2d mouse_position, wxMenu *menu) { // BBS: GUI refactor: move sidebar to the left int x, y; @@ -13335,7 +13268,7 @@ void Plater::priv::show_right_click_menu(Vec2d mouse_position, wxMenu* menu) // specified (even though the position is sane). position = wxDefaultPosition; #endif - GLCanvas3D& canvas = *q->canvas3D(); + GLCanvas3D &canvas = *q->canvas3D(); canvas.apply_retina_scale(mouse_position); canvas.set_popup_menu_position(mouse_position); q->PopupMenu(menu, position); @@ -13348,19 +13281,22 @@ void Plater::priv::on_right_click(RBtnEvent& evt) wxMenu* menu = nullptr; - if (obj_idx == -1) { // no one or several object are selected - if (evt.data.second) { // right button was clicked on empty space + if (obj_idx == -1) { // no one or several object are selected + if (evt.data.second) { // right button was clicked on empty space if (!get_selection().is_empty()) // several objects are selected in 3DScene return; menu = menus.default_menu(); - } else { + } + else { if (current_panel == assemble_view) { menu = menus.assemble_multi_selection_menu(); - } else { + } + else { menu = menus.multi_selection_menu(); } } - } else { + } + else { // If in 3DScene is(are) selected volume(s), but right button was clicked on empty space if (evt.data.second) return; @@ -13374,24 +13310,24 @@ void Plater::priv::on_right_click(RBtnEvent& evt) else { const Selection& selection = get_selection(); // show "Object menu" for each one or several FullInstance instead of FullObject - const bool is_some_full_instances = selection.is_single_full_instance() || selection.is_single_full_object() || + const bool is_some_full_instances = selection.is_single_full_instance() || + selection.is_single_full_object() || selection.is_multiple_full_instance(); - const bool is_part = selection.is_single_volume() || selection.is_single_modifier(); + const bool is_part = selection.is_single_volume() || selection.is_single_modifier(); - // BBS get assemble view menu + //BBS get assemble view menu if (current_panel == assemble_view) { - menu = is_some_full_instances ? menus.assemble_object_menu() : - is_part ? menus.assemble_part_menu() : - menus.assemble_multi_selection_menu(); + menu = is_some_full_instances ? menus.assemble_object_menu() : + is_part ? menus.assemble_part_menu() : menus.assemble_multi_selection_menu(); } else { if (is_some_full_instances) menu = printer_technology == ptSLA ? menus.sla_object_menu() : menus.object_menu(); else if (is_part) { - const GLVolume* gl_volume = selection.get_first_volume(); - const ModelVolume* model_volume = get_model_volume(*gl_volume, selection.get_model()->objects); - menu = (model_volume != nullptr && model_volume->is_text()) ? menus.text_part_menu() : - (model_volume != nullptr && model_volume->is_svg()) ? menus.svg_part_menu() : - menus.part_menu(); + const GLVolume* gl_volume = selection.get_first_volume(); + const ModelVolume *model_volume = get_model_volume(*gl_volume, selection.get_model()->objects); + menu = (model_volume != nullptr && model_volume->is_text()) ? menus.text_part_menu() : + (model_volume != nullptr && model_volume->is_svg()) ? menus.svg_part_menu() : + menus.part_menu(); } else menu = menus.multi_selection_menu(); } @@ -13403,10 +13339,10 @@ void Plater::priv::on_right_click(RBtnEvent& evt) } } -// BBS: add part plate related logic +//BBS: add part plate related logic void Plater::priv::on_plate_right_click(RBtnPlateEvent& evt) { - wxMenu* menu = menus.plate_menu(); + wxMenu *menu = menus.plate_menu(); show_right_click_menu(evt.data.first, menu); } @@ -13415,7 +13351,10 @@ void Plater::priv::on_update_geometry(Vec3dsEvent<2>&) // TODO } -void Plater::priv::on_3dcanvas_mouse_dragging_started(SimpleEvent&) { view3D->get_canvas3d()->reset_sequential_print_clearance(); } +void Plater::priv::on_3dcanvas_mouse_dragging_started(SimpleEvent&) +{ + view3D->get_canvas3d()->reset_sequential_print_clearance(); +} // Update the scene from the background processing, // if the update message was received during mouse manipulation. @@ -13426,21 +13365,23 @@ void Plater::priv::on_3dcanvas_mouse_dragging_finished(SimpleEvent&) update_sla_scene(); } - // partplate_list.reload_all_objects(); + //partplate_list.reload_all_objects(); } -// BBS: add plate id for thumbnail generate param -void Plater::priv::generate_thumbnail(ThumbnailData& data, - unsigned int w, - unsigned int h, - const ThumbnailsParams& thumbnail_params, - Camera::EType camera_type, - Camera::ViewAngleType camera_view_angle_type, - bool for_picking, - bool ban_light) -{ view3D->get_canvas3d()->render_thumbnail(data, w, h, thumbnail_params, camera_type, camera_view_angle_type, for_picking, ban_light); } +//BBS: add plate id for thumbnail generate param +void Plater::priv::generate_thumbnail(ThumbnailData & data, + unsigned int w, + unsigned int h, + const ThumbnailsParams &thumbnail_params, + Camera::EType camera_type, + Camera::ViewAngleType camera_view_angle_type, + bool for_picking, + bool ban_light) +{ + view3D->get_canvas3d()->render_thumbnail(data, w, h, thumbnail_params, camera_type, camera_view_angle_type, for_picking, ban_light); +} -// BBS: add plate id for thumbnail generate param +//BBS: add plate id for thumbnail generate param ThumbnailsList Plater::priv::generate_thumbnails(const ThumbnailsParams& params, Camera::EType camera_type) { ThumbnailsList thumbnails; @@ -13459,48 +13400,49 @@ PlateBBoxData Plater::priv::generate_first_layer_bbox() PlateBBoxData bboxdata; std::vector& id_bboxes = bboxdata.bbox_objs; BoundingBoxf bbox_all; - auto print = this->background_process.m_fff_print; - auto curr_plate = this->partplate_list.get_curr_plate(); - auto curr_plate_seq = curr_plate->get_real_print_seq(); - bboxdata.is_seq_print = (curr_plate_seq == PrintSequence::ByObject); - bboxdata.first_extruder = print->get_tool_ordering().first_extruder(); - bboxdata.bed_type = bed_type_to_gcode_string(print->config().curr_bed_type.value); + auto print = this->background_process.m_fff_print; + auto curr_plate = this->partplate_list.get_curr_plate(); + auto curr_plate_seq = curr_plate->get_real_print_seq(); + bboxdata.is_seq_print = (curr_plate_seq == PrintSequence::ByObject); + bboxdata.first_extruder = print->get_tool_ordering().first_extruder(); + bboxdata.bed_type = bed_type_to_gcode_string(print->config().curr_bed_type.value); bboxdata.first_layer_time = partplate_list.get_curr_plate()->get_slice_result()->initial_layer_time; // get nozzle diameter auto opt_nozzle_diameters = print->config().option("nozzle_diameter"); if (opt_nozzle_diameters != nullptr) bboxdata.nozzle_diameter = float(opt_nozzle_diameters->get_at(bboxdata.first_extruder)); - // PrintObjectPtrs objects; - // if (this->printer_technology == ptFFF) { - // objects = this->background_process.m_fff_print->objects().vector(); - // } - // else { - // objects = this->background_process.m_sla_print->objects(); - // } + //PrintObjectPtrs objects; + //if (this->printer_technology == ptFFF) { + // objects = this->background_process.m_fff_print->objects().vector(); + //} + //else { + // objects = this->background_process.m_sla_print->objects(); + //} auto objects = print->objects(); - auto orig = this->partplate_list.get_curr_plate()->get_origin(); - Vec2d orig2d = {orig[0], orig[1]}; + auto orig = this->partplate_list.get_curr_plate()->get_origin(); + Vec2d orig2d = { orig[0], orig[1] }; BBoxData data; - for (auto obj : objects) { + for (auto obj : objects) + { auto bb_scaled = obj->get_first_layer_bbox(data.area, data.layer_height, data.name); - auto bb = unscaled(bb_scaled); + auto bb = unscaled(bb_scaled); bb.min -= orig2d; bb.max -= orig2d; bbox_all.merge(bb); data.area *= (SCALING_FACTOR * SCALING_FACTOR); // unscale area - data.id = obj->id().id; - data.bbox = {bb.min.x(), bb.min.y(), bb.max.x(), bb.max.y()}; + data.id = obj->id().id; + data.bbox = { bb.min.x(),bb.min.y(),bb.max.x(),bb.max.y() }; id_bboxes.emplace_back(data); } // add wipe tower bounding box if (print->has_wipe_tower()) { - auto wt_corners = print->first_layer_wipe_tower_corners(); + auto wt_corners = print->first_layer_wipe_tower_corners(); // when loading gcode.3mf, wipe tower info may not be correct if (!wt_corners.empty()) { BoundingBox bb_scaled = {wt_corners[0], wt_corners[2]}; - auto bb = unscaled(bb_scaled); + auto bb = unscaled(bb_scaled); bb.min -= orig2d; bb.max -= orig2d; bbox_all.merge(bb); @@ -13511,7 +13453,7 @@ PlateBBoxData Plater::priv::generate_first_layer_bbox() } } - bboxdata.bbox_all = {bbox_all.min.x(), bbox_all.min.y(), bbox_all.max.x(), bbox_all.max.y()}; + bboxdata.bbox_all = { bbox_all.min.x(),bbox_all.min.y(),bbox_all.max.x(),bbox_all.max.y() }; return bboxdata; } @@ -13540,8 +13482,7 @@ wxString Plater::priv::get_export_gcode_filename(const wxString& extension, bool auto full_filename = m_project_folder / std::string((m_project_name + extension).mb_str(wxConvUTF8)); return from_path(full_filename); } else { - auto full_filename = m_project_folder / - std::string((m_project_name + from_u8(plate_index_str) + extension).mb_str(wxConvUTF8)); + auto full_filename = m_project_folder / std::string((m_project_name + from_u8(plate_index_str) + extension).mb_str(wxConvUTF8)); return from_path(full_filename); } } else { @@ -13552,26 +13493,30 @@ wxString Plater::priv::get_export_gcode_filename(const wxString& extension, bool } } else { if (only_filename) { - if (!model.objects.empty() && m_project_name == _L("Untitled")) + if(!model.objects.empty() && m_project_name == _L("Untitled")) return wxString(fs::path(model.objects.front()->name).replace_extension().c_str()) + from_u8(plate_index_str) + extension; if (export_all) return m_project_name + extension; else return m_project_name + from_u8(plate_index_str) + extension; - } else + } + else return ""; } } -wxString Plater::priv::get_project_name() { return m_project_name; } +wxString Plater::priv::get_project_name() +{ + return m_project_name; +} -// BBS +//BBS void Plater::priv::set_project_name(const wxString& project_name) { BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << __LINE__ << " project is:" << project_name; m_project_name = project_name; - // update topbar title + //update topbar title #ifdef __APPLE__ wxGetApp().mainframe->SetTitle(m_project_name); if (!m_project_name.IsEmpty()) @@ -13599,30 +13544,30 @@ void Plater::priv::update_title_dirty_status() #else wxGetApp().mainframe->SetTitle(title + " - OrcaSlicer"); wxGetApp().mainframe->topbar()->SetTitle(title); -#endif +#endif } void Plater::priv::set_project_filename(const wxString& filename) { boost::filesystem::path full_path = into_path(filename); - boost::filesystem::path ext = full_path.extension(); - // if (boost::iequals(ext.string(), ".amf")) { - // // Remove the first extension. - // full_path.replace_extension(""); - // // It may be ".zip.amf". - // if (boost::iequals(full_path.extension().string(), ".zip")) - // // Remove the 2nd extension. - // full_path.replace_extension(""); - // } else { - // // Remove just one extension. - // full_path.replace_extension(""); - // } + boost::filesystem::path ext = full_path.extension(); + //if (boost::iequals(ext.string(), ".amf")) { + // // Remove the first extension. + // full_path.replace_extension(""); + // // It may be ".zip.amf". + // if (boost::iequals(full_path.extension().string(), ".zip")) + // // Remove the 2nd extension. + // full_path.replace_extension(""); + //} else { + // // Remove just one extension. + // full_path.replace_extension(""); + //} full_path.replace_extension(""); m_project_folder = full_path.parent_path(); BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << __LINE__ << " project folder is:" << m_project_folder.string(); - // BBS + //BBS wxString project_name = from_u8(full_path.filename().string()); set_project_name(project_name); // record filename for hint when open exported file/.gcode @@ -13654,14 +13599,14 @@ void Plater::priv::init_notification_manager() notification_manager->init_progress_indicator(); } -void Plater::priv::update_objects_position_when_select_preset(const std::function& select_prest) +void Plater::priv::update_objects_position_when_select_preset(const std::function &select_prest) { select_prest(); wxGetApp().obj_list()->update_object_list_by_printer_technology(); // Re-clamp wipe tower positions to new bed boundaries after preset change - PartPlateList& cur_plate_list = this->partplate_list; + PartPlateList &cur_plate_list = this->partplate_list; for (size_t plate_id = 0; plate_id < cur_plate_list.get_plate_list().size(); ++plate_id) { cur_plate_list.set_default_wipe_tower_pos_for_plate(plate_id); } @@ -13671,23 +13616,29 @@ void Plater::priv::update_objects_position_when_select_preset(const std::functio void Plater::orient() { - auto& w = get_ui_job_worker(); + auto &w = get_ui_job_worker(); if (w.is_idle()) { p->take_snapshot(_u8L("Orient")); replace_job(w, std::make_unique()); } } -// BBS: add job state related functions -void Plater::set_prepare_state(int state) { p->m_job_prepare_state = state; } +//BBS: add job state related functions +void Plater::set_prepare_state(int state) +{ + p->m_job_prepare_state = state; +} -int Plater::get_prepare_state() { return p->m_job_prepare_state; } +int Plater::get_prepare_state() +{ + return p->m_job_prepare_state; +} void Plater::get_print_job_data(PrintPrepareData* data) { if (data) { - data->plate_idx = p->m_print_job_data.plate_idx; - data->_3mf_path = p->m_print_job_data._3mf_path; + data->plate_idx = p->m_print_job_data.plate_idx; + data->_3mf_path = p->m_print_job_data._3mf_path; data->_3mf_config_path = p->m_print_job_data._3mf_config_path; } } @@ -13696,18 +13647,32 @@ void Plater::set_print_job_plate_idx(int plate_idx) { if (plate_idx == PLATE_CURRENT_IDX) { p->m_print_job_data.plate_idx = get_partplate_list().get_curr_plate_index(); - } else { + } + else { p->m_print_job_data.plate_idx = plate_idx; } } -int Plater::get_send_calibration_finished_event() { return EVT_SEND_CALIBRATION_FINISHED; } -int Plater::get_print_finished_event() { return EVT_PRINT_FINISHED; } +int Plater::get_send_calibration_finished_event() +{ + return EVT_SEND_CALIBRATION_FINISHED; +} -int Plater::get_send_finished_event() { return EVT_SEND_FINISHED; } +int Plater::get_print_finished_event() +{ + return EVT_PRINT_FINISHED; +} -int Plater::get_publish_finished_event() { return EVT_PUBLISH_FINISHED; } +int Plater::get_send_finished_event() +{ + return EVT_SEND_FINISHED; +} + +int Plater::get_publish_finished_event() +{ + return EVT_PUBLISH_FINISHED; +} void Plater::priv::set_current_canvas_as_dirty() { @@ -13727,10 +13692,10 @@ GLCanvas3D* Plater::priv::get_current_canvas3D(bool exclude_preview) return preview->get_canvas3d(); else if (current_panel == assemble_view) return assemble_view->get_canvas3d(); - else // BBS default set to view3D + else //BBS default set to view3D return view3D->get_canvas3d(); - // return (current_panel == view3D) ? view3D->get_canvas3d() : ((current_panel == preview) ? preview->get_canvas3d() : nullptr); + //return (current_panel == view3D) ? view3D->get_canvas3d() : ((current_panel == preview) ? preview->get_canvas3d() : nullptr); } void Plater::priv::unbind_canvas_event_handlers() @@ -13756,7 +13721,7 @@ void Plater::priv::reset_canvas_volumes() bool Plater::priv::check_ams_status_impl(bool is_slice_all) { - Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + Slic3r::DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); if (!dev) return true; @@ -13766,9 +13731,9 @@ bool Plater::priv::check_ams_status_impl(bool is_slice_all) if (q->is_gcode_3mf() || q->only_gcode_mode() || q->get_partplate_list().get_curr_plate()->get_objects().empty()) { return true; } - PresetBundle* preset_bundle = wxGetApp().preset_bundle; + PresetBundle *preset_bundle = wxGetApp().preset_bundle; if (preset_bundle && preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle) == obj->get_show_printer_type()) { - bool is_same_as_printer = true; + bool is_same_as_printer = true; auto nozzle_volumes_values = preset_bundle->project_config.option("nozzle_volume_type")->values; assert(obj->GetExtderSystem()->GetTotalExtderCount() == 2 && nozzle_volumes_values.size() == 2); if (obj->GetExtderSystem()->GetTotalExtderCount() == 2 && nozzle_volumes_values.size() == 2) { @@ -13778,14 +13743,13 @@ bool Plater::priv::check_ams_status_impl(bool is_slice_all) // After device sync, extruder_nozzle_stats matches printer → dialog suppressed. // Reference to BBS: BambuStudio/src/slic3r/GUI/Plater.cpp is_extruder_stat_synced() using namespace MultiNozzleUtils; - auto nozzle_diameter_values = - preset_bundle->printers.get_edited_preset().config.option("nozzle_diameter")->values; + auto nozzle_diameter_values = preset_bundle->printers.get_edited_preset().config.option("nozzle_diameter")->values; // Build preset nozzle groups from extruder_nozzle_stats config std::vector> preset_nozzle_infos(nozzle_diameter_values.size()); for (size_t extruder_id = 0; extruder_id < nozzle_diameter_values.size(); ++extruder_id) { NozzleVolumeType preset_volume_type = NozzleVolumeType(nozzle_volumes_values[extruder_id]); - std::string preset_diameter = format_diameter_to_str(nozzle_diameter_values[extruder_id]); + std::string preset_diameter = format_diameter_to_str(nozzle_diameter_values[extruder_id]); if (preset_volume_type == nvtHybrid) { // Hybrid: expand into separate groups for each nozzle type from stats @@ -13808,9 +13772,9 @@ bool Plater::priv::check_ams_status_impl(bool is_slice_all) for (const auto& preset_group : preset_groups) { if (preset_group.nozzle_count == 0) { // Never synced: if printer has nozzles of this type → needs sync - if (std::find_if(printer_groups.begin(), printer_groups.end(), [&preset_group](const NozzleGroupInfo& elem) { - return preset_group.is_same_type(elem); - }) != printer_groups.end()) { + if (std::find_if(printer_groups.begin(), printer_groups.end(), + [&preset_group](const NozzleGroupInfo& elem) { return preset_group.is_same_type(elem); }) + != printer_groups.end()) { is_same_as_printer = false; break; } @@ -13852,22 +13816,21 @@ bool Plater::priv::check_ams_status_impl(bool is_slice_all) } if (!preset_bundle->extruder_ams_counts.empty() && !preset_bundle->extruder_ams_counts.front().empty()) { - is_same_as_printer &= preset_bundle->extruder_ams_counts[0][4] == left_4 && - preset_bundle->extruder_ams_counts[0][1] == left_1 && - preset_bundle->extruder_ams_counts[1][4] == right_4 && - preset_bundle->extruder_ams_counts[1][1] == right_1; + is_same_as_printer &= preset_bundle->extruder_ams_counts[0][4] == left_4 + && preset_bundle->extruder_ams_counts[0][1] == left_1 + && preset_bundle->extruder_ams_counts[1][4] == right_4 + && preset_bundle->extruder_ams_counts[1][1] == right_1; } if (!is_same_as_printer) { struct SyncInfoDialog : MessageDialog { - SyncInfoDialog(wxWindow* parent) + SyncInfoDialog(wxWindow *parent) : MessageDialog(parent, _L("The nozzle type and AMS quantity information has not been synced from the connected printer.\n" "After syncing, software can optimize printing time and filament usage when slicing.\n" "Would you like to sync now?"), - _L("Warning"), - 0) + _L("Warning"), 0) { add_button(wxID_YES, true, _L("Sync now")); add_button(wxID_NO, true, _L("Later")); @@ -13892,7 +13855,7 @@ bool Plater::priv::check_ams_status_impl(bool is_slice_all) bool Plater::priv::get_machine_sync_status() { - Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + Slic3r::DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); if (!dev) return false; @@ -13900,7 +13863,7 @@ bool Plater::priv::get_machine_sync_status() if (!obj) return false; - PresetBundle* preset_bundle = wxGetApp().preset_bundle; + PresetBundle *preset_bundle = wxGetApp().preset_bundle; return preset_bundle && preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle) == obj->get_show_printer_type(); } @@ -13915,10 +13878,10 @@ bool Plater::priv::init_collapse_toolbar() BackgroundTexture::Metadata background_data; background_data.filename = m_is_dark ? "toolbar_background_dark.png" : "toolbar_background.png"; - background_data.left = 16; - background_data.top = 16; - background_data.right = 16; - background_data.bottom = 16; + background_data.left = 16; + background_data.top = 16; + background_data.right = 16; + background_data.bottom = 16; if (!collapse_toolbar.init(background_data)) return false; @@ -13936,9 +13899,11 @@ bool Plater::priv::init_collapse_toolbar() item.name = "collapse_sidebar"; // set collapse svg name - item.icon_filename = "collapse.svg"; - item.sprite_id = 0; - item.left.action_callback = []() { wxGetApp().plater()->collapse_sidebar(!wxGetApp().plater()->is_sidebar_collapsed()); }; + item.icon_filename = "collapse.svg"; + item.sprite_id = 0; + item.left.action_callback = []() { + wxGetApp().plater()->collapse_sidebar(!wxGetApp().plater()->is_sidebar_collapsed()); + }; if (!collapse_toolbar.add_item(item)) return false; @@ -13949,7 +13914,10 @@ bool Plater::priv::init_collapse_toolbar() return true; } -void Plater::priv::update_preview_bottom_toolbar() { ; } +void Plater::priv::update_preview_bottom_toolbar() +{ + ; +} #if 0 void Plater::update_partplate() @@ -13958,25 +13926,32 @@ void Plater::update_partplate() } #endif -void Plater::priv::reset_gcode_toolpaths() { preview->get_canvas3d()->reset_gcode_toolpaths(); } +void Plater::priv::reset_gcode_toolpaths() +{ + preview->get_canvas3d()->reset_gcode_toolpaths(); +} bool Plater::priv::can_set_instance_to_object() const { const int obj_idx = get_selected_object_idx(); - return 0 <= obj_idx && obj_idx < (int) model.objects.size() && model.objects[obj_idx]->instances.size() > 1; + return 0 <= obj_idx && obj_idx < (int)model.objects.size() && model.objects[obj_idx]->instances.size() > 1; } -bool Plater::priv::can_split(bool to_objects) const { return sidebar->obj_list()->is_splittable(to_objects); } +bool Plater::priv::can_split(bool to_objects) const +{ + return sidebar->obj_list()->is_splittable(to_objects); +} bool Plater::priv::can_fillcolor() const { - // BBS TODO + //BBS TODO return true; } bool Plater::priv::has_assemble_view() const { - for (auto object : model.objects) { + for (auto object: model.objects) + { for (auto instance : object->instances) if (instance->is_assemble_initialized()) return true; @@ -13997,19 +13972,29 @@ bool Plater::priv::has_assemble_view() const bool Plater::priv::can_scale_to_print_volume() const { const BuildVolume_Type type = this->bed.build_volume().type(); - return !sidebar->obj_list()->has_selected_cut_object() && !view3D->get_canvas3d()->get_selection().is_empty() && - (type == BuildVolume_Type::Rectangle || type == BuildVolume_Type::Circle); + return !sidebar->obj_list()->has_selected_cut_object() + && !view3D->get_canvas3d()->get_selection().is_empty() + && (type == BuildVolume_Type::Rectangle || type == BuildVolume_Type::Circle); } #endif // ENABLE_ENHANCED_PRINT_VOLUME_FIT bool Plater::priv::can_mirror() const -{ return !sidebar->obj_list()->has_selected_cut_object() && get_selection().is_from_single_instance(); } +{ + return !sidebar->obj_list()->has_selected_cut_object() + && get_selection().is_from_single_instance(); +} bool Plater::priv::can_replace_with_stl() const -{ return !sidebar->obj_list()->has_selected_cut_object() && get_selection().get_volume_idxs().size() == 1; } +{ + return !sidebar->obj_list()->has_selected_cut_object() + && get_selection().get_volume_idxs().size() == 1; +} bool Plater::priv::can_replace_all_with_stl() const -{ return !sidebar->obj_list()->has_selected_cut_object() && get_selection().get_volume_idxs().size() != 1; } +{ + return !sidebar->obj_list()->has_selected_cut_object() + && get_selection().get_volume_idxs().size() != 1; +} bool Plater::priv::can_reload_from_disk() const { @@ -14030,9 +14015,8 @@ bool Plater::priv::can_reload_from_disk() const int volume_idx; // operators needed by std::algorithms - bool operator<(const SelectedVolume& other) const - { return (object_idx < other.object_idx) || ((object_idx == other.object_idx) && (volume_idx < other.volume_idx)); } - bool operator==(const SelectedVolume& other) const { return (object_idx == other.object_idx) && (volume_idx == other.volume_idx); } + bool operator < (const SelectedVolume& other) const { return (object_idx < other.object_idx) || ((object_idx == other.object_idx) && (volume_idx < other.volume_idx)); } + bool operator == (const SelectedVolume& other) const { return (object_idx == other.object_idx) && (volume_idx == other.volume_idx); } }; std::vector selected_volumes; @@ -14042,24 +14026,22 @@ bool Plater::priv::can_reload_from_disk() const const std::set& selected_volumes_idxs = selection.get_volume_idxs(); for (unsigned int idx : selected_volumes_idxs) { const GLVolume* v = selection.get_volume(idx); - int v_idx = v->volume_idx(); + int v_idx = v->volume_idx(); if (v_idx >= 0) { int o_idx = v->object_idx(); - if (0 <= o_idx && o_idx < (int) model.objects.size()) - selected_volumes.push_back({o_idx, v_idx}); + if (0 <= o_idx && o_idx < (int)model.objects.size()) + selected_volumes.push_back({ o_idx, v_idx }); } } #endif // ENABLE_RELOAD_FROM_DISK_REWORK #if ENABLE_RELOAD_FROM_DISK_REWORK - std::sort(selected_volumes.begin(), selected_volumes.end(), [](const std::pair& v1, const std::pair& v2) { + std::sort(selected_volumes.begin(), selected_volumes.end(), [](const std::pair &v1, const std::pair &v2) { return (v1.first < v2.first) || (v1.first == v2.first && v1.second < v2.second); - }); - selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end(), - [](const std::pair& v1, const std::pair& v2) { - return (v1.first == v2.first) && (v1.second == v2.second); - }), - selected_volumes.end()); + }); + selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end(), [](const std::pair &v1, const std::pair &v2) { + return (v1.first == v2.first) && (v1.second == v2.second); + }), selected_volumes.end()); // collects paths of files to load std::vector paths; @@ -14087,7 +14069,7 @@ bool Plater::priv::can_reload_from_disk() const return !paths.empty(); } -void Plater::priv::update_publish_dialog_status(wxString& msg, int percent) +void Plater::priv::update_publish_dialog_status(wxString &msg, int percent) { if (m_publish_dlg) m_publish_dlg->UpdateStatus(msg, percent); @@ -14095,45 +14077,42 @@ void Plater::priv::update_publish_dialog_status(wxString& msg, int percent) bool Plater::priv::show_publish_dlg(bool show) { - if (q != nullptr) { - BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":recevied publish event\n"; - } + if (q != nullptr) { BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ":recevied publish event\n"; } - if (!m_publish_dlg) - m_publish_dlg = new PublishDialog(q); + if (!m_publish_dlg) m_publish_dlg = new PublishDialog(q); if (show) { m_publish_dlg->reset(); m_publish_dlg->start_slicing(); - // m_publish_dlg->Show(); + //m_publish_dlg->Show(); m_publish_dlg->ShowModal(); } else { m_publish_dlg->EndModal(wxID_OK); - // cancel the slicing + //cancel the slicing if (this->background_process.running()) this->background_process.stop(); } return true; } -// BBS: add bed exclude area -void Plater::priv::set_bed_shape(const Pointfs& shape, - const Pointfs& exclude_areas, - const Pointfs& wrapping_exclude_areas, - const double printable_height, +//BBS: add bed exclude area +void Plater::priv::set_bed_shape(const Pointfs &shape, + const Pointfs &exclude_areas, + const Pointfs &wrapping_exclude_areas, + const double printable_height, std::vector extruder_areas, - std::vector extruder_heights, - const std::string& custom_texture, - const std::string& custom_model, - bool force_as_custom) + std::vector extruder_heights, + const std::string &custom_texture, + const std::string &custom_model, + bool force_as_custom) { - // Orca: reduce resolution for large bed printer + //Orca: reduce resolution for large bed printer BoundingBoxf bed_size = get_extents(shape); if (bed_size.size().maxCoeff() <= LARGE_BED_THRESHOLD) SCALING_FACTOR = SCALING_FACTOR_INTERNAL; else SCALING_FACTOR = SCALING_FACTOR_INTERNAL_LARGE_PRINTER; - // BBS: add shape position + //BBS: add shape position Vec2d shape_position = partplate_list.get_current_shape_position(); bool new_shape = bed.set_shape(shape, printable_height, extruder_areas, extruder_heights, custom_model, force_as_custom, shape_position); @@ -14142,28 +14121,25 @@ void Plater::priv::set_bed_shape(const Pointfs& shape, double height_to_lid = config->opt_float("extruder_clearance_height_to_lid"); double height_to_rod = config->opt_float("extruder_clearance_height_to_rod"); - Pointfs prev_exclude_areas = partplate_list.get_exclude_area(); + Pointfs prev_exclude_areas = partplate_list.get_exclude_area(); Pointfs prev_wrapping_exclude_areas = partplate_list.get_wrapping_exclude_area(); - new_shape |= (height_to_lid != prev_height_lid) || (height_to_rod != prev_height_rod) || (prev_exclude_areas != exclude_areas) || - (prev_wrapping_exclude_areas != wrapping_exclude_areas); + new_shape |= (height_to_lid != prev_height_lid) || (height_to_rod != prev_height_rod) || (prev_exclude_areas != exclude_areas) + || (prev_wrapping_exclude_areas != wrapping_exclude_areas); if (!new_shape && partplate_list.get_logo_texture_filename() != custom_texture) { partplate_list.update_logo_texture_filename(custom_texture); } if (new_shape) { - if (view3D) - view3D->bed_shape_changed(); - if (preview) - preview->bed_shape_changed(); + if (view3D) view3D->bed_shape_changed(); + if (preview) preview->bed_shape_changed(); - // BBS: update part plate's size - // BBS: to be checked + //BBS: update part plate's size + // BBS: to be checked Vec3d max = bed.printable_bounding_box().max; Vec3d min = bed.printable_bounding_box().min; - double z = config->opt_float("printable_height"); + double z = config->opt_float("printable_height"); partplate_list.reset_size(max.x() - min.x() - Bed3D::Axes::DefaultTipRadius, max.y() - min.y() - Bed3D::Axes::DefaultTipRadius, z); - partplate_list.set_shapes(shape, exclude_areas, wrapping_exclude_areas, extruder_areas, extruder_heights, custom_texture, - height_to_lid, height_to_rod); + partplate_list.set_shapes(shape, exclude_areas, wrapping_exclude_areas, extruder_areas, extruder_heights, custom_texture, height_to_lid, height_to_rod); Vec2d new_shape_position = partplate_list.get_current_shape_position(); if (shape_position != new_shape_position) @@ -14171,13 +14147,25 @@ void Plater::priv::set_bed_shape(const Pointfs& shape, } } -bool Plater::priv::can_delete() const { return !get_selection().is_empty() && !get_selection().is_wipe_tower(); } +bool Plater::priv::can_delete() const +{ + return !get_selection().is_empty() && !get_selection().is_wipe_tower(); +} -bool Plater::priv::can_delete_all() const { return !model.objects.empty(); } +bool Plater::priv::can_delete_all() const +{ + return !model.objects.empty(); +} -bool Plater::priv::can_add_plate() const { return q->get_partplate_list().get_plate_count() < PartPlateList::MAX_PLATES_COUNT; } +bool Plater::priv::can_add_plate() const +{ + return q->get_partplate_list().get_plate_count() < PartPlateList::MAX_PLATES_COUNT; +} -bool Plater::priv::can_delete_plate() const { return q->get_partplate_list().get_plate_count() > 1; } +bool Plater::priv::can_delete_plate() const +{ + return q->get_partplate_list().get_plate_count() > 1; +} bool Plater::priv::can_fix_through_cgal() const { @@ -14186,8 +14174,8 @@ bool Plater::priv::can_fix_through_cgal() const #if FIX_THROUGH_CGAL_ALWAYS // Fixing always. - return !obj_idxs.empty() || !vol_idxs.empty(); -#else // FIX_THROUGH_CGAL_ALWAYS + return ! obj_idxs.empty() || ! vol_idxs.empty(); +#else // FIX_THROUGH_CGAL_ALWAYS // Fixing only if the model is not manifold. if (vol_idxs.empty()) { for (auto obj_idx : obj_idxs) @@ -14207,10 +14195,10 @@ bool Plater::priv::can_fix_through_cgal() const bool Plater::priv::can_simplify() const { // is object for simplification selected - if (get_selected_object_idx() < 0) - return false; + if (get_selected_object_idx() < 0) return false; // is already opened? - if (q->get_view3D_canvas3D()->get_gizmos_manager().get_current_type() == GLGizmosManager::EType::Simplify) + if (q->get_view3D_canvas3D()->get_gizmos_manager().get_current_type() == + GLGizmosManager::EType::Simplify) return false; return true; } @@ -14235,30 +14223,41 @@ bool Plater::priv::can_smooth_mesh() const bool Plater::priv::can_increase_instances() const { - if (!m_worker.is_idle() || q->get_view3D_canvas3D()->get_gizmos_manager().is_in_editing_mode()) - return false; + if (!m_worker.is_idle() + || q->get_view3D_canvas3D()->get_gizmos_manager().is_in_editing_mode()) + return false; int obj_idx = get_selected_object_idx(); - return (0 <= obj_idx) && (obj_idx < (int) model.objects.size()) && !sidebar->obj_list()->has_selected_cut_object() && - std::all_of(model.objects[obj_idx]->instances.begin(), model.objects[obj_idx]->instances.end(), - [](auto& inst) { return inst->printable; }); + return (0 <= obj_idx) && (obj_idx < (int)model.objects.size()) + && !sidebar->obj_list()->has_selected_cut_object() + && std::all_of(model.objects[obj_idx]->instances.begin(), model.objects[obj_idx]->instances.end(), [](auto& inst) {return inst->printable; }); } bool Plater::priv::can_decrease_instances() const { - if (!m_worker.is_idle() || q->get_view3D_canvas3D()->get_gizmos_manager().is_in_editing_mode()) - return false; + if (!m_worker.is_idle() + || q->get_view3D_canvas3D()->get_gizmos_manager().is_in_editing_mode()) + return false; int obj_idx = get_selected_object_idx(); - return (0 <= obj_idx) && (obj_idx < (int) model.objects.size()) && (model.objects[obj_idx]->instances.size() > 1) && - !sidebar->obj_list()->has_selected_cut_object(); + return (0 <= obj_idx) && (obj_idx < (int)model.objects.size()) && (model.objects[obj_idx]->instances.size() > 1) + && !sidebar->obj_list()->has_selected_cut_object(); } -bool Plater::priv::can_split_to_objects() const { return q->can_split(true); } +bool Plater::priv::can_split_to_objects() const +{ + return q->can_split(true); +} -bool Plater::priv::can_split_to_volumes() const { return (printer_technology != ptSLA) && q->can_split(false); } +bool Plater::priv::can_split_to_volumes() const +{ + return (printer_technology != ptSLA) && q->can_split(false); +} -bool Plater::priv::can_arrange() const { return !model.objects.empty() && m_worker.is_idle(); } +bool Plater::priv::can_arrange() const +{ + return !model.objects.empty() && m_worker.is_idle(); +} bool Plater::priv::layers_height_allowed() const { @@ -14266,11 +14265,13 @@ bool Plater::priv::layers_height_allowed() const return false; int obj_idx = get_selected_object_idx(); - return 0 <= obj_idx && obj_idx < (int) model.objects.size() && model.objects[obj_idx]->max_z() > SINKING_Z_THRESHOLD && - view3D->is_layers_editing_allowed(); + return 0 <= obj_idx && obj_idx < (int)model.objects.size() && model.objects[obj_idx]->max_z() > SINKING_Z_THRESHOLD && view3D->is_layers_editing_allowed(); } -bool Plater::priv::can_layers_editing() const { return layers_height_allowed(); } +bool Plater::priv::can_layers_editing() const +{ + return layers_height_allowed(); +} void Plater::priv::on_action_layersediting(SimpleEvent&) { @@ -14281,9 +14282,9 @@ void Plater::priv::on_action_layersediting(SimpleEvent&) const auto& print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config; if (print_config.opt_bool("enable_mixed_color_sublayer")) { if (wxGetApp().app_config->get("no_warn_mixed_sublayer_variable_layer") != "1") { - MessageDialog - dlg(q, _L("Using variable layer height together with mixed color sublayer may result in poor color mixing quality."), - _L("Warning"), wxICON_WARNING | wxOK); + MessageDialog dlg(q, + _L("Using variable layer height together with mixed color sublayer may result in poor color mixing quality."), + _L("Warning"), wxICON_WARNING | wxOK); dlg.show_dsa_button(); dlg.ShowModal(); if (dlg.get_checkbox_state()) @@ -14295,7 +14296,7 @@ void Plater::priv::on_action_layersediting(SimpleEvent&) notification_manager->set_move_from_overlay(view3D->is_layers_editing_enabled()); } -void Plater::priv::on_create_filament(SimpleEvent&) +void Plater::priv::on_create_filament(SimpleEvent &) { CreateFilamentPresetDialog dlg(wxGetApp().mainframe); int res = dlg.ShowModal(); @@ -14304,48 +14305,51 @@ void Plater::priv::on_create_filament(SimpleEvent&) update_ui_from_settings(); sidebar->update_all_preset_comboboxes(); CreatePresetSuccessfulDialog success_dlg(wxGetApp().mainframe, SuccessType::FILAMENT); - int res = success_dlg.ShowModal(); + int res = success_dlg.ShowModal(); } } -void Plater::priv::on_modify_filament(SimpleEvent& evt) +void Plater::priv::on_modify_filament(SimpleEvent &evt) { - Filamentinformation* filament_info = static_cast(evt.GetEventObject()); - int res; + Filamentinformation *filament_info = static_cast(evt.GetEventObject()); + int res; std::shared_ptr need_edit_preset; { EditFilamentPresetDialog dlg(wxGetApp().mainframe, filament_info); - res = dlg.ShowModal(); + res = dlg.ShowModal(); need_edit_preset = dlg.get_need_edit_preset(); } wxGetApp().mainframe->update_side_preset_ui(); update_ui_from_settings(); sidebar->update_all_preset_comboboxes(); if (wxID_EDIT == res) { - Tab* tab = wxGetApp().get_tab(Preset::Type::TYPE_FILAMENT); - // tab->restore_last_select_item(); - if (tab == nullptr) { - return; - } + Tab *tab = wxGetApp().get_tab(Preset::Type::TYPE_FILAMENT); + //tab->restore_last_select_item(); + if (tab == nullptr) { return; } // Popup needs to be called before "restore_last_select_item", otherwise the page may not be updated wxGetApp().params_dialog()->Popup(); tab->restore_last_select_item(); - // Opening Studio and directly accessing the Filament settings interface through the edit preset button will not take effect and - // requires manual settings. + // Opening Studio and directly accessing the Filament settings interface through the edit preset button will not take effect and requires manual settings. tab->set_just_edit(true); tab->select_preset(need_edit_preset->name); - // when some preset have modified, if the printer is not need_edit_preset_name compatible printer, the preset will jump to other - // preset, need select again - if (!need_edit_preset->is_compatible) - tab->select_preset(need_edit_preset->name); + // when some preset have modified, if the printer is not need_edit_preset_name compatible printer, the preset will jump to other preset, need select again + if (!need_edit_preset->is_compatible) tab->select_preset(need_edit_preset->name); } + } -void Plater::priv::on_add_filament(SimpleEvent& evt) { sidebar->add_filament(); } +void Plater::priv::on_add_filament(SimpleEvent &evt) { + sidebar->add_filament(); +} -void Plater::priv::on_delete_filament(SimpleEvent& evt) { sidebar->delete_filament(); } +void Plater::priv::on_delete_filament(SimpleEvent &evt) { + sidebar->delete_filament(); +} -void Plater::priv::on_add_custom_filament(ColorEvent& evt) { sidebar->add_custom_filament(evt.data); } +void Plater::priv::on_add_custom_filament(ColorEvent &evt) +{ + sidebar->add_custom_filament(evt.data); +} void Plater::priv::enter_gizmos_stack() { @@ -14364,7 +14368,7 @@ bool Plater::priv::leave_gizmos_stack() bool changed = false; assert(m_undo_redo_stack_active == &m_undo_redo_stack_gizmos); if (m_undo_redo_stack_active == &m_undo_redo_stack_gizmos) { - assert(!m_undo_redo_stack_active->empty()); + assert(! m_undo_redo_stack_active->empty()); changed = m_undo_redo_stack_gizmos.has_undo_snapshot(); m_undo_redo_stack_active->clear(); m_undo_redo_stack_active = &m_undo_redo_stack_main; @@ -14374,7 +14378,7 @@ bool Plater::priv::leave_gizmos_stack() int Plater::priv::get_active_snapshot_index() { - const size_t active_snapshot_time = this->undo_redo_stack().active_snapshot_time(); + const size_t active_snapshot_time = this->undo_redo_stack().active_snapshot_time(); const std::vector& ss_stack = this->undo_redo_stack().snapshots(); const auto it = std::lower_bound(ss_stack.begin(), ss_stack.end(), UndoRedo::Snapshot(active_snapshot_time)); return it - ss_stack.begin(); @@ -14396,10 +14400,12 @@ void Plater::priv::take_snapshot(const std::string& snapshot_name, const UndoRed if (this->sidebar->obj_list()->is_selected(itSettings)) { snapshot_data.flags |= UndoRedo::SnapshotData::SELECTED_SETTINGS_ON_SIDEBAR; snapshot_data.layer_range_idx = this->sidebar->obj_list()->get_selected_layers_range_idx(); - } else if (this->sidebar->obj_list()->is_selected(itLayer)) { + } + else if (this->sidebar->obj_list()->is_selected(itLayer)) { snapshot_data.flags |= UndoRedo::SnapshotData::SELECTED_LAYER_ON_SIDEBAR; snapshot_data.layer_range_idx = this->sidebar->obj_list()->get_selected_layers_range_idx(); - } else if (this->sidebar->obj_list()->is_selected(itLayerRoot)) + } + else if (this->sidebar->obj_list()->is_selected(itLayerRoot)) snapshot_data.flags |= UndoRedo::SnapshotData::SELECTED_LAYERROOT_ON_SIDEBAR; // If SLA gizmo is active, ask it if it wants to trigger support generation @@ -14407,12 +14413,12 @@ void Plater::priv::take_snapshot(const std::string& snapshot_name, const UndoRed if (view3D->get_canvas3d()->get_gizmos_manager().wants_reslice_supports_on_undo()) snapshot_data.flags |= UndoRedo::SnapshotData::RECALCULATE_SLA_SUPPORTS; - // FIXME updating the Wipe tower config values at the ModelWipeTower from the Print config. - // This is a workaround until we refactor the Wipe Tower position / orientation to live solely inside the Model, not in the Print - // config. BBS: add partplate logic + //FIXME updating the Wipe tower config values at the ModelWipeTower from the Print config. + // This is a workaround until we refactor the Wipe Tower position / orientation to live solely inside the Model, not in the Print config. + // BBS: add partplate logic if (this->printer_technology == ptFFF) { - const DynamicPrintConfig& config = wxGetApp().preset_bundle->prints.get_edited_preset().config; - const DynamicPrintConfig& proj_cfg = wxGetApp().preset_bundle->project_config; + const DynamicPrintConfig& config = wxGetApp().preset_bundle->prints.get_edited_preset().config; + const DynamicPrintConfig& proj_cfg = wxGetApp().preset_bundle->project_config; const ConfigOptionFloats* tower_x_opt = proj_cfg.option("wipe_tower_x"); const ConfigOptionFloats* tower_y_opt = proj_cfg.option("wipe_tower_y"); assert(tower_x_opt->values.size() == tower_y_opt->values.size()); @@ -14422,24 +14428,18 @@ void Plater::priv::take_snapshot(const std::string& snapshot_name, const UndoRed ModelWipeTower& tower = model.wipe_tower; tower.positions[plate_idx] = Vec2d(tower_x_opt->get_at(plate_idx), tower_y_opt->get_at(plate_idx)); - tower.rotation = config.opt_float("wipe_tower_rotation_angle"); + tower.rotation = config.opt_float("wipe_tower_rotation_angle"); } } - const GLGizmosManager& gizmos = get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? - assemble_view->get_canvas3d()->get_gizmos_manager() : - view3D->get_canvas3d()->get_gizmos_manager(); + const GLGizmosManager& gizmos = get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_gizmos_manager() : view3D->get_canvas3d()->get_gizmos_manager(); if (snapshot_type == UndoRedo::SnapshotType::ProjectSeparator) this->undo_redo_stack().clear(); - this->undo_redo_stack().take_snapshot(snapshot_name, model, - get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? - assemble_view->get_canvas3d()->get_selection() : - view3D->get_canvas3d()->get_selection(), - gizmos, partplate_list, snapshot_data); + this->undo_redo_stack().take_snapshot(snapshot_name, model, get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_selection() : view3D->get_canvas3d()->get_selection(), gizmos, partplate_list, snapshot_data); if (snapshot_type == UndoRedo::SnapshotType::LeavingGizmoWithAction) { - // Filter all but the last UndoRedo::SnapshotType::GizmoAction in a row between the last UndoRedo::SnapshotType::EnteringGizmo and - // UndoRedo::SnapshotType::LeavingGizmoWithAction. The remaining snapshot will be renamed to a more generic name, depending on what - // gizmo is being left. + // Filter all but the last UndoRedo::SnapshotType::GizmoAction in a row between the last UndoRedo::SnapshotType::EnteringGizmo and UndoRedo::SnapshotType::LeavingGizmoWithAction. + // The remaining snapshot will be renamed to a more generic name, + // depending on what gizmo is being left. if (gizmos.get_current() != nullptr) { std::string new_name = gizmos.get_current()->get_action_snapshot_name(); this->undo_redo_stack().reduce_noisy_snapshots(new_name); @@ -14448,29 +14448,23 @@ void Plater::priv::take_snapshot(const std::string& snapshot_name, const UndoRed // Reset the "dirty project" flag. m_undo_redo_stack_main.mark_current_as_saved(); } - // BBS: add PartPlateList as the paremeter for take_snapshot + //BBS: add PartPlateList as the paremeter for take_snapshot this->undo_redo_stack().release_least_recently_used(); dirty_state.update_from_undo_redo_stack(m_undo_redo_stack_main.project_modified()); // Save the last active preset name of a particular printer technology. - ((this->printer_technology == ptFFF) ? m_last_fff_printer_profile_name : - m_last_sla_printer_profile_name) = wxGetApp().preset_bundle->printers.get_selected_preset_name(); - BOOST_LOG_TRIVIAL(info) << "Undo / Redo snapshot taken: " << snapshot_name - << ", Undo / Redo stack memory: " << Slic3r::format_memsize_MB(this->undo_redo_stack().memsize()) - << log_memory_info(); + ((this->printer_technology == ptFFF) ? m_last_fff_printer_profile_name : m_last_sla_printer_profile_name) = wxGetApp().preset_bundle->printers.get_selected_preset_name(); + BOOST_LOG_TRIVIAL(info) << "Undo / Redo snapshot taken: " << snapshot_name << ", Undo / Redo stack memory: " << Slic3r::format_memsize_MB(this->undo_redo_stack().memsize()) << log_memory_info(); } void Plater::priv::undo() { - const std::vector& snapshots = this->undo_redo_stack().snapshots(); - auto it_current = std::lower_bound(snapshots.begin(), snapshots.end(), - UndoRedo::Snapshot(this->undo_redo_stack().active_snapshot_time())); + const std::vector &snapshots = this->undo_redo_stack().snapshots(); + auto it_current = std::lower_bound(snapshots.begin(), snapshots.end(), UndoRedo::Snapshot(this->undo_redo_stack().active_snapshot_time())); // BBS: undo-redo until modify record - while (--it_current != snapshots.begin() && !snapshot_modifies_project(*it_current)) - ; - if (it_current == snapshots.begin()) - return; + while (--it_current != snapshots.begin() && !snapshot_modifies_project(*it_current)); + if (it_current == snapshots.begin()) return; if (get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView) { if (it_current->snapshot_data.snapshot_type != UndoRedo::SnapshotType::GizmoAction && it_current->snapshot_data.snapshot_type != UndoRedo::SnapshotType::EnteringGizmo && @@ -14483,22 +14477,19 @@ void Plater::priv::undo() void Plater::priv::redo() { - const std::vector& snapshots = this->undo_redo_stack().snapshots(); - auto it_current = std::lower_bound(snapshots.begin(), snapshots.end(), - UndoRedo::Snapshot(this->undo_redo_stack().active_snapshot_time())); + const std::vector &snapshots = this->undo_redo_stack().snapshots(); + auto it_current = std::lower_bound(snapshots.begin(), snapshots.end(), UndoRedo::Snapshot(this->undo_redo_stack().active_snapshot_time())); // BBS: undo-redo until modify record - while (it_current != snapshots.end() && !snapshot_modifies_project(*it_current++)) - ; + while (it_current != snapshots.end() && !snapshot_modifies_project(*it_current++)); if (it_current != snapshots.end()) { - while (it_current != snapshots.end() && !snapshot_modifies_project(*it_current++)) - ; + while (it_current != snapshots.end() && !snapshot_modifies_project(*it_current++)); this->undo_redo_to(--it_current); } } void Plater::priv::undo_redo_to(size_t time_to_load) { - const std::vector& snapshots = this->undo_redo_stack().snapshots(); + const std::vector &snapshots = this->undo_redo_stack().snapshots(); auto it_current = std::lower_bound(snapshots.begin(), snapshots.end(), UndoRedo::Snapshot(time_to_load)); assert(it_current != snapshots.end()); this->undo_redo_to(it_current); @@ -14513,7 +14504,8 @@ bool Plater::priv::up_to_date(bool saved, bool backup) if (!backup) undo_redo_stack_main().mark_current_as_saved(); return true; - } else { + } + else { return !undo_redo_stack_main().has_real_change_from(last_time); } } @@ -14523,21 +14515,20 @@ void Plater::priv::undo_redo_to(std::vector::const_iterator // Make sure that no updating function calls take_snapshot until we are done. SuppressSnapshots snapshot_supressor(q); - bool temp_snapshot_was_taken = this->undo_redo_stack().temp_snapshot_active(); - PrinterTechnology new_printer_technology = it_snapshot->snapshot_data.printer_technology; - bool printer_technology_changed = this->printer_technology != new_printer_technology; + bool temp_snapshot_was_taken = this->undo_redo_stack().temp_snapshot_active(); + PrinterTechnology new_printer_technology = it_snapshot->snapshot_data.printer_technology; + bool printer_technology_changed = this->printer_technology != new_printer_technology; if (printer_technology_changed) { - // BBS do not support SLA + //BBS do not support SLA } // Save the last active preset name of a particular printer technology. - ((this->printer_technology == ptFFF) ? m_last_fff_printer_profile_name : - m_last_sla_printer_profile_name) = wxGetApp().preset_bundle->printers.get_selected_preset_name(); - // FIXME updating the Wipe tower config values at the ModelWipeTower from the Print config. - // This is a workaround until we refactor the Wipe Tower position / orientation to live solely inside the Model, not in the Print - // config. BBS: add partplate logic + ((this->printer_technology == ptFFF) ? m_last_fff_printer_profile_name : m_last_sla_printer_profile_name) = wxGetApp().preset_bundle->printers.get_selected_preset_name(); + //FIXME updating the Wipe tower config values at the ModelWipeTower from the Print config. + // This is a workaround until we refactor the Wipe Tower position / orientation to live solely inside the Model, not in the Print config. + // BBS: add partplate logic if (this->printer_technology == ptFFF) { - const DynamicPrintConfig& config = wxGetApp().preset_bundle->prints.get_edited_preset().config; - const DynamicPrintConfig& proj_cfg = wxGetApp().preset_bundle->project_config; + const DynamicPrintConfig& config = wxGetApp().preset_bundle->prints.get_edited_preset().config; + const DynamicPrintConfig& proj_cfg = wxGetApp().preset_bundle->project_config; const ConfigOptionFloats* tower_x_opt = proj_cfg.option("wipe_tower_x"); const ConfigOptionFloats* tower_y_opt = proj_cfg.option("wipe_tower_y"); assert(tower_x_opt->values.size() == tower_y_opt->values.size()); @@ -14547,7 +14538,7 @@ void Plater::priv::undo_redo_to(std::vector::const_iterator ModelWipeTower& tower = model.wipe_tower; tower.positions[plate_idx] = Vec2d(tower_x_opt->get_at(plate_idx), tower_y_opt->get_at(plate_idx)); - tower.rotation = config.opt_float("wipe_tower_rotation_angle"); + tower.rotation = config.opt_float("wipe_tower_rotation_angle"); } } const int layer_range_idx = it_snapshot->snapshot_data.layer_range_idx; @@ -14560,15 +14551,17 @@ void Plater::priv::undo_redo_to(std::vector::const_iterator if (this->sidebar->obj_list()->is_selected(itSettings)) { top_snapshot_data.flags |= UndoRedo::SnapshotData::SELECTED_SETTINGS_ON_SIDEBAR; top_snapshot_data.layer_range_idx = this->sidebar->obj_list()->get_selected_layers_range_idx(); - } else if (this->sidebar->obj_list()->is_selected(itLayer)) { + } + else if (this->sidebar->obj_list()->is_selected(itLayer)) { top_snapshot_data.flags |= UndoRedo::SnapshotData::SELECTED_LAYER_ON_SIDEBAR; top_snapshot_data.layer_range_idx = this->sidebar->obj_list()->get_selected_layers_range_idx(); - } else if (this->sidebar->obj_list()->is_selected(itLayerRoot)) + } + else if (this->sidebar->obj_list()->is_selected(itLayerRoot)) top_snapshot_data.flags |= UndoRedo::SnapshotData::SELECTED_LAYERROOT_ON_SIDEBAR; - bool new_variable_layer_editing_active = (new_flags & UndoRedo::SnapshotData::VARIABLE_LAYER_EDITING_ACTIVE) != 0; - bool new_selected_settings_on_sidebar = (new_flags & UndoRedo::SnapshotData::SELECTED_SETTINGS_ON_SIDEBAR) != 0; - bool new_selected_layer_on_sidebar = (new_flags & UndoRedo::SnapshotData::SELECTED_LAYER_ON_SIDEBAR) != 0; - bool new_selected_layerroot_on_sidebar = (new_flags & UndoRedo::SnapshotData::SELECTED_LAYERROOT_ON_SIDEBAR) != 0; + bool new_variable_layer_editing_active = (new_flags & UndoRedo::SnapshotData::VARIABLE_LAYER_EDITING_ACTIVE) != 0; + bool new_selected_settings_on_sidebar = (new_flags & UndoRedo::SnapshotData::SELECTED_SETTINGS_ON_SIDEBAR) != 0; + bool new_selected_layer_on_sidebar = (new_flags & UndoRedo::SnapshotData::SELECTED_LAYER_ON_SIDEBAR) != 0; + bool new_selected_layerroot_on_sidebar = (new_flags & UndoRedo::SnapshotData::SELECTED_LAYERROOT_ON_SIDEBAR) != 0; if (this->view3D->get_canvas3d()->get_gizmos_manager().wants_reslice_supports_on_undo()) top_snapshot_data.flags |= UndoRedo::SnapshotData::RECALCULATE_SLA_SUPPORTS; @@ -14581,45 +14574,32 @@ void Plater::priv::undo_redo_to(std::vector::const_iterator const UndoRedo::Snapshot snapshot_copy = *it_snapshot; // Do the jump in time. if (it_snapshot->timestamp < this->undo_redo_stack().active_snapshot_time() ? - this->undo_redo_stack().undo(model, - get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? - assemble_view->get_canvas3d()->get_selection() : - this->view3D->get_canvas3d()->get_selection(), - get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? - assemble_view->get_canvas3d()->get_gizmos_manager() : - this->view3D->get_canvas3d()->get_gizmos_manager(), - this->partplate_list, top_snapshot_data, it_snapshot->timestamp) : - this->undo_redo_stack().redo(model, - get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? - assemble_view->get_canvas3d()->get_gizmos_manager() : - this->view3D->get_canvas3d()->get_gizmos_manager(), - this->partplate_list, it_snapshot->timestamp)) { + this->undo_redo_stack().undo(model, get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_selection() : this->view3D->get_canvas3d()->get_selection(), get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_gizmos_manager() : this->view3D->get_canvas3d()->get_gizmos_manager(), this->partplate_list, top_snapshot_data, it_snapshot->timestamp) : + this->undo_redo_stack().redo(model, get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_gizmos_manager() : this->view3D->get_canvas3d()->get_gizmos_manager(), this->partplate_list, it_snapshot->timestamp)) { if (printer_technology_changed) { // Switch to the other printer technology. Switch to the last printer active for that particular technology. - AppConfig* app_config = wxGetApp().app_config; - app_config->set("presets", PRESET_PRINTER_NAME, - (new_printer_technology == ptFFF) ? m_last_fff_printer_profile_name : m_last_sla_printer_profile_name); - // FIXME Why are we reloading the whole preset bundle here? Please document. This is fishy and it is unnecessarily expensive. - // Anyways, don't report any config value substitutions, they have been already reported to the user at application start up. + AppConfig *app_config = wxGetApp().app_config; + app_config->set("presets", PRESET_PRINTER_NAME, (new_printer_technology == ptFFF) ? m_last_fff_printer_profile_name : m_last_sla_printer_profile_name); + //FIXME Why are we reloading the whole preset bundle here? Please document. This is fishy and it is unnecessarily expensive. + // Anyways, don't report any config value substitutions, they have been already reported to the user at application start up. wxGetApp().preset_bundle->load_presets(*app_config, ForwardCompatibilitySubstitutionRule::EnableSilent); - // load_current_presets() calls Tab::load_current_preset() -> TabPrint::update() -> - // Object_list::update_and_show_object_settings_item(), but the Object list still keeps pointer to the old Model. Avoid a crash - // by removing selection first. + // load_current_presets() calls Tab::load_current_preset() -> TabPrint::update() -> Object_list::update_and_show_object_settings_item(), + // but the Object list still keeps pointer to the old Model. Avoid a crash by removing selection first. this->sidebar->obj_list()->unselect_objects(); // Load the currently selected preset into the GUI, update the preset selection box. // This also switches the printer technology based on the printer technology of the active printer profile. wxGetApp().load_current_presets(); } - // FIXME updating the Print config from the Wipe tower config values at the ModelWipeTower. - // This is a workaround until we refactor the Wipe Tower position / orientation to live solely inside the Model, not in the Print - // config. BBS: add partplate logic + //FIXME updating the Print config from the Wipe tower config values at the ModelWipeTower. + // This is a workaround until we refactor the Wipe Tower position / orientation to live solely inside the Model, not in the Print config. + // BBS: add partplate logic if (this->printer_technology == ptFFF) { - const DynamicPrintConfig& config = wxGetApp().preset_bundle->prints.get_edited_preset().config; + const DynamicPrintConfig& config = wxGetApp().preset_bundle->prints.get_edited_preset().config; const DynamicPrintConfig& proj_cfg = wxGetApp().preset_bundle->project_config; - ConfigOptionFloats* tower_x_opt = const_cast(proj_cfg.option("wipe_tower_x")); - ConfigOptionFloats* tower_y_opt = const_cast(proj_cfg.option("wipe_tower_y")); + ConfigOptionFloats* tower_x_opt = const_cast(proj_cfg.option("wipe_tower_x")); + ConfigOptionFloats* tower_y_opt = const_cast(proj_cfg.option("wipe_tower_y")); // BBS: don't support wipe tower rotation - // double current_rotation = proj_cfg.opt_float("wipe_tower_rotation_angle"); + //double current_rotation = proj_cfg.opt_float("wipe_tower_rotation_angle"); bool need_update = false; if (tower_x_opt->values.size() != model.wipe_tower.positions.size()) { tower_x_opt->clear(); @@ -14673,28 +14653,18 @@ void Plater::priv::undo_redo_to(std::vector::const_iterator void Plater::priv::update_after_undo_redo(const UndoRedo::Snapshot& snapshot, bool /* temp_snapshot_was_taken */) { - get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_selection().clear() : - this->view3D->get_canvas3d()->get_selection().clear(); + get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_selection().clear() : this->view3D->get_canvas3d()->get_selection().clear(); // Update volumes from the deserializd model, always stop / update the background processing (for both the SLA and FFF technologies). - this->update((unsigned int) UpdateParams::FORCE_BACKGROUND_PROCESSING_UPDATE | - (unsigned int) UpdateParams::POSTPONE_VALIDATION_ERROR_MESSAGE); - // Release old snapshots if the memory allocated is excessive. This may remove the top most snapshot if jumping to the very first - // snapshot. - // if (temp_snapshot_was_taken) - // Release the old snapshots always, as it may have happened, that some of the triangle meshes got deserialized from the snapshot, while - // some triangle meshes may have gotten released from the scene or the background processing, therefore now being calculated into the - // Undo / Redo stack size. - this->undo_redo_stack().release_least_recently_used(); - // YS_FIXME update obj_list from the deserialized model (maybe store ObjectIDs into the tree?) (no selections at this point of time) - get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? - assemble_view->get_canvas3d() - ->get_selection() - .set_deserialized(GUI::Selection::EMode(this->undo_redo_stack().selection_deserialized().mode), - this->undo_redo_stack().selection_deserialized().volumes_and_instances) : - this->view3D->get_canvas3d() - ->get_selection() - .set_deserialized(GUI::Selection::EMode(this->undo_redo_stack().selection_deserialized().mode), - this->undo_redo_stack().selection_deserialized().volumes_and_instances); + this->update((unsigned int)UpdateParams::FORCE_BACKGROUND_PROCESSING_UPDATE | (unsigned int)UpdateParams::POSTPONE_VALIDATION_ERROR_MESSAGE); + // Release old snapshots if the memory allocated is excessive. This may remove the top most snapshot if jumping to the very first snapshot. + //if (temp_snapshot_was_taken) + // Release the old snapshots always, as it may have happened, that some of the triangle meshes got deserialized from the snapshot, while some + // triangle meshes may have gotten released from the scene or the background processing, therefore now being calculated into the Undo / Redo stack size. + this->undo_redo_stack().release_least_recently_used(); + //YS_FIXME update obj_list from the deserialized model (maybe store ObjectIDs into the tree?) (no selections at this point of time) + get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? + assemble_view->get_canvas3d()->get_selection().set_deserialized(GUI::Selection::EMode(this->undo_redo_stack().selection_deserialized().mode), this->undo_redo_stack().selection_deserialized().volumes_and_instances) : + this->view3D->get_canvas3d()->get_selection().set_deserialized(GUI::Selection::EMode(this->undo_redo_stack().selection_deserialized().mode), this->undo_redo_stack().selection_deserialized().volumes_and_instances); get_current_canvas3D()->get_canvas_type() == GLCanvas3D::CanvasAssembleView ? assemble_view->get_canvas3d()->get_gizmos_manager().update_after_undo_redo(snapshot) : this->view3D->get_canvas3d()->get_gizmos_manager().update_after_undo_redo(snapshot); @@ -14703,23 +14673,20 @@ void Plater::priv::update_after_undo_redo(const UndoRedo::Snapshot& snapshot, bo if (wxGetApp().get_mode() == comSimple && model_has_advanced_features(this->model)) { // If the user jumped to a snapshot that require user interface with advanced features, switch to the advanced mode without asking. - // There is a little risk of surprising the user, as he already must have had the advanced or advanced mode active for such a - // snapshot to be taken. + // There is a little risk of surprising the user, as he already must have had the advanced or advanced mode active for such a snapshot to be taken. Slic3r::GUI::wxGetApp().save_mode(comAdvanced); view3D->set_as_dirty(); } - // this->update() above was called with POSTPONE_VALIDATION_ERROR_MESSAGE, so that if an error message was generated when updating the - // back end, it would not open immediately, but it would be saved to be show later. Let's do it now. We do not want to display the - // message box earlier, because on Windows & OSX the message box takes over the message queue pump, which in turn executes the rendering - // function before a full update after the Undo / Redo jump. + // this->update() above was called with POSTPONE_VALIDATION_ERROR_MESSAGE, so that if an error message was generated when updating the back end, it would not open immediately, + // but it would be saved to be show later. Let's do it now. We do not want to display the message box earlier, because on Windows & OSX the message box takes over the message + // queue pump, which in turn executes the rendering function before a full update after the Undo / Redo jump. this->show_delayed_error_message(); - // FIXME what about the state of the manipulators? - // FIXME what about the focus? Cursor in the side panel? + //FIXME what about the state of the manipulators? + //FIXME what about the focus? Cursor in the side panel? - BOOST_LOG_TRIVIAL(info) << "Undo / Redo snapshot reloaded. Undo / Redo stack memory: " - << Slic3r::format_memsize_MB(this->undo_redo_stack().memsize()) << log_memory_info(); + BOOST_LOG_TRIVIAL(info) << "Undo / Redo snapshot reloaded. Undo / Redo stack memory: " << Slic3r::format_memsize_MB(this->undo_redo_stack().memsize()) << log_memory_info(); } void Plater::priv::bring_instance_forward() const @@ -14733,7 +14700,7 @@ void Plater::priv::bring_instance_forward() const return; } BOOST_LOG_TRIVIAL(debug) << "Orca Slicer window going forward"; - // this code maximize app window on Fedora + //this code maximize app window on Fedora { main_frame->Iconize(false); if (main_frame->IsMaximized()) @@ -14741,25 +14708,25 @@ void Plater::priv::bring_instance_forward() const else main_frame->Maximize(false); } - // this code maximize window on Ubuntu + //this code maximize window on Ubuntu { main_frame->Restore(); - wxGetApp().GetTopWindow()->SetFocus(); // focus on my window + wxGetApp().GetTopWindow()->SetFocus(); // focus on my window wxGetApp().GetTopWindow()->Show(true); // show the window - wxGetApp().GetTopWindow()->Raise(); // bring window to front + wxGetApp().GetTopWindow()->Raise(); // bring window to front } } -// BBS: popup object table +//BBS: popup object table bool Plater::priv::PopupObjectTable(int object_id, int volume_id, const wxPoint& position) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, create ObjectTableDialog"); int max_width{1920}, max_height{1080}; - max_width = q->GetMaxWidth(); + max_width = q->GetMaxWidth(); max_height = q->GetMaxHeight(); ObjectTableDialog table_dialog(q, q, &model, wxSize(max_width, max_height)); - // m_popup_table = new ObjectTableDialog(q, q, &model); + //m_popup_table = new ObjectTableDialog(q, q, &model); wxRect rect = sidebar->GetRect(); wxPoint pos = sidebar->ClientToScreen(wxPoint(rect.x, rect.y)); @@ -14773,17 +14740,19 @@ bool Plater::priv::PopupObjectTable(int object_id, int volume_id, const wxPoint& void Sidebar::set_btn_label(const ActionButtonType btn_type, const wxString& label) const { - switch (btn_type) { - case ActionButtonType::abReslice: p->btn_reslice->SetLabelText(label); break; - case ActionButtonType::abExport: p->btn_export_gcode->SetLabelText(label); break; - case ActionButtonType::abSendGCode: /*p->btn_send_gcode->SetLabelText(label);*/ break; + switch (btn_type) + { + case ActionButtonType::abReslice: p->btn_reslice->SetLabelText(label); break; + case ActionButtonType::abExport: p->btn_export_gcode->SetLabelText(label); break; + case ActionButtonType::abSendGCode: /*p->btn_send_gcode->SetLabelText(label);*/ break; } } // Plater / Public -Plater::Plater(wxWindow* parent, MainFrame* main_frame) - : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxGetApp().get_min_size()), p(new priv(this, main_frame)) +Plater::Plater(wxWindow *parent, MainFrame *main_frame) + : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxGetApp().get_min_size()) + , p(new priv(this, main_frame)) { // Initialization performed in the private c-tor enable_wireframe(true); @@ -14801,7 +14770,7 @@ bool Plater::is_project_dirty() const { return p->is_project_dirty(); } bool Plater::is_presets_dirty() const { return p->is_presets_dirty(); } void Plater::set_plater_dirty(bool is_dirty) { p->set_plater_dirty(is_dirty); } void Plater::update_project_dirty_from_presets() { p->update_project_dirty_from_presets(); } -int Plater::save_project_if_dirty(const wxString& reason) { return p->save_project_if_dirty(reason); } +int Plater::save_project_if_dirty(const wxString& reason) { return p->save_project_if_dirty(reason); } void Plater::reset_project_dirty_after_save() { p->reset_project_dirty_after_save(); } void Plater::reset_project_dirty_initial_presets() { p->reset_project_dirty_initial_presets(); } #if ENABLE_PROJECT_DIRTY_STATE_DEBUG_WINDOW @@ -14812,12 +14781,10 @@ std::vector Plater::mixed_filament_config_indices() const { std::vector indices; auto& config = wxGetApp().preset_bundle->project_config; - auto* opt = config.option("filament_is_mixed"); - if (!opt) - return indices; + auto* opt = config.option("filament_is_mixed"); + if (!opt) return indices; for (size_t i = 0; i < opt->values.size(); ++i) - if (opt->values[i]) - indices.push_back(i); + if (opt->values[i]) indices.push_back(i); return indices; } @@ -14825,7 +14792,7 @@ std::vector Plater::physical_filament_config_indices() const { std::vector indices; auto& config = wxGetApp().preset_bundle->project_config; - auto* opt = config.option("filament_is_mixed"); + auto* opt = config.option("filament_is_mixed"); size_t total = wxGetApp().preset_bundle->filament_presets.size(); for (size_t i = 0; i < total; ++i) { if (!opt || i >= opt->values.size() || !opt->values[i]) @@ -14834,13 +14801,11 @@ std::vector Plater::physical_filament_config_indices() const return indices; } -bool Plater::priv::run_textured_mesh_import_dialog(Slic3r::Model& loaded_model, - TextureImportResult& result, +bool Plater::priv::run_textured_mesh_import_dialog(Slic3r::Model& loaded_model, TextureImportResult& result, std::function cancel_callback, std::function progress_callback) { - if (!loaded_model.texture_mesh || !has_importable_texture(*loaded_model.texture_mesh)) - return false; + if (!loaded_model.texture_mesh || !has_importable_texture(*loaded_model.texture_mesh)) return false; // Defense in depth: if all geometry got dropped earlier (e.g. by a future // regression of the zero-volume cleanup) but the textured mesh is still @@ -14854,31 +14819,29 @@ bool Plater::priv::run_textured_mesh_import_dialog(Slic3r::Model& loaded_model, return true; } - const wxString fallback_warning = _L("Texture import failed. The model appears to contain texture data, but the texture import process " - "could not be completed. The model will be imported as geometry only."); + const wxString fallback_warning = _L("Texture import failed. The model appears to contain texture data, but the texture import process could not be completed. The model will be imported as geometry only."); BOOST_LOG_TRIVIAL(info) << "handle_textured_mesh_import: opening texture import dialog"; std::vector filament_entries; { - auto& preset_bundle = *wxGetApp().preset_bundle; + auto& preset_bundle = *wxGetApp().preset_bundle; auto& project_config = preset_bundle.project_config; - auto* colours_opt = project_config.option("filament_colour"); - auto* is_mixed_opt = project_config.option("filament_is_mixed"); - auto* type_opt = project_config.option("filament_type"); + auto* colours_opt = project_config.option("filament_colour"); + auto* is_mixed_opt = project_config.option("filament_is_mixed"); + auto* type_opt = project_config.option("filament_type"); auto* components_opt = project_config.option("filament_mixed_components"); - auto* ratios_opt = project_config.option("filament_mixed_sublayer_ratios"); - const size_t total = preset_bundle.filament_presets.size(); + auto* ratios_opt = project_config.option("filament_mixed_sublayer_ratios"); + const size_t total = preset_bundle.filament_presets.size(); filament_entries.reserve(total); for (size_t i = 0; i < total; ++i) { TextureFilamentEntry entry; - entry.kind = (is_mixed_opt && i < is_mixed_opt->values.size() && is_mixed_opt->values[i]) ? - TextureFilamentKind::ExistingMixed : - TextureFilamentKind::ExistingPhysical; - entry.dialog_index = (int) filament_entries.size(); + entry.kind = (is_mixed_opt && i < is_mixed_opt->values.size() && is_mixed_opt->values[i]) ? + TextureFilamentKind::ExistingMixed : TextureFilamentKind::ExistingPhysical; + entry.dialog_index = (int)filament_entries.size(); entry.project_config_index = i; - entry.color_hex = (colours_opt && i < colours_opt->values.size()) ? colours_opt->values[i] : "#808080"; - entry.type = (type_opt && i < type_opt->values.size()) ? type_opt->values[i] : ""; + entry.color_hex = (colours_opt && i < colours_opt->values.size()) ? colours_opt->values[i] : "#808080"; + entry.type = (type_opt && i < type_opt->values.size()) ? type_opt->values[i] : ""; std::string name; if (i < preset_bundle.filament_presets.size()) { @@ -14893,19 +14856,19 @@ bool Plater::priv::run_textured_mesh_import_dialog(Slic3r::Model& loaded_model, if (entry.kind == TextureFilamentKind::ExistingMixed) { if (components_opt && i < components_opt->values.size()) entry.mixed_components = Slic3r::parse_mixed_components(components_opt->values[i]); - std::vector ratios = Slic3r::parse_mixed_ratios(ratios_opt && i < ratios_opt->values.size() ? - ratios_opt->values[i] : - "", - entry.mixed_components.size()); + std::vector ratios = Slic3r::parse_mixed_ratios( + ratios_opt && i < ratios_opt->values.size() ? ratios_opt->values[i] : "", + entry.mixed_components.size()); entry.mixed_ratios.reserve(ratios.size()); for (double ratio : ratios) - entry.mixed_ratios.push_back((int) std::lround(ratio * 100.0)); + entry.mixed_ratios.push_back((int)std::lround(ratio * 100.0)); } filament_entries.push_back(std::move(entry)); } } - TextureImportDialog dlg(q, *loaded_model.texture_mesh, filament_entries, std::move(cancel_callback), std::move(progress_callback)); + TextureImportDialog dlg(q, *loaded_model.texture_mesh, filament_entries, + std::move(cancel_callback), std::move(progress_callback)); if (dlg.ShowModal() != wxID_OK) { if (dlg.was_skipped()) { BOOST_LOG_TRIVIAL(info) << "handle_textured_mesh_import: user skipped texture matching"; @@ -14916,7 +14879,7 @@ bool Plater::priv::run_textured_mesh_import_dialog(Slic3r::Model& loaded_model, if (dlg.fallback_to_geometry_only()) { BOOST_LOG_TRIVIAL(warning) << "handle_textured_mesh_import: texture import failed, falling back to geometry-only import"; result.fallback_to_geometry_only = true; - result.fallback_warning = fallback_warning; + result.fallback_warning = fallback_warning; loaded_model.texture_mesh.reset(); return true; } @@ -14925,13 +14888,13 @@ bool Plater::priv::run_textured_mesh_import_dialog(Slic3r::Model& loaded_model, return false; } - auto painted = dlg.get_painted_mesh(); + auto painted = dlg.get_painted_mesh(); auto final_matches = dlg.get_matches(); if (painted.face_colors.empty() || final_matches.empty()) { BOOST_LOG_TRIVIAL(warning) << "handle_textured_mesh_import: no painting result"; result.fallback_to_geometry_only = true; - result.fallback_warning = fallback_warning; + result.fallback_warning = fallback_warning; loaded_model.texture_mesh.reset(); return true; } @@ -14939,28 +14902,26 @@ bool Plater::priv::run_textured_mesh_import_dialog(Slic3r::Model& loaded_model, BOOST_LOG_TRIVIAL(info) << "handle_textured_mesh_import: got " << painted.cluster_colors.size() << " clusters, skipped=" << dlg.was_skipped(); - result.painted = std::move(painted); - result.matches = std::move(final_matches); - result.new_filament_colors = dlg.get_new_filament_colors(); + result.painted = std::move(painted); + result.matches = std::move(final_matches); + result.new_filament_colors = dlg.get_new_filament_colors(); result.new_filament_preset_names = dlg.get_new_filament_preset_names(); - result.new_mixed_filaments = dlg.get_new_mixed_filaments(); - result.filament_entries = dlg.get_filament_entries(); - result.existing_filament_count = dlg.get_existing_filament_count(); - result.skipped = dlg.was_skipped(); + result.new_mixed_filaments = dlg.get_new_mixed_filaments(); + result.filament_entries = dlg.get_filament_entries(); + result.existing_filament_count = dlg.get_existing_filament_count(); + result.skipped = dlg.was_skipped(); return true; } -void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model, - const std::vector& obj_idxs, +void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model, const std::vector& obj_idxs, const TextureImportResult& result, - LoadProgressCallback progress_callback, - bool update_scene) + LoadProgressCallback progress_callback, bool update_scene) { auto update_apply_progress = [&progress_callback](int percent, const wxString& message) { return !progress_callback || progress_callback(std::clamp(percent, 0, 100), message); }; - const auto& painted = result.painted; + const auto& painted = result.painted; const auto& final_matches = result.matches; if (painted.face_colors.empty() || final_matches.empty()) { @@ -14977,9 +14938,9 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model auto collect_physical_color_strs = []() { std::vector colors; auto& project_config = wxGetApp().preset_bundle->project_config; - auto* colours_opt = project_config.option("filament_colour"); - auto* is_mixed_opt = project_config.option("filament_is_mixed"); - const size_t total = wxGetApp().preset_bundle->filament_presets.size(); + auto* colours_opt = project_config.option("filament_colour"); + auto* is_mixed_opt = project_config.option("filament_is_mixed"); + const size_t total = wxGetApp().preset_bundle->filament_presets.size(); for (size_t i = 0; i < total; ++i) { const bool is_mixed = is_mixed_opt && i < is_mixed_opt->values.size() && is_mixed_opt->values[i]; if (!is_mixed) @@ -14991,7 +14952,7 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model const auto& entries = result.filament_entries; std::vector filament_index_remap(entries.size(), -1); size_t existing_physical_count = 0; - size_t new_physical_count = 0; + size_t new_physical_count = 0; for (const auto& entry : entries) { if (entry.kind == TextureFilamentKind::ExistingPhysical) ++existing_physical_count; @@ -15000,12 +14961,12 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model } for (const auto& entry : entries) { - if (entry.dialog_index < 0 || entry.dialog_index >= (int) filament_index_remap.size()) + if (entry.dialog_index < 0 || entry.dialog_index >= (int)filament_index_remap.size()) continue; if (entry.kind == TextureFilamentKind::ExistingPhysical) { - filament_index_remap[entry.dialog_index] = (int) entry.project_config_index; + filament_index_remap[entry.dialog_index] = (int)entry.project_config_index; } else if (entry.kind == TextureFilamentKind::ExistingMixed) { - filament_index_remap[entry.dialog_index] = (int) (entry.project_config_index + new_physical_count); + filament_index_remap[entry.dialog_index] = (int)(entry.project_config_index + new_physical_count); } } @@ -15016,10 +14977,12 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model wxColour new_col(entry.color_hex); const size_t final_idx = existing_physical_count + new_physical_order; sidebar->add_custom_filament(new_col, entry.preset_name); - if (entry.dialog_index >= 0 && entry.dialog_index < (int) filament_index_remap.size()) - filament_index_remap[entry.dialog_index] = (int) final_idx; - BOOST_LOG_TRIVIAL(info) << "handle_textured_mesh_import: created pending physical filament dialog=" << entry.dialog_index - << " final=" << final_idx << " color=" << entry.color_hex << " preset=" << entry.preset_name; + if (entry.dialog_index >= 0 && entry.dialog_index < (int)filament_index_remap.size()) + filament_index_remap[entry.dialog_index] = (int)final_idx; + BOOST_LOG_TRIVIAL(info) << "handle_textured_mesh_import: created pending physical filament dialog=" + << entry.dialog_index << " final=" << final_idx + << " color=" << entry.color_hex + << " preset=" << entry.preset_name; ++new_physical_order; } @@ -15030,25 +14993,27 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model mixed_result.components.reserve(mixed.component_dialog_indices.size()); bool valid_components = true; for (int component_dialog_idx : mixed.component_dialog_indices) { - if (component_dialog_idx < 0 || component_dialog_idx >= (int) filament_index_remap.size() || + if (component_dialog_idx < 0 || component_dialog_idx >= (int)filament_index_remap.size() || filament_index_remap[component_dialog_idx] < 0) { valid_components = false; break; } - mixed_result.components.push_back((unsigned int) (filament_index_remap[component_dialog_idx] + 1)); + mixed_result.components.push_back((unsigned int)(filament_index_remap[component_dialog_idx] + 1)); } - if (!valid_components || mixed_result.components.size() < 2 || mixed_result.components.size() != mixed_result.ratios.size()) { - BOOST_LOG_TRIVIAL(warning) << "handle_textured_mesh_import: invalid pending mixed filament dialog=" << mixed.dialog_index; + if (!valid_components || mixed_result.components.size() < 2 || + mixed_result.components.size() != mixed_result.ratios.size()) { + BOOST_LOG_TRIVIAL(warning) << "handle_textured_mesh_import: invalid pending mixed filament dialog=" + << mixed.dialog_index; continue; } - const int final_idx = (int) wxGetApp().preset_bundle->filament_presets.size(); + const int final_idx = (int)wxGetApp().preset_bundle->filament_presets.size(); if (create_mixed_filament_from_result(sidebar, mixed_result, physical_colors_for_mixing)) { - if (mixed.dialog_index >= 0 && mixed.dialog_index < (int) filament_index_remap.size()) + if (mixed.dialog_index >= 0 && mixed.dialog_index < (int)filament_index_remap.size()) filament_index_remap[mixed.dialog_index] = final_idx; physical_colors_for_mixing = collect_physical_color_strs(); - BOOST_LOG_TRIVIAL(info) << "handle_textured_mesh_import: created pending mixed filament dialog=" << mixed.dialog_index - << " final=" << final_idx; + BOOST_LOG_TRIVIAL(info) << "handle_textured_mesh_import: created pending mixed filament dialog=" + << mixed.dialog_index << " final=" << final_idx; } } @@ -15056,11 +15021,11 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model for (auto& m : remapped_matches) { if (m.filament_index < 0) continue; - if (m.filament_index < (int) filament_index_remap.size() && filament_index_remap[m.filament_index] >= 0) { + if (m.filament_index < (int)filament_index_remap.size() && filament_index_remap[m.filament_index] >= 0) { m.filament_index = filament_index_remap[m.filament_index]; } else { - BOOST_LOG_TRIVIAL(warning) << "handle_textured_mesh_import: invalid filament index " << m.filament_index - << " in texture mapping"; + BOOST_LOG_TRIVIAL(warning) << "handle_textured_mesh_import: invalid filament index " + << m.filament_index << " in texture mapping"; m.filament_index = -1; } } @@ -15069,7 +15034,7 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model { std::map, int> color_to_filament; for (const auto& m : remapped_matches) { - if (m.cluster_index >= 0 && m.cluster_index < (int) painted.cluster_colors.size() && m.filament_index >= 0) + if (m.cluster_index >= 0 && m.cluster_index < (int)painted.cluster_colors.size() && m.filament_index >= 0) color_to_filament[painted.cluster_colors[m.cluster_index]] = m.filament_index + 1; } for (const auto& face_color : painted.face_colors) { @@ -15088,11 +15053,9 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model for (size_t obj_order = 0; obj_order < obj_idxs.size(); ++obj_order) { size_t idx = obj_idxs[obj_order]; - if (idx >= loaded_model.objects.size()) - continue; + if (idx >= loaded_model.objects.size()) continue; ModelObject* obj = loaded_model.objects[idx]; - if (!obj) - continue; + if (!obj) continue; // painted is derived from the whole textured mesh and is meaningful // only against a single MODEL_PART volume. Applying it to every @@ -15100,37 +15063,38 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model // volume with the same painted geometry. Restrict to the first // model_part and warn when the object holds more than one. ModelVolume* target = nullptr; - int part_count = 0; + int part_count = 0; for (ModelVolume* vol : obj->volumes) { if (vol && vol->is_model_part()) { ++part_count; - if (!target) - target = vol; + if (!target) target = vol; } } - if (!target) - continue; + if (!target) continue; if (part_count > 1) { - BOOST_LOG_TRIVIAL(warning) << "handle_textured_mesh_import: object has " << part_count - << " model parts; painting only applied to the first part."; + BOOST_LOG_TRIVIAL(warning) + << "handle_textured_mesh_import: object has " << part_count + << " model parts; painting only applied to the first part."; } - if (Slic3r::apply_painted_mesh_to_volume(painted, remapped_matches, *target) && min_used_filament_1based > 0) { + if (Slic3r::apply_painted_mesh_to_volume(painted, remapped_matches, *target) + && min_used_filament_1based > 0) { target->config.set("extruder", min_used_filament_1based); obj->config.set("extruder", min_used_filament_1based); if (update_scene) { if (auto* obj_list = wxGetApp().obj_list()) { - obj_list->update_objects_list_filament_column( - std::max(wxGetApp().filaments_cnt(), (size_t) min_used_filament_1based)); + obj_list->update_objects_list_filament_column(std::max( + wxGetApp().filaments_cnt(), (size_t)min_used_filament_1based)); obj_list->update_info_items(idx); } } - BOOST_LOG_TRIVIAL(info) << "handle_textured_mesh_import: set base filament to " << min_used_filament_1based - << " for object index " << idx << ", object extruder=" << obj->config.extruder() + BOOST_LOG_TRIVIAL(info) << "handle_textured_mesh_import: set base filament to " + << min_used_filament_1based << " for object index " << idx + << ", object extruder=" << obj->config.extruder() << ", volume extruder=" << target->config.extruder(); } // bbox invalidation is performed inside apply_painted_mesh_to_volume. obj->ensure_on_bed(); - const int object_percent = 25 + (int) (60 * (obj_order + 1) / std::max(obj_idxs.size(), 1)); + const int object_percent = 25 + (int)(60 * (obj_order + 1) / std::max(obj_idxs.size(), 1)); if (!update_apply_progress(object_percent, _L("Applying texture colors..."))) return; } @@ -15145,8 +15109,7 @@ void Plater::priv::apply_textured_mesh_import_result(Slic3r::Model& loaded_model update_apply_progress(100, _L("Texture colors applied.")); } -void Plater::priv::handle_textured_mesh_import(Slic3r::Model& loaded_model, - const std::vector& obj_idxs, +void Plater::priv::handle_textured_mesh_import(Slic3r::Model& loaded_model, const std::vector& obj_idxs, std::function cancel_callback) { TextureImportResult result; @@ -15156,13 +15119,13 @@ void Plater::priv::handle_textured_mesh_import(Slic3r::Model& loaded_model, apply_textured_mesh_import_result(loaded_model, obj_idxs, result); } -Sidebar& Plater::sidebar() { return *p->sidebar; } -const Model& Plater::model() const { return p->model; } -Model& Plater::model() { return p->model; } -const Print& Plater::fff_print() const { return p->fff_print; } -Print& Plater::fff_print() { return p->fff_print; } -const SLAPrint& Plater::sla_print() const { return p->sla_print; } -SLAPrint& Plater::sla_print() { return p->sla_print; } +Sidebar& Plater::sidebar() { return *p->sidebar; } +const Model& Plater::model() const { return p->model; } +Model& Plater::model() { return p->model; } +const Print& Plater::fff_print() const { return p->fff_print; } +Print& Plater::fff_print() { return p->fff_print; } +const SLAPrint& Plater::sla_print() const { return p->sla_print; } +SLAPrint& Plater::sla_print() { return p->sla_print; } int Plater::new_project(bool skip_confirm, bool silent, const wxString& project_name) { @@ -15171,20 +15134,18 @@ int Plater::new_project(bool skip_confirm, bool silent, const wxString& project_ bool transfer_preset_changes = false; // BBS: save confirm - auto check = [this, &transfer_preset_changes](bool yes_or_no) { + auto check = [this,&transfer_preset_changes](bool yes_or_no) { m_new_project_and_check_state = true; wxString header = _L("Some presets are modified.") + "\n" + - (yes_or_no ? - _L("You can keep the modified presets for the new project or discard them") : - _L("You can keep the modified presets for the new project, discard, or save changes as new presets.")); + (yes_or_no ? _L("You can keep the modified presets for the new project or discard them") : + _L("You can keep the modified presets for the new project, discard, or save changes as new presets.")); int act_buttons = ActionButtons::KEEP | ActionButtons::REMEMBER_CHOISE; if (!yes_or_no) act_buttons |= ActionButtons::SAVE; if (m_exported_file) { //.gcode.3mf ignore presets modify m_exported_file = false; } - bool result = wxGetApp().check_and_keep_current_preset_changes(_L("Creating a new project"), header, act_buttons, - &transfer_preset_changes); + bool result = wxGetApp().check_and_keep_current_preset_changes(_L("Creating a new project"), header, act_buttons, &transfer_preset_changes); m_new_project_and_check_state = false; return result; }; @@ -15192,26 +15153,26 @@ int Plater::new_project(bool skip_confirm, bool silent, const wxString& project_ if (!skip_confirm && (result = close_with_confirm(check)) == wxID_CANCEL) return wxID_CANCEL; - m_only_gcode = false; - m_exported_file = false; + m_only_gcode = false; + m_exported_file = false; m_loading_project = false; get_notification_manager()->clear_all(); if (!silent) wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); - // get_partplate_list().reinit(); - // get_partplate_list().update_slice_context_to_current_plate(p->background_process); - // p->preview->update_gcode_result(p->partplate_list.get_current_slice_result()); + //get_partplate_list().reinit(); + //get_partplate_list().update_slice_context_to_current_plate(p->background_process); + //p->preview->update_gcode_result(p->partplate_list.get_current_slice_result()); reset(transfer_preset_changes); reset_project_dirty_after_save(); reset_project_dirty_initial_presets(); wxGetApp().update_saved_preset_from_current_preset(); update_project_dirty_from_presets(); - // reset project + //reset project p->project.reset(); - // set project name + //set project name if (project_name.empty()) p->set_project_name(_L("Untitled")); else @@ -15222,7 +15183,7 @@ int Plater::new_project(bool skip_confirm, bool silent, const wxString& project_ Model m; model().load_from(m); // new id avoid same path name - // select first plate + //select first plate get_partplate_list().select_plate(0); SimpleEvent event(EVT_GLCANVAS_PLATE_SELECT); p->on_plate_selected(event); @@ -15244,7 +15205,8 @@ int Plater::new_project(bool skip_confirm, bool silent, const wxString& project_ LoadType determine_load_type(std::string filename, std::string override_setting = ""); // BBS: FIXME, missing resotre logic -void Plater::load_project(wxString const& filename2, wxString const& originfile) +void Plater::load_project(wxString const& filename2, + wxString const& originfile) { model().calib_pa_pattern.reset(nullptr); model().plates_custom_gcodes.clear(); @@ -15252,8 +15214,9 @@ void Plater::load_project(wxString const& filename2, wxString const& originfile) BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "filename is: " << filename2 << "and originfile is: " << originfile; BOOST_LOG_TRIVIAL(info) << __FUNCTION__; auto filename = filename2; - auto check = [&filename, this](bool yes_or_no) { - if (!yes_or_no && !wxGetApp().check_and_save_current_preset_changes(_L("Load project"), _L("Some presets are modified."))) + auto check = [&filename, this] (bool yes_or_no) { + if (!yes_or_no && !wxGetApp().check_and_save_current_preset_changes(_L("Load project"), + _L("Some presets are modified."))) return false; if (filename.empty()) { // Ask user for a project file name. @@ -15270,8 +15233,8 @@ void Plater::load_project(wxString const& filename2, wxString const& originfile) // BBS if (m_loading_project) { - // some error cases happens - // return directly + //some error cases happens + //return directly BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": current loading other project, return directly"); return; } @@ -15279,7 +15242,7 @@ void Plater::load_project(wxString const& filename2, wxString const& originfile) m_loading_project = true; ScopeGuard loading_project_sc([this]() { m_loading_project = false; }); // Make sure state restored on any early return - m_only_gcode = false; + m_only_gcode = false; m_exported_file = false; get_notification_manager()->bbl_close_plateinfo_notification(); get_notification_manager()->bbl_close_preview_only_notification(); @@ -15290,7 +15253,7 @@ void Plater::load_project(wxString const& filename2, wxString const& originfile) get_notification_manager()->close_notification_of_type(NotificationType::SlicingSeriousWarning); get_notification_manager()->close_notification_of_type(NotificationType::SlicingWarning); - auto path = into_path(filename); + auto path = into_path(filename); auto strategy = LoadStrategy::LoadModel | LoadStrategy::LoadConfig; if (originfile == "") { @@ -15301,9 +15264,9 @@ void Plater::load_project(wxString const& filename2, wxString const& originfile) strategy = strategy | LoadStrategy::Restore; } else { switch (determine_load_type(filename.ToStdString())) { - case LoadType::OpenProject: break; // Do nothing - case LoadType::LoadGeometry:; strategy = LoadStrategy::LoadModel; break; - default: return; // User cancelled + case LoadType::OpenProject: break; // Do nothing + case LoadType::LoadGeometry:; strategy = LoadStrategy::LoadModel; break; + default: return; // User cancelled } } bool load_restore = strategy & LoadStrategy::Restore; @@ -15330,7 +15293,7 @@ void Plater::load_project(wxString const& filename2, wxString const& originfile) BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " call set_project_filename: " << (load_restore ? originfile : filename); p->set_project_filename(load_restore ? originfile : filename); if (load_restore && originfile.IsEmpty()) { - p->set_project_name(_L("Untitled")); + p->set_project_name(_L("Untitled")); } } else { @@ -15346,15 +15309,17 @@ void Plater::load_project(wxString const& filename2, wxString const& originfile) if (!filename.IsEmpty()) wxGetApp().mainframe->add_to_recent_projects(filename); } + } // BBS set default 3D view and direction after loading project - // p->select_view_3D("3D"); + //p->select_view_3D("3D"); if (!m_exported_file) { p->select_view("topfront"); p->camera.requires_zoom_to_plate = REQUIRES_ZOOM_TO_ALL_PLATE; wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); - } else { + } + else { p->partplate_list.select_plate_view(); } @@ -15374,7 +15339,7 @@ void Plater::load_project(wxString const& filename2, wxString const& originfile) wxGetApp().params_panel()->switch_to_object_if_has_object_configs(); - auto has_modify = is_flush_config_modified(); + auto has_modify = is_flush_config_modified(); sidebar().set_flushing_volume_warning(has_modify); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " load project done"; @@ -15383,8 +15348,8 @@ void Plater::load_project(wxString const& filename2, wxString const& originfile) // BBS: save logic int Plater::save_project(bool saveAs) { - // if (up_to_date(false, false)) // should we always save - // return; + //if (up_to_date(false, false)) // should we always save + // return; auto filename = get_project_filename(".3mf"); if (!saveAs && filename.IsEmpty()) saveAs = true; @@ -15395,18 +15360,15 @@ int Plater::save_project(bool saveAs) if (filename == "") return wxID_CANCEL; - // BBS export 3mf without gcode - auto save_strategy = SaveStrategy::SplitModel | SaveStrategy::ShareMesh; + //BBS export 3mf without gcode + auto save_strategy = SaveStrategy::SplitModel | SaveStrategy::ShareMesh; bool full_pathnames = wxGetApp().app_config->get_bool("export_sources_full_pathnames"); if (full_pathnames) { save_strategy = save_strategy | SaveStrategy::FullPathSources; } if (export_3mf(into_path(filename), save_strategy) < 0) { - MessageDialog(this, - _L("Failed to save the project.\nPlease check whether the folder exists online or if other programs have the project " - "file open."), - _L("Save project"), wxOK | wxICON_WARNING) - .ShowModal(); + MessageDialog(this, _L("Failed to save the project.\nPlease check whether the folder exists online or if other programs have the project file open."), + _L("Save project"), wxOK | wxICON_WARNING).ShowModal(); return wxID_CANCEL; } @@ -15423,17 +15385,18 @@ int Plater::save_project(bool saveAs) try { json j; boost::uintmax_t size = boost::filesystem::file_size(into_path(filename)); - j["file_size"] = size; - j["file_name"] = std::string(filename.mb_str()); + j["file_size"] = size; + j["file_name"] = std::string(filename.mb_str()); NetworkAgent* agent = wxGetApp().getAgent(); - } catch (...) {} + } + catch (...) {} update_title_dirty_status(); return wxID_YES; } -// BBS import model by model id +//BBS import model by model id void Plater::import_model_id(wxString download_info) { BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << __LINE__ << " download info: " << download_info; @@ -15443,135 +15406,155 @@ void Plater::import_model_id(wxString download_info) wxString filename; wxString separator = "&name="; - try { + try + { size_t namePos = download_info.Find(separator); if (namePos != wxString::npos) { download_url = download_info.Mid(0, namePos); - filename = download_info.Mid(namePos + separator.Length()); + filename = download_info.Mid(namePos + separator.Length()); - } else { + } + else { fs::path download_path = fs::path(download_origin_url.wx_str()); - download_url = download_origin_url; - filename = download_path.filename().string(); + download_url = download_origin_url; + filename = download_path.filename().string(); } - } catch (const std::exception&) { - // wxString sError = error.what(); + } + catch (const std::exception&) + { + //wxString sError = error.what(); } - bool download_ok = false; - int retry_count = 0; + bool download_ok = false; + int retry_count = 0; const int max_retries = 3; /* jump to 3D eidtor */ wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); /* prepare progress dialog */ - bool cont = true; + bool cont = true; bool cont_dlg = true; - bool cancel = false; + bool cancel = false; wxString msg; wxString dlg_title = _L("Importing Model"); int percent = 0; - ProgressDialog dlg(dlg_title, wxString(' ', 100) + "\n\n\n\n", - 100, // range - this, // parent - wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_SMOOTH); + ProgressDialog dlg(dlg_title, + wxString(' ', 100) + "\n\n\n\n", + 100, // range + this, // parent + wxPD_CAN_ABORT | + wxPD_APP_MODAL | + wxPD_AUTO_HIDE | + wxPD_SMOOTH); boost::filesystem::path target_path; - // reset params + //reset params p->project.reset(); /* prepare project and profile */ boost::thread import_thread = Slic3r::create_thread([&percent, &cont, &retry_count, &msg, &target_path, &download_ok, download_url, &filename] { - int res = 0; - std::string http_body; + // Orca: NetworkAgent is not needed and only prevents this from running +// NetworkAgent* m_agent = Slic3r::GUI::wxGetApp().getAgent(); +// if (!m_agent) return; - msg = _L("Preparing 3MF file..."); + int res = 0; + std::string http_body; - // gets the number of files with the same name - std::vector vecFiles; - bool is_already_exist = false; + msg = _L("Preparing 3MF file..."); - target_path = fs::path(wxGetApp().app_config->get("download_path")); + //gets the number of files with the same name + std::vector vecFiles; + bool is_already_exist = false; - try { - vecFiles.clear(); - wxString extension = fs::path(filename.wx_str()).extension().c_str(); - // check file suffix - if (!extension.Contains(".3mf")) { - msg = _L("Download failed; unknown file format."); - return; + target_path = fs::path(wxGetApp().app_config->get("download_path")); + + try + { + vecFiles.clear(); + wxString extension = fs::path(filename.wx_str()).extension().c_str(); + + + //check file suffix + if (!extension.Contains(".3mf")) { + msg = _L("Download failed; unknown file format."); + return; + } + + auto name = filename.substr(0, filename.length() - extension.length() - 1); + + for (const auto& iter : boost::filesystem::directory_iterator(target_path)) + { + if (boost::filesystem::is_directory(iter.path())) + continue; + + wxString sFile = iter.path().filename().string().c_str(); + if (strstr(sFile.c_str(), name.c_str()) != NULL) { + vecFiles.push_back(sFile); } - auto name = filename.substr(0, filename.length() - extension.length() - 1); - - for (const auto& iter : boost::filesystem::directory_iterator(target_path)) { - if (boost::filesystem::is_directory(iter.path())) - continue; - - wxString sFile = iter.path().filename().string().c_str(); - if (strstr(sFile.c_str(), name.c_str()) != NULL) { - vecFiles.push_back(sFile); - } - - if (sFile == filename) - is_already_exist = true; - } - } catch (const std::exception&) { - // wxString sError = error.what(); + if (sFile == filename) is_already_exist = true; } + } + catch (const std::exception&) + { + //wxString sError = error.what(); + } - // update filename - if (is_already_exist && vecFiles.size() >= 1) { - wxString extension = fs::path(filename.wx_str()).extension().c_str(); - wxString name = filename.substr(0, filename.length() - extension.length()); - filename = wxString::Format("%s(%d)%s", name, vecFiles.size() + 1, extension).ToStdString(); - } + //update filename + if (is_already_exist && vecFiles.size() >= 1) { + wxString extension = fs::path(filename.wx_str()).extension().c_str(); + wxString name = filename.substr(0, filename.length() - extension.length()); + filename = wxString::Format("%s(%d)%s", name, vecFiles.size() + 1, extension).ToStdString(); + } - msg = _L("Downloading project..."); - // target_path = wxStandardPaths::Get().GetTempDir().utf8_str().data(); + msg = _L("Downloading project..."); - // target_path = wxGetApp().get_local_models_path().c_str(); - boost::uuids::uuid uuid = boost::uuids::random_generator()(); - std::string unique = to_string(uuid).substr(0, 6); + //target_path = wxStandardPaths::Get().GetTempDir().utf8_str().data(); - if (filename.empty()) { - filename = "untitled.3mf"; - } - // target_path /= (boost::format("%1%_%2%.3mf") % filename % unique).str(); - target_path /= fs::path(filename.wc_str()); + //target_path = wxGetApp().get_local_models_path().c_str(); + boost::uuids::uuid uuid = boost::uuids::random_generator()(); + std::string unique = to_string(uuid).substr(0, 6); - fs::path tmp_path = target_path; - tmp_path += format(".%1%", ".download"); + if (filename.empty()) { + filename = "untitled.3mf"; + } - auto filesize = 0; - bool size_limit = false; - auto http = Http::get(download_url.ToStdString()); + //target_path /= (boost::format("%1%_%2%.3mf") % filename % unique).str(); + target_path /= fs::path(filename.wc_str()); - while (cont && retry_count < max_retries) { - retry_count++; - http.on_progress([&percent, &cont, &msg, &filesize, &size_limit](Http::Progress progress, bool& cancel) { - if (!cont) - cancel = true; - if (progress.dltotal != 0) { - if (filesize == 0) { - filesize = progress.dltotal; - double megabytes = static_cast(progress.dltotal) / (1024 * 1024); - // The maximum size of a 3mf file is 500mb - if (megabytes > 500) { - cont = false; - size_limit = true; - } + fs::path tmp_path = target_path; + tmp_path += format(".%1%", ".download"); + + auto filesize = 0; + bool size_limit = false; + auto http = Http::get(download_url.ToStdString()); + + while (cont && retry_count < max_retries) { + retry_count++; + http.on_progress([&percent, &cont, &msg, &filesize, &size_limit](Http::Progress progress, bool& cancel) { + + if (!cont) cancel = true; + if (progress.dltotal != 0) { + + if (filesize == 0) { + filesize = progress.dltotal; + double megabytes = static_cast(progress.dltotal) / (1024 * 1024); + //The maximum size of a 3mf file is 500mb + if (megabytes > 500) { + cont = false; + size_limit = true; } - percent = progress.dlnow * 100 / progress.dltotal; } + percent = progress.dlnow * 100 / progress.dltotal; + } if (size_limit) { msg = _L("Download failed; File size exception."); @@ -15587,31 +15570,31 @@ void Plater::import_model_id(wxString download_info) http_status, error); - if (retry_count == max_retries) { - msg = _L("Importing to Orca Slicer failed. Please download the file and manually import it."); - cont = false; - } - }) - .on_complete([&cont, &download_ok, tmp_path, target_path](std::string body, unsigned /* http_status */) { + if (retry_count == max_retries) { + msg = _L("Importing to Orca Slicer failed. Please download the file and manually import it."); + cont = false; + } + }) + .on_complete([&cont, &download_ok, tmp_path, target_path](std::string body, unsigned /* http_status */) { fs::fstream file(tmp_path, std::ios::out | std::ios::binary | std::ios::trunc); file.write(body.c_str(), body.size()); file.close(); fs::rename(tmp_path, target_path); - cont = false; + cont = false; download_ok = true; - }) - .perform_sync(); + }).perform_sync(); // for break while - // cont = false; - } - }); + //cont = false; + } + + }); while (cont && cont_dlg) { wxMilliSleep(50); cont_dlg = dlg.Update(percent, msg); if (!cont_dlg) { - cont = cont_dlg; + cont = cont_dlg; cancel = true; } @@ -15632,15 +15615,13 @@ void Plater::import_model_id(wxString download_info) BOOST_LOG_TRIVIAL(trace) << "import_model_id: target_path = " << target_path.string(); /* load project */ // Orca: If download is a zip file, treat it as if file has been drag and dropped on the plater - if (target_path.extension() == ".zip") { - wxArrayString arr; - arr.Add(from_path(target_path)); - this->load_files(arr); - } else + if (target_path.extension() == ".zip") + { wxArrayString arr; arr.Add(from_path(target_path)); this->load_files(arr); } + else this->load_project(from_path(target_path)); /*BBS set project info after load project, project info is reset in load project */ - // p->project.project_model_id = model_id; - // p->project.project_design_id = design_id; + //p->project.project_model_id = model_id; + //p->project.project_design_id = design_id; AppConfig* config = wxGetApp().app_config; if (config) { p->project.project_country_code = config->get_country_code(); @@ -15649,7 +15630,8 @@ void Plater::import_model_id(wxString download_info) // show save new project p->set_project_filename(target_path.wstring()); p->notification_manager->push_import_finished_notification(target_path.string(), target_path.parent_path().string(), false); - } else { + } + else { if (!msg.empty()) { MessageDialog msg_wingow(nullptr, msg, wxEmptyString, wxICON_WARNING | wxOK); msg_wingow.SetSize(wxSize(FromDIP(480), -1)); @@ -15658,8 +15640,11 @@ void Plater::import_model_id(wxString download_info) return; } } -// BBS download project by project id -void Plater::download_project(const wxString& project_id) { return; } +//BBS download project by project id +void Plater::download_project(const wxString& project_id) +{ + return; +} void Plater::request_model_download(wxString url) { @@ -15682,7 +15667,8 @@ bool Plater::up_to_date(bool saved, bool backup) Slic3r::clear_other_changes(backup); return p->up_to_date(saved, backup); } - return p->model.objects.empty() || (p->up_to_date(saved, backup) && !Slic3r::has_other_changes(backup)); + return p->model.objects.empty() || (p->up_to_date(saved, backup) && + !Slic3r::has_other_changes(backup)); } bool Plater::add_model(bool imperial_units, std::string fname) @@ -15697,12 +15683,13 @@ bool Plater::add_model(bool imperial_units, std::string fname) for (const auto& file : input_files) paths.emplace_back(into_path(file)); - } else { + } + else { paths.emplace_back(fname); } std::string snapshot_label; - assert(!paths.empty()); + assert(! paths.empty()); if (paths.size() == 1) { snapshot_label = "Import Object"; snapshot_label += ": "; @@ -15711,7 +15698,7 @@ bool Plater::add_model(bool imperial_units, std::string fname) snapshot_label = "Import Objects"; snapshot_label += ": "; snapshot_label += paths.front().filename().string().c_str(); - for (size_t i = 1; i < paths.size(); ++i) { + for (size_t i = 1; i < paths.size(); ++ i) { snapshot_label += ", "; snapshot_label += encode_path(paths[i].filename().string().c_str()); } @@ -15723,21 +15710,11 @@ bool Plater::add_model(bool imperial_units, std::string fname) auto loadfiles_type = LoadFilesType::NoFile; auto amf_files_count = get_3mf_file_count(paths); - if (paths.size() > 1 && amf_files_count < paths.size()) { - loadfiles_type = LoadFilesType::Multiple3MFOther; - } - if (paths.size() > 1 && amf_files_count == paths.size()) { - loadfiles_type = LoadFilesType::Multiple3MF; - } - if (paths.size() > 1 && amf_files_count == 0) { - loadfiles_type = LoadFilesType::MultipleOther; - } - if (paths.size() == 1 && amf_files_count == 1) { - loadfiles_type = LoadFilesType::Single3MF; - }; - if (paths.size() == 1 && amf_files_count == 0) { - loadfiles_type = LoadFilesType::SingleOther; - }; + if (paths.size() > 1 && amf_files_count < paths.size()) { loadfiles_type = LoadFilesType::Multiple3MFOther; } + if (paths.size() > 1 && amf_files_count == paths.size()) { loadfiles_type = LoadFilesType::Multiple3MF; } + if (paths.size() > 1 && amf_files_count == 0) { loadfiles_type = LoadFilesType::MultipleOther; } + if (paths.size() == 1 && amf_files_count == 1) { loadfiles_type = LoadFilesType::Single3MF; }; + if (paths.size() == 1 && amf_files_count == 0) { loadfiles_type = LoadFilesType::SingleOther; }; bool ask_multi = false; @@ -15745,10 +15722,10 @@ bool Plater::add_model(bool imperial_units, std::string fname) ask_multi = true; auto strategy = LoadStrategy::LoadModel; - if (imperial_units) - strategy = strategy | LoadStrategy::ImperialUnits; + if (imperial_units) strategy = strategy | LoadStrategy::ImperialUnits; const bool loaded = !load_files(paths, strategy, ask_multi).empty(); if (loaded) { + if (get_project_name() == _L("Untitled") && paths.size() > 0) { boost::filesystem::path full_path(paths[0].string()); p->set_project_name(from_u8(full_path.stem().string())); @@ -15764,16 +15741,22 @@ void Plater::calib_pa(const Calib_Params& params) const auto calib_pa_name = wxString::Format(L"Pressure Advance Test"); new_project(false, false, calib_pa_name); wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); - auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; + auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; print_config->set_key_value("overhang_reverse", new ConfigOptionBool(false)); print_config->set_key_value("precise_z_height", new ConfigOptionBool(false)); printer_config->set_key_value("resonance_avoidance", new ConfigOptionBool{false}); switch (params.mode) { - case CalibMode::Calib_PA_Line: add_model(false, Slic3r::resources_dir() + "/calib/pressure_advance/pressure_advance_test.drc"); break; - case CalibMode::Calib_PA_Pattern: _calib_pa_pattern(params); break; - case CalibMode::Calib_PA_Tower: _calib_pa_tower(params); break; - default: break; + case CalibMode::Calib_PA_Line: + add_model(false, Slic3r::resources_dir() + "/calib/pressure_advance/pressure_advance_test.drc"); + break; + case CalibMode::Calib_PA_Pattern: + _calib_pa_pattern(params); + break; + case CalibMode::Calib_PA_Tower: + _calib_pa_tower(params); + break; + default: break; } p->background_process.fff_print()->set_calib_params(params); } @@ -15784,17 +15767,17 @@ void Plater::_calib_pa_pattern(const Calib_Params& params) std::vector accels{params.accelerations}; std::vector object_idxs{}; /* Set common parameters */ - auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; + auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; DynamicPrintConfig& print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config; - auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; - double nozzle_diameter = printer_config->option("nozzle_diameter")->get_at(0); + auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; + double nozzle_diameter = printer_config->option("nozzle_diameter")->get_at(0); set_config_values(filament_config, "filament_retract_when_changing_layer", false); set_config_values(filament_config, "filament_wipe", false); set_config_values(printer_config, "wipe", false); set_config_values(printer_config, "retract_when_changing_layer", false); printer_config->set_key_value("resonance_avoidance", new ConfigOptionBool(false)); - // Orca: find acceleration to use in the test + //Orca: find acceleration to use in the test auto accel = print_config.get_abs_value_at("outer_wall_acceleration", params.extruder_id); // get the outer wall acceleration if (accel == 0) // if outer wall accel isnt defined, fall back to inner wall accel accel = print_config.get_abs_value_at("inner_wall_acceleration", params.extruder_id); @@ -15804,27 +15787,26 @@ void Plater::_calib_pa_pattern(const Calib_Params& params) // is set to the travel accel before printing the pattern. if (accels.empty()) { accels.assign({accel}); - const auto msg{_L("INFO:") + "\n" + _L("No accelerations provided for calibration. Use default acceleration value ") + - std::to_string(long(accel)) + _L(u8"mm/s²")}; + const auto msg{_L("INFO:") + "\n" + + _L("No accelerations provided for calibration. Use default acceleration value ") + std::to_string(long(accel)) + _L(u8"mm/s²")}; get_notification_manager()->push_notification(msg.utf8_string()); } else { // set max acceleration in case of batch mode to get correct test pattern size accel = *std::max_element(accels.begin(), accels.end()); } set_config_values(&print_config, "outer_wall_acceleration", accel); - print_config.set_key_value("print_sequence", new ConfigOptionEnum(PrintSequence::ByLayer)); - - // Orca: find jerk value to use in the test - if (!has_junction_deviation(printer_config) && - print_config.get_abs_value_at("default_jerk", params.extruder_id) > 0) { // we have set a jerk value + print_config.set_key_value( "print_sequence", new ConfigOptionEnum(PrintSequence::ByLayer)); + + //Orca: find jerk value to use in the test + if(!has_junction_deviation(printer_config) && print_config.get_abs_value_at("default_jerk", params.extruder_id) > 0){ // we have set a jerk value auto jerk = print_config.get_abs_value_at("outer_wall_jerk", params.extruder_id); // get outer wall jerk if (jerk == 0) // if outer wall jerk is not defined, get inner wall jerk jerk = print_config.get_abs_value_at("inner_wall_jerk", params.extruder_id); if (jerk == 0) // if inner wall jerk is not defined, get the default jerk jerk = print_config.get_abs_value_at("default_jerk", params.extruder_id); - - // Orca: Set jerk values. Again first layer jerk should not matter as it is reset to the travel jerk before the - // first PA pattern is printed. + + //Orca: Set jerk values. Again first layer jerk should not matter as it is reset to the travel jerk before the + // first PA pattern is printed. set_config_values(&print_config, "default_jerk", jerk); set_config_values(&print_config, "outer_wall_jerk", jerk); set_config_values(&print_config, "inner_wall_jerk", jerk); @@ -15833,38 +15815,45 @@ void Plater::_calib_pa_pattern(const Calib_Params& params) set_config_values(&print_config, "travel_jerk", jerk); } - if (has_junction_deviation(printer_config)) { + if (has_junction_deviation(printer_config)){ set_config_values(&print_config, "default_junction_deviation", 0); } - + for (const auto& opt : SuggestedConfigCalibPAPattern().floats_pairs) { set_config_values(&print_config, opt.first, opt.second[0]); } for (const auto& opt : SuggestedConfigCalibPAPattern().nozzle_ratio_pairs) { - print_config.set_key_value(opt.first, new ConfigOptionFloatOrPercent(nozzle_diameter * opt.second / 100, false)); + print_config.set_key_value( + opt.first, + new ConfigOptionFloatOrPercent(nozzle_diameter * opt.second / 100, false) + ); } for (const auto& opt : SuggestedConfigCalibPAPattern().int_pairs) { - print_config.set_key_value(opt.first, new ConfigOptionInt(opt.second)); + print_config.set_key_value( + opt.first, + new ConfigOptionInt(opt.second) + ); } print_config.set_key_value(SuggestedConfigCalibPAPattern().brim_pair.first, - new ConfigOptionEnum(SuggestedConfigCalibPAPattern().brim_pair.second)); + new ConfigOptionEnum(SuggestedConfigCalibPAPattern().brim_pair.second)); print_config.set_key_value("enable_wrapping_detection", new ConfigOptionBool(false)); // Orca: Set the outer wall speed to the optimal speed for the test, cap it with max volumetric speed if (speeds.empty()) { // TODO: per-variant cap - double speed = CalibPressureAdvance::find_optimal_PA_speed(wxGetApp().preset_bundle->full_config(), - print_config.get_abs_value("line_width", nozzle_diameter), - print_config.get_abs_value("layer_height"), 0, 0); + double speed = CalibPressureAdvance::find_optimal_PA_speed( + wxGetApp().preset_bundle->full_config(), + print_config.get_abs_value("line_width", nozzle_diameter), + print_config.get_abs_value("layer_height"), 0, 0); set_config_values(&print_config, "outer_wall_speed", speed); speeds.assign({speed}); - const auto msg{_L("INFO:") + "\n" + _L("No speeds provided for calibration. Use default optimal speed ") + - std::to_string(long(speed)) + _L("mm/s")}; + const auto msg{_L("INFO:") + "\n" + + _L("No speeds provided for calibration. Use default optimal speed ") + std::to_string(long(speed)) + _L("mm/s")}; get_notification_manager()->push_notification(msg.utf8_string()); } else if (speeds.size() == 1) { // If we have single value provided, set speed using global configuration. @@ -15880,15 +15869,21 @@ void Plater::_calib_pa_pattern(const Calib_Params& params) wxGetApp().get_tab(Preset::TYPE_PRINTER)->reload_config(); const DynamicPrintConfig full_config = wxGetApp().preset_bundle->full_config(); - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - const bool is_bbl_machine = preset_bundle->is_bbl_vendor(); - auto cur_plate = get_partplate_list().get_plate(0); + PresetBundle* preset_bundle = wxGetApp().preset_bundle; + const bool is_bbl_machine = preset_bundle->is_bbl_vendor(); + auto cur_plate = get_partplate_list().get_plate(0); // add "handle" cube sidebar().obj_list()->load_generic_subobject("Cube", ModelVolumeType::INVALID); - auto* cube = model().objects[0]; + auto *cube = model().objects[0]; - CalibPressureAdvancePattern pa_pattern(params, full_config, is_bbl_machine, *cube, cur_plate->get_origin()); + CalibPressureAdvancePattern pa_pattern( + params, + full_config, + is_bbl_machine, + *cube, + cur_plate->get_origin() + ); /* Having PA pattern configured, we could make a set of polygons resembling N test patterns. * We'll arrange this set of polygons, so we would know position of each test pattern and @@ -15898,7 +15893,8 @@ void Plater::_calib_pa_pattern(const Calib_Params& params) * as a reference for objects arrangement. Polygon is slightly oversized to add spaces between patterns. * That arrangement will be used to place 'handle cubes' for each test. */ auto cube_bb = cube->raw_bounding_box(); - cube->scale((pa_pattern.print_size_x() + 4) / cube_bb.size().x(), (pa_pattern.print_size_y() + 4) / cube_bb.size().y(), + cube->scale((pa_pattern.print_size_x() + 4) / cube_bb.size().x(), + (pa_pattern.print_size_y() + 4) / cube_bb.size().y(), pa_pattern.max_layer_z() / cube_bb.size().z()); arrangement::ArrangePolygons arranged_items; @@ -15906,7 +15902,7 @@ void Plater::_calib_pa_pattern(const Calib_Params& params) arrangement::ArrangeParams ap; Points bedpts = arrangement::get_shrink_bedpts(&full_config, ap); - for (size_t i = 0; i < speeds.size() * accels.size(); i++) { + for(size_t i = 0; i < speeds.size() * accels.size(); i++) { arrangement::ArrangePolygon p; cube->instances[0]->get_arrange_polygon(&p); p.bed_idx = 0; @@ -15918,23 +15914,24 @@ void Plater::_calib_pa_pattern(const Calib_Params& params) /* scale cube back to the size of test pattern 'handle' */ cube_bb = cube->raw_bounding_box(); - cube->scale(pa_pattern.handle_xy_size() / cube_bb.size().x(), pa_pattern.handle_xy_size() / cube_bb.size().y(), + cube->scale(pa_pattern.handle_xy_size() / cube_bb.size().x(), + pa_pattern.handle_xy_size() / cube_bb.size().y(), pa_pattern.max_layer_z() / cube_bb.size().z()); /* Set speed and acceleration on per-object basis and arrange anchor object on the plates. * Test gcode will be genecated during plate slicing */ - for (size_t test_idx = 0; test_idx < arranged_items.size(); test_idx++) { - const auto& ai = arranged_items[test_idx]; + for(size_t test_idx = 0; test_idx < arranged_items.size(); test_idx++) { + const auto &ai = arranged_items[test_idx]; size_t plate_idx = arranged_items[test_idx].bed_idx; - auto tspd = speeds[test_idx % speeds.size()]; - auto tacc = accels[test_idx / speeds.size()]; + auto tspd = speeds[test_idx % speeds.size()]; + auto tacc = accels[test_idx / speeds.size()]; /* make an own copy of anchor cube for each test */ - auto obj = test_idx == 0 ? cube : model().add_object(*cube); + auto obj = test_idx == 0 ? cube : model().add_object(*cube); auto obj_idx = std::distance(model().objects.begin(), std::find(model().objects.begin(), model().objects.end(), obj)); obj->name.assign(std::string("pa_pattern_") + std::to_string(int(tspd)) + std::string("_") + std::to_string(int(tacc))); - auto& obj_config = obj->config; + auto &obj_config = obj->config; if (speeds.size() > 1) obj_config.set_key_value("outer_wall_speed", new ConfigOptionFloatsNullable(1, tspd)); if (accels.size() > 1) @@ -15948,7 +15945,9 @@ void Plater::_calib_pa_pattern(const Calib_Params& params) object_idxs.emplace_back(obj_idx); get_partplate_list().add_to_plate(obj_idx, 0, plate_idx); - const Vec3d obj_offset{unscale(ai.translation(X)), unscale(ai.translation(Y)), 0}; + const Vec3d obj_offset{unscale(ai.translation(X)), + unscale(ai.translation(Y)), + 0}; obj->instances[0]->set_offset(cur_plate->get_origin() + obj_offset + pa_pattern.handle_pos_offset()); obj->ensure_on_bed(); @@ -15975,23 +15974,27 @@ void Plater::_calib_pa_pattern_gen_gcode() * We'll store gcode for all tests on a single plate here. Once the plate handling is done, * all the g-codes will be merged into a single one on per-layer basis */ std::vector mgc; - PresetBundle* preset_bundle = wxGetApp().preset_bundle; + PresetBundle *preset_bundle = wxGetApp().preset_bundle; /* iterate over all cubes on current plate and generate gcode for them */ for (auto obj : cur_plate->get_objects_on_this_plate()) { - auto gcode = model().calib_pa_pattern->generate_custom_gcodes(preset_bundle->full_config(), preset_bundle->is_bbl_vendor(), *obj, - cur_plate->get_origin()); + auto gcode = model().calib_pa_pattern->generate_custom_gcodes( + preset_bundle->full_config(), + preset_bundle->is_bbl_vendor(), + *obj, + cur_plate->get_origin() + ); mgc.emplace_back(gcode); } // move first item into model custom gcode - auto& pcgc = model().plates_custom_gcodes[get_partplate_list().get_curr_plate_index()]; - pcgc = std::move(mgc[0]); + auto &pcgc = model().plates_custom_gcodes[get_partplate_list().get_curr_plate_index()]; + pcgc = std::move(mgc[0]); mgc.erase(mgc.begin()); // concat layer gcodes for each test for (size_t i = 0; i < pcgc.gcodes.size(); i++) { - for (auto& gc : mgc) { + for (auto &gc : mgc) { pcgc.gcodes[i].extra += gc.gcodes[i].extra; } } @@ -16000,35 +16003,35 @@ void Plater::_calib_pa_pattern_gen_gcode() void Plater::cut_horizontal(size_t obj_idx, size_t instance_idx, double z, ModelObjectCutAttributes attributes) { wxCHECK_RET(obj_idx < p->model.objects.size(), "obj_idx out of bounds"); - auto* object = p->model.objects[obj_idx]; + auto *object = p->model.objects[obj_idx]; wxCHECK_RET(instance_idx < object->instances.size(), "instance_idx out of bounds"); - if (!attributes.has(ModelObjectCutAttribute::KeepUpper) && !attributes.has(ModelObjectCutAttribute::KeepLower)) + if (! attributes.has(ModelObjectCutAttribute::KeepUpper) && ! attributes.has(ModelObjectCutAttribute::KeepLower)) return; wxBusyCursor wait; const Vec3d instance_offset = object->instances[instance_idx]->get_offset(); - Cut cut(object, instance_idx, Geometry::translation_transform(z * Vec3d::UnitZ() - instance_offset), attributes); - const auto new_objects = cut.perform_with_plane(); + Cut cut(object, instance_idx, Geometry::translation_transform(z * Vec3d::UnitZ() - instance_offset), attributes); + const auto new_objects = cut.perform_with_plane(); apply_cut_object_to_model(obj_idx, new_objects); } -void Plater::_calib_pa_tower(const Calib_Params& params) -{ +void Plater::_calib_pa_tower(const Calib_Params& params) { if (!add_model(false, Slic3r::resources_dir() + "/calib/pressure_advance/tower_with_seam.drc")) return; - auto& print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config; - auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; + auto& print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config; + auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; const double nozzle_diameter = printer_config->option("nozzle_diameter")->get_at(0); print_config.set_key_value("enable_wrapping_detection", new ConfigOptionBool(false)); - filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats{1.0f}); + filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats{ 1.0f }); + auto& obj_cfg = model().objects[0]->config; @@ -16048,7 +16051,7 @@ void Plater::_calib_pa_tower(const Calib_Params& params) obj_cfg.set_key_value("seam_slope_type", new ConfigOptionEnum(SeamScarfType::None)); print_config.set_key_value("max_volumetric_extrusion_rate_slope", new ConfigOptionFloat(0)); - changed_objects({0}); + changed_objects({ 0 }); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_FILAMENT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_PRINTER)->update_dirty(); @@ -16057,7 +16060,7 @@ void Plater::_calib_pa_tower(const Calib_Params& params) wxGetApp().get_tab(Preset::TYPE_PRINTER)->reload_config(); auto new_height = std::ceil((params.end - params.start) / params.step) + 1; - auto obj_bb = model().objects[0]->bounding_box_exact(); + auto obj_bb = model().objects[0]->bounding_box_exact(); if (new_height < obj_bb.size().z()) { cut_horizontal(0, 0, new_height, ModelObjectCutAttribute::KeepLower); } @@ -16065,8 +16068,7 @@ void Plater::_calib_pa_tower(const Calib_Params& params) _calib_pa_select_added_objects(); } -void Plater::_calib_pa_select_added_objects() -{ +void Plater::_calib_pa_select_added_objects() { // update printable state for new volumes on canvas3D wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_objects({0}); @@ -16088,28 +16090,27 @@ void Plater::_calib_pa_select_added_objects() // ORCA: Add pattern parameter void adjust_settings_for_flowrate_calib(ModelObjectPtrs& objects, bool linear, int pass, InfillPattern pattern) { - auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; + auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; /// --- scale --- // model is created for a 0.4 nozzle, scale z with nozzle size. const ConfigOptionFloats* nozzle_diameter_config = printer_config->option("nozzle_diameter"); - std::vector extruder_types = printer_config->option("extruder_type")->values; - std::vector nozzle_volume_types = - wxGetApp().preset_bundle->project_config.option("nozzle_volume_type")->values; + std::vector extruder_types = printer_config->option("extruder_type")->values; + std::vector nozzle_volume_types = wxGetApp().preset_bundle->project_config.option("nozzle_volume_type")->values; assert(nozzle_diameter_config->values.size() > 0); float nozzle_diameter = nozzle_diameter_config->values[0]; - float xyScale = nozzle_diameter / 0.6; - // scale z to have 10 layers - // 2 bottom, 5 top, 3 sparse infill + float xyScale = nozzle_diameter / 0.6; + //scale z to have 10 layers + // 2 bottom, 5 top, 3 sparse infill double first_layer_height = print_config->option("initial_layer_print_height")->value; - double layer_height = nozzle_diameter / 2.0; // prefer 0.2 layer height for 0.4 nozzle - first_layer_height = std::max(first_layer_height, layer_height); + double layer_height = nozzle_diameter / 2.0; // prefer 0.2 layer height for 0.4 nozzle + first_layer_height = std::max(first_layer_height, layer_height); - const auto canvas = wxGetApp().plater()->canvas3D(); - auto& selection = canvas->get_selection(); + const auto canvas = wxGetApp().plater()->canvas3D(); + auto& selection = canvas->get_selection(); selection.setup_cache(); TransformationType transformation_type; transformation_type.set_relative(); @@ -16124,7 +16125,7 @@ void adjust_settings_for_flowrate_calib(ModelObjectPtrs& objects, bool linear, i auto cur_flowrate = filament_config->option("filament_flow_ratio")->get_at(0); // TODO: per-filament param std::vector internal_solid_speeds = generate_max_speed_parameter_value("internal_solid_infill_speed", linear, pass); - std::vector top_surface_speeds = generate_max_speed_parameter_value("top_surface_speed", linear, pass); + std::vector top_surface_speeds = generate_max_speed_parameter_value("top_surface_speed", linear, pass); // adjust parameters for (auto _obj : objects) { @@ -16135,7 +16136,7 @@ void adjust_settings_for_flowrate_calib(ModelObjectPtrs& objects, bool linear, i _obj->config.set_key_value("enable_extra_bridge_layer", new ConfigOptionEnum(eblDisabled)); _obj->config.set_key_value("internal_bridge_density", new ConfigOptionPercent(100)); _obj->config.set_key_value("sparse_infill_density", new ConfigOptionPercent(35)); - _obj->config.set_key_value("min_width_top_surface", new ConfigOptionFloatOrPercent(100, true)); + _obj->config.set_key_value("min_width_top_surface", new ConfigOptionFloatOrPercent(100,true)); _obj->config.set_key_value("bottom_shell_layers", new ConfigOptionInt(2)); _obj->config.set_key_value("top_shell_layers", new ConfigOptionInt(5)); _obj->config.set_key_value("top_shell_thickness", new ConfigOptionFloat(0)); @@ -16150,8 +16151,7 @@ void adjust_settings_for_flowrate_calib(ModelObjectPtrs& objects, bool linear, i _obj->config.set_key_value("top_solid_infill_flow_ratio", new ConfigOptionFloat(1.0f)); _obj->config.set_key_value("infill_direction", new ConfigOptionFloat(45)); _obj->config.set_key_value("solid_infill_direction", new ConfigOptionFloat(135)); - _obj->config.set_key_value("center_of_surface_pattern", - new ConfigOptionEnum(CenterOfSurfacePattern::Each_Surface)); + _obj->config.set_key_value("center_of_surface_pattern", new ConfigOptionEnum(CenterOfSurfacePattern::Each_Surface)); _obj->config.set_key_value("separated_infills", new ConfigOptionBool(false)); _obj->config.set_key_value("align_infill_direction_to_model", new ConfigOptionBool(true)); _obj->config.set_key_value("ironing_type", new ConfigOptionEnum(IroningType::NoIroning)); @@ -16176,18 +16176,20 @@ void adjust_settings_for_flowrate_calib(ModelObjectPtrs& objects, bool linear, i obj_name[0] = '-'; // Orca: force set locale to C to avoid parsing error const std::string _loc = std::setlocale(LC_NUMERIC, nullptr); - std::setlocale(LC_NUMERIC, "C"); - auto modifier = 1.0f; + std::setlocale(LC_NUMERIC,"C"); + auto modifier = 1.0f; try { modifier = stof(obj_name); - } catch (...) {} + } catch (...) { + } // restore locale std::setlocale(LC_NUMERIC, _loc.c_str()); - if (linear) - _obj->config.set_key_value("print_flow_ratio", new ConfigOptionFloat((cur_flowrate + modifier) / cur_flowrate)); + if(linear) + _obj->config.set_key_value("print_flow_ratio", new ConfigOptionFloat((cur_flowrate + modifier)/cur_flowrate)); else - _obj->config.set_key_value("print_flow_ratio", new ConfigOptionFloat(1.0f + modifier / 100.f)); + _obj->config.set_key_value("print_flow_ratio", new ConfigOptionFloat(1.0f + modifier/100.f)); + } print_config->set_key_value("layer_height", new ConfigOptionFloat(layer_height)); @@ -16205,8 +16207,7 @@ void adjust_settings_for_flowrate_calib(ModelObjectPtrs& objects, bool linear, i } // ORCA: Add pattern parameter -void Plater::calib_flowrate(bool is_linear, int pass, InfillPattern pattern) -{ +void Plater::calib_flowrate(bool is_linear, int pass, InfillPattern pattern) { if (pass != 1 && pass != 2) return; wxString calib_name; @@ -16249,28 +16250,27 @@ void Plater::calib_flowrate(bool is_linear, int pass, InfillPattern pattern) changed_objects(object_idx); } -void Plater::calib_temp(const Calib_Params& params) -{ + +void Plater::calib_temp(const Calib_Params& params) { constexpr double base_temp_tower_nozzle_diameter = 0.4; - constexpr double base_temp_tower_block_height = 10.0; - constexpr int base_temp_tower_temp_step = 5; + constexpr double base_temp_tower_block_height = 10.0; + constexpr int base_temp_tower_temp_step = 5; const auto calib_temp_name = wxString::Format(L"Nozzle temperature test"); new_project(false, false, calib_temp_name); wxGetApp().mainframe->select_tab(TAB_ID_PREPARE); - if (params.mode != CalibMode::Calib_Temp_Tower) - return; - + if (params.mode != CalibMode::Calib_Temp_Tower) return; + if (!add_model(false, Slic3r::resources_dir() + "/calib/temperature_tower/temperature_tower.drc")) return; - auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; - auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; - auto start_temp = lround(params.start); + auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; + auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; + auto start_temp = lround(params.start); const ConfigOptionFloats* nozzle_diameter_config = printer_config->option("nozzle_diameter"); - size_t nozzle_id = static_cast(std::max(params.extruder_id, 0)); - double nozzle_diameter = base_temp_tower_nozzle_diameter; + size_t nozzle_id = static_cast(std::max(params.extruder_id, 0)); + double nozzle_diameter = base_temp_tower_nozzle_diameter; if (nozzle_diameter_config && !nozzle_diameter_config->values.empty()) { - nozzle_id = std::min(nozzle_id, nozzle_diameter_config->values.size() - 1); + nozzle_id = std::min(nozzle_id, nozzle_diameter_config->values.size() - 1); nozzle_diameter = nozzle_diameter_config->values[nozzle_id]; } if (nozzle_diameter <= 0.0) @@ -16280,7 +16280,7 @@ void Plater::calib_temp(const Calib_Params& params) const double block_height = base_temp_tower_block_height; // cut upper - auto obj_bb = model().objects[0]->bounding_box_exact(); + auto obj_bb = model().objects[0]->bounding_box_exact(); auto block_count = lround((500 - params.end) / base_temp_tower_temp_step + 1); if (block_count > 0) { // subtract EPSILON offset to avoid cutting at the exact location where the flat surface is @@ -16291,7 +16291,7 @@ void Plater::calib_temp(const Calib_Params& params) } // cut bottom - obj_bb = model().objects[0]->bounding_box_exact(); + obj_bb = model().objects[0]->bounding_box_exact(); block_count = lround((500 - params.start) / base_temp_tower_temp_step); if (block_count > 0) { auto new_height = block_count * block_height + EPSILON; @@ -16310,7 +16310,7 @@ void Plater::calib_temp(const Calib_Params& params) set_config_values(filament_config, "nozzle_temperature", (int) start_temp); // When resizing is disabled the 0.4 mm / 0.2 mm reference model is printed as-is (preset layer height kept). if (params.nozzle_based_resize) - model().objects[0]->config.set_key_value("layer_height", new ConfigOptionFloat(nozzle_diameter / 2)); + model().objects[0]->config.set_key_value("layer_height", new ConfigOptionFloat(nozzle_diameter/2)); model().objects[0]->config.set_key_value("brim_type", new ConfigOptionEnum(btOuterOnly)); model().objects[0]->config.set_key_value("brim_width", new ConfigOptionFloat(5.0)); model().objects[0]->config.set_key_value("brim_object_gap", new ConfigOptionFloat(0.0)); @@ -16322,9 +16322,10 @@ void Plater::calib_temp(const Calib_Params& params) auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; print_config->set_key_value("enable_wrapping_detection", new ConfigOptionBool(false)); if (params.nozzle_based_resize) - print_config->set_key_value("initial_layer_print_height", new ConfigOptionFloat(nozzle_diameter / 2)); + print_config->set_key_value("initial_layer_print_height", new ConfigOptionFloat(nozzle_diameter/2)); - changed_objects({0}); + + changed_objects({ 0 }); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_FILAMENT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_PRINT)->reload_config(); @@ -16343,23 +16344,23 @@ void Plater::calib_max_vol_speed(const Calib_Params& params) if (!add_model(false, Slic3r::resources_dir() + "/calib/volumetric_speed/SpeedTestStructure.drc")) return; - auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; + auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; - auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; - auto obj = model().objects[0]; - auto& obj_cfg = obj->config; + auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; + auto obj = model().objects[0]; + auto& obj_cfg = obj->config; - auto bed_shape = printer_config->option("printable_area")->values; + auto bed_shape = printer_config->option("printable_area")->values; BoundingBoxf bed_ext = get_extents(bed_shape); - auto scale_obj = (bed_ext.size().x() - 10) / obj->bounding_box_exact().size().x(); + auto scale_obj = (bed_ext.size().x() - 10) / obj->bounding_box_exact().size().x(); if (scale_obj < 1.0) obj->scale(scale_obj, 1, 1); const ConfigOptionFloats* nozzle_diameter_config = printer_config->option("nozzle_diameter"); assert(nozzle_diameter_config->values.size() > 0); double nozzle_diameter = nozzle_diameter_config->values[0]; - double line_width = nozzle_diameter * 1.75; - double layer_height = nozzle_diameter * 0.8; + double line_width = nozzle_diameter * 1.75; + double layer_height = nozzle_diameter * 0.8; auto max_lh = printer_config->option("max_layer_height"); for (size_t i = 0; i < max_lh->values.size(); ++i) { @@ -16368,8 +16369,7 @@ void Plater::calib_max_vol_speed(const Calib_Params& params) } const double filament_max_volumetric_speed = filament_config->option("filament_max_volumetric_speed")->get_at(0); - set_config_values(filament_config, "filament_max_volumetric_speed", - std::max(filament_max_volumetric_speed, 200.0)); + set_config_values(filament_config, "filament_max_volumetric_speed", std::max(filament_max_volumetric_speed, 200.0)); filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats{0.0}); printer_config->set_key_value("resonance_avoidance", new ConfigOptionBool{false}); obj_cfg.set_key_value("enable_overhang_speed", new ConfigOptionBoolsNullable(1, false)); @@ -16389,7 +16389,7 @@ void Plater::calib_max_vol_speed(const Calib_Params& params) print_config->set_key_value("max_volumetric_extrusion_rate_slope", new ConfigOptionFloat(0)); print_config->set_key_value("enable_wrapping_detection", new ConfigOptionBool(false)); - changed_objects({0}); + changed_objects({ 0 }); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_FILAMENT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_PRINTER)->update_dirty(); @@ -16405,8 +16405,7 @@ void Plater::calib_max_vol_speed(const Calib_Params& params) } auto new_params = params; - auto mm3_per_mm = Flow(line_width, layer_height, nozzle_diameter).mm3_per_mm() * - filament_config->option("filament_flow_ratio")->get_at(0); + auto mm3_per_mm = Flow(line_width, layer_height, nozzle_diameter).mm3_per_mm() * filament_config->option("filament_flow_ratio")->get_at(0); new_params.end = params.end / mm3_per_mm; new_params.start = params.start / mm3_per_mm; new_params.step = params.step / mm3_per_mm; @@ -16425,10 +16424,10 @@ void Plater::calib_retraction(const Calib_Params& params) if (!add_model(false, Slic3r::resources_dir() + "/calib/retraction/retraction_tower.drc")) return; - auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; + auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; - auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; - auto obj = model().objects[0]; + auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; + auto obj = model().objects[0]; print_config->set_key_value("enable_wrapping_detection", new ConfigOptionBool(false)); @@ -16444,8 +16443,7 @@ void Plater::calib_retraction(const Calib_Params& params) auto max_lh = printer_config->option("max_layer_height"); for (size_t i = 0; i < max_lh->values.size(); ++i) { - if (max_lh->values[i] < layer_height) - max_lh->values[i] = layer_height; + if (max_lh->values[i] < layer_height) max_lh->values[i] = layer_height; } printer_config->set_key_value("resonance_avoidance", new ConfigOptionBool{false}); @@ -16462,7 +16460,8 @@ void Plater::calib_retraction(const Calib_Params& params) obj->config.set_key_value("overhang_reverse", new ConfigOptionBool(false)); obj->config.set_key_value("precise_z_height", new ConfigOptionBool(false)); - changed_objects({0}); + + changed_objects({ 0 }); // cut upper auto obj_bb = obj->bounding_box_exact(); @@ -16484,15 +16483,15 @@ void Plater::calib_VFA(const Calib_Params& params) if (!add_model(false, Slic3r::resources_dir() + "/calib/vfa/vfa.drc")) return; - auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; + auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; const ConfigOptionFloats* nozzle_diameter_config = printer_config->option("nozzle_diameter"); - size_t nozzle_id = static_cast(std::max(params.extruder_id, 0)); - double nozzle_diameter = vfa_base_nozzle_diameter; + size_t nozzle_id = static_cast(std::max(params.extruder_id, 0)); + double nozzle_diameter = vfa_base_nozzle_diameter; if (nozzle_diameter_config && !nozzle_diameter_config->values.empty()) { - nozzle_id = std::min(nozzle_id, nozzle_diameter_config->values.size() - 1); + nozzle_id = std::min(nozzle_id, nozzle_diameter_config->values.size() - 1); nozzle_diameter = nozzle_diameter_config->values[nozzle_id]; } if (nozzle_diameter <= 0.0) @@ -16524,7 +16523,7 @@ void Plater::calib_VFA(const Calib_Params& params) model().objects[0]->ensure_on_bed(); printer_config->set_key_value("resonance_avoidance", new ConfigOptionBool{false}); - filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats{0.0}); + filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats { 0.0 }); set_config_values(print_config, "enable_overhang_speed", false); print_config->set_key_value("timelapse_type", new ConfigOptionEnum(tlTraditional)); print_config->set_key_value("wall_loops", new ConfigOptionInt(1)); @@ -16544,7 +16543,7 @@ void Plater::calib_VFA(const Calib_Params& params) model().objects[0]->config.set_key_value("brim_width", new ConfigOptionFloat(3.0)); model().objects[0]->config.set_key_value("brim_object_gap", new ConfigOptionFloat(0.0)); - changed_objects({0}); + changed_objects({ 0 }); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_FILAMENT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_ui_from_settings(); @@ -16552,7 +16551,7 @@ void Plater::calib_VFA(const Calib_Params& params) // Pass the resolved layer height on (only meaningful when resized). GCode's VFA stepping is layer-based, so // it does not require it, but keep it consistent with the geometry. - Calib_Params calib_params = params; + Calib_Params calib_params = params; calib_params.vfa_layer_height = params.nozzle_based_resize ? layer_height : 0.0; p->background_process.fff_print()->set_calib_params(calib_params); } @@ -16565,31 +16564,20 @@ void Plater::calib_input_shaping_freq(const Calib_Params& params) if (params.mode != CalibMode::Calib_Input_shaping_freq) return; - if (!add_model(false, Slic3r::resources_dir() + (params.test_model < 1 ? "/calib/input_shaping/ringing_tower.drc" : - "/calib/input_shaping/fast_tower_test.drc"))) + if (!add_model(false, Slic3r::resources_dir() + (params.test_model < 1 ? "/calib/input_shaping/ringing_tower.drc" : "/calib/input_shaping/fast_tower_test.drc"))) return; - auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; - auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; - auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; + auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; + auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; + auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; const auto gcode_flavor_option = printer_config->option>("gcode_flavor"); if (has_junction_deviation(printer_config)) { - printer_config - ->set_key_value("machine_max_junction_deviation", - new ConfigOptionFloats{ - (std::max(printer_config->option("machine_max_junction_deviation")->values.front(), - 0.25))}); + printer_config->set_key_value("machine_max_junction_deviation", new ConfigOptionFloats {(std::max(printer_config->option("machine_max_junction_deviation")->values.front(), 0.25))}); set_config_values(print_config, "default_junction_deviation", 0); } else { const double jerk_value = (gcode_flavor_option && gcode_flavor_option->value == GCodeFlavor::gcfKlipper) ? 5.0 : 10.0; - printer_config->set_key_value("machine_max_jerk_x", - new ConfigOptionFloats{ - std::max(printer_config->option("machine_max_jerk_x")->values.front(), - jerk_value)}); - printer_config->set_key_value("machine_max_jerk_y", - new ConfigOptionFloats{ - std::max(printer_config->option("machine_max_jerk_y")->values.front(), - jerk_value)}); + printer_config->set_key_value("machine_max_jerk_x", new ConfigOptionFloats{std::max(printer_config->option("machine_max_jerk_x")->values.front(), jerk_value)}); + printer_config->set_key_value("machine_max_jerk_y", new ConfigOptionFloats{std::max(printer_config->option("machine_max_jerk_y")->values.front(), jerk_value)}); set_config_values(print_config, "default_jerk", 0); } @@ -16601,8 +16589,8 @@ void Plater::calib_input_shaping_freq(const Calib_Params& params) printer_config->set_key_value("resonance_avoidance", new ConfigOptionBool{false}); printer_config->set_key_value("input_shaping_emit", new ConfigOptionBool{false}); - filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats{0.0}); - filament_config->set_key_value("slow_down_min_speed", new ConfigOptionFloats{0.0}); + filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats { 0.0 }); + filament_config->set_key_value("slow_down_min_speed", new ConfigOptionFloats { 0.0 }); filament_config->set_key_value("slow_down_for_layer_cooling", new ConfigOptionBools{false}); print_config->set_key_value("layer_height", new ConfigOptionFloat(0.2)); set_config_values(print_config, "enable_overhang_speed", false); @@ -16615,8 +16603,7 @@ void Plater::calib_input_shaping_freq(const Calib_Params& params) print_config->set_key_value("spiral_mode", new ConfigOptionBool(true)); print_config->set_key_value("spiral_mode_smooth", new ConfigOptionBool(false)); print_config->set_key_value("bottom_surface_pattern", new ConfigOptionEnum(ipRectilinear)); - const double machine_max_speed = std::min(printer_config->option("machine_max_speed_x")->get_at(0), - printer_config->option("machine_max_speed_y")->get_at(0)); + const double machine_max_speed = std::min(printer_config->option("machine_max_speed_x")->get_at(0), printer_config->option("machine_max_speed_y")->get_at(0)); const double machine_max_acceleration = printer_config->option("machine_max_acceleration_extruding")->get_at(0); set_config_values(print_config, "outer_wall_speed", machine_max_speed); set_config_values(print_config, "default_acceleration", machine_max_acceleration); @@ -16626,7 +16613,7 @@ void Plater::calib_input_shaping_freq(const Calib_Params& params) model().objects[0]->config.set_key_value("brim_width", new ConfigOptionFloat(3.0)); model().objects[0]->config.set_key_value("brim_object_gap", new ConfigOptionFloat(0.0)); - changed_objects({0}); + changed_objects({ 0 }); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_FILAMENT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_ui_from_settings(); @@ -16643,31 +16630,20 @@ void Plater::calib_input_shaping_damp(const Calib_Params& params) if (params.mode != CalibMode::Calib_Input_shaping_damp) return; - if (!add_model(false, Slic3r::resources_dir() + (params.test_model < 1 ? "/calib/input_shaping/ringing_tower.drc" : - "/calib/input_shaping/fast_tower_test.drc"))) + if (!add_model(false, Slic3r::resources_dir() + (params.test_model < 1 ? "/calib/input_shaping/ringing_tower.drc" : "/calib/input_shaping/fast_tower_test.drc"))) return; - auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; - auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; - auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; + auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; + auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; + auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; const auto gcode_flavor_option = printer_config->option>("gcode_flavor"); if (has_junction_deviation(printer_config)) { - printer_config - ->set_key_value("machine_max_junction_deviation", - new ConfigOptionFloats{ - (std::max(printer_config->option("machine_max_junction_deviation")->values.front(), - 0.25))}); + printer_config->set_key_value("machine_max_junction_deviation", new ConfigOptionFloats {(std::max(printer_config->option("machine_max_junction_deviation")->values.front(), 0.25))}); set_config_values(print_config, "default_junction_deviation", 0); } else { const double jerk_value = (gcode_flavor_option && gcode_flavor_option->value == GCodeFlavor::gcfKlipper) ? 5.0 : 10.0; - printer_config->set_key_value("machine_max_jerk_x", - new ConfigOptionFloats{ - std::max(printer_config->option("machine_max_jerk_x")->values.front(), - jerk_value)}); - printer_config->set_key_value("machine_max_jerk_y", - new ConfigOptionFloats{ - std::max(printer_config->option("machine_max_jerk_y")->values.front(), - jerk_value)}); + printer_config->set_key_value("machine_max_jerk_x", new ConfigOptionFloats{std::max(printer_config->option("machine_max_jerk_x")->values.front(), jerk_value)}); + printer_config->set_key_value("machine_max_jerk_y", new ConfigOptionFloats{std::max(printer_config->option("machine_max_jerk_y")->values.front(), jerk_value)}); set_config_values(print_config, "default_jerk", 0); } @@ -16679,8 +16655,8 @@ void Plater::calib_input_shaping_damp(const Calib_Params& params) printer_config->set_key_value("resonance_avoidance", new ConfigOptionBool{false}); printer_config->set_key_value("input_shaping_emit", new ConfigOptionBool{false}); - filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats{0.0}); - filament_config->set_key_value("slow_down_min_speed", new ConfigOptionFloats{0.0}); + filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats { 0.0 }); + filament_config->set_key_value("slow_down_min_speed", new ConfigOptionFloats { 0.0 }); filament_config->set_key_value("slow_down_for_layer_cooling", new ConfigOptionBools{false}); set_config_values(print_config, "enable_overhang_speed", false); print_config->set_key_value("timelapse_type", new ConfigOptionEnum(tlTraditional)); @@ -16692,8 +16668,7 @@ void Plater::calib_input_shaping_damp(const Calib_Params& params) print_config->set_key_value("spiral_mode", new ConfigOptionBool(true)); print_config->set_key_value("spiral_mode_smooth", new ConfigOptionBool(false)); print_config->set_key_value("bottom_surface_pattern", new ConfigOptionEnum(ipRectilinear)); - const double machine_max_speed = std::min(printer_config->option("machine_max_speed_x")->get_at(0), - printer_config->option("machine_max_speed_y")->get_at(0)); + const double machine_max_speed = std::min(printer_config->option("machine_max_speed_x")->get_at(0), printer_config->option("machine_max_speed_y")->get_at(0)); const double machine_max_acceleration = printer_config->option("machine_max_acceleration_extruding")->get_at(0); set_config_values(print_config, "outer_wall_speed", machine_max_speed); set_config_values(print_config, "default_acceleration", machine_max_acceleration); @@ -16703,7 +16678,7 @@ void Plater::calib_input_shaping_damp(const Calib_Params& params) model().objects[0]->config.set_key_value("brim_width", new ConfigOptionFloat(3.0)); model().objects[0]->config.set_key_value("brim_object_gap", new ConfigOptionFloat(0.0)); - changed_objects({0}); + changed_objects({ 0 }); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_FILAMENT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_ui_from_settings(); @@ -16720,12 +16695,12 @@ void Plater::Calib_Cornering(const Calib_Params& params) if (params.mode != CalibMode::Calib_Cornering) return; - const std::string cornering_model_path = params.test_model == 0 ? "/calib/input_shaping/ringing_tower.drc" : - (params.test_model == 1 ? "/calib/input_shaping/fast_tower_test.drc" : - "/calib/cornering/SCV-V2.drc"); + const std::string cornering_model_path = params.test_model == 0 + ? "/calib/input_shaping/ringing_tower.drc" + : (params.test_model == 1 ? "/calib/input_shaping/fast_tower_test.drc" : "/calib/cornering/SCV-V2.drc"); if (!add_model(false, Slic3r::resources_dir() + cornering_model_path)) return; - auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; + auto print_config = &wxGetApp().preset_bundle->prints.get_edited_preset().config; auto filament_config = &wxGetApp().preset_bundle->filaments.get_edited_preset().config; auto printer_config = &wxGetApp().preset_bundle->printers.get_edited_preset().config; @@ -16747,8 +16722,8 @@ void Plater::Calib_Cornering(const Calib_Params& params) printer_config->set_key_value("resonance_avoidance", new ConfigOptionBool{false}); printer_config->set_key_value("input_shaping_emit", new ConfigOptionBool{true}); printer_config->set_key_value("input_shaping_type", new ConfigOptionEnum(InputShaperType::Disable)); - filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats{0.0}); - filament_config->set_key_value("slow_down_min_speed", new ConfigOptionFloats{0.0}); + filament_config->set_key_value("slow_down_layer_time", new ConfigOptionFloats { 0.0 }); + filament_config->set_key_value("slow_down_min_speed", new ConfigOptionFloats { 0.0 }); filament_config->set_key_value("slow_down_for_layer_cooling", new ConfigOptionBools{false}); const double filament_max_volumetric_speed = filament_config->option("filament_max_volumetric_speed")->get_at(0); filament_config->set_key_value("filament_max_volumetric_speed", new ConfigOptionFloats{std::max(filament_max_volumetric_speed, 200.0)}); @@ -16762,8 +16737,7 @@ void Plater::Calib_Cornering(const Calib_Params& params) print_config->set_key_value("spiral_mode", new ConfigOptionBool(true)); print_config->set_key_value("spiral_mode_smooth", new ConfigOptionBool(false)); print_config->set_key_value("bottom_surface_pattern", new ConfigOptionEnum(ipRectilinear)); - const double machine_max_speed = std::min(printer_config->option("machine_max_speed_x")->get_at(0), - printer_config->option("machine_max_speed_y")->get_at(0)); + const double machine_max_speed = std::min(printer_config->option("machine_max_speed_x")->get_at(0), printer_config->option("machine_max_speed_y")->get_at(0)); const double machine_max_acceleration = printer_config->option("machine_max_acceleration_extruding")->get_at(0); set_config_values(print_config, "outer_wall_speed", machine_max_speed); set_config_values(print_config, "default_acceleration", machine_max_acceleration); @@ -16773,7 +16747,7 @@ void Plater::Calib_Cornering(const Calib_Params& params) model().objects[0]->config.set_key_value("brim_width", new ConfigOptionFloat(3.0)); model().objects[0]->config.set_key_value("brim_object_gap", new ConfigOptionFloat(0.0)); - changed_objects({0}); + changed_objects({ 0 }); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_FILAMENT)->update_dirty(); wxGetApp().get_tab(Preset::TYPE_PRINT)->update_ui_from_settings(); @@ -16798,7 +16772,7 @@ void Plater::import_zip_archive() void Plater::import_sl1_archive() { - auto& w = get_ui_job_worker(); + auto &w = get_ui_job_worker(); if (w.is_idle() && p->m_sla_import_dlg->ShowModal() == wxID_OK) { p->take_snapshot(_u8L("Import SLA archive")); replace_job(w, std::make_unique(p->m_sla_import_dlg)); @@ -16810,8 +16784,8 @@ void Plater::extract_config_from_project() wxString input_file; wxGetApp().load_project(this, input_file); - if (!input_file.empty()) - load_files({into_path(input_file)}, LoadStrategy::LoadConfig); + if (! input_file.empty()) + load_files({ into_path(input_file) }, LoadStrategy::LoadConfig); } void Plater::load_gcode() @@ -16823,12 +16797,14 @@ void Plater::load_gcode() load_gcode(input_file); } -// BBS: remove GCodeViewer as seperate APP logic +//BBS: remove GCodeViewer as seperate APP logic void Plater::load_gcode(const wxString& filename) { BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << __LINE__ << " entry and filename: " << filename; BOOST_LOG_TRIVIAL(info) << __FUNCTION__; - if (!is_gcode_file(into_u8(filename)) || (m_last_loaded_gcode == filename && m_only_gcode)) + if (! is_gcode_file(into_u8(filename)) + || (m_last_loaded_gcode == filename && m_only_gcode) + ) return; m_last_loaded_gcode = filename; @@ -16840,37 +16816,40 @@ void Plater::load_gcode(const wxString& filename) m_only_gcode = true; // cleanup view before to start loading/processing - // BBS: update gcode to current partplate's + //BBS: update gcode to current partplate's GCodeProcessorResult* current_result = p->partplate_list.get_current_slice_result(); - Print& current_print = p->partplate_list.get_current_fff_print(); - // BBS:already reset in new_project - // current_result->reset(); - // p->gcode_result.reset(); - // reset_gcode_toolpaths(); + Print& current_print = p->partplate_list.get_current_fff_print(); + //BBS:already reset in new_project + //current_result->reset(); + //p->gcode_result.reset(); + //reset_gcode_toolpaths(); p->preview->reload_print(m_only_gcode); wxGetApp().mainframe->select_tab(TAB_ID_PREVIEW); p->set_current_panel(p->preview, true); p->get_current_canvas3D()->render(); - // p->notification_manager->bbl_show_plateinfo_notification(into_u8(_L("Preview only mode for gcode file."))); + //p->notification_manager->bbl_show_plateinfo_notification(into_u8(_L("Preview only mode for gcode file."))); wxBusyCursor wait; // process gcode GCodeProcessor processor; processor.init_filament_maps_and_nozzle_type_when_import_only_gcode(); - try { + try + { GCodeProcessor::s_IsBBLPrinter = wxGetApp().preset_bundle->is_bbl_vendor(); processor.process_file(filename.ToUTF8().data()); - } catch (const std::exception& ex) { + } + catch (const std::exception& ex) + { show_error(this, ex.what()); return; } *current_result = std::move(processor.extract_result()); - // current_result->filename = filename; + //current_result->filename = filename; BedType bed_type = current_result->bed_type; if (bed_type != BedType::btCount) { - DynamicPrintConfig& proj_config = wxGetApp().preset_bundle->project_config; + DynamicPrintConfig &proj_config = wxGetApp().preset_bundle->project_config; proj_config.set_key_value("curr_bed_type", new ConfigOptionEnum(bed_type)); on_bed_type_change(bed_type); } @@ -16879,14 +16858,14 @@ void Plater::load_gcode(const wxString& filename) current_print.apply_config_for_render(processor.export_config_for_render()); - // BBS: add cost info when drag in gcode - auto& ps = current_result->print_statistics; + //BBS: add cost info when drag in gcode + auto& ps = current_result->print_statistics; double total_cost = 0.0; for (auto volume : ps.total_volumes_per_extruder) { size_t extruder_id = volume.first; - double density = current_result->filament_densities.at(extruder_id); - double cost = current_result->filament_costs.at(extruder_id); - double weight = volume.second * density * 0.001; + double density = current_result->filament_densities.at(extruder_id); + double cost = current_result->filament_costs.at(extruder_id); + double weight = volume.second * density * 0.001; total_cost += weight * cost * 0.001; } current_print.print_statistics().total_cost = total_cost; @@ -16895,15 +16874,13 @@ void Plater::load_gcode(const wxString& filename) // show results p->preview->reload_print(m_only_gcode); - // BBS: zoom to bed 0 for gcode preview - // p->preview->get_canvas3d()->zoom_to_gcode(); + //BBS: zoom to bed 0 for gcode preview + //p->preview->get_canvas3d()->zoom_to_gcode(); p->preview->get_canvas3d()->zoom_to_plate(0); if (p->preview->get_canvas3d()->get_gcode_layers_zs().empty()) { MessageDialog(this, _L("The selected file") + ":\n" + filename + "\n" + _L("Does not contain valid G-code."), - wxString(GCODEVIEWER_APP_NAME) + " - " + _L("An Error has occurred while loading the G-code file."), - wxCLOSE | wxICON_WARNING | wxCENTRE) - .ShowModal(); + wxString(GCODEVIEWER_APP_NAME) + " - " + _L("An Error has occurred while loading the G-code file."), wxCLOSE | wxICON_WARNING | wxCENTRE).ShowModal(); set_project_filename(DEFAULT_PROJECT_NAME); } else { set_project_filename(filename); @@ -16914,7 +16891,7 @@ void Plater::load_gcode(const wxString& filename) p->view3D->get_canvas3d()->remove_raycasters_for_picking(SceneRaycaster::EType::Bed); } - p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, false, false); // 20250416 ban gcode to send print + p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, false, false); //20250416 ban gcode to send print } void Plater::reload_gcode_from_disk() @@ -16924,43 +16901,45 @@ void Plater::reload_gcode_from_disk() load_gcode(filename); } -void Plater::reload_print() { p->preview->reload_print(); } +void Plater::reload_print() +{ + p->preview->reload_print(); +} // BBS -wxString Plater::get_project_name() { return p->get_project_name(); } +wxString Plater::get_project_name() +{ + return p->get_project_name(); +} void Plater::update_all_plate_thumbnails(bool force_update) { for (int i = 0; i < get_partplate_list().get_plate_count(); i++) { - PartPlate* plate = get_partplate_list().get_plate(i); - ThumbnailsParams thumbnail_params = {{}, false, true, true, true, i}; + PartPlate* plate = get_partplate_list().get_plate(i); + ThumbnailsParams thumbnail_params = { {}, false, true, true, true, i}; if (force_update || !plate->thumbnail_data.is_valid()) { - get_view3D_canvas3D()->render_thumbnail(plate->thumbnail_data, plate->plate_thumbnail_width, plate->plate_thumbnail_height, - thumbnail_params, Camera::EType::Ortho); + get_view3D_canvas3D()->render_thumbnail(plate->thumbnail_data, plate->plate_thumbnail_width, plate->plate_thumbnail_height, thumbnail_params, Camera::EType::Ortho); } if (force_update || !plate->no_light_thumbnail_data.is_valid()) { - get_view3D_canvas3D()->render_thumbnail(plate->no_light_thumbnail_data, plate->plate_thumbnail_width, - plate->plate_thumbnail_height, thumbnail_params, Camera::EType::Ortho, - Camera::ViewAngleType::Iso, false, true); + get_view3D_canvas3D()->render_thumbnail(plate->no_light_thumbnail_data, plate->plate_thumbnail_width, plate->plate_thumbnail_height, thumbnail_params, + Camera::EType::Ortho, Camera::ViewAngleType::Iso, false, true); } } } -void Plater::update_obj_preview_thumbnail( - ModelObject* mo, int obj_idx, int vol_idx, std::vector colors, int camera_view_angle_type) +void Plater::update_obj_preview_thumbnail(ModelObject *mo, int obj_idx, int vol_idx, std::vector colors, int camera_view_angle_type) { - PartPlate* plate = get_partplate_list().get_plate(0); + PartPlate * plate = get_partplate_list().get_plate(0); ThumbnailsParams thumbnail_params = {{}, false, true, true, true, 0, false}; GLVolumeCollection cur_volumes; cur_volumes.load_object_volume(mo, obj_idx, vol_idx, 0, "volume", true, false, false, false); ModelObjectPtrs model_objects; model_objects.emplace_back(mo); - get_view3D_canvas3D()->render_thumbnail(plate->obj_preview_thumbnail_data, colors, plate->plate_thumbnail_width, - plate->plate_thumbnail_height, thumbnail_params, model_objects, cur_volumes, - Camera::EType::Ortho, (Camera::ViewAngleType) camera_view_angle_type, false, false); + get_view3D_canvas3D()->render_thumbnail(plate->obj_preview_thumbnail_data, colors, plate->plate_thumbnail_width, plate->plate_thumbnail_height, thumbnail_params, + model_objects, cur_volumes, Camera::EType::Ortho, (Camera::ViewAngleType) camera_view_angle_type, false, false); } -// invalid all plate's thumbnails +//invalid all plate's thumbnails void Plater::invalid_all_plate_thumbnails() { if (using_exported_file() || skip_thumbnail_invalid) @@ -16977,28 +16956,29 @@ void Plater::invalid_all_plate_thumbnails() void Plater::force_update_all_plate_thumbnails() { if (using_exported_file() || skip_thumbnail_invalid) { - } else { + } + else { invalid_all_plate_thumbnails(); update_all_plate_thumbnails(true); } } // BBS: backup -std::vector Plater::load_files(const std::vector& input_files, LoadStrategy strategy, bool ask_multi, bool* published_out) -{ - // BBS: wish to reset state when load a new file +std::vector Plater::load_files(const std::vector& input_files, LoadStrategy strategy, bool ask_multi, bool* published_out) { + //BBS: wish to reset state when load a new file p->m_slice_all_only_has_gcode = false; - // BBS: wish to reset all plates stats item selected state when load a new file + //BBS: wish to reset all plates stats item selected state when load a new file p->preview->get_canvas3d()->reset_select_plate_toolbar_selection(); return p->load_files(input_files, strategy, ask_multi, published_out); } bool Plater::preview_zip_archive(const boost::filesystem::path& archive_path) { - // std::vector unzipped_paths; + //std::vector unzipped_paths; std::vector non_project_paths; std::vector project_paths; - try { + try + { mz_zip_archive archive; mz_zip_zero_struct(&archive); @@ -17012,14 +16992,15 @@ bool Plater::preview_zip_archive(const boost::filesystem::path& archive_path) // selected_paths contains paths and its uncompressed size. The size is used to distinguish between files with same path. std::vector> selected_paths; FileArchiveDialog dlg(static_cast(wxGetApp().mainframe), &archive, selected_paths); - if (dlg.ShowModal() == wxID_OK) { + if (dlg.ShowModal() == wxID_OK) + { std::string archive_path_string = archive_path.string(); - archive_path_string = archive_path_string.substr(0, archive_path_string.size() - 4); + archive_path_string = archive_path_string.substr(0, archive_path_string.size() - 4); fs::path archive_dir(wxStandardPaths::Get().GetTempDir().utf8_str().data()); for (auto& path_w_size : selected_paths) { const fs::path& path = path_w_size.first; - size_t size = path_w_size.second; + size_t size = path_w_size.second; // find path in zip archive for (mz_uint i = 0; i < num_entries; ++i) { if (mz_zip_reader_file_stat(&archive, i, &stat)) { @@ -17033,29 +17014,29 @@ bool Plater::preview_zip_archive(const boost::filesystem::path& archive_path) if (path != archive_path) continue; // decompressing - try { + try + { std::replace(name.begin(), name.end(), '\\', '/'); // rename if file exists - std::string filename = path.filename().string(); - std::string extension = path.extension().string(); - std::string just_filename = filename.substr(0, filename.size() - extension.size()); + std::string filename = path.filename().string(); + std::string extension = path.extension().string(); + std::string just_filename = filename.substr(0, filename.size() - extension.size()); std::string final_filename = just_filename; size_t version = 0; - while (fs::exists(archive_dir / (final_filename + extension))) { + while (fs::exists(archive_dir / (final_filename + extension))) + { ++version; final_filename = just_filename + "(" + std::to_string(version) + ")"; } - filename = final_filename + extension; + filename = final_filename + extension; fs::path final_path = archive_dir / filename; - std::string buffer((size_t) stat.m_uncomp_size, 0); + std::string buffer((size_t)stat.m_uncomp_size, 0); // Decompress action. We already has correct file index in stat structure. - mz_bool res = mz_zip_reader_extract_to_mem(&archive, stat.m_file_index, (void*) buffer.data(), - (size_t) stat.m_uncomp_size, 0); + mz_bool res = mz_zip_reader_extract_to_mem(&archive, stat.m_file_index, (void*)buffer.data(), (size_t)stat.m_uncomp_size, 0); if (res == 0) { // TRN: First argument = path to file, second argument = error description - wxString error_log = GUI::format_wxstr(_L("Failed to unzip file to %1%: %2%"), final_path.string(), - mz_zip_get_error_string(mz_zip_get_last_error(&archive))); + wxString error_log = GUI::format_wxstr(_L("Failed to unzip file to %1%: %2%"), final_path.string(), mz_zip_get_error_string(mz_zip_get_last_error(&archive))); BOOST_LOG_TRIVIAL(error) << error_log; show_error(nullptr, error_log); break; @@ -17065,9 +17046,7 @@ bool Plater::preview_zip_archive(const boost::filesystem::path& archive_path) file.write(buffer.c_str(), buffer.size()); file.close(); if (!fs::exists(final_path)) { - wxString error_log = - GUI::format_wxstr(_L("Failed to find unzipped file at %1%. Unzipping of file has failed."), - final_path.string()); + wxString error_log = GUI::format_wxstr(_L("Failed to find unzipped file at %1%. Unzipping of file has failed."), final_path.string()); BOOST_LOG_TRIVIAL(error) << error_log; show_error(nullptr, error_log); break; @@ -17086,7 +17065,9 @@ bool Plater::preview_zip_archive(const boost::filesystem::path& archive_path) project_paths.emplace_back(final_path); break; - } catch (const std::exception& e) { + } + catch (const std::exception& e) + { // ensure the zip archive is closed and rethrow the exception close_zip_reader(&archive); throw Slic3r::FileIOError(e.what()); @@ -17096,25 +17077,30 @@ bool Plater::preview_zip_archive(const boost::filesystem::path& archive_path) } close_zip_reader(&archive); if (non_project_paths.size() + project_paths.size() != selected_paths.size()) - BOOST_LOG_TRIVIAL(error) << "Decompresing of archive did not retrieve all files. Expected files: " << selected_paths.size() - << " Decopressed files: " << non_project_paths.size() + project_paths.size(); + BOOST_LOG_TRIVIAL(error) << "Decompresing of archive did not retrieve all files. Expected files: " + << selected_paths.size() + << " Decopressed files: " + << non_project_paths.size() + project_paths.size(); } else { close_zip_reader(&archive); return false; } - } catch (const Slic3r::FileIOError& e) { + } + catch (const Slic3r::FileIOError& e) { // zip reader should be already closed or not even opened GUI::show_error(this, e.what()); return false; } // none selected - if (project_paths.empty() && non_project_paths.empty()) { + if (project_paths.empty() && non_project_paths.empty()) + { return false; } // 1 project file and some models - behave like drag n drop of 3mf and then load models - if (project_paths.size() == 1) { + if (project_paths.size() == 1) + { wxArrayString aux; aux.Add(from_u8(project_paths.front().string())); bool loaded3mf = load_files(aux); @@ -17139,6 +17125,7 @@ bool Plater::preview_zip_archive(const boost::filesystem::path& archive_path) load_files(project_paths, LoadStrategy::LoadModel); load_files(non_project_paths, LoadStrategy::LoadModel); + for (const fs::path& path : project_paths) { // Delete file from temp file (path variable), it will stay only in app memory. boost::system::error_code ec; @@ -17162,32 +17149,32 @@ bool Plater::preview_zip_archive(const boost::filesystem::path& archive_path) class ProjectDropDialog : public DPIDialog { private: - wxColour m_def_color = wxColour(255, 255, 255); - int m_action{1}; - bool m_remember_choice{false}; + wxColour m_def_color = wxColour(255, 255, 255); + int m_action{1}; + bool m_remember_choice{false}; public: - ProjectDropDialog(const std::string& filename); + ProjectDropDialog(const std::string &filename); - wxPanel* m_top_line; - wxStaticText* m_fname_title; - wxStaticText* m_fname_f; - StaticBox* m_panel_select; + wxPanel * m_top_line; + wxStaticText *m_fname_title; + wxStaticText *m_fname_f; + StaticBox * m_panel_select; - void on_select_ok(wxCommandEvent& event); - void on_select_cancel(wxCommandEvent& event); + void on_select_ok(wxCommandEvent &event); + void on_select_cancel(wxCommandEvent &event); - int get_action() const { return m_action; } - void set_action(int index) { m_action = index; } + int get_action() const { return m_action; } + void set_action(int index) { m_action = index; } - wxBoxSizer* create_remember_checkbox(wxString title, wxWindow* parent, wxString tooltip); + wxBoxSizer *create_remember_checkbox(wxString title, wxWindow* parent, wxString tooltip); protected: - void on_dpi_changed(const wxRect& suggested_rect) override; + void on_dpi_changed(const wxRect &suggested_rect) override; }; -ProjectDropDialog::ProjectDropDialog(const std::string& filename) - : DPIDialog(static_cast(wxGetApp().mainframe), +ProjectDropDialog::ProjectDropDialog(const std::string &filename) + : DPIDialog(static_cast(wxGetApp().mainframe), wxID_ANY, from_u8((boost::format(_utf8(L("Drop project file")))).str()), wxDefaultPosition, @@ -17198,7 +17185,7 @@ ProjectDropDialog::ProjectDropDialog(const std::string& filename) // def setting SetBackgroundColour(m_def_color); - wxBoxSizer* m_sizer_main = new wxBoxSizer(wxVERTICAL); + wxBoxSizer *m_sizer_main = new wxBoxSizer(wxVERTICAL); m_top_line = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); m_top_line->SetBackgroundColour(wxColour(166, 169, 170)); @@ -17214,25 +17201,24 @@ ProjectDropDialog::ProjectDropDialog(const std::string& filename) m_fname_f = new wxStaticText(this, wxID_ANY, filename); m_fname_f->SetFont(::Label::Head_14); - m_fname_f->SetMaxSize(wxSize(FromDIP(300), -1)); + m_fname_f->SetMaxSize(wxSize(FromDIP(300),-1)); m_fname_f->Wrap(FromDIP(300)); m_fname_f->SetForegroundColour(wxColour("#363636")); m_sizer_main->Add(m_fname_title, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(20)); m_sizer_main->AddSpacer(FromDIP(10)); - m_sizer_main->Add(m_fname_f, 1, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(20)); + m_sizer_main->Add(m_fname_f , 1, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(20)); m_sizer_main->AddSpacer(FromDIP(10)); - auto radio_group = new RadioGroup(this, - { - _L("Open as project"), // 0 - _L("Import geometry only") // 1 - }, - wxVERTICAL); - radio_group->SetMinSize(wxSize(FromDIP(300), -1)); + auto radio_group = new RadioGroup(this, { + _L("Open as project"), // 0 + _L("Import geometry only") // 1 + }, wxVERTICAL); + radio_group->SetMinSize(wxSize(FromDIP(300),-1)); radio_group->SetSelection(get_action() - 1); - radio_group->Bind(wxEVT_COMMAND_RADIOBOX_SELECTED, - [this, radio_group](wxCommandEvent& e) { set_action(radio_group->GetSelection() + 1); }); + radio_group->Bind(wxEVT_COMMAND_RADIOBOX_SELECTED, [this, radio_group](wxCommandEvent &e) { + set_action(radio_group->GetSelection() + 1); + }); m_sizer_main->Add(radio_group, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(20)); @@ -17242,8 +17228,8 @@ ProjectDropDialog::ProjectDropDialog(const std::string& filename) // Orca: hide the "Don't show again" checkbox, people keeps accidentally checked this then forgot // wxBoxSizer *m_sizer_left = new wxBoxSizer(wxHORIZONTAL); // - // auto dont_show_again = create_remember_checkbox(_L("Remember my choice."), this, _L("This option can be changed later in preferences, - // under 'Load Behaviour'.")); m_sizer_left->Add(dont_show_again, 0, wxALL, 5); + // auto dont_show_again = create_remember_checkbox(_L("Remember my choice."), this, _L("This option can be changed later in preferences, under 'Load Behaviour'.")); + // m_sizer_left->Add(dont_show_again, 0, wxALL, 5); // // m_sizer_bottom->Add(m_sizer_left, 0, wxEXPAND, 5); @@ -17263,9 +17249,9 @@ ProjectDropDialog::ProjectDropDialog(const std::string& filename) wxGetApp().UpdateDlgDarkUI(this); } -wxBoxSizer* ProjectDropDialog::create_remember_checkbox(wxString title, wxWindow* parent, wxString tooltip) +wxBoxSizer *ProjectDropDialog::create_remember_checkbox(wxString title, wxWindow *parent, wxString tooltip) { - wxBoxSizer* m_sizer_checkbox = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *m_sizer_checkbox = new wxBoxSizer(wxHORIZONTAL); m_sizer_checkbox->Add(0, 0, 0, wxEXPAND | wxLEFT, 5); auto checkbox = new ::CheckBox(parent); @@ -17275,13 +17261,13 @@ wxBoxSizer* ProjectDropDialog::create_remember_checkbox(wxString title, wxWindow m_sizer_checkbox->Add(0, 0, 0, wxEXPAND | wxLEFT, 8); auto checkbox_title = new wxStaticText(parent, wxID_ANY, title, wxDefaultPosition, wxSize(-1, -1), 0); - checkbox_title->SetForegroundColour(wxColour(144, 144, 144)); + checkbox_title->SetForegroundColour(wxColour(144,144,144)); checkbox_title->SetFont(::Label::Body_13); checkbox_title->Wrap(-1); checkbox_title->SetToolTip(tooltip); m_sizer_checkbox->Add(checkbox_title, 0, wxALIGN_CENTER | wxALL, 3); - checkbox->Bind(wxEVT_TOGGLEBUTTON, [this, checkbox](wxCommandEvent& e) { + checkbox->Bind(wxEVT_TOGGLEBUTTON, [this, checkbox](wxCommandEvent &e) { m_remember_choice = checkbox->GetValue(); e.Skip(); }); @@ -17289,24 +17275,28 @@ wxBoxSizer* ProjectDropDialog::create_remember_checkbox(wxString title, wxWindow return m_sizer_checkbox; } -void ProjectDropDialog::on_select_ok(wxCommandEvent& event) +void ProjectDropDialog::on_select_ok(wxCommandEvent &event) { if (m_remember_choice) { LoadType load_type = static_cast(get_action()); - switch (load_type) { - case LoadType::OpenProject: - wxGetApp().app_config->set(SETTING_PROJECT_LOAD_BEHAVIOUR, OPTION_PROJECT_LOAD_BEHAVIOUR_LOAD_ALL); - break; - case LoadType::LoadGeometry: - wxGetApp().app_config->set(SETTING_PROJECT_LOAD_BEHAVIOUR, OPTION_PROJECT_LOAD_BEHAVIOUR_LOAD_GEOMETRY); - break; + switch (load_type) + { + case LoadType::OpenProject: + wxGetApp().app_config->set(SETTING_PROJECT_LOAD_BEHAVIOUR, OPTION_PROJECT_LOAD_BEHAVIOUR_LOAD_ALL); + break; + case LoadType::LoadGeometry: + wxGetApp().app_config->set(SETTING_PROJECT_LOAD_BEHAVIOUR, OPTION_PROJECT_LOAD_BEHAVIOUR_LOAD_GEOMETRY); + break; } } EndModal(wxID_OK); } -void ProjectDropDialog::on_select_cancel(wxCommandEvent& event) { EndModal(wxID_CANCEL); } +void ProjectDropDialog::on_select_cancel(wxCommandEvent &event) +{ + EndModal(wxID_CANCEL); +} void ProjectDropDialog::on_dpi_changed(const wxRect& suggested_rect) { @@ -17314,7 +17304,7 @@ void ProjectDropDialog::on_dpi_changed(const wxRect& suggested_rect) Refresh(); } -// BBS: remove GCodeViewer as seperate APP logic +//BBS: remove GCodeViewer as seperate APP logic bool Plater::load_files(const wxArrayString& filenames) { const std::regex pattern_drop(".*[.](stp|step|stl|oltp|obj|amf|3mf|svg|zip|drc)", std::regex::icase); @@ -17333,14 +17323,14 @@ bool Plater::load_files(const wxArrayString& filenames) continue; } - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": normal_paths %1%, gcode_paths %2%") % normal_paths.size() % gcode_paths.size(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": normal_paths %1%, gcode_paths %2%")%normal_paths.size() %gcode_paths.size(); if (normal_paths.empty() && gcode_paths.empty()) { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(": can not find valid path, return directly"); // Likely no supported files return false; - } else if (normal_paths.empty()) { - // only gcode files + } + else if (normal_paths.empty()){ + //only gcode files if (gcode_paths.size() > 1) { show_info(this, _L("Only one G-code file can be opened at a time."), _L("G-code loading")); return false; @@ -17355,12 +17345,12 @@ bool Plater::load_files(const wxArrayString& filenames) } //// searches for project files - // for (std::vector::const_reverse_iterator it = normal_paths.rbegin(); it != normal_paths.rend(); ++it) { - // std::string filename = (*it).filename().string(); - // ////BBS: only 3mf will be treated as project file - // if (open_3mf_file((*it))) - // return true; - // } + //for (std::vector::const_reverse_iterator it = normal_paths.rbegin(); it != normal_paths.rend(); ++it) { + // std::string filename = (*it).filename().string(); + // ////BBS: only 3mf will be treated as project file + // if (open_3mf_file((*it))) + // return true; + //} //// other files std::string snapshot_label; @@ -17379,31 +17369,20 @@ bool Plater::load_files(const wxArrayString& filenames) } } - // Plater::TakeSnapshot snapshot(this, snapshot_label); - // load_files(normal_paths, LoadStrategy::LoadModel); + //Plater::TakeSnapshot snapshot(this, snapshot_label); + //load_files(normal_paths, LoadStrategy::LoadModel); // BBS: check file types - std::sort(normal_paths.begin(), normal_paths.end(), - [](fs::path obj1, fs::path obj2) { return obj1.filename().string() < obj2.filename().string(); }); + std::sort(normal_paths.begin(), normal_paths.end(), [](fs::path obj1, fs::path obj2) { return obj1.filename().string() < obj2.filename().string(); }); auto loadfiles_type = LoadFilesType::NoFile; auto amf_files_count = get_3mf_file_count(normal_paths); - if (normal_paths.size() > 1 && amf_files_count < normal_paths.size()) { - loadfiles_type = LoadFilesType::Multiple3MFOther; - } - if (normal_paths.size() > 1 && amf_files_count == normal_paths.size()) { - loadfiles_type = LoadFilesType::Multiple3MF; - } - if (normal_paths.size() > 1 && amf_files_count == 0) { - loadfiles_type = LoadFilesType::MultipleOther; - } - if (normal_paths.size() == 1 && amf_files_count == 1) { - loadfiles_type = LoadFilesType::Single3MF; - }; - if (normal_paths.size() == 1 && amf_files_count == 0) { - loadfiles_type = LoadFilesType::SingleOther; - }; + if (normal_paths.size() > 1 && amf_files_count < normal_paths.size()) { loadfiles_type = LoadFilesType::Multiple3MFOther; } + if (normal_paths.size() > 1 && amf_files_count == normal_paths.size()) { loadfiles_type = LoadFilesType::Multiple3MF; } + if (normal_paths.size() > 1 && amf_files_count == 0) { loadfiles_type = LoadFilesType::MultipleOther; } + if (normal_paths.size() == 1 && amf_files_count == 1) { loadfiles_type = LoadFilesType::Single3MF; }; + if (normal_paths.size() == 1 && amf_files_count == 0) { loadfiles_type = LoadFilesType::SingleOther; }; auto first_file = std::vector{}; auto tmf_file = std::vector{}; @@ -17411,7 +17390,8 @@ bool Plater::load_files(const wxArrayString& filenames) auto res = true; if (this->m_only_gcode || this->m_exported_file) { - if ((loadfiles_type == LoadFilesType::SingleOther) || (loadfiles_type == LoadFilesType::MultipleOther)) { + if ((loadfiles_type == LoadFilesType::SingleOther) + || (loadfiles_type == LoadFilesType::MultipleOther)) { show_info(this, _L("Unable to add models in preview mode"), _L("Add Models")); return false; } @@ -17433,46 +17413,38 @@ bool Plater::load_files(const wxArrayString& filenames) }; switch (loadfiles_type) { - case LoadFilesType::Single3MF: open_3mf_file(normal_paths[0]); break; + case LoadFilesType::Single3MF: + open_3mf_file(normal_paths[0]); + break; case LoadFilesType::SingleOther: { Plater::TakeSnapshot snapshot(this, snapshot_label); - if (handle_zips(normal_paths)) - return true; - if (load_files(normal_paths, LoadStrategy::LoadModel, false).empty()) { - res = false; - } + if (handle_zips(normal_paths)) return true; + if (load_files(normal_paths, LoadStrategy::LoadModel, false).empty()) { res = false; } break; } case LoadFilesType::Multiple3MF: first_file = std::vector{normal_paths[0]}; for (auto i = 0; i < normal_paths.size(); i++) { - if (i > 0) { - other_file.push_back(normal_paths[i]); - } + if (i > 0) { other_file.push_back(normal_paths[i]); } }; open_3mf_file(first_file[0]); - if (load_files(other_file, LoadStrategy::LoadModel).empty()) { - res = false; - } + if (load_files(other_file, LoadStrategy::LoadModel).empty()) { res = false; } break; case LoadFilesType::MultipleOther: { Plater::TakeSnapshot snapshot(this, snapshot_label); if (handle_zips(normal_paths)) { - if (normal_paths.empty()) - return true; - } - if (load_files(normal_paths, LoadStrategy::LoadModel, true).empty()) { - res = false; + if (normal_paths.empty()) return true; } + if (load_files(normal_paths, LoadStrategy::LoadModel, true).empty()) { res = false; } break; } case LoadFilesType::Multiple3MFOther: - for (const auto& path : normal_paths) { - if (boost::iends_with(path.filename().string(), ".3mf")) { + for (const auto &path : normal_paths) { + if (boost::iends_with(path.filename().string(), ".3mf")){ if (first_file.size() <= 0) first_file.push_back(path); else @@ -17483,16 +17455,11 @@ bool Plater::load_files(const wxArrayString& filenames) } open_3mf_file(first_file[0]); - if (load_files(tmf_file, LoadStrategy::LoadModel).empty()) { - res = false; - } + if (load_files(tmf_file, LoadStrategy::LoadModel).empty()) { res = false; } if (res && handle_zips(other_file)) { - if (normal_paths.empty()) - return true; - } - if (load_files(other_file, LoadStrategy::LoadModel, false).empty()) { - res = false; + if (normal_paths.empty()) return true; } + if (load_files(other_file, LoadStrategy::LoadModel, false).empty()) { res = false; } break; default: break; } @@ -17515,7 +17482,7 @@ LoadType determine_load_type(std::string filename, std::string override_setting) } else if (setting == OPTION_PROJECT_LOAD_BEHAVIOUR_ALWAYS_ASK) { ProjectDropDialog dlg(filename); if (dlg.ShowModal() == wxID_OK) { - int choice = dlg.get_action(); + int choice = dlg.get_action(); LoadType load_type = static_cast(choice); wxGetApp().app_config->set("import_project_action", std::to_string(choice)); @@ -17530,42 +17497,38 @@ LoadType determine_load_type(std::string filename, std::string override_setting) } } -bool Plater::open_3mf_file(const fs::path& file_path) +bool Plater::open_3mf_file(const fs::path &file_path) { std::string filename = encode_path(file_path.filename().string().c_str()); if (!boost::algorithm::iends_with(filename, ".3mf")) { return false; } - bool not_empty_plate = !model().objects.empty(); - bool load_setting_ask_when_relevant = wxGetApp().app_config->get(SETTING_PROJECT_LOAD_BEHAVIOUR) == - OPTION_PROJECT_LOAD_BEHAVIOUR_ASK_WHEN_RELEVANT; - LoadType load_type = determine_load_type(filename, (not_empty_plate && load_setting_ask_when_relevant) ? - OPTION_PROJECT_LOAD_BEHAVIOUR_ALWAYS_ASK : - ""); + bool not_empty_plate = !model().objects.empty(); + bool load_setting_ask_when_relevant = wxGetApp().app_config->get(SETTING_PROJECT_LOAD_BEHAVIOUR) == OPTION_PROJECT_LOAD_BEHAVIOUR_ASK_WHEN_RELEVANT; + LoadType load_type = determine_load_type(filename, (not_empty_plate && load_setting_ask_when_relevant) ? OPTION_PROJECT_LOAD_BEHAVIOUR_ALWAYS_ASK : ""); - if (load_type == LoadType::Unknown) - return false; + if (load_type == LoadType::Unknown) return false; switch (load_type) { - case LoadType::OpenProject: { - if (wxGetApp().can_load_project()) - load_project(from_path(file_path), ""); - break; - } - case LoadType::LoadGeometry: { - Plater::TakeSnapshot snapshot(this, "Import Object"); - load_files({file_path}, LoadStrategy::LoadModel); - break; - } - case LoadType::LoadConfig: { - load_files({file_path}, LoadStrategy::LoadConfig); - break; - } - case LoadType::Unknown: { - assert(false); - break; - } + case LoadType::OpenProject: { + if (wxGetApp().can_load_project()) + load_project(from_path(file_path), ""); + break; + } + case LoadType::LoadGeometry: { + Plater::TakeSnapshot snapshot(this, "Import Object"); + load_files({file_path}, LoadStrategy::LoadModel); + break; + } + case LoadType::LoadConfig: { + load_files({file_path}, LoadStrategy::LoadConfig); + break; + } + case LoadType::Unknown: { + assert(false); + break; + } } return true; @@ -17574,7 +17537,7 @@ bool Plater::open_3mf_file(const fs::path& file_path) int Plater::get_3mf_file_count(std::vector paths) { auto count = 0; - for (const auto& path : paths) { + for (const auto &path : paths) { if (boost::iends_with(path.filename().string(), ".3mf")) { count++; } @@ -17587,12 +17550,10 @@ void Plater::add_file() BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " entry"; wxArrayString input_files; wxGetApp().import_model(this, input_files); - if (input_files.empty()) - return; + if (input_files.empty()) return; std::vector paths; - for (const auto& file : input_files) - paths.emplace_back(into_path(file)); + for (const auto &file : input_files) paths.emplace_back(into_path(file)); std::string snapshot_label; assert(!paths.empty()); @@ -17609,28 +17570,21 @@ void Plater::add_file() auto loadfiles_type = LoadFilesType::NoFile; auto amf_files_count = get_3mf_file_count(paths); - if (paths.size() > 1 && amf_files_count < paths.size()) { - loadfiles_type = LoadFilesType::Multiple3MFOther; - } - if (paths.size() > 1 && amf_files_count == paths.size()) { - loadfiles_type = LoadFilesType::Multiple3MF; - } - if (paths.size() > 1 && amf_files_count == 0) { - loadfiles_type = LoadFilesType::MultipleOther; - } - if (paths.size() == 1 && amf_files_count == 1) { - loadfiles_type = LoadFilesType::Single3MF; - }; - if (paths.size() == 1 && amf_files_count == 0) { - loadfiles_type = LoadFilesType::SingleOther; - }; + if (paths.size() > 1 && amf_files_count < paths.size()) { loadfiles_type = LoadFilesType::Multiple3MFOther; } + if (paths.size() > 1 && amf_files_count == paths.size()) { loadfiles_type = LoadFilesType::Multiple3MF; } + if (paths.size() > 1 && amf_files_count == 0) { loadfiles_type = LoadFilesType::MultipleOther; } + if (paths.size() == 1 && amf_files_count == 1) { loadfiles_type = LoadFilesType::Single3MF; }; + if (paths.size() == 1 && amf_files_count == 0) { loadfiles_type = LoadFilesType::SingleOther; }; auto first_file = std::vector{}; auto tmf_file = std::vector{}; auto other_file = std::vector{}; - switch (loadfiles_type) { - case LoadFilesType::Single3MF: open_3mf_file(paths[0]); break; + switch (loadfiles_type) + { + case LoadFilesType::Single3MF: + open_3mf_file(paths[0]); + break; case LoadFilesType::SingleOther: { Plater::TakeSnapshot snapshot(this, snapshot_label); @@ -17648,15 +17602,11 @@ void Plater::add_file() case LoadFilesType::Multiple3MF: first_file = std::vector{paths[0]}; for (auto i = 0; i < paths.size(); i++) { - if (i > 0) { - other_file.push_back(paths[i]); - } + if (i > 0) { other_file.push_back(paths[i]); } }; open_3mf_file(first_file[0]); - if (!load_files(other_file, LoadStrategy::LoadModel).empty()) { - wxGetApp().mainframe->update_title(); - } + if (!load_files(other_file, LoadStrategy::LoadModel).empty()) { wxGetApp().mainframe->update_title(); } break; case LoadFilesType::MultipleOther: { @@ -17668,13 +17618,13 @@ void Plater::add_file() } wxGetApp().mainframe->update_title(); if (wxGetApp().app_config->get("recent_models") == "true") - for (auto& path : paths) + for (auto &path : paths) wxGetApp().mainframe->add_to_recent_projects(path.wstring()); } break; } case LoadFilesType::Multiple3MFOther: - for (const auto& path : paths) { + for (const auto &path : paths) { if (boost::iends_with(path.filename().string(), ".3mf")) { if (first_file.size() <= 0) first_file.push_back(path); @@ -17690,11 +17640,11 @@ void Plater::add_file() if (!load_files(other_file, LoadStrategy::LoadModel, false).empty()) { wxGetApp().mainframe->update_title(); if (wxGetApp().app_config->get("recent_models") == "true") - for (auto& file : other_file) + for (auto &file : other_file) wxGetApp().mainframe->add_to_recent_projects(file.wstring()); } break; - default: break; + default:break; } } @@ -17703,31 +17653,33 @@ void Plater::update(bool conside_update_flag, bool force_background_processing_u if (is_new_project_and_check_state()) { return; } - unsigned int flag = force_background_processing_update ? (unsigned int) Plater::priv::UpdateParams::FORCE_BACKGROUND_PROCESSING_UPDATE : - 0; + unsigned int flag = force_background_processing_update ? (unsigned int)Plater::priv::UpdateParams::FORCE_BACKGROUND_PROCESSING_UPDATE : 0; if (conside_update_flag) { if (need_update()) { p->update(flag); p->set_need_update(false); } - } else + } + else p->update(flag); } void Plater::object_list_changed() { p->object_list_changed(); } -Worker& Plater::get_ui_job_worker() { return p->m_worker; } +Worker &Plater::get_ui_job_worker() { return p->m_worker; } -const Worker& Plater::get_ui_job_worker() const { return p->m_worker; } +const Worker &Plater::get_ui_job_worker() const { return p->m_worker; } void Plater::update_ui_from_settings() { p->update_ui_from_settings(); } void Plater::select_view(const std::string& direction) { p->select_view(direction); } -// BBS: add no_slice logic +//BBS: add no_slice logic void Plater::select_view_3D(const std::string& name, bool no_slice) { p->select_view_3D(name, no_slice); } -void Plater::reload_paint_after_background_process_apply() { p->preview->set_reload_paint_after_background_process_apply(true); } +void Plater::reload_paint_after_background_process_apply() { + p->preview->set_reload_paint_after_background_process_apply(true); +} bool Plater::is_preview_shown() const { return p->is_preview_shown(); } bool Plater::is_preview_loaded() const { return p->is_preview_loaded(); } @@ -17737,7 +17689,7 @@ bool Plater::are_view3D_labels_shown() const { return p->are_view3D_labels_shown void Plater::show_view3D_labels(bool show) { p->show_view3D_labels(show); } bool Plater::is_view3D_overhang_shown() const { return p->is_view3D_overhang_shown(); } -void Plater::show_view3D_overhang(bool show) { p->show_view3D_overhang(show); } +void Plater::show_view3D_overhang(bool show) { p->show_view3D_overhang(show); } bool Plater::is_sidebar_enabled() const { return p->sidebar_layout.is_enabled; } void Plater::enable_sidebar(bool enabled) { p->enable_sidebar(enabled); } @@ -17747,7 +17699,7 @@ Sidebar::DockingState Plater::get_sidebar_docking_state() const { return p->get_ void Plater::reset_window_layout() { p->reset_window_layout(); } -// BBS +//BBS void Plater::select_curr_plate_all() { p->select_curr_plate_all(); } void Plater::remove_curr_plate_all() { p->remove_curr_plate_all(); } @@ -17759,10 +17711,9 @@ void Plater::remove(size_t obj_idx) { p->remove(obj_idx); } void Plater::reset(bool apply_presets_change) { p->reset(apply_presets_change); } void Plater::reset_with_confirm() { - if (p->model.objects.empty() || - MessageDialog(static_cast(this), _L("All objects will be removed, continue?"), - wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Delete All"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE) - .ShowModal() == wxID_YES) { + if (p->model.objects.empty() || MessageDialog(static_cast(this), _L("All objects will be removed, continue?"), + wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Delete All"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE) + .ShowModal() == wxID_YES) { reset(); // BBS: jump to plater panel wxGetApp().mainframe->select_tab(TAB_ID_HOME); @@ -17773,15 +17724,13 @@ void Plater::reset_with_confirm() int GUI::Plater::close_with_confirm(std::function second_check) { if (up_to_date(false, false)) { - if (second_check && !second_check(false)) - return wxID_CANCEL; + if (second_check && !second_check(false)) return wxID_CANCEL; model().set_backup_path(""); return wxID_NO; } - MessageDialog dlg(static_cast(this), - _L("The current project has unsaved changes. Would you like to save before continuing\?"), - wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Save"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE); + MessageDialog dlg(static_cast(this), _L("The current project has unsaved changes. Would you like to save before continuing\?"), + wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Save"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE); dlg.show_dsa_button(_L("Remember my choice.")); auto choise = wxGetApp().app_config->get("save_project_choise"); auto result = choise.empty() ? dlg.ShowModal() : choise == "yes" ? wxID_YES : wxID_NO; @@ -17801,8 +17750,7 @@ int GUI::Plater::close_with_confirm(std::function second_check) } } - if (second_check && !second_check(result == wxID_YES)) - return wxID_CANCEL; + if (second_check && !second_check(result == wxID_YES)) return wxID_CANCEL; model().set_backup_path(""); up_to_date(true, false); @@ -17811,21 +17759,23 @@ int GUI::Plater::close_with_confirm(std::function second_check) return result; } -// BBS: trigger a restore project event +//BBS: trigger a restore project event void Plater::trigger_restore_project(int skip_confirm) { auto evt = new wxCommandEvent(EVT_RESTORE_PROJECT, this->GetId()); evt->SetInt(skip_confirm); wxQueueEvent(this, evt); - // wxPostEvent(this, *evt); + //wxPostEvent(this, *evt); } -// BBS -bool Plater::delete_object_from_model(size_t obj_idx, bool refresh_immediately) -{ return p->delete_object_from_model(obj_idx, refresh_immediately); } +//BBS +bool Plater::delete_object_from_model(size_t obj_idx, bool refresh_immediately) { return p->delete_object_from_model(obj_idx, refresh_immediately); } -// BBS: delete all from model -void Plater::delete_all_objects_from_model() { p->delete_all_objects_from_model(); } +//BBS: delete all from model +void Plater::delete_all_objects_from_model() +{ + p->delete_all_objects_from_model(); +} void Plater::set_selected_visible(bool visible) { @@ -17838,6 +17788,7 @@ void Plater::set_selected_visible(bool visible) p->get_current_canvas3D()->set_selected_visible(visible); } + void Plater::remove_selected() { /*if (p->get_selection().is_empty()) @@ -17852,33 +17803,30 @@ void Plater::remove_selected() Plater::TakeSnapshot snapshot(this, "Delete Selected Objects"); get_ui_job_worker().cancel_all(); - // BBS delete current selected - // p->view3D->delete_selected(); + //BBS delete current selected + // p->view3D->delete_selected(); p->get_current_canvas3D()->delete_selected(); } void Plater::increase_instances(size_t num) { - if (!can_increase_instances()) { - return; - } + if (! can_increase_instances()) { return; } Plater::TakeSnapshot snapshot(this, "Increase Instances"); int obj_idx = p->get_selected_object_idx(); - ModelObject* model_object = p->model.objects[obj_idx]; + ModelObject* model_object = p->model.objects[obj_idx]; ModelInstance* model_instance = model_object->instances.back(); - bool was_one_instance = model_object->instances.size() == 1; + bool was_one_instance = model_object->instances.size()==1; double offset_base = canvas3D()->get_size_proportional_to_max_bed_size(0.05); - double offset = offset_base; + double offset = offset_base; for (size_t i = 0; i < num; i++, offset += offset_base) { Vec3d offset_vec = model_instance->get_offset() + Vec3d(offset, offset, 0.0); - model_object->add_instance(offset_vec, model_instance->get_scaling_factor(), model_instance->get_rotation(), - model_instance->get_mirror()); - // p->print.get_object(obj_idx)->add_copy(Slic3r::to_2d(offset_vec)); + model_object->add_instance(offset_vec, model_instance->get_scaling_factor(), model_instance->get_rotation(), model_instance->get_mirror()); +// p->print.get_object(obj_idx)->add_copy(Slic3r::to_2d(offset_vec)); } #ifdef SUPPORT_AUTO_CENTER @@ -17888,23 +17836,21 @@ void Plater::increase_instances(size_t num) p->update(); - p->get_selection().add_instance(obj_idx, (int) model_object->instances.size() - 1); + p->get_selection().add_instance(obj_idx, (int)model_object->instances.size() - 1); sidebar().obj_list()->increase_object_instances(obj_idx, was_one_instance ? num + 1 : num); p->selection_changed(); this->p->schedule_background_process(); - // if (wxGetApp().app_config->get("auto_arrange") == "true") { - // this->set_prepare_state(Job::PREPARE_STATE_MENU); - // this->arrange(); - // } + //if (wxGetApp().app_config->get("auto_arrange") == "true") { + // this->set_prepare_state(Job::PREPARE_STATE_MENU); + // this->arrange(); + //} } void Plater::decrease_instances(size_t num) { - if (!can_decrease_instances()) { - return; - } + if (! can_decrease_instances()) { return; } Plater::TakeSnapshot snapshot(this, "Decrease Instances"); @@ -17912,28 +17858,34 @@ void Plater::decrease_instances(size_t num) ModelObject* model_object = p->model.objects[obj_idx]; if (model_object->instances.size() > num) { - for (size_t i = 0; i < num; ++i) + for (size_t i = 0; i < num; ++ i) model_object->delete_last_instance(); p->update(); // Delete object from Sidebar list. Do it after update, so that the GLScene selection is updated with the modified model. sidebar().obj_list()->decrease_object_instances(obj_idx, num); - } else { + } + else { remove(obj_idx); } if (!model_object->instances.empty()) - p->get_selection().add_instance(obj_idx, (int) model_object->instances.size() - 1); + p->get_selection().add_instance(obj_idx, (int)model_object->instances.size() - 1); p->selection_changed(); this->p->schedule_background_process(); - // if (wxGetApp().app_config->get("auto_arrange") == "true") { - // this->set_prepare_state(Job::PREPARE_STATE_MENU); - // this->arrange(); - // } + //if (wxGetApp().app_config->get("auto_arrange") == "true") { + // this->set_prepare_state(Job::PREPARE_STATE_MENU); + // this->arrange(); + //} } -static long GetNumberFromUser( - const wxString& msg, const wxString& prompt, const wxString& title, long value, long min, long max, wxWindow* parent) +static long GetNumberFromUser( const wxString& msg, + const wxString& prompt, + const wxString& title, + long value, + long min, + long max, + wxWindow* parent) { #ifdef _WIN32 wxNumberEntryDialog dialog(parent, msg, prompt, title, value, min, max, wxDefaultPosition); @@ -17955,14 +17907,14 @@ void Plater::set_number_of_copies(/*size_t num*/) ModelObject* model_object = p->model.objects[obj_idx]; - const int num = GetNumberFromUser(" ", _L("Number of copies:"), _L("Copies of the selected object"), model_object->instances.size(), 0, - 1000, this); + const int num = GetNumberFromUser( " ", _L("Number of copies:"), + _L("Copies of the selected object"), model_object->instances.size(), 0, 1000, this ); if (num < 0) return; - Plater::TakeSnapshot snapshot(this, (boost::format("Set numbers of copies to %1%") % num).str()); + Plater::TakeSnapshot snapshot(this, (boost::format("Set numbers of copies to %1%")%num).str()); - int diff = num - (int) model_object->instances.size(); + int diff = num - (int)model_object->instances.size(); if (diff > 0) increase_instances(diff); else if (diff < 0) @@ -17971,7 +17923,7 @@ void Plater::set_number_of_copies(/*size_t num*/) void Plater::fill_bed_with_copies() { - auto& w = get_ui_job_worker(); + auto &w = get_ui_job_worker(); if (w.is_idle()) { p->take_snapshot(_u8L("Arrange")); replace_job(w, std::make_unique()); @@ -17980,16 +17932,22 @@ void Plater::fill_bed_with_copies() void Plater::fill_bed_with_instances() { - auto& w = get_ui_job_worker(); + auto &w = get_ui_job_worker(); if (w.is_idle()) { p->take_snapshot(_u8L("Arrange")); replace_job(w, std::make_unique(true)); } } -bool Plater::is_selection_empty() const { return p->get_selection().is_empty() || p->get_selection().is_wipe_tower(); } +bool Plater::is_selection_empty() const +{ + return p->get_selection().is_empty() || p->get_selection().is_wipe_tower(); +} -void Plater::scale_selection_to_fit_print_volume() { p->scale_selection_to_fit_print_volume(); } +void Plater::scale_selection_to_fit_print_volume() +{ + p->scale_selection_to_fit_print_volume(); +} void Plater::convert_unit(ConversionType conv_type) { @@ -18000,14 +17958,13 @@ void Plater::convert_unit(ConversionType conv_type) TakeSnapshot snapshot(this, conv_type == ConversionType::CONV_FROM_INCH ? "Convert from imperial units" : conv_type == ConversionType::CONV_TO_INCH ? "Revert conversion from imperial units" : - conv_type == ConversionType::CONV_FROM_METER ? "Convert from meters" : - "Revert conversion from meters"); + conv_type == ConversionType::CONV_FROM_METER ? "Convert from meters" : "Revert conversion from meters"); wxBusyCursor wait; ModelObjectPtrs objects; std::reverse(obj_idxs.begin(), obj_idxs.end()); for (int obj_idx : obj_idxs) { - ModelObject* object = p->model.objects[obj_idx]; + ModelObject *object = p->model.objects[obj_idx]; object->convert_units(objects, conv_type, volume_idxs); remove(obj_idx); } @@ -18015,12 +17972,13 @@ void Plater::convert_unit(ConversionType conv_type) p->load_model_objects(objects); Selection& selection = p->view3D->get_canvas3d()->get_selection(); - size_t last_obj_idx = p->model.objects.size() - 1; + size_t last_obj_idx = p->model.objects.size() - 1; if (volume_idxs.empty()) { for (size_t i = 0; i < objects.size(); ++i) - selection.add_object((unsigned int) (last_obj_idx - i), i == 0); - } else { + selection.add_object((unsigned int)(last_obj_idx - i), i == 0); + } + else { for (int vol_idx : volume_idxs) selection.add_volume(last_obj_idx, vol_idx, 0, false); } @@ -18042,9 +18000,9 @@ void Plater::apply_cut_object_to_model(size_t obj_idx, const ModelObjectPtrs& ne wxGetApp().obj_list()->update_info_items(idx); Selection& selection = p->get_selection(); - size_t last_id = p->model.objects.size() - 1; + size_t last_id = p->model.objects.size() - 1; for (size_t i = 0; i < new_objects.size(); ++i) - selection.add_object((unsigned int) (last_id - i), i == 0); + selection.add_object((unsigned int)(last_id - i), i == 0); // UIThreadWorker w; // arrange(w, true); @@ -18056,8 +18014,8 @@ void Plater::export_gcode(bool prefer_removable) if (p->model.objects.empty()) return; - // if (get_view3D_canvas3D()->get_gizmos_manager().is_in_editing_mode(true)) - // return; + //if (get_view3D_canvas3D()->get_gizmos_manager().is_in_editing_mode(true)) + // return; if (p->process_completed_with_error == p->partplate_list.get_curr_plate_index()) return; @@ -18071,20 +18029,21 @@ void Plater::export_gcode(bool prefer_removable) unsigned int state = this->p->update_restart_background_process(false, false); if (state & priv::UPDATE_BACKGROUND_PROCESS_INVALID) return; - default_output_file = this->p->background_process.output_filepath_for_project(into_path(this->p->get_project_filename(".3mf"))); - } catch (const Slic3r::PlaceholderParserError& ex) { + default_output_file = this->p->background_process.output_filepath_for_project( + into_path(this->p->get_project_filename(".3mf"))); + } catch (const Slic3r::PlaceholderParserError &ex) { // Show the error with monospaced font. show_error(this, ex.what(), true); return; - } catch (const std::exception& ex) { + } catch (const std::exception &ex) { show_error(this, ex.what(), false); return; } - default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string())); - AppConfig& appconfig = *wxGetApp().app_config; - RemovableDriveManager& removable_drive_manager = *wxGetApp().removable_drive_manager(); + default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string())); + AppConfig &appconfig = *wxGetApp().app_config; + RemovableDriveManager &removable_drive_manager = *wxGetApp().removable_drive_manager(); // Get a last save path, either to removable media or to an internal media. - std::string start_dir = appconfig.get_last_output_dir(default_output_file.parent_path().string(), prefer_removable); + std::string start_dir = appconfig.get_last_output_dir(default_output_file.parent_path().string(), prefer_removable); if (prefer_removable) { // Returns a path to a removable media if it exists, prefering start_dir. Update the internal removable drives database. start_dir = removable_drive_manager.get_removable_drive_path(start_dir); @@ -18096,14 +18055,17 @@ void Plater::export_gcode(bool prefer_removable) fs::path output_path; { std::string ext = default_output_file.extension().string(); - wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _L("Save G-code file as:") : _L("Save SLA file as:"), start_dir, - from_path(default_output_file.filename()), - GUI::file_wildcards((printer_technology() == ptFFF) ? FT_GCODE : FT_SL1, ext), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _L("Save G-code file as:") : _L("Save SLA file as:"), + start_dir, + from_path(default_output_file.filename()), + GUI::file_wildcards((printer_technology() == ptFFF) ? FT_GCODE : FT_SL1, ext), + wxFD_SAVE | wxFD_OVERWRITE_PROMPT + ); if (dlg.ShowModal() == wxID_OK) { output_path = into_path(dlg.GetPath()); while (has_illegal_filename_characters(output_path.filename().string())) { show_error(this, _L("The provided file name is not valid.") + "\n" + - _L("The following characters are not allowed by a FAT file system:") + " <>:/\\|?*\""); + _L("The following characters are not allowed by a FAT file system:") + " <>:/\\|?*\""); dlg.SetFilename(from_path(output_path.filename())); if (dlg.ShowModal() == wxID_OK) output_path = into_path(dlg.GetPath()); @@ -18115,17 +18077,17 @@ void Plater::export_gcode(bool prefer_removable) } } - if (!output_path.empty()) { + if (! output_path.empty()) { bool path_on_removable_media = removable_drive_manager.set_and_verify_last_save_path(output_path.string()); - // bool path_on_removable_media = false; + //bool path_on_removable_media = false; p->notification_manager->new_export_began(path_on_removable_media); - p->exporting_status = path_on_removable_media ? ExportingStatus::EXPORTING_TO_REMOVABLE : ExportingStatus::EXPORTING_TO_LOCAL; - p->last_output_path = output_path.string(); + p->exporting_status = path_on_removable_media ? ExportingStatus::EXPORTING_TO_REMOVABLE : ExportingStatus::EXPORTING_TO_LOCAL; + p->last_output_path = output_path.string(); p->last_output_dir_path = output_path.parent_path().string(); p->export_gcode(output_path, path_on_removable_media); // Storing a path to AppConfig either as path to removable media or a path to internal media. - // is_path_on_removable_drive() is called with the "true" parameter to update its internal database as the user may have shuffled - // the external drives while the dialog was open. + // is_path_on_removable_drive() is called with the "true" parameter to update its internal database as the user may have shuffled the external drives + // while the dialog was open. appconfig.update_last_output_dir(output_path.parent_path().string(), path_on_removable_media); try { @@ -18137,18 +18099,22 @@ void Plater::export_gcode(bool prefer_removable) j["printer_preset"] = printer_config.config.opt_string("inherits"); } - PresetBundle* preset_bundle = wxGetApp().preset_bundle; + PresetBundle *preset_bundle = wxGetApp().preset_bundle; if (preset_bundle) { j["gcode_printer_model"] = preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle); } - NetworkAgent* agent = wxGetApp().getAgent(); + NetworkAgent *agent = wxGetApp().getAgent(); } catch (...) {} + } } -void Plater::send_to_printer(bool isall) { p->on_action_send_to_printer(isall); } +void Plater::send_to_printer(bool isall) +{ + p->on_action_send_to_printer(isall); +} -// BBS export gcode 3mf to file +//BBS export gcode 3mf to file void Plater::export_gcode_3mf(bool export_all) { if (p->model.objects.empty()) @@ -18157,7 +18123,7 @@ void Plater::export_gcode_3mf(bool export_all) if (p->process_completed_with_error == p->partplate_list.get_curr_plate_index()) return; - // calc default_output_file, get default output file from background process + //calc default_output_file, get default output file from background process fs::path default_output_file; AppConfig& appconfig = *wxGetApp().app_config; std::string start_dir; @@ -18167,52 +18133,60 @@ void Plater::export_gcode_3mf(bool export_all) unsigned int state = this->p->update_restart_background_process(false, false); if (state & priv::UPDATE_BACKGROUND_PROCESS_INVALID) return; - default_output_file = this->p->background_process.output_filepath_for_project(into_path(this->p->get_project_filename(".3mf"))); - } catch (const Slic3r::PlaceholderParserError& ex) { + default_output_file = this->p->background_process.output_filepath_for_project( + into_path(this->p->get_project_filename(".3mf"))); + } + catch (const Slic3r::PlaceholderParserError& ex) { // Show the error with monospaced font. show_error(this, ex.what(), true); return; - } catch (const std::exception& ex) { + } + catch (const std::exception& ex) { show_error(this, ex.what(), false); return; } default_output_file.replace_extension(".gcode.3mf"); default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string())); - // Get a last save path + //Get a last save path start_dir = appconfig.get_last_output_dir(default_output_file.parent_path().string(), false); fs::path output_path; { std::string ext = default_output_file.extension().string(); - wxFileDialog dlg(this, _L("Save Sliced file as:"), start_dir, from_path(default_output_file.filename()), - GUI::file_wildcards(FT_GCODE_3MF, ""), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + wxFileDialog dlg(this, _L("Save Sliced file as:"), + start_dir, + from_path(default_output_file.filename()), + GUI::file_wildcards(FT_GCODE_3MF, ""), + wxFD_SAVE | wxFD_OVERWRITE_PROMPT + ); if (dlg.ShowModal() == wxID_OK) { output_path = into_path(dlg.GetPath()); - ext = output_path.extension().string(); + ext = output_path.extension().string(); if (ext != ".3mf") output_path = output_path.string() + ".3mf"; } } if (!output_path.empty()) { - // BBS do not set to removable media path + //BBS do not set to removable media path bool path_on_removable_media = false; p->notification_manager->new_export_began(path_on_removable_media); p->exporting_status = path_on_removable_media ? ExportingStatus::EXPORTING_TO_REMOVABLE : ExportingStatus::EXPORTING_TO_LOCAL; - // BBS do not save last output path - p->last_output_path = output_path.string(); + //BBS do not save last output path + p->last_output_path = output_path.string(); p->last_output_dir_path = output_path.parent_path().string(); - int plate_idx = get_partplate_list().get_curr_plate_index(); + int plate_idx = get_partplate_list().get_curr_plate_index(); if (export_all) plate_idx = PLATE_ALL_IDX; - export_3mf(output_path, SaveStrategy::Silence | SaveStrategy::SplitModel | SaveStrategy::WithGcode | SaveStrategy::SkipModel, - plate_idx); // BBS: silence + export_3mf(output_path, SaveStrategy::Silence | SaveStrategy::SplitModel | SaveStrategy::WithGcode | SaveStrategy::SkipModel, plate_idx); // BBS: silence RemovableDriveManager& removable_drive_manager = *wxGetApp().removable_drive_manager(); + bool on_removable = removable_drive_manager.is_path_on_removable_drive(p->last_output_dir_path); + // update last output dir appconfig.update_last_output_dir(output_path.parent_path().string(), false); p->notification_manager->push_exporting_finished_notification(output_path.string(), p->last_output_dir_path, on_removable); @@ -18224,13 +18198,10 @@ void Plater::send_gcode_finish(wxString name) auto out_str = GUI::format(_L("The file %s has been sent to the printer's storage space and can be viewed on the printer."), name); p->notification_manager->push_exporting_finished_notification(out_str, "", false); } - void Plater::export_core_3mf() { wxString path = p->get_export_file(FT_3MF); - if (path.empty()) { - return; - } + if (path.empty()) { return; } const std::string path_u8 = into_u8(path); export_3mf(path_u8, SaveStrategy::Silence); } @@ -18401,28 +18372,26 @@ void Plater::set_pending_published(const std::vector& published_key p->m_pending_material_keys = material_keys; } -Preset* get_printer_preset(const MachineObject* obj) +Preset *get_printer_preset(const MachineObject *obj) { if (!obj) return nullptr; - Preset* printer_preset = nullptr; + Preset *printer_preset = nullptr; - PresetBundle* preset_bundle = wxGetApp().preset_bundle; + PresetBundle *preset_bundle = wxGetApp().preset_bundle; for (auto printer_it = preset_bundle->printers.begin(); printer_it != preset_bundle->printers.end(); printer_it++) { // only use system printer preset if (!printer_it->is_system) continue; - ConfigOption* printer_nozzle_opt = printer_it->config.option("nozzle_diameter"); - ConfigOptionFloats* printer_nozzle_vals = nullptr; - if (printer_nozzle_opt) - printer_nozzle_vals = dynamic_cast(printer_nozzle_opt); + ConfigOption *printer_nozzle_opt = printer_it->config.option("nozzle_diameter"); + ConfigOptionFloats *printer_nozzle_vals = nullptr; + if (printer_nozzle_opt) printer_nozzle_vals = dynamic_cast(printer_nozzle_opt); std::string model_id = printer_it->get_current_printer_type(preset_bundle); - std::string printer_type = obj->get_show_printer_type(); - bool nozzle_diameter_matches_or_unknown = printer_nozzle_vals && - obj->GetExtderSystem()->NozzleDiameterMatchesOrUnknown(0, printer_nozzle_vals->get_at(0)); + std::string printer_type = obj->get_show_printer_type(); + bool nozzle_diameter_matches_or_unknown = printer_nozzle_vals && obj->GetExtderSystem()->NozzleDiameterMatchesOrUnknown(0, printer_nozzle_vals->get_at(0)); if (model_id.compare(printer_type) == 0 && nozzle_diameter_matches_or_unknown) { printer_preset = &(*printer_it); } @@ -18430,7 +18399,7 @@ Preset* get_printer_preset(const MachineObject* obj) return printer_preset; } -bool Plater::check_printer_initialized(MachineObject* obj, bool only_warning, bool popup_warning) +bool Plater::check_printer_initialized(MachineObject *obj, bool only_warning, bool popup_warning) { if (!obj) return false; @@ -18439,6 +18408,7 @@ bool Plater::check_printer_initialized(MachineObject* obj, bool only_warning, bo const auto& extruders = obj->GetExtderSystem()->GetExtruders(); for (const DevExtder& extruder : extruders) { + // Skip check if nozzle type is unknown if (extruder.GetNozzleType() == NozzleType::ntUndefine) { continue; @@ -18454,16 +18424,14 @@ bool Plater::check_printer_initialized(MachineObject* obj, bool only_warning, bo if (popup_warning) { if (!only_warning) { if (DevPrinterConfigUtil::get_printer_can_set_nozzle(obj->get_show_printer_type())) { - MessageDialog dlg(wxGetApp().plater(), _L("The nozzle type is not set. Please set the nozzle and try again."), - _L("Warning"), wxOK | wxICON_WARNING); + MessageDialog dlg(wxGetApp().plater(), _L("The nozzle type is not set. Please set the nozzle and try again."), _L("Warning"), wxOK | wxICON_WARNING); dlg.ShowModal(); } else { - MessageDialog dlg(wxGetApp().plater(), _L("The nozzle type is not set. Please check."), _L("Warning"), - wxOK | wxICON_WARNING); + MessageDialog dlg(wxGetApp().plater(), _L("The nozzle type is not set. Please check."), _L("Warning"), wxOK | wxICON_WARNING); dlg.ShowModal(); } - PrinterPartsDialog* print_parts_dlg = new PrinterPartsDialog(nullptr); + PrinterPartsDialog *print_parts_dlg = new PrinterPartsDialog(nullptr); print_parts_dlg->update_machine_obj(obj); print_parts_dlg->ShowModal(); } else { @@ -18484,25 +18452,26 @@ TriangleMesh Plater::combine_mesh_fff(const ModelObject& mo, int instance_id, st std::vector csgmesh; csgmesh.reserve(2 * mo.volumes.size()); bool has_splitable_volume = csg::model_to_csgmesh(mo, Transform3d::Identity(), std::back_inserter(csgmesh), - csg::mpartsPositive | csg::mpartsNegative); - + csg::mpartsPositive | csg::mpartsNegative); + std::string fail_msg = _u8L("Unable to perform boolean operation on model meshes. " - "Only positive parts will be kept. You may fix the meshes and try again."); - if (auto fail_reason_name = csg::check_csgmesh_booleans(Range{std::begin(csgmesh), std::end(csgmesh)}); - std::get<0>(fail_reason_name) != csg::BooleanFailReason::OK) { + "Only positive parts will be kept. You may fix the meshes and try again."); + if (auto fail_reason_name = csg::check_csgmesh_booleans(Range{ std::begin(csgmesh), std::end(csgmesh) }); std::get<0>(fail_reason_name) != csg::BooleanFailReason::OK) { std::string name = std::get<1>(fail_reason_name); - std::map fail_reasons = - {{csg::BooleanFailReason::OK, "OK"}, - {csg::BooleanFailReason::MeshEmpty, Slic3r::format(_u8L("Reason: part \"%1%\" is empty."), name)}, - {csg::BooleanFailReason::NotBoundAVolume, Slic3r::format(_u8L("Reason: part \"%1%\" does not bound a volume."), name)}, - {csg::BooleanFailReason::SelfIntersect, Slic3r::format(_u8L("Reason: part \"%1%\" has self intersection."), name)}, - {csg::BooleanFailReason::NoIntersection, Slic3r::format(_u8L("Reason: \"%1%\" and another part have no intersection."), name)}}; + std::map fail_reasons = { + {csg::BooleanFailReason::OK, "OK"}, + {csg::BooleanFailReason::MeshEmpty, Slic3r::format( _u8L("Reason: part \"%1%\" is empty."), name)}, + {csg::BooleanFailReason::NotBoundAVolume, Slic3r::format(_u8L("Reason: part \"%1%\" does not bound a volume."), name)}, + {csg::BooleanFailReason::SelfIntersect, Slic3r::format(_u8L("Reason: part \"%1%\" has self intersection."), name)}, + {csg::BooleanFailReason::NoIntersection, Slic3r::format(_u8L("Reason: \"%1%\" and another part have no intersection."), name)} }; fail_msg += " " + fail_reasons[std::get<0>(fail_reason_name)]; - } else { + } + else { try { - MeshBoolean::mcut::McutMeshPtr meshPtr = csg::perform_csgmesh_booleans_mcut(Range{std::begin(csgmesh), std::end(csgmesh)}); - mesh = MeshBoolean::mcut::mcut_to_triangle_mesh(*meshPtr); - } catch (...) {} + MeshBoolean::mcut::McutMeshPtr meshPtr = csg::perform_csgmesh_booleans_mcut(Range{ std::begin(csgmesh), std::end(csgmesh) }); + mesh = MeshBoolean::mcut::mcut_to_triangle_mesh(*meshPtr); + } + catch (...) {} #if 0 // if mcut fails, try again with CGAL if (mesh.empty()) { @@ -18535,7 +18504,8 @@ TriangleMesh Plater::combine_mesh_fff(const ModelObject& mo, int instance_id, st m.transform(i->get_matrix(), true); mesh.merge(m); } - } else if (0 <= instance_id && instance_id < int(mo.instances.size())) + } + else if (0 <= instance_id && instance_id < int(mo.instances.size())) mesh.transform(mo.instances[instance_id]->get_matrix(), true); return mesh; } @@ -18544,9 +18514,7 @@ TriangleMesh Plater::combine_mesh_fff(const ModelObject& mo, int instance_id, st #define EXPORT_WITH_BOOLEAN 0 void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, FileType file_type) { - if (p->model.objects.empty()) { - return; - } + if (p->model.objects.empty()) { return; } int quality = 0; @@ -18570,35 +18538,31 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil } else { path = p->get_export_file(file_type); } - if (path.empty()) { - return; - } + if (path.empty()) { return; } const std::string path_u8 = into_u8(path); wxBusyCursor wait; const auto& selection = p->get_selection(); - const auto obj_idx = selection.get_object_idx(); + const auto obj_idx = selection.get_object_idx(); #if EXPORT_WITH_BOOLEAN if (selection_only && (obj_idx == -1 || selection.is_wipe_tower())) return; #else // BBS support selecting multiple objects - if (selection_only && selection.is_wipe_tower()) - return; + if (selection_only && selection.is_wipe_tower()) return; // BBS if (selection_only) { // only support selection single full object and mulitiple full object - if (!selection.is_single_full_object() && !selection.is_multiple_full_object()) - return; + if (!selection.is_single_full_object() && !selection.is_multiple_full_object()) return; } // Following lambda generates a combined mesh for export with normals pointing outwards. - auto mesh_to_export_fff_no_boolean = [this](const ModelObject& mo, int instance_id) { + auto mesh_to_export_fff_no_boolean = [this](const ModelObject &mo, int instance_id) { TriangleMesh mesh; - // Prusa export negative parts + //Prusa export negative parts std::vector csgmesh; csgmesh.reserve(2 * mo.volumes.size()); csg::model_to_csgmesh(mo, Transform3d::Identity(), std::back_inserter(csgmesh), @@ -18610,13 +18574,14 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil } else if (std::get<2>(csg::check_csgmesh_booleans(csgrange)) == csgrange.end()) { try { auto cgalm = csg::perform_csgmesh_booleans(csgrange); - mesh = MeshBoolean::cgal::cgal_to_triangle_mesh(*cgalm); + mesh = MeshBoolean::cgal::cgal_to_triangle_mesh(*cgalm); } catch (...) {} } if (mesh.empty()) { - get_notification_manager()->push_plater_error_notification(_u8L("Unable to perform boolean operation on model meshes. " - "Only positive parts will be exported.")); + get_notification_manager()->push_plater_error_notification( + _u8L("Unable to perform boolean operation on model meshes. " + "Only positive parts will be exported.")); for (const ModelVolume* v : mo.volumes) if (v->is_model_part()) { @@ -18628,7 +18593,7 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil if (instance_id == -1) { TriangleMesh vols_mesh(mesh); mesh = TriangleMesh(); - for (const ModelInstance* i : mo.instances) { + for (const ModelInstance *i : mo.instances) { TriangleMesh m = vols_mesh; m.transform(i->get_matrix(), true); mesh.merge(m); @@ -18641,17 +18606,15 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil auto mesh_to_export_sla = [&, this](const ModelObject& mo, int instance_id) { TriangleMesh mesh; - const SLAPrintObject* object = this->p->sla_print.get_print_object_by_model_object_id(mo.id()); + const SLAPrintObject *object = this->p->sla_print.get_print_object_by_model_object_id(mo.id()); if (auto m = object->get_mesh_to_print(); m.empty()) - mesh = combine_mesh_fff(mo, instance_id, [this](const std::string& msg) { - return get_notification_manager()->push_general_error_notification(msg); - }); + mesh = combine_mesh_fff(mo, instance_id, [this](const std::string& msg) {return get_notification_manager()->push_general_error_notification(msg); }); else { const Transform3d mesh_trafo_inv = object->trafo().inverse(); - const bool is_left_handed = object->is_left_handed(); + const bool is_left_handed = object->is_left_handed(); - auto pad_mesh = extended ? object->pad_mesh() : TriangleMesh{}; + auto pad_mesh = extended? object->pad_mesh() : TriangleMesh{}; pad_mesh.transform(mesh_trafo_inv); auto supports_mesh = extended ? object->support_mesh() : TriangleMesh{}; @@ -18660,16 +18623,16 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil const std::vector& obj_instances = object->instances(); for (const SLAPrintObject::Instance& obj_instance : obj_instances) { auto it = std::find_if(object->model_object()->instances.begin(), object->model_object()->instances.end(), - [&obj_instance](const ModelInstance* mi) { return mi->id() == obj_instance.instance_id; }); + [&obj_instance](const ModelInstance *mi) { return mi->id() == obj_instance.instance_id; }); assert(it != object->model_object()->instances.end()); if (it != object->model_object()->instances.end()) { - const bool one_inst_only = selection_only && !selection.is_single_full_object(); + const bool one_inst_only = selection_only && ! selection.is_single_full_object(); const int instance_idx = it - object->model_object()->instances.begin(); - const Transform3d& inst_transform = - one_inst_only ? Transform3d::Identity() : - object->model_object()->instances[instance_idx]->get_transformation().get_matrix(); + const Transform3d& inst_transform = one_inst_only + ? Transform3d::Identity() + : object->model_object()->instances[instance_idx]->get_transformation().get_matrix(); TriangleMesh inst_mesh; @@ -18692,10 +18655,10 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil inst_mesh.merge(inst_object_mesh); - // ensure that the instance lays on the bed + // ensure that the instance lays on the bed inst_mesh.translate(0.0f, 0.0f, -inst_mesh.bounding_box().min.z()); - // merge instance with global mesh + // merge instance with global mesh mesh.merge(inst_mesh); if (one_inst_only) @@ -18707,22 +18670,20 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil return mesh; }; - std::function mesh_to_export; + std::function + mesh_to_export; if (p->printer_technology == ptFFF) #if EXPORT_WITH_BOOLEAN - mesh_to_export = [this](const ModelObject& mo, int instance_id) { - return Plater::combine_mesh_fff(mo, instance_id, [this](const std::string& msg) { - return get_notification_manager()->push_general_error_notification(msg); - }); - }; + mesh_to_export = [this](const ModelObject& mo, int instance_id) {return Plater::combine_mesh_fff(mo, instance_id, + [this](const std::string& msg) {return get_notification_manager()->push_general_error_notification(msg); }); }; #else mesh_to_export = mesh_to_export_fff_no_boolean; #endif else mesh_to_export = mesh_to_export_sla; - auto get_save_file = [file_type](std::string const& dir, std::string const& name) { + auto get_save_file = [file_type](std::string const & dir, std::string const & name) { std::string ext = ""; switch (file_type) { case FT_STL: ext = ".stl"; break; @@ -18730,38 +18691,39 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil } auto path = dir + name + ext; - int n = 1; + int n = 1; while (boost::filesystem::exists(path)) - path = dir + name + "(" + std::to_string(n++) + ")" + ext; + path = dir + name + "(" + std::to_string(n++) + ")"+ext; return path; }; TriangleMesh mesh; if (selection_only) { if (selection.is_single_full_object()) { - const auto obj_idx = selection.get_object_idx(); + const auto obj_idx = selection.get_object_idx(); const ModelObject* model_object = p->model.objects[obj_idx]; if (selection.get_mode() == Selection::Instance) mesh = mesh_to_export(*model_object, (model_object->instances.size() > 1) ? -1 : selection.get_instance_idx()); else { const GLVolume* volume = selection.get_first_volume(); - mesh = model_object->volumes[volume->volume_idx()]->mesh(); + mesh = model_object->volumes[volume->volume_idx()]->mesh(); mesh.transform(volume->get_volume_transformation().get_matrix(), true); } - if (model_object->instances.size() == 1) - mesh.translate(-model_object->origin_translation.cast()); - } else if (selection.is_multiple_full_object() && !multi_stls) { + if (model_object->instances.size() == 1) mesh.translate(-model_object->origin_translation.cast()); + } + else if (selection.is_multiple_full_object() && !multi_stls) { const std::set>& instances_idxs = p->get_selection().get_selected_object_instances(); for (const std::pair& i : instances_idxs) { ModelObject* object = p->model.objects[i.first]; mesh.merge(mesh_to_export(*object, i.second)); } - } else if (selection.is_multiple_full_object() && multi_stls) { - const std::set>& instances_idxs = p->get_selection().get_selected_object_instances(); - for (const std::pair& i : instances_idxs) { - ModelObject* object = p->model.objects[i.first]; - auto mesh = mesh_to_export(*object, i.second); + } + else if (selection.is_multiple_full_object() && multi_stls) { + const std::set> &instances_idxs = p->get_selection().get_selected_object_instances(); + for (const std::pair &i : instances_idxs) { + ModelObject *object = p->model.objects[i.first]; + auto mesh = mesh_to_export(*object, i.second); mesh.translate(-object->origin_translation.cast()); switch (file_type) { @@ -18771,7 +18733,8 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil } return; } - } else if (!multi_stls) { + } + else if (!multi_stls) { for (const ModelObject* o : p->model.objects) { mesh.merge(mesh_to_export(*o, -1)); } @@ -18794,7 +18757,7 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil } } -// BBS: remove amf export +//BBS: remove amf export /*void Plater::export_amf() { if (p->model.objects.empty()) { return; } @@ -18815,7 +18778,7 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls, Fil }*/ namespace { -std::string get_file_name(const std::string& file_path) +std::string get_file_name(const std::string &file_path) { size_t pos_last_delimiter = file_path.find_last_of("/\\"); size_t pos_point = file_path.find_last_of('.'); @@ -18823,33 +18786,33 @@ std::string get_file_name(const std::string& file_path) size_t count = pos_point - pos_last_delimiter - 1; return file_path.substr(offset, count); } -using SvgFile = EmbossShape::SvgFile; +using SvgFile = EmbossShape::SvgFile; using SvgFiles = std::vector; -std::string create_unique_3mf_filepath(const std::string& file, const SvgFiles svgs) +std::string create_unique_3mf_filepath(const std::string &file, const SvgFiles svgs) { // const std::string MODEL_FOLDER = "3D/"; // copy from file 3mf.cpp std::string path_in_3mf = "3D/" + file + ".svg"; - size_t suffix_number = 0; - bool is_unique = false; - do { - is_unique = true; - path_in_3mf = "3D/" + file + ((suffix_number++) ? ("_" + std::to_string(suffix_number)) : "") + ".svg"; - for (SvgFile* svgfile : svgs) { + size_t suffix_number = 0; + bool is_unique = false; + do{ + is_unique = true; + path_in_3mf = "3D/" + file + ((suffix_number++)? ("_" + std::to_string(suffix_number)) : "") + ".svg"; + for (SvgFile *svgfile : svgs) { if (svgfile->path_in_3mf.empty()) continue; if (svgfile->path_in_3mf.compare(path_in_3mf) == 0) { is_unique = false; break; } - } + } } while (!is_unique); return path_in_3mf; } -bool set_by_local_path(SvgFile& svg, const SvgFiles& svgs) +bool set_by_local_path(SvgFile &svg, const SvgFiles& svgs) { // Try to find already used svg file - for (SvgFile* svg_ : svgs) { + for (SvgFile *svg_ : svgs) { if (svg_->path_in_3mf.empty()) continue; if (svg.path.compare(svg_->path) == 0) { @@ -18864,13 +18827,13 @@ bool set_by_local_path(SvgFile& svg, const SvgFiles& svgs) /// Function to secure private data before store to 3mf /// /// Data(also private) to clean before publishing -void publish(Model& model, SaveStrategy strategy) -{ +void publish(Model &model, SaveStrategy strategy) { + // SVG file publishing bool exist_new = false; SvgFiles svgfiles; - for (ModelObject* object : model.objects) { - for (ModelVolume* volume : object->volumes) { + for (ModelObject *object: model.objects){ + for (ModelVolume *volume : object->volumes) { if (!volume->emboss_shape.has_value()) continue; if (volume->text_configuration.has_value()) @@ -18887,7 +18850,7 @@ void publish(Model& model, SaveStrategy strategy) } } - for (SvgFile* svgfile : svgfiles) { + for (SvgFile *svgfile : svgfiles) { if (!svgfile->path_in_3mf.empty()) continue; // already suggested path (previous save) @@ -18899,26 +18862,26 @@ void publish(Model& model, SaveStrategy strategy) // check whether original filename is already in: filename = get_file_name(svgfile->path); } - svgfile->path_in_3mf = create_unique_3mf_filepath(filename, svgfiles); + svgfile->path_in_3mf = create_unique_3mf_filepath(filename, svgfiles); } } -} // namespace +} // BBS: backup int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy strategy, int export_plate_idx, Export3mfProgressFn proFn) { int ret = 0; - // if (p->model.objects.empty()) { - // MessageDialog dialog(nullptr, _L("No objects to export."), _L("Save project"), wxYES); - // if (dialog.ShowModal() == wxYES) - // return -1; - // } + //if (p->model.objects.empty()) { + // MessageDialog dialog(nullptr, _L("No objects to export."), _L("Save project"), wxYES); + // if (dialog.ShowModal() == wxYES) + // return -1; + //} if (output_path.empty()) return -1; bool export_config = true; - wxString path = from_path(output_path); + wxString path = from_path(output_path); if (!path.Lower().EndsWith(".3mf")) return -1; @@ -18927,19 +18890,17 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy // modify model publish(p->model, strategy); - DynamicPrintConfig cfg = wxGetApp().preset_bundle->full_config_secure(); + DynamicPrintConfig cfg = wxGetApp().preset_bundle->full_config_secure(); const std::string path_u8 = into_u8(path); wxBusyCursor wait; - BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ - << boost::format(": path=%1%, backup=%2%, export_plate_idx=%3%, SaveStrategy=%4%") % output_path.string() % - (strategy & SaveStrategy::Backup) % export_plate_idx % (unsigned int) strategy; + BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << boost::format(": path=%1%, backup=%2%, export_plate_idx=%3%, SaveStrategy=%4%") + %output_path.string()%(strategy & SaveStrategy::Backup)%export_plate_idx %(unsigned int)strategy; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": path=%1%, backup=%2%, export_plate_idx=%3%, SaveStrategy=%4%") % std::string("") % - (strategy & SaveStrategy::Backup) % export_plate_idx % (unsigned int) strategy; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": path=%1%, backup=%2%, export_plate_idx=%3%, SaveStrategy=%4%") + % std::string("") % (strategy & SaveStrategy::Backup) % export_plate_idx % (unsigned int)strategy; - // BBS: add plate logic for thumbnail generate + //BBS: add plate logic for thumbnail generate std::vector thumbnails; std::vector no_light_thumbnails; std::vector calibration_thumbnails; @@ -18950,113 +18911,106 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy if (!(strategy & SaveStrategy::Backup)) { for (int i = 0; i < p->partplate_list.get_plate_count(); i++) { ThumbnailData* thumbnail_data = &p->partplate_list.get_plate(i)->thumbnail_data; - if (p->partplate_list.get_plate(i)->thumbnail_data.is_valid() && using_exported_file()) { - // no need to generate thumbnail - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": non need to re-generate thumbnail for gcode/exported mode of plate %1%") % i; - } else { + if (p->partplate_list.get_plate(i)->thumbnail_data.is_valid() && using_exported_file()) { + //no need to generate thumbnail + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": non need to re-generate thumbnail for gcode/exported mode of plate %1%")%i; + } + else { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": re-generate thumbnail for plate %1%") % i; - const ThumbnailsParams thumbnail_params = {{}, false, true, true, true, i}; + const ThumbnailsParams thumbnail_params = { {}, false, true, true, true, i }; p->generate_thumbnail(p->partplate_list.get_plate(i)->thumbnail_data, THUMBNAIL_SIZE_3MF.first, THUMBNAIL_SIZE_3MF.second, - thumbnail_params, Camera::EType::Ortho); + thumbnail_params, Camera::EType::Ortho); } thumbnails.push_back(thumbnail_data); - ThumbnailData* no_light_thumbnail_data = &p->partplate_list.get_plate(i)->no_light_thumbnail_data; + ThumbnailData *no_light_thumbnail_data = &p->partplate_list.get_plate(i)->no_light_thumbnail_data; if (p->partplate_list.get_plate(i)->no_light_thumbnail_data.is_valid() && using_exported_file()) { // no need to generate thumbnail - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": non need to re-generate thumbnail for gcode/exported mode of plate %1%") % i; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": non need to re-generate thumbnail for gcode/exported mode of plate %1%") % i; } else { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": re-generate thumbnail for plate %1%") % i; const ThumbnailsParams thumbnail_params = {{}, false, true, true, true, i}; - p->generate_thumbnail(p->partplate_list.get_plate(i)->no_light_thumbnail_data, THUMBNAIL_SIZE_3MF.first, - THUMBNAIL_SIZE_3MF.second, thumbnail_params, Camera::EType::Ortho, Camera::ViewAngleType::Iso, false, - true); + p->generate_thumbnail(p->partplate_list.get_plate(i)->no_light_thumbnail_data, THUMBNAIL_SIZE_3MF.first, THUMBNAIL_SIZE_3MF.second, thumbnail_params, + Camera::EType::Ortho, Camera::ViewAngleType::Iso, false, true); } no_light_thumbnails.push_back(no_light_thumbnail_data); - // ThumbnailData* calibration_data = &p->partplate_list.get_plate(i)->cali_thumbnail_data; - // calibration_thumbnails.push_back(calibration_data); + //ThumbnailData* calibration_data = &p->partplate_list.get_plate(i)->cali_thumbnail_data; + //calibration_thumbnails.push_back(calibration_data); PlateBBoxData* plate_bbox_data = &p->partplate_list.get_plate(i)->cali_bboxes_data; plate_bboxes.push_back(plate_bbox_data); - // generate top and picking thumbnails + //generate top and picking thumbnails ThumbnailData* top_thumbnail = &p->partplate_list.get_plate(i)->top_thumbnail_data; - if (top_thumbnail->is_valid() && using_exported_file()) { - // no need to generate thumbnail - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": non need to re-generate top_thumbnail for gcode/exported mode of plate %1%") % - i; - } else { + if (top_thumbnail->is_valid() && using_exported_file()) { + //no need to generate thumbnail + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": non need to re-generate top_thumbnail for gcode/exported mode of plate %1%")%i; + } + else { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": re-generate top_thumbnail for plate %1%") % i; - const ThumbnailsParams thumbnail_params = {{}, false, true, false, true, i}; - p->generate_thumbnail(p->partplate_list.get_plate(i)->top_thumbnail_data, THUMBNAIL_SIZE_3MF.first, - THUMBNAIL_SIZE_3MF.second, thumbnail_params, Camera::EType::Ortho, Camera::ViewAngleType::Top_Plate, - false); + const ThumbnailsParams thumbnail_params = { {}, false, true, false, true, i }; + p->generate_thumbnail(p->partplate_list.get_plate(i)->top_thumbnail_data, THUMBNAIL_SIZE_3MF.first, THUMBNAIL_SIZE_3MF.second, thumbnail_params, + Camera::EType::Ortho, Camera::ViewAngleType::Top_Plate, false); } top_thumbnails.push_back(top_thumbnail); ThumbnailData* picking_thumbnail = &p->partplate_list.get_plate(i)->pick_thumbnail_data; - if (picking_thumbnail->is_valid() && using_exported_file()) { - // no need to generate thumbnail - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": non need to re-generate pick_thumbnail for gcode/exported mode of plate %1%") % - i; - } else { + if (picking_thumbnail->is_valid() && using_exported_file()) { + //no need to generate thumbnail + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": non need to re-generate pick_thumbnail for gcode/exported mode of plate %1%")%i; + } + else { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": re-generate pick_thumbnail for plate %1%") % i; - const ThumbnailsParams thumbnail_params = {{}, false, true, false, true, i}; - p->generate_thumbnail(p->partplate_list.get_plate(i)->pick_thumbnail_data, THUMBNAIL_SIZE_3MF.first, - THUMBNAIL_SIZE_3MF.second, thumbnail_params, Camera::EType::Ortho, Camera::ViewAngleType::Top_Plate, - true, true); + const ThumbnailsParams thumbnail_params = { {}, false, true, false, true, i }; + p->generate_thumbnail(p->partplate_list.get_plate(i)->pick_thumbnail_data, THUMBNAIL_SIZE_3MF.first, THUMBNAIL_SIZE_3MF.second, thumbnail_params, + Camera::EType::Ortho, Camera::ViewAngleType::Top_Plate, true,true); } picking_thumbnails.push_back(picking_thumbnail); } if (p->partplate_list.get_curr_plate()->is_slice_result_valid()) { - // BBS generate BBS calibration thumbnails + //BBS generate BBS calibration thumbnails int index = p->partplate_list.get_curr_plate_index(); - // ThumbnailData* calibration_data = calibration_thumbnails[index]; - // const ThumbnailsParams calibration_params = { {}, false, true, true, true, p->partplate_list.get_curr_plate_index() }; - // p->generate_calibration_thumbnail(*calibration_data, PartPlate::cali_thumbnail_width, PartPlate::cali_thumbnail_height, - // calibration_params); + //ThumbnailData* calibration_data = calibration_thumbnails[index]; + //const ThumbnailsParams calibration_params = { {}, false, true, true, true, p->partplate_list.get_curr_plate_index() }; + //p->generate_calibration_thumbnail(*calibration_data, PartPlate::cali_thumbnail_width, PartPlate::cali_thumbnail_height, calibration_params); if (using_exported_file()) { - // do nothing - } else + //do nothing + } + else *plate_bboxes[index] = p->generate_first_layer_bbox(); } } - // BBS: add bbs 3mf logic + //BBS: add bbs 3mf logic PlateDataPtrs plate_data_list; - p->partplate_list.store_to_3mf_structure(plate_data_list, - (strategy & SaveStrategy::WithGcode || strategy & SaveStrategy::WithSliceInfo), - export_plate_idx); + p->partplate_list.store_to_3mf_structure(plate_data_list, (strategy & SaveStrategy::WithGcode || strategy & SaveStrategy::WithSliceInfo), export_plate_idx); // BBS: backup - PresetBundle& preset_bundle = *wxGetApp().preset_bundle; + PresetBundle& preset_bundle = *wxGetApp().preset_bundle; std::vector project_presets = preset_bundle.get_current_project_embedded_presets(); StoreParams store_params; - store_params.path = path_u8; - store_params.model = &p->model; - store_params.plate_data_list = plate_data_list; - store_params.export_plate_idx = export_plate_idx; - store_params.project_presets = project_presets; - store_params.config = export_config ? &cfg : nullptr; - store_params.thumbnail_data = thumbnails; - store_params.no_light_thumbnail_data = no_light_thumbnails; - store_params.top_thumbnail_data = top_thumbnails; - store_params.pick_thumbnail_data = picking_thumbnails; + store_params.path = path_u8; + store_params.model = &p->model; + store_params.plate_data_list = plate_data_list; + store_params.export_plate_idx = export_plate_idx; + store_params.project_presets = project_presets; + store_params.config = export_config ? &cfg : nullptr; + store_params.thumbnail_data = thumbnails; + store_params.no_light_thumbnail_data = no_light_thumbnails; + store_params.top_thumbnail_data = top_thumbnails; + store_params.pick_thumbnail_data = picking_thumbnails; store_params.calibration_thumbnail_data = calibration_thumbnails; - store_params.proFn = proFn; - store_params.id_bboxes = plate_bboxes; // BBS - store_params.project = &p->project; - store_params.strategy = strategy | SaveStrategy::Zip64; + store_params.proFn = proFn; + store_params.id_bboxes = plate_bboxes;//BBS + store_params.project = &p->project; + store_params.strategy = strategy | SaveStrategy::Zip64; + // get type and color for platedata - auto* filament_color = dynamic_cast(cfg.option("filament_colour")); + auto* filament_color = dynamic_cast(cfg.option("filament_colour")); auto* nozzle_diameter_option = dynamic_cast(cfg.option("nozzle_diameter")); - auto* filament_id_opt = dynamic_cast(cfg.option("filament_ids")); + auto* filament_id_opt = dynamic_cast(cfg.option("filament_ids")); std::string nozzle_diameter_str; if (nozzle_diameter_option) nozzle_diameter_str = nozzle_diameter_option->serialize(); @@ -19064,14 +19018,14 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy std::string printer_model_id = preset_bundle.printers.get_edited_preset().get_printer_type(&preset_bundle); for (int i = 0; i < plate_data_list.size(); i++) { - PlateData* plate_data = plate_data_list[i]; + PlateData *plate_data = plate_data_list[i]; plate_data->printer_model_id = printer_model_id; plate_data->nozzle_diameters = nozzle_diameter_str; for (auto it = plate_data->slice_filaments_info.begin(); it != plate_data->slice_filaments_info.end(); it++) { std::string display_filament_type; - it->type = cfg.get_filament_type(display_filament_type, it->id); + it->type = cfg.get_filament_type(display_filament_type, it->id); it->filament_id = filament_id_opt ? filament_id_opt->get_at(it->id) : ""; - it->color = filament_color ? filament_color->get_at(it->id) : "#FFFFFF"; + it->color = filament_color ? filament_color->get_at(it->id) : "#FFFFFF"; // save filament info used in curr plate int index = p->partplate_list.get_curr_plate_index(); if (store_params.id_bboxes.size() > index) { @@ -19095,11 +19049,11 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy if (p->model.design_info == nullptr) { // set designInfo before export and reset after export if (wxGetApp().is_user_login()) { - p->model.design_info = std::make_shared(); - // p->model.design_info->Designer = wxGetApp().getAgent()->get_user_nickname(); + p->model.design_info = std::make_shared(); + //p->model.design_info->Designer = wxGetApp().getAgent()->get_user_nickname(); p->model.design_info->Designer = ""; p->model.design_info->DesignerUserId = wxGetApp().getAgent()->get_user_id(); - BOOST_LOG_TRIVIAL(trace) << "design_info prepare, designer = " << ""; + BOOST_LOG_TRIVIAL(trace) << "design_info prepare, designer = "<< ""; BOOST_LOG_TRIVIAL(trace) << "design_info prepare, designer_user_id = " << p->model.design_info->DesignerUserId; } } @@ -19116,12 +19070,15 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy p->set_project_filename(path); BOOST_LOG_TRIVIAL(trace) << __FUNCTION__ << __LINE__ << " call set_project_filename: " << path; } - } else { + } + else { ret = -1; } - if (project_presets.size() > 0) { - for (unsigned int i = 0; i < project_presets.size(); i++) { + if (project_presets.size() > 0) + { + for (unsigned int i = 0; i < project_presets.size(); i++) + { delete project_presets[i]; } project_presets.clear(); @@ -19129,40 +19086,61 @@ int Plater::export_3mf(const boost::filesystem::path& output_path, SaveStrategy release_PlateData_list(plate_data_list); - for (unsigned int i = 0; i < calibration_thumbnails.size(); i++) { - // release the data here, as it will always be generated when export + for (unsigned int i = 0; i < calibration_thumbnails.size(); i++) + { + //release the data here, as it will always be generated when export calibration_thumbnails[i]->reset(); } for (unsigned int i = 0; i < no_light_thumbnails.size(); i++) { // release the data here, as it will always be generated when export no_light_thumbnails[i]->reset(); } - for (unsigned int i = 0; i < top_thumbnails.size(); i++) { - // release the data here, as it will always be generated when export + for (unsigned int i = 0; i < top_thumbnails.size(); i++) + { + //release the data here, as it will always be generated when export top_thumbnails[i]->reset(); } top_thumbnails.clear(); - for (unsigned int i = 0; i < picking_thumbnails.size(); i++) { - // release the data here, as it will always be generated when export - picking_thumbnails[i]->reset(); - ; + for (unsigned int i = 0; i < picking_thumbnails.size(); i++) + { + //release the data here, as it will always be generated when export + picking_thumbnails[i]->reset();; } picking_thumbnails.clear(); return ret; } -void Plater::publish_project() { return; } +void Plater::publish_project() +{ + return; +} -void Plater::reload_from_disk() { p->reload_from_disk(); } -void Plater::replace_with_stl() { p->replace_with_stl(); } +void Plater::reload_from_disk() +{ + p->reload_from_disk(); +} -void Plater::replace_all_with_stl() { p->replace_all_with_stl(); } +void Plater::replace_with_stl() +{ + p->replace_with_stl(); +} -void Plater::reload_all_from_disk() { p->reload_all_from_disk(); } +void Plater::replace_all_with_stl() +{ + p->replace_all_with_stl(); +} -bool Plater::has_toolpaths_to_export() const { return p->preview->get_canvas3d()->has_toolpaths_to_export(); } +void Plater::reload_all_from_disk() +{ + p->reload_all_from_disk(); +} + +bool Plater::has_toolpaths_to_export() const +{ + return p->preview->get_canvas3d()->has_toolpaths_to_export(); +} void Plater::export_toolpaths_to_obj() const { @@ -19177,11 +19155,13 @@ void Plater::export_toolpaths_to_obj() const p->preview->get_canvas3d()->export_toolpaths_to_obj(into_u8(path).c_str()); } -bool Plater::is_empty_project() { return model().objects.empty(); } +bool Plater::is_empty_project() { + return model().objects.empty(); +} bool Plater::is_multi_extruder_ams_empty() { - std::vector extruder_ams_count_str = p->config->option("extruder_ams_count", true)->values; - std::vector> extruder_ams_counts = get_extruder_ams_count(extruder_ams_count_str); + std::vector extruder_ams_count_str = p->config->option("extruder_ams_count", true)->values; + std::vector> extruder_ams_counts = get_extruder_ams_count(extruder_ams_count_str); for (auto extruder_ams_count : extruder_ams_counts) { for (auto iter = extruder_ams_count.begin(); iter != extruder_ams_count.end(); ++iter) { if (iter->second != 0) @@ -19191,14 +19171,13 @@ bool Plater::is_multi_extruder_ams_empty() return true; } -// BBS: add multiple plate reslice logic +//BBS: add multiple plate reslice logic void Plater::reslice() { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(", Line %1%: enter, process_completed_with_error=%2%") % __LINE__ % - p->process_completed_with_error; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: enter, process_completed_with_error=%2%")%__LINE__ %p->process_completed_with_error; // There is "invalid data" button instead "slice now" - if (p->process_completed_with_error == p->partplate_list.get_curr_plate_index()) { + if (p->process_completed_with_error == p->partplate_list.get_curr_plate_index()) + { BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": process_completed_with_error, return directly"); reset_gcode_toolpaths(); return; @@ -19234,7 +19213,8 @@ void Plater::reslice() // get stopped. unsigned timeout_ms = 10000; if (!stop_queue(this->get_ui_job_worker(), timeout_ms)) { - BOOST_LOG_TRIVIAL(error) << "Could not stop UI job within " << timeout_ms << " milliseconds timeout!"; + BOOST_LOG_TRIVIAL(error) << "Could not stop UI job within " + << timeout_ms << " milliseconds timeout!"; return; } @@ -19249,33 +19229,32 @@ void Plater::reslice() object->sla_points_status = sla::PointsStatus::Generating; } - // FIXME Don't reslice if export of G-code or sending to OctoPrint is running. - // bitmask of UpdateBackgroundProcessReturnState + //FIXME Don't reslice if export of G-code or sending to OctoPrint is running. + // bitmask of UpdateBackgroundProcessReturnState unsigned int state = this->p->update_background_process(true); if (state & priv::UPDATE_BACKGROUND_PROCESS_REFRESH_SCENE) this->p->view3D->reload_scene(false); // If the SLA processing of just a single object's supports is running, restart slicing for the whole object. this->p->background_process.set_task(PrintBase::TaskParams()); // Only restarts if the state is valid. - // BBS: jusdge the result + //BBS: jusdge the result bool result = this->p->restart_background_process(state | priv::UPDATE_BACKGROUND_PROCESS_FORCE_RESTART); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(", Line %1%: restart background,state=%2%, result=%3%") % __LINE__ % state % result; - if ((state & priv::UPDATE_BACKGROUND_PROCESS_INVALID) != 0) { - // BBS: add logs - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format(": state %1% is UPDATE_BACKGROUND_PROCESS_INVALID, can not slice") % state; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: restart background,state=%2%, result=%3%")%__LINE__%state %result; + if ((state & priv::UPDATE_BACKGROUND_PROCESS_INVALID) != 0) + { + //BBS: add logs + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": state %1% is UPDATE_BACKGROUND_PROCESS_INVALID, can not slice") % state; p->update_fff_scene_only_shells(); return; } - if ((!result) && p->m_slice_all && (p->m_cur_slice_plate < (p->partplate_list.get_plate_count() - 1))) { - // slice next - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ - << boost::format(": in slicing all, current plate %1% already sliced, skip to next") % - p->m_cur_slice_plate; - SlicingProcessCompletedEvent evt(EVT_PROCESS_COMPLETED, 0, SlicingProcessCompletedEvent::Finished, nullptr); + if ((!result) && p->m_slice_all && (p->m_cur_slice_plate < (p->partplate_list.get_plate_count() - 1))) + { + //slice next + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": in slicing all, current plate %1% already sliced, skip to next") % p->m_cur_slice_plate ; + SlicingProcessCompletedEvent evt(EVT_PROCESS_COMPLETED, 0, + SlicingProcessCompletedEvent::Finished, nullptr); // Post the "complete" callback message, so that it will slice the next plate soon wxQueueEvent(this, evt.Clone()); p->m_is_slicing = true; @@ -19290,31 +19269,32 @@ void Plater::reslice() bool clean_gcode_toolpaths = true; // BBS - if (p->background_process.running()) { - // p->ready_to_slice = false; + if (p->background_process.running()) + { + //p->ready_to_slice = false; p->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, false); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": background process is running, m_is_slicing is true"); - } else if (!p->background_process.empty() && !p->background_process.idle()) { - // p->show_action_buttons(true); - // p->ready_to_slice = true; + } + else if (!p->background_process.empty() && !p->background_process.idle()) { + //p->show_action_buttons(true); + //p->ready_to_slice = true; p->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, true); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": background process changes to not_idle, set ready_to_slice back to true"); - } else { - // BBS: add reset logic for empty plate - PartPlate* current_plate = p->background_process.get_current_plate(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": background process changes to not_idle, set ready_to_slice back to true"); + } + else { + //BBS: add reset logic for empty plate + PartPlate * current_plate = p->background_process.get_current_plate(); if (!current_plate->has_printable_instances()) { clean_gcode_toolpaths = true; current_plate->update_slice_result_valid_state(false); - } else { + } + else { clean_gcode_toolpaths = false; current_plate->update_slice_result_valid_state(true); } p->main_frame->update_slice_print_status(MainFrame::eEventSliceUpdate, false); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": background process in idle state, use previous result, clean_gcode_toolpaths=%1%") % - clean_gcode_toolpaths; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": background process in idle state, use previous result, clean_gcode_toolpaths=%1%")%clean_gcode_toolpaths; } if (clean_gcode_toolpaths) @@ -19322,8 +19302,7 @@ void Plater::reslice() p->preview->reload_print(); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": finished, started slicing for plate %1%") % p->partplate_list.get_curr_plate_index(); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": finished, started slicing for plate %1%") % p->partplate_list.get_curr_plate_index(); record_slice_preset("slicing"); } @@ -19331,12 +19310,14 @@ void Plater::reslice() void Plater::record_slice_preset(std::string action) { // record slice preset - try { + try + { json j; auto printer_preset = wxGetApp().preset_bundle->printers.get_edited_preset_with_vendor_profile().preset; if (printer_preset.is_system) { j["printer_preset_name"] = printer_preset.name; - } else { + } + else { j["printer_preset_name"] = printer_preset.config.opt_string("inherits"); } const t_config_enum_values* keys_map = print_config_def.get("curr_bed_type")->enum_keys_map; @@ -19353,7 +19334,8 @@ void Plater::record_slice_preset(std::string action) auto filament_preset = wxGetApp().preset_bundle->filaments.find_preset(filament_presets[i]); if (filament_preset->is_system) { j["filament_preset_" + std::to_string(i)] = filament_preset->name; - } else { + } + else { j["filament_preset_" + std::to_string(i)] = filament_preset->config.opt_string("inherits"); } } @@ -19361,12 +19343,12 @@ void Plater::record_slice_preset(std::string action) Preset& print_preset = wxGetApp().preset_bundle->prints.get_edited_preset(); if (print_preset.is_system) { j["process_preset"] = print_preset.name; - } else { + } + else { j["process_preset"] = print_preset.config.opt_string("inherits"); } j["support_type"] = ConfigOptionEnum::get_enum_names().at(print_preset.config.opt_enum("support_type")); - j["sparse_infill_pattern"] = ConfigOptionEnum::get_enum_names().at( - print_preset.config.opt_enum("sparse_infill_pattern")); + j["sparse_infill_pattern"] = ConfigOptionEnum::get_enum_names().at(print_preset.config.opt_enum("sparse_infill_pattern")); j["sparse_infill_density"] = print_preset.config.opt("sparse_infill_density")->value; j["brim_type"] = ConfigOptionEnum::get_enum_names().at(print_preset.config.opt_enum("brim_type")); @@ -19374,7 +19356,7 @@ void Plater::record_slice_preset(std::string action) if (p->background_process.fff_print()) { const DynamicPrintConfig& full_config = p->background_process.fff_print()->full_print_config(); - json values = json::array(); + json values = json::array(); if (full_config.has("different_settings_to_system")) { std::vector different_values = full_config.option("different_settings_to_system")->values; for (auto& item : different_values) { @@ -19384,26 +19366,28 @@ void Plater::record_slice_preset(std::string action) j["different_settings_to_system"] = values; } - j["record_event"] = action; + j["record_event"] = action; NetworkAgent* agent = wxGetApp().getAgent(); - } catch (...) { + } + catch (...) + { return; } } -// BBS: add project slicing related logic +//BBS: add project slicing related logic int Plater::start_next_slice() { // Stop arrange and (or) optimize rotation tasks. - // this->stop_jobs(); + //this->stop_jobs(); - // FIXME Don't reslice if export of G-code or sending to OctoPrint is running. - // bitmask of UpdateBackgroundProcessReturnState + //FIXME Don't reslice if export of G-code or sending to OctoPrint is running. + // bitmask of UpdateBackgroundProcessReturnState unsigned int state = this->p->update_background_process(true, false, false); if (state & priv::UPDATE_BACKGROUND_PROCESS_REFRESH_SCENE) this->p->view3D->reload_scene(false); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": update_background_process returns %1%") % state; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": update_background_process returns %1%")%state; if (!p->partplate_list.get_curr_plate()->can_slice()) { p->process_completed_with_error = p->partplate_list.get_curr_plate_index(); BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": found invalidated apply in update_background_process."); @@ -19412,27 +19396,34 @@ int Plater::start_next_slice() // Only restarts if the state is valid. bool result = this->p->restart_background_process(state | priv::UPDATE_BACKGROUND_PROCESS_FORCE_RESTART); - if (!result) { - // slice next - SlicingProcessCompletedEvent evt(EVT_PROCESS_COMPLETED, 0, SlicingProcessCompletedEvent::Finished, nullptr); + if (!result) + { + //slice next + SlicingProcessCompletedEvent evt(EVT_PROCESS_COMPLETED, 0, + SlicingProcessCompletedEvent::Finished, nullptr); // Post the "complete" callback message, so that it will slice the next plate soon wxQueueEvent(this, evt.Clone()); } - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": restart_background_process returns %1%") % result; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": restart_background_process returns %1%")%result; return 0; } -void Plater::reslice_SLA_supports(const ModelObject& object, bool postpone_error_messages) -{ reslice_SLA_until_step(slaposPad, object, postpone_error_messages); } -void Plater::reslice_SLA_hollowing(const ModelObject& object, bool postpone_error_messages) -{ reslice_SLA_until_step(slaposDrillHoles, object, postpone_error_messages); } - -void Plater::reslice_SLA_until_step(SLAPrintObjectStep step, const ModelObject& object, bool postpone_error_messages) +void Plater::reslice_SLA_supports(const ModelObject &object, bool postpone_error_messages) { - // FIXME Don't reslice if export of G-code or sending to OctoPrint is running. - // bitmask of UpdateBackgroundProcessReturnState + reslice_SLA_until_step(slaposPad, object, postpone_error_messages); +} + +void Plater::reslice_SLA_hollowing(const ModelObject &object, bool postpone_error_messages) +{ + reslice_SLA_until_step(slaposDrillHoles, object, postpone_error_messages); +} + +void Plater::reslice_SLA_until_step(SLAPrintObjectStep step, const ModelObject &object, bool postpone_error_messages) +{ + //FIXME Don't reslice if export of G-code or sending to OctoPrint is running. + // bitmask of UpdateBackgroundProcessReturnState unsigned int state = this->p->update_background_process(true, postpone_error_messages); if (state & priv::UPDATE_BACKGROUND_PROCESS_REFRESH_SCENE) this->p->view3D->reload_scene(false); @@ -19448,7 +19439,7 @@ void Plater::reslice_SLA_until_step(SLAPrintObjectStep step, const ModelObject& // Otherwise calculate everything, but start with the provided object. if (!this->p->background_processing_enabled()) { task.single_model_instance_only = true; - task.to_object_step = step; + task.to_object_step = step; } this->p->background_process.set_task(task); // and let the background processing start. @@ -19459,7 +19450,7 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) // if physical_printer is selected, send gcode for this printer // DynamicPrintConfig* physical_printer_config = wxGetApp().preset_bundle->physical_printers.get_selected_printer_config(); DynamicPrintConfig* physical_printer_config = &Slic3r::GUI::wxGetApp().preset_bundle->printers.get_edited_preset().config; - if (!physical_printer_config || p->model.objects.empty()) + if (! physical_printer_config || p->model.objects.empty()) return; PrintHostJob upload_job(physical_printer_config); @@ -19468,7 +19459,7 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) // Orca: the use_3mf printer option makes us send a .gcode.3mf to the printer const auto* use_3mf_opt = physical_printer_config->option("use_3mf"); - const bool use_3mf = use_3mf_opt != nullptr && use_3mf_opt->value; + const bool use_3mf = use_3mf_opt != nullptr && use_3mf_opt->value; upload_job.upload_data.use_3mf = use_3mf; // Orca: the concrete plate to export/send (PLATE_CURRENT_IDX resolves to the current plate). @@ -19482,7 +19473,8 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) unsigned int state = this->p->update_restart_background_process(false, false); if (state & priv::UPDATE_BACKGROUND_PROCESS_INVALID) return; - default_output_file = this->p->background_process.output_filepath_for_project(into_path(this->p->get_project_filename(".3mf"))); + default_output_file = this->p->background_process.output_filepath_for_project( + into_path(this->p->get_project_filename(".3mf"))); } catch (const Slic3r::PlaceholderParserError& ex) { // Show the error with monospaced font. show_error(this, ex.what(), true); @@ -19518,8 +19510,8 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) } { - auto preset_bundle = wxGetApp().preset_bundle; - auto config = get_app_config(); + auto preset_bundle = wxGetApp().preset_bundle; + auto config = get_app_config(); const auto host_type_opt = physical_printer_config->option>("host_type"); const auto host_type = host_type_opt != nullptr ? host_type_opt->value : htElegooLink; @@ -19534,8 +19526,8 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) storage_paths, storage_names, config->get_bool("open_device_tab_post_upload")); } else if (host_type == htCrealityPrint) { - pDlg = std::make_unique(default_output_file, upload_job.printhost->get_post_upload_actions(), - groups, storage_paths, storage_names, + pDlg = std::make_unique(default_output_file, upload_job.printhost->get_post_upload_actions(), groups, + storage_paths, storage_names, config->get_bool("open_device_tab_post_upload"), upload_job.printhost.get()); } else if (flashforge_local_api) { @@ -19546,10 +19538,10 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) } std::vector slots; - bool supports_material_station = false; + bool supports_material_station = false; { wxBusyCursor wait; - wxString msg; + wxString msg; if (!flashforge_host->fetch_material_slots(slots, &supports_material_station, msg)) { show_error(this, msg.empty() ? _L("Unable to log in to the Flashforge printer.") : msg, false); return; @@ -19557,10 +19549,10 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) } std::vector project_filaments; - PlateDataPtrs plate_data_list; - DynamicPrintConfig cfg = wxGetApp().preset_bundle->full_config(); - const auto* filament_color = dynamic_cast(cfg.option("filament_colour")); - const auto* filament_id_opt = dynamic_cast(cfg.option("filament_ids")); + PlateDataPtrs plate_data_list; + DynamicPrintConfig cfg = wxGetApp().preset_bundle->full_config(); + const auto* filament_color = dynamic_cast(cfg.option("filament_colour")); + const auto* filament_id_opt = dynamic_cast(cfg.option("filament_ids")); auto enrich_project_filaments = [&](std::vector& filaments) { for (auto& filament : filaments) { if (filament.id < 0) @@ -19569,7 +19561,8 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) std::string display_filament_type; try { filament.type = cfg.get_filament_type(display_filament_type, filament.id); - } catch (...) {} + } catch (...) { + } if (filament.type.empty()) filament.type = display_filament_type; @@ -19584,9 +19577,7 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) }; p->partplate_list.store_to_3mf_structure(plate_data_list, true, plate_idx); - PlateData* selected_plate_data = (resolved_plate_idx >= 0 && resolved_plate_idx < static_cast(plate_data_list.size())) ? - plate_data_list[resolved_plate_idx] : - nullptr; + PlateData* selected_plate_data = (resolved_plate_idx >= 0 && resolved_plate_idx < static_cast(plate_data_list.size())) ? plate_data_list[resolved_plate_idx] : nullptr; if (selected_plate_data == nullptr && !plate_data_list.empty()) selected_plate_data = plate_data_list.front(); @@ -19602,10 +19593,13 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) enrich_project_filaments(project_filaments); release_PlateData_list(plate_data_list); - pDlg = std::make_unique(default_output_file, upload_job.printhost->get_post_upload_actions(), - groups, storage_paths, storage_names, - config->get_bool("open_device_tab_post_upload"), flashforge_host, - supports_material_station, std::move(slots), project_filaments); + pDlg = std::make_unique(default_output_file, upload_job.printhost->get_post_upload_actions(), groups, + storage_paths, storage_names, + config->get_bool("open_device_tab_post_upload"), + flashforge_host, + supports_material_station, + std::move(slots), + project_filaments); } else { pDlg = std::make_unique(default_output_file, upload_job.printhost->get_post_upload_actions(), groups, storage_paths, storage_names, config->get_bool("open_device_tab_post_upload")); @@ -19618,11 +19612,11 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) config->set_bool("open_device_tab_post_upload", pDlg->switch_to_device_tab()); // PrintHostUpload upload_data; - upload_job.switch_to_device_tab = pDlg->switch_to_device_tab(); - upload_job.upload_data.upload_path = pDlg->filename(); - upload_job.upload_data.post_action = pDlg->post_action(); - upload_job.upload_data.group = pDlg->group(); - upload_job.upload_data.storage = pDlg->storage(); + upload_job.switch_to_device_tab = pDlg->switch_to_device_tab(); + upload_job.upload_data.upload_path = pDlg->filename(); + upload_job.upload_data.post_action = pDlg->post_action(); + upload_job.upload_data.group = pDlg->group(); + upload_job.upload_data.storage = pDlg->storage(); upload_job.upload_data.extended_info = pDlg->extendedInfo(); // Orca: gcode inside a .gcode.3mf is index-coded (Metadata/plate_.gcode) and a bundle may // carry several of them, so the upload must name which plate to print via a 1-based plateindex. @@ -19636,10 +19630,8 @@ void Plater::send_gcode_legacy(int plate_idx, Export3mfProgressFn proFn) } // Show "Is printer clean" dialog for PrusaConnect - Upload and print. - if (std::string(upload_job.printhost->get_name()) == "PrusaConnect" && - upload_job.upload_data.post_action == PrintHostPostUploadAction::StartPrint) { - GUI::MessageDialog dlg(nullptr, _L("Is the printer ready? Is the print sheet in place, empty and clean?"), _L("Upload and Print"), - wxOK | wxCANCEL); + if (std::string(upload_job.printhost->get_name()) == "PrusaConnect" && upload_job.upload_data.post_action == PrintHostPostUploadAction::StartPrint) { + GUI::MessageDialog dlg(nullptr, _L("Is the printer ready? Is the print sheet in place, empty and clean?"), _L("Upload and Print"), wxOK | wxCANCEL); if (dlg.ShowModal() != wxID_OK) return; } @@ -19669,14 +19661,15 @@ int Plater::send_gcode(int plate_idx, Export3mfProgressFn proFn) try { p->m_print_job_data._3mf_path = fs::path(plate->get_tmp_gcode_path()); p->m_print_job_data._3mf_path.replace_extension("3mf"); - } catch (std::exception&) { + } + catch (std::exception&) { BOOST_LOG_TRIVIAL(error) << "generate 3mf path failed"; return -1; } SaveStrategy strategy = SaveStrategy::Silence | SaveStrategy::SkipModel | SaveStrategy::WithGcode | SaveStrategy::SkipAuxiliary; #if !BBL_RELEASE_TO_PUBLIC - // only save model in QA environment + //only save model in QA environment std::string sel = get_app_config()->get("iot_environment"); if (sel == ENV_PRE_HOST) strategy = SaveStrategy::Silence | SaveStrategy::SplitModel | SaveStrategy::WithGcode; @@ -19696,19 +19689,20 @@ int Plater::export_config_3mf(int plate_idx, Export3mfProgressFn proFn) PartPlate* plate = get_partplate_list().get_curr_plate(); try { p->m_print_job_data._3mf_config_path = fs::path(plate->get_temp_config_3mf_path()); - } catch (std::exception&) { + } + catch (std::exception&) { BOOST_LOG_TRIVIAL(error) << "generate 3mf path failed"; return -1; } SaveStrategy strategy = SaveStrategy::Silence | SaveStrategy::SkipModel | SaveStrategy::WithSliceInfo | SaveStrategy::SkipAuxiliary; - result = export_3mf(p->m_print_job_data._3mf_config_path, strategy, plate_idx, proFn); + result = export_3mf(p->m_print_job_data._3mf_config_path, strategy, plate_idx, proFn); return result; } -// BBS -void Plater::send_calibration_job_finished(wxCommandEvent& evt) +//BBS +void Plater::send_calibration_job_finished(wxCommandEvent & evt) { p->main_frame->request_select_tab(TAB_ID_CALIBRATION); auto calibration_panel = p->main_frame->m_calibration; @@ -19722,9 +19716,9 @@ void Plater::send_calibration_job_finished(wxCommandEvent& evt) evt.Skip(); } -void Plater::print_job_finished(wxCommandEvent& evt) +void Plater::print_job_finished(wxCommandEvent &evt) { - // start print failed + //start print failed if (p) { #ifdef __APPLE__ p->hide_select_machine_dlg(); @@ -19737,60 +19731,63 @@ void Plater::print_job_finished(wxCommandEvent& evt) #endif // __APPLE__ } + Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); - if (!dev) - return; + if (!dev) return; dev->set_selected_machine(evt.GetString().ToStdString()); p->main_frame->request_select_tab(TAB_ID_MONITOR); - // jump to monitor and select device status panel + //jump to monitor and select device status panel MonitorPanel* curr_monitor = p->main_frame->m_monitor; - if (curr_monitor) - curr_monitor->get_tabpanel()->ChangeSelection(MonitorPanel::PrinterTab::PT_STATUS); + if(curr_monitor) + curr_monitor->get_tabpanel()->ChangeSelection(MonitorPanel::PrinterTab::PT_STATUS); } void Plater::send_job_finished(wxCommandEvent& evt) { Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); - if (!dev) - return; - // dev->set_selected_machine(evt.GetString().ToStdString()); + if (!dev) return; + //dev->set_selected_machine(evt.GetString().ToStdString()); send_gcode_finish(evt.GetString()); p->hide_send_to_printer_dlg(); - // p->main_frame->request_select_tab(TAB_ID_MONITOR); + //p->main_frame->request_select_tab(TAB_ID_MONITOR); ////jump to monitor and select device status panel - // MonitorPanel* curr_monitor = p->main_frame->m_monitor; - // if (curr_monitor) - // curr_monitor->get_tabpanel()->ChangeSelection(MonitorPanel::PrinterTab::PT_STATUS); + //MonitorPanel* curr_monitor = p->main_frame->m_monitor; + //if (curr_monitor) + // curr_monitor->get_tabpanel()->ChangeSelection(MonitorPanel::PrinterTab::PT_STATUS); } -void Plater::publish_job_finished(wxCommandEvent& evt) +void Plater::publish_job_finished(wxCommandEvent &evt) { p->m_publish_dlg->EndModal(wxID_OK); - // GUI::wxGetApp().load_url(evt.GetString()); - // GUI::wxGetApp().open_publish_page_dialog(evt.GetString()); + // GUI::wxGetApp().load_url(evt.GetString()); + //GUI::wxGetApp().open_publish_page_dialog(evt.GetString()); } // Called when the Eject button is pressed. void Plater::eject_drive() { - wxBusyCursor wait; + wxBusyCursor wait; wxGetApp().removable_drive_manager()->set_and_verify_last_save_path(p->last_output_dir_path); - wxGetApp().removable_drive_manager()->eject_drive(); + wxGetApp().removable_drive_manager()->eject_drive(); } -void Plater::take_snapshot(const std::string& snapshot_name) { p->take_snapshot(snapshot_name); } -// void Plater::take_snapshot(const wxString &snapshot_name) { p->take_snapshot(snapshot_name); } -void Plater::take_snapshot(const std::string& snapshot_name, UndoRedo::SnapshotType snapshot_type) -{ p->take_snapshot(snapshot_name, snapshot_type); } -// void Plater::take_snapshot(const wxString &snapshot_name, UndoRedo::SnapshotType snapshot_type) { p->take_snapshot(snapshot_name, -// snapshot_type); } +void Plater::take_snapshot(const std::string &snapshot_name) { p->take_snapshot(snapshot_name); } +//void Plater::take_snapshot(const wxString &snapshot_name) { p->take_snapshot(snapshot_name); } +void Plater::take_snapshot(const std::string &snapshot_name, UndoRedo::SnapshotType snapshot_type) { p->take_snapshot(snapshot_name, snapshot_type); } +//void Plater::take_snapshot(const wxString &snapshot_name, UndoRedo::SnapshotType snapshot_type) { p->take_snapshot(snapshot_name, snapshot_type); } void Plater::suppress_snapshots() { p->suppress_snapshots(); } void Plater::allow_snapshots() { p->allow_snapshots(); } // BBS: single snapshot -void Plater::single_snapshots_enter(SingleSnapshot* single) { p->single_snapshots_enter(single); } -void Plater::single_snapshots_leave(SingleSnapshot* single) { p->single_snapshots_leave(single); } +void Plater::single_snapshots_enter(SingleSnapshot *single) +{ + p->single_snapshots_enter(single); +} +void Plater::single_snapshots_leave(SingleSnapshot *single) +{ + p->single_snapshots_leave(single); +} void Plater::undo() { p->undo(); } void Plater::redo() { p->redo(); } void Plater::undo_to(int selection) @@ -19816,9 +19813,9 @@ void Plater::redo_to(int selection) bool Plater::undo_redo_string_getter(const bool is_undo, int idx, const char** out_text) { const std::vector& ss_stack = p->undo_redo_stack().snapshots(); - const int idx_in_ss_stack = p->get_active_snapshot_index() + (is_undo ? -(++idx) : idx); + const int idx_in_ss_stack = p->get_active_snapshot_index() + (is_undo ? -(++idx) : idx); - if (0 < idx_in_ss_stack && (size_t) idx_in_ss_stack < ss_stack.size() - 1) { + if (0 < idx_in_ss_stack && (size_t)idx_in_ss_stack < ss_stack.size() - 1) { *out_text = ss_stack[idx_in_ss_stack].name.c_str(); return true; } @@ -19826,19 +19823,18 @@ bool Plater::undo_redo_string_getter(const bool is_undo, int idx, const char** o return false; } -int Plater::update_print_required_data(Slic3r::DynamicPrintConfig config, - Slic3r::Model model, - Slic3r::PlateDataPtrs plate_data_list, - std::string file_name, - std::string file_path) -{ return p->update_print_required_data(config, model, plate_data_list, file_name, file_path); } +int Plater::update_print_required_data(Slic3r::DynamicPrintConfig config, Slic3r::Model model, Slic3r::PlateDataPtrs plate_data_list, std::string file_name, std::string file_path) +{ + return p->update_print_required_data(config, model, plate_data_list, file_name, file_path); +} + void Plater::undo_redo_topmost_string_getter(const bool is_undo, std::string& out_text) { const std::vector& ss_stack = p->undo_redo_stack().snapshots(); - const int idx_in_ss_stack = p->get_active_snapshot_index() + (is_undo ? -1 : 0); + const int idx_in_ss_stack = p->get_active_snapshot_index() + (is_undo ? -1 : 0); - if (0 < idx_in_ss_stack && (size_t) idx_in_ss_stack < ss_stack.size() - 1) { + if (0 < idx_in_ss_stack && (size_t)idx_in_ss_stack < ss_stack.size() - 1) { out_text = ss_stack[idx_in_ss_stack].name; return; } @@ -19850,7 +19846,7 @@ bool Plater::search_string_getter(int idx, const char** label, const char** tool { const Search::OptionsSearcher& search_list = p->sidebar->get_searcher(); - if (0 <= idx && (size_t) idx < search_list.size()) { + if (0 <= idx && (size_t)idx < search_list.size()) { search_list[idx].get_marked_label_and_tooltip(label, tooltip); return true; } @@ -19877,7 +19873,7 @@ void Plater::on_filament_count_change(size_t num_filaments) sidebar().on_filament_count_change(num_filaments); sidebar().obj_list()->update_objects_list_filament_column(num_filaments); - Slic3r::GUI::PartPlateList& plate_list = get_partplate_list(); + Slic3r::GUI::PartPlateList &plate_list = get_partplate_list(); plate_list.set_filament_count(num_filaments); for (int i = 0; i < plate_list.get_plate_count(); ++i) { PartPlate* part_plate = plate_list.get_plate(i); @@ -19891,16 +19887,13 @@ void Plater::on_filament_count_change(size_t num_filaments) } } -void Plater::on_filaments_delete(size_t num_filaments, - size_t filament_id, - int replace_filament_id, - const std::vector& is_mixed_before_delete) +void Plater::on_filaments_delete(size_t num_filaments, size_t filament_id, int replace_filament_id, const std::vector& is_mixed_before_delete) { // only update elements in plater update_filament_colors_in_full_config(); // update fisrt print sequence and other layer sequence - // move to partplate->on_filament_deleted + //move to partplate->on_filament_deleted /*Slic3r::GUI::PartPlateList &plate_list = get_partplate_list(); for (int i = 0; i < plate_list.get_plate_count(); ++i) { PartPlate *part_plate = plate_list.get_plate(i); @@ -19911,13 +19904,12 @@ void Plater::on_filaments_delete(size_t num_filaments, // A volume assigned to a mixed slot legitimately sits past the physical filament count, so // the paint cleanup must know which slots were mixed. Callers that already shrank the arrays // pass the pre-delete flags; otherwise read the current ones. - const auto& is_mixed = is_mixed_before_delete.empty() ? - wxGetApp().preset_bundle->project_config.option("filament_is_mixed")->values : - is_mixed_before_delete; - for (ModelObject* mo : wxGetApp().model().objects) { - for (ModelVolume* mv : mo->volumes) { - mv->update_extruder_count_when_delete_filament(num_filaments, filament_id + 1, replace_filament_id + 1, - is_mixed); // this function is 1 base + const auto &is_mixed = is_mixed_before_delete.empty() + ? wxGetApp().preset_bundle->project_config.option("filament_is_mixed")->values + : is_mixed_before_delete; + for (ModelObject *mo : wxGetApp().model().objects) { + for (ModelVolume *mv : mo->volumes) { + mv->update_extruder_count_when_delete_filament(num_filaments, filament_id + 1, replace_filament_id + 1, is_mixed); // this function is 1 base } } @@ -19927,10 +19919,10 @@ void Plater::on_filaments_delete(size_t num_filaments, sidebar().obj_list()->update_objects_list_filament_column_when_delete_filament(filament_id, num_filaments, replace_filament_id); // update global support filament - static const char* keys[] = {"support_filament", "support_interface_filament"}; + static const char *keys[] = {"support_filament", "support_interface_filament"}; for (auto key : keys) if (p->config->has(key)) { - if (p->config->opt_int(key) == filament_id + 1) + if(p->config->opt_int(key) == filament_id + 1) (*(p->config)).erase(key); else { int new_value = p->config->opt_int(key) > filament_id ? p->config->opt_int(key) - 1 : p->config->opt_int(key); @@ -19948,7 +19940,7 @@ void Plater::on_filaments_delete(size_t num_filaments, }); if (replace_filament_id == -1) item->second.gcodes.erase(iter, item->second.gcodes.end()); - else if (iter != item->second.gcodes.end()) { + else if(iter != item->second.gcodes.end()) { iter->extruder = replace_filament_id + 1; } @@ -19961,10 +19953,10 @@ void Plater::on_filaments_delete(size_t num_filaments, std::vector Plater::get_extruders_colors() { - unsigned char rgba_color[4] = {}; - std::vector colors = get_extruder_colors_from_plater_config(); + unsigned char rgba_color[4] = {}; + std::vector colors = get_extruder_colors_from_plater_config(); std::vector colors_out(colors.size()); - for (const std::string& color : colors) { + for (const std::string &color : colors) { Slic3r::GUI::BitmapCache::parse_color4(color, rgba_color); size_t color_idx = &color - &colors.front(); colors_out[color_idx] = { @@ -19977,21 +19969,24 @@ std::vector Plater::get_extruders_colors() return colors_out; } -void Plater::on_bed_type_change(BedType bed_type) { sidebar().on_bed_type_change(bed_type); } +void Plater::on_bed_type_change(BedType bed_type) +{ + sidebar().on_bed_type_change(bed_type); +} bool Plater::update_filament_colors_in_full_config() { - DynamicPrintConfig& project_config = wxGetApp().preset_bundle->project_config; - const auto& full_config = wxGetApp().preset_bundle->full_config(); - ConfigOptionStrings* color_opt = project_config.option("filament_colour"); + DynamicPrintConfig& project_config = wxGetApp().preset_bundle->project_config; + const auto& full_config = wxGetApp().preset_bundle->full_config(); + ConfigOptionStrings* color_opt = project_config.option("filament_colour"); const ConfigOptionStrings* type_opt = full_config.option("filament_type"); p->config->option("filament_colour")->values = color_opt->values; - p->config->option("filament_type")->values = type_opt->values; + p->config->option("filament_type")->values = type_opt->values; return true; } -void Plater::config_change_notification(const DynamicPrintConfig& config, const std::string& key) +void Plater::config_change_notification(const DynamicPrintConfig &config, const std::string& key) { GLCanvas3D* view3d_canvas = get_view3D_canvas3D(); if (key == std::string("print_sequence")) { @@ -20001,23 +19996,24 @@ void Plater::config_change_notification(const DynamicPrintConfig& config, const if (seq_print->value == PrintSequence::ByObject) { std::string info_text = _u8L("Print By Object: \nWe suggest using auto-arrange to avoid collisions when printing."); notify_manager->bbl_show_seqprintinfo_notification(info_text); - } else + } + else notify_manager->bbl_close_seqprintinfo_notification(); } } // notification for more options } -void Plater::on_config_change(const DynamicPrintConfig& config) +void Plater::on_config_change(const DynamicPrintConfig &config) { - bool update_scheduled = false; + bool update_scheduled = false; bool bed_shape_changed = false; - // bool print_sequence_changed = false; + //bool print_sequence_changed = false; t_config_option_keys diff_keys = p->config->diff(config); size_t old_nozzle_size = 1, new_nozzle_size = 1; - auto* opt_old = p->config->option("nozzle_diameter"); - auto* opt_new = config.option("nozzle_diameter"); + auto * opt_old = p->config->option("nozzle_diameter"); + auto * opt_new = config.option("nozzle_diameter"); if (opt_old && opt_new) { old_nozzle_size = opt_old->values.size(); new_nozzle_size = opt_new->values.size(); @@ -20059,34 +20055,43 @@ void Plater::on_config_change(const DynamicPrintConfig& config) p->reset_gcode_toolpaths(); p->view3D->get_canvas3d()->reset_sequential_print_clearance(); p->preview->get_canvas3d()->reset_volumes(); - // BBS: invalid all the slice results + //BBS: invalid all the slice results p->partplate_list.invalid_all_slice_result(); } - // BBS: add bed_exclude_area - else if (opt_key == "printable_area" || opt_key == "bed_exclude_area" || opt_key == "bed_custom_texture" || - opt_key == "bed_custom_model" || opt_key == "extruder_clearance_height_to_lid" || - opt_key == "extruder_clearance_height_to_rod") { + //BBS: add bed_exclude_area + else if (opt_key == "printable_area" || opt_key == "bed_exclude_area" + || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model" + || opt_key == "extruder_clearance_height_to_lid" + || opt_key == "extruder_clearance_height_to_rod") { bed_shape_changed = true; - update_scheduled = true; - } else if (opt_key == "bed_shape" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model") { + update_scheduled = true; + } + else if (opt_key == "bed_shape" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model") { bed_shape_changed = true; - update_scheduled = true; - } else if (boost::starts_with(opt_key, "enable_prime_tower") || boost::starts_with(opt_key, "prime_tower") || - boost::starts_with(opt_key, "wipe_tower") || opt_key == "filament_minimal_purge_on_wipe_tower" || - opt_key == "single_extruder_multi_material" || - // BBS - opt_key == "prime_volume") { update_scheduled = true; - } else if (opt_key == "extruder_colour") { + } + else if (boost::starts_with(opt_key, "enable_prime_tower") || + boost::starts_with(opt_key, "prime_tower") || + boost::starts_with(opt_key, "wipe_tower") || + opt_key == "filament_minimal_purge_on_wipe_tower" || + opt_key == "single_extruder_multi_material" || + // BBS + opt_key == "prime_volume") { update_scheduled = true; - // p->sidebar->obj_list()->update_extruder_colors(); - } else if (opt_key == "printable_height") { + } + else if(opt_key == "extruder_colour") { + update_scheduled = true; + //p->sidebar->obj_list()->update_extruder_colors(); + } + else if (opt_key == "printable_height") { bed_shape_changed = true; - update_scheduled = true; - } else if (opt_key == "print_sequence") { update_scheduled = true; - // print_sequence_changed = true; - } else if (opt_key == "printer_model") { + } + else if (opt_key == "print_sequence") { + update_scheduled = true; + //print_sequence_changed = true; + } + else if (opt_key == "printer_model") { p->reset_gcode_toolpaths(); if (old_nozzle_size != new_nozzle_size) { update_flush_volume_matrix(old_nozzle_size, new_nozzle_size); @@ -20094,11 +20099,12 @@ void Plater::on_config_change(const DynamicPrintConfig& config) // update to force bed selection(for texturing) bed_shape_changed = true; - update_scheduled = true; + update_scheduled = true; } // Orca: update when *_filament changed - else if (opt_key == "support_interface_filament" || opt_key == "support_filament" || opt_key == "outer_wall_filament_id" || - opt_key == "inner_wall_filament_id" || opt_key == "sparse_infill_filament_id" || opt_key == "internal_solid_filament_id" || + else if (opt_key == "support_interface_filament" || opt_key == "support_filament" || + opt_key == "outer_wall_filament_id" || opt_key == "inner_wall_filament_id" || + opt_key == "sparse_infill_filament_id" || opt_key == "internal_solid_filament_id" || opt_key == "top_surface_filament_id" || opt_key == "bottom_surface_filament_id") { update_scheduled = true; } @@ -20121,45 +20127,42 @@ void Plater::on_config_change(const DynamicPrintConfig& config) void Plater::update_flush_volume_matrix(size_t old_nozzle_size, size_t new_nozzle_size) { - size_t nozzle_nums = wxGetApp().preset_bundle->get_printer_extruder_count(); - Slic3r::DynamicPrintConfig* project_config = &wxGetApp().preset_bundle->project_config; + size_t nozzle_nums = wxGetApp().preset_bundle->get_printer_extruder_count(); + Slic3r::DynamicPrintConfig *project_config = &wxGetApp().preset_bundle->project_config; // Verify whether it is the first time start Studio - size_t filament_nums = project_config->option("filament_colour")->values.size(); + size_t filament_nums = project_config->option("filament_colour")->values.size(); size_t flush_volume_size = project_config->option("flush_volumes_matrix")->values.size(); assert(nozzle_nums == new_nozzle_size); if (old_nozzle_size < new_nozzle_size) { - std::vector first_flush_volume_mtx = - get_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, -1, old_nozzle_size); + + std::vector first_flush_volume_mtx = get_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, -1, old_nozzle_size); if (first_flush_volume_mtx.size() == filament_nums * filament_nums * new_nozzle_size) { // load file - set_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, first_flush_volume_mtx, -1, - new_nozzle_size); + set_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, first_flush_volume_mtx, -1, new_nozzle_size); } else { first_flush_volume_mtx.resize(filament_nums * filament_nums, 0); std::vector flush_volume_mtx; for (size_t i = 0; i < new_nozzle_size; ++i) { flush_volume_mtx.insert(flush_volume_mtx.end(), first_flush_volume_mtx.begin(), first_flush_volume_mtx.end()); } - set_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, flush_volume_mtx, -1, - new_nozzle_size); + set_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, flush_volume_mtx, -1, new_nozzle_size); } std::vector flush_multipliers = project_config->option("flush_multiplier")->values; flush_multipliers.resize(nozzle_nums, 1.f); project_config->option("flush_multiplier")->values = flush_multipliers; - } else if (old_nozzle_size > new_nozzle_size) { + } + else if (old_nozzle_size > new_nozzle_size) { std::vector new_flush_volume_mtx; for (size_t i = 0; i < new_nozzle_size; ++i) { - std::vector flush_volume_mtx = - get_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, -1, old_nozzle_size); + std::vector flush_volume_mtx = get_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, -1, old_nozzle_size); flush_volume_mtx.resize(filament_nums * filament_nums, 0); new_flush_volume_mtx.insert(new_flush_volume_mtx.end(), flush_volume_mtx.begin(), flush_volume_mtx.end()); } std::vector flush_multipliers = project_config->option("flush_multiplier")->values; flush_multipliers.resize(nozzle_nums, 1.f); - set_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, new_flush_volume_mtx, -1, - new_nozzle_size); + set_flush_volumes_matrix(project_config->option("flush_volumes_matrix")->values, new_flush_volume_mtx, -1, new_nozzle_size); project_config->option("flush_multiplier")->values = flush_multipliers; } } @@ -20173,43 +20176,32 @@ void Plater::set_bed_shape() const if (curr->is_system) texture_filename = PresetUtils::system_printer_bed_texture(*curr); else { - auto* printer_model = curr->config.opt("printer_model"); - if (printer_model != nullptr && !printer_model->value.empty()) { + auto *printer_model = curr->config.opt("printer_model"); + if (printer_model != nullptr && ! printer_model->value.empty()) { texture_filename = bundle->get_texture_for_printer_model(printer_model->value); } } } set_bed_shape(p->config->option("printable_area")->values, - // BBS: add bed exclude areas - p->config->option("bed_exclude_area")->values, - p->config->option("wrapping_exclude_area")->values, - p->config->option("printable_height")->value, - p->config->option("extruder_printable_area")->values, - p->config->option("extruder_printable_height")->values, - p->config->option("bed_custom_texture")->value.empty() ? - texture_filename : - p->config->option("bed_custom_texture")->value, - p->config->option("bed_custom_model")->value); + //BBS: add bed exclude areas + p->config->option("bed_exclude_area")->values, + p->config->option("wrapping_exclude_area")->values, + p->config->option("printable_height")->value, + p->config->option("extruder_printable_area")->values, + p->config->option("extruder_printable_height")->values, + p->config->option("bed_custom_texture")->value.empty() ? texture_filename : p->config->option("bed_custom_texture")->value, + p->config->option("bed_custom_model")->value); } -// BBS: add bed exclude area -void Plater::set_bed_shape(const Pointfs& shape, - const Pointfs& exclude_area, - const Pointfs& wrapping_exclude_area, - const double printable_height, - std::vector extruder_areas, - std::vector extruder_heights, - const std::string& custom_texture, - const std::string& custom_model, - bool force_as_custom) const +//BBS: add bed exclude area +void Plater::set_bed_shape(const Pointfs& shape, const Pointfs& exclude_area, const Pointfs& wrapping_exclude_area, const double printable_height, std::vector extruder_areas, std::vector extruder_heights, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom) const { - p->set_bed_shape(make_counter_clockwise(shape), exclude_area, wrapping_exclude_area, printable_height, extruder_areas, extruder_heights, - custom_texture, custom_model, force_as_custom); + p->set_bed_shape(make_counter_clockwise(shape), exclude_area, wrapping_exclude_area, printable_height, extruder_areas, extruder_heights, custom_texture, custom_model, force_as_custom); } void Plater::force_filament_colors_update() { -// BBS: filament_color logic has been moved out of filament setting +//BBS: filament_color logic has been moved out of filament setting #if 0 bool update_scheduled = false; DynamicPrintConfig* config = p->config; @@ -20242,12 +20234,15 @@ void Plater::force_filament_colors_update() void Plater::force_print_bed_update() { - // Fill in the printer model key with something which cannot possibly be valid, so that Plater::on_config_change() will update the print - // bed once a new Printer profile config is loaded. + // Fill in the printer model key with something which cannot possibly be valid, so that Plater::on_config_change() will update the print bed + // once a new Printer profile config is loaded. p->config->opt_string("printer_model", true) = "bbl_empty"; } -void Plater::on_activate() { this->p->show_delayed_error_message(); } +void Plater::on_activate() +{ + this->p->show_delayed_error_message(); +} // Get vector of extruder colors considering filament color, if extruder color is undefined. std::vector Plater::get_extruder_colors_from_plater_config(const GCodeProcessorResult* const result) const @@ -20270,9 +20265,8 @@ namespace { // A gradient mixed filament fades between its two components over Z, so the UI shows it as a // two-tone swatch rather than one blended colour. Resolve each slot to its from/to endpoint // colours; non-gradient slots are left untouched. -struct MixedGradientSlot -{ - bool is_gradient = false; +struct MixedGradientSlot { + bool is_gradient = false; std::string color_from; std::string color_to; }; @@ -20285,16 +20279,12 @@ std::vector parse_mixed_gradient_slots(const Slic3r::DynamicP const auto* mixed_comp = config.option("filament_mixed_components"); const auto* grad_range = config.option("filament_mixed_gradient_range"); const auto* fil_colour = config.option("filament_colour"); - if (!is_mixed || !mixed_grad || !mixed_comp || !fil_colour) - return result; + if (!is_mixed || !mixed_grad || !mixed_comp || !fil_colour) return result; for (size_t i = 0; i < slot_count && i < is_mixed->values.size(); ++i) { - if (!is_mixed->values[i]) - continue; - if (i >= mixed_grad->values.size() || !mixed_grad->values[i]) - continue; - if (i >= mixed_comp->values.size()) - continue; + if (!is_mixed->values[i]) continue; + if (i >= mixed_grad->values.size() || !mixed_grad->values[i]) continue; + if (i >= mixed_comp->values.size()) continue; std::vector comp_ids; std::istringstream iss(mixed_comp->values[i]); @@ -20304,8 +20294,7 @@ std::vector parse_mixed_gradient_slots(const Slic3r::DynamicP if (std::sscanf(tok.c_str(), "%u", &v) == 1) comp_ids.push_back(v); } - if (comp_ids.size() != 2) - continue; + if (comp_ids.size() != 2) continue; int direction = 0; if (grad_range && i < grad_range->values.size()) { @@ -20315,11 +20304,13 @@ std::vector parse_mixed_gradient_slots(const Slic3r::DynamicP direction = (v0 > v1) ? 0 : 1; } - unsigned int from_id = (direction == 0) ? comp_ids[0] : comp_ids[1]; - unsigned int to_id = (direction == 0) ? comp_ids[1] : comp_ids[0]; + unsigned int from_id = (direction == 0) ? comp_ids[0] : comp_ids[1]; + unsigned int to_id = (direction == 0) ? comp_ids[1] : comp_ids[0]; result[i].is_gradient = true; - result[i].color_from = (from_id >= 1 && from_id <= fil_colour->values.size()) ? fil_colour->values[from_id - 1] : "#D9D9D9"; - result[i].color_to = (to_id >= 1 && to_id <= fil_colour->values.size()) ? fil_colour->values[to_id - 1] : "#D9D9D9"; + result[i].color_from = (from_id >= 1 && from_id <= fil_colour->values.size()) + ? fil_colour->values[from_id - 1] : "#D9D9D9"; + result[i].color_to = (to_id >= 1 && to_id <= fil_colour->values.size()) + ? fil_colour->values[to_id - 1] : "#D9D9D9"; } return result; } @@ -20330,8 +20321,7 @@ std::vector Plater::get_filament_colors_render_info() const { const Slic3r::DynamicPrintConfig* config = &wxGetApp().preset_bundle->project_config; std::vector color_packs; - if (!config->has("filament_multi_colour")) - return color_packs; + if (!config->has("filament_multi_colour")) return color_packs; color_packs = (config->option("filament_multi_colour"))->values; @@ -20346,16 +20336,14 @@ std::vector Plater::get_filament_colors_render_info() const std::vector Plater::get_filament_color_render_type() const { - const Slic3r::DynamicPrintConfig* config = &wxGetApp().preset_bundle->project_config; - std::vector ctype; - if (!config->has("filament_colour_type")) - return ctype; + const Slic3r::DynamicPrintConfig *config = &wxGetApp().preset_bundle->project_config; + std::vector ctype; + if (!config->has("filament_colour_type")) return ctype; ctype = (config->option("filament_colour_type"))->values; auto slots = parse_mixed_gradient_slots(*config, ctype.size()); - while (ctype.size() < slots.size()) - ctype.push_back("1"); + while (ctype.size() < slots.size()) ctype.push_back("1"); for (size_t i = 0; i < ctype.size() && i < slots.size(); ++i) { if (slots[i].is_gradient) ctype[i] = "0"; @@ -20371,11 +20359,12 @@ const std::vector>& Plater::get_filament_gradient_ramps() // are built from. The cache is static rather than a Plater member because the extruder icons // ask for the ramps from MenuFactory::init(), which runs while this Plater is still inside its // own constructor, so wxGetApp().plater_ is not assigned yet. - static std::string s_ramps_key; + static std::string s_ramps_key; static std::vector> s_ramps; - static const char* ramp_keys[] = {"filament_is_mixed", "filament_mixed_gradient", "filament_mixed_components", - "filament_colour", "filament_mixed_gradient_range", "filament_mixed_gradient_curve"}; + static const char* ramp_keys[] = {"filament_is_mixed", "filament_mixed_gradient", + "filament_mixed_components", "filament_colour", + "filament_mixed_gradient_range", "filament_mixed_gradient_curve"}; const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->project_config; std::string key; @@ -20387,8 +20376,8 @@ const std::vector>& Plater::get_filament_gradient_ramps() // 64 bands outresolve every swatch drawn from this, all of which resample it down to their // own height, so one cached resolution serves the icons and both ImGui filament bars. - const auto* colour_opt = config.option("filament_colour"); - const size_t n = colour_opt ? colour_opt->values.size() : 0; + const auto* colour_opt = config.option("filament_colour"); + const size_t n = colour_opt ? colour_opt->values.size() : 0; s_ramps.assign(n, {}); for (size_t i = 0; i < n; ++i) s_ramps[i] = mixed_gradient_ramp(config, i, 64); @@ -20409,8 +20398,9 @@ std::vector Plater::get_colors_for_color_print(const GCodeProcessor if (code.type == CustomGCode::ColorChange) colors.emplace_back(code.color); } - } else { - // BBS + } + else { + //BBS colors.reserve(colors.size() + p->model.get_curr_plate_custom_gcodes().gcodes.size()); for (const CustomGCode::Item& code : p->model.get_curr_plate_custom_gcodes().gcodes) { if (code.type == CustomGCode::ColorChange) @@ -20423,23 +20413,23 @@ std::vector Plater::get_colors_for_color_print(const GCodeProcessor void Plater::set_global_filament_map_mode(FilamentMapMode mode) { - auto& project_config = wxGetApp().preset_bundle->project_config; - auto mode_ptr = project_config.option>("filament_map_mode"); + auto& project_config = wxGetApp().preset_bundle->project_config; + auto mode_ptr = project_config.option>("filament_map_mode"); FilamentMapMode old_mode = mode_ptr->value; - if (mode != old_mode) + if(mode != old_mode) on_filament_map_mode_change(); mode_ptr->value = mode; } void Plater::set_global_filament_map(const std::vector& filament_map) { - auto& project_config = wxGetApp().preset_bundle->project_config; + auto& project_config = wxGetApp().preset_bundle->project_config; project_config.option("filament_map")->values = filament_map; } void Plater::set_global_filament_volume_map(const std::vector& filament_volume_map) { - auto& project_config = wxGetApp().preset_bundle->project_config; + auto& project_config = wxGetApp().preset_bundle->project_config; project_config.option("filament_volume_map")->values = filament_volume_map; } @@ -20455,6 +20445,7 @@ std::vector Plater::get_global_filament_volume_map() const return project_config.option("filament_volume_map")->values; } + FilamentMapMode Plater::get_global_filament_map_mode() const { auto& project_config = wxGetApp().preset_bundle->project_config; @@ -20464,16 +20455,19 @@ FilamentMapMode Plater::get_global_filament_map_mode() const void Plater::on_filament_map_mode_change() { auto& plate_list = this->get_partplate_list(); - int plate_count = plate_list.get_plate_count(); + int plate_count = plate_list.get_plate_count(); for (int idx = 0; idx < plate_count; ++idx) { - auto plate = plate_list.get_plate(idx); + auto plate=plate_list.get_plate(idx); auto plate_map_mode = plate->get_filament_map_mode(); if (plate_map_mode == fmmDefault) plate->clear_filament_map(); } } -wxWindow* Plater::get_select_machine_dialog() { return p->m_select_machine_dlg; } +wxWindow* Plater::get_select_machine_dialog() +{ + return p->m_select_machine_dlg; +} void Plater::update_print_error_info(int code, std::string msg, std::string extra) { @@ -20488,20 +20482,40 @@ void Plater::update_print_error_info(int code, std::string msg, std::string extr p->main_frame->m_calibration->update_print_error_info(code, msg, extra); } -wxString Plater::get_project_filename(const wxString& extension) const { return p->get_project_filename(extension); } +wxString Plater::get_project_filename(const wxString& extension) const +{ + return p->get_project_filename(extension); +} -wxString Plater::get_export_gcode_filename(const wxString& extension, bool only_filename, bool export_all) const -{ return p->get_export_gcode_filename(extension, only_filename, export_all); } +wxString Plater::get_export_gcode_filename(const wxString & extension, bool only_filename, bool export_all) const +{ + return p->get_export_gcode_filename(extension, only_filename, export_all); +} -void Plater::set_project_filename(const wxString& filename) { p->set_project_filename(filename); } +void Plater::set_project_filename(const wxString& filename) +{ + p->set_project_filename(filename); +} -bool Plater::is_export_gcode_scheduled() const { return p->background_process.is_export_scheduled(); } +bool Plater::is_export_gcode_scheduled() const +{ + return p->background_process.is_export_scheduled(); +} -const Selection& Plater::get_selection() const { return p->get_selection(); } +const Selection &Plater::get_selection() const +{ + return p->get_selection(); +} -int Plater::get_selected_object_idx() { return p->get_selected_object_idx(); } +int Plater::get_selected_object_idx() +{ + return p->get_selected_object_idx(); +} -bool Plater::is_single_full_object_selection() const { return p->get_selection().is_single_full_object(); } +bool Plater::is_single_full_object_selection() const +{ + return p->get_selection().is_single_full_object(); +} GLCanvas3D* Plater::canvas3D() { @@ -20515,9 +20529,15 @@ const GLCanvas3D* Plater::canvas3D() const return p->get_current_canvas3D(); } -GLCanvas3D* Plater::get_view3D_canvas3D() { return p ? p->view3D->get_canvas3d() : nullptr; } +GLCanvas3D* Plater::get_view3D_canvas3D() +{ + return p ? p->view3D->get_canvas3d() : nullptr; +} -GLCanvas3D* Plater::get_preview_canvas3D() { return p->preview->get_canvas3d(); } +GLCanvas3D* Plater::get_preview_canvas3D() +{ + return p->preview->get_canvas3d(); +} GLCanvas3D* Plater::get_assmeble_canvas3D() { @@ -20526,36 +20546,51 @@ GLCanvas3D* Plater::get_assmeble_canvas3D() return nullptr; } -GLCanvas3D* Plater::get_current_canvas3D(bool exclude_preview) { return p->get_current_canvas3D(exclude_preview); } +GLCanvas3D* Plater::get_current_canvas3D(bool exclude_preview) +{ + return p->get_current_canvas3D(exclude_preview); +} void Plater::arrange() { - auto& w = get_ui_job_worker(); + auto &w = get_ui_job_worker(); if (w.is_idle()) { p->take_snapshot(_u8L("Arrange")); replace_job(w, std::make_unique()); } } -void Plater::set_current_canvas_as_dirty() { p->set_current_canvas_as_dirty(); } +void Plater::set_current_canvas_as_dirty() +{ + p->set_current_canvas_as_dirty(); +} -void Plater::unbind_canvas_event_handlers() { p->unbind_canvas_event_handlers(); } +void Plater::unbind_canvas_event_handlers() +{ + p->unbind_canvas_event_handlers(); +} -void Plater::reset_canvas_volumes() { p->reset_canvas_volumes(); } +void Plater::reset_canvas_volumes() +{ + p->reset_canvas_volumes(); +} -PrinterTechnology Plater::printer_technology() const { return p->printer_technology; } +PrinterTechnology Plater::printer_technology() const +{ + return p->printer_technology; +} -const DynamicPrintConfig* Plater::config() const { return p->config; } +const DynamicPrintConfig * Plater::config() const { return p->config; } bool Plater::set_printer_technology(PrinterTechnology printer_technology) { p->printer_technology = printer_technology; - bool ret = p->background_process.select_technology(printer_technology); + bool ret = p->background_process.select_technology(printer_technology); if (ret) { // Update the active presets. } - // FIXME for SLA synchronize - // p->background_process.apply(Model)! + //FIXME for SLA synchronize + //p->background_process.apply(Model)! if (printer_technology == ptSLA) { for (ModelObject* model_object : p->model.objects) { @@ -20564,7 +20599,7 @@ bool Plater::set_printer_technology(PrinterTechnology printer_technology) } p->label_btn_export = printer_technology == ptFFF ? L("Export G-code") : L("Export"); - p->label_btn_send = printer_technology == ptFFF ? L("Send G-code") : L("Send to printer"); + p->label_btn_send = printer_technology == ptFFF ? L("Send G-code") : L("Send to printer"); if (wxGetApp().mainframe != nullptr) wxGetApp().mainframe->update_menubar(); @@ -20585,8 +20620,7 @@ void Plater::clear_before_change_mesh(int obj_idx) // may be different and they would make no sense. bool paint_removed = false; for (ModelVolume* mv : mo->volumes) { - paint_removed |= !mv->supported_facets.empty() || !mv->seam_facets.empty() || !mv->mmu_segmentation_facets.empty() || - !mv->fuzzy_skin_facets.empty(); + paint_removed |= ! mv->supported_facets.empty() || ! mv->seam_facets.empty() || ! mv->mmu_segmentation_facets.empty() || !mv->fuzzy_skin_facets.empty(); mv->supported_facets.reset(); mv->seam_facets.reset(); mv->mmu_segmentation_facets.reset(); @@ -20594,9 +20628,10 @@ void Plater::clear_before_change_mesh(int obj_idx) } if (paint_removed) { // snapshot_time is captured by copy so the lambda knows where to undo/redo to. - get_notification_manager()->push_notification(NotificationType::CustomSupportsAndSeamRemovedAfterRepair, - NotificationManager::NotificationLevel::PrintInfoNotificationLevel, - _u8L("Custom supports and color painting were removed before repairing.")); + get_notification_manager()->push_notification( + NotificationType::CustomSupportsAndSeamRemovedAfterRepair, + NotificationManager::NotificationLevel::PrintInfoNotificationLevel, + _u8L("Custom supports and color painting were removed before repairing.")); } } @@ -20609,8 +20644,7 @@ void Plater::changed_mesh(int obj_idx) p->schedule_background_process(); } -void Plater::changed_object(ModelObject& object) -{ +void Plater::changed_object(ModelObject &object){ assert(object.get_model() == &p->model); // is object from same model? object.invalidate_bounding_box(); @@ -20626,7 +20660,7 @@ void Plater::changed_object(ModelObject& object) // update print p->schedule_background_process(); - + // Check outside bed get_current_canvas3D()->requires_check_outside_state(); } @@ -20635,7 +20669,7 @@ void Plater::changed_object(int obj_idx) { if (obj_idx < 0) return; - ModelObject* object = p->model.objects[obj_idx]; + ModelObject *object = p->model.objects[obj_idx]; if (object == nullptr) return; changed_object(*object); @@ -20657,7 +20691,8 @@ void Plater::changed_objects(const std::vector& object_idxs) // Update the SLAPrint from the current Model, so that the reload_scene() // pulls the correct data, update the 3D scene. this->p->update_restart_background_process(true, false); - } else { + } + else { p->view3D->reload_scene(false); p->view3D->get_canvas3d()->update_instance_printable_state_for_objects(object_idxs); } @@ -20666,7 +20701,7 @@ void Plater::changed_objects(const std::vector& object_idxs) this->p->schedule_background_process(); } -void Plater::schedule_background_process(bool schedule /* = true*/) +void Plater::schedule_background_process(bool schedule/* = true*/) { if (schedule) this->p->schedule_background_process(); @@ -20674,7 +20709,10 @@ void Plater::schedule_background_process(bool schedule /* = true*/) this->p->suppressed_backround_processing_update = false; } -bool Plater::is_background_process_update_scheduled() const { return this->p->background_process_timer.IsRunning(); } +bool Plater::is_background_process_update_scheduled() const +{ + return this->p->background_process_timer.IsRunning(); +} void Plater::suppress_background_process(const bool stop_background_process) { @@ -20687,29 +20725,28 @@ void Plater::suppress_background_process(const bool stop_background_process) // Expose the slicing process to the device GUI. BackgroundSlicingProcess& Plater::background_process() { return p->background_process; } -void Plater::center_selection() { p->center_selection(); } -void Plater::drop_selection() { p->drop_selection(); } -void Plater::mirror(Axis axis) { p->mirror(axis); } -void Plater::split_object(bool auto_drop) { p->split_object(auto_drop); } -void Plater::split_volume() { p->split_volume(); } +void Plater::center_selection() { p->center_selection(); } +void Plater::drop_selection() { p->drop_selection(); } +void Plater::mirror(Axis axis) { p->mirror(axis); } +void Plater::split_object(bool auto_drop) { p->split_object(auto_drop); } +void Plater::split_volume() { p->split_volume(); } void Plater::optimize_rotation() { - auto& w = get_ui_job_worker(); + auto &w = get_ui_job_worker(); if (w.is_idle()) { p->take_snapshot(_u8L("Optimize Rotation")); replace_job(w, std::make_unique()); } } -void Plater::update_menus() { p->menus.update(); } +void Plater::update_menus() { p->menus.update(); } -wxString Plater::get_selected_printer_name_in_combox() -{ - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - std::string printer_model = preset_bundle->printers.get_selected_preset().config.option("printer_model")->value; +wxString Plater::get_selected_printer_name_in_combox() { + PresetBundle * preset_bundle = wxGetApp().preset_bundle; + std::string printer_model = preset_bundle->printers.get_selected_preset().config.option("printer_model")->value; return printer_model; } -void Plater::pop_warning_and_go_to_device_page(wxString printer_name, PrinterWarningType type, const wxString& title) +void Plater::pop_warning_and_go_to_device_page(wxString printer_name, PrinterWarningType type, const wxString &title) { printer_name.Replace("Bambu Lab", "", false); wxString content; @@ -20723,16 +20760,14 @@ void Plater::pop_warning_and_go_to_device_page(wxString printer_name, PrinterWar _L("OrcaSlicer can't connect to %s. Please check if the printer is powered on and connected to the network."), printer_name); } } else if (type == PrinterWarningType::INCONSISTENT) { - content = wxString::Format(_L("The currently connected printer on the device page is not %s. Please switch to %s before syncing."), - printer_name, printer_name); + content = wxString::Format(_L("The currently connected printer on the device page is not %s. Please switch to %s before syncing."), printer_name, printer_name); } else if (type == PrinterWarningType::UNINSTALL_FILAMENT) { content = _L("There are no filaments on the printer. Please load the filaments on the printer first."); } else if (type == PrinterWarningType::EMPTY_FILAMENT) { - content = _L("The filaments on the printer are all unknown types. Please go to the printer screen or software device page to set " - "the filament type."); + content = _L("The filaments on the printer are all unknown types. Please go to the printer screen or software device page to set the filament type."); } MessageDialog dlg(this, content, title, wxOK | wxFORWARD | wxICON_WARNING, _L("Device Page")); - auto result = dlg.ShowModal(); + auto result = dlg.ShowModal(); if (result == wxFORWARD) { wxGetApp().mainframe->select_tab(TAB_ID_MONITOR); } @@ -20743,13 +20778,13 @@ bool Plater::is_same_printer_for_connected_and_selected(bool popup_warning) if (!wxGetApp().getDeviceManager()) { return false; } - MachineObject* obj = wxGetApp().getDeviceManager()->get_selected_machine(); + MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine(); if (obj == nullptr) { return false; } if (!check_printer_initialized(obj, true, popup_warning)) return false; - Preset* machine_preset = get_printer_preset(obj); + Preset * machine_preset = get_printer_preset(obj); if (!machine_preset) return false; @@ -20763,7 +20798,7 @@ bool Plater::is_same_printer_for_connected_and_selected(bool popup_warning) return true; } // BBS -// void Plater::show_action_buttons(const bool ready_to_slice) const { p->show_action_buttons(ready_to_slice); } +//void Plater::show_action_buttons(const bool ready_to_slice) const { p->show_action_buttons(ready_to_slice); } void Plater::fill_color(int extruder_id) { @@ -20772,7 +20807,7 @@ void Plater::fill_color(int extruder_id) } } -// BBS +//BBS void Plater::cut_selection_to_clipboard() { Plater::TakeSnapshot snapshot(this, "Cut Selected Objects"); @@ -20804,7 +20839,7 @@ void Plater::paste_from_clipboard() p->view3D->get_canvas3d()->get_selection().paste_from_clipboard(); } -// BBS: add clone +//BBS: add clone void Plater::clone_selection() { if (is_selection_empty()) @@ -20815,13 +20850,13 @@ void Plater::clone_selection() std::vector Plater::get_empty_cells(const Vec2f step) { - PartPlate* plate = wxGetApp().plater()->get_partplate_list().get_curr_plate(); + PartPlate* plate = wxGetApp().plater()->get_partplate_list().get_curr_plate(); BoundingBoxf3 build_volume = plate->get_build_volume(true); Vec2d vmin(build_volume.min.x(), build_volume.min.y()), vmax(build_volume.max.x(), build_volume.max.y()); BoundingBoxf bbox(vmin, vmax); std::vector cells; - auto min_x = step(0) / 2; // start_point.x() - step(0) * int((start_point.x() - bbox.min.x()) / step(0)); - auto min_y = step(1) / 2; // start_point.y() - step(1) * int((start_point.y() - bbox.min.y()) / step(1)); + auto min_x = step(0)/2;// start_point.x() - step(0) * int((start_point.x() - bbox.min.x()) / step(0)); + auto min_y = step(1)/2;// start_point.y() - step(1) * int((start_point.y() - bbox.min.y()) / step(1)); auto& exclude_box3s = plate->get_exclude_areas(); std::vector exclude_boxs; for (auto& box : exclude_box3s) { @@ -20838,14 +20873,14 @@ std::vector Plater::get_empty_cells(const Vec2f step) break; } } - if (in_exclude) + if(in_exclude) continue; cells.emplace_back(x, y); } return cells; } -void Plater::search(bool plater_is_active, Preset::Type type, wxWindow* tag, TextInput* etag, wxWindow* stag) +void Plater::search(bool plater_is_active, Preset::Type type, wxWindow *tag, TextInput *etag, wxWindow *stag) { if (plater_is_active) { if (is_preview_shown()) @@ -20856,12 +20891,13 @@ void Plater::search(bool plater_is_active, Preset::Type type, wxWindow* tag, Tex wxKeyEvent evt; #ifdef __APPLE__ evt.m_keyCode = 'f'; -#else /* __APPLE__ */ +#else /* __APPLE__ */ evt.m_keyCode = WXK_CONTROL_F; #endif /* __APPLE__ */ evt.SetControlDown(true); canvas3D()->on_char(evt); - } else + } + else p->sidebar->get_searcher().show_dialog(type, tag, etag, stag); } @@ -20884,8 +20920,7 @@ void Plater::sys_color_changed() p->preview->sys_color_changed(); p->sidebar->sys_color_changed(); p->menus.sys_color_changed(); - if (p->m_select_machine_dlg) - p->m_select_machine_dlg->sys_color_changed(); + if (p->m_select_machine_dlg) p->m_select_machine_dlg->sys_color_changed(); Layout(); GetParent()->Layout(); @@ -20904,48 +20939,60 @@ void Plater::enable_view_toolbar(bool enable) } #endif -bool Plater::init_collapse_toolbar() { return p->init_collapse_toolbar(); } +bool Plater::init_collapse_toolbar() +{ + return p->init_collapse_toolbar(); +} -const Camera& Plater::get_camera() const { return p->camera; } +const Camera& Plater::get_camera() const +{ + return p->camera; +} -Camera& Plater::get_camera() { return p->camera; } +Camera& Plater::get_camera() +{ + return p->camera; +} -// BBS: partplate list related functions -PartPlateList& Plater::get_partplate_list() { return p->partplate_list; } +//BBS: partplate list related functions +PartPlateList& Plater::get_partplate_list() +{ + return p->partplate_list; +} void Plater::apply_background_progress() { - PartPlate* part_plate = p->partplate_list.get_curr_plate(); - int plate_index = p->partplate_list.get_curr_plate_index(); - bool result_valid = part_plate->is_slice_result_valid(); + PartPlate* part_plate = p->partplate_list.get_curr_plate(); + int plate_index = p->partplate_list.get_curr_plate_index(); + bool result_valid = part_plate->is_slice_result_valid(); const auto& preset_bundle = wxGetApp().preset_bundle; - // always apply the current plate's print + //always apply the current plate's print Print::ApplyStatus invalidated; if (preset_bundle->get_printer_extruder_count() > 1) { - std::vector f_maps = part_plate->get_real_filament_maps(preset_bundle->project_config); + std::vector f_maps = part_plate->get_real_filament_maps(preset_bundle->project_config); std::vector f_volume_maps = part_plate->get_filament_volume_maps(); if (f_volume_maps.empty()) { f_volume_maps = preset_bundle->get_default_nozzle_volume_types_for_filaments(f_maps); } invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false, f_maps, f_volume_maps)); - } else + } + else invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false)); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(" %1%: plate %2%, after apply, invalidated= %3%, previous result_valid %4% ") % __LINE__ % - plate_index % invalidated % result_valid; - if (invalidated & PrintBase::APPLY_STATUS_INVALIDATED) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, after apply, invalidated= %3%, previous result_valid %4% ") % __LINE__ % plate_index % invalidated % result_valid; + if (invalidated & PrintBase::APPLY_STATUS_INVALIDATED) + { part_plate->update_slice_result_valid_state(false); - // p->ready_to_slice = true; + //p->ready_to_slice = true; p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, true); } } -// BBS: select Plate +//BBS: select Plate int Plater::select_plate(int plate_index, bool need_slice) { int ret; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, need_slice %3% ") % __LINE__ % plate_index % need_slice; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, need_slice %3% ")%__LINE__ %plate_index %need_slice; take_snapshot("select partplate!"); ret = p->partplate_list.select_plate(plate_index); if (!ret) { @@ -20954,106 +21001,124 @@ int Plater::select_plate(int plate_index, bool need_slice) } const auto& preset_bundle = wxGetApp().preset_bundle; - if ((!ret) && (p->background_process.can_switch_print())) { - // select successfully + if ((!ret) && (p->background_process.can_switch_print())) + { + //select successfully p->partplate_list.update_slice_context_to_current_plate(p->background_process); p->preview->update_gcode_result(p->partplate_list.get_current_slice_result()); p->update_print_volume_state(); - PartPlate* part_plate = p->partplate_list.get_curr_plate(); - bool result_valid = part_plate->is_slice_result_valid(); - PrintBase* print = nullptr; + PartPlate* part_plate = p->partplate_list.get_curr_plate(); + bool result_valid = part_plate->is_slice_result_valid(); + PrintBase* print = nullptr; GCodeResult* gcode_result = nullptr; Print::ApplyStatus invalidated; part_plate->get_print(&print, &gcode_result, NULL); - // always apply the current plate's print + //always apply the current plate's print if (preset_bundle->get_printer_extruder_count() > 1) { - std::vector f_maps = part_plate->get_real_filament_maps(preset_bundle->project_config); + std::vector f_maps = part_plate->get_real_filament_maps(preset_bundle->project_config); std::vector f_volume_maps = part_plate->get_filament_volume_maps(); if (f_volume_maps.empty()) { f_volume_maps = preset_bundle->get_default_nozzle_volume_types_for_filaments(f_maps); } invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false, f_maps, f_volume_maps)); - } else + } + else invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false)); bool model_fits, validate_err; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(" %1%: plate %2%, after apply, invalidated= %3%, previous result_valid %4% ") % __LINE__ % - plate_index % invalidated % result_valid; - if (result_valid) { - if (is_preview_shown()) { - if (need_slice) { // from preview's thumbnail - if ((invalidated & PrintBase::APPLY_STATUS_INVALIDATED) || (gcode_result->moves.empty())) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, after apply, invalidated= %3%, previous result_valid %4% ")%__LINE__ %plate_index %invalidated %result_valid; + if (result_valid) + { + if (is_preview_shown()) + { + if (need_slice) { //from preview's thumbnail + if ((invalidated & PrintBase::APPLY_STATUS_INVALIDATED) || (gcode_result->moves.empty())){ if (invalidated & PrintBase::APPLY_STATUS_INVALIDATED) part_plate->update_slice_result_valid_state(false); p->process_completed_with_error = -1; - p->m_slice_all = false; + p->m_slice_all = false; reset_gcode_toolpaths(); reslice(); - } else { + } + else { validate_current_plate(model_fits, validate_err); - // just refresh_print + //just refresh_print reload_print(); p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, false, true); } - } else { // from multiple slice's next - // do nothing } - } else { + else {// from multiple slice's next + //do nothing + } + } + else + { validate_current_plate(model_fits, validate_err); - if (invalidated & PrintBase::APPLY_STATUS_INVALIDATED) { + if (invalidated & PrintBase::APPLY_STATUS_INVALIDATED) + { part_plate->update_slice_result_valid_state(false); // BBS - // p->show_action_buttons(true); - // p->ready_to_slice = true; + //p->show_action_buttons(true); + //p->ready_to_slice = true; p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, true); - } else { + } + else + { // BBS - // p->show_action_buttons(false); - // p->ready_to_slice = false; + //p->show_action_buttons(false); + //p->ready_to_slice = false; p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, false); reload_print(); } } - } else { - // check inside status - // model_fits = p->view3D->get_canvas3d()->check_volumes_outside_state() != ModelInstancePVS_Partly_Outside; - // bool validate_err = false; + } + else + { + //check inside status + //model_fits = p->view3D->get_canvas3d()->check_volumes_outside_state() != ModelInstancePVS_Partly_Outside; + //bool validate_err = false; validate_current_plate(model_fits, validate_err); if (model_fits && !validate_err) { p->process_completed_with_error = -1; - } else { + } + else { p->process_completed_with_error = p->partplate_list.get_curr_plate_index(); } - if (is_preview_shown()) { - if (need_slice) { - // p->process_completed_with_error = -1; + if (is_preview_shown()) + { + if (need_slice) + { + //p->process_completed_with_error = -1; p->m_slice_all = false; reset_gcode_toolpaths(); if (model_fits && !validate_err) { - if (!check_ams_status(false)) { + if (!check_ams_status(false)){ return ret; } reslice(); - } else { + } + else { p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, false); - // sometimes the previous print's sliced result is still valid, but the newly added object is laid over the boundary - // then the print toolpath will be shown, so we should not refresh print here, only onload shell - // refresh_print(); + //sometimes the previous print's sliced result is still valid, but the newly added object is laid over the boundary + //then the print toolpath will be shown, so we should not refresh print here, only onload shell + //refresh_print(); p->update_fff_scene_only_shells(); } - } else { - // p->ready_to_slice = false; + } + else { + //p->ready_to_slice = false; p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, false); reload_print(); } - } else { - // validate_current_plate(model_fits, validate_err); - // check inside status + } + else + { + //validate_current_plate(model_fits, validate_err); + //check inside status /*if (model_fits && !validate_err){ p->process_completed_with_error = -1; } @@ -21062,13 +21127,16 @@ int Plater::select_plate(int plate_index, bool need_slice) }*/ // BBS: don't show action buttons - // p->show_action_buttons(true); - // p->ready_to_slice = true; - if (model_fits && part_plate->has_printable_instances()) { - // p->view3D->get_canvas3d()->post_event(Event(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, true)); + //p->show_action_buttons(true); + //p->ready_to_slice = true; + if (model_fits && part_plate->has_printable_instances()) + { + //p->view3D->get_canvas3d()->post_event(Event(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, true)); p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, true); - } else { - // p->view3D->get_canvas3d()->post_event(Event(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, false)); + } + else + { + //p->view3D->get_canvas3d()->post_event(Event(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, false)); p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, false); } } @@ -21078,7 +21146,7 @@ int Plater::select_plate(int plate_index, bool need_slice) SimpleEvent event(EVT_GLCANVAS_PLATE_SELECT); p->on_plate_selected(event); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, return %3%") % __LINE__ % plate_index % ret; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, return %3%")%__LINE__ %plate_index %ret; return ret; } @@ -21089,12 +21157,13 @@ int Plater::select_sliced_plate(int plate_index, bool skip_zoom) Freeze(); ret = select_plate(plate_index, true); - if (ret) { + if (ret) + { BOOST_LOG_TRIVIAL(error) << "select_plate error for plate_idx=" << plate_index; Thaw(); return -1; } - if (skip_zoom) + if(skip_zoom) p->partplate_list.select_plate_view(); Thaw(); @@ -21110,13 +21179,11 @@ void Plater::validate_current_plate(bool& model_fits, bool& validate_error) { ObjectFilamentResults object_results; ModelInstanceEPrintVolumeState state = p->view3D->get_canvas3d()->check_volumes_outside_state(&object_results); - model_fits = (state != ModelInstancePVS_Partly_Outside); + model_fits = (state != ModelInstancePVS_Partly_Outside); - PartPlate* cur_plate = wxGetApp().plater()->get_partplate_list().get_curr_plate(); - if (model_fits) { // TPU check - bool tpu_valid = cur_plate->check_tpu_printable_status(wxGetApp().preset_bundle->full_config(), - wxGetApp().preset_bundle->get_used_tpu_filaments( - cur_plate->get_extruders(true))); + PartPlate *cur_plate = wxGetApp().plater()->get_partplate_list().get_curr_plate(); + if (model_fits) { // TPU check + bool tpu_valid = cur_plate->check_tpu_printable_status(wxGetApp().preset_bundle->full_config(), wxGetApp().preset_bundle->get_used_tpu_filaments(cur_plate->get_extruders(true))); model_fits &= tpu_valid; } @@ -21126,23 +21193,19 @@ void Plater::validate_current_plate(bool& model_fits, bool& validate_error) model_fits &= filament_printable; } - model_fits = model_fits && object_results.filaments.empty(); + model_fits = model_fits && object_results.filaments.empty(); validate_error = false; if (p->printer_technology == ptFFF) { - // std::string plater_text = _u8L("An object is laid over the boundary of plate or exceeds the height limit.\n" - // "Please solve the problem by moving it totally on or off the plate, and confirming that the height is within the - // build volume.");; + //std::string plater_text = _u8L("An object is laid over the boundary of plate or exceeds the height limit.\n" + // "Please solve the problem by moving it totally on or off the plate, and confirming that the height is within the build volume.");; std::vector warnings; Polygons polygons; std::vector> height_polygons; - p->background_process.fff_print()->set_check_multi_filaments_compatibility( - wxGetApp().app_config->get("enable_high_low_temp_mixed_printing") == "false"); + p->background_process.fff_print()->set_check_multi_filaments_compatibility(wxGetApp().app_config->get("enable_high_low_temp_mixed_printing") == "false"); StringObjectException err = p->background_process.validate(&warnings, &polygons, &height_polygons); // update string by type post_process_string_object_exception(err); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": validate err=%1%, warnings=%2%, model_fits %3%") % err.string % warnings.size() % - model_fits; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": validate err=%1%, warnings=%2%, model_fits %3%")%err.string%warnings.size() %model_fits; if (err.string.empty()) { p->partplate_list.get_curr_plate()->update_apply_result_invalid(false); @@ -21154,13 +21217,14 @@ void Plater::validate_current_plate(bool& model_fits, bool& validate_error) p->view3D->get_canvas3d()->reset_sequential_print_clearance(); p->view3D->get_canvas3d()->set_as_dirty(); p->view3D->get_canvas3d()->request_extra_frame(); - } else { + } + else { // The print is not valid. p->partplate_list.get_curr_plate()->update_apply_result_invalid(true); // Show error as notification. p->notification_manager->push_validate_error_notification(err); p->process_validation_warnings(warnings); - // model_fits = false; + //model_fits = false; validate_error = true; p->view3D->get_canvas3d()->set_sequential_print_clearance_visible(true); p->view3D->get_canvas3d()->set_sequential_print_clearance_render_fill(true); @@ -21170,25 +21234,25 @@ void Plater::validate_current_plate(bool& model_fits, bool& validate_error) std::string clashed_text = get_object_clashed_text(); if (state == ModelInstancePVS_Partly_Outside) { p->notification_manager->push_plater_error_notification(clashed_text); - } else { + } + else { p->notification_manager->close_plater_error_notification(clashed_text); } - std::string left_unprintable_text = get_left_extruder_unprintable_text(), - right_unprintable_text = get_right_extruder_unprintable_text(); - if (!left_unprintable_text.empty()) { - p->notification_manager->bbl_show_filament_map_invalid_notification_before_slice(NotificationType::LeftExtruderUnprintableError, - left_unprintable_text); - } else { - p->notification_manager->bbl_close_filament_map_invalid_notification_before_slice( - NotificationType::LeftExtruderUnprintableError); + std::string left_unprintable_text = get_left_extruder_unprintable_text(), right_unprintable_text = get_right_extruder_unprintable_text(); + if (!left_unprintable_text.empty()) + { + p->notification_manager->bbl_show_filament_map_invalid_notification_before_slice(NotificationType::LeftExtruderUnprintableError, left_unprintable_text); + } + else { + p->notification_manager->bbl_close_filament_map_invalid_notification_before_slice(NotificationType::LeftExtruderUnprintableError); } - if (!right_unprintable_text.empty()) { - p->notification_manager->bbl_show_filament_map_invalid_notification_before_slice(NotificationType::RightExtruderUnprintableError, - right_unprintable_text); - } else { - p->notification_manager->bbl_close_filament_map_invalid_notification_before_slice( - NotificationType::RightExtruderUnprintableError); + if (!right_unprintable_text.empty()) + { + p->notification_manager->bbl_show_filament_map_invalid_notification_before_slice(NotificationType::RightExtruderUnprintableError,right_unprintable_text); + } + else { + p->notification_manager->bbl_close_filament_map_invalid_notification_before_slice(NotificationType::RightExtruderUnprintableError); } /*if (state == ModelInstancePVS_Limited) { @@ -21246,18 +21310,16 @@ bool Plater::refresh_missing_plugin_block(bool* block_toggled) std::vector refs = missing_refs(missing); std::sort(refs.begin(), refs.end()); std::string sig; - for (const std::string& r : refs) { - sig += r; - sig += '\n'; - } + for (const std::string& r : refs) { sig += r; sig += '\n'; } return sig; }; // Show/refresh the non-closable notification for one missing set. Only (re)create it when the // set changes; pushing every validate would close+recreate it (flicker, reset hover) since // validate runs on many triggers. shown_sig also gates plugin-load re-validation. - const auto update = [&](NotificationType type, const std::vector& missing, std::string* shown_sig, - const std::string& header, const std::string& resolve_label, + const auto update = [&](NotificationType type, const std::vector& missing, + std::string* shown_sig, const std::string& header, + const std::string& resolve_label, std::function resolve_action) { if (missing.empty()) { if (!shown_sig->empty()) { @@ -21272,49 +21334,46 @@ bool Plater::refresh_missing_plugin_block(bool* block_toggled) for (const auto& m : missing) body.emplace_back(JumpTo{m.ref.capability_name, m.opt, m.opt_type}); - p->notification_manager->push_plugin_missing_notification(type, header, resolve_label, std::move(body), - std::move(resolve_action)); + p->notification_manager->push_plugin_missing_notification( + type, header, resolve_label, std::move(body), std::move(resolve_action)); *shown_sig = sig; } }; - const std::vector missing_cloud = get_missing_cloud_plugins(); - const std::vector missing_local = get_missing_local_plugins(); + const std::vector missing_cloud = get_missing_cloud_plugins(); + const std::vector missing_local = get_missing_local_plugins(); const std::vector missing_cloud_refs = missing_refs(missing_cloud); const std::vector missing_local_refs = missing_refs(missing_local); - update(NotificationType::OrcaCloudPluginMissingError, missing_cloud, &p->m_cloud_missing_shown_sig, - _u8L("OrcaCloud plugins required by the current preset are not installed:"), _u8L("Install Plugins"), - [this, missing_cloud_refs](wxEvtHandler*) { - install_missing_cloud_plugins(missing_cloud_refs); - return false; - }); + update(NotificationType::OrcaCloudPluginMissingError, missing_cloud, + &p->m_cloud_missing_shown_sig, + _u8L("OrcaCloud plugins required by the current preset are not installed:"), + _u8L("Install Plugins"), + [this, missing_cloud_refs](wxEvtHandler*) { install_missing_cloud_plugins(missing_cloud_refs); return false; }); // "Find on OrcaCloud" is only a suggestion: it opens the browser but cannot resolve the missing // plugin in-session, so it never closes the notification or unblocks slicing. The user resolves a // local plugin by installing it or by changing the setting that needs it. - update(NotificationType::OrcaLocalPluginMissingError, missing_local, &p->m_local_missing_shown_sig, - _u8L("Local plugins required by the current preset are missing:"), _u8L("Find on OrcaCloud"), - [missing_local_refs](wxEvtHandler*) { - open_missing_plugins_on_cloud(missing_local_refs); - return false; - }); + update(NotificationType::OrcaLocalPluginMissingError, missing_local, + &p->m_local_missing_shown_sig, + _u8L("Local plugins required by the current preset are missing:"), + _u8L("Find on OrcaCloud"), + [missing_local_refs](wxEvtHandler*) { open_missing_plugins_on_cloud(missing_local_refs); return false; }); - const std::vector inactive = get_inactive_plugins(); - const std::vector broken = get_broken_plugins(); - const std::vector inactive_refs = missing_refs(inactive); - const std::vector broken_refs = missing_refs(broken); + const std::vector inactive = get_inactive_plugins(); + const std::vector broken = get_broken_plugins(); + const std::vector inactive_refs = missing_refs(inactive); + const std::vector broken_refs = missing_refs(broken); - update(NotificationType::OrcaPluginInactiveError, inactive, &p->m_inactive_shown_sig, - _u8L("Plugins required by the current preset are not activated:"), _u8L("Activate Now"), [this, inactive_refs](wxEvtHandler*) { - enable_inactive_plugins(inactive_refs); - return false; - }); - update(NotificationType::OrcaPluginCapabilityUnavailableError, broken, &p->m_broken_shown_sig, - _u8L("The installed plugin does not provide the required capability — it may be outdated:"), _u8L("Find on OrcaCloud"), - [broken_refs](wxEvtHandler*) { - open_missing_plugins_on_cloud(broken_refs); - return false; - }); + update(NotificationType::OrcaPluginInactiveError, inactive, + &p->m_inactive_shown_sig, + _u8L("Plugins required by the current preset are not activated:"), + _u8L("Activate Now"), + [this, inactive_refs](wxEvtHandler*) { enable_inactive_plugins(inactive_refs); return false; }); + update(NotificationType::OrcaPluginCapabilityUnavailableError, broken, + &p->m_broken_shown_sig, + _u8L("The installed plugin does not provide the required capability — it may be outdated:"), + _u8L("Find on OrcaCloud"), + [broken_refs](wxEvtHandler*) { open_missing_plugins_on_cloud(broken_refs); return false; }); const bool blocked = has_missing_plugins() || has_inactive_plugins() || has_broken_plugins(); if (block_toggled) @@ -21326,8 +21385,8 @@ void Plater::revalidate_current_plate_if_plugins_missing() { // Only do work while a missing-plugin notification is up, so the plugin-load hook does not // trigger a full validation for every plugin that loads during normal startup/use. - if (p->m_local_missing_shown_sig.empty() && p->m_cloud_missing_shown_sig.empty() && p->m_inactive_shown_sig.empty() && - p->m_broken_shown_sig.empty()) + if (p->m_local_missing_shown_sig.empty() && p->m_cloud_missing_shown_sig.empty() && + p->m_inactive_shown_sig.empty() && p->m_broken_shown_sig.empty()) return; bool model_fits = true, validate_error = false; validate_current_plate(model_fits, validate_error); @@ -21344,14 +21403,15 @@ void Plater::install_missing_cloud_plugins(const std::vector& cloud std::atomic cancel{false}; std::atomic finished{false}; std::atomic torn_down{false}; - std::mutex mtx; - std::string message; + std::mutex mtx; + std::string message; }; auto state = std::make_shared(); state->message = _u8L("Preparing to install plugins..."); wxWindow* parent = wxGetApp().mainframe; - auto* dialog = new wxProgressDialog(_L("Installing plugins"), from_u8(state->message), 100, parent, wxPD_APP_MODAL | wxPD_CAN_ABORT); + auto* dialog = new wxProgressDialog(_L("Installing plugins"), from_u8(state->message), 100, + parent, wxPD_APP_MODAL | wxPD_CAN_ABORT); dialog->Pulse(); // UI-thread timer: animate the pulse, observe the Cancel button, and tear down when the worker @@ -21409,8 +21469,7 @@ bool Plater::plugins_block_slicing() const return has_missing_plugins() || has_inactive_plugins() || has_broken_plugins(); } -void Plater::open_platesettings_dialog(wxCommandEvent& evt) -{ +void Plater::open_platesettings_dialog(wxCommandEvent& evt) { int plate_index = evt.GetInt(); PlateSettingsDialog dlg(this, _L("Plate Settings"), evt.GetString() == "only_layer_sequence"); PartPlate* curr_plate = p->partplate_list.get_curr_plate(); @@ -21419,7 +21478,8 @@ void Plater::open_platesettings_dialog(wxCommandEvent& evt) auto curr_print_seq = curr_plate->get_print_seq(); if (curr_print_seq != PrintSequence::ByDefault) { dlg.sync_print_seq(int(curr_print_seq) + 1); - } else + } + else dlg.sync_print_seq(0); auto first_layer_print_seq = curr_plate->get_first_layer_print_sequence(); @@ -21439,8 +21499,8 @@ void Plater::open_platesettings_dialog(wxCommandEvent& evt) dlg.Bind(EVT_SET_BED_TYPE_CONFIRM, [this, plate_index, &dlg](wxCommandEvent& e) { PartPlate* curr_plate = p->partplate_list.get_curr_plate(); - BedType old_bed_type = curr_plate->get_bed_type(); - auto bt_sel = dlg.get_bed_type_choice(); + BedType old_bed_type = curr_plate->get_bed_type(); + auto bt_sel = dlg.get_bed_type_choice(); if (old_bed_type != bt_sel) { curr_plate->set_bed_type(bt_sel); update_project_dirty_from_presets(); @@ -21467,54 +21527,63 @@ void Plater::open_platesettings_dialog(wxCommandEvent& evt) int spiral_sel = dlg.get_spiral_mode_choice(); if (spiral_sel == 1) { curr_plate->set_spiral_vase_mode(true, false); - } else if (spiral_sel == 2) { + } + else if (spiral_sel == 2) { curr_plate->set_spiral_vase_mode(false, false); - } else { + } + else { curr_plate->set_spiral_vase_mode(false, true); } update_project_dirty_from_presets(); set_plater_dirty(true); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format("select print sequence %1% for plate %2% at plate side") % ps_sel % plate_index; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("select print sequence %1% for plate %2% at plate side") % ps_sel % plate_index; auto plate_config = *(curr_plate->config()); wxGetApp().plater()->config_change_notification(plate_config, std::string("print_sequence")); update(); wxGetApp().obj_list()->update_selections(); - }); + }); dlg.set_plate_name(from_u8(curr_plate->get_plate_name())); dlg.ShowModal(); curr_plate->set_plate_name(dlg.get_plate_name().ToUTF8().data()); } -void Plater::open_filament_map_setting_dialog(wxCommandEvent& evt) +void Plater::open_filament_map_setting_dialog(wxCommandEvent &evt) { PartPlate* curr_plate = p->partplate_list.get_curr_plate(); - int value = evt.GetInt(); // 1 means from gcode view - bool need_slice = value == 1; // If from gcode view, should slice + int value = evt.GetInt(); //1 means from gcode view + bool need_slice = value ==1; // If from gcode view, should slice const auto& project_config = wxGetApp().preset_bundle->project_config; - auto filament_colors = config()->option("filament_colour")->values; - auto filament_types = config()->option("filament_type")->values; + auto filament_colors = config()->option("filament_colour")->values; + auto filament_types = config()->option("filament_type")->values; - auto plate_filament_maps = curr_plate->get_real_filament_maps(project_config); - auto plate_filament_map_mode = curr_plate->get_filament_map_mode(); + auto plate_filament_maps = curr_plate->get_real_filament_maps(project_config); + auto plate_filament_map_mode = curr_plate->get_filament_map_mode(); auto plate_filament_volume_maps = curr_plate->get_real_filament_volume_maps(project_config); - if (plate_filament_maps.size() != filament_colors.size()) // refine it later, save filament map to app config + if (plate_filament_maps.size() != filament_colors.size()) // refine it later, save filament map to app config plate_filament_maps.resize(filament_colors.size(), 1); if (plate_filament_volume_maps.size() != filament_colors.size()) plate_filament_volume_maps.resize(filament_colors.size(), 0); - FilamentMapDialog filament_dlg(this, filament_colors, filament_types, plate_filament_maps, plate_filament_volume_maps, - curr_plate->get_extruders(true), plate_filament_map_mode, this->get_machine_sync_status(), false); + FilamentMapDialog filament_dlg(this, + filament_colors, + filament_types, + plate_filament_maps, + plate_filament_volume_maps, + curr_plate->get_extruders(true), + plate_filament_map_mode, + this->get_machine_sync_status(), + false + ); if (filament_dlg.ShowModal() == wxID_OK) { std::vector new_filament_maps = filament_dlg.get_filament_maps(); std::vector old_filament_maps = curr_plate->get_real_filament_maps(project_config); - FilamentMapMode old_map_mode = curr_plate->get_filament_map_mode(); - FilamentMapMode new_map_mode = filament_dlg.get_mode(); + FilamentMapMode old_map_mode = curr_plate->get_filament_map_mode(); + FilamentMapMode new_map_mode = filament_dlg.get_mode(); std::vector new_filament_volume_maps = filament_dlg.get_filament_volume_maps(); std::vector old_filament_volume_maps = curr_plate->get_real_filament_volume_maps(project_config); @@ -21523,18 +21592,20 @@ void Plater::open_filament_map_setting_dialog(wxCommandEvent& evt) curr_plate->set_filament_map_mode(new_map_mode); } - if (new_map_mode == fmmManual) { + if (new_map_mode == fmmManual){ curr_plate->set_filament_maps(new_filament_maps); curr_plate->set_filament_volume_maps(new_filament_volume_maps); } - bool need_invalidate = (old_map_mode != new_map_mode || old_filament_maps != new_filament_maps || + bool need_invalidate = (old_map_mode != new_map_mode || + old_filament_maps != new_filament_maps || old_filament_volume_maps != new_filament_volume_maps); if (need_invalidate) { if (need_slice) { wxPostEvent(this, SimpleEvent(EVT_GLTOOLBAR_SLICE_PLATE)); - } else { + } + else { curr_plate->update_slice_result_valid_state(false); set_plater_dirty(true); update(); @@ -21544,7 +21615,8 @@ void Plater::open_filament_map_setting_dialog(wxCommandEvent& evt) return; } -// BBS: select Plate by hover_id + +//BBS: select Plate by hover_id int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModidyPlateName) { int ret; @@ -21553,121 +21625,145 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi plate_index = hover_id / PartPlate::GRABBER_COUNT; action = isModidyPlateName ? PartPlate::PLATE_NAME_HOVER_ID : hover_id % PartPlate::GRABBER_COUNT; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": enter, hover_id %1%, plate_index %2%, action %3%") % hover_id % plate_index % action; - if (action == 0) { - // select plate + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, hover_id %1%, plate_index %2%, action %3%")%hover_id % plate_index %action; + if (action == 0) + { + //select plate ret = p->partplate_list.select_plate(plate_index); if (!ret) { SimpleEvent event(EVT_GLCANVAS_PLATE_SELECT); p->on_plate_selected(event); } - if ((!ret) && (p->background_process.can_switch_print())) { - // select successfully + if ((!ret)&&(p->background_process.can_switch_print())) + { + //select successfully p->partplate_list.update_slice_context_to_current_plate(p->background_process); p->preview->update_gcode_result(p->partplate_list.get_current_slice_result()); p->update_print_volume_state(); - PartPlate* part_plate = p->partplate_list.get_curr_plate(); - bool result_valid = part_plate->is_slice_result_valid(); - PrintBase* print = nullptr; + PartPlate* part_plate = p->partplate_list.get_curr_plate(); + bool result_valid = part_plate->is_slice_result_valid(); + PrintBase* print = nullptr; GCodeResult* gcode_result = nullptr; Print::ApplyStatus invalidated; const auto& preset_bundle = wxGetApp().preset_bundle; part_plate->get_print(&print, &gcode_result, NULL); - // always apply the current plate's print + //always apply the current plate's print if (preset_bundle->get_printer_extruder_count() > 1) { - std::vector f_maps = part_plate->get_real_filament_maps(preset_bundle->project_config); + std::vector f_maps = part_plate->get_real_filament_maps(preset_bundle->project_config); std::vector f_volume_maps = part_plate->get_filament_volume_maps(); if (f_volume_maps.empty()) { f_volume_maps = preset_bundle->get_default_nozzle_volume_types_for_filaments(f_maps); } invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false, f_maps, f_volume_maps)); - } else + } + else invalidated = p->background_process.apply(this->model(), preset_bundle->full_config(false)); bool model_fits, validate_err; validate_current_plate(model_fits, validate_err); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(" %1%: after apply, invalidated= %2%, previous result_valid %3% ") % __LINE__ % - invalidated % result_valid; - if (result_valid) { - if (invalidated & PrintBase::APPLY_STATUS_INVALIDATED) { - // bool model_fits, validate_err; - // validate_current_plate(model_fits, validate_err); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: after apply, invalidated= %2%, previous result_valid %3% ")%__LINE__ % invalidated %result_valid; + if (result_valid) + { + if (invalidated & PrintBase::APPLY_STATUS_INVALIDATED) + { + //bool model_fits, validate_err; + //validate_current_plate(model_fits, validate_err); part_plate->update_slice_result_valid_state(false); // BBS - // p->show_action_buttons(true); - // p->ready_to_slice = true; + //p->show_action_buttons(true); + //p->ready_to_slice = true; p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, true); - } else { + } + else + { // BBS - // p->show_action_buttons(false); - // validate_current_plate(model_fits, validate_err); - // p->ready_to_slice = false; + //p->show_action_buttons(false); + //validate_current_plate(model_fits, validate_err); + //p->ready_to_slice = false; p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, false); reload_print(); } - } else { - // check inside status - if (model_fits && !validate_err) { + } + else + { + //check inside status + if (model_fits && !validate_err){ p->process_completed_with_error = -1; - } else { + } + else { p->process_completed_with_error = p->partplate_list.get_curr_plate_index(); } // BBS: don't show action buttons - // p->show_action_buttons(true); - // p->ready_to_slice = true; - if (model_fits && part_plate->has_printable_instances()) { - // p->view3D->get_canvas3d()->post_event(Event(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, true)); + //p->show_action_buttons(true); + //p->ready_to_slice = true; + if (model_fits && part_plate->has_printable_instances()) + { + //p->view3D->get_canvas3d()->post_event(Event(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, true)); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": will set can_slice to true"); p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, true); - } else { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ - << boost::format(": will set can_slice to false, has_printable_instances %1%") % - part_plate->has_printable_instances(); - // p->view3D->get_canvas3d()->post_event(Event(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, false)); + } + else + { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": will set can_slice to false, has_printable_instances %1%")%part_plate->has_printable_instances(); + //p->view3D->get_canvas3d()->post_event(Event(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, false)); p->main_frame->update_slice_print_status(MainFrame::eEventPlateUpdate, false); } } } - } else if ((action == 1) && (!right_click)) { - // delete plate + } + else if ((action == 1)&&(!right_click)) + { + //delete plate ret = delete_plate(plate_index); - } else if ((action == 2) && (!right_click)) { - // arrange the plate - // take_snapshot("select_orient partplate"); + } + else if ((action == 2)&&(!right_click)) + { + //arrange the plate + //take_snapshot("select_orient partplate"); ret = select_plate(plate_index); - if (!ret) { + if (!ret) + { set_prepare_state(Job::PREPARE_STATE_MENU); orient(); - } else { + } + else + { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "can not select plate %1%" << plate_index; ret = -1; } - } else if ((action == 3) && (!right_click)) { - // arrange the plate - // take_snapshot("select_arrange partplate"); + } + else if ((action == 3)&&(!right_click)) + { + //arrange the plate + //take_snapshot("select_arrange partplate"); ret = select_plate(plate_index); - if (!ret) { + if (!ret) + { if (last_arrange_job_is_finished()) { set_prepare_state(Job::PREPARE_STATE_MENU); arrange(); } - } else { + } + else + { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "can not select plate %1%" << plate_index; ret = -1; } - } else if ((action == 4) && (!right_click)) { - // lock the plate + } + else if ((action == 4)&&(!right_click)) + { + //lock the plate take_snapshot("lock partplate"); ret = p->partplate_list.lock_plate(plate_index, !p->partplate_list.is_locked(plate_index)); - } else if ((action == 5) && (!right_click)) { + } + else if ((action == 5)&&(!right_click)) + { // set the plate type ret = select_plate(plate_index); if (!ret) { @@ -21681,10 +21777,11 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "can not select plate %1%" << plate_index; ret = -1; } - } else if ((action == PartPlate::PLATE_FILAMENT_MAP_ID) && (!right_click)) { + } + else if ((action == PartPlate::PLATE_FILAMENT_MAP_ID) && (!right_click)) { ret = select_plate(plate_index); if (!ret) { - PartPlate* curr_plate = p->partplate_list.get_curr_plate(); + PartPlate * curr_plate = p->partplate_list.get_curr_plate(); wxCommandEvent evt(EVT_OPEN_FILAMENT_MAP_SETTINGS_DIALOG); evt.SetInt(0); // 0 means not from gcodeviewer evt.SetEventObject(this); @@ -21693,17 +21790,18 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "can not select plate %1%" << plate_index; ret = -1; } - } else if ((action == 6) && (!right_click)) { + } + else if ((action == 6) && (!right_click)) { // set the plate type ret = select_plate(plate_index); if (!ret) { PlateNameEditDialog dlg(this, wxID_ANY, _L("Edit Plate Name")); - PartPlate* curr_plate = p->partplate_list.get_curr_plate(); + PartPlate * curr_plate = p->partplate_list.get_curr_plate(); wxString curr_plate_name = from_u8(curr_plate->get_plate_name()); dlg.set_plate_name(curr_plate_name); - int result = dlg.ShowModal(); + int result=dlg.ShowModal(); if (result == wxID_YES) { wxString dlg_plate_name = dlg.get_plate_name(); curr_plate->set_plate_name(dlg_plate_name.ToUTF8().data()); @@ -21715,7 +21813,7 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi } else if ((action == 7) && (!right_click)) { // move plate to the front take_snapshot("move plate to the front"); - ret = p->partplate_list.move_plate_to_index(plate_index, 0); + ret = p->partplate_list.move_plate_to_index(plate_index,0); p->partplate_list.update_slice_context_to_current_plate(p->background_process); p->preview->update_gcode_result(p->partplate_list.get_current_slice_result()); p->sidebar->obj_list()->reload_all_plates(); @@ -21724,12 +21822,13 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi p->partplate_list.select_plate(0); } - else { + else + { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "invalid action %1%, with right_click=%2%" << action << right_click; ret = -1; } - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: return %2%") % __LINE__ % ret; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: return %2%")%__LINE__ % ret; return ret; } @@ -21741,12 +21840,12 @@ int Plater::duplicate_plate(int plate_index) ret = p->partplate_list.duplicate_plate(index); - // need to call update + //need to call update update(); return ret; } -// BBS: delete the plate, index= -1 means the current plate +//BBS: delete the plate, index= -1 means the current plate int Plater::delete_plate(int plate_index) { int index = plate_index, ret; @@ -21757,41 +21856,47 @@ int Plater::delete_plate(int plate_index) take_snapshot("delete partplate"); ret = p->partplate_list.delete_plate(index); - // BBS: update the current print to the current plate + //BBS: update the current print to the current plate p->partplate_list.update_slice_context_to_current_plate(p->background_process); p->preview->update_gcode_result(p->partplate_list.get_current_slice_result()); p->sidebar->obj_list()->reload_all_plates(); // BBS update default view - // get_camera().select_view("topfront"); - // get_camera().requires_zoom_to_plate = REQUIRES_ZOOM_TO_ALL_PLATE; + //get_camera().select_view("topfront"); + //get_camera().requires_zoom_to_plate = REQUIRES_ZOOM_TO_ALL_PLATE; - // need to call update + //need to call update update(); return ret; } -// BBS: set bed positions -void Plater::set_bed_position(Vec2d& pos) { p->bed.set_position(pos); } +//BBS: set bed positions +void Plater::set_bed_position(Vec2d& pos) +{ + p->bed.set_position(pos); +} -// BBS: is the background process slicing currently -bool Plater::is_background_process_slicing() const { return p->m_is_slicing; } +//BBS: is the background process slicing currently +bool Plater::is_background_process_slicing() const +{ + return p->m_is_slicing; +} -// BBS: update slicing context +//BBS: update slicing context void Plater::update_slicing_context_to_current_partplate() { p->partplate_list.update_slice_context_to_current_plate(p->background_process); p->preview->update_gcode_result(p->partplate_list.get_current_slice_result()); } -// BBS: show object info +//BBS: show object info void Plater::show_object_info() { - NotificationManager* notify_manager = get_notification_manager(); - const Selection& selection = get_selection(); - int selCount = selection.get_volume_idxs().size(); - ModelObjectPtrs objects = model().objects; - int obj_idx = selection.get_object_idx(); + NotificationManager *notify_manager = get_notification_manager(); + const Selection& selection = get_selection(); + int selCount = selection.get_volume_idxs().size(); + ModelObjectPtrs objects = model().objects; + int obj_idx = selection.get_object_idx(); std::string info_text; if (selCount > 1 && !selection.is_single_full_object()) { @@ -21804,22 +21909,25 @@ void Plater::show_object_info() } notify_manager->bbl_show_objectsinfo_notification(info_text, false, !(p->current_panel == p->view3D)); return; - } else if (objects.empty() || (obj_idx < 0) || (obj_idx >= objects.size()) || - objects[obj_idx]->volumes.empty() || // hack to avoid crash when deleting the last object on the bed - (selection.is_single_full_object() && objects[obj_idx]->instances.size() > 1) || - !(selection.is_single_full_instance() || selection.is_single_volume())) { + } + else if (objects.empty() || (obj_idx < 0) || (obj_idx >= objects.size()) || + objects[obj_idx]->volumes.empty() ||// hack to avoid crash when deleting the last object on the bed + (selection.is_single_full_object() && objects[obj_idx]->instances.size()> 1) || + !(selection.is_single_full_instance() || selection.is_single_volume())) + { notify_manager->bbl_close_objectsinfo_notification(); return; } const ModelObject* model_object = objects[obj_idx]; - int inst_idx = selection.get_instance_idx(); - if ((inst_idx < 0) || (inst_idx >= model_object->instances.size())) { + int inst_idx = selection.get_instance_idx(); + if ((inst_idx < 0) || (inst_idx >= model_object->instances.size())) + { notify_manager->bbl_close_objectsinfo_notification(); return; } bool imperial_units = wxGetApp().app_config->get("use_inches") == "1"; - double koef = imperial_units ? GizmoObjectManipulation::mm_to_in : 1.0f; + double koef = imperial_units ? GizmoObjectManipulation::mm_to_in : 1.0f; ModelVolume* vol = nullptr; Transform3d t; @@ -21828,60 +21936,65 @@ void Plater::show_object_info() if (selection.is_single_volume()) { std::vector obj_idxs, vol_idxs; wxGetApp().obj_list()->get_selection_indexes(obj_idxs, vol_idxs); - if (vol_idxs.size() != 1) { - // corner case when merge/split/remove + if (vol_idxs.size() != 1) + { + //corner case when merge/split/remove return; } vol = model_object->volumes[vol_idxs[0]]; - t = model_object->instances[inst_idx]->get_matrix() * vol->get_matrix(); + t = model_object->instances[inst_idx]->get_matrix() * vol->get_matrix(); info_text += (boost::format(_utf8(L("Part name: %1%\n"))) % vol->name).str(); face_count = static_cast(vol->mesh().facets_count()); - size = vol->get_convex_hull().transformed_bounding_box(t).size(); - } else { - // int obj_idx, vol_idx; - // wxGetApp().obj_list()->get_selected_item_indexes(obj_idx, vol_idx); - // if (obj_idx < 0) { - // //corner case when merge/split/remove - // return; - // } + size = vol->get_convex_hull().transformed_bounding_box(t).size(); + } + else { + //int obj_idx, vol_idx; + //wxGetApp().obj_list()->get_selected_item_indexes(obj_idx, vol_idx); + //if (obj_idx < 0) { + // //corner case when merge/split/remove + // return; + //} info_text += (boost::format(_utf8(L("Object name: %1%\n"))) % model_object->name).str(); face_count = static_cast(model_object->facets_count()); - size = model_object->instance_convex_hull_bounding_box(inst_idx).size(); + size = model_object->instance_convex_hull_bounding_box(inst_idx).size(); } - // Vec3d size = vol ? vol->mesh().transformed_bounding_box(t).size() : model_object->instance_bounding_box(inst_idx).size(); + //Vec3d size = vol ? vol->mesh().transformed_bounding_box(t).size() : model_object->instance_bounding_box(inst_idx).size(); if (imperial_units) - info_text += (boost::format(_utf8(L("Size: %1% x %2% x %3% in\n"))) % (size(0) * koef) % (size(1) * koef) % (size(2) * koef)).str(); + info_text += (boost::format(_utf8(L("Size: %1% x %2% x %3% in\n"))) %(size(0)*koef) %(size(1)*koef) %(size(2)*koef)).str(); else - info_text += (boost::format(_utf8(L("Size: %1% x %2% x %3% mm\n"))) % size(0) % size(1) % size(2)).str(); + info_text += (boost::format(_utf8(L("Size: %1% x %2% x %3% mm\n"))) %size(0) %size(1) %size(2)).str(); const TriangleMeshStats& stats = vol ? vol->mesh().stats() : model_object->get_object_stl_stats(); - double volume_val = stats.volume; + double volume_val = stats.volume; if (vol) volume_val *= std::fabs(t.matrix().block(0, 0, 3, 3).determinant()); - volume_val = volume_val * pow(koef, 3); + volume_val = volume_val * pow(koef,3); if (imperial_units) - info_text += (boost::format(_utf8(L("Volume: %1% in³\n"))) % volume_val).str(); + info_text += (boost::format(_utf8(L("Volume: %1% in³\n"))) %volume_val).str(); else - info_text += (boost::format(_utf8(L("Volume: %1% mm³\n"))) % volume_val).str(); - info_text += (boost::format(_utf8(L("Triangles: %1%\n"))) % face_count).str(); + info_text += (boost::format(_utf8(L("Volume: %1% mm³\n"))) %volume_val).str(); + info_text += (boost::format(_utf8(L("Triangles: %1%\n"))) %face_count).str(); wxString info_manifold; int non_manifold_edges = 0; - auto mesh_errors = p->sidebar->obj_list()->get_mesh_errors_info(&info_manifold, &non_manifold_edges); + auto mesh_errors = p->sidebar->obj_list()->get_mesh_errors_info(&info_manifold, &non_manifold_edges); - if (non_manifold_edges > 0) { - info_manifold += "\n" + _L("Tips:") + "\n" + _L("Use \"Fix Model\" to repair the mesh."); - } + if (non_manifold_edges > 0) { + info_manifold += "\n" + _L("Tips:") + "\n" + _L("Use \"Fix Model\" to repair the mesh."); + } info_manifold = "" + info_manifold + ""; info_text += into_u8(info_manifold); notify_manager->bbl_show_objectsinfo_notification(info_text, non_manifold_edges > 0, !(p->current_panel == p->view3D)); } -bool Plater::show_publish_dialog(bool show) { return p->show_publish_dlg(show); } +bool Plater::show_publish_dialog(bool show) +{ + return p->show_publish_dlg(show); +} -void Plater::post_process_string_object_exception(StringObjectException& err) +void Plater::post_process_string_object_exception(StringObjectException &err) { PresetBundle* preset_bundle = wxGetApp().preset_bundle; if (err.type == StringExceptionType::STRING_EXCEPT_FILAMENT_NOT_MATCH_BED_TYPE) { @@ -21904,9 +22017,8 @@ void Plater::post_process_string_object_exception(StringObjectException& err) break; } } - err.string = format(_L("Plate %d: %s is not suggested for use printing filament %s (%s). If you still want to do this " - "print job, please set this filament\'s bed temperature to a number that is not zero."), - err.params[0], err.params[1], err.params[2], filament_name); + err.string = format(_L("Plate %d: %s is not suggested for use printing filament %s (%s). If you still want to do this print job, please set this filament\'s bed temperature to a number that is not zero."), + err.params[0], err.params[1], err.params[2], filament_name); err.string += "\n"; } } catch (...) { @@ -21917,8 +22029,10 @@ void Plater::post_process_string_object_exception(StringObjectException& err) return; } -void Plater::update_objects_position_when_select_preset(const std::function& select_prest) -{ p->update_objects_position_when_select_preset(select_prest); } +void Plater::update_objects_position_when_select_preset(const std::function &select_prest) +{ + p->update_objects_position_when_select_preset(select_prest); +} bool Plater::check_ams_status(bool is_slice_all) { @@ -21926,7 +22040,8 @@ bool Plater::check_ams_status(bool is_slice_all) if (!p->check_ams_status_impl(is_slice_all)) { m_check_status = 0; return false; - } else { + } + else { m_check_status = 1; } } @@ -21936,33 +22051,32 @@ bool Plater::check_ams_status(bool is_slice_all) void Plater::update_machine_sync_status() { - DeviceManager* dev_maneger = wxGetApp().getDeviceManager(); + DeviceManager *dev_maneger = wxGetApp().getDeviceManager(); if (!dev_maneger) { GUI::wxGetApp().sidebar().update_sync_status(nullptr); return; } - MachineObject* obj = wxGetApp().getDeviceManager()->get_selected_machine(); + MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine(); GUI::wxGetApp().sidebar().update_sync_status(obj); } -bool Plater::get_machine_sync_status() { return p->get_machine_sync_status(); } +bool Plater::get_machine_sync_status() +{ + return p->get_machine_sync_status(); +} void Plater::update_filament_volume_map(int extruder_id, int volume_type) { // Hybrid is a per-extruder mix, not a per-filament volume; reset the affected filaments // to Standard so the manual grouping dialog starts from a concrete assignment. - int selected_volume_type = volume_type == static_cast(NozzleVolumeType::nvtHybrid) ? - static_cast(NozzleVolumeType::nvtStandard) : - volume_type; - auto& partplate_list = get_partplate_list(); + int selected_volume_type = volume_type == static_cast(NozzleVolumeType::nvtHybrid) ? static_cast(NozzleVolumeType::nvtStandard) : volume_type; + auto& partplate_list = get_partplate_list(); for (int idx = 0; idx < partplate_list.get_plate_count(); ++idx) { auto plate = partplate_list.get_plate(idx); - if (!plate) - continue; + if (!plate) continue; auto filament_map = plate->get_filament_maps(); auto filament_volume_map = plate->get_filament_volume_maps(); - if (filament_map.empty() || filament_volume_map.empty()) - continue; + if (filament_map.empty() || filament_volume_map.empty()) continue; if (filament_volume_map.size() < filament_map.size()) { filament_volume_map.resize(filament_map.size(), static_cast(NozzleVolumeType::nvtStandard)); } @@ -21982,10 +22096,16 @@ void Plater::init_environment_texture() p->environment_texture.load_from_file(resources_dir() + "/images/Pmetal_001.png", false, GLTexture::SingleThreaded, false); } -unsigned int Plater::get_environment_texture_id() const { return p->environment_texture.get_id(); } +unsigned int Plater::get_environment_texture_id() const +{ + return p->environment_texture.get_id(); +} #endif // ENABLE_ENVIRONMENT_MAP -const BuildVolume& Plater::build_volume() const { return p->bed.build_volume(); } +const BuildVolume& Plater::build_volume() const +{ + return p->bed.build_volume(); +} // BBS #if 0 @@ -22000,24 +22120,42 @@ GLToolbar& Plater::get_view_toolbar() } #endif -const GLToolbar& Plater::get_collapse_toolbar() const { return p->collapse_toolbar; } +const GLToolbar& Plater::get_collapse_toolbar() const +{ + return p->collapse_toolbar; +} -GLToolbar& Plater::get_collapse_toolbar() { return p->collapse_toolbar; } +GLToolbar& Plater::get_collapse_toolbar() +{ + return p->collapse_toolbar; +} -void Plater::update_preview_bottom_toolbar() { p->update_preview_bottom_toolbar(); } +void Plater::update_preview_bottom_toolbar() +{ + p->update_preview_bottom_toolbar(); +} void Plater::reset_gcode_toolpaths() { - // BBS: add some logs + //BBS: add some logs BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": reset the gcode viewer's toolpaths"); p->reset_gcode_toolpaths(); } -const Mouse3DController& Plater::get_mouse3d_controller() const { return p->mouse3d_controller; } +const Mouse3DController& Plater::get_mouse3d_controller() const +{ + return p->mouse3d_controller; +} -Mouse3DController& Plater::get_mouse3d_controller() { return p->mouse3d_controller; } +Mouse3DController& Plater::get_mouse3d_controller() +{ + return p->mouse3d_controller; +} -NotificationManager* Plater::get_notification_manager() { return p->notification_manager.get(); } +NotificationManager * Plater::get_notification_manager() +{ + return p->notification_manager.get(); +} DailyTipsWindow* Plater::get_dailytips() const { @@ -22025,11 +22163,20 @@ DailyTipsWindow* Plater::get_dailytips() const return dailytips_win; } -const NotificationManager* Plater::get_notification_manager() const { return p->notification_manager.get(); } +const NotificationManager * Plater::get_notification_manager() const +{ + return p->notification_manager.get(); +} -void Plater::init_notification_manager() { p->init_notification_manager(); } +void Plater::init_notification_manager() +{ + p->init_notification_manager(); +} -void Plater::show_status_message(std::string s) { BOOST_LOG_TRIVIAL(trace) << "show_status_message:" << s; } +void Plater::show_status_message(std::string s) +{ + BOOST_LOG_TRIVIAL(trace) << "show_status_message:" << s; +} bool Plater::can_delete() const { return p->can_delete(); } bool Plater::can_delete_all() const { return p->can_delete_all(); } @@ -22048,10 +22195,9 @@ bool Plater::can_arrange() const { return p->can_arrange(); } bool Plater::can_layers_editing() const { return p->can_layers_editing(); } bool Plater::can_paste_from_clipboard() const { - if (!IsShown() || !p->is_view3D_shown()) - return false; + if (!IsShown() || !p->is_view3D_shown()) return false; - const Selection& selection = p->view3D->get_canvas3d()->get_selection(); + const Selection& selection = p->view3D->get_canvas3d()->get_selection(); const Selection::Clipboard& clipboard = selection.get_clipboard(); if (clipboard.is_empty() && p->sidebar->obj_list()->clipboard_is_empty()) @@ -22070,7 +22216,7 @@ bool Plater::can_paste_from_clipboard() const return true; } -// BBS support cut +//BBS support cut bool Plater::can_cut_to_clipboard() const { if (is_selection_empty()) @@ -22096,7 +22242,7 @@ bool Plater::can_copy_to_clipboard() const bool Plater::can_undo() const { return IsShown() && p->is_view3D_shown() && p->undo_redo_stack().has_undo_snapshot(); } bool Plater::can_redo() const { return IsShown() && p->is_view3D_shown() && p->undo_redo_stack().has_redo_snapshot(); } bool Plater::can_reload_from_disk() const { return p->can_reload_from_disk(); } -// BBS +//BBS bool Plater::can_fillcolor() const { return p->can_fillcolor(); } bool Plater::has_assmeble_view() const { return p->has_assemble_view(); } bool Plater::can_replace_with_stl() const { return p->can_replace_with_stl(); } @@ -22113,33 +22259,53 @@ void Plater::enter_gizmos_stack() { p->enter_gizmos_stack(); } bool Plater::leave_gizmos_stack() { return p->leave_gizmos_stack(); } // BBS: return false if not changed bool Plater::inside_snapshot_capture() { return p->inside_snapshot_capture(); } -void Plater::toggle_render_statistic_dialog() { p->show_render_statistic_dialog = !p->show_render_statistic_dialog; } +void Plater::toggle_render_statistic_dialog() +{ + p->show_render_statistic_dialog = !p->show_render_statistic_dialog; +} -bool Plater::is_render_statistic_dialog_visible() const { return p->show_render_statistic_dialog; } +bool Plater::is_render_statistic_dialog_visible() const +{ + return p->show_render_statistic_dialog; +} -void Plater::toggle_show_wireframe() { p->show_wireframe = !p->show_wireframe; } +void Plater::toggle_show_wireframe() +{ + p->show_wireframe = !p->show_wireframe; +} -bool Plater::is_show_wireframe() const { return p->show_wireframe; } +bool Plater::is_show_wireframe() const +{ + return p->show_wireframe; +} -void Plater::enable_wireframe(bool status) { p->wireframe_enabled = status; } +void Plater::enable_wireframe(bool status) +{ + p->wireframe_enabled = status; +} + +bool Plater::is_wireframe_enabled() const +{ + return p->wireframe_enabled; +} -bool Plater::is_wireframe_enabled() const { return p->wireframe_enabled; } /*Plater::TakeSnapshot::TakeSnapshot(Plater *plater, const std::string &snapshot_name) : TakeSnapshot(plater, from_u8(snapshot_name)) {} Plater::TakeSnapshot::TakeSnapshot(Plater* plater, const std::string& snapshot_name, UndoRedo::SnapshotType snapshot_type) : TakeSnapshot(plater, from_u8(snapshot_name), snapshot_type) {}*/ + // Wrapper around wxWindow::PopupMenu to suppress error messages popping out while tracking the popup menu. -bool Plater::PopupMenu(wxMenu* menu, const wxPoint& pos) +bool Plater::PopupMenu(wxMenu *menu, const wxPoint& pos) { // Don't want to wake up and trigger reslicing while tracking the pop-up menu. SuppressBackgroundProcessingUpdate sbpu; // When tracking a pop-up menu, postpone error messages from the slicing result. m_tracking_popup_menu = true; - bool out = wxGetApp().mainframe->PopupMenu(menu, pos); + bool out = wxGetApp().mainframe->PopupMenu(menu, pos); m_tracking_popup_menu = false; - if (!m_tracking_popup_menu_error_message.empty()) { + if (! m_tracking_popup_menu_error_message.empty()) { // Don't know whether the CallAfter is necessary, but it should not hurt. // The menus likely sends out some commands, so we may be safer if the dialog is shown after the menu command is processed. wxString message = std::move(m_tracking_popup_menu_error_message); @@ -22148,19 +22314,27 @@ bool Plater::PopupMenu(wxMenu* menu, const wxPoint& pos) } return out; } -void Plater::bring_instance_forward() { p->bring_instance_forward(); } +void Plater::bring_instance_forward() +{ + p->bring_instance_forward(); +} -bool Plater::need_update() const { return p->need_update(); } +bool Plater::need_update() const +{ + return p->need_update(); +} -void Plater::set_need_update(bool need_update) { p->set_need_update(need_update); } +void Plater::set_need_update(bool need_update) +{ + p->set_need_update(need_update); +} // BBS -// BBS: add popup logic for table object +//BBS: add popup logic for table object bool Plater::PopupObjectTable(int object_id, int volume_id, const wxPoint& position) { - if (dynamic_cast(wxGetApp().get_tab(Preset::TYPE_PRINTER))->m_extruders_count > 1) { - MessageDialog dlg(this, _L("Currently, the object configuration form cannot be used with a multiple-extruder printer."), - _L("Not available"), wxOK | wxICON_WARNING); + if (dynamic_cast(wxGetApp().get_tab(Preset::TYPE_PRINTER))->m_extruders_count > 1) { + MessageDialog dlg(this, _L("Currently, the object configuration form cannot be used with a multiple-extruder printer."), _L("Not available"), wxOK | wxICON_WARNING); dlg.ShowModal(); return false; } @@ -22171,34 +22345,41 @@ bool Plater::PopupObjectTableBySelection() { wxDataViewItem item; int obj_idx, vol_idx; - const wxPoint pos = wxPoint(0, 0); // Fake position + const wxPoint pos = wxPoint(0, 0); //Fake position wxGetApp().obj_list()->get_selected_item_indexes(obj_idx, vol_idx, item); return p->PopupObjectTable(obj_idx, vol_idx, pos); } -void Plater::update_title_dirty_status() { p->update_title_dirty_status(); } +void Plater::update_title_dirty_status() +{ + p->update_title_dirty_status(); +} -wxMenu* Plater::plate_menu() { return p->menus.plate_menu(); } -wxMenu* Plater::object_menu() { return p->menus.object_menu(); } -wxMenu* Plater::part_menu() { return p->menus.part_menu(); } -wxMenu* Plater::text_part_menu() { return p->menus.text_part_menu(); } -wxMenu* Plater::svg_part_menu() { return p->menus.svg_part_menu(); } -wxMenu* Plater::sla_object_menu() { return p->menus.sla_object_menu(); } -wxMenu* Plater::default_menu() { return p->menus.default_menu(); } -wxMenu* Plater::instance_menu() { return p->menus.instance_menu(); } -wxMenu* Plater::layer_menu() { return p->menus.layer_menu(); } -wxMenu* Plater::multi_selection_menu() { return p->menus.multi_selection_menu(); } -wxMenu* Plater::filament_action_menu(int active_filament_menu_id) { return p->menus.filament_action_menu(active_filament_menu_id); } -int Plater::GetPlateIndexByRightMenuInLeftUI() { return p->m_is_RightClickInLeftUI; } -void Plater::SetPlateIndexByRightMenuInLeftUI(int index) { p->m_is_RightClickInLeftUI = index; } -SuppressBackgroundProcessingUpdate::SuppressBackgroundProcessingUpdate() - : m_was_scheduled(wxGetApp().plater()->is_background_process_update_scheduled()) -{ wxGetApp().plater()->suppress_background_process(m_was_scheduled); } + +wxMenu* Plater::plate_menu() { return p->menus.plate_menu(); } +wxMenu* Plater::object_menu() { return p->menus.object_menu(); } +wxMenu* Plater::part_menu() { return p->menus.part_menu(); } +wxMenu* Plater::text_part_menu() { return p->menus.text_part_menu(); } +wxMenu* Plater::svg_part_menu() { return p->menus.svg_part_menu(); } +wxMenu* Plater::sla_object_menu() { return p->menus.sla_object_menu(); } +wxMenu* Plater::default_menu() { return p->menus.default_menu(); } +wxMenu* Plater::instance_menu() { return p->menus.instance_menu(); } +wxMenu* Plater::layer_menu() { return p->menus.layer_menu(); } +wxMenu* Plater::multi_selection_menu() { return p->menus.multi_selection_menu(); } +wxMenu *Plater::filament_action_menu(int active_filament_menu_id) { return p->menus.filament_action_menu(active_filament_menu_id); } +int Plater::GetPlateIndexByRightMenuInLeftUI() { return p->m_is_RightClickInLeftUI; } +void Plater::SetPlateIndexByRightMenuInLeftUI(int index) { p->m_is_RightClickInLeftUI = index; } +SuppressBackgroundProcessingUpdate::SuppressBackgroundProcessingUpdate() : + m_was_scheduled(wxGetApp().plater()->is_background_process_update_scheduled()) +{ + wxGetApp().plater()->suppress_background_process(m_was_scheduled); +} SuppressBackgroundProcessingUpdate::~SuppressBackgroundProcessingUpdate() -{ wxGetApp().plater()->schedule_background_process(m_was_scheduled); } -wxString get_view_type_string(Camera::ViewAngleType type) { + wxGetApp().plater()->schedule_background_process(m_was_scheduled); +} +wxString get_view_type_string(Camera::ViewAngleType type) { switch (type) { case Slic3r::GUI::Camera::ViewAngleType::Iso: return _L("isometric"); case Slic3r::GUI::Camera::ViewAngleType::Top_Front: return _L("top_front"); @@ -22211,12 +22392,11 @@ wxString get_view_type_string(Camera::ViewAngleType type) default: return ""; } } -wxArrayString get_all_camera_view_type() -{ +wxArrayString get_all_camera_view_type() { wxArrayString all_types; - for (size_t i = 0; i < (int) Camera::ViewAngleType::Count_ViewAngleType; i++) { + for (size_t i = 0; i < (int)Camera::ViewAngleType::Count_ViewAngleType; i++) { all_types.Add(get_view_type_string((Camera::ViewAngleType) i)); } return all_types; } -}} // namespace Slic3r::GUI +}} // namespace Slic3r::GUI diff --git a/tests/libslic3r/test_3mf.cpp b/tests/libslic3r/test_3mf.cpp index d30b40004d..5c38859a12 100644 --- a/tests/libslic3r/test_3mf.cpp +++ b/tests/libslic3r/test_3mf.cpp @@ -866,6 +866,65 @@ SCENARIO("Minimal published 3MF omits project config, preset dumps and slicer ta } } +// A minimal published 3MF must not leak the slicer tags of the source project. The exporter seeds +// metadata_item_map from the input file's metadata_items, so re-publishing a project opened from a +// regular Orca/BBS 3MF (the typical remix flow) must strip the Application / OrcaSlicer tags it +// came with, otherwise old receivers route onto the baked-in "old version" popup. +SCENARIO("MinimalPublished strips slicer tags carried by the source project", "[3mf]") { + GIVEN("a model loaded from a regular Orca/BBS 3MF whose metadata carries the slicer tags") { + Model model; + std::string src_file = std::string(TEST_DATA_DIR) + "/test_3mf/Prusa.stl"; + REQUIRE(load_stl(src_file.c_str(), &model)); + model.add_default_instances(); + + model.model_info = std::make_shared(); + model.model_info->metadata_items[ORCA_PUBLISHED_TAG] = "1"; + model.model_info->metadata_items["Application"] = "BambuStudio-2.0.0"; + model.model_info->metadata_items["OrcaSlicer"] = "2.1.0"; + + ScopedTemporaryDir backup_dir("orca_strip_tags"); + model.set_backup_path(backup_dir.string()); + + WHEN("stored using SaveStrategy::MinimalPublished and reloaded") { + ScopedTemporaryFile temp(".3mf"); + const std::string test_file = temp.string(); + + DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); + StoreParams store_params; + store_params.path = test_file.c_str(); + store_params.model = &model; + store_params.config = &config; + store_params.strategy = SaveStrategy::Zip64 | SaveStrategy::Silence | SaveStrategy::MinimalPublished; + REQUIRE(store_bbs_3mf(store_params)); + + Model dst_model; + DynamicPrintConfig dst_config; + ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Enable }; + PlateDataPtrs dst_plates; + std::vector loaded_presets; + bool is_bbl_3mf = false, is_orca_3mf = false; + Semver file_version; + bool loaded = load_bbs_3mf(test_file.c_str(), &dst_config, &ctxt, &dst_model, &dst_plates, + &loaded_presets, &is_bbl_3mf, &is_orca_3mf, &file_version, nullptr, + LoadStrategy::LoadModel | LoadStrategy::LoadConfig); + THEN("the source slicer tags are stripped, not carried through") { + REQUIRE(loaded); + REQUIRE(dst_model.model_info != nullptr); + REQUIRE(dst_model.model_info->metadata_items.count("Application") == 0); + REQUIRE(dst_model.model_info->metadata_items.count("OrcaSlicer") == 0); + // The published marker itself must survive. + REQUIRE(dst_model.model_info->metadata_items[ORCA_PUBLISHED_TAG] == "1"); + } + THEN("the file classifies as a generic 3MF without a version popup") { + REQUIRE_FALSE(is_bbl_3mf); + REQUIRE_FALSE(is_orca_3mf); + REQUIRE_FALSE(file_version.valid()); + } + release_PlateData_list(dst_plates); + } + } +} + // An entry masks the non-published slots to their defaults so publishing slot 1 never leaks slot // 0's value into the file. Both a full entry (the whole-slot key list) and a partial entry (a // per-slot key) go through the same masking path in filter_published_config (keys and full_keys @@ -938,6 +997,40 @@ SCENARIO("Unmaskable keys are dropped from the published payload instead of leak } } +// A per-extruder printer key carrying a "#N" variant (e.g. retraction_length#1) must not serialize +// every extruder's value: the base is masked to the author's extruder and the other slots are +// restored to their option default, matching the material-side slot-masking invariant. A bare +// printer base key (no variant) keeps whole-vector serialization. +SCENARIO("Published per-extruder printer keys mask the other extruders to their defaults", "[3mf]") { + GIVEN("a full print configuration with three extruders carrying per-extruder retraction values") { + DynamicPrintConfig full_cfg = DynamicPrintConfig::full_print_config(); + // Non-default values on the un-selected slots, so a leak is distinguishable from the mask + // restoring the option default (retraction_length defaults to {0.8}). + full_cfg.opt("retraction_length")->values = { 3.0, 1.2, 4.0 }; + + WHEN("filtering with only extruder 1's retraction_length checked") { + DynamicPrintConfig filtered_cfg = filter_published_config(full_cfg, { "retraction_length#1" }, {}); + + THEN("the author's extruder value survives") { + REQUIRE_THAT(filtered_cfg.opt("retraction_length")->values[1], Catch::Matchers::WithinAbs(1.2, 1e-6)); + } + THEN("the other extruders are masked to their default") { + REQUIRE_THAT(filtered_cfg.opt("retraction_length")->values[0], Catch::Matchers::WithinAbs(0.8, 1e-6)); + REQUIRE_THAT(filtered_cfg.opt("retraction_length")->values[2], Catch::Matchers::WithinAbs(0.8, 1e-6)); + } + } + WHEN("filtering the bare base key without a '#N' variant") { + DynamicPrintConfig filtered_cfg = filter_published_config(full_cfg, { "retraction_length" }, {}); + + THEN("the whole vector is serialized unmasked") { + REQUIRE_THAT(filtered_cfg.opt("retraction_length")->values[0], Catch::Matchers::WithinAbs(3.0, 1e-6)); + REQUIRE_THAT(filtered_cfg.opt("retraction_length")->values[1], Catch::Matchers::WithinAbs(1.2, 1e-6)); + REQUIRE_THAT(filtered_cfg.opt("retraction_length")->values[2], Catch::Matchers::WithinAbs(4.0, 1e-6)); + } + } + } +} + // The extended per-entry fields (full dump list, published type and colour) travel inside the // published_material_keys metadata and round-trip unchanged. SCENARIO("Published 3MF round-trips the extended material metadata", "[3mf]") {