From f90ea5060d7d0633cbb6cea4ba7dba8eeacee620 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Sat, 27 Jan 2018 17:39:00 +0100 Subject: [PATCH] Fixed performance of preset switching. --- xs/src/slic3r/GUI/Field.cpp | 4 ++++ xs/src/slic3r/GUI/Field.hpp | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 976fa304df..995eff17a5 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -358,6 +358,8 @@ void Choice::set_value(const std::string value) //! Redundant? void Choice::set_value(boost::any value) { + m_disable_change_event = true; + switch (m_opt.type){ case coInt: case coFloat: @@ -388,6 +390,8 @@ void Choice::set_value(boost::any value) default: break; } + + m_disable_change_event = false; } //! it's needed for _update_serial_ports() diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index cca55cbeee..21f5dba452 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -49,6 +49,7 @@ public: /// Function object to store callback passed in from owning object. t_change m_on_change {nullptr}; + // This is used to avoid recursive invocation of the field change/update by wxWidgets. bool m_disable_change_event {false}; /// Copy of ConfigOption for deduction purposes @@ -112,10 +113,14 @@ public: wxWindow* window {nullptr}; virtual void set_value(std::string value) { + m_disable_change_event = true; dynamic_cast(window)->SetValue(wxString(value)); + m_disable_change_event = false; } virtual void set_value(boost::any value) { + m_disable_change_event = true; dynamic_cast(window)->SetValue(boost::any_cast(value)); + m_disable_change_event = false; } boost::any get_value() override; @@ -136,11 +141,15 @@ public: wxWindow* window{ nullptr }; void BUILD() override; - void set_value (const bool value) { + void set_value(const bool value) { + m_disable_change_event = true; dynamic_cast(window)->SetValue(value); + m_disable_change_event = false; } void set_value(boost::any value) { + m_disable_change_event = true; dynamic_cast(window)->SetValue(boost::any_cast(value)); + m_disable_change_event = false; } boost::any get_value() override { return boost::any(dynamic_cast(window)->GetValue()); @@ -163,10 +172,14 @@ public: void BUILD() override; void set_value(const std::string value) { + m_disable_change_event = true; dynamic_cast(window)->SetValue(value); + m_disable_change_event = false; } void set_value(boost::any value) { + m_disable_change_event = true; dynamic_cast(window)->SetValue(boost::any_cast(value)); + m_disable_change_event = false; } boost::any get_value() override { return boost::any(dynamic_cast(window)->GetValue()); @@ -207,10 +220,14 @@ public: void BUILD() override; void set_value(const std::string value) { - dynamic_cast(window)->SetColour(value); + m_disable_change_event = true; + dynamic_cast(window)->SetColour(value); + m_disable_change_event = false; } void set_value(boost::any value) { + m_disable_change_event = true; dynamic_cast(window)->SetColour(boost::any_cast(value)); + m_disable_change_event = false; } boost::any get_value() override {