diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 26542640b..e958640d6 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1258,8 +1258,12 @@ void Sidebar::priv::update_sync_status(const MachineObject *obj) if (preset_bundle && preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle) == obj->printer_type) { panel_printer_preset->ShowBadge(true); printer_synced = true; + + wxGetApp().plater()->sidebar().udpate_combos_filament_badge(); } else { clear_all_sync_status(); + + wxGetApp().plater()->sidebar().clear_combos_filament_badge(); return; } @@ -2957,9 +2961,7 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn) c->ShowBadge(true); }; { // badge ams filament - for (auto &c : p->combos_filament) {//clear flag - c->ShowBadge(false); - } + clear_combos_filament_badge(); if (sync_result.direct_sync) { for (auto &c : p->combos_filament) { badge_combox_filament(c); @@ -3232,6 +3234,25 @@ std::vector& Sidebar::combos_filament() return p->combos_filament; } +void Sidebar::clear_combos_filament_badge() +{ + auto &combos_filament = p->combos_filament; + for (auto &c : combos_filament) { // clear flag + c->ShowBadge(false); + } +} + +void Sidebar::udpate_combos_filament_badge() { + auto &combos_filament = p->combos_filament; + for (auto &c : combos_filament) { + auto selection = c->GetSelection(); + auto select_flag = c->GetFlag(selection); + auto ok = select_flag == (int) PresetComboBox::FilamentAMSType::FROM_AMS; + c->ShowBadge(ok); + } + +} + Search::OptionsSearcher& Sidebar::get_searcher() { return p->searcher; @@ -10598,6 +10619,8 @@ bool Plater::try_sync_preset_with_connected_printer() TipsDialog dlg(wxGetApp().mainframe, _L("Tips"), tips, "sync_after_load_file_show_flag", wxYES_NO,option_map); if (dlg.ShowModal() == wxID_YES) { sync_printer_preset = true; + } else { + return false; } } } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 5a366fd17..100c76e7d 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -207,6 +207,8 @@ public: #endif std::vector& combos_filament(); + void clear_combos_filament_badge(); + void udpate_combos_filament_badge(); Search::OptionsSearcher& get_searcher(); std::string& get_search_line(); void set_is_gcode_file(bool flag); diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 756978817..ca53a82dd 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -496,8 +496,9 @@ int PresetComboBox::selected_connected_printer(int index) const return -1; } -void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name) +bool PresetComboBox::add_ams_filaments(std::string selected, bool alias_name) { + bool selected_in_ams = false; bool is_bbl_vendor_preset = m_preset_bundle->printers.get_edited_preset().is_bbl_vendor_preset(m_preset_bundle); if (is_bbl_vendor_preset && !m_preset_bundle->filament_ams_list.empty()) { bool dual_extruder = (m_preset_bundle->filament_ams_list.begin()->first & 0x10000) == 0; @@ -540,12 +541,26 @@ void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name) auto color = tray.opt_string("filament_colour", 0u); auto name = tray.opt_string("tray_name", 0u); wxBitmap bmp(*get_extruder_color_icon(color, name, icon_width, 16)); - int item_id = Append(get_preset_name(*iter), bmp.ConvertToImage(), &m_first_ams_filament + entry.first); + auto text = get_preset_name(*iter); + int item_id = Append(text, bmp.ConvertToImage(), &m_first_ams_filament + entry.first); SetFlag(GetCount() - 1, (int) FilamentAMSType::FROM_AMS); + if (text == selected) { + DynamicPrintConfig *cfg = &wxGetApp().preset_bundle->project_config; + if (cfg) { + auto colors = static_cast(cfg->option("filament_colour")->clone()); + if (m_filament_idx < colors->values.size()) { + auto cur_color = colors->values[m_filament_idx]; + if (color == cur_color) { + selected_in_ams = true; + } + } + } + } //validate_selection(id->value == selected); // can not select } m_last_ams_filament = GetCount(); } + return selected_in_ams; } int PresetComboBox::selected_ams_filament() const @@ -937,6 +952,13 @@ void PlaterPresetComboBox::OnSelect(wxCommandEvent &evt) evt.Skip(); } +void PlaterPresetComboBox::update_badge_according_flag() { + auto selection = GetSelection(); + auto select_flag = GetFlag(selection); + auto ok = select_flag == (int) PresetComboBox::FilamentAMSType::FROM_AMS; + ShowBadge(ok); +} + bool PlaterPresetComboBox::switch_to_tab() { Tab* tab = wxGetApp().get_tab(m_type); @@ -1205,17 +1227,17 @@ void PlaterPresetComboBox::update() } //if (m_type == Preset::TYPE_PRINTER) // add_connected_printers("", true); - + bool selected_in_ams = false; if (m_type == Preset::TYPE_FILAMENT) { set_replace_text("Bambu", "BambuStudioBlack"); - add_ams_filaments(into_u8(selected_user_preset.empty() ? selected_system_preset : selected_user_preset), true); + selected_in_ams = add_ams_filaments(into_u8(selected_user_preset.empty() ? selected_system_preset : selected_user_preset), true); } std::vector filament_orders = {"Bambu PLA Basic", "Bambu PLA Matte", "Bambu PETG HF", "Bambu ABS", "Bambu PLA Silk", "Bambu PLA-CF", "Bambu PLA Galaxy", "Bambu PLA Metal", "Bambu PLA Marble", "Bambu PETG-CF", "Bambu PETG Translucent", "Bambu ABS-GF"}; std::vector first_vendors = {"Bambu Lab", "Generic"}; std::vector first_types = {"PLA", "PETG", "ABS", "TPU"}; - auto add_presets = [this, &preset_descriptions, &filament_orders, &preset_filament_vendors, &first_vendors, &preset_filament_types, &first_types] + auto add_presets = [this, &preset_descriptions, &filament_orders, &preset_filament_vendors, &first_vendors, &preset_filament_types, &first_types, &selected_in_ams] (std::map const &presets, wxString const &selected, std::string const &group) { if (!presets.empty()) { set_label_marker(Append(separator(group), wxNullBitmap)); @@ -1246,7 +1268,11 @@ void PlaterPresetComboBox::update() }); for (auto it : list) { SetItemTooltip(Append(it->first, *it->second), preset_descriptions[it->first]); - validate_selection(it->first == selected); + bool is_selected = it->first == selected; + validate_selection(is_selected); + if (is_selected && selected_in_ams) { + SetFlag(GetCount() - 1, (int) FilamentAMSType::FROM_AMS); + } } } else { for (std::map::const_iterator it = presets.begin(); it != presets.end(); ++it) { @@ -1304,6 +1330,9 @@ void PlaterPresetComboBox::update() } update_selection(); + if (m_type == Preset::TYPE_FILAMENT) { + update_badge_according_flag(); + } Thaw(); if (!tooltip.IsEmpty()) { diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index e3c76f7b8..107edbfb5 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -80,7 +80,7 @@ public: int selected_connected_printer(int index) const; // BBS: ams - void add_ams_filaments(std::string selected, bool alias_name = false); + bool add_ams_filaments(std::string selected, bool alias_name = false); int selected_ams_filament() const; void set_filament_idx(const int extr_idx) { m_filament_idx = extr_idx; } @@ -207,6 +207,7 @@ public: void update() override; void msw_rescale() override; void OnSelect(wxCommandEvent& evt) override; + void update_badge_according_flag(); private: // BBS diff --git a/src/slic3r/GUI/SyncAmsInfoDialog.cpp b/src/slic3r/GUI/SyncAmsInfoDialog.cpp index fe3e63f56..dfb56ba28 100644 --- a/src/slic3r/GUI/SyncAmsInfoDialog.cpp +++ b/src/slic3r/GUI/SyncAmsInfoDialog.cpp @@ -4013,13 +4013,20 @@ void SyncAmsInfoDialog::clone_thumbnail_data(bool allow_clone_ams_color) while (iter != m_materialList.end()) { int id = iter->first; Material *item = iter->second; - auto m = item->item; - m_preview_colors_in_thumbnail[id] = m->m_material_coloul; - if (item->id < m_cur_colors_in_thumbnail.size()) { - m_cur_colors_in_thumbnail[item->id] = m->m_ams_coloul; - } else { // exist empty or unrecognized type ams in machine - m_cur_colors_in_thumbnail.resize(item->id + 1); - m_cur_colors_in_thumbnail[item->id] = m->m_ams_coloul; + if (item) { + auto m = item->item; + if (m) { + m_preview_colors_in_thumbnail[id] = m->m_material_coloul; + if (item->id < m_cur_colors_in_thumbnail.size()) { + m_cur_colors_in_thumbnail[item->id] = m->m_ams_coloul; + } else { // exist empty or unrecognized type ams in machine + m_cur_colors_in_thumbnail.resize(item->id + 1); + m_cur_colors_in_thumbnail[item->id] = m->m_ams_coloul; + } + } + } + else { + BOOST_LOG_TRIVIAL(error) << "check error:SyncAmsInfoDialog::clone_thumbnail_data:item is nullptr"; } iter++; }