From e4b767e8403c1c860c36598e822b02d6c2bbfc2d Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 6 Apr 2018 13:37:00 +0200 Subject: [PATCH 01/15] Experiment with own ComboCtrl for preset_choice. --- xs/src/slic3r/GUI/Field.cpp | 3 +- xs/src/slic3r/GUI/Tab.cpp | 47 ++++++++++++++++++++++++++++++ xs/src/slic3r/GUI/Tab.hpp | 2 ++ xs/src/slic3r/GUI/wxExtensions.cpp | 44 ++++++++++++++++++++++++++++ xs/src/slic3r/GUI/wxExtensions.hpp | 24 +++++++++++++++ 5 files changed, 118 insertions(+), 2 deletions(-) diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index fee08e27e..a7fd8d29e 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -173,8 +173,7 @@ namespace Slic3r { namespace GUI { temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e) { -// on_kill_focus(e); - e.Skip(); + e.Skip();// on_kill_focus(e); temp->GetToolTip()->Enable(true); }), temp->GetId()); diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index babff7d80..3935dda5a 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -20,6 +20,7 @@ #include #include +#include "wxExtensions.hpp" namespace Slic3r { namespace GUI { @@ -38,6 +39,50 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) // preset chooser m_presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1), 0, 0,wxCB_READONLY); + m_cc_presets_choice = new wxComboCtrl(panel, wxID_ANY, L("Presets"), wxDefaultPosition, wxSize(270, -1), wxCB_READONLY); + wxDataViewTreeCtrlComboPopup* popup = new wxDataViewTreeCtrlComboPopup; + if (popup != nullptr) + { + // FIXME If the following line is removed, the combo box popup list will not react to mouse clicks. + // On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10. +// comboCtrl->UseAltPopupWindow(); +// comboCtrl->EnablePopupAnimation(false); + m_cc_presets_choice->SetPopupControl(popup); + popup->SetStringValue(from_u8("Text1")); + + popup->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this, popup](wxCommandEvent& evt) + { + auto selected = popup->GetItemText(popup->GetSelection()); + if (selected != _(L("System presets")) && selected != _(L("Default presets"))) + m_cc_presets_choice->SetText(selected); +// popup->OnDataViewTreeCtrlSelection(evt); + }); + popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); + popup->Bind(wxEVT_KEY_UP, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); + + auto icons = new wxImageList(16, 16, true, 1); + popup->SetImageList(icons); + icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-red-icon.png")), wxBITMAP_TYPE_PNG)); + icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-green-icon.png")), wxBITMAP_TYPE_PNG)); + + Freeze(); + + // get label of the currently selected item + auto selected = popup->GetItemText(popup->GetSelection()); + auto root_sys = popup->AppendContainer(wxDataViewItem(0), _(L("System presets"))); + auto tree_node1 = popup->AppendItem(root_sys, _("Sys1"), 0); + auto tree_node2 = popup->AppendContainer(root_sys, _("Sys2"), 0); + auto tree_node2_1 = popup->AppendItem(tree_node2, _("Sys2_1"), 0); + + auto root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); + auto tree_node01 = popup->AppendContainer(root_def, _("Def1"), 0); + auto tree_node02 = popup->AppendContainer(root_def, _("Def2"), 0); + auto tree_node02_1 = popup->AppendItem(tree_node02, _("Def2_1"), 0); + + Thaw(); + } + + auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); //buttons @@ -82,6 +127,8 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) m_hsizer->AddSpacer(64); m_hsizer->Add(m_undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL); + m_hsizer->AddSpacer(64); + m_hsizer->Add(m_cc_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3); //Horizontal sizer to hold the tree and the selected page. m_hsizer = new wxBoxSizer(wxHORIZONTAL); diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index f39ff728c..075eab218 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,7 @@ protected: wxButton* m_compatible_printers_btn; wxButton* m_undo_btn; wxButton* m_undo_to_sys_btn; + wxComboCtrl* m_cc_presets_choice; int m_icon_count; std::map m_icon_index; // Map from an icon file name to its index diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index 1ebd7979e..c4dfb7e10 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -109,3 +109,47 @@ void wxCheckListBoxComboPopup::OnListBoxSelection(wxCommandEvent& evt) ProcessEvent(event); } } + + +// *** wxDataViewTreeCtrlComboPopup *** + +const unsigned int wxDataViewTreeCtrlComboPopup::DefaultWidth = 270; +const unsigned int wxDataViewTreeCtrlComboPopup::DefaultHeight = 200; +const unsigned int wxDataViewTreeCtrlComboPopup::DefaultItemHeight = 22; + +bool wxDataViewTreeCtrlComboPopup::Create(wxWindow* parent) +{ + return wxDataViewTreeCtrl::Create(parent, wxID_HIGHEST + 1, wxPoint(0, 0), wxSize(270, -1)); +} + +wxSize wxDataViewTreeCtrlComboPopup::GetAdjustedSize(int minWidth, int prefHeight, int maxHeight) +{ + // matches owner wxComboCtrl's width + // and sets height dinamically in dependence of contained items count + return wxSize(DefaultWidth, DefaultHeight); +} + +void wxDataViewTreeCtrlComboPopup::OnKeyEvent(wxKeyEvent& evt) +{ + // filters out all the keys which are not working properly + if (evt.GetKeyCode() == WXK_UP) + { + return; + } + else if (evt.GetKeyCode() == WXK_DOWN) + { + return; + } + else + { + evt.Skip(); + return; + } +} + +void wxDataViewTreeCtrlComboPopup::OnDataViewTreeCtrlSelection(wxCommandEvent& evt) +{ + wxComboCtrl* cmb = GetComboCtrl(); + auto selected = GetItemText(GetSelection()); + cmb->SetText(selected); +} diff --git a/xs/src/slic3r/GUI/wxExtensions.hpp b/xs/src/slic3r/GUI/wxExtensions.hpp index e61c17bbc..bba412cfd 100644 --- a/xs/src/slic3r/GUI/wxExtensions.hpp +++ b/xs/src/slic3r/GUI/wxExtensions.hpp @@ -3,6 +3,7 @@ #include #include +#include class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup { @@ -25,4 +26,27 @@ public: void OnListBoxSelection(wxCommandEvent& evt); }; + +// *** wxDataViewTreeCtrlComboBox *** + +class wxDataViewTreeCtrlComboPopup: public wxDataViewTreeCtrl, public wxComboPopup +{ + static const unsigned int DefaultWidth; + static const unsigned int DefaultHeight; + static const unsigned int DefaultItemHeight; + + wxString m_text; + int m_cnt_open_items=2; + +public: + virtual bool Create(wxWindow* parent); + virtual wxWindow* GetControl() { return this; } + virtual void SetStringValue(const wxString& value) { m_text = value; } + virtual wxString GetStringValue() const { return m_text; } + virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight); + + virtual void OnKeyEvent(wxKeyEvent& evt); + void OnDataViewTreeCtrlSelection(wxCommandEvent& evt); +}; + #endif // slic3r_GUI_wxExtensions_hpp_ From 004f9ba1e5457203057b8cb2dad04c089bd64acf Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 6 Apr 2018 15:42:52 +0200 Subject: [PATCH 02/15] Added update_tab_presets functions to m_cc_preset_choise filling --- xs/src/slic3r/GUI/Preset.cpp | 4 ++ xs/src/slic3r/GUI/Preset.hpp | 6 +++ xs/src/slic3r/GUI/Tab.cpp | 65 ++++++++++++++++++++++-------- xs/src/slic3r/GUI/Tab.hpp | 1 + xs/src/slic3r/GUI/wxExtensions.cpp | 14 ++++++- xs/src/slic3r/GUI/wxExtensions.hpp | 3 +- 6 files changed, 74 insertions(+), 19 deletions(-) diff --git a/xs/src/slic3r/GUI/Preset.cpp b/xs/src/slic3r/GUI/Preset.cpp index c437f8b41..d612896a5 100644 --- a/xs/src/slic3r/GUI/Preset.cpp +++ b/xs/src/slic3r/GUI/Preset.cpp @@ -417,6 +417,10 @@ const Preset* PresetCollection::get_selected_preset_parent() const return (preset == nullptr || preset->is_default || preset->is_external) ? nullptr : preset; } +const std::string& PresetCollection::get_suffix_modified() { + return g_suffix_modified; +} + // Return a preset by its name. If the preset is active, a temporary copy is returned. // If a preset is not found by its name, null is returned. Preset* PresetCollection::find_preset(const std::string &name, bool first_visible_if_not_found) diff --git a/xs/src/slic3r/GUI/Preset.hpp b/xs/src/slic3r/GUI/Preset.hpp index 3634c5dd9..f19f511c3 100644 --- a/xs/src/slic3r/GUI/Preset.hpp +++ b/xs/src/slic3r/GUI/Preset.hpp @@ -212,6 +212,12 @@ public: // Return the selected preset including the user modifications. Preset& get_edited_preset() { return m_edited_preset; } const Preset& get_edited_preset() const { return m_edited_preset; } + + // used to update preset_choice from Tab + const std::deque& get_presets() { return m_presets; } + int get_idx_selected() { return m_idx_selected; } + const std::string& get_suffix_modified(); + // Return a preset possibly with modifications. const Preset& default_preset() const { return m_presets.front(); } // Return a preset by an index. If the preset is active, a temporary copy is returned. diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 3935dda5a..37ed8f97f 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -54,32 +54,21 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) { auto selected = popup->GetItemText(popup->GetSelection()); if (selected != _(L("System presets")) && selected != _(L("Default presets"))) + { m_cc_presets_choice->SetText(selected); + std::string selected_string = selected.ToUTF8().data(); +//! select_preset(selected_string); + } // popup->OnDataViewTreeCtrlSelection(evt); }); + popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); popup->Bind(wxEVT_KEY_UP, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); auto icons = new wxImageList(16, 16, true, 1); popup->SetImageList(icons); - icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-red-icon.png")), wxBITMAP_TYPE_PNG)); icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-green-icon.png")), wxBITMAP_TYPE_PNG)); - - Freeze(); - - // get label of the currently selected item - auto selected = popup->GetItemText(popup->GetSelection()); - auto root_sys = popup->AppendContainer(wxDataViewItem(0), _(L("System presets"))); - auto tree_node1 = popup->AppendItem(root_sys, _("Sys1"), 0); - auto tree_node2 = popup->AppendContainer(root_sys, _("Sys2"), 0); - auto tree_node2_1 = popup->AppendItem(tree_node2, _("Sys2_1"), 0); - - auto root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); - auto tree_node01 = popup->AppendContainer(root_def, _("Def1"), 0); - auto tree_node02 = popup->AppendContainer(root_def, _("Def2"), 0); - auto tree_node02_1 = popup->AppendItem(tree_node02, _("Def2_1"), 0); - - Thaw(); + icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-red-icon.png")), wxBITMAP_TYPE_PNG)); } @@ -525,11 +514,13 @@ void Tab::update_dirty(){ m_presets->update_dirty_ui(m_presets_choice); on_presets_changed(); update_changed_ui(); +// update_dirty_presets(m_cc_presets_choice); } void Tab::update_tab_ui() { m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets); + update_tab_presets(m_cc_presets_choice, m_show_incompatible_presets); } // Load a provied DynamicConfig into the tab, modifying the active preset. @@ -2141,6 +2132,46 @@ wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox return sizer; } +void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) +{ + if (ui == nullptr) + return; + ui->Freeze(); + ui->Clear(); + auto presets = m_presets->get_presets(); + auto idx_selected = m_presets->get_idx_selected(); + auto suffix_modified = m_presets->get_suffix_modified(); + int icon_compatible = 0; + int icon_incompatible = 1; + int cnt_items = 0; + + wxDataViewTreeCtrlComboPopup* popup = wxDynamicCast(m_cc_presets_choice->GetPopupControl(), wxDataViewTreeCtrlComboPopup); + if (popup != nullptr) + { + popup->DeleteAllItems(); + auto root_sys = popup->AppendContainer(wxDataViewItem(0), _(L("System presets"))); + auto root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); + + for (size_t i = presets.front().is_visible ? 0 : 1; i < presets.size(); ++i) { + const Preset &preset = presets[i]; + if (!preset.is_visible || (!show_incompatible && !preset.is_compatible && i != idx_selected)) + continue; + + auto preset_name = wxString::FromUTF8((preset.name + (preset.is_dirty ? suffix_modified : "")).c_str()); + + auto item = popup->AppendItem(preset.is_system ? root_sys : root_def, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + cnt_items++; + if (i == idx_selected){ + popup->Select(item); + m_cc_presets_choice->SetText(preset_name); + } + } + } + popup->SetItemsCnt(cnt_items); + ui->Thaw(); +} + void Page::reload_config() { for (auto group : m_optgroups) diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index 075eab218..5e2eec80d 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -196,6 +196,7 @@ public: protected: void on_presets_changed(); void update_frequently_changed_parameters(); + void update_tab_presets(wxComboCtrl* ui, bool show_incompatible); }; //Slic3r::GUI::Tab::Print; diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index c4dfb7e10..d9f4e520a 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -126,7 +126,19 @@ wxSize wxDataViewTreeCtrlComboPopup::GetAdjustedSize(int minWidth, int prefHeigh { // matches owner wxComboCtrl's width // and sets height dinamically in dependence of contained items count - return wxSize(DefaultWidth, DefaultHeight); + wxComboCtrl* cmb = GetComboCtrl(); + if (cmb != nullptr) + { + wxSize size = GetComboCtrl()->GetSize(); + if (m_cnt_open_items > 0) + size.SetHeight(m_cnt_open_items * DefaultItemHeight); + else + size.SetHeight(DefaultHeight); + + return size; + } + else + return wxSize(DefaultWidth, DefaultHeight); } void wxDataViewTreeCtrlComboPopup::OnKeyEvent(wxKeyEvent& evt) diff --git a/xs/src/slic3r/GUI/wxExtensions.hpp b/xs/src/slic3r/GUI/wxExtensions.hpp index bba412cfd..701b12dba 100644 --- a/xs/src/slic3r/GUI/wxExtensions.hpp +++ b/xs/src/slic3r/GUI/wxExtensions.hpp @@ -36,7 +36,7 @@ class wxDataViewTreeCtrlComboPopup: public wxDataViewTreeCtrl, public wxComboPop static const unsigned int DefaultItemHeight; wxString m_text; - int m_cnt_open_items=2; + int m_cnt_open_items{0}; public: virtual bool Create(wxWindow* parent); @@ -47,6 +47,7 @@ public: virtual void OnKeyEvent(wxKeyEvent& evt); void OnDataViewTreeCtrlSelection(wxCommandEvent& evt); + void SetItemsCnt(int cnt) { m_cnt_open_items = cnt; } }; #endif // slic3r_GUI_wxExtensions_hpp_ From e33db203d8b1819cc452e173c39003c33cef5f75 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 9 Apr 2018 09:55:24 +0200 Subject: [PATCH 03/15] Next try to use wxDataViewTreeCtrlComboPopup on macOS and Linux: Added: m_cc_presets_choice->UseAltPopupWindow(); m_cc_presets_choice->EnablePopupAnimation(false); like for wxCheckListBoxComboPopup --- xs/src/slic3r/GUI/Tab.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 37ed8f97f..ee8d1261c 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -45,8 +45,9 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) { // FIXME If the following line is removed, the combo box popup list will not react to mouse clicks. // On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10. -// comboCtrl->UseAltPopupWindow(); -// comboCtrl->EnablePopupAnimation(false); + m_cc_presets_choice->UseAltPopupWindow(); + + m_cc_presets_choice->EnablePopupAnimation(false); m_cc_presets_choice->SetPopupControl(popup); popup->SetStringValue(from_u8("Text1")); @@ -57,7 +58,7 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) { m_cc_presets_choice->SetText(selected); std::string selected_string = selected.ToUTF8().data(); -//! select_preset(selected_string); + select_preset(selected_string); } // popup->OnDataViewTreeCtrlSelection(evt); }); @@ -2159,8 +2160,14 @@ void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) auto preset_name = wxString::FromUTF8((preset.name + (preset.is_dirty ? suffix_modified : "")).c_str()); - auto item = popup->AppendItem(preset.is_system ? root_sys : root_def, preset_name, - preset.is_compatible ? icon_compatible : icon_incompatible); + wxDataViewItem item; + if (preset.is_system || preset.is_default) + item = popup->AppendItem(preset.is_system ? root_sys : root_def, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + else { + + } + cnt_items++; if (i == idx_selected){ popup->Select(item); @@ -2168,7 +2175,7 @@ void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) } } } - popup->SetItemsCnt(cnt_items); + popup->SetItemsCnt(cnt_items+2); ui->Thaw(); } From affaeef2ab18972374d571260cba9c34d578eee7 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 9 Apr 2018 12:41:25 +0200 Subject: [PATCH 04/15] Default presets are visible only if it's selected from Preferences --- xs/src/slic3r/GUI/Tab.cpp | 19 +++++++++++++------ xs/src/slic3r/GUI/wxExtensions.cpp | 4 ++-- xs/src/slic3r/GUI/wxExtensions.hpp | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index ee8d1261c..5f727830f 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -45,9 +45,9 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) { // FIXME If the following line is removed, the combo box popup list will not react to mouse clicks. // On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10. - m_cc_presets_choice->UseAltPopupWindow(); +// m_cc_presets_choice->UseAltPopupWindow(); - m_cc_presets_choice->EnablePopupAnimation(false); +// m_cc_presets_choice->EnablePopupAnimation(false); m_cc_presets_choice->SetPopupControl(popup); popup->SetStringValue(from_u8("Text1")); @@ -2150,8 +2150,11 @@ void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) if (popup != nullptr) { popup->DeleteAllItems(); + auto root_1 = popup->AppendContainer(wxDataViewItem(0), _(L("Root 1"))); auto root_sys = popup->AppendContainer(wxDataViewItem(0), _(L("System presets"))); - auto root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); + auto show_def = get_app_config()->get("no_defaults")[0] != '1'; + wxDataViewItem root_def; + if (show_def) root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); for (size_t i = presets.front().is_visible ? 0 : 1; i < presets.size(); ++i) { const Preset &preset = presets[i]; @@ -2161,11 +2164,15 @@ void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) auto preset_name = wxString::FromUTF8((preset.name + (preset.is_dirty ? suffix_modified : "")).c_str()); wxDataViewItem item; - if (preset.is_system || preset.is_default) - item = popup->AppendItem(preset.is_system ? root_sys : root_def, preset_name, + if (preset.is_system) + item = popup->AppendItem(root_sys, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + else if (show_def && preset.is_default) + item = popup->AppendItem(root_def, preset_name, preset.is_compatible ? icon_compatible : icon_incompatible); else { - + item = popup->AppendItem(root_1, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); } cnt_items++; diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index d9f4e520a..666da7f8a 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -121,7 +121,7 @@ bool wxDataViewTreeCtrlComboPopup::Create(wxWindow* parent) { return wxDataViewTreeCtrl::Create(parent, wxID_HIGHEST + 1, wxPoint(0, 0), wxSize(270, -1)); } - +/* wxSize wxDataViewTreeCtrlComboPopup::GetAdjustedSize(int minWidth, int prefHeight, int maxHeight) { // matches owner wxComboCtrl's width @@ -140,7 +140,7 @@ wxSize wxDataViewTreeCtrlComboPopup::GetAdjustedSize(int minWidth, int prefHeigh else return wxSize(DefaultWidth, DefaultHeight); } - +*/ void wxDataViewTreeCtrlComboPopup::OnKeyEvent(wxKeyEvent& evt) { // filters out all the keys which are not working properly diff --git a/xs/src/slic3r/GUI/wxExtensions.hpp b/xs/src/slic3r/GUI/wxExtensions.hpp index 701b12dba..ed8bb9276 100644 --- a/xs/src/slic3r/GUI/wxExtensions.hpp +++ b/xs/src/slic3r/GUI/wxExtensions.hpp @@ -43,7 +43,7 @@ public: virtual wxWindow* GetControl() { return this; } virtual void SetStringValue(const wxString& value) { m_text = value; } virtual wxString GetStringValue() const { return m_text; } - virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight); +// virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight); virtual void OnKeyEvent(wxKeyEvent& evt); void OnDataViewTreeCtrlSelection(wxCommandEvent& evt); From 674ddcd73a86b93f393ff50856a5111c81438123 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 9 Apr 2018 16:50:17 +0200 Subject: [PATCH 05/15] Show preset_tree according to preset inheritance --- xs/src/slic3r/GUI/Preset.cpp | 10 +++++ xs/src/slic3r/GUI/Preset.hpp | 4 +- xs/src/slic3r/GUI/Tab.cpp | 64 ++++++++++++++++++++++++------ xs/src/slic3r/GUI/wxExtensions.cpp | 2 +- 4 files changed, 65 insertions(+), 15 deletions(-) diff --git a/xs/src/slic3r/GUI/Preset.cpp b/xs/src/slic3r/GUI/Preset.cpp index d612896a5..845f11c96 100644 --- a/xs/src/slic3r/GUI/Preset.cpp +++ b/xs/src/slic3r/GUI/Preset.cpp @@ -417,6 +417,16 @@ const Preset* PresetCollection::get_selected_preset_parent() const return (preset == nullptr || preset->is_default || preset->is_external) ? nullptr : preset; } +const Preset* PresetCollection::get_preset_parent(const Preset& child) const +{ + auto *inherits = dynamic_cast(child.config.option("inherits")); + if (inherits == nullptr || inherits->value.empty()) +// return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr; + return nullptr; + const Preset* preset = this->find_preset(inherits->value, false); + return (preset == nullptr/* || preset->is_default */|| preset->is_external) ? nullptr : preset; +} + const std::string& PresetCollection::get_suffix_modified() { return g_suffix_modified; } diff --git a/xs/src/slic3r/GUI/Preset.hpp b/xs/src/slic3r/GUI/Preset.hpp index f19f511c3..c038160f4 100644 --- a/xs/src/slic3r/GUI/Preset.hpp +++ b/xs/src/slic3r/GUI/Preset.hpp @@ -209,7 +209,9 @@ public: // The parent preset may be a system preset or a user preset, which will be // reflected by the UI. const Preset* get_selected_preset_parent() const; - // Return the selected preset including the user modifications. + // get parent preset for some child preset + const Preset* get_preset_parent(const Preset& child) const; + // Return the selected preset including the user modifications. Preset& get_edited_preset() { return m_edited_preset; } const Preset& get_edited_preset() const { return m_edited_preset; } diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 5f727830f..fa414563c 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -39,7 +39,7 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) // preset chooser m_presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1), 0, 0,wxCB_READONLY); - m_cc_presets_choice = new wxComboCtrl(panel, wxID_ANY, L("Presets"), wxDefaultPosition, wxSize(270, -1), wxCB_READONLY); + m_cc_presets_choice = new wxComboCtrl(panel, wxID_ANY, L(""), wxDefaultPosition, wxDefaultSize/*wxSize(270, -1)*/, wxCB_READONLY); wxDataViewTreeCtrlComboPopup* popup = new wxDataViewTreeCtrlComboPopup; if (popup != nullptr) { @@ -63,8 +63,8 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) // popup->OnDataViewTreeCtrlSelection(evt); }); - popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); - popup->Bind(wxEVT_KEY_UP, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); +// popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); +// popup->Bind(wxEVT_KEY_UP, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); auto icons = new wxImageList(16, 16, true, 1); popup->SetImageList(icons); @@ -307,7 +307,7 @@ void Tab::update_changed_ui() is_nonsys_value = true; sys_icon = m_nonsys_btn_icon; if(find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) == m_dirty_options.end()) - color = wxSYS_COLOUR_WINDOWTEXT; + color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); else color = *get_modified_label_clr(); } @@ -380,7 +380,7 @@ void Tab::update_sys_ui_after_sel_preset() field->m_Undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(m_nonsys_btn_icon)), wxBITMAP_TYPE_PNG)); field->m_is_nonsys_value = true; if (field->m_Label != nullptr){ - field->m_Label->SetForegroundColour(wxSYS_COLOUR_WINDOWTEXT); + field->m_Label->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); field->m_Label->Refresh(true); } } @@ -427,7 +427,7 @@ void Tab::update_changed_tree_ui() else if (modified_page) m_treectrl->SetItemTextColour(cur_item, *get_modified_label_clr()); else - m_treectrl->SetItemTextColour(cur_item, wxSYS_COLOUR_WINDOWTEXT); + m_treectrl->SetItemTextColour(cur_item, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); page->m_is_nonsys_values = !sys_page; page->m_is_modified_values = modified_page; @@ -2150,11 +2150,16 @@ void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) if (popup != nullptr) { popup->DeleteAllItems(); - auto root_1 = popup->AppendContainer(wxDataViewItem(0), _(L("Root 1"))); + + auto root_exp1 = popup->AppendContainer(wxDataViewItem(0), "Exp_root_1"); + auto item1 = popup->AppendItem(root_exp1, "child_1_1"); + auto item2 = popup->AppendItem(root_exp1, "child_1_2"); + auto item3 = popup->AppendItem(item2, "child_2_1"); + auto root_sys = popup->AppendContainer(wxDataViewItem(0), _(L("System presets"))); + auto root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); + auto show_def = get_app_config()->get("no_defaults")[0] != '1'; - wxDataViewItem root_def; - if (show_def) root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); for (size_t i = presets.front().is_visible ? 0 : 1; i < presets.size(); ++i) { const Preset &preset = presets[i]; @@ -2170,9 +2175,41 @@ void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) else if (show_def && preset.is_default) item = popup->AppendItem(root_def, preset_name, preset.is_compatible ? icon_compatible : icon_incompatible); - else { - item = popup->AppendItem(root_1, preset_name, - preset.is_compatible ? icon_compatible : icon_incompatible); + else + { + auto parent = m_presets->get_preset_parent(preset); + if (parent == nullptr) + item = popup->AppendItem(root_def, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + else + { + auto parent_name = parent->name; + + wxDataViewTreeStoreContainerNode *node = popup->GetStore()->FindContainerNode(root_sys); + if (node) + { + wxDataViewTreeStoreNodeList::iterator iter; + for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) + { + wxDataViewTreeStoreNode* child = *iter; + auto child_item = child->GetItem(); + auto item_text = popup->GetItemText(child_item); + if (item_text == parent_name) + { + auto added_child = popup->AppendItem(child->GetItem(), preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + if (!added_child){ + popup->DeleteItem(child->GetItem()); + auto new_parent = popup->AppendContainer(root_sys, parent_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + popup->AppendItem(new_parent, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + } + break; + } + } + } + } } cnt_items++; @@ -2181,8 +2218,9 @@ void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) m_cc_presets_choice->SetText(preset_name); } } + if (popup->GetStore()->GetChildCount(root_def) == 0) + popup->DeleteItem(root_def); } - popup->SetItemsCnt(cnt_items+2); ui->Thaw(); } diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index 666da7f8a..8bc282474 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -119,7 +119,7 @@ const unsigned int wxDataViewTreeCtrlComboPopup::DefaultItemHeight = 22; bool wxDataViewTreeCtrlComboPopup::Create(wxWindow* parent) { - return wxDataViewTreeCtrl::Create(parent, wxID_HIGHEST + 1, wxPoint(0, 0), wxSize(270, -1)); + return wxDataViewTreeCtrl::Create(parent, wxID_ANY/*HIGHEST + 1*/, wxPoint(0, 0), wxDefaultSize/*wxSize(270, -1)*/, wxDV_NO_HEADER); } /* wxSize wxDataViewTreeCtrlComboPopup::GetAdjustedSize(int minWidth, int prefHeight, int maxHeight) From 0cca7bb5e736c89088cc84cebb3702efbc676a1a Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 9 Apr 2018 17:09:00 +0200 Subject: [PATCH 06/15] Dont use select_preset from preset_tree... --- xs/src/slic3r/GUI/Tab.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index fa414563c..a40da002b 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -58,9 +58,8 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) { m_cc_presets_choice->SetText(selected); std::string selected_string = selected.ToUTF8().data(); - select_preset(selected_string); +// select_preset(selected_string); } -// popup->OnDataViewTreeCtrlSelection(evt); }); // popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); @@ -2151,11 +2150,6 @@ void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) { popup->DeleteAllItems(); - auto root_exp1 = popup->AppendContainer(wxDataViewItem(0), "Exp_root_1"); - auto item1 = popup->AppendItem(root_exp1, "child_1_1"); - auto item2 = popup->AppendItem(root_exp1, "child_1_2"); - auto item3 = popup->AppendItem(item2, "child_2_1"); - auto root_sys = popup->AppendContainer(wxDataViewItem(0), _(L("System presets"))); auto root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); From fa4462514bb3b5a9e79e6819d007112169c6e787 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 10 Apr 2018 10:31:58 +0200 Subject: [PATCH 07/15] Added preset grouping to PresetCollection::update_tab_ui --- xs/src/slic3r/GUI/2DBed.hpp | 6 ++++-- xs/src/slic3r/GUI/Preset.cpp | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/xs/src/slic3r/GUI/2DBed.hpp b/xs/src/slic3r/GUI/2DBed.hpp index 859417efb..a170b708a 100644 --- a/xs/src/slic3r/GUI/2DBed.hpp +++ b/xs/src/slic3r/GUI/2DBed.hpp @@ -6,7 +6,7 @@ namespace GUI { class Bed_2D : public wxPanel { - bool m_user_drawn_background = false; + bool m_user_drawn_background = true; bool m_painted = false; bool m_interactive = false; @@ -26,7 +26,9 @@ public: { Create(parent, wxID_ANY, wxDefaultPosition, wxSize(250, -1), wxTAB_TRAVERSAL); // m_user_drawn_background = $^O ne 'darwin'; - m_user_drawn_background = true; +#ifdef __APPLE__ + m_user_drawn_background = false; +#endif /*__APPLE__*/ Bind(wxEVT_PAINT, ([this](wxPaintEvent e) { repaint(); })); // EVT_ERASE_BACKGROUND($self, sub{}) if $self->{user_drawn_background}; // Bind(EVT_MOUSE_EVENTS, ([this](wxMouseEvent event){/*mouse_event()*/; })); diff --git a/xs/src/slic3r/GUI/Preset.cpp b/xs/src/slic3r/GUI/Preset.cpp index 845f11c96..bc34e193a 100644 --- a/xs/src/slic3r/GUI/Preset.cpp +++ b/xs/src/slic3r/GUI/Preset.cpp @@ -531,16 +531,44 @@ void PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompatibl return; ui->Freeze(); ui->Clear(); + std::map nonsys_presets; + wxString selected = ""; for (size_t i = this->m_presets.front().is_visible ? 0 : 1; i < this->m_presets.size(); ++ i) { const Preset &preset = this->m_presets[i]; if (! preset.is_visible || (! show_incompatible && ! preset.is_compatible && i != m_idx_selected)) continue; const wxBitmap *bmp = preset.is_compatible ? m_bitmap_compatible : m_bitmap_incompatible; - ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), - (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); - if (i == m_idx_selected) - ui->SetSelection(ui->GetCount() - 1); +// ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), +// (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); +// if (i == m_idx_selected) +// ui->SetSelection(ui->GetCount() - 1); + + if (preset.is_default || preset.is_system){ + ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), + (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); + if (i == m_idx_selected) + ui->SetSelection(ui->GetCount() - 1); + } + else + { + nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), preset.is_compatible); + if (i == m_idx_selected) + selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()); + } + if (preset.is_default) + ui->Append("______________________", wxNullBitmap); } + if (!nonsys_presets.empty()) + { + ui->Append("______________________", wxNullBitmap); + for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { + const wxBitmap *bmp = it->second ? m_bitmap_compatible : m_bitmap_incompatible; + ui->Append(it->first, + (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); + if (it->first == selected) + ui->SetSelection(ui->GetCount() - 1); + } + } ui->Thaw(); } From c1d25ba25926ef6aeb46edc6984926f1ff68fae2 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 10 Apr 2018 14:00:48 +0200 Subject: [PATCH 08/15] Experiments with wxDataViewTreeCtrl --- xs/src/slic3r/GUI/Tab.cpp | 108 ++++++++++++++++++++++++++++++++++++++ xs/src/slic3r/GUI/Tab.hpp | 3 ++ 2 files changed, 111 insertions(+) diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index a40da002b..c074a1e58 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -123,6 +123,32 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) m_hsizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(m_hsizer, 1, wxEXPAND, 0); + + + //temporary left vertical sizer + m_left_sizer = new wxBoxSizer(wxVERTICAL); + m_hsizer->Add(m_left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3); + + // tree + m_presetctrl = new wxDataViewTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(200, -1), wxDV_NO_HEADER); + m_left_sizer->Add(m_presetctrl, 1, wxEXPAND); + m_preset_icons = new wxImageList(16, 16, true, 1); + m_presetctrl->SetImageList(m_preset_icons); + m_preset_icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-green-icon.png")), wxBITMAP_TYPE_PNG)); + m_preset_icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-red-icon.png")), wxBITMAP_TYPE_PNG)); + + m_presetctrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxCommandEvent& evt) + { + auto selected = m_presetctrl->GetItemText(m_presetctrl->GetSelection()); + if (selected != _(L("System presets")) && selected != _(L("Default presets"))) + { + std::string selected_string = selected.ToUTF8().data(); + select_preset(selected_string); + } + }); + + + //left vertical sizer m_left_sizer = new wxBoxSizer(wxVERTICAL); m_hsizer->Add(m_left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3); @@ -521,6 +547,7 @@ void Tab::update_tab_ui() { m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets); update_tab_presets(m_cc_presets_choice, m_show_incompatible_presets); + update_presetsctrl(m_presetctrl, m_show_incompatible_presets); } // Load a provied DynamicConfig into the tab, modifying the active preset. @@ -2132,6 +2159,87 @@ wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox return sizer; } +void Tab::update_presetsctrl(wxDataViewTreeCtrl* ui, bool show_incompatible) +{ + if (ui == nullptr) + return; + ui->Freeze(); + ui->DeleteAllItems(); + auto presets = m_presets->get_presets(); + auto idx_selected = m_presets->get_idx_selected(); + auto suffix_modified = m_presets->get_suffix_modified(); + int icon_compatible = 0; + int icon_incompatible = 1; + int cnt_items = 0; + + auto root_sys = ui->AppendContainer(wxDataViewItem(0), _(L("System presets"))); + auto root_def = ui->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); + + auto show_def = get_app_config()->get("no_defaults")[0] != '1'; + + for (size_t i = presets.front().is_visible ? 0 : 1; i < presets.size(); ++i) { + const Preset &preset = presets[i]; + if (!preset.is_visible || (!show_incompatible && !preset.is_compatible && i != idx_selected)) + continue; + + auto preset_name = wxString::FromUTF8((preset.name + (preset.is_dirty ? suffix_modified : "")).c_str()); + + wxDataViewItem item; + if (preset.is_system) + item = ui->AppendItem(root_sys, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + else if (show_def && preset.is_default) + item = ui->AppendItem(root_def, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + else + { + auto parent = m_presets->get_preset_parent(preset); + if (parent == nullptr) + item = ui->AppendItem(root_def, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + else + { + auto parent_name = parent->name; + + wxDataViewTreeStoreContainerNode *node = ui->GetStore()->FindContainerNode(root_sys); + if (node) + { + wxDataViewTreeStoreNodeList::iterator iter; + for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) + { + wxDataViewTreeStoreNode* child = *iter; + auto child_item = child->GetItem(); + auto item_text = ui->GetItemText(child_item); + if (item_text == parent_name) + { + auto added_child = ui->AppendItem(child->GetItem(), preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + if (!added_child){ + ui->DeleteItem(child->GetItem()); + auto new_parent = ui->AppendContainer(root_sys, parent_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + ui->AppendItem(new_parent, preset_name, + preset.is_compatible ? icon_compatible : icon_incompatible); + } + break; + } + } + } + } + } + + cnt_items++; + if (i == idx_selected){ + ui->Select(item); + m_cc_presets_choice->SetText(preset_name); + } + } + if (ui->GetStore()->GetChildCount(root_def) == 0) + ui->DeleteItem(root_def); + + ui->Thaw(); +} + void Tab::update_tab_presets(wxComboCtrl* ui, bool show_incompatible) { if (ui == nullptr) diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index 5e2eec80d..8a2c38e05 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -97,6 +97,8 @@ protected: wxButton* m_undo_btn; wxButton* m_undo_to_sys_btn; wxComboCtrl* m_cc_presets_choice; + wxDataViewTreeCtrl* m_presetctrl; + wxImageList* m_preset_icons; int m_icon_count; std::map m_icon_index; // Map from an icon file name to its index @@ -149,6 +151,7 @@ public: bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, std::string new_printer_name = ""); wxSizer* compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn); + void update_presetsctrl(wxDataViewTreeCtrl* ui, bool show_incompatible); void load_key_value(std::string opt_key, boost::any value); void reload_compatible_printers_widget(); From e7520c3d18709337e5340dff6a2d0f995cbdc27c Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 10 Apr 2018 14:52:03 +0200 Subject: [PATCH 09/15] Don't use select_preset on OS X --- xs/src/slic3r/GUI/Tab.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index c074a1e58..1b70dfa5c 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -58,7 +58,10 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) { m_cc_presets_choice->SetText(selected); std::string selected_string = selected.ToUTF8().data(); -// select_preset(selected_string); +#ifdef __APPLE__ +#else + select_preset(selected_string); +#endif } }); @@ -143,7 +146,10 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) if (selected != _(L("System presets")) && selected != _(L("Default presets"))) { std::string selected_string = selected.ToUTF8().data(); +#ifdef __APPLE__ +#else select_preset(selected_string); +#endif } }); From 762306d98536522bed52d493c92684cdea7be2ea Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 11 Apr 2018 13:56:37 +0200 Subject: [PATCH 10/15] Added preset grouping to all presets ComboBoxes Changed icons for action_undo, sys_lock and sys_unlock. There are used same icons for all OS now. Deleted/Commented temporarily used wxDataViewTreeCtrl --- resources/icons/action_undo.png | Bin 616 -> 491 bytes resources/icons/sys_lock.png | Bin 448 -> 510 bytes resources/icons/sys_unlock.png | Bin 454 -> 419 bytes xs/src/slic3r/GUI/BitmapCache.hpp | 5 +++- xs/src/slic3r/GUI/Preset.cpp | 42 ++++++++++++++++++++++++----- xs/src/slic3r/GUI/PresetBundle.cpp | 34 ++++++++++++++++++++--- xs/src/slic3r/GUI/Tab.cpp | 33 ++++++++++++----------- 7 files changed, 87 insertions(+), 27 deletions(-) diff --git a/resources/icons/action_undo.png b/resources/icons/action_undo.png index 866ae9773bf144069986bf74e5524fe7b387ff48..877f159868640a0399143631438313a31dacf1a1 100644 GIT binary patch delta 429 zcmV;e0aE_x1nUEkNPiB)000id0mpBsWB>pGfJsC_R5(wykxNSgQ545V%^63>_gk}< zP(iE4M^Mt2kto`yMY*Xq(ym%bkF_lfw55$L>|?08G8A_%g@5;6hEPTeiGFZ6bB25V z=f(XiNjV1fb9Oe?)@kzW0w1lG;HHs`CM+;%oc=vezeoEIz4z|G=8mCVKs?tti+~F@_!Maw3s5J#gC{6K{WeeZvay zIs^LszIKFWqX7e%nJr3|$3&irMOaAnus?v^?VX7Q7{{3m%)Ed|FvR@oN)#TlIG4@N z{)t8&gTY|B0Ocy5C->H|QRvob+jMp+Mq2+ld6dWd2PWktn^i8)FO>Ised=QW2*-T^ X&Lg-nvC@Jh00000NkvXXu0mjfw4BNi delta 555 zcmV+`0@VHM1Ly>hNPiM^000tn0p4aGcmMza{YgYYR5(v{Q_oKmQ4pTpZM(a)6xy=1 zpa=*76HgY@geDgFBQ!?iRm0uNLA?`hz=@cMM?7G{j~fR64N0iwiS@KAib*XMxm-F02E z9b0U*fjrL>9vEHSy?@U2p(j{-`wr>U2vS4CVlz0_dw;3e+1iGeNGe_|)M_>H1&&a> zxPaoeOH?+CX0s`N#`pbwL~RFm(iuEk%88Hn`2}>5^+Evy5gQX@pGlSxEDR5(wKl08VnP!xsz0UbmT5k$eE zgXrMqrr6C@aB+3FlauHof*`mFD!6vYP$*5)rcK(WO;SW06-5wdad1!vrD~1eGf!#L zR&wBy_TGEWJ@3BP)d{Mq4i<~WwMwPp+O~b?IL>9MR5~^cV}F`*x8KzPiA16g@-C!T z$Pb8|^S$AJjo+uHX+~sgd(bc|iPxD-W+9bI4KaB_I6&l`?>6X>?X938=DO}DE;c>S z`?HJK48r#a+v12a-3kQu5UAl~S*CuVY1#GY^fHzSwJ^=Gr$6)f-Tx;~#w zCdYmQQiS?OK7XIzQWRyJ_U2_m8n!I!P)ra@`!CAnvLyycs*ggUu!QxuYPITx3682r zst?Y*iaYxG*KvM>_$Q=CG3}H?k8H2_=Bd10Gf{wJ2}kxv>`3!7cYc ziO>5KgGKK6CD_<5#Bp$SBB?&& q@%RASUT2~%>~#t;S&&s#o%#mod=~CNPr6V50000qL!1Y*~qEaA95?rrWn5LOWUNoCcoKB~FR8s;4j>jWx z+s-2|_WQk*I2a6M{2}1`z9cmo4M{BPGp^p#>9iZfTc6W-&xu6pBszgL^6U_z(U!E82@6X617ehT#aed!N}L)k@{uL3M*wOUD^=JE*3 zd=*e0kn(9L3IbJ0tyT+*#R730i*fHTzYw8e{9#zTYJ``H$!sc4Ln;1ok)kM)i^T2M f!6}^VI1c^*)N{#pGI7vi7R5(wilf6pBKoEfQPa;7{tRlXFjo5pYh4=*4cD{iK7FLShT_K!z=QonTo?dXlfsZ7! zGv7`&#HgyuD$CMV$@AO|f?&yUoORo_H$Bf=$+FD1FuDeRn6TBeW55uq%MbQGUvO(@# znk8BV_2?tGOp;`-$qO=_`Yiks(0B?HM8|4j8?yu_@PXh^Eo|dkFeA+Rsu#@!?7GA5 zukfZpH%-%E>RlBO?6DvRI8l)AzXhL4PPo<)49P9al-%zsd2PWM2DPB4B$xE=di^BJPU8GEvCF1unmK?l z#sFi}G-=&54YX|wp6AgT&mND5%tH_3IL@jeS(c%qW>FN;8Gjeh@-+b@j$?Vrb=^4# z0=ae^hjOs$9|8iAoagznGt>Egzn_bukZWO@K$0YM`E)wbT0IkpJz)mFAgSw`d>Dr0 z1-xWwuV@1I`#`?yI`Y_!zf8cW48x$doX=;tTrS}IK5RA{{JbUY8*HO(+pt=#o)w`0 zlBTJA!2fKw+kep=?G1Q~$m4L(fN-!f-b#wq{q=fH9?{<5m9i}1dc9K2e~>&Pgpjua z{Ij5{DvH%hs@PkB m_map; diff --git a/xs/src/slic3r/GUI/Preset.cpp b/xs/src/slic3r/GUI/Preset.cpp index bc34e193a..0afbcf8cd 100644 --- a/xs/src/slic3r/GUI/Preset.cpp +++ b/xs/src/slic3r/GUI/Preset.cpp @@ -512,16 +512,44 @@ void PresetCollection::update_platter_ui(wxBitmapComboBox *ui) // Otherwise fill in the list from scratch. ui->Freeze(); ui->Clear(); + std::map nonsys_presets; + wxString selected = ""; for (size_t i = this->m_presets.front().is_visible ? 0 : 1; i < this->m_presets.size(); ++ i) { const Preset &preset = this->m_presets[i]; if (! preset.is_visible || (! preset.is_compatible && i != m_idx_selected)) continue; const wxBitmap *bmp = (i == 0 || preset.is_compatible) ? m_bitmap_main_frame : m_bitmap_incompatible; - ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), - (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); - if (i == m_idx_selected) - ui->SetSelection(ui->GetCount() - 1); - } +// ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), +// (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); +// if (i == m_idx_selected) +// ui->SetSelection(ui->GetCount() - 1); + + if (preset.is_default || preset.is_system){ + ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), + (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); + if (i == m_idx_selected) + ui->SetSelection(ui->GetCount() - 1); + } + else + { + nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), preset.is_compatible); + if (i == m_idx_selected) + selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()); + } + if (preset.is_default) + ui->Append("------------------------------------", wxNullBitmap); + } + if (!nonsys_presets.empty()) + { + ui->Append("------------------------------------", wxNullBitmap); + for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { + const wxBitmap *bmp = it->second ? m_bitmap_compatible : m_bitmap_incompatible; + ui->Append(it->first, + (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); + if (it->first == selected) + ui->SetSelection(ui->GetCount() - 1); + } + } ui->Thaw(); } @@ -556,11 +584,11 @@ void PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompatibl selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()); } if (preset.is_default) - ui->Append("______________________", wxNullBitmap); + ui->Append("------------------------------------", wxNullBitmap); } if (!nonsys_presets.empty()) { - ui->Append("______________________", wxNullBitmap); + ui->Append("------------------------------------", wxNullBitmap); for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { const wxBitmap *bmp = it->second ? m_bitmap_compatible : m_bitmap_incompatible; ui->Append(it->first, diff --git a/xs/src/slic3r/GUI/PresetBundle.cpp b/xs/src/slic3r/GUI/PresetBundle.cpp index 7131bf771..dcf10198d 100644 --- a/xs/src/slic3r/GUI/PresetBundle.cpp +++ b/xs/src/slic3r/GUI/PresetBundle.cpp @@ -986,6 +986,8 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, wxBitma // and draw a red flag in front of the selected preset. bool wide_icons = selected_preset != nullptr && ! selected_preset->is_compatible && m_bitmapIncompatible != nullptr; assert(selected_preset != nullptr); + std::map nonsys_presets; + wxString selected_str = ""; for (int i = this->filaments().front().is_visible ? 0 : 1; i < int(this->filaments().size()); ++ i) { const Preset &preset = this->filaments.preset(i); bool selected = this->filament_presets[idx_extruder] == preset.name; @@ -1023,10 +1025,36 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, wxBitma (preset.is_dirty ? *m_bitmapLockOpen : *m_bitmapLock) : m_bitmapCache->mkclear(16, 16)); bitmap = m_bitmapCache->insert(bitmap_key, bmps); } - ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), (bitmap == 0) ? wxNullBitmap : *bitmap); - if (selected) - ui->SetSelection(ui->GetCount() - 1); +// ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), (bitmap == 0) ? wxNullBitmap : *bitmap); +// if (selected) +// ui->SetSelection(ui->GetCount() - 1); + + if (preset.is_default || preset.is_system){ + ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), + (bitmap == 0) ? wxNullBitmap : *bitmap); + if (selected) + ui->SetSelection(ui->GetCount() - 1); + } + else + { + nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), + (bitmap == 0) ? wxNullBitmap : *bitmap); + if (selected) + selected_str = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); + } + if (preset.is_default) + ui->Append("------------------------------------", wxNullBitmap); } + + if (!nonsys_presets.empty()) + { + ui->Append("------------------------------------", wxNullBitmap); + for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { + ui->Append(it->first, it->second); + if (it->first == selected_str) + ui->SetSelection(ui->GetCount() - 1); + } + } ui->Thaw(); } diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 1b70dfa5c..0b79f8229 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -38,8 +38,8 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) // preset chooser m_presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1), 0, 0,wxCB_READONLY); - - m_cc_presets_choice = new wxComboCtrl(panel, wxID_ANY, L(""), wxDefaultPosition, wxDefaultSize/*wxSize(270, -1)*/, wxCB_READONLY); + /* + m_cc_presets_choice = new wxComboCtrl(panel, wxID_ANY, L(""), wxDefaultPosition, wxDefaultSize, wxCB_READONLY); wxDataViewTreeCtrlComboPopup* popup = new wxDataViewTreeCtrlComboPopup; if (popup != nullptr) { @@ -73,8 +73,7 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-green-icon.png")), wxBITMAP_TYPE_PNG)); icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-red-icon.png")), wxBITMAP_TYPE_PNG)); } - - +*/ auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); //buttons @@ -119,14 +118,16 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) m_hsizer->AddSpacer(64); m_hsizer->Add(m_undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL); - m_hsizer->AddSpacer(64); - m_hsizer->Add(m_cc_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3); +// m_hsizer->AddSpacer(64); +// m_hsizer->Add(m_cc_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3); //Horizontal sizer to hold the tree and the selected page. m_hsizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(m_hsizer, 1, wxEXPAND, 0); +/* + //temporary left vertical sizer m_left_sizer = new wxBoxSizer(wxVERTICAL); @@ -153,7 +154,7 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) } }); - +*/ //left vertical sizer m_left_sizer = new wxBoxSizer(wxVERTICAL); @@ -202,8 +203,8 @@ void Tab::load_initial_data() { m_config = &m_presets->get_edited_preset().config; m_nonsys_btn_icon = m_presets->get_selected_preset_parent() == nullptr ? - "bullet_white.png" : - wxMSW ? "sys_unlock.png" : "lock_open.png"; + "bullet_white.png" : "sys_unlock.png"; +// wxMSW ? "sys_unlock.png" : "lock_open.png"; } PageShp Tab::add_options_page(wxString title, std::string icon, bool is_extruder_pages/* = false*/) @@ -331,8 +332,8 @@ void Tab::update_changed_ui() { bool is_nonsys_value = false; bool is_modified_value = true; - std::string sys_icon = wxMSW ? "sys_lock.png" : "lock.png"; - std::string icon = wxMSW ? "action_undo.png" : "arrow_undo.png"; + std::string sys_icon = /*wxMSW ? */"sys_lock.png"/* : "lock.png"*/; + std::string icon = /*wxMSW ? */"action_undo.png"/* : "arrow_undo.png"*/; wxColour& color = *get_sys_label_clr(); if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) { is_nonsys_value = true; @@ -478,9 +479,9 @@ void Tab::update_changed_tree_ui() void Tab::update_undo_buttons() { const std::string& undo_icon = !m_is_modified_values ? "bullet_white.png" : - wxMSW ? "action_undo.png" : "arrow_undo.png"; + /*wxMSW ? */"action_undo.png"/* : "arrow_undo.png"*/; const std::string& undo_to_sys_icon = m_is_nonsys_values ? m_nonsys_btn_icon : - wxMSW ? "sys_lock.png" : "lock.png"; + /*wxMSW ? */"sys_lock.png"/* : "lock.png"*/; m_undo_btn->SetBitmap(wxBitmap(from_u8(var(undo_icon)), wxBITMAP_TYPE_PNG)); m_undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(undo_to_sys_icon)), wxBITMAP_TYPE_PNG)); @@ -552,8 +553,8 @@ void Tab::update_dirty(){ void Tab::update_tab_ui() { m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets); - update_tab_presets(m_cc_presets_choice, m_show_incompatible_presets); - update_presetsctrl(m_presetctrl, m_show_incompatible_presets); +// update_tab_presets(m_cc_presets_choice, m_show_incompatible_presets); +// update_presetsctrl(m_presetctrl, m_show_incompatible_presets); } // Load a provied DynamicConfig into the tab, modifying the active preset. @@ -1786,7 +1787,7 @@ void Tab::load_current_preset() const Preset* parent = m_presets->get_selected_preset_parent(); m_nonsys_btn_icon = parent == nullptr ? "bullet_white.png" : - wxMSW ? "sys_unlock.png" : "lock_open.png"; + /*wxMSW ? */"sys_unlock.png"/* : "lock_open.png"*/; // use CallAfter because some field triggers schedule on_change calls using CallAfter, // and we don't want them to be called after this update_dirty() as they would mark the From 723bd22b96ac23b1af3ee1438cc41f0dd86a70f9 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 11 Apr 2018 15:35:04 +0200 Subject: [PATCH 11/15] Changed icons for lock/unlock filament_presets on Plater tab Experiment with filament_presets transparency on GTK --- xs/src/slic3r/GUI/BitmapCache.cpp | 5 ++++- xs/src/slic3r/GUI/PresetBundle.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/xs/src/slic3r/GUI/BitmapCache.cpp b/xs/src/slic3r/GUI/BitmapCache.cpp index f92369650..e29687ce5 100644 --- a/xs/src/slic3r/GUI/BitmapCache.cpp +++ b/xs/src/slic3r/GUI/BitmapCache.cpp @@ -88,7 +88,10 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, std::vectorLoadFile( wxString::FromUTF8(Slic3r::var(path_bitmap_compatible).c_str()), wxBITMAP_TYPE_PNG); bool loaded_incompatible = m_bitmapIncompatible->LoadFile( From d82505984a3f63bcf66a472c54c520495421a8c3 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 12 Apr 2018 16:46:17 +0200 Subject: [PATCH 12/15] Rollback changes in BitmapCache --- xs/src/slic3r/GUI/BitmapCache.cpp | 3 --- xs/src/slic3r/GUI/BitmapCache.hpp | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/xs/src/slic3r/GUI/BitmapCache.cpp b/xs/src/slic3r/GUI/BitmapCache.cpp index e29687ce5..acbcb5c73 100644 --- a/xs/src/slic3r/GUI/BitmapCache.cpp +++ b/xs/src/slic3r/GUI/BitmapCache.cpp @@ -88,10 +88,7 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, std::vector m_map; From 120c1978ae9c389393ad3332c2077d5ba255353a Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 13 Apr 2018 12:35:04 +0200 Subject: [PATCH 13/15] Cleaned code --- xs/src/slic3r/GUI/Field.cpp | 31 +++++------------- xs/src/slic3r/GUI/Field.hpp | 52 +++++++++++++++++------------- xs/src/slic3r/GUI/GUI.cpp | 25 ++++++++------ xs/src/slic3r/GUI/GUI.hpp | 8 ++--- xs/src/slic3r/GUI/OptionsGroup.cpp | 33 +++++++------------ xs/src/slic3r/GUI/OptionsGroup.hpp | 36 ++++++++++----------- xs/src/slic3r/GUI/Tab.cpp | 45 ++++++++++++-------------- xs/src/slic3r/GUI/Tab.hpp | 26 +++++++-------- 8 files changed, 120 insertions(+), 136 deletions(-) diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index a7fd8d29e..c68b2304c 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -75,13 +75,13 @@ namespace Slic3r { namespace GUI { return tooltip_text; } - bool Field::is_matched(std::string string, std::string pattern) + bool Field::is_matched(const std::string& string, const std::string& pattern) { std::regex regex_pattern(pattern, std::regex_constants::icase); // use ::icase to make the matching case insensitive like /i in perl return std::regex_match(string, regex_pattern); } - boost::any Field::get_value_by_opt_type(wxString str) + boost::any Field::get_value_by_opt_type(wxString& str) { boost::any ret_val; switch (m_opt.type){ @@ -377,7 +377,7 @@ void Choice::set_selection() } } -void Choice::set_value(const std::string value, bool change_event) //! Redundant? +void Choice::set_value(const std::string& value, bool change_event) //! Redundant? { m_disable_change_event = !change_event; @@ -396,7 +396,7 @@ void Choice::set_value(const std::string value, bool change_event) //! Redundan m_disable_change_event = false; } -void Choice::set_value(boost::any value, bool change_event) +void Choice::set_value(const boost::any& value, bool change_event) { m_disable_change_event = !change_event; @@ -435,7 +435,7 @@ void Choice::set_value(boost::any value, bool change_event) } //! it's needed for _update_serial_ports() -void Choice::set_values(const std::vector values) +void Choice::set_values(const std::vector& values) { if (values.empty()) return; @@ -554,7 +554,7 @@ void PointCtrl::BUILD() y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y)); } -void PointCtrl::set_value(const Pointf value, bool change_event) +void PointCtrl::set_value(const Pointf& value, bool change_event) { m_disable_change_event = !change_event; @@ -566,10 +566,10 @@ void PointCtrl::set_value(const Pointf value, bool change_event) m_disable_change_event = false; } -void PointCtrl::set_value(boost::any value, bool change_event) +void PointCtrl::set_value(const boost::any& value, bool change_event) { Pointf pt; - Pointf *ptf = boost::any_cast(&value); + const Pointf *ptf = boost::any_cast(&value); if (!ptf) { ConfigOptionPoints* pts = boost::any_cast(value); @@ -577,21 +577,6 @@ void PointCtrl::set_value(boost::any value, bool change_event) } else pt = *ptf; -// try -// { -// pt = boost::any_cast(value)->values.at(0); -// } -// catch (const std::exception &e) -// { -// try{ -// pt = boost::any_cast(value); -// } -// catch (const std::exception &e) -// { -// std::cerr << "Error! Can't cast PointCtrl value" << m_opt_id << "\n"; -// return; -// } -// } set_value(pt, change_event); } diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index da3e23ccd..cdc7c0d81 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -31,8 +31,8 @@ namespace Slic3r { namespace GUI { 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; +using t_change = std::function; +using t_back_to_init = std::function; wxString double_to_string(double const value); @@ -81,7 +81,7 @@ public: /// Sets a value for this control. /// subclasses should overload with a specific version /// Postcondition: Method does not fire the on_change event. - virtual void set_value(boost::any value, bool change_event) = 0; + virtual void set_value(const boost::any& value, bool change_event) = 0; /// Gets a boost::any representing this control. /// subclasses should overload with a specific version @@ -100,7 +100,7 @@ public: virtual wxString get_tooltip_text(const wxString& default_string); // set icon to "UndoToSystemValue" button according to an inheritance of preset - void set_nonsys_btn_icon(const std::string& icon); + void set_nonsys_btn_icon(const std::string& icon); Field(const ConfigOptionDef& opt, const t_config_option_key& id) : m_opt(opt), m_opt_id(id) {}; Field(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : m_parent(parent), m_opt(opt), m_opt_id(id) {}; @@ -109,8 +109,8 @@ public: virtual wxSizer* getSizer() { return nullptr; } virtual wxWindow* getWindow() { return nullptr; } - bool is_matched(std::string string, std::string pattern); - boost::any get_value_by_opt_type(wxString str); + bool is_matched(const std::string& string, const std::string& pattern); + boost::any get_value_by_opt_type(wxString& str); /// Factory method for generating new derived classes. template @@ -137,16 +137,17 @@ class TextCtrl : public Field { public: TextCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} TextCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + ~TextCtrl() {} void BUILD(); wxWindow* window {nullptr}; - virtual void set_value(std::string value, bool change_event = false) { + virtual void set_value(const std::string& value, bool change_event = false) { m_disable_change_event = !change_event; dynamic_cast(window)->SetValue(wxString(value)); m_disable_change_event = false; } - virtual void set_value(boost::any value, bool change_event = false) { + virtual void set_value(const boost::any& value, bool change_event = false) { m_disable_change_event = !change_event; dynamic_cast(window)->SetValue(boost::any_cast(value)); m_disable_change_event = false; @@ -164,6 +165,7 @@ class CheckBox : public Field { public: CheckBox(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} CheckBox(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + ~CheckBox() {} wxWindow* window{ nullptr }; void BUILD() override; @@ -173,7 +175,7 @@ public: dynamic_cast(window)->SetValue(value); m_disable_change_event = false; } - void set_value(boost::any value, bool change_event = false) { + void set_value(const boost::any& value, bool change_event = false) { m_disable_change_event = !change_event; dynamic_cast(window)->SetValue(boost::any_cast(value)); m_disable_change_event = false; @@ -190,21 +192,22 @@ class SpinCtrl : public Field { public: SpinCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id), tmp_value(-9999) {} SpinCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id), tmp_value(-9999) {} + ~SpinCtrl() {} int tmp_value; wxWindow* window{ nullptr }; void BUILD() override; - void set_value(const std::string value, bool change_event = false) { + void set_value(const std::string& value, bool change_event = false) { m_disable_change_event = !change_event; dynamic_cast(window)->SetValue(value); m_disable_change_event = false; } - void set_value(boost::any value, bool change_event = false) { + void set_value(const boost::any& value, bool change_event = false) { m_disable_change_event = !change_event; tmp_value = boost::any_cast(value); - dynamic_cast(window)->SetValue(tmp_value/*boost::any_cast(value)*/); + dynamic_cast(window)->SetValue(tmp_value); m_disable_change_event = false; } boost::any get_value() override { @@ -221,14 +224,15 @@ class Choice : public Field { public: Choice(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} Choice(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + ~Choice() {} wxWindow* window{ nullptr }; void BUILD() override; void set_selection(); - void set_value(const std::string value, bool change_event = false); - void set_value(boost::any value, bool change_event = false); - void set_values(const std::vector values); + void set_value(const std::string& value, bool change_event = false); + void set_value(const boost::any& value, bool change_event = false); + void set_values(const std::vector &values); boost::any get_value() override; void enable() override { dynamic_cast(window)->Enable(); }; @@ -241,16 +245,17 @@ class ColourPicker : public Field { public: ColourPicker(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} ColourPicker(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + ~ColourPicker() {} wxWindow* window{ nullptr }; void BUILD() override; - void set_value(const std::string value, bool change_event = false) { + void set_value(const std::string& value, bool change_event = false) { m_disable_change_event = !change_event; dynamic_cast(window)->SetColour(value); m_disable_change_event = false; } - void set_value(boost::any value, bool change_event = false) { + void set_value(const boost::any& value, bool change_event = false) { m_disable_change_event = !change_event; dynamic_cast(window)->SetColour(boost::any_cast(value)); m_disable_change_event = false; @@ -268,23 +273,24 @@ class PointCtrl : public Field { public: PointCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} PointCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} + ~PointCtrl() {} wxSizer* sizer{ nullptr }; - wxTextCtrl* x_textctrl; - wxTextCtrl* y_textctrl; + wxTextCtrl* x_textctrl{ nullptr }; + wxTextCtrl* y_textctrl{ nullptr }; void BUILD() override; - void set_value(const Pointf value, bool change_event = false); - void set_value(boost::any value, bool change_event = false); + void set_value(const Pointf& value, bool change_event = false); + void set_value(const boost::any& value, bool change_event = false); boost::any get_value() override; void enable() override { x_textctrl->Enable(); - y_textctrl->Enable(); }; + y_textctrl->Enable(); } void disable() override{ x_textctrl->Disable(); - y_textctrl->Disable(); }; + y_textctrl->Disable(); } wxSizer* getSizer() override { return sizer; } }; diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 9450f44ae..794e873d5 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -403,7 +403,7 @@ TabIface* get_preset_tab_iface(char *name) } // opt_index = 0, by the reason of zero-index in ConfigOptionVector by default (in case only one element) -void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, boost::any value, int opt_index /*= 0*/) +void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/) { try{ switch (config.def()->get(opt_key)->type){ @@ -439,11 +439,18 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast(value))); break; case coStrings:{ - if (opt_key.compare("compatible_printers") == 0 || - config.def()->get(opt_key)->gui_flags.compare("serialized") == 0){ - config.option(opt_key)->values.resize(0); - std::vector values = boost::any_cast>(value); - if (values.size() == 1 && values[0] == "") + if (opt_key.compare("compatible_printers") == 0) { + config.option(opt_key)->values = + boost::any_cast>(value); + } + else if (config.def()->get(opt_key)->gui_flags.compare("serialized") == 0){ + std::string str = boost::any_cast(value); + if (str.back() == ';') str.pop_back(); + // Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values. + // Currently used for the post_process config value only. + std::vector values; + boost::split(values, str, boost::is_any_of(";")); + if (values.size() == 1 && values[0] == "") break; config.option(opt_key)->values = values; } @@ -510,17 +517,17 @@ void add_created_tab(Tab* panel) g_wxTabPanel->AddPage(panel, panel->title()); } -void show_error(wxWindow* parent, wxString message){ +void show_error(wxWindow* parent, const wxString& message){ auto msg_wingow = new wxMessageDialog(parent, message, _(L("Error")), wxOK | wxICON_ERROR); msg_wingow->ShowModal(); } -void show_info(wxWindow* parent, wxString message, wxString title){ +void show_info(wxWindow* parent, const wxString& message, const wxString& title){ auto msg_wingow = new wxMessageDialog(parent, message, title.empty() ? _(L("Notice")) : title, wxOK | wxICON_INFORMATION); msg_wingow->ShowModal(); } -void warning_catcher(wxWindow* parent, wxString message){ +void warning_catcher(wxWindow* parent, const wxString& message){ if (message == _(L("GLUquadricObjPtr | Attempt to free unreferenced scalar")) ) return; auto msg = new wxMessageDialog(parent, message, _(L("Warning")), wxOK | wxICON_WARNING); diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index 24c3ec3f4..d92246c50 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -96,11 +96,11 @@ TabIface* get_preset_tab_iface(char *name); // add it at the end of the tab panel. void add_created_tab(Tab* panel); // Change option value in config -void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, boost::any value, int opt_index = 0); +void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0); -void show_error(wxWindow* parent, wxString message); -void show_info(wxWindow* parent, wxString message, wxString title); -void warning_catcher(wxWindow* parent, wxString message); +void show_error(wxWindow* parent, const wxString& message); +void show_info(wxWindow* parent, const wxString& message, const wxString& title); +void warning_catcher(wxWindow* parent, const wxString& message); // load language saved at application config bool load_language(); diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index 24e1ddf2e..8e2268965 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -227,12 +227,12 @@ Line OptionsGroup::create_single_option_line(const Option& option) const { return retval; } -void OptionsGroup::on_change_OG(t_config_option_key id, /*config_value*/boost::any value) { +void OptionsGroup::on_change_OG(const t_config_option_key& opt_id, const boost::any& value) { if (m_on_change != nullptr) - m_on_change(id, value); + m_on_change(opt_id, value); } -Option ConfigOptionsGroup::get_option(const std::string opt_key, int opt_index /*= -1*/) +Option ConfigOptionsGroup::get_option(const std::string& opt_key, int opt_index /*= -1*/) { if (!m_config->has(opt_key)) { std::cerr << "No " << opt_key << " in ConfigOptionsGroup config."; @@ -245,7 +245,7 @@ Option ConfigOptionsGroup::get_option(const std::string opt_key, int opt_index / return Option(*m_config->def()->get(opt_key), opt_id); } -void ConfigOptionsGroup::on_change_OG(t_config_option_key opt_id, boost::any value) +void ConfigOptionsGroup::on_change_OG(const t_config_option_key& opt_id, const boost::any& value) { if (!m_opt_map.empty()) { @@ -268,16 +268,7 @@ void ConfigOptionsGroup::on_change_OG(t_config_option_key opt_id, boost::any val if (opt_index != -1){ // die "Can't set serialized option indexed value" ; } - // # Split a string to multiple strings by a semi - colon.This is the old way of storing multi - string values. - // # Currently used for the post_process config value only. - // my @values = split / ; / , $field_value; - // $self->config->set($opt_key, \@values); - std::string str = boost::any_cast(value); - if (str.back() == ';') - str.pop_back(); - std::vector values; - boost::split(values, str, boost::is_any_of(";")); - change_opt_value(*m_config, opt_key, values); + change_opt_value(*m_config, opt_key, value); } else { if (opt_index == -1) { @@ -297,14 +288,14 @@ 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) +void ConfigOptionsGroup::back_to_initial_value(const std::string& opt_key) { if (m_get_initial_config == nullptr) return; back_to_config_value(m_get_initial_config(), opt_key); } -void ConfigOptionsGroup::back_to_sys_value(const std::string opt_key) +void ConfigOptionsGroup::back_to_sys_value(const std::string& opt_key) { if (m_get_sys_config == nullptr) return; @@ -313,7 +304,7 @@ void ConfigOptionsGroup::back_to_sys_value(const std::string opt_key) back_to_config_value(m_get_sys_config(), opt_key); } -void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, const std::string opt_key) +void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, const std::string& opt_key) { boost::any value; if (opt_key == "extruders_count"){ @@ -348,7 +339,7 @@ void ConfigOptionsGroup::reload_config(){ } -boost::any ConfigOptionsGroup::config_value(std::string opt_key, int opt_index, bool deserialize){ +boost::any ConfigOptionsGroup::config_value(const std::string& opt_key, int opt_index, bool deserialize){ if (deserialize) { // Want to edit a vector value(currently only multi - strings) in a single edit box. @@ -365,7 +356,7 @@ boost::any ConfigOptionsGroup::config_value(std::string opt_key, int opt_index, } } -boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config, std::string opt_key, int opt_index /*= -1*/) +boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config, const std::string& opt_key, int opt_index /*= -1*/) { size_t idx = opt_index == -1 ? 0 : opt_index; @@ -457,7 +448,7 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config return ret; } -Field* ConfigOptionsGroup::get_fieldc(t_config_option_key opt_key, int opt_index){ +Field* ConfigOptionsGroup::get_fieldc(const t_config_option_key& opt_key, int opt_index){ Field* field = get_field(opt_key); if (field != nullptr) return field; @@ -471,7 +462,7 @@ Field* ConfigOptionsGroup::get_fieldc(t_config_option_key opt_key, int opt_index return opt_id.empty() ? nullptr : get_field(opt_id); } -void ogStaticText::SetText(wxString value) +void ogStaticText::SetText(const wxString& value) { SetLabel(value); Wrap(400); diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp index e58d9c9a9..b5846f24d 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.hpp +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -98,16 +98,16 @@ public: void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); } // return a non-owning pointer reference - inline Field* get_field(t_config_option_key id) const{ + inline Field* get_field(const t_config_option_key& id) const{ if (m_fields.find(id) == m_fields.end()) return nullptr; return m_fields.at(id).get(); } - bool set_value(t_config_option_key id, boost::any value, bool change_event = false) { + bool set_value(const t_config_option_key& id, const boost::any& value, bool change_event = false) { if (m_fields.find(id) == m_fields.end()) return false; m_fields.at(id)->set_value(value, change_event); return true; } - boost::any get_value(t_config_option_key id) { + boost::any get_value(const t_config_option_key& id) { boost::any out; if (m_fields.find(id) == m_fields.end()) ; else @@ -118,7 +118,7 @@ public: inline void enable() { for (auto& field : m_fields) field.second->enable(); } inline void disable() { for (auto& field : m_fields) field.second->disable(); } - OptionsGroup(wxWindow* _parent, wxString title, bool is_tab_opt=false) : + OptionsGroup(wxWindow* _parent, const wxString& title, bool is_tab_opt=false) : m_parent(_parent), title(title), m_is_tab_opt(is_tab_opt), staticbox(title!="") { sizer = (staticbox ? new wxStaticBoxSizer(new wxStaticBox(_parent, wxID_ANY, title), wxVERTICAL) : new wxBoxSizer(wxVERTICAL)); auto num_columns = 1U; @@ -152,14 +152,14 @@ protected: const t_field& build_field(const Option& opt, wxStaticText* label = nullptr); 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){}; - virtual void back_to_sys_value(const std::string opt_key){}; + virtual void on_change_OG(const t_config_option_key& opt_id, const boost::any& value); + virtual void back_to_initial_value(const std::string& opt_key){} + virtual void back_to_sys_value(const std::string& opt_key){} }; class ConfigOptionsGroup: public OptionsGroup { public: - ConfigOptionsGroup(wxWindow* parent, wxString title, DynamicPrintConfig* _config = nullptr, bool is_tab_opt = false) : + ConfigOptionsGroup(wxWindow* parent, const wxString& title, DynamicPrintConfig* _config = nullptr, bool is_tab_opt = false) : OptionsGroup(parent, title, is_tab_opt), m_config(_config) {} /// reference to libslic3r config, non-owning pointer (?). @@ -167,8 +167,8 @@ public: bool m_full_labels {0}; t_opt_map m_opt_map; - Option get_option(const std::string opt_key, int opt_index = -1); - Line create_single_option_line(const std::string title, int idx = -1) /*const*/{ + Option get_option(const std::string& opt_key, int opt_index = -1); + Line create_single_option_line(const std::string& title, int idx = -1) /*const*/{ Option option = get_option(title, idx); return OptionsGroup::create_single_option_line(option); } @@ -181,16 +181,16 @@ public: append_single_option_line(option); } - void on_change_OG(t_config_option_key opt_id, boost::any value) override; - void back_to_initial_value(const std::string opt_key) override; - void back_to_sys_value(const std::string opt_key) override; - void back_to_config_value(const DynamicPrintConfig& config, const std::string opt_key); + void on_change_OG(const t_config_option_key& opt_id, const boost::any& value) override; + void back_to_initial_value(const std::string& opt_key) override; + void back_to_sys_value(const std::string& opt_key) override; + void back_to_config_value(const DynamicPrintConfig& config, const std::string& opt_key); void on_kill_focus() override{ reload_config();} void reload_config(); - boost::any config_value(std::string opt_key, int opt_index, bool deserialize); + boost::any config_value(const std::string& opt_key, int opt_index, bool deserialize); // return option value from config - boost::any get_config_value(const DynamicPrintConfig& config, std::string opt_key, int opt_index = -1); - Field* get_fieldc(t_config_option_key opt_key, int opt_index); + boost::any get_config_value(const DynamicPrintConfig& config, const std::string& opt_key, int opt_index = -1); + Field* get_fieldc(const t_config_option_key& opt_key, int opt_index); }; // Static text shown among the options. @@ -200,7 +200,7 @@ public: ogStaticText(wxWindow* parent, const char *text) : wxStaticText(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize){} ~ogStaticText(){} - void SetText(wxString value); + void SetText(const wxString& value); }; }} diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index ebcd4af88..a9faf4c59 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -203,11 +203,10 @@ void Tab::load_initial_data() { m_config = &m_presets->get_edited_preset().config; m_nonsys_btn_icon = m_presets->get_selected_preset_parent() == nullptr ? - "bullet_white.png" : "sys_unlock.png"; -// wxMSW ? "sys_unlock.png" : "lock_open.png"; + "bullet_white.png" : "sys_unlock.png"; } -PageShp Tab::add_options_page(wxString title, std::string icon, bool is_extruder_pages/* = false*/) +PageShp Tab::add_options_page(const wxString& title, const std::string& icon, bool is_extruder_pages/* = false*/) { // Index of icon in an icon list $self->{icons}. auto icon_idx = 0; @@ -332,8 +331,8 @@ void Tab::update_changed_ui() { bool is_nonsys_value = false; bool is_modified_value = true; - std::string sys_icon = /*wxMSW ? */"sys_lock.png"/* : "lock.png"*/; - std::string icon = /*wxMSW ? */"action_undo.png"/* : "arrow_undo.png"*/; + std::string sys_icon = "sys_lock.png"; + std::string icon = "action_undo.png"; wxColour color = get_sys_label_clr(); if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) { is_nonsys_value = true; @@ -478,10 +477,8 @@ void Tab::update_changed_tree_ui() void Tab::update_undo_buttons() { - const std::string& undo_icon = !m_is_modified_values ? "bullet_white.png" : - /*wxMSW ? */"action_undo.png"/* : "arrow_undo.png"*/; - const std::string& undo_to_sys_icon = m_is_nonsys_values ? m_nonsys_btn_icon : - /*wxMSW ? */"sys_lock.png"/* : "lock.png"*/; + const std::string& undo_icon = !m_is_modified_values ? "bullet_white.png" : "action_undo.png"; + const std::string& undo_to_sys_icon = m_is_nonsys_values ? m_nonsys_btn_icon : "sys_lock.png"; m_undo_btn->SetBitmap(wxBitmap(from_u8(var(undo_icon)), wxBITMAP_TYPE_PNG)); m_undo_to_sys_btn->SetBitmap(wxBitmap(from_u8(var(undo_to_sys_icon)), wxBITMAP_TYPE_PNG)); @@ -559,7 +556,7 @@ void Tab::update_tab_ui() // Load a provied DynamicConfig into the tab, modifying the active preset. // This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view. -void Tab::load_config(DynamicPrintConfig config) +void Tab::load_config(const DynamicPrintConfig& config) { bool modified = 0; for(auto opt_key : m_config->diff(config)) { @@ -582,7 +579,7 @@ void Tab::reload_config(){ Thaw(); } -Field* Tab::get_field(t_config_option_key opt_key, int opt_index/* = -1*/) const +Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const { Field* field = nullptr; for (auto page : m_pages){ @@ -596,7 +593,7 @@ Field* Tab::get_field(t_config_option_key opt_key, int opt_index/* = -1*/) const // Set a key/value pair on this page. Return true if the value has been modified. // Currently used for distributing extruders_count over preset pages of Slic3r::GUI::Tab::Printer // after a preset is loaded. -bool Tab::set_value(t_config_option_key opt_key, boost::any value){ +bool Tab::set_value(const t_config_option_key& opt_key, const boost::any& value){ bool changed = false; for(auto page: m_pages) { if (page->set_value(opt_key, value)) @@ -607,7 +604,7 @@ bool Tab::set_value(t_config_option_key opt_key, boost::any value){ // To be called by custom widgets, load a value into a config, // update the preset selection boxes (the dirty flags) -void Tab::load_key_value(std::string opt_key, boost::any value) +void Tab::load_key_value(const std::string& opt_key, const boost::any& value) { change_opt_value(*m_config, opt_key, value); // Mark the print & filament enabled if they are compatible with the currently selected preset. @@ -621,7 +618,7 @@ void Tab::load_key_value(std::string opt_key, boost::any value) extern wxFrame *g_wxMainFrame; -void Tab::on_value_change(std::string opt_key, boost::any value) +void Tab::on_value_change(const std::string& opt_key, const boost::any& value) { if (m_event_value_change > 0) { wxCommandEvent event(m_event_value_change); @@ -636,8 +633,8 @@ void Tab::on_value_change(std::string opt_key, boost::any value) } if (opt_key == "fill_density") { - value = get_optgroup()->get_config_value(*m_config, opt_key); - get_optgroup()->set_value(opt_key, value); + boost::any val = get_optgroup()->get_config_value(*m_config, opt_key); + get_optgroup()->set_value(opt_key, val); } if (opt_key == "support_material" || opt_key == "support_material_buildplate_only") { @@ -1785,9 +1782,7 @@ void Tab::load_current_preset() // Reload preset pages with the new configuration values. reload_config(); const Preset* parent = m_presets->get_selected_preset_parent(); - m_nonsys_btn_icon = parent == nullptr ? - "bullet_white.png" : - /*wxMSW ? */"sys_unlock.png"/* : "lock_open.png"*/; + m_nonsys_btn_icon = parent == nullptr ? "bullet_white.png" : "sys_unlock.png"; // use CallAfter because some field triggers schedule on_change calls using CallAfter, // and we don't want them to be called after this update_dirty() as they would mark the @@ -1844,7 +1839,7 @@ void Tab::rebuild_page_tree() // Called by the UI combo box when the user switches profiles. // Select a preset by a name.If !defined(name), then the default preset is selected. // If the current profile is modified, user is asked to save the changes. -void Tab::select_preset(std::string preset_name /*= ""*/) +void Tab::select_preset(const std::string& preset_name /*= ""*/) { std::string name = preset_name; auto force = false; @@ -1911,7 +1906,7 @@ void Tab::select_preset(std::string preset_name /*= ""*/) // If the current preset is dirty, the user is asked whether the changes may be discarded. // if the current preset was not dirty, or the user agreed to discard the changes, 1 is returned. -bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr*/, std::string new_printer_name /*= ""*/) +bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr*/, const std::string& new_printer_name /*= ""*/) { if (presets == nullptr) presets = m_presets; // Display a dialog showing the dirty options in a human readable form. @@ -2339,7 +2334,7 @@ void Page::reload_config() group->reload_config(); } -Field* Page::get_field(t_config_option_key opt_key, int opt_index/* = -1*/) const +Field* Page::get_field(const t_config_option_key& opt_key, int opt_index /*= -1*/) const { Field* field = nullptr; for (auto opt : m_optgroups){ @@ -2350,7 +2345,7 @@ Field* Page::get_field(t_config_option_key opt_key, int opt_index/* = -1*/) cons return field; } -bool Page::set_value(t_config_option_key opt_key, boost::any value){ +bool Page::set_value(const t_config_option_key& opt_key, const boost::any& value){ bool changed = false; for(auto optgroup: m_optgroups) { if (optgroup->set_value(opt_key, value)) @@ -2360,7 +2355,7 @@ bool Page::set_value(t_config_option_key opt_key, boost::any value){ } // package Slic3r::GUI::Tab::Page; -ConfigOptionsGroupShp Page::new_optgroup(wxString title, int noncommon_label_width /*= -1*/) +ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_label_width /*= -1*/) { //! config_ have to be "right" ConfigOptionsGroupShp optgroup = std::make_shared(this, title, m_config, true); @@ -2401,7 +2396,7 @@ ConfigOptionsGroupShp Page::new_optgroup(wxString title, int noncommon_label_wid return optgroup; } -void SavePresetWindow::build(wxString title, std::string default_name, std::vector &values) +void SavePresetWindow::build(const wxString& title, const std::string& default_name, std::vector &values) { auto text = new wxStaticText(this, wxID_ANY, _(L("Save ")) + title + _(L(" as:")), wxDefaultPosition, wxDefaultSize); diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index 8a2c38e05..9465f86b4 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -68,9 +68,9 @@ public: size_t iconID() const { return m_iconID; } void set_config(DynamicPrintConfig* config_in) { m_config = config_in; } void reload_config(); - Field* get_field(t_config_option_key opt_key, int opt_index = -1) const; - bool set_value(t_config_option_key opt_key, boost::any value); - ConfigOptionsGroupShp new_optgroup(wxString title, int noncommon_label_width = -1); + Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const; + bool set_value(const t_config_option_key& opt_key, const boost::any& value); + ConfigOptionsGroupShp new_optgroup(const wxString& title, int noncommon_label_width = -1); }; // Slic3r::GUI::Tab; @@ -129,7 +129,7 @@ public: public: Tab() {} - Tab(wxNotebook* parent, wxString title, const char* name, bool no_controller) : + Tab(wxNotebook* parent, const wxString& title, const char* name, bool no_controller) : m_parent(parent), m_title(title), m_name(name), m_no_controller(no_controller) { Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL); get_tabs_list().push_back(this); @@ -147,12 +147,12 @@ public: void create_preset_tab(PresetBundle *preset_bundle); void load_current_preset(); void rebuild_page_tree(); - void select_preset(std::string preset_name = ""); - bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, std::string new_printer_name = ""); + void select_preset(const std::string& preset_name = ""); + bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, const std::string& new_printer_name = ""); wxSizer* compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn); void update_presetsctrl(wxDataViewTreeCtrl* ui, bool show_incompatible); - void load_key_value(std::string opt_key, boost::any value); + void load_key_value(const std::string& opt_key, const boost::any& value); void reload_compatible_printers_widget(); void OnTreeSelChange(wxTreeEvent& event); @@ -172,7 +172,7 @@ public: void on_back_to_initial_value(); void on_back_to_sys_value(); - PageShp add_options_page(wxString title, std::string icon, bool is_extruder_pages = false); + PageShp add_options_page(const wxString& title, const std::string& icon, bool is_extruder_pages = false); virtual void OnActivate(){} virtual void on_preset_loaded(){} @@ -181,10 +181,10 @@ public: void load_initial_data(); void update_dirty(); void update_tab_ui(); - void load_config(DynamicPrintConfig config); + void load_config(const DynamicPrintConfig& config); virtual void reload_config(); - Field* get_field(t_config_option_key opt_key, int opt_index = -1) const; - bool set_value(t_config_option_key opt_key, boost::any value); + Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const; + bool set_value(const t_config_option_key& opt_key, const boost::any& value); wxSizer* description_line_widget(wxWindow* parent, ogStaticText** StaticText); bool current_preset_is_dirty(); DynamicPrintConfig* get_config() { return m_config; } @@ -194,7 +194,7 @@ public: } std::vector get_dependent_tabs() { return m_reload_dependent_tabs; } - void on_value_change(std::string opt_key, boost::any value); + void on_value_change(const std::string& opt_key, const boost::any& value); protected: void on_presets_changed(); @@ -270,7 +270,7 @@ public: std::string m_chosen_name; wxComboBox* m_combo; - void build(wxString title, std::string default_name, std::vector &values); + void build(const wxString& title, const std::string& default_name, std::vector &values); void accept(); std::string get_name() { return m_chosen_name; } }; From 64976c249d854572b9227e3283f35172e9d1a4a0 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 13 Apr 2018 12:49:12 +0200 Subject: [PATCH 14/15] Added @bubnikv's changes to BitmapCache --- xs/src/slic3r/GUI/BitmapCache.cpp | 186 +++++++++++++++++++----------- xs/src/slic3r/GUI/BitmapCache.hpp | 3 +- 2 files changed, 121 insertions(+), 68 deletions(-) diff --git a/xs/src/slic3r/GUI/BitmapCache.cpp b/xs/src/slic3r/GUI/BitmapCache.cpp index acbcb5c73..93853458e 100644 --- a/xs/src/slic3r/GUI/BitmapCache.cpp +++ b/xs/src/slic3r/GUI/BitmapCache.cpp @@ -1,5 +1,14 @@ #include "BitmapCache.hpp" +#if ! defined(WIN32) && ! defined(__APPLE__) +#define BROKEN_ALPHA +#endif + +#ifdef BROKEN_ALPHA + #include + #include +#endif /* BROKEN_ALPHA */ + namespace Slic3r { namespace GUI { void BitmapCache::clear() @@ -8,19 +17,31 @@ void BitmapCache::clear() delete bitmap.second; } +static wxBitmap wxImage_to_wxBitmap_with_alpha(wxImage &&image) +{ +#ifdef BROKEN_ALPHA + wxMemoryOutputStream stream; + image.SaveFile(stream, wxBITMAP_TYPE_PNG); + wxStreamBuffer *buf = stream.GetOutputStreamBuffer(); + return wxBitmap::NewFromPNGData(buf->GetBufferStart(), buf->GetBufferSize()); +#else + return wxBitmap(std::move(image)); +#endif +} + wxBitmap* BitmapCache::insert(const std::string &bitmap_key, size_t width, size_t height) { - wxBitmap *bitmap = nullptr; - auto it = m_map.find(bitmap_key); - if (it == m_map.end()) { - bitmap = new wxBitmap(width, height); - m_map[bitmap_key] = bitmap; - } else { - bitmap = it->second; - if (bitmap->GetWidth() != width || bitmap->GetHeight() != height) - bitmap->Create(width, height); - } -#if defined(__APPLE__) || defined(_MSC_VER) + wxBitmap *bitmap = nullptr; + auto it = m_map.find(bitmap_key); + if (it == m_map.end()) { + bitmap = new wxBitmap(width, height); + m_map[bitmap_key] = bitmap; + } else { + bitmap = it->second; + if (bitmap->GetWidth() != width || bitmap->GetHeight() != height) + bitmap->Create(width, height); + } +#ifndef BROKEN_ALPHA bitmap->UseAlpha(); #endif return bitmap; @@ -28,77 +49,108 @@ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, size_t width, size_ wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap &bmp) { - wxBitmap *bitmap = this->insert(bitmap_key, bmp.GetWidth(), bmp.GetHeight()); - - wxMemoryDC memDC; - memDC.SelectObject(*bitmap); - memDC.SetBackground(*wxTRANSPARENT_BRUSH); - memDC.Clear(); - memDC.DrawBitmap(bmp, 0, 0, true); - memDC.SelectObject(wxNullBitmap); - - return bitmap; + wxBitmap *bitmap = nullptr; + auto it = m_map.find(bitmap_key); + if (it == m_map.end()) { + bitmap = new wxBitmap(bmp); + m_map[bitmap_key] = bitmap; + } else { + bitmap = it->second; + *bitmap = bmp; + } + return bitmap; } wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap &bmp, const wxBitmap &bmp2) { - wxBitmap *bitmap = this->insert(bitmap_key, bmp.GetWidth() + bmp2.GetWidth(), std::max(bmp.GetHeight(), bmp2.GetHeight())); - - wxMemoryDC memDC; - memDC.SelectObject(*bitmap); - memDC.SetBackground(*wxTRANSPARENT_BRUSH); - memDC.Clear(); - if (bmp.GetWidth() > 0) - memDC.DrawBitmap(bmp, 0, 0, true); - if (bmp2.GetWidth() > 0) - memDC.DrawBitmap(bmp2, bmp.GetWidth(), 0, true); - memDC.SelectObject(wxNullBitmap); - - return bitmap; + // Copying the wxBitmaps is cheap as the bitmap's content is reference counted. + const wxBitmap bmps[2] = { bmp, bmp2 }; + return this->insert(bitmap_key, bmps, bmps + 2); } wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap &bmp, const wxBitmap &bmp2, const wxBitmap &bmp3) { - wxBitmap *bitmap = this->insert(bitmap_key, bmp.GetWidth() + bmp2.GetWidth() + bmp3.GetWidth(), std::max(std::max(bmp.GetHeight(), bmp2.GetHeight()), bmp3.GetHeight())); + // Copying the wxBitmaps is cheap as the bitmap's content is reference counted. + const wxBitmap bmps[3] = { bmp, bmp2, bmp3 }; + return this->insert(bitmap_key, bmps, bmps + 3); +} +wxBitmap* BitmapCache::insert(const std::string &bitmap_key, const wxBitmap *begin, const wxBitmap *end) +{ + size_t width = 0; + size_t height = 0; + for (const wxBitmap *bmp = begin; bmp != end; ++ bmp) { + width += bmp->GetWidth(); + height = std::max(height, bmp->GetHeight()); + } + +#ifdef BROKEN_ALPHA + + wxImage image(width, height); + image.InitAlpha(); + // Fill in with a white color. + memset(image.GetData(), 0x0ff, width * height * 3); + // Fill in with full transparency. + memset(image.GetAlpha(), 0, width * height); + size_t x = 0; + for (const wxBitmap *bmp = begin; bmp != end; ++ bmp) { + if (bmp->GetWidth() > 0) { + if (bmp->GetDepth() == 32) { + wxAlphaPixelData data(*const_cast(bmp)); + data.UseAlpha(); + if (data) { + for (int r = 0; r < bmp->GetHeight(); ++ r) { + wxAlphaPixelData::Iterator src(data); + src.Offset(data, 0, r); + unsigned char *dst_pixels = image.GetData() + (x + r * width) * 3; + unsigned char *dst_alpha = image.GetAlpha() + x + r * width; + for (int c = 0; c < bmp->GetWidth(); ++ c, ++ src) { + *dst_pixels ++ = src.Red(); + *dst_pixels ++ = src.Green(); + *dst_pixels ++ = src.Blue(); + *dst_alpha ++ = src.Alpha(); + } + } + } + } else if (bmp->GetDepth() == 24) { + wxNativePixelData data(*const_cast(bmp)); + if (data) { + for (int r = 0; r < bmp->GetHeight(); ++ r) { + wxNativePixelData::Iterator src(data); + src.Offset(data, 0, r); + unsigned char *dst_pixels = image.GetData() + (x + r * width) * 3; + unsigned char *dst_alpha = image.GetAlpha() + x + r * width; + for (int c = 0; c < bmp->GetWidth(); ++ c, ++ src) { + *dst_pixels ++ = src.Red(); + *dst_pixels ++ = src.Green(); + *dst_pixels ++ = src.Blue(); + *dst_alpha ++ = wxALPHA_OPAQUE; + } + } + } + } + } + x += bmp->GetWidth(); + } + return this->insert(bitmap_key, wxImage_to_wxBitmap_with_alpha(std::move(image))); + +#else + + wxBitmap *bitmap = this->insert(bitmap_key, width, height); wxMemoryDC memDC; memDC.SelectObject(*bitmap); memDC.SetBackground(*wxTRANSPARENT_BRUSH); memDC.Clear(); - if (bmp.GetWidth() > 0) - memDC.DrawBitmap(bmp, 0, 0, true); - if (bmp2.GetWidth() > 0) - memDC.DrawBitmap(bmp2, bmp.GetWidth(), 0, true); - if (bmp3.GetWidth() > 0) - memDC.DrawBitmap(bmp3, bmp.GetWidth() + bmp2.GetWidth(), 0, true); - memDC.SelectObject(wxNullBitmap); - - return bitmap; -} - -wxBitmap* BitmapCache::insert(const std::string &bitmap_key, std::vector &bmps) -{ - size_t width = 0; - size_t height = 0; - for (wxBitmap &bmp : bmps) { - width += bmp.GetWidth(); - height = std::max(height, bmp.GetHeight()); - } - wxBitmap *bitmap = this->insert(bitmap_key, width, height); - - wxMemoryDC memDC; - memDC.SelectObject(*bitmap); - memDC.SetBackground(*wxTRANSPARENT_BRUSH); - memDC.Clear(); size_t x = 0; - for (wxBitmap &bmp : bmps) { - if (bmp.GetWidth() > 0) - memDC.DrawBitmap(bmp, x, 0, true); - x += bmp.GetWidth(); - } + for (const wxBitmap *bmp = begin; bmp != end; ++ bmp) { + if (bmp->GetWidth() > 0) + memDC.DrawBitmap(*bmp, x, 0, true); + x += bmp->GetWidth(); + } memDC.SelectObject(wxNullBitmap); + return bitmap; - return bitmap; +#endif } wxBitmap BitmapCache::mksolid(size_t width, size_t height, unsigned char r, unsigned char g, unsigned char b, unsigned char transparency) @@ -113,7 +165,7 @@ wxBitmap BitmapCache::mksolid(size_t width, size_t height, unsigned char r, unsi *imgdata ++ = b; *imgalpha ++ = transparency; } - return wxBitmap(std::move(image)); + return wxImage_to_wxBitmap_with_alpha(std::move(image)); } } // namespace GUI diff --git a/xs/src/slic3r/GUI/BitmapCache.hpp b/xs/src/slic3r/GUI/BitmapCache.hpp index 0cf9d8acf..bec9a7ad2 100644 --- a/xs/src/slic3r/GUI/BitmapCache.hpp +++ b/xs/src/slic3r/GUI/BitmapCache.hpp @@ -27,7 +27,8 @@ public: wxBitmap* insert(const std::string &name, const wxBitmap &bmp); wxBitmap* insert(const std::string &name, const wxBitmap &bmp, const wxBitmap &bmp2); wxBitmap* insert(const std::string &name, const wxBitmap &bmp, const wxBitmap &bmp2, const wxBitmap &bmp3); - wxBitmap* insert(const std::string &name, std::vector &bmps); + wxBitmap* insert(const std::string &name, const std::vector &bmps) { return this->insert(name, &bmps.front(), &bmps.front() + bmps.size()); } + wxBitmap* insert(const std::string &name, const wxBitmap *begin, const wxBitmap *end); static wxBitmap mksolid(size_t width, size_t height, unsigned char r, unsigned char g, unsigned char b, unsigned char transparency); static wxBitmap mksolid(size_t width, size_t height, const unsigned char rgb[3]) { return mksolid(width, height, rgb[0], rgb[1], rgb[2], wxALPHA_OPAQUE); } From 215c2082d3bb011f5ba95cd03b8614abafb488e8 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 13 Apr 2018 18:22:06 +0200 Subject: [PATCH 15/15] Decorated "bed_shape" and "compatible_printers" labels --- xs/src/slic3r/GUI/OptionsGroup.cpp | 7 +++- xs/src/slic3r/GUI/OptionsGroup.hpp | 2 +- xs/src/slic3r/GUI/Tab.cpp | 62 ++++++++++++++++++++++-------- xs/src/slic3r/GUI/Tab.hpp | 2 + 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index 8e2268965..168ffcdc9 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -97,7 +97,7 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co return field; } -void OptionsGroup::append_line(const Line& line) { +void OptionsGroup::append_line(const Line& line, wxStaticText** colored_Label/* = nullptr*/) { //! if (line.sizer != nullptr || (line.widget != nullptr && line.full_width > 0)){ if ( (line.sizer != nullptr || line.widget != nullptr) && line.full_width){ if (line.sizer != nullptr) { @@ -150,6 +150,7 @@ void OptionsGroup::append_line(const Line& line) { if (line.widget != nullptr) { auto wgt = line.widget(parent()); grid_sizer->Add(wgt, 0, wxEXPAND | wxBOTTOM | wxTOP, wxOSX ? 0 : 5); + if (colored_Label != nullptr) *colored_Label = label; return; } @@ -396,6 +397,10 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config ret = static_cast(config.opt_string(opt_key)); break; case coStrings: + if (opt_key.compare("compatible_printers") == 0){ + ret = config.option(opt_key)->values; + break; + } if (config.option(opt_key)->values.empty()) ret = text_value; else if (opt->gui_flags.compare("serialized") == 0){ diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp index b5846f24d..dd6d48f46 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.hpp +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -93,7 +93,7 @@ public: /// but defining it as const means a lot of const_casts to deal with wx functions. inline wxWindow* parent() const { return m_parent; } - void append_line(const Line& line); + void append_line(const Line& line, wxStaticText** colored_Label = nullptr); Line create_single_option_line(const Option& option) const; void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); } diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index a9faf4c59..4f6580f24 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -326,6 +326,7 @@ void Tab::update_changed_ui() m_dirty_options = dirty_options; } + Freeze(); //update options "decoration" for (const auto opt_key : m_full_options_list) { @@ -347,6 +348,14 @@ void Tab::update_changed_ui() is_modified_value = false; icon = "bullet_white.png"; } + if (opt_key == "bed_shape" || opt_key == "compatible_printers") { + if (m_colored_Label != nullptr) { + m_colored_Label->SetForegroundColour(color); + m_colored_Label->Refresh(true); + } + continue; + } + Field* field = get_field(opt_key); if (field == nullptr) continue; field->m_is_nonsys_value = is_nonsys_value; @@ -358,6 +367,7 @@ void Tab::update_changed_ui() field->m_Label->Refresh(true); } } + Thaw(); wxTheApp->CallAfter([this]() { update_changed_tree_ui(); @@ -419,13 +429,20 @@ void Tab::update_sys_ui_after_sel_preset() m_sys_options.resize(0); } +void Tab::get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page) +{ + if (sys_page && find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) + sys_page = false; + if (!modified_page && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) + modified_page = true; +} + void Tab::update_changed_tree_ui() { auto cur_item = m_treectrl->GetFirstVisibleItem(); auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection()); while (cur_item){ auto title = m_treectrl->GetItemText(cur_item); - int i=0; for (auto page : m_pages) { if (page->title() != title) @@ -435,23 +452,20 @@ void Tab::update_changed_tree_ui() if (title == _("General")){ std::initializer_list optional_keys{ "extruders_count", "bed_shape" }; for (auto &opt_key : optional_keys) { - if (sys_page && find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) - sys_page = false; - if (!modified_page && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) - modified_page = true; + get_sys_and_mod_flags(opt_key, sys_page, modified_page); } } + if (title == _("Dependencies")){ + get_sys_and_mod_flags("compatible_printers", sys_page, modified_page); + } for (auto group : page->m_optgroups) { - for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { - const std::string& opt_key = it->first; - if (sys_page && find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) - sys_page = false; - if (!modified_page && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) - modified_page = true; - } if (!sys_page && modified_page) break; + for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { + const std::string& opt_key = it->first; + get_sys_and_mod_flags(opt_key, sys_page, modified_page); + } } if (sys_page) m_treectrl->SetItemTextColour(cur_item, get_sys_label_clr()); @@ -500,6 +514,14 @@ void Tab::on_back_to_initial_value() if (find(m_dirty_options.begin(), m_dirty_options.end(), "bed_shape") != m_dirty_options.end()) group->back_to_initial_value("bed_shape"); } + if (group->title == _("Profile dependencies")){ + if (find(m_dirty_options.begin(), m_dirty_options.end(), "compatible_printers") != m_dirty_options.end()) + group->back_to_initial_value("compatible_printers"); + + bool is_empty = m_config->option("compatible_printers")->values.empty(); + m_compatible_printers_checkbox->SetValue(is_empty); + is_empty ? m_compatible_printers_btn->Disable() : m_compatible_printers_btn->Enable(); + } for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { const std::string& opt_key = it->first; if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) @@ -527,6 +549,14 @@ void Tab::on_back_to_sys_value() if (find(m_sys_options.begin(), m_sys_options.end(), "bed_shape") == m_sys_options.end()) group->back_to_sys_value("bed_shape"); } + if (group->title == _("Profile dependencies")){ + if (find(m_sys_options.begin(), m_sys_options.end(), "compatible_printers") == m_sys_options.end()) + group->back_to_sys_value("compatible_printers"); + + bool is_empty = m_config->option("compatible_printers")->values.empty(); + m_compatible_printers_checkbox->SetValue(is_empty); + is_empty ? m_compatible_printers_btn->Disable() : m_compatible_printers_btn->Enable(); + } for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { const std::string& opt_key = it->first; if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) @@ -905,7 +935,7 @@ void TabPrint::build() line.widget = [this](wxWindow* parent){ return compatible_printers_widget(parent, &m_compatible_printers_checkbox, &m_compatible_printers_btn); }; - optgroup->append_line(line); + optgroup->append_line(line, &m_colored_Label); option = optgroup->get_option("compatible_printers_condition"); option.opt.full_width = true; @@ -1279,7 +1309,7 @@ void TabFilament::build() line.widget = [this](wxWindow* parent){ return compatible_printers_widget(parent, &m_compatible_printers_checkbox, &m_compatible_printers_btn); }; - optgroup->append_line(line); + optgroup->append_line(line, &m_colored_Label); option = optgroup->get_option("compatible_printers_condition"); option.opt.full_width = true; @@ -1376,7 +1406,7 @@ void TabPrinter::build() return sizer; }; - optgroup->append_line(line); + optgroup->append_line(line, &m_colored_Label); optgroup->append_single_option_line("max_print_height"); optgroup->append_single_option_line("z_offset"); @@ -2114,6 +2144,7 @@ wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox if ((*checkbox)->GetValue()) load_key_value("compatible_printers", std::vector {}); get_field("compatible_printers_condition")->toggle((*checkbox)->GetValue()); + update_changed_ui(); }) ); (*btn)->Bind(wxEVT_BUTTON, ([this, parent, checkbox, btn](wxCommandEvent e) @@ -2156,6 +2187,7 @@ wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox } // All printers have been made compatible with this preset. load_key_value("compatible_printers", value); + update_changed_ui(); } })); return sizer; diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index 9465f86b4..c69f4285d 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -126,6 +126,7 @@ public: DynamicPrintConfig* m_config; std::string m_nonsys_btn_icon; ogStaticText* m_parent_preset_description_line; + wxStaticText* m_colored_Label = nullptr; public: Tab() {} @@ -166,6 +167,7 @@ public: void update_changed_ui(); void update_full_options_list(); void update_sys_ui_after_sel_preset(); + void get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page); void update_changed_tree_ui(); void update_undo_buttons();