diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 045c55d96..d64ae876b 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -18,6 +18,17 @@ namespace Slic3r { namespace GUI { wxNumberFormatter::ToString(value, precision, wxNumberFormatter::Style_None); } + void Field::PostInitialize(){ + m_Undo_btn = new wxButton(m_parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); + // use bouth of temporary_icons till don't have "undo_icon" + auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); + m_Undo_btn->SetBackgroundColour(color); + m_Undo_btn->SetBitmap(wxBitmap(from_u8(var("Bullet_white.png")), wxBITMAP_TYPE_PNG)); + m_Undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent){ on_back_to_initial_value(); })); + + BUILD(); + } + void Field::on_kill_focus(wxEvent& event) { // Without this, there will be nasty focus bugs on Windows. // Also, docs for wxEvent::Skip() say "In general, it is recommended to skip all @@ -34,6 +45,12 @@ namespace Slic3r { namespace GUI { m_on_change(m_opt_id, get_value()); } + void Field::on_back_to_initial_value() + { + if (m_back_to_initial_value != nullptr) + m_back_to_initial_value(m_opt_id); + } + wxString Field::get_tooltip_text(const wxString& default_string) { wxString tooltip_text(""); diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index 56de333cf..454cd1430 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -26,21 +26,14 @@ class Field; using t_field = std::unique_ptr; using t_kill_focus = std::function; using t_change = std::function; +using t_back_to_init = std::function; wxString double_to_string(double const value); class Field { protected: // factory function to defer and enforce creation of derived type. - virtual void PostInitialize(){ - m_Undo_btn = new wxButton(m_parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT|wxNO_BORDER); - // use bouth of temporary_icons till don't have "undo_icon" - m_Undo_btn->SetBitmap(wxBitmap(from_u8(__WXMSW__ ? var("action_undo.png") : var("arrow_undo.png")), wxBITMAP_TYPE_PNG)); - auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); - m_Undo_btn->SetBackgroundColour(color); - m_Undo_btn->Hide(); - BUILD(); - } + virtual void PostInitialize(); /// Finish constructing the Field's wxWidget-related properties, including setting its own sizer, etc. virtual void BUILD() = 0; @@ -51,6 +44,8 @@ protected: void on_kill_focus(wxEvent& event); /// Call the attached on_change method. void on_change_field(); + /// Call the attached m_back_to_initial_value method. + void on_back_to_initial_value(); public: /// parent wx item, opportunity to refactor (probably not necessary - data duplication) @@ -62,6 +57,9 @@ public: /// Function object to store callback passed in from owning object. t_change m_on_change {nullptr}; + /// Function object to store callback passed in from owning object. + t_back_to_init m_back_to_initial_value{ nullptr }; + // This is used to avoid recursive invocation of the field change/update by wxWidgets. bool m_disable_change_event {false}; diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index 138496b2e..d19d9b548 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -75,7 +75,11 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co field->m_parent = parent(); //! Label to change background color, when option is modified - field->m_Label = label; + field->m_Label = label; + field->m_back_to_initial_value = [this](std::string opt_id){ + if (!this->m_disabled) + this->back_to_initial_value(opt_id); + }; // assign function objects for callbacks, etc. return field; @@ -270,6 +274,16 @@ void ConfigOptionsGroup::on_change_OG(t_config_option_key opt_id, boost::any val OptionsGroup::on_change_OG(opt_id, value); //!? Why doing this } +void ConfigOptionsGroup::back_to_initial_value(const std::string opt_key) +{ + if (m_get_initial_config == nullptr) + return; + DynamicPrintConfig config = m_get_initial_config(); + boost::any value = get_config_value(config, opt_key); + set_value(opt_key, value); + on_change_OG(opt_key, get_value(opt_key)/*value*/); +} + void ConfigOptionsGroup::reload_config(){ for (std::map< std::string, std::pair >::iterator it = m_opt_map.begin(); it != m_opt_map.end(); ++it) { auto opt_id = it->first; diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp index 6819a1174..56755595b 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.hpp +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -19,6 +19,12 @@ #define wxOSX false #endif +#ifdef __WXMSW__ +#define wxMSW true +#else +#define wxMSW false +#endif + #define BORDER(a, b) ((wxOSX ? a : b)) namespace Slic3r { namespace GUI { @@ -78,6 +84,7 @@ public: wxSizer* sizer {nullptr}; column_t extra_column {nullptr}; t_change m_on_change {nullptr}; + std::function m_get_initial_config{ nullptr }; wxFont sidetext_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; wxFont label_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; @@ -145,6 +152,7 @@ protected: virtual void on_kill_focus (){}; virtual void on_change_OG(t_config_option_key opt_id, boost::any value); + virtual void back_to_initial_value(const std::string opt_key){}; }; class ConfigOptionsGroup: public OptionsGroup { @@ -172,10 +180,8 @@ public: } void on_change_OG(t_config_option_key opt_id, boost::any value) override; - void on_kill_focus() override - { - reload_config(); - } + void back_to_initial_value(const std::string opt_key) override; + void on_kill_focus() override{ reload_config();} void reload_config(); boost::any config_value(std::string opt_key, int opt_index, bool deserialize); // return option value from config diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index aa30a655c..1995d409a 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -148,8 +148,8 @@ void Tab::update_dirty(){ for (auto opt_key : dirty_options){ Field* field = get_field(opt_key/*, opt_index*/); if (field != nullptr && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()){ - field->m_Label->SetForegroundColour(*get_modified_label_clr()); - field->m_Undo_btn->Show(); + field->m_Label->SetForegroundColour(*get_modified_label_clr()); + field->m_Undo_btn->SetBitmap(wxBitmap(from_u8(wxMSW ? var("action_undo.png") : var("arrow_undo.png")), wxBITMAP_TYPE_PNG)); m_dirty_options.push_back(opt_key); } @@ -157,13 +157,13 @@ void Tab::update_dirty(){ // Delete undirty options from m_dirty_options size_t cnt = m_dirty_options.size(); - for (auto i = 0; i < /*cnt*/m_dirty_options.size(); ++i) + for (auto i = 0; i < m_dirty_options.size(); ++i) { const std::string &opt_key = m_dirty_options[i]; Field* field = get_field(opt_key/*, opt_index*/); if (field != nullptr && find(dirty_options.begin(), dirty_options.end(), opt_key) == dirty_options.end()) { - field->m_Undo_btn->Hide(); + field->m_Undo_btn->SetBitmap(wxBitmap(from_u8(var("Bullet_white.png")), wxBITMAP_TYPE_PNG)); field->m_Label->SetForegroundColour(wxSYS_COLOUR_WINDOWTEXT); std::vector::iterator itr = find(m_dirty_options.begin(), m_dirty_options.end(), opt_key); if (itr != m_dirty_options.end()){ @@ -1774,6 +1774,11 @@ ConfigOptionsGroupShp Page::new_optgroup(wxString title, int noncommon_label_wid //! }); }; + optgroup->m_get_initial_config = [this](){ + DynamicPrintConfig config = static_cast(GetParent())->m_presets->get_selected_preset().config; + return config; + }; + vsizer()->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 10); m_optgroups.push_back(optgroup);