From 2dba40789f2d9a9042bcd342a2efd0b826834ac2 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 15 Mar 2023 13:33:46 +0100 Subject: [PATCH] Some refactoring related to sequential print clearance contours --- src/slic3r/GUI/GLCanvas3D.cpp | 41 ++++++++++------------- src/slic3r/GUI/GLCanvas3D.hpp | 28 +++++----------- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 14 ++++---- src/slic3r/GUI/Plater.cpp | 26 +++++++------- 4 files changed, 47 insertions(+), 62 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index fd9fe3a71..661d276cb 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -880,7 +880,7 @@ void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas ImGui::PopStyleVar(2); } -void GLCanvas3D::SequentialPrintClearance::set_contours(const ContoursList& contours) +void GLCanvas3D::SequentialPrintClearance::set_contours(const ContoursList& contours, bool generate_fill) { m_contours.clear(); m_instances.clear(); @@ -889,7 +889,7 @@ void GLCanvas3D::SequentialPrintClearance::set_contours(const ContoursList& cont if (contours.empty()) return; - if (m_render_fill) { + if (generate_fill) { GLModel::Geometry fill_data; fill_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; fill_data.color = { 0.3333f, 0.0f, 0.0f, 0.5f }; @@ -966,8 +966,7 @@ void GLCanvas3D::SequentialPrintClearance::render() glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - if (m_render_fill) - m_fill.render(); + m_fill.render(); #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_core_profile()) { @@ -991,7 +990,7 @@ void GLCanvas3D::SequentialPrintClearance::render() for (const auto& [id, trafo] : m_instances) { shader->set_uniform("view_model_matrix", camera.get_view_matrix() * trafo); assert(id < m_contours.size()); - m_contours[id].set_color(m_render_fill ? FILL_COLOR : m_evaluating ? NO_FILL_EVALUATING_COLOR : NO_FILL_COLOR); + m_contours[id].set_color(m_fill.is_initialized() ? FILL_COLOR : m_evaluating ? NO_FILL_EVALUATING_COLOR : NO_FILL_COLOR); m_contours[id].render(); } @@ -3487,17 +3486,12 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // Not only detection of some modifiers !!! if (evt.Dragging()) { GLGizmosManager::EType c = m_gizmos.get_current_type(); - if (current_printer_technology() == ptFFF && - fff_print()->config().complete_objects){ - if (c == GLGizmosManager::EType::Move || - c == GLGizmosManager::EType::Scale || - c == GLGizmosManager::EType::Rotate) + if (c == GLGizmosManager::EType::Move || + c == GLGizmosManager::EType::Scale || + c == GLGizmosManager::EType::Rotate) { + show_sinking_contours(); + if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) update_sequential_clearance(true); - } else { - if (c == GLGizmosManager::EType::Move || - c == GLGizmosManager::EType::Scale || - c == GLGizmosManager::EType::Rotate) - show_sinking_contours(); } } else if (evt.LeftUp() && @@ -4005,7 +3999,7 @@ void GLCanvas3D::do_move(const std::string& snapshot_type) if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) { update_sequential_clearance(true); - m_sequential_print_clearance.set_evaluating(true); + m_sequential_print_clearance.m_evaluating = true; } m_dirty = true; @@ -4093,7 +4087,7 @@ void GLCanvas3D::do_rotate(const std::string& snapshot_type) if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) { update_sequential_clearance(true); - m_sequential_print_clearance.set_evaluating(true); + m_sequential_print_clearance.m_evaluating = true; } m_dirty = true; @@ -4170,7 +4164,7 @@ void GLCanvas3D::do_scale(const std::string& snapshot_type) if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) { update_sequential_clearance(true); - m_sequential_print_clearance.set_evaluating(true); + m_sequential_print_clearance.m_evaluating = true; } m_dirty = true; @@ -4475,6 +4469,9 @@ void GLCanvas3D::update_sequential_clearance(bool force_contours_generation) // second: fill temporary cache with data from volumes for (const GLVolume* v : m_volumes.volumes) { + if (v->is_wipe_tower) + continue; + const int object_idx = v->object_idx(); const int instance_idx = v->instance_idx(); auto& transform = instance_transforms[object_idx][instance_idx]; @@ -4490,12 +4487,11 @@ void GLCanvas3D::update_sequential_clearance(bool force_contours_generation) Geometry::rotation_transform(Geometry::rotation_diff_z(hull_trafo, inst_trafo.get_matrix()) * Vec3d::UnitZ()); }; - set_sequential_print_clearance_render_fill(false); - // calculates objects 2d hulls (see also: Print::sequential_print_horizontal_clearance_valid()) // this is done only the first time this method is called while moving the mouse, // the results are then cached for following displacements if (force_contours_generation || m_sequential_print_clearance_first_displacement) { + m_sequential_print_clearance.m_evaluating = false; m_sequential_print_clearance.m_hulls_2d_cache.clear(); const float shrink_factor = static_cast(scale_(0.5 * fff_print()->config().extruder_clearance_radius.value - EPSILON)); const double mitter_limit = scale_(0.1); @@ -4537,7 +4533,7 @@ void GLCanvas3D::update_sequential_clearance(bool force_contours_generation) } } - set_sequential_print_clearance_contours(contours); + set_sequential_print_clearance_contours(contours, false); m_sequential_print_clearance_first_displacement = false; } else { @@ -4554,9 +4550,6 @@ void GLCanvas3D::update_sequential_clearance(bool force_contours_generation) m_sequential_print_clearance.update_instances_trafos(trafos); } } - - // sends instances 2d hulls to be rendered - set_sequential_print_clearance_visible(true); } bool GLCanvas3D::is_object_sinking(int object_idx) const diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 68b532f66..7e8cc5d25 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -638,18 +638,13 @@ private: std::vector m_contours; // list of transforms used to render the contours std::vector> m_instances; - bool m_render_fill{ true }; - bool m_visible{ false }; bool m_evaluating{ false }; std::vector> m_hulls_2d_cache; public: - void set_contours(const ContoursList& contours); + void set_contours(const ContoursList& contours, bool generate_fill); void update_instances_trafos(const std::vector& trafos); - void set_render_fill(bool render_fill) { m_render_fill = render_fill; } - void set_visible(bool visible) { m_visible = visible; } - void set_evaluating(bool evaluating) { m_evaluating = evaluating; } void render(); bool empty() const { return m_contours.empty(); } @@ -975,25 +970,20 @@ public: } void reset_sequential_print_clearance() { - m_sequential_print_clearance.set_visible(false); - m_sequential_print_clearance.set_render_fill(false); - m_sequential_print_clearance.set_contours(ContoursList()); + m_sequential_print_clearance.m_evaluating = false; + m_sequential_print_clearance.set_contours(ContoursList(), false); } - void set_sequential_print_clearance_visible(bool visible) { - m_sequential_print_clearance.set_visible(visible); + void set_sequential_print_clearance_contours(const ContoursList& contours, bool generate_fill) { + m_sequential_print_clearance.set_contours(contours, generate_fill); } - void set_sequential_print_clearance_render_fill(bool render_fill) { - m_sequential_print_clearance.set_render_fill(render_fill); + bool is_sequential_print_clearance_empty() const { + return m_sequential_print_clearance.empty(); } - void set_sequential_print_clearance_contours(const ContoursList& contours) { - m_sequential_print_clearance.set_contours(contours); - } - - void set_sequential_print_clearance_evaluating(bool evaluating) { - m_sequential_print_clearance.set_evaluating(evaluating); + bool is_sequential_print_clearance_evaluating() const { + return m_sequential_print_clearance.m_evaluating; } void update_sequential_clearance(bool force_contours_generation); diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index d86c8275e..ae40e0f76 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -859,13 +859,13 @@ wxString ObjectManipulation::coordinate_type_str(ECoordinatesType type) #if ENABLE_OBJECT_MANIPULATION_DEBUG void ObjectManipulation::render_debug_window() { - ImGuiWrapper& imgui = *wxGetApp().imgui(); -// ImGui::SetNextWindowCollapsed(true, ImGuiCond_Once); - imgui.begin(std::string("ObjectManipulation"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize); - imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Coordinates type"); - ImGui::SameLine(); - imgui.text(coordinate_type_str(m_coordinates_type)); - imgui.end(); + ImGuiWrapper& imgui = *wxGetApp().imgui(); +// ImGui::SetNextWindowCollapsed(true, ImGuiCond_Once); + imgui.begin(std::string("ObjectManipulation"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize); + imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Coordinates type"); + ImGui::SameLine(); + imgui.text(coordinate_type_str(m_coordinates_type)); + imgui.end(); } #endif // ENABLE_OBJECT_MANIPULATION_DEBUG diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5a815892e..27f6a38f9 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3294,24 +3294,26 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool // or hide the old one. process_validation_warning(warning); if (printer_technology == ptFFF) { - view3D->get_canvas3d()->reset_sequential_print_clearance(); - view3D->get_canvas3d()->set_as_dirty(); - view3D->get_canvas3d()->request_extra_frame(); + GLCanvas3D* canvas = view3D->get_canvas3d(); + if (canvas->is_sequential_print_clearance_evaluating()) { + canvas->reset_sequential_print_clearance(); + canvas->set_as_dirty(); + canvas->request_extra_frame(); + } } } else { - // The print is not valid. - // Show error as notification. + // The print is not valid. + // Show error as notification. notification_manager->push_validate_error_notification(err); return_state |= UPDATE_BACKGROUND_PROCESS_INVALID; if (printer_technology == ptFFF) { - const Print* print = background_process.fff_print(); - GLCanvas3D::ContoursList contours; - contours.contours = print->get_sequential_print_clearance_contours(); - view3D->get_canvas3d()->set_sequential_print_clearance_visible(!contours.empty()); - view3D->get_canvas3d()->set_sequential_print_clearance_render_fill(!contours.empty()); - view3D->get_canvas3d()->set_sequential_print_clearance_contours(contours); - view3D->get_canvas3d()->set_sequential_print_clearance_evaluating(false); + GLCanvas3D* canvas = view3D->get_canvas3d(); + if (canvas->is_sequential_print_clearance_empty() || canvas->is_sequential_print_clearance_evaluating()) { + GLCanvas3D::ContoursList contours; + contours.contours = background_process.fff_print()->get_sequential_print_clearance_contours(); + canvas->set_sequential_print_clearance_contours(contours, true); + } } } }