From b594ffc7ef182323d44b8dc126fed0dcf660af56 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Thu, 29 Sep 2022 18:46:18 +0200 Subject: [PATCH] Selection of font for unknown one from 3mf fix creation of style name --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 39 ++++++++++++++++++------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 4 +-- src/slic3r/Utils/EmbossStyleManager.cpp | 17 +++++++---- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 074da27341..18616b656e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -124,7 +124,7 @@ template void to_range_pi_pi(T& angle) GLGizmoEmboss::GLGizmoEmboss(GLCanvas3D &parent) : GLGizmoBase(parent, M_ICON_FILENAME, -2) , m_volume(nullptr) - , m_exist_notification(false) + , m_is_unknown_font(false) , m_rotate_gizmo(parent, GLGizmoRotate::Axis::Z) // grab id = 2 (Z axis) , m_style_manager(m_imgui->get_glyph_ranges()) , m_update_job_cancel(nullptr) @@ -1009,6 +1009,12 @@ void GLGizmoEmboss::draw_window() if (!is_activ_font) m_imgui->text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, _L("Warning: No font is selected. Select correct one.")); + // Disable all except selection of font, when open text from 3mf with unknown font + m_imgui->disabled_begin(m_is_unknown_font); + ScopeGuard unknown_font_sc([&]() { + m_imgui->disabled_end(); + }); + draw_text_input(); draw_model_type(); draw_style_list(); @@ -1040,7 +1046,13 @@ void GLGizmoEmboss::draw_window() ImGui::PopStyleColor(); ImGui::SameLine(); - if (ImGui::Button(_u8L("Apply").c_str())) close(); + if (ImGui::Button(_u8L("Apply").c_str())) { + if (m_is_unknown_font) { + process(); + } else { + close(); + } + } // Option to create text volume when reselecting volumes m_imgui->disabled_begin(!is_activ_font); @@ -1087,14 +1099,10 @@ void GLGizmoEmboss::draw_text_input() auto create_range_text = [&mng = m_style_manager, &text = m_text, &exist_unknown = m_text_contain_unknown_glyph]() { auto& ff = mng.get_font_file_with_cache(); assert(ff.has_value()); - const auto &cn = mng.get_font_prop().collection_number; + const auto &cn = mng.get_font_prop().collection_number; unsigned int font_index = (cn.has_value()) ? *cn : 0; return Emboss::create_range_text(text, *ff.font_file, font_index, &exist_unknown); }; - - static const ImGuiInputTextFlags flags = - ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_AutoSelectAll; - ImFont *imgui_font = m_style_manager.get_imgui_font(); if (imgui_font == nullptr) { @@ -1119,6 +1127,7 @@ void GLGizmoEmboss::draw_text_input() float extra_height = window_height - minimal_height; ImVec2 text_size(m_gui_cfg->text_size.x, m_gui_cfg->text_size.y + extra_height); + const ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput | ImGuiInputTextFlags_AutoSelectAll; if (ImGui::InputTextMultiline("##Text", &m_text, text_size, flags)) { process(); range_text = create_range_text(); @@ -1324,7 +1333,15 @@ void GLGizmoEmboss::draw_font_list() } const char * selected = (!actual_face_name.empty()) ? actual_face_name.ToUTF8().data() : " --- "; + wxString del_facename; + ScopeGuard unknown_font_sc; + if (m_is_unknown_font) { + m_imgui->disabled_end(); + unknown_font_sc = ScopeGuard([&]() { + m_imgui->disabled_begin(true); + }); + } if (ImGui::BeginCombo("##font_selector", selected)) { if (!m_face_names.is_init) init_face_names(); init_font_name_texture(); @@ -2821,8 +2838,8 @@ void GLGizmoEmboss::create_notification_not_valid_font( const TextConfiguration &tc) { // not neccessary, but for sure that old notification doesnt exist - if (m_exist_notification) remove_notification_not_valid_font(); - m_exist_notification = true; + if (m_is_unknown_font) remove_notification_not_valid_font(); + m_is_unknown_font = true; auto type = NotificationType::UnknownFont; auto level = @@ -2859,8 +2876,8 @@ void GLGizmoEmboss::create_notification_not_valid_font( void GLGizmoEmboss::remove_notification_not_valid_font() { - if (!m_exist_notification) return; - m_exist_notification = false; + if (!m_is_unknown_font) return; + m_is_unknown_font = false; auto type = NotificationType::UnknownFont; auto notification_manager = wxGetApp().plater()->get_notification_manager(); notification_manager->close_notification_of_type(type); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index 9eb2580df7..d30a4a0207 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -160,8 +160,8 @@ private: EmbossDataBase create_emboss_data_base(); bool load_configuration(ModelVolume *volume); - // Create notification when unknown font type is used - bool m_exist_notification; + // When open text loaded from .3mf it could be written with unknown font + bool m_is_unknown_font; void create_notification_not_valid_font(const TextConfiguration& tc); void remove_notification_not_valid_font(); diff --git a/src/slic3r/Utils/EmbossStyleManager.cpp b/src/slic3r/Utils/EmbossStyleManager.cpp index 3799dfa6c0..3fff460361 100644 --- a/src/slic3r/Utils/EmbossStyleManager.cpp +++ b/src/slic3r/Utils/EmbossStyleManager.cpp @@ -259,19 +259,26 @@ void EmbossStyleManager::make_unique_name(std::string &name) return true; }; - if (name.empty()) name = "font"; + // Style name can't be empty so default name is set + if (name.empty()) name = "Text style"; + + // When name is already unique, nothing need to be changed if (is_unique(name)) return; - auto pos = name.find(" ("); - if (pos != std::string::npos && name.find(")", pos) != std::string::npos) { + // when there is previous version of style name only find number + const char *prefix = " ("; + const char suffix = ')'; + auto pos = name.find_last_of(prefix); + if (name.c_str()[name.size() - 1] == suffix && + pos != std::string::npos) { // short name by ord number name = name.substr(0, pos); } - int order = 1; // start with value 2 to represents same font name + int order = 1; // start with value 2 to represents same font name std::string new_name; do { - new_name = name + " (" + std::to_string(++order) + ")"; + new_name = name + prefix + std::to_string(++order) + suffix; } while (!is_unique(new_name)); name = new_name; }