From 815989d488f4c3a3ccbc552509fa09c49dd359be Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 1 Apr 2020 19:01:00 +0200 Subject: [PATCH] The print bed is limited to 1.2m x 1.2m. (related to #2877) --- src/slic3r/GUI/BedShapeDialog.cpp | 4 ++++ src/slic3r/GUI/Field.cpp | 31 ++++++++++++++++++++++++++++--- src/slic3r/GUI/Field.hpp | 1 + 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/BedShapeDialog.cpp b/src/slic3r/GUI/BedShapeDialog.cpp index 58c76fe26b0..4357a371a49 100644 --- a/src/slic3r/GUI/BedShapeDialog.cpp +++ b/src/slic3r/GUI/BedShapeDialog.cpp @@ -74,6 +74,8 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf ConfigOptionDef def; def.type = coPoints; def.set_default_value(new ConfigOptionPoints{ Vec2d(200, 200) }); + def.min = 0; + def.max = 1200; def.label = L("Size"); def.tooltip = L("Size in X and Y of the rectangular plate."); Option option(def, "rect_size"); @@ -81,6 +83,8 @@ void BedShapePanel::build_panel(const ConfigOptionPoints& default_pt, const Conf def.type = coPoints; def.set_default_value(new ConfigOptionPoints{ Vec2d(0, 0) }); + def.min = -600; + def.max = 600; def.label = L("Origin"); def.tooltip = L("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle."); option = Option(def, "rect_origin"); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 6d900797467..a1a6583bcc3 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -1242,12 +1242,24 @@ void PointCtrl::msw_rescale(bool rescale_sidetext/* = false*/) y_textctrl->SetMinSize(field_size); } +bool PointCtrl::value_was_changed(wxTextCtrl* win) +{ + if (m_value.empty()) + return true; + + boost::any val = m_value; + // update m_value! + get_value(); + + return boost::any_cast(m_value) != boost::any_cast(val); +} + void PointCtrl::propagate_value(wxTextCtrl* win) { - if (!win->GetValue().empty()) - on_change_field(); - else + if (win->GetValue().empty()) on_kill_focus(); + else if (value_was_changed(win)) + on_change_field(); } void PointCtrl::set_value(const Vec2d& value, bool change_event) @@ -1281,6 +1293,19 @@ boost::any& PointCtrl::get_value() double x, y; x_textctrl->GetValue().ToDouble(&x); y_textctrl->GetValue().ToDouble(&y); + + if (m_opt.min > x || x > m_opt.max || + m_opt.min > y || y > m_opt.max) + { + if (m_opt.min > x) x = m_opt.min; + if (x > m_opt.max) x = m_opt.max; + if (m_opt.min > y) y = m_opt.min; + if (y > m_opt.max) y = m_opt.max; + set_value(Vec2d(x, y), true); + + show_error(m_parent, _(L("Input value is out of range"))); + } + return m_value = Vec2d(x, y); } diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 1f8b642b104..5bdbfadc894 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -445,6 +445,7 @@ class PointCtrl : public Field { wxTextCtrl* y_textctrl{ nullptr }; void BUILD() override; + bool value_was_changed(wxTextCtrl* win); // Propagate value from field to the OptionGroupe and Config after kill_focus/ENTER void propagate_value(wxTextCtrl* win); void set_value(const Vec2d& value, bool change_event = false);