From 8b3ff9b9c4a14bef14565d08e7c3a5d80903c8ca Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 6 Feb 2023 15:13:04 +0100 Subject: [PATCH] Fix std::optional value() build error on older macOS SDK For old macOS (pre 10.14), std::optional does not have .value() method, so the code is using operator*() instead. --- src/libslic3r/Config.hpp | 4 ++-- src/slic3r/GUI/ConfigManipulation.cpp | 2 +- src/slic3r/GUI/Field.cpp | 12 ++++++------ src/slic3r/GUI/GUI.cpp | 4 ++-- src/slic3r/GUI/UnsavedChangesDialog.cpp | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index c327779755..f29a79e0f3 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1689,7 +1689,7 @@ public: assert(this->is_valid_closed_enum()); auto opt = this->enum_to_index(enum_val); return opt.has_value() ? - std::optional>{ this->value(opt.value()) } : + std::optional>{ this->value(*opt) } : std::optional>{}; } @@ -1697,7 +1697,7 @@ public: assert(this->is_valid_closed_enum()); auto opt = this->enum_to_index(enum_val); return opt.has_value() ? - std::optional>{ this->label(opt.value()) } : + std::optional>{ this->label(*opt) } : std::optional>{}; } diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index b4c98fcb1b..50ce249814 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -194,7 +194,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con const ConfigOptionDef *fill_pattern_def = config->option_def("fill_pattern"); assert(fill_pattern_def != nullptr); if (auto label = fill_pattern_def->enum_def->enum_to_label(fill_pattern); label.has_value()) { - wxString msg_text = GUI::format_wxstr(_L("The %1% infill pattern is not supposed to work at 100%% density."), _(label.value())); + wxString msg_text = GUI::format_wxstr(_L("The %1% infill pattern is not supposed to work at 100%% density."), _(*label)); if (is_global_config) msg_text += "\n\n" + _L("Shall I switch to rectilinear fill pattern?"); MessageDialog dialog(m_msg_dlg_parent, msg_text, _L("Infill"), diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 70fc3d53dc..13a9e6e07c 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -1141,7 +1141,7 @@ void Choice::set_selection() if (!text_value.IsEmpty()) { if (auto opt = m_opt.enum_def->value_to_index(into_u8(text_value)); opt.has_value()) // This enum has a value field of the same content as text_value. Select it. - field->SetSelection(opt.value()); + field->SetSelection(*opt); else field->SetValue(text_value); } @@ -1153,7 +1153,7 @@ void Choice::set_value(const std::string& value, bool change_event) //! Redunda choice_ctrl* field = dynamic_cast(window); if (auto opt = m_opt.enum_def->value_to_index(value); opt.has_value()) // This enum has a value field of the same content as text_value. Select it. - field->SetSelection(opt.value()); + field->SetSelection(*opt); else field->SetValue(value); m_disable_change_event = false; @@ -1178,9 +1178,9 @@ void Choice::set_value(const boost::any& value, bool change_event) int sel_idx = -1; if (m_opt.enum_def) { if (auto idx = m_opt.enum_def->label_to_index(into_u8(text_value)); idx.has_value()) - sel_idx = idx.value(); + sel_idx = *idx; else if (idx = m_opt.enum_def->value_to_index(into_u8(text_value)); idx.has_value()) - sel_idx = idx.value(); + sel_idx = *idx; } if (sel_idx >= 0 ) @@ -1205,7 +1205,7 @@ void Choice::set_value(const boost::any& value, bool change_event) case coEnum: { auto val = m_opt.enum_def->enum_to_index(boost::any_cast(value)); assert(val.has_value()); - field->SetSelection(val.has_value() ? val.value() : 0); + field->SetSelection(val.has_value() ? *val : 0); break; } default: @@ -1325,7 +1325,7 @@ void Choice::msw_rescale() if (auto opt = m_opt.enum_def->label_to_index(into_u8(selection)); opt.has_value()) // This enum has a value field of the same content as text_value. Select it. - field->SetSelection(opt.value()); + field->SetSelection(*opt); else field->SetValue(selection); } diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index c7c5056d09..beee256004 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -282,8 +282,8 @@ static void add_config_substitutions(const ConfigSubstitutions& conf_substitutio { auto opt = def->enum_def->enum_to_index(conf_substitution.new_value->getInt()); new_val = opt.has_value() ? - wxString("\"") + def->enum_def->value(opt.value()) + "\"" + " (" + - _(wxString::FromUTF8(def->enum_def->label(opt.value()))) + ")" : + wxString("\"") + def->enum_def->value(*opt) + "\"" + " (" + + _(from_u8(def->enum_def->label(*opt))) + ")" : _L("Undefined"); break; } diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index 06cba39fed..502c85f038 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -1194,7 +1194,7 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig& } case coEnum: { auto opt = config.option_def(opt_key)->enum_def->enum_to_label(config.option(opt_key)->getInt()); - return opt.has_value() ? _(wxString::FromUTF8(opt.value())) : _L("Undef"); + return opt.has_value() ? _(from_u8(*opt)) : _L("Undef"); } case coPoints: { if (opt_key == "bed_shape") {