Fixed black rects for extruder colors, when we load 3mf project with MM-printer profile and extruder colors is set to the filament colors

+ Fixed a bug with updating colors in extruder editors in ObjectList, when we use filaments colors for extruders and some filament profile is switched
This commit is contained in:
YuSanka 2021-01-07 08:52:45 +01:00
parent c3f88db392
commit 3070e66aae
2 changed files with 26 additions and 16 deletions

View File

@ -2384,6 +2384,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
CustomGCode::update_custom_gcode_per_print_z_from_config(model.custom_gcode_per_print_z, &wxGetApp().preset_bundle->project_config); CustomGCode::update_custom_gcode_per_print_z_from_config(model.custom_gcode_per_print_z, &wxGetApp().preset_bundle->project_config);
// For exporting from the amf/3mf we shouldn't check printer_presets for the containing information about "Print Host upload" // For exporting from the amf/3mf we shouldn't check printer_presets for the containing information about "Print Host upload"
wxGetApp().load_current_presets(false); wxGetApp().load_current_presets(false);
// Update filament colors for the MM-printer profile in the full config
// to avoid black (default) colors for Extruders in the ObjectList,
// when for extruder colors are used filament colors
q->update_filament_colors_in_full_config();
is_project_file = true; is_project_file = true;
} }
wxGetApp().app_config->update_config_dir(path.parent_path().string()); wxGetApp().app_config->update_config_dir(path.parent_path().string());
@ -5786,6 +5790,26 @@ void Plater::on_extruders_change(size_t num_extruders)
sidebar().scrolled_panel()->Refresh(); sidebar().scrolled_panel()->Refresh();
} }
bool Plater::update_filament_colors_in_full_config()
{
// There is a case, when we use filament_color instead of extruder_color (when extruder_color == "").
// Thus plater config option "filament_colour" should be filled with filament_presets values.
// Otherwise, on 3dScene will be used last edited filament color for all volumes with extruder_color == "".
const std::vector<std::string> filament_presets = wxGetApp().preset_bundle->filament_presets;
if (filament_presets.size() == 1 || !p->config->has("filament_colour"))
return false;
const PresetCollection& filaments = wxGetApp().preset_bundle->filaments;
std::vector<std::string> filament_colors;
filament_colors.reserve(filament_presets.size());
for (const std::string& filament_preset : filament_presets)
filament_colors.push_back(filaments.find_preset(filament_preset, true)->config.opt_string("filament_colour", (unsigned)0));
p->config->option<ConfigOptionStrings>("filament_colour")->values = filament_colors;
return true;
}
void Plater::on_config_change(const DynamicPrintConfig &config) void Plater::on_config_change(const DynamicPrintConfig &config)
{ {
bool update_scheduled = false; bool update_scheduled = false;
@ -5795,22 +5819,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
{ {
update_scheduled = true; // update should be scheduled (for update 3DScene) #2738 update_scheduled = true; // update should be scheduled (for update 3DScene) #2738
/* There is a case, when we use filament_color instead of extruder_color (when extruder_color == ""). if (update_filament_colors_in_full_config()) {
* Thus plater config option "filament_colour" should be filled with filament_presets values.
* Otherwise, on 3dScene will be used last edited filament color for all volumes with extruder_color == "".
*/
const std::vector<std::string> filament_presets = wxGetApp().preset_bundle->filament_presets;
if (filament_presets.size() > 1 &&
p->config->option<ConfigOptionStrings>(opt_key)->values.size() != config.option<ConfigOptionStrings>(opt_key)->values.size())
{
const PresetCollection& filaments = wxGetApp().preset_bundle->filaments;
std::vector<std::string> filament_colors;
filament_colors.reserve(filament_presets.size());
for (const std::string& filament_preset : filament_presets)
filament_colors.push_back(filaments.find_preset(filament_preset, true)->config.opt_string("filament_colour", (unsigned)0));
p->config->option<ConfigOptionStrings>(opt_key)->values = filament_colors;
p->sidebar->obj_list()->update_extruder_colors(); p->sidebar->obj_list()->update_extruder_colors();
continue; continue;
} }

View File

@ -233,6 +233,7 @@ public:
void leave_gizmos_stack(); void leave_gizmos_stack();
void on_extruders_change(size_t extruders_count); void on_extruders_change(size_t extruders_count);
bool update_filament_colors_in_full_config();
void on_config_change(const DynamicPrintConfig &config); void on_config_change(const DynamicPrintConfig &config);
void force_filament_colors_update(); void force_filament_colors_update();
void force_print_bed_update(); void force_print_bed_update();