From 9fc75d7b34e0e1ca93f8c495d52a2d5d0e6d4959 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 6 Feb 2019 15:16:25 +0100 Subject: [PATCH] SLA support points (better backend->frontend synchronization and more) - backend to frontend data synchronization to inform the gizmo that new points have been generated - fixed the inadvertent cancellation of background processing caused by the SLA gizmo touching frontend data during the process - inactive instances of the object are hidden when the SLA gizmo is active - fix of imgui combobox rendering --- src/slic3r/GUI/GLCanvas3D.cpp | 5 +++-- src/slic3r/GUI/GLCanvas3D.hpp | 2 +- src/slic3r/GUI/GLGizmo.cpp | 14 ++++++++------ src/slic3r/GUI/GLGizmo.hpp | 1 + src/slic3r/GUI/ImGuiWrapper.cpp | 10 +++++----- src/slic3r/GUI/Plater.cpp | 1 + 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 210d00eef..883d08314 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4238,10 +4238,11 @@ void GLCanvas3D::toggle_sla_auxiliaries_visibility(bool visible) m_render_sla_auxiliaries = visible; } -void GLCanvas3D::toggle_model_objects_visibility(bool visible, const ModelObject* mo) +void GLCanvas3D::toggle_model_objects_visibility(bool visible, const ModelObject* mo, int instance_idx) { for (GLVolume* vol : m_volumes.volumes) { - if (mo == nullptr || m_model->objects[vol->composite_id.object_id] == mo) + if (mo == nullptr + | (m_model->objects[vol->composite_id.object_id] == mo && vol->composite_id.instance_id == instance_idx)) vol->is_active = visible; } if (visible && !mo) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 8e4acd724..9f341083b 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -952,7 +952,7 @@ public: int check_volumes_outside_state() const; void toggle_sla_auxiliaries_visibility(bool visible); - void toggle_model_objects_visibility(bool visible, const ModelObject* mo = nullptr); + void toggle_model_objects_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1); void set_config(const DynamicPrintConfig* config); void set_process(BackgroundSlicingProcess* process); diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index fc7350207..563ac3259 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -1782,28 +1782,30 @@ void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const G if (selection.is_empty()) m_old_instance_id = -1; + m_active_instance = selection.get_instance_idx(); + if ((model_object != nullptr) && selection.is_from_single_instance()) { if (is_mesh_update_necessary()) update_mesh(); // If there are no points, let's ask the backend if it calculated some. - if (model_object->sla_support_points.empty() && m_parent.sla_print()->is_step_done(slaposSupportPoints)) { + if (m_editing_mode_cache.empty() && m_parent.sla_print()->is_step_done(slaposSupportPoints)) { for (const SLAPrintObject* po : m_parent.sla_print()->objects()) { if (po->model_object()->id() == model_object->id()) { const Eigen::MatrixXd& points = po->get_support_points(); for (unsigned int i=0; isla_support_points.emplace_back(po->trafo().inverse().cast() * Vec3f(points(i,0), points(i,1), points(i,2)), + m_editing_mode_cache.emplace_back(po->trafo().inverse().cast() * Vec3f(points(i,0), points(i,1), points(i,2)), points(i, 3), points(i, 4)); break; } } } - if (m_old_model_object != m_model_object) - m_editing_mode_cache = m_model_object->sla_support_points; // make a copy of ModelObject's support points + if (m_model_object != m_old_model_object) + m_editing_mode = false; if (m_state == On) { m_parent.toggle_model_objects_visibility(false); - m_parent.toggle_model_objects_visibility(true, m_model_object); + m_parent.toggle_model_objects_visibility(true, m_model_object, m_active_instance); } } } @@ -2221,7 +2223,7 @@ void GLGizmoSlaSupports::on_set_state() m_parent.toggle_model_objects_visibility(false); if (m_model_object) - m_parent.toggle_model_objects_visibility(true, m_model_object); + m_parent.toggle_model_objects_visibility(true, m_model_object, m_active_instance); } if (m_state == Off) m_parent.toggle_model_objects_visibility(true); diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index 060be6fbb..f5ddbd76f 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -442,6 +442,7 @@ class GLGizmoSlaSupports : public GLGizmoBase private: ModelObject* m_model_object = nullptr; ModelObject* m_old_model_object = nullptr; + int m_active_instance = -1; int m_old_instance_id = -1; Vec3f unproject_on_mesh(const Vec2d& mouse_pos); diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 4f5cbf749..3ce187a44 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -170,17 +170,17 @@ void ImGuiWrapper::text(const wxString &label) void ImGuiWrapper::combo(const wxString& label, const std::vector& options, wxString& selection) { - const char* selection_u8 = into_u8(selection).c_str(); + std::string selection_u8 = into_u8(selection); // this is to force the label to the left of the widget: text(label); ImGui::SameLine(); - if (ImGui::BeginCombo("", selection_u8)) { + if (ImGui::BeginCombo("", selection_u8.c_str())) { for (const wxString& option : options) { - const char* option_u8 = into_u8(option).c_str(); - bool is_selected = (selection_u8 == nullptr) ? false : strcmp(option_u8, selection_u8) == 0; - if (ImGui::Selectable(option_u8, is_selected)) + std::string option_u8 = into_u8(option); + bool is_selected = (selection_u8.empty()) ? false : (option_u8 == selection_u8); + if (ImGui::Selectable(option_u8.c_str(), is_selected)) selection = option_u8; } ImGui::EndCombo(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 709e9c9e5..671b6499f 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2231,6 +2231,7 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent &evt) } if (evt.status.flags & PrintBase::SlicingStatus::RELOAD_SLA_SUPPORT_POINTS) { // Update SLA gizmo + q->canvas3D()->reload_scene(true); } }