ENH: sync with ams filament

Change-Id: Ifa8b9487c934a18ad1003f380bbb53fa9288e387
This commit is contained in:
chunmao.guo 2022-09-14 13:15:39 +08:00 committed by Lane.Wei
parent 83a9c259f7
commit 673b6418c1
8 changed files with 94 additions and 46 deletions

View file

@ -0,0 +1,12 @@
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.60031 3.36816C1.60031 2.53974 2.27188 1.86816 3.10031 1.86816H14.7634C15.5918 1.86816 16.2634 2.53974 16.2634 3.36816V10.0047H1.60031V3.36816ZM3.10031 2.86816C2.82417 2.86816 2.60031 3.09202 2.60031 3.36816V9.00474H15.2634V3.36816C15.2634 3.09202 15.0395 2.86816 14.7634 2.86816H3.10031Z" fill="#262E30"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M0.252106 10.5047C0.252106 9.6763 0.923678 9.00473 1.75211 9.00473H15.9972C16.8256 9.00473 17.4972 9.6763 17.4972 10.5047V15.6229C17.4972 16.4514 16.8256 17.1229 15.9972 17.1229H1.7521C0.923676 17.1229 0.252106 16.4514 0.252106 15.6229V10.5047ZM1.75211 10.0047C1.47596 10.0047 1.25211 10.2286 1.25211 10.5047V15.6229C1.25211 15.8991 1.47596 16.1229 1.7521 16.1229H15.9972C16.2733 16.1229 16.4972 15.8991 16.4972 15.6229V10.5047C16.4972 10.2286 16.2734 10.0047 15.9972 10.0047H1.75211Z" fill="#262E30"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.15292 3.96497H6.79239V10.0046H3.15292V3.96497ZM4.15292 4.96497V9.00458H5.79239V4.96497H4.15292Z" fill="#262E30"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.79236 3.96484H9.43183V10.0045H5.79236V3.96484ZM6.79236 4.96484V9.00446H8.43183V4.96484H6.79236Z" fill="#262E30"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.43182 3.96484H12.0713V10.0045H8.43182V3.96484ZM9.43182 4.96484V9.00446H11.0713V4.96484H9.43182Z" fill="#262E30"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.0713 3.9649H14.7107V10.0045H11.0713V3.9649ZM12.0713 4.9649V9.00452H13.7107V4.9649H12.0713Z" fill="#262E30"/>
<path d="M19.7747 13.0638C19.7747 16.4492 17.0303 19.1936 13.6449 19.1936C10.2595 19.1936 7.51514 16.4492 7.51514 13.0638C7.51514 9.67844 10.2595 6.93405 13.6449 6.93405C17.0303 6.93405 19.7747 9.67844 19.7747 13.0638Z" fill="#F5F5F5"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M13.6449 18.1936C16.478 18.1936 18.7747 15.8969 18.7747 13.0638C18.7747 10.2307 16.478 7.93405 13.6449 7.93405C10.8118 7.93405 8.51514 10.2307 8.51514 13.0638C8.51514 15.8969 10.8118 18.1936 13.6449 18.1936ZM13.6449 19.1936C17.0303 19.1936 19.7747 16.4492 19.7747 13.0638C19.7747 9.67844 17.0303 6.93405 13.6449 6.93405C10.2595 6.93405 7.51514 9.67844 7.51514 13.0638C7.51514 16.4492 10.2595 19.1936 13.6449 19.1936Z" fill="#262E30"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.455 10.2222C14.6503 10.0269 14.9669 10.0269 15.1621 10.2222L16.6376 11.6976C16.7806 11.8406 16.8234 12.0557 16.746 12.2425C16.6686 12.4294 16.4863 12.5512 16.284 12.5512H11.0631C10.787 12.5512 10.5631 12.3273 10.5631 12.0512C10.5631 11.775 10.787 11.5512 11.0631 11.5512H15.0769L14.455 10.9293C14.2598 10.734 14.2598 10.4174 14.455 10.2222Z" fill="#262E30"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.8347 15.9055C12.6395 16.1007 12.3229 16.1007 12.1276 15.9055L10.6522 14.43C10.5092 14.287 10.4664 14.0719 10.5438 13.8851C10.6212 13.6983 10.8035 13.5764 11.0057 13.5764L16.2266 13.5764C16.5028 13.5764 16.7266 13.8003 16.7266 14.0764C16.7266 14.3526 16.5028 14.5764 16.2266 14.5764L12.2128 14.5764L12.8347 15.1984C13.03 15.3936 13.03 15.7102 12.8347 15.9055Z" fill="#262E30"/>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

@ -1314,6 +1314,31 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
update_multi_material_filament_presets();
}
unsigned int PresetBundle::sync_ams_list()
{
std::vector<std::string> filament_presets;
std::vector<std::string> filament_colors;
for (auto &ams : filament_ams_list) {
auto filament_id = ams.opt_string("filament_id", 0u);
auto filament_color = ams.opt_string("filament_colour", 0u);
auto iter = std::find_if(filaments.begin(), filaments.end(), [&filament_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == filament_id; });
if (iter == filaments.end()) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
continue;
}
filament_presets.push_back(iter->name);
filament_colors.push_back(filament_color);
}
if (filament_presets.empty())
return 0;
this->filament_presets = filament_presets;
ConfigOptionStrings *filament_color = project_config.option<ConfigOptionStrings>("filament_colour");
filament_color->resize(filament_presets.size());
filament_color->values = filament_colors;
update_multi_material_filament_presets();
return filament_presets.size();
}
//BBS: check whether this is the only edited filament
bool PresetBundle::is_the_only_edited_filament(unsigned int filament_index)
{

View file

@ -79,6 +79,7 @@ public:
// BBS
void set_num_filaments(unsigned int n, std::string new_col = "");
unsigned int sync_ams_list();
//BBS: check whether this is the only edited filament
bool is_the_only_edited_filament(unsigned int filament_index);

View file

@ -1641,12 +1641,9 @@ void GUI_App::init_networking_callbacks()
if (obj) {
obj->parse_json(msg);
#if !BBL_RELEASE_TO_PUBLIC
if (obj->is_ams_need_update) {
GUI::wxGetApp().sidebar().load_ams_list(obj->amsList);
}
#endif
}
});
};

View file

@ -287,6 +287,7 @@ struct Sidebar::priv
wxStaticText* m_staticText_filament_settings;
ScalableButton * m_bpButton_add_filament;
ScalableButton * m_bpButton_del_filament;
ScalableButton * m_bpButton_ams_filament;
ScalableButton * m_bpButton_set_filament;
wxPanel* m_panel_filament_content;
wxScrolledWindow* m_scrolledWindow_filament_content;
@ -636,6 +637,7 @@ Sidebar::Sidebar(Plater *parent)
bSizer39->Add(FromDIP(10), 0, 0, 0, 0 );
ScalableButton* add_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "add_filament");
add_btn->SetToolTip(_L("Add one filament"));
add_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent& e){
// BBS: limit filament choices to 16
if (p->combos_filament.size() >= 16)
@ -654,7 +656,8 @@ Sidebar::Sidebar(Plater *parent)
bSizer39->Add(FromDIP(10), 0, 0, 0, 0 );
ScalableButton* del_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "delete_filament");
del_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent& e){
del_btn->SetToolTip(_L("Remove last filament"));
del_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent &e) {
if (p->combos_filament.size() <= 1)
return;
@ -676,8 +679,20 @@ Sidebar::Sidebar(Plater *parent)
bSizer39->Add(del_btn, 0, wxALIGN_CENTER_VERTICAL, FromDIP(5));
bSizer39->Add(FromDIP(20), 0, 0, 0, 0);
ScalableButton *ams_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "ams_fila_sync", wxEmptyString, wxDefaultSize, wxDefaultPosition,
wxBU_EXACTFIT | wxNO_BORDER, false, 18);
ams_btn->SetToolTip(_L("Sync material list from AMS"));
ams_btn->Bind(wxEVT_BUTTON, [this, scrolled_sizer](wxCommandEvent &e) {
sync_ams_list();
});
p->m_bpButton_ams_filament = ams_btn;
bSizer39->Add(ams_btn, 0, wxALIGN_CENTER|wxALL, FromDIP(5));
bSizer39->Add(FromDIP(10), 0, 0, 0, 0 );
ScalableButton* set_btn = new ScalableButton(p->m_panel_filament_title, wxID_ANY, "settings");
set_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) {
set_btn->SetToolTip(_L("Set filaments to use"));
set_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) {
// p->editing_filament = -1;
// wxGetApp().params_dialog()->Popup();
// wxGetApp().get_tab(Preset::TYPE_FILAMENT)->restore_last_select_item();
@ -992,6 +1007,7 @@ void Sidebar::msw_rescale()
p->m_filament_icon->msw_rescale();
p->m_bpButton_add_filament->msw_rescale();
p->m_bpButton_del_filament->msw_rescale();
p->m_bpButton_ams_filament->msw_rescale();
p->m_bpButton_set_filament->msw_rescale();
p->m_flushing_volume_btn->Rescale();
//BBS
@ -1171,42 +1187,9 @@ void Sidebar::load_ams_list(std::map<std::string, Ams *> const &list)
std::vector<DynamicPrintConfig> filament_ams_list;
for (auto ams : list) {
for (auto tray : ams.second->trayList) {
if (tray.second->setting_id.empty())
continue;
if (tray.second->setting_id.empty()) continue;
DynamicPrintConfig ams;
auto & filaments = wxGetApp().preset_bundle->filaments.get_presets();
auto iter = std::find_if(filaments.begin(), filaments.end(),
[&tray](auto &f) { return f.filament_id == tray.second->setting_id; });
if (iter != filaments.end()) {
ams.set_key_value("filament_settings_id", new ConfigOptionStrings{tray.second->setting_id});
} else {
/* std::shared_ptr<std::map<std::string, std::string>> preset(new std::map<std::string, std::string>);
(*preset)->setting_id = tray.second->setting_id;
ams.set_key_value("filament_settings_id", new ConfigOptionStrings{tray.second->setting_id});
//TODO: comment it currently
NetworkAgent* agent = wxGetApp().getAgent();
if (agent) {
agent->get_setting(tray.second->setting_id, *preset, [preset] {
wxGetApp().CallAfter([preset] {
if ((*preset)->name.empty())
return;
PresetsConfigSubstitutions substitutions;
wxGetApp().preset_bundle->filaments.load_user_presets({{(*preset)->name, *preset}},
PRESET_FILAMENT_NAME, substitutions, ForwardCompatibilitySubstitutionRule::Enable);
auto & ams_list = wxGetApp().preset_bundle->filament_ams_list;
for (auto& ams : ams_list) {
if (ams.opt_string("filament_settings_id", 0u) == (*preset)->setting_id) {
ams.set_key_value("filament_settings_id", new ConfigOptionStrings{(*preset)->name});
for (auto c : wxGetApp().sidebar().combos_filament()) c->update();
break;
}
}
});
});
}
*/
continue;
}
ams.set_key_value("filament_id", new ConfigOptionStrings{tray.second->setting_id});
ams.set_key_value("filament_colour", new ConfigOptionStrings{"#" + tray.second->color.substr(0, 6)});
filament_ams_list.emplace_back(std::move(ams));
}
@ -1216,6 +1199,34 @@ void Sidebar::load_ams_list(std::map<std::string, Ams *> const &list)
c->update();
}
void Sidebar::sync_ams_list()
{
auto & list = wxGetApp().preset_bundle->filament_ams_list;
if (list.empty()) {
MessageDialog dlg(this,
_L("No AMS filaments. Please select a printer in 'Device' page to load AMS info."),
_L("Sync filaments with AMS"), wxOK);
dlg.ShowModal();
return;
}
MessageDialog dlg(this,
_L("Sync filaments with AMS will drop all current selected filament presets and colors. Do you want to continue?"),
_L("Sync filaments with AMS"), wxYES_NO);
if (dlg.ShowModal() != wxID_YES) return;
auto n = wxGetApp().preset_bundle->sync_ams_list();
if (n == 0) {
MessageDialog dlg(this,
_L("There are no compatible filaments, and sync is not performed."),
_L("Sync filaments with AMS"), wxOK);
dlg.ShowModal();
return;
}
wxGetApp().plater()->on_filaments_change(n);
for (auto &c : p->combos_filament)
c->update();
wxGetApp().get_tab(Preset::TYPE_PRINT)->update();
}
ObjectList* Sidebar::obj_list()
{
// BBS

View file

@ -117,7 +117,8 @@ public:
void on_filaments_change(size_t num_filaments);
// BBS
void on_bed_type_change(BedType bed_type);
void load_ams_list(std::map<std::string, Ams *> const & list);
void load_ams_list(std::map<std::string, Ams *> const &list);
void sync_ams_list();
ObjectList* obj_list();
ObjectSettings* obj_settings();

View file

@ -387,11 +387,11 @@ void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name)
m_first_ams_filament = GetCount();
auto &filaments = m_collection->get_presets();
for (auto &f : m_preset_bundle->filament_ams_list) {
std::string setting_id = f.opt_string("filament_settings_id", 0u);
std::string filament_id = f.opt_string("filament_id", 0u);
auto iter = std::find_if(filaments.begin(), filaments.end(),
[&setting_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == setting_id; });
[&filament_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == filament_id; });
if (iter == filaments.end()) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % setting_id;
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
continue;
}
const_cast<Preset&>(*iter).is_visible = true;

View file

@ -231,7 +231,7 @@ void Tab::create_preset_tab()
m_btn_compare_preset->SetToolTip(_L("Compare presets"));
// TRN "Save current Settings"
m_btn_save_preset->SetToolTip(from_u8((boost::format(_utf8(L("Save current %s"))) % m_title).str()));
m_btn_save_preset->SetToolTip(wxString::Format(_L("Save current %s"), m_title));
m_btn_delete_preset->SetToolTip(_(L("Delete this preset")));
m_btn_delete_preset->Hide();
@ -255,6 +255,7 @@ void Tab::create_preset_tab()
add_scaled_button(m_top_panel, &m_undo_btn, m_bmp_white_bullet.name());
add_scaled_button(m_top_panel, &m_undo_to_sys_btn, m_bmp_white_bullet.name());
add_scaled_button(m_top_panel, &m_btn_search, "search");
m_btn_search->SetToolTip(_L("Search in preset"));
//search input
m_search_item = new RoundedRectangle(m_top_panel, wxColour(238, 238, 238), wxDefaultPosition, wxSize(m_top_panel->GetSize().GetWidth(), 3 * wxGetApp().em_unit()), 8);
@ -993,7 +994,7 @@ void Tab::update_undo_buttons()
m_undo_btn-> SetBitmap_(m_presets->get_edited_preset().is_dirty ? m_bmp_value_revert: m_bmp_white_bullet);
m_undo_to_sys_btn-> SetBitmap_(m_is_nonsys_values ? *m_bmp_non_system : m_bmp_value_lock);
m_undo_btn->SetToolTip(m_is_modified_values ? m_ttg_value_revert : m_ttg_white_bullet);
m_undo_btn->SetToolTip(m_presets->get_edited_preset().is_dirty ? _L("Click to reset all settings to the last saved preset.") : m_ttg_white_bullet);
m_undo_to_sys_btn->SetToolTip(m_is_nonsys_values ? *m_ttg_non_system : m_ttg_value_lock);
}