From 3fd36f08e0a239fa58dcbdfcdf4c0e4281ff215b Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 22 Feb 2021 13:35:00 +0100 Subject: [PATCH] Show a notification when attempting to slice during SLA support points editing This should also fix #5736 and a similar crash when deleting an object during manual editing (which was introduced between 2.2.0 and 2.3.0) --- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 15 ++++++++++++ src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 2 ++ src/slic3r/GUI/Plater.cpp | 24 +++++++++++++++----- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 2f7fa4638..b5dbab284 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -903,7 +903,7 @@ void GLGizmoSlaSupports::on_set_state() m_new_point_head_diameter = static_cast(cfg.option("support_head_front_diameter"))->value; } if (m_state == Off && m_old_state != Off) { // the gizmo was just turned Off - bool will_ask = m_editing_mode && unsaved_changes(); + bool will_ask = m_editing_mode && unsaved_changes() && on_is_activable(); if (will_ask) { wxGetApp().CallAfter([this]() { // Following is called through CallAfter, because otherwise there was a problem diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index e3bb964ad..abbc8599b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -7,6 +7,7 @@ #include "slic3r/GUI/GUI_ObjectManipulation.hpp" #include "slic3r/GUI/Plater.hpp" #include "slic3r/Utils/UndoRedo.hpp" +#include "slic3r/GUI/NotificationManager.hpp" #include "slic3r/GUI/Gizmos/GLGizmoMove.hpp" #include "slic3r/GUI/Gizmos/GLGizmoScale.hpp" @@ -1139,5 +1140,19 @@ bool GLGizmosManager::grabber_contains_mouse() const return (curr != nullptr) ? (curr->get_hover_id() != -1) : false; } + +bool GLGizmosManager::is_in_editing_mode(bool error_notification) const +{ + if (m_current != SlaSupports || ! dynamic_cast(get_current())->is_in_editing_mode()) + return false; + + if (error_notification) + wxGetApp().plater()->get_notification_manager()->push_slicing_error_notification( + _u8L("You are currently editing SLA support points. Please, apply or discard " + "your changes first.")); + + return true; +} + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index 7f47167e9..917a5830c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -210,6 +210,8 @@ public: ClippingPlane get_clipping_plane() const; bool wants_reslice_supports_on_undo() const; + bool is_in_editing_mode(bool error_notification = false) const; + void render_current_gizmo() const; void render_current_gizmo_for_picking_pass() const; void render_painter_gizmo() const; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5b245afee..e8cd605cf 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -790,6 +790,9 @@ Sidebar::Sidebar(Plater *parent) p->btn_export_gcode->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { p->plater->export_gcode(false); }); p->btn_reslice->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { + if (p->plater->canvas3D()->get_gizmos_manager().is_in_editing_mode(true)) + return; + const bool export_gcode_after_slicing = wxGetKeyState(WXK_SHIFT); if (export_gcode_after_slicing) p->plater->export_gcode(true); @@ -4214,9 +4217,9 @@ bool Plater::priv::can_fix_through_netfabb() const bool Plater::priv::can_increase_instances() const { - if (m_ui_jobs.is_any_running()) { - return false; - } + if (m_ui_jobs.is_any_running() + || q->canvas3D()->get_gizmos_manager().is_in_editing_mode()) + return false; int obj_idx = get_selected_object_idx(); return (0 <= obj_idx) && (obj_idx < (int)model.objects.size()); @@ -4224,9 +4227,9 @@ bool Plater::priv::can_increase_instances() const bool Plater::priv::can_decrease_instances() const { - if (m_ui_jobs.is_any_running()) { - return false; - } + if (m_ui_jobs.is_any_running() + || q->canvas3D()->get_gizmos_manager().is_in_editing_mode()) + return false; int obj_idx = get_selected_object_idx(); return (0 <= obj_idx) && (obj_idx < (int)model.objects.size()) && (model.objects[obj_idx]->instances.size() > 1); @@ -5116,6 +5119,10 @@ void Plater::export_gcode(bool prefer_removable) if (p->model.objects.empty()) return; + if (canvas3D()->get_gizmos_manager().is_in_editing_mode(true)) + return; + + if (p->process_completed_with_error) return; @@ -5391,6 +5398,11 @@ void Plater::reslice() if (p->process_completed_with_error) return; + // In case SLA gizmo is in editing mode, refuse to continue + // and notify user that he should leave it first. + if (canvas3D()->get_gizmos_manager().is_in_editing_mode(true)) + return; + // Stop arrange and (or) optimize rotation tasks. this->stop_jobs();