From cc5660ad8cf28a134cad5164061d890441655612 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 29 Mar 2023 10:45:11 +0200 Subject: [PATCH 1/2] Lock for rotation. --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 39 +++++++++++++++++-------- src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp | 2 ++ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index ec2a74f962..a3cdb92a53 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -223,6 +223,10 @@ enum class IconType : unsigned { system_selector, open_file, exclamation, + lock, + lock_bold, + unlock, + unlock_bold, // automatic calc of icon's count _count }; @@ -779,12 +783,12 @@ GLGizmoEmboss::GuiCfg GLGizmoEmboss::create_gui_configuration() ImGui::CalcTextSize(tr.boldness.c_str()).x, ImGui::CalcTextSize(tr.skew_ration.c_str()).x, ImGui::CalcTextSize(tr.from_surface.c_str()).x, - ImGui::CalcTextSize(tr.rotation.c_str()).x, + ImGui::CalcTextSize(tr.rotation.c_str()).x + cfg.icon_width + 2*space, ImGui::CalcTextSize(tr.keep_up.c_str()).x, ImGui::CalcTextSize(tr.collection.c_str()).x }); cfg.advanced_input_offset = max_advanced_text_width + 3 * space + cfg.indent; - + cfg.lock_offset = cfg.advanced_input_offset - (cfg.icon_width + space); // calculate window size float window_title = line_height + 2*style.FramePadding.y + 2 * style.WindowTitleAlign.y; float input_height = line_height_with_spacing + 2*style.FramePadding.y; @@ -806,9 +810,9 @@ GLGizmoEmboss::GuiCfg GLGizmoEmboss::create_gui_configuration() + 2 * (cfg.icon_width + space); cfg.minimal_window_size = ImVec2(window_width, window_height); - // 9 = useSurface, charGap, lineGap, bold, italic, surfDist, rotation, keepUp, textFaceToCamera + // 8 = useSurface, charGap, lineGap, bold, italic, surfDist, rotation, textFaceToCamera // 4 = 1px for fix each edit image of drag float - float advance_height = input_height * 9 + 8; + float advance_height = input_height * 8 + 8; cfg.minimal_window_size_with_advance = ImVec2(cfg.minimal_window_size.x, cfg.minimal_window_size.y + advance_height); @@ -2652,8 +2656,8 @@ void GLGizmoEmboss::draw_height(bool use_inch) { float &value = m_style_manager.get_style().prop.size_in_mm; const EmbossStyle* stored_style = m_style_manager.get_stored_style(); - const float *stored = ((stored_style)? &stored_style->prop.size_in_mm : nullptr); - const char *size_format = ((use_inch) ? "%.2f in" : "%.1f mm"); + const float *stored = (stored_style != nullptr)? &stored_style->prop.size_in_mm : nullptr; + const char *size_format = use_inch ? "%.2f in" : "%.1f mm"; const std::string revert_text_size = _u8L("Revert text size."); const std::string& name = m_gui_cfg->translations.height; if (rev_input_mm(name, value, stored, revert_text_size, 0.1f, 1.f, size_format, use_inch, m_scale_height)) @@ -2913,10 +2917,10 @@ void GLGizmoEmboss::draw_advanced() &stored_style->prop.distance : nullptr; m_imgui->disabled_begin(!allowe_surface_distance); - bool use_inch = wxGetApp().app_config->get_bool("use_inches"); const std::string undo_move_tooltip = _u8L("Undo translation"); const wxString move_tooltip = _L("Distance of the center of text from model surface"); bool is_moved = false; + bool use_inch = wxGetApp().app_config->get_bool("use_inches"); if (use_inch) { std::optional distance_inch; if (distance.has_value()) distance_inch = (*distance * ObjectManipulation::mm_to_in); @@ -2982,16 +2986,23 @@ void GLGizmoEmboss::draw_advanced() process(); } - ImGui::Text("%s", tr.keep_up.c_str()); - ImGui::SameLine(m_gui_cfg->advanced_input_offset); - if (ImGui::Checkbox("##keep_up", &m_keep_up)) { + // Keep up - lock button icon + ImGui::SameLine(m_gui_cfg->lock_offset); + const IconManager::Icon &icon = get_icon(m_icons, m_keep_up ? IconType::lock : IconType::unlock, IconState::activable); + const IconManager::Icon &icon_hover = get_icon(m_icons, m_keep_up ? IconType::lock_bold : IconType::unlock_bold, IconState::activable); + const IconManager::Icon &icon_disable = get_icon(m_icons, m_keep_up ? IconType::lock : IconType::unlock, IconState::disabled); + if (button(icon, icon_hover, icon_disable)) { + m_keep_up = !m_keep_up; if (m_keep_up) { // copy angle to volume m_volume->text_configuration->style.prop.angle = font_prop.angle; } } if (ImGui::IsItemHovered()) - ImGui::SetTooltip("%s", _u8L("Lock the text's rotation when moving text along the object's surface.").c_str()); + ImGui::SetTooltip("%s", (m_keep_up? + _u8L("Unlock the text's up orientation when moving text along the object's surface."): + _u8L("Lock the text's up orientation when moving text along the object's surface.") + ).c_str()); // when more collection add selector if (ff.font_file->infos.size() > 1) { @@ -3270,7 +3281,11 @@ void GLGizmoEmboss::init_icons() "make_unbold.svg", "search.svg", "open.svg", - "exclamation.svg" + "exclamation.svg", + "lock_closed.svg", // lock, + "lock_closed_f.svg",// lock_bold, + "lock_open.svg", // unlock, + "lock_open_f.svg" // unlock_bold, }; assert(filenames.size() == static_cast(IconType::_count)); std::string path = resources_dir() + "/icons/"; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp index a57def86e5..d461425af6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.hpp @@ -182,6 +182,8 @@ private: float input_offset = 0.f; float advanced_input_offset = 0.f; + float lock_offset = 0.f; + ImVec2 text_size; // maximal size of face name image From eec51c67d32e18b079e72a4c9d4745a0d2f8f727 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Wed, 29 Mar 2023 10:49:35 +0200 Subject: [PATCH 2/2] Refactoring of PrintObject::discover_vertical_shells() for readability and efficiency. Also added an experiment of adding one more "ensuring" layer to support top / bottom surfaces, disabled with one_more_layer_below_top_bottom_surfaces --- src/libslic3r/PrintObject.cpp | 61 +++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 61067ed18d..26b359c0e7 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -1373,43 +1373,56 @@ void PrintObject::discover_vertical_shells() } #endif /* SLIC3R_DEBUG_SLICE_PROCESSING */ polygons_append(holes, cache_top_botom_regions[idx_layer].holes); + auto combine_holes = [&holes](const Polygons &holes2) { + if (holes.empty() || holes2.empty()) + holes.clear(); + else + holes = intersection(holes, holes2); + }; + auto combine_shells = [&shell](const Polygons &shells2) { + if (shell.empty()) + shell = std::move(shells2); + else if (! shells2.empty()) { + polygons_append(shell, shells2); + // Running the union_ using the Clipper library piece by piece is cheaper + // than running the union_ all at once. + shell = union_(shell); + } + }; + static constexpr const bool one_more_layer_below_top_bottom_surfaces = false; if (int n_top_layers = region_config.top_solid_layers.value; n_top_layers > 0) { // Gather top regions projected to this layer. coordf_t print_z = layer->print_z; - for (int i = int(idx_layer) + 1; - i < int(cache_top_botom_regions.size()) && - (i < int(idx_layer) + n_top_layers || - m_layers[i]->print_z - print_z < region_config.top_solid_min_thickness - EPSILON); + int i = int(idx_layer) + 1; + int itop = int(idx_layer) + n_top_layers; + for (; i < int(cache_top_botom_regions.size()) && + (i < itop || m_layers[i]->print_z - print_z < region_config.top_solid_min_thickness - EPSILON); ++ i) { const DiscoverVerticalShellsCacheEntry &cache = cache_top_botom_regions[i]; - if (! holes.empty()) - holes = intersection(holes, cache.holes); - if (! cache.top_surfaces.empty()) { - polygons_append(shell, cache.top_surfaces); - // Running the union_ using the Clipper library piece by piece is cheaper - // than running the union_ all at once. - shell = union_(shell); - } + combine_holes(cache.holes); + combine_shells(cache.top_surfaces); } + if (one_more_layer_below_top_bottom_surfaces) + if (i < int(cache_top_botom_regions.size()) && + (i <= itop || m_layers[i]->bottom_z() - print_z < region_config.top_solid_min_thickness - EPSILON)) + combine_holes(cache_top_botom_regions[i].holes); } if (int n_bottom_layers = region_config.bottom_solid_layers.value; n_bottom_layers > 0) { // Gather bottom regions projected to this layer. coordf_t bottom_z = layer->bottom_z(); - for (int i = int(idx_layer) - 1; - i >= 0 && - (i > int(idx_layer) - n_bottom_layers || - bottom_z - m_layers[i]->bottom_z() < region_config.bottom_solid_min_thickness - EPSILON); + int i = int(idx_layer) - 1; + int ibottom = int(idx_layer) - n_bottom_layers; + for (; i >= 0 && + (i > ibottom || bottom_z - m_layers[i]->bottom_z() < region_config.bottom_solid_min_thickness - EPSILON); -- i) { const DiscoverVerticalShellsCacheEntry &cache = cache_top_botom_regions[i]; - if (! holes.empty()) - holes = intersection(holes, cache.holes); - if (! cache.bottom_surfaces.empty()) { - polygons_append(shell, cache.bottom_surfaces); - // Running the union_ using the Clipper library piece by piece is cheaper - // than running the union_ all at once. - shell = union_(shell); - } + combine_holes(cache.holes); + combine_shells(cache.bottom_surfaces); } + if (one_more_layer_below_top_bottom_surfaces) + if (i >= 0 && + (i > ibottom || bottom_z - m_layers[i]->print_z < region_config.bottom_solid_min_thickness - EPSILON)) + combine_holes(cache_top_botom_regions[i].holes); } #ifdef SLIC3R_DEBUG_SLICE_PROCESSING {