diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 07119b8de..decd55dd2 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -3961,7 +3961,23 @@ void ObjectList::fix_through_netfabb() void ObjectList::simplify() { - GLGizmosManager& gizmos_mgr = wxGetApp().plater()->canvas3D()->get_gizmos_manager(); + auto plater = wxGetApp().plater(); + GLGizmosManager& gizmos_mgr = plater->canvas3D()->get_gizmos_manager(); + + // Do not simplify when a gizmo is open. There might be issues with updates + // and what is worse, the snapshot time would refer to the internal stack. + auto current_type = gizmos_mgr.get_current_type(); + if (current_type == GLGizmosManager::Simplify) { + // close first + gizmos_mgr.open_gizmo(GLGizmosManager::EType::Simplify); + }else if (current_type != GLGizmosManager::Undefined) { + plater->get_notification_manager()->push_notification( + NotificationType::CustomSupportsAndSeamRemovedAfterRepair, + NotificationManager::NotificationLevel::RegularNotification, + _u8L("ERROR: Please close all manipulators available from " + "the left toolbar before start simplify the mesh.")); + return; + } gizmos_mgr.open_gizmo(GLGizmosManager::EType::Simplify); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp index 06a999cad..a921a121e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp @@ -1,17 +1,14 @@ -// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. #include "GLGizmoSimplify.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GUI_App.hpp" -#include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/GUI_ObjectManipulation.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" +#include "slic3r/GUI/NotificationManager.hpp" +#include "slic3r/GUI/Plater.hpp" #include "libslic3r/AppConfig.hpp" #include "libslic3r/Model.hpp" #include "libslic3r/QuadricEdgeCollapse.hpp" -#include -#include - namespace Slic3r::GUI { GLGizmoSimplify::GLGizmoSimplify(GLCanvas3D & parent, @@ -38,7 +35,6 @@ bool GLGizmoSimplify::on_init() return true; } - std::string GLGizmoSimplify::on_get_name() const { return (_L("Simplify")).ToUTF8().data(); @@ -195,6 +191,11 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi process(); } else { // use preview and close + if (m_original_its.has_value()) { + // fix hollowing, sla support points, modifiers, ... + auto plater = wxGetApp().plater(); + plater->changed_mesh(m_obj_index); + } close(); } } @@ -213,18 +214,17 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi if (m_need_reload) { m_need_reload = false; - + bool close_on_end = (m_state == State::close_on_end); // Reload visualization of mesh - change VBO, FBO on GPU m_parent.reload_scene(true); - if (m_state == State::close_on_end) { + // set m_state must be before close() !!! + m_state = State::settings; + if (close_on_end) { // fix hollowing, sla support points, modifiers, ... auto plater = wxGetApp().plater(); plater->changed_mesh(m_obj_index); close(); } - - // change from simplifying | apply - m_state = State::settings; // Fix warning icon in object list wxGetApp().obj_list()->update_item_error_icon(m_obj_index, -1); @@ -287,7 +287,6 @@ void GLGizmoSimplify::process() m_last_error = max_error; } catch (SimplifyCanceledException &) { // set state out of main thread - m_last_error = {}; m_state = State::settings; } // need to render last status fn to change bar graph to buttons @@ -310,10 +309,30 @@ bool GLGizmoSimplify::on_is_activable() const } void GLGizmoSimplify::on_set_state() -{ +{ // Closing gizmo. e.g. selecting another one if (GLGizmoBase::m_state == GLGizmoBase::Off) { - m_volume = nullptr; + + // refuse outgoing during simlification + if (m_state != State::settings) { + GLGizmoBase::m_state = GLGizmoBase::On; + auto notification_manager = wxGetApp().plater()->get_notification_manager(); + notification_manager->push_notification( + NotificationType::CustomNotification, + NotificationManager::NotificationLevel::RegularNotification, + _u8L("ERROR: Wait until Simplification ends or Cancel process.")); + return; + } + + // revert preview + if (m_original_its.has_value()) { + set_its(*m_original_its); + m_parent.reload_scene(true); + m_need_reload = false; + } + + // invalidate selected model + m_volume = nullptr; } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp index 5a84cabad..4539fef01 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp @@ -1,14 +1,20 @@ #ifndef slic3r_GLGizmoSimplify_hpp_ #define slic3r_GLGizmoSimplify_hpp_ +// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, +// which overrides our localization "L" macro. #include "GLGizmoBase.hpp" -#include "libslic3r/Model.hpp" +#include "admesh/stl.h" // indexed_triangle_set #include #include namespace Slic3r { + +class ModelVolume; + namespace GUI { + class GLGizmoSimplify : public GLGizmoBase { public: diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 22a1b36ae..e037a0ac8 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4283,6 +4283,12 @@ bool Plater::priv::can_fix_through_netfabb() const bool Plater::priv::can_simplify() const { + // is object for simplification selected + if (get_selected_object_idx() < 0) return false; + // is already opened? + if (q->canvas3D()->get_gizmos_manager().get_current_type() == + GLGizmosManager::EType::Simplify) + return false; return true; }