FIX: [STUDIO-1574] not switch filament preset after wizard

Change-Id: Ica703553a6994456f12b509564443902697ed374
This commit is contained in:
chunmao.guo 2022-12-05 11:24:12 +08:00 committed by Lane.Wei
parent f49c4c7e4c
commit 8cee81b5ef
5 changed files with 16 additions and 43 deletions

View file

@ -807,36 +807,6 @@ void PresetBundle::update_system_preset_setting_ids(std::map<std::string, std::m
return;
}
void PresetBundle::load_default_setting_from_app_config(const AppConfig &config) {
auto config_filament_presets = config.get_filament_presets();
if (!config_filament_presets.empty())
this->filament_presets = config_filament_presets;
auto config_filament_colors = config.get_filament_colors();
if (!config_filament_colors.empty()) {
ConfigOptionStrings *filament_color = project_config.option<ConfigOptionStrings>("filament_colour");
filament_color->resize(config_filament_colors.size());
filament_color->values = config_filament_colors;
}
auto config_flush_volumes_matrix = config.get_flush_volumes_matrix();
if (!config_flush_volumes_matrix.empty()) {
ConfigOptionFloats *flush_volumes_matrix = project_config.option<ConfigOptionFloats>("flush_volumes_matrix");
flush_volumes_matrix->values = std::vector<double>(config_flush_volumes_matrix.begin(), config_flush_volumes_matrix.end());
}
}
void PresetBundle::update_filament_info_to_app_config(AppConfig &config)
{
config.set_filament_presets(this->filament_presets);
ConfigOptionStrings *filament_color = project_config.option<ConfigOptionStrings>("filament_colour");
config.set_filament_colors(filament_color->values);
ConfigOptionFloats *flush_volumes_matrix = project_config.option<ConfigOptionFloats>("flush_volumes_matrix");
config.set_flush_volumes_matrix(std::vector<float>(flush_volumes_matrix->values.begin(), flush_volumes_matrix->values.end()));
}
//BBS: validate printers from previous project
bool PresetBundle::validate_printers(const std::string &name, DynamicPrintConfig& config)
{
@ -1346,6 +1316,15 @@ void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& p
}
}
std::string first_visible_filament_name;
for (auto & fp : filament_presets) {
if (auto it = filaments.find_preset_internal(fp); it == filaments.end() || !it->is_visible || !it->is_compatible) {
if (first_visible_filament_name.empty())
first_visible_filament_name = filaments.first_compatible().name;
fp = first_visible_filament_name;
}
}
// Parse the initial physical printer name.
std::string initial_physical_printer_name = remove_ini_suffix(config.get("presets", "physical_printer"));

View file

@ -54,8 +54,6 @@ public:
void update_user_presets_directory(const std::string preset_folder);
void remove_user_presets_directory(const std::string preset_folder);
void update_system_preset_setting_ids(std::map<std::string, std::map<std::string, std::string>>& system_presets);
void load_default_setting_from_app_config(const AppConfig &config);
void update_filament_info_to_app_config(AppConfig &config);
//BBS: add API to get previous machine
bool validate_printers(const std::string &name, DynamicPrintConfig& config);

View file

@ -2198,7 +2198,6 @@ bool GUI_App::on_init_inner()
BOOST_LOG_TRIVIAL(info) << "loading systen presets...";
preset_bundle = new PresetBundle();
preset_bundle->load_default_setting_from_app_config(*app_config);
// just checking for existence of Slic3r::data_dir is not enough : it may be an empty directory
// supplied as argument to --datadir; in that case we should still run the wizard

View file

@ -703,7 +703,7 @@ Sidebar::Sidebar(Plater *parent)
(project_config.option<ConfigOptionFloat>("flush_multiplier"))->set(new ConfigOptionFloat(dlg.get_flush_multiplier()));
wxGetApp().app_config->set("flush_multiplier", std::to_string(dlg.get_flush_multiplier()));
wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config);
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
wxGetApp().plater()->update_project_dirty_from_presets();
wxPostEvent(parent, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, parent));
@ -726,7 +726,7 @@ Sidebar::Sidebar(Plater *parent)
wxGetApp().preset_bundle->set_num_filaments(filament_count, new_color);
wxGetApp().plater()->on_filaments_change(filament_count);
wxGetApp().get_tab(Preset::TYPE_PRINT)->update();
wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config);
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
});
p->m_bpButton_add_filament = add_btn;
@ -751,7 +751,7 @@ Sidebar::Sidebar(Plater *parent)
wxGetApp().preset_bundle->set_num_filaments(filament_count);
wxGetApp().plater()->on_filaments_change(filament_count);
wxGetApp().get_tab(Preset::TYPE_PRINT)->update();
wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config);
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
});
p->m_bpButton_del_filament = del_btn;
@ -1352,7 +1352,7 @@ void Sidebar::sync_ams_list()
for (auto &c : p->combos_filament)
c->update();
wxGetApp().get_tab(Preset::TYPE_PRINT)->update();
wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config);
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
}
ObjectList* Sidebar::obj_list()
@ -5382,7 +5382,7 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
if (preset_type == Preset::TYPE_FILAMENT) {
wxGetApp().preset_bundle->set_filament_preset(idx, preset_name);
wxGetApp().plater()->update_project_dirty_from_presets();
wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config);
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
}
bool select_preset = !combo->selection_is_changed_according_to_physical_printers();
@ -7376,7 +7376,7 @@ void Plater::load_project(wxString const& filename2,
reset_project_dirty_initial_presets();
update_project_dirty_from_presets();
wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config);
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
// if res is empty no data has been loaded
if (!res.empty() && (load_restore || !(strategy & LoadStrategy::Silence))) {

View file

@ -697,7 +697,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset
//wxGetApp().get_tab(Preset::TYPE_PRINTER)->load_config(cfg_new);
cfg->apply(cfg_new);
wxGetApp().plater()->update_project_dirty_from_presets();
wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config);
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
update();
wxGetApp().plater()->on_config_change(cfg_new);
@ -1094,9 +1094,6 @@ void PlaterPresetComboBox::update()
}
update_selection();
if (selected_system_preset != GetValue()) {
sendComboBoxEvent();
}
Thaw();
if (!tooltip.IsEmpty()) {