From eb431db7ed9d76008078add31552b74d5af19c27 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 20 May 2021 11:04:47 +0200 Subject: [PATCH 1/5] Test --- src/slic3r/GUI/GCodeViewer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index ce4c18a53..209679c0f 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -591,7 +591,7 @@ void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print& m_last_result_id = gcode_result.id; // release gpu memory, if used - reset(); + reset(); #if ENABLE_GCODE_WINDOW m_sequential_view.gcode_window.set_filename(gcode_result.filename); From f0ef5e409dd15d12efdbe447bc68505ddf1dc802 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 20 May 2021 12:53:47 +0200 Subject: [PATCH 2/5] Added unit test for calculation of 2D convex hull of sinking object --- tests/libslic3r/test_3mf.cpp | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/libslic3r/test_3mf.cpp b/tests/libslic3r/test_3mf.cpp index fb41ef93b..d6d3686d9 100644 --- a/tests/libslic3r/test_3mf.cpp +++ b/tests/libslic3r/test_3mf.cpp @@ -85,3 +85,43 @@ SCENARIO("Export+Import geometry to/from 3mf file cycle", "[3mf]") { } } } + +SCENARIO("2D convex hull of sinking object", "[3mf]") { + GIVEN("model") { + // load a model + Model model; + std::string src_file = std::string(TEST_DATA_DIR) + "/test_3mf/Prusa.stl"; + load_stl(src_file.c_str(), &model); + model.add_default_instances(); + + WHEN("model is rotated, scaled and set as sinking") { + ModelObject* object = model.objects[0]; + object->center_around_origin(false); + + // set instance's attitude so that it is rotated, scaled and sinking + ModelInstance* instance = object->instances[0]; + instance->set_rotation(Y, -M_PI / 4.0); + instance->set_offset(Vec3d::Zero()); + instance->set_scaling_factor({ 2.0, 2.0, 2.0 }); + + // calculate 2D convex hull + Polygon hull_2d = object->convex_hull_2d(instance->get_transformation().get_matrix()); + + // verify result + Points result = { + { -4242641, -16299551 }, + { -4241, -19502998 }, + { 66824768, -19502998 }, + { 66824768, 19502998 }, + { -4244, 19502998 }, + { -4242640, -8537523 } + }; + bool res = hull_2d.points == result; + + THEN("2D convex hull should match with reference") { + REQUIRE(res); + } + } + } +} + From 635bf8d9f14e3556d2f43ee09540360409c01140 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 20 May 2021 13:09:25 +0200 Subject: [PATCH 3/5] Notifications: Calculating space left for hypertext with escaped text --- src/slic3r/GUI/NotificationManager.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index 1b29b7f76..921f9f2b1 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -6,6 +6,7 @@ #include "PrintHostDialogs.hpp" #include "wxExtensions.hpp" #include "../Utils/PrintHost.hpp" +#include "libslic3r/Config.hpp" #include #include @@ -304,8 +305,8 @@ void NotificationManager::PopNotification::count_lines() } // hypertext calculation if (!m_hypertext.empty()) { - int prev_end = m_endlines.size() > 1 ? m_endlines[m_endlines.size() - 2] : 0; - if (ImGui::CalcTextSize((text.substr(prev_end, last_end - prev_end) + m_hypertext).c_str()).x > m_window_width - m_window_width_offset) { + int prev_end = m_endlines.size() > 1 ? m_endlines[m_endlines.size() - 2] : 0; // m_endlines.size() - 2 because we are fitting hypertext instead of last endline + if (ImGui::CalcTextSize((escape_string_cstyle(text.substr(prev_end, last_end - prev_end)) + m_hypertext).c_str()).x > m_window_width - m_window_width_offset) { m_endlines.push_back(last_end); m_lines_count++; } @@ -366,7 +367,7 @@ void NotificationManager::PopNotification::render_text(ImGuiWrapper& imgui, cons } //hyperlink text if (!m_hypertext.empty()) { - render_hypertext(imgui, x_offset + ImGui::CalcTextSize((line + " ").c_str()).x, starting_y + (m_lines_count - 1) * shift_y, m_hypertext); + render_hypertext(imgui, x_offset + ImGui::CalcTextSize((line + (line.empty() ? "" : " ")).c_str()).x, starting_y + (m_lines_count - 1) * shift_y, m_hypertext); } From ef9004cee462b96a0b7e4910f9983fe73586b530 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 20 May 2021 13:58:27 +0200 Subject: [PATCH 4/5] Fix of its_collect_mesh_projection_points_above() Fix of perl integration tests after introduction of not using the mesh below the print bed. --- lib/Slic3r/Test.pm | 4 ++-- src/libslic3r/TriangleMesh.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/Test.pm b/lib/Slic3r/Test.pm index 570bca41b..8d2a79f2a 100644 --- a/lib/Slic3r/Test.pm +++ b/lib/Slic3r/Test.pm @@ -192,12 +192,12 @@ sub init_print { if (defined $params{duplicate} && $params{duplicate} > 1) { $model->duplicate($params{duplicate} // 1, $config->min_object_distance); } - $model->arrange_objects($config->min_object_distance); - $model->center_instances_around_point($params{print_center} ? Slic3r::Pointf->new(@{$params{print_center}}) : Slic3r::Pointf->new(100,100)); foreach my $model_object (@{$model->objects}) { $model_object->ensure_on_bed; $print->auto_assign_extruders($model_object); } + $model->arrange_objects($config->min_object_distance); + $model->center_instances_around_point($params{print_center} ? Slic3r::Pointf->new(@{$params{print_center}}) : Slic3r::Pointf->new(100,100)); $print->apply($model, $config); $print->validate; diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index 8648edc52..fba1429ea 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -914,7 +914,7 @@ void its_collect_mesh_projection_points_above(const indexed_triangle_set &its, c float t = (z - p1.z()) / (p2.z() - p1.z()); all_pts.emplace_back(scaled(p1.x() + (p2.x() - p1.x()) * t), scaled(p1.y() + (p2.y() - p1.y()) * t)); } - if (p2.z() > z) + if (p2.z() >= z) all_pts.emplace_back(scaled(p2.x()), scaled(p2.y())); iprev = iedge; } From 2bd3e018b129358b5b952487ae5e78038e2c57cc Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 20 May 2021 14:42:40 +0200 Subject: [PATCH 5/5] Follow-up of d54548367a946f4c1c388a91fca61f1589533fa2 -> Reintroduce GLCanvas3D::m_old_size to avoid unneeded calls to render() --- src/slic3r/GUI/GLCanvas3D.cpp | 8 ++++++++ src/slic3r/GUI/GLCanvas3D.hpp | 8 ++++++++ src/slic3r/GUI/Plater.cpp | 10 +++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index ea3bec131..3829ab0d1 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4527,6 +4527,14 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h) if (m_canvas == nullptr && m_context == nullptr) return; +#if ENABLE_SCROLLABLE_LEGEND + const std::array new_size = { w, h }; + if (m_old_size == new_size) + return; + + m_old_size = new_size; +#endif // ENABLE_SCROLLABLE_LEGEND + auto *imgui = wxGetApp().imgui(); imgui->set_display_size(static_cast(w), static_cast(h)); const float font_size = 1.5f * wxGetApp().em_unit(); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index a5c010d95..f7493f157 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -425,6 +425,10 @@ private: Model* m_model; BackgroundSlicingProcess *m_process; +#if ENABLE_SCROLLABLE_LEGEND + std::array m_old_size{ 0, 0 }; +#endif // ENABLE_SCROLLABLE_LEGEND + // Screen is only refreshed from the OnIdle handler if it is dirty. bool m_dirty; bool m_initialized; @@ -733,6 +737,10 @@ public: #endif } +#if ENABLE_SCROLLABLE_LEGEND + void reset_old_size() { m_old_size = { 0, 0 }; } +#endif // ENABLE_SCROLLABLE_LEGEND + private: bool _is_shown_on_screen() const; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index e306641a9..3aff82fb4 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3437,8 +3437,12 @@ void Plater::priv::set_current_panel(wxPanel* panel) // sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably) view3D->set_as_dirty(); +#if ENABLE_SCROLLABLE_LEGEND + // reset cached size to force a resize on next call to render() to keep imgui in synch with canvas size + view3D->get_canvas3d()->reset_old_size(); +#endif // ENABLE_SCROLLABLE_LEGEND view_toolbar.select_item("3D"); - if(notification_manager != nullptr) + if (notification_manager != nullptr) notification_manager->set_in_preview(false); } else if (current_panel == preview) { @@ -3457,6 +3461,10 @@ void Plater::priv::set_current_panel(wxPanel* panel) preview->reload_print(true); preview->set_as_dirty(); +#if ENABLE_SCROLLABLE_LEGEND + // reset cached size to force a resize on next call to render() to keep imgui in synch with canvas size + preview->get_canvas3d()->reset_old_size(); +#endif // ENABLE_SCROLLABLE_LEGEND view_toolbar.select_item("Preview"); if (notification_manager != nullptr) notification_manager->set_in_preview(true);