From a8318ee4f3187ef90064c8f756b86b586f84e3b3 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Mon, 21 Nov 2022 16:46:16 +0100 Subject: [PATCH] Fix ../src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp:3021:58: error: use of deleted function 'std::optional& std::optional::operator=(std::optional&&)' ../src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp:3026:55: error: use of deleted function 'std::optional& std::optional::operator=(std::optional&&)' --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 33 ++++++++++++++----------- src/slic3r/Utils/WxFontUtils.cpp | 19 +++++++------- src/slic3r/Utils/WxFontUtils.hpp | 6 ++--- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 9385d98643..37ac6f88d0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -3016,43 +3016,46 @@ bool GLGizmoEmboss::load_configuration(ModelVolume *volume) return es.name == style.name; }; - std::optional wx_font_opt; - if (style.type == WxFontUtils::get_actual_type()) - wx_font_opt = WxFontUtils::load_wxFont(style.path); + int wx_font_opt; + wxFont wx_font; bool is_path_changed = false; - if (!wx_font_opt.has_value()) { + if (style.type == WxFontUtils::get_actual_type()) + wx_font = WxFontUtils::load_wxFont(style.path); + if (!wx_font.IsOk()) { create_notification_not_valid_font(tc); // Try create similar wx font - wx_font_opt = WxFontUtils::create_wxFont(style); - is_path_changed = wx_font_opt.has_value(); + wx_font = WxFontUtils::create_wxFont(style); + is_path_changed = wx_font.IsOk(); } const auto& styles = m_style_manager.get_styles(); auto it = std::find_if(styles.begin(), styles.end(), has_same_name); if (it == styles.end()) { // style was not found - if (wx_font_opt.has_value()) - m_style_manager.load_style(style, *wx_font_opt); + if (wx_font.IsOk()) + m_style_manager.load_style(style, wx_font); } else { size_t style_index = it - styles.begin(); if (!m_style_manager.load_style(style_index)) { // can`t load stored style m_style_manager.erase(style_index); - if (wx_font_opt.has_value()) - m_style_manager.load_style(style, *wx_font_opt); + if (wx_font.IsOk()) + m_style_manager.load_style(style, wx_font); } else { // stored style is loaded, now set modification of style m_style_manager.get_style() = style; - m_style_manager.set_wx_font(*wx_font_opt); + m_style_manager.set_wx_font(wx_font); } } - if (is_path_changed) - m_style_manager.get_style().path = WxFontUtils::store_wxFont(*wx_font_opt); + if (is_path_changed) { + std::string path = WxFontUtils::store_wxFont(wx_font); + m_style_manager.get_style().path = path; + } - m_text = tc.text; - m_volume = volume; + m_text = tc.text; + m_volume = volume; // store volume state before edit m_unmodified_volume = {*volume->get_mesh_shared_ptr(), // copy diff --git a/src/slic3r/Utils/WxFontUtils.cpp b/src/slic3r/Utils/WxFontUtils.cpp index 422ec725ae..2727c5e259 100644 --- a/src/slic3r/Utils/WxFontUtils.cpp +++ b/src/slic3r/Utils/WxFontUtils.cpp @@ -171,13 +171,11 @@ std::string WxFontUtils::store_wxFont(const wxFont &font) return std::string(font_descriptor.c_str()); } -std::optional WxFontUtils::load_wxFont( - const std::string &font_descriptor) +wxFont WxFontUtils::load_wxFont(const std::string &font_descriptor) { wxString font_descriptor_wx(font_descriptor); - std::optional res = std::make_optional(font_descriptor_wx); - if (!res->IsOk()) return {}; - return res; + wxFont wx_font(font_descriptor_wx); + return wx_font; } using TypeToFamily = boost::bimap; @@ -212,7 +210,7 @@ const TypeToWeight WxFontUtils::type_to_weight = (wxFONTWEIGHT_HEAVY, "heavy") (wxFONTWEIGHT_EXTRAHEAVY, "extraHeavy"); -std::optional WxFontUtils::create_wxFont(const EmbossStyle &style) +wxFont WxFontUtils::create_wxFont(const EmbossStyle &style) { const FontProp &fp = style.prop; double point_size = static_cast(fp.size_in_mm); @@ -244,9 +242,12 @@ std::optional WxFontUtils::create_wxFont(const EmbossStyle &style) // default: //} - std::optional res = std::make_optional(info); - if (!res->IsOk()) return {}; - return res; + wxFont wx_font(info); + // Check if exist font file + std::unique_ptr ff = create_font_file(wx_font); + if (ff == nullptr) return {}; + + return wx_font; } void WxFontUtils::update_property(FontProp &font_prop, const wxFont &font) diff --git a/src/slic3r/Utils/WxFontUtils.hpp b/src/slic3r/Utils/WxFontUtils.hpp index 9732d2dc91..ed8fb61582 100644 --- a/src/slic3r/Utils/WxFontUtils.hpp +++ b/src/slic3r/Utils/WxFontUtils.hpp @@ -32,11 +32,11 @@ public: static std::string get_human_readable_name(const wxFont &font); // serialize / deserialize font - static std::string store_wxFont(const wxFont &font); - static std::optional load_wxFont(const std::string &font_descriptor); + static std::string store_wxFont(const wxFont &font); + static wxFont load_wxFont(const std::string &font_descriptor); // Try to create similar font, loaded from 3mf from different Computer - static std::optional create_wxFont(const EmbossStyle &style); + static wxFont create_wxFont(const EmbossStyle &style); // update font property by wxFont - without emboss depth and font size static void update_property(FontProp &font_prop, const wxFont &font);