From f7ecd99f4de17fea6c7d2519f49acecc4311f58c Mon Sep 17 00:00:00 2001 From: Craig Link Date: Wed, 2 Jun 2021 20:04:48 -0700 Subject: [PATCH] Issue 1238: Unsaved changes dialog displays incorrect GCode Flavor The order in which enums are added to the 2 vectors is not guarenteed to be in numerical order. Thus always look up the values and labels by key and not by the enum's int value. --- src/slic3r/GUI/UnsavedChangesDialog.cpp | 27 ++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index 4636f6a4b..b3c0ca335 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -838,25 +838,20 @@ bool UnsavedChangesDialog::save(PresetCollection* dependent_presets) } template -wxString get_string_from_enum(const std::string& opt_key, const DynamicPrintConfig& config, bool is_infill = false) +wxString get_string_from_enum(const std::string& opt_key, const DynamicPrintConfig& config) { const ConfigOptionDef& def = config.def()->options.at(opt_key); const std::vector& names = def.enum_labels;//ConfigOptionEnum::get_enum_names(); T val = config.option>(opt_key)->value; - // Each infill doesn't use all list of infill declared in PrintConfig.hpp. - // So we should "convert" val to the correct one - if (is_infill) { - for (auto key_val : *def.enum_keys_map) - if ((int)key_val.second == (int)val) { - auto it = std::find(def.enum_values.begin(), def.enum_values.end(), key_val.first); - if (it == def.enum_values.end()) - return ""; - return from_u8(_utf8(names[it - def.enum_values.begin()])); - } - return _L("Undef"); - } - return from_u8(_utf8(names[static_cast(val)])); + for (auto key_val : *def.enum_keys_map) + if ((int)key_val.second == (int)val) { + auto it = std::find(def.enum_values.begin(), def.enum_values.end(), key_val.first); + if (it == def.enum_values.end()) + return ""; + return from_u8(_utf8(names[it - def.enum_values.begin()])); + } + return _L("Undef"); } static int get_id_from_opt_key(std::string opt_key) @@ -954,7 +949,7 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig& opt_key == "solid_fill_pattern" || opt_key == "brim_ears_pattern" || opt_key == "support_material_interface_pattern") - return get_string_from_enum(opt_key, config, true); + return get_string_from_enum(opt_key, config); if (opt_key == "complete_objects_sort") return get_string_from_enum(opt_key, config); if (opt_key == "display_orientation") @@ -977,7 +972,7 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig& if (opt_key == "no_perimeter_unsupported_algo") return get_string_from_enum(opt_key, config); if (opt_key == "perimeter_loop_seam") - return get_string_from_enum(opt_key, config, true); + return get_string_from_enum(opt_key, config); if (opt_key == "printhost_authorization_type") return get_string_from_enum(opt_key, config); if (opt_key == "seam_position")