From 35836654efebac27825a23aa554904c080c78172 Mon Sep 17 00:00:00 2001 From: Kunlong Ma Date: Mon, 8 Jan 2024 15:46:23 +0800 Subject: [PATCH] ENH: restrict the scope of multiplier JIRA: STUDIO-5781 1. restrict the scope of multiplier 2. Only numerical values can be entered in the input box Signed-off-by: Kunlong Ma Change-Id: Ie3cff3731b0e42c4bf8dbc879f3e4a74e0724224 --- src/slic3r/GUI/WipeTowerDialog.cpp | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/slic3r/GUI/WipeTowerDialog.cpp b/src/slic3r/GUI/WipeTowerDialog.cpp index a346670c1..74f309b3d 100644 --- a/src/slic3r/GUI/WipeTowerDialog.cpp +++ b/src/slic3r/GUI/WipeTowerDialog.cpp @@ -460,8 +460,42 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector& matrix, con param_sizer->AddStretchSpacer(1); m_sizer_advanced->Add(param_sizer, 0, wxEXPAND | wxLEFT, TEXT_BEG_PADDING); + wxStaticText* suggest = new wxStaticText(m_page_advanced, wxID_ANY, wxString::Format(_L("The multiplier should be in range [%.2f, %.2f]."), g_min_flush_multiplier, g_max_flush_multiplier)); + suggest->SetForegroundColour(g_text_color); + m_sizer_advanced->Add(suggest, 0, wxEXPAND | wxLEFT, TEXT_BEG_PADDING); + m_sizer_advanced->AddSpacer(5); + m_flush_multiplier_ebox->Bind(wxEVT_TEXT_ENTER, on_apply_text_modify); m_flush_multiplier_ebox->Bind(wxEVT_KILL_FOCUS, on_apply_text_modify); + m_flush_multiplier_ebox->Bind(wxEVT_COMMAND_TEXT_UPDATED, [this](wxCommandEvent&) { + wxString str = m_flush_multiplier_ebox->GetValue(); + float multiplier = wxAtof(str); + if (multiplier < g_min_flush_multiplier || multiplier > g_max_flush_multiplier) { + str = wxString::Format(("%.2f"), multiplier < g_min_flush_multiplier ? g_min_flush_multiplier : g_max_flush_multiplier); + m_flush_multiplier_ebox->SetValue(str); + m_flush_multiplier_ebox->SetInsertionPointEnd(); + } + }); + m_flush_multiplier_ebox->Bind(wxEVT_CHAR, [this](wxKeyEvent& e) { + int keycode = e.GetKeyCode(); + + if (keycode == WXK_NONE) + return; + + if (keycode == WXK_BACK || keycode == WXK_DELETE || keycode == WXK_RETURN || + keycode == WXK_LEFT || keycode == WXK_RIGHT || + keycode == WXK_HOME || keycode == WXK_END) { + e.Skip(); + return; + } + + wxString input_char = wxString::Format("%c", keycode); + long value; + if (!input_char.ToLong(&value) && input_char != ".") + return; + + e.Skip(); + }); } this->update_warning_texts();