From b69dfd63ca3179de4c3d53326c97b7edf5caca4d Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 16 Apr 2020 09:59:12 +0200 Subject: [PATCH] Completed a search list cleaning (deleted unused options). + Implemented BlinkingBitmap + Options, that doesn't have related controls, are highlighted near the widgets. --- src/slic3r/GUI/Field.cpp | 3 +- src/slic3r/GUI/Field.hpp | 19 ++----- src/slic3r/GUI/OptionsGroup.cpp | 2 +- src/slic3r/GUI/Search.cpp | 76 +++++++++++++++++++------- src/slic3r/GUI/Search.hpp | 10 ++-- src/slic3r/GUI/Tab.cpp | 95 +++++++++++++++++++++++++-------- src/slic3r/GUI/Tab.hpp | 23 +++++--- src/slic3r/GUI/wxExtensions.cpp | 35 ++++++++++++ src/slic3r/GUI/wxExtensions.hpp | 24 +++++++++ 9 files changed, 219 insertions(+), 68 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index dfe561caf..f78714fcb 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -57,8 +57,7 @@ void Field::PostInitialize() m_Undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_initial_value(); })); m_Undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_sys_value(); })); - m_attention_bmp = ScalableBitmap(m_parent, "attention"); - m_find_image = new wxStaticBitmap(m_parent, wxID_ANY, wxNullBitmap, wxDefaultPosition, m_attention_bmp.bmp().GetSize()); + m_blinking_bmp = new BlinkingBitmap(m_parent); switch (m_opt.type) { diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index d716be25c..f41e3c7b0 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -191,20 +191,6 @@ public: return false; } - void invalidate_attention_bmp() const { - m_find_image->SetBitmap(wxNullBitmap); - m_find_image->Show(); - } - - void activate_attention_bmp() const { - m_find_image->SetBitmap(m_attention_bmp.bmp()); - } - - void blink_attention_bmp() const { - bool is_shown = m_find_image->IsShown(); - m_find_image->Show(!is_shown); - } - bool set_label_colour_force(const wxColour *clr) { if (m_Label == nullptr) return false; m_Label->SetForegroundColour(*clr); @@ -244,6 +230,8 @@ public: static int def_width_wider() ; static int def_width_thinner() ; + BlinkingBitmap* blinking_bitmap() const { return m_blinking_bmp;} + protected: RevertButton* m_Undo_btn = nullptr; // Bitmap and Tooltip text for m_Undo_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one. @@ -254,8 +242,7 @@ protected: const ScalableBitmap* m_undo_to_sys_bitmap = nullptr; const wxString* m_undo_to_sys_tooltip = nullptr; - ScalableBitmap m_attention_bmp; - wxStaticBitmap* m_find_image{ nullptr }; + BlinkingBitmap* m_blinking_bmp{ nullptr }; wxStaticText* m_Label = nullptr; // Color for Label. The wxColour will be updated only if the new wxColour pointer differs from the currently rendered one. diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index bafcac3a4..22e259244 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -108,9 +108,9 @@ void OptionsGroup::add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& fiel return; } + sizer->Add(field->m_blinking_bmp, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 2); sizer->Add(field->m_Undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL); sizer->Add(field->m_Undo_btn, 0, wxALIGN_CENTER_VERTICAL); - sizer->Add(field->m_find_image, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 2); } void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = nullptr*/) { diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index b55f4fbab..f5b36cf89 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -92,16 +92,35 @@ void FoundOption::get_marked_label(const char** out_text) const } template -void change_opt_key(std::string& opt_key, DynamicPrintConfig* config) +//void change_opt_key(std::string& opt_key, DynamicPrintConfig* config) +void change_opt_key(std::string& opt_key, DynamicPrintConfig* config, int& cnt) { T* opt_cur = static_cast(config->option(opt_key)); + cnt = opt_cur->values.size(); + return; + if (opt_cur->values.size() > 0) opt_key += "#" + std::to_string(0); } void OptionsSearcher::append_options(DynamicPrintConfig* config, Preset::Type type, ConfigOptionMode mode) { - std::vector non_added_options {"printer_technology", "thumbnails" }; + auto emplace = [this, type](const std::string opt_key, const wxString& label) + { + const GroupAndCategory& gc = groups_and_categories[opt_key]; + if (gc.group.IsEmpty() || gc.category.IsEmpty()) + return; + + wxString suffix; + if (gc.category == "Machine limits") + suffix = opt_key.back()=='1' ? L("Stealth") : L("Normal"); + + if (!label.IsEmpty()) + options.emplace_back(Option{ opt_key, type, + label+ " " + suffix, _(label)+ " " + _(suffix), + gc.group, _(gc.group), + gc.category, _(gc.category) }); + }; for (std::string opt_key : config->keys()) { @@ -109,27 +128,37 @@ void OptionsSearcher::append_options(DynamicPrintConfig* config, Preset::Type ty if (opt.mode > mode) continue; - if (type == Preset::TYPE_SLA_MATERIAL || type == Preset::TYPE_PRINTER) + int cnt = 0; + + if ( (type == Preset::TYPE_SLA_MATERIAL || type == Preset::TYPE_PRINTER) && opt_key != "bed_shape") switch (config->option(opt_key)->type()) { - case coInts: change_opt_key(opt_key, config); break; - case coBools: change_opt_key(opt_key, config); break; - case coFloats: change_opt_key(opt_key, config); break; - case coStrings: change_opt_key(opt_key, config); break; - case coPercents:change_opt_key(opt_key, config); break; - case coPoints: change_opt_key(opt_key, config); break; + case coInts: change_opt_key(opt_key, config, cnt); break; + case coBools: change_opt_key(opt_key, config, cnt); break; + case coFloats: change_opt_key(opt_key, config, cnt); break; + case coStrings: change_opt_key(opt_key, config, cnt); break; + case coPercents:change_opt_key(opt_key, config, cnt); break; + case coPoints: change_opt_key(opt_key, config, cnt); break; default: break; } wxString label = opt.full_label.empty() ? opt.label : opt.full_label; - const GroupAndCategory& gc = groups_and_categories[opt_key]; + if (cnt == 0) + emplace(opt_key, label); + else + for (int i = 0; i < cnt; ++i) + emplace(opt_key + "#" + std::to_string(i), label); + + /*const GroupAndCategory& gc = groups_and_categories[opt_key]; + if (gc.group.IsEmpty() || gc.category.IsEmpty()) + continue; if (!label.IsEmpty()) options.emplace_back(Option{opt_key, type, label, _(label), gc.group, _(gc.group), - gc.category, _(gc.category) }); + gc.category, _(gc.category) });*/ } } @@ -243,6 +272,22 @@ void OptionsSearcher::init(std::vector input_values) search(search_line, true); } +void OptionsSearcher::apply(DynamicPrintConfig* config, Preset::Type type, ConfigOptionMode mode) +{ + if (options.empty()) + return; + + options.erase(std::remove_if(options.begin(), options.end(), [type](Option opt) { + return opt.type == type; + }), options.end()); + + append_options(config, type, mode); + + sort_options(); + + search(search_line, true); +} + const Option& OptionsSearcher::get_option(size_t pos_in_filter) const { assert(pos_in_filter != size_t(-1) && found[pos_in_filter].option_idx != size_t(-1)); @@ -353,12 +398,7 @@ SearchCtrl::SearchCtrl(wxWindow* parent) : this->Bind(wxEVT_TEXT, &SearchCtrl::OnInputText, this); this->Bind(wxEVT_TEXT_ENTER, &SearchCtrl::PopupList, this); this->Bind(wxEVT_COMBOBOX_DROPDOWN, &SearchCtrl::PopupList, this); -/* - this->Bind(wxEVT_KEY_DOWN, [this](wxKeyEvent&e) - { - - }); -*/ + this->GetTextCtrl()->Bind(wxEVT_LEFT_UP, &SearchCtrl::OnLeftUpInTextCtrl, this); popupListBox->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this); } @@ -421,7 +461,7 @@ void SearchCtrl::OnSelect(wxCommandEvent& event) void SearchCtrl::update_list(const std::vector& filters) { - if (popupListBox->GetCount() == filters.size() && + if (!filters.empty() && popupListBox->GetCount() == filters.size() && popupListBox->GetString(0) == filters[0].label && popupListBox->GetString(popupListBox->GetCount()-1) == filters[filters.size()-1].label) return; diff --git a/src/slic3r/GUI/Search.hpp b/src/slic3r/GUI/Search.hpp index 83df4136c..3f24fbd3a 100644 --- a/src/slic3r/GUI/Search.hpp +++ b/src/slic3r/GUI/Search.hpp @@ -76,11 +76,11 @@ struct FoundOption { class OptionsSearcher { - std::string search_line; + std::string search_line; std::map groups_and_categories; - std::vector