From 4ffe76f012529185aa7834adea53087063b3959f Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Fri, 18 Jan 2019 15:02:07 +0100 Subject: [PATCH] Cut: Prevent the neither part kept option --- src/slic3r/GUI/GLGizmo.cpp | 4 +++- src/slic3r/GUI/ImGuiWrapper.cpp | 23 +++++++++++++++++++++++ src/slic3r/GUI/ImGuiWrapper.hpp | 5 ++++- src/slic3r/GUI/Plater.cpp | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index 9decc625d..2ea7e677e 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -2466,11 +2466,13 @@ void GLGizmoCut::on_render_input_window(float x, float y, const GLCanvas3D::Sele m_imgui->checkbox(_(L("Keep lower part")), m_keep_lower); m_imgui->checkbox(_(L("Rotate lower part upwards")), m_rotate_lower); + m_imgui->disabled_begin(!m_keep_upper && !m_keep_lower); const bool cut_clicked = m_imgui->button(_(L("Perform cut"))); + m_imgui->disabled_end(); m_imgui->end(); - if (cut_clicked) { + if (cut_clicked && (m_keep_upper || m_keep_lower)) { perform_cut(selection); } } diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 2cc22d2b5..7ce34d4e2 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -12,6 +12,8 @@ #include +#include + #include "libslic3r/libslic3r.h" #include "libslic3r/Utils.hpp" #include "GUI.hpp" @@ -23,6 +25,7 @@ namespace GUI { ImGuiWrapper::ImGuiWrapper() : m_font_texture(0) , m_mouse_buttons(0) + , m_disabled(false) { } @@ -154,6 +157,26 @@ void ImGuiWrapper::text(const wxString &label) ImGui::Text(label_utf8.c_str(), NULL); } +void ImGuiWrapper::disabled_begin(bool disabled) +{ + wxCHECK_RET(!m_disabled, "ImGUI: Unbalanced disabled_begin() call"); + + if (disabled) { + ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); + ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); + m_disabled = true; + } +} + +void ImGuiWrapper::disabled_end() +{ + if (m_disabled) { + ImGui::PopItemFlag(); + ImGui::PopStyleVar(); + m_disabled = false; + } +} + bool ImGuiWrapper::want_mouse() const { return ImGui::GetIO().WantCaptureMouse; diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index cd8508aef..5293bee26 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -21,8 +21,8 @@ class ImGuiWrapper FontsMap m_fonts; unsigned m_font_texture; - unsigned m_mouse_buttons; + bool m_disabled; public: ImGuiWrapper(); @@ -50,6 +50,9 @@ public: bool checkbox(const wxString &label, bool &value); void text(const wxString &label); + void disabled_begin(bool disabled); + void disabled_end(); + bool want_mouse() const; bool want_keyboard() const; bool want_text_input() const; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ad4472bcf..7cdb8cfc8 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2767,6 +2767,10 @@ void Plater::cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_uppe wxCHECK_RET(instance_idx < object->instances.size(), "instance_idx out of bounds"); + if (!keep_upper && !keep_lower) { + return; + } + const auto new_objects = object->cut(instance_idx, z, keep_upper, keep_lower, rotate_lower); remove(obj_idx);