ENH: save ams list to compare with last sync
Change-Id: I44db0b0a61cf366929aed6ab703407e5d9b170b7
This commit is contained in:
parent
ddf8c216c6
commit
b3a4384aec
|
@ -1427,6 +1427,13 @@ unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns)
|
||||||
for (auto &ams : filament_ams_list) {
|
for (auto &ams : filament_ams_list) {
|
||||||
auto filament_id = ams.opt_string("filament_id", 0u);
|
auto filament_id = ams.opt_string("filament_id", 0u);
|
||||||
auto filament_color = ams.opt_string("filament_colour", 0u);
|
auto filament_color = ams.opt_string("filament_colour", 0u);
|
||||||
|
auto filament_changed = !ams.has("filament_changed") || ams.opt_bool("filament_changed");
|
||||||
|
if (filament_id.empty()) continue;
|
||||||
|
if (!filament_changed && this->filament_presets.size() > filament_presets.size()) {
|
||||||
|
filament_presets.push_back(this->filament_presets[filament_presets.size()]);
|
||||||
|
filament_colors.push_back(filament_color);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
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; });
|
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()) {
|
if (iter == filaments.end()) {
|
||||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
|
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
|
||||||
|
|
|
@ -1756,7 +1756,7 @@ void GUI_App::init_networking_callbacks()
|
||||||
obj->parse_json(msg);
|
obj->parse_json(msg);
|
||||||
|
|
||||||
if (this->m_device_manager->get_selected_machine() == obj && obj->is_ams_need_update) {
|
if (this->m_device_manager->get_selected_machine() == obj && obj->is_ams_need_update) {
|
||||||
GUI::wxGetApp().sidebar().load_ams_list(obj->amsList);
|
GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj->amsList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1780,7 +1780,7 @@ void GUI_App::init_networking_callbacks()
|
||||||
if (obj) {
|
if (obj) {
|
||||||
obj->parse_json(msg);
|
obj->parse_json(msg);
|
||||||
if (this->m_device_manager->get_selected_machine() == obj && obj->is_ams_need_update) {
|
if (this->m_device_manager->get_selected_machine() == obj && obj->is_ams_need_update) {
|
||||||
GUI::wxGetApp().sidebar().load_ams_list(obj->amsList);
|
GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj->amsList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3351,7 +3351,7 @@ void GUI_App::request_user_logout()
|
||||||
m_agent->set_user_selected_machine("");
|
m_agent->set_user_selected_machine("");
|
||||||
/* delete old user settings */
|
/* delete old user settings */
|
||||||
m_device_manager->clean_user_info();
|
m_device_manager->clean_user_info();
|
||||||
GUI::wxGetApp().sidebar().load_ams_list({});
|
GUI::wxGetApp().sidebar().load_ams_list({}, {});
|
||||||
GUI::wxGetApp().stop_sync_user_preset();
|
GUI::wxGetApp().stop_sync_user_preset();
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
|
|
|
@ -153,7 +153,7 @@ MonitorPanel::~MonitorPanel()
|
||||||
if (!dev) return;
|
if (!dev) return;
|
||||||
MachineObject *obj_ = dev->get_selected_machine();
|
MachineObject *obj_ = dev->get_selected_machine();
|
||||||
if (obj_)
|
if (obj_)
|
||||||
GUI::wxGetApp().sidebar().load_ams_list(obj_->amsList);
|
GUI::wxGetApp().sidebar().load_ams_list(obj_->dev_id, obj_->amsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonitorPanel::init_tabpanel()
|
void MonitorPanel::init_tabpanel()
|
||||||
|
@ -228,7 +228,7 @@ void MonitorPanel::set_default()
|
||||||
/* reset side tool*/
|
/* reset side tool*/
|
||||||
//m_bitmap_wifi_signal->SetBitmap(wxNullBitmap);
|
//m_bitmap_wifi_signal->SetBitmap(wxNullBitmap);
|
||||||
|
|
||||||
wxGetApp().sidebar().load_ams_list({});
|
wxGetApp().sidebar().load_ams_list({}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWindow* MonitorPanel::create_side_tools()
|
wxWindow* MonitorPanel::create_side_tools()
|
||||||
|
@ -309,7 +309,7 @@ void MonitorPanel::on_update_all(wxMouseEvent &event)
|
||||||
|
|
||||||
MachineObject *obj_ = dev->get_selected_machine();
|
MachineObject *obj_ = dev->get_selected_machine();
|
||||||
if (obj_)
|
if (obj_)
|
||||||
GUI::wxGetApp().sidebar().load_ams_list(obj_->amsList);
|
GUI::wxGetApp().sidebar().load_ams_list(obj_->dev_id, obj_->amsList);
|
||||||
|
|
||||||
Layout();
|
Layout();
|
||||||
Refresh();
|
Refresh();
|
||||||
|
|
|
@ -334,6 +334,7 @@ struct Sidebar::priv
|
||||||
|
|
||||||
bool is_collapsed {false};
|
bool is_collapsed {false};
|
||||||
Search::OptionsSearcher searcher;
|
Search::OptionsSearcher searcher;
|
||||||
|
std::string ams_list_device;
|
||||||
|
|
||||||
priv(Plater *plater) : plater(plater) {}
|
priv(Plater *plater) : plater(plater) {}
|
||||||
~priv();
|
~priv();
|
||||||
|
@ -1355,13 +1356,12 @@ void Sidebar::on_bed_type_change(BedType bed_type)
|
||||||
m_bed_type_list->SetSelection(sel_idx);
|
m_bed_type_list->SetSelection(sel_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sidebar::load_ams_list(std::map<std::string, Ams *> const &list)
|
void Sidebar::load_ams_list(std::string const &device, std::map<std::string, Ams *> const &list)
|
||||||
{
|
{
|
||||||
std::vector<DynamicPrintConfig> filament_ams_list;
|
std::vector<DynamicPrintConfig> filament_ams_list;
|
||||||
for (auto ams : list) {
|
for (auto ams : list) {
|
||||||
char n = ams.first.front() - '0' + 'A';
|
char n = ams.first.front() - '0' + 'A';
|
||||||
for (auto tray : ams.second->trayList) {
|
for (auto tray : ams.second->trayList) {
|
||||||
if (tray.second->setting_id.empty()) continue;
|
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__
|
||||||
<< boost::format(": ams %1% tray %2% id %3% color %4%") % ams.first % tray.first % tray.second->setting_id % tray.second->color;
|
<< boost::format(": ams %1% tray %2% id %3% color %4%") % ams.first % tray.first % tray.second->setting_id % tray.second->color;
|
||||||
char t = tray.first.front() - '0' + '1';
|
char t = tray.first.front() - '0' + '1';
|
||||||
|
@ -1373,6 +1373,7 @@ void Sidebar::load_ams_list(std::map<std::string, Ams *> const &list)
|
||||||
filament_ams_list.emplace_back(std::move(ams));
|
filament_ams_list.emplace_back(std::move(ams));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
p->ams_list_device = device;
|
||||||
wxGetApp().preset_bundle->filament_ams_list = filament_ams_list;
|
wxGetApp().preset_bundle->filament_ams_list = filament_ams_list;
|
||||||
for (auto c : p->combos_filament)
|
for (auto c : p->combos_filament)
|
||||||
c->update();
|
c->update();
|
||||||
|
@ -1392,6 +1393,17 @@ void Sidebar::sync_ams_list()
|
||||||
_L("Sync filaments with AMS will drop all current selected filament presets and colors. Do you want to continue?"),
|
_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);
|
_L("Sync filaments with AMS"), wxYES_NO);
|
||||||
if (dlg.ShowModal() != wxID_YES) return;
|
if (dlg.ShowModal() != wxID_YES) return;
|
||||||
|
std::string ams_filament_ids = wxGetApp().app_config->get("ams_filament_ids", p->ams_list_device);
|
||||||
|
if (!ams_filament_ids.empty()) {
|
||||||
|
std::vector<std::string> list2;
|
||||||
|
boost::algorithm::split(list2, ams_filament_ids, boost::algorithm::is_any_of(","));
|
||||||
|
if (list2.size() == list.size()) {
|
||||||
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
|
list[i].set_key_value("filament_changed",
|
||||||
|
new ConfigOptionBool{!list2[i].empty() && list2[i] != list[i].opt_string("filament_id", 0u)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
unsigned int unknowns = 0;
|
unsigned int unknowns = 0;
|
||||||
auto n = wxGetApp().preset_bundle->sync_ams_list(unknowns);
|
auto n = wxGetApp().preset_bundle->sync_ams_list(unknowns);
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
|
@ -1401,6 +1413,10 @@ void Sidebar::sync_ams_list()
|
||||||
dlg.ShowModal();
|
dlg.ShowModal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
std::vector<std::string> list2;
|
||||||
|
for (auto &f : list) list2.push_back(f.opt_string("filament_id", 0u));
|
||||||
|
ams_filament_ids = boost::algorithm::join(list2, ",");
|
||||||
|
wxGetApp().app_config ->set("ams_filament_ids", p->ams_list_device, ams_filament_ids);
|
||||||
if (unknowns > 0) {
|
if (unknowns > 0) {
|
||||||
MessageDialog dlg(this,
|
MessageDialog dlg(this,
|
||||||
_L("There are some unknown filaments mapped to generic preset. Please update Bambu Studio or restart Bambu Studio to check if there is an update to system presets."),
|
_L("There are some unknown filaments mapped to generic preset. Please update Bambu Studio or restart Bambu Studio to check if there is an update to system presets."),
|
||||||
|
|
|
@ -123,7 +123,7 @@ public:
|
||||||
void on_filaments_change(size_t num_filaments);
|
void on_filaments_change(size_t num_filaments);
|
||||||
// BBS
|
// BBS
|
||||||
void on_bed_type_change(BedType bed_type);
|
void on_bed_type_change(BedType bed_type);
|
||||||
void load_ams_list(std::map<std::string, Ams *> const &list);
|
void load_ams_list(std::string const & device, std::map<std::string, Ams *> const &list);
|
||||||
void sync_ams_list();
|
void sync_ams_list();
|
||||||
|
|
||||||
ObjectList* obj_list();
|
ObjectList* obj_list();
|
||||||
|
|
|
@ -376,6 +376,7 @@ void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name)
|
||||||
auto &filaments = m_collection->get_presets();
|
auto &filaments = m_collection->get_presets();
|
||||||
for (auto &f : m_preset_bundle->filament_ams_list) {
|
for (auto &f : m_preset_bundle->filament_ams_list) {
|
||||||
std::string filament_id = f.opt_string("filament_id", 0u);
|
std::string filament_id = f.opt_string("filament_id", 0u);
|
||||||
|
if (filament_id.empty()) continue;
|
||||||
auto iter = std::find_if(filaments.begin(), filaments.end(),
|
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; });
|
[&filament_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == filament_id; });
|
||||||
if (iter == filaments.end()) {
|
if (iter == filaments.end()) {
|
||||||
|
|
|
@ -2555,7 +2555,7 @@ void SelectMachineDialog::on_selection_changed(wxCommandEvent &event)
|
||||||
obj->command_request_push_all();
|
obj->command_request_push_all();
|
||||||
dev->set_selected_machine(m_printer_last_select);
|
dev->set_selected_machine(m_printer_last_select);
|
||||||
// Has changed machine unrecoverably
|
// Has changed machine unrecoverably
|
||||||
GUI::wxGetApp().sidebar().load_ams_list(obj->amsList);
|
GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj->amsList);
|
||||||
update_select_layout(obj);
|
update_select_layout(obj);
|
||||||
} else {
|
} else {
|
||||||
BOOST_LOG_TRIVIAL(error) << "on_selection_changed dev_id not found";
|
BOOST_LOG_TRIVIAL(error) << "on_selection_changed dev_id not found";
|
||||||
|
|
Loading…
Reference in New Issue