From e1c201e7147e944f408e659ea0d8de120ceca1bf Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 23 Feb 2021 12:00:23 +0100 Subject: [PATCH] Partial revert of 204714d56647aadb6f5f694a057b131fd4e936ce -> Alternate fix for crash on printer presets switching between MM and SM printers --- src/slic3r/GUI/GCodeViewer.cpp | 20 +++++++------------- src/slic3r/GUI/Plater.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index b1ac57d53..71441e037 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -1458,6 +1458,8 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) if (m_moves_count == 0) return; + m_extruders_count = gcode_result.extruders_count; + unsigned int progress_count = 0; static const unsigned int progress_threshold = 1000; wxProgressDialog* progress_dialog = wxGetApp().is_gcode_viewer() ? @@ -4079,15 +4081,12 @@ void GCodeViewer::render_legend() const } } } - else // multi extruder use case - { + else { // multi extruder use case // shows only extruders actually used for (unsigned char i : m_extruder_ids) { std::vector>> cp_values = color_print_ranges(i, custom_gcode_per_print_z); const int items_cnt = static_cast(cp_values.size()); if (items_cnt == 0) { // There are no color changes, but there are some pause print or custom Gcode - if (i >= m_tool_colors.size()) - break; append_item(EItemType::Rect, m_tool_colors[i], _u8L("Extruder") + " " + std::to_string(i + 1) + " " + _u8L("default color")); } else { @@ -4148,11 +4147,6 @@ void GCodeViewer::render_legend() const for (int i = 0; i < extruders_count; ++i) { last_color[i] = m_tool_colors[i]; } - auto get_last_color = [last_color](int extruder_id) { - if (extruder_id >= (int)last_color.size()) - return last_color[0]; - return last_color[extruder_id - 1]; - }; int last_extruder_id = 1; for (const auto& time_rec : times) { switch (time_rec.first) @@ -4160,7 +4154,7 @@ void GCodeViewer::render_legend() const case CustomGCode::PausePrint: { auto it = std::find_if(custom_gcode_per_print_z.begin(), custom_gcode_per_print_z.end(), [time_rec](const CustomGCode::Item& item) { return item.type == time_rec.first; }); if (it != custom_gcode_per_print_z.end()) { - items.push_back({ PartialTime::EType::Print, it->extruder, get_last_color(it->extruder), Color(), time_rec.second }); + items.push_back({ PartialTime::EType::Print, it->extruder, last_color[it->extruder - 1], Color(), time_rec.second }); items.push_back({ PartialTime::EType::Pause, it->extruder, Color(), Color(), time_rec.second }); custom_gcode_per_print_z.erase(it); } @@ -4169,14 +4163,14 @@ void GCodeViewer::render_legend() const case CustomGCode::ColorChange: { auto it = std::find_if(custom_gcode_per_print_z.begin(), custom_gcode_per_print_z.end(), [time_rec](const CustomGCode::Item& item) { return item.type == time_rec.first; }); if (it != custom_gcode_per_print_z.end()) { - items.push_back({ PartialTime::EType::Print, it->extruder, get_last_color(it->extruder), Color(), time_rec.second }); - items.push_back({ PartialTime::EType::ColorChange, it->extruder, get_last_color(it->extruder), decode_color(it->color), time_rec.second }); + items.push_back({ PartialTime::EType::Print, it->extruder, last_color[it->extruder - 1], Color(), time_rec.second }); + items.push_back({ PartialTime::EType::ColorChange, it->extruder, last_color[it->extruder - 1], decode_color(it->color), time_rec.second }); last_color[it->extruder - 1] = decode_color(it->color); last_extruder_id = it->extruder; custom_gcode_per_print_z.erase(it); } else - items.push_back({ PartialTime::EType::Print, last_extruder_id, get_last_color(last_extruder_id), Color(), time_rec.second }); + items.push_back({ PartialTime::EType::Print, last_extruder_id, last_color[last_extruder_id - 1], Color(), time_rec.second }); break; } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index e8cd605cf..6400bbbcc 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5653,8 +5653,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config) bool update_scheduled = false; bool bed_shape_changed = false; for (auto opt_key : p->config->diff(config)) { - if (opt_key == "filament_colour") - { + if (opt_key == "filament_colour") { update_scheduled = true; // update should be scheduled (for update 3DScene) #2738 if (update_filament_colors_in_full_config()) { @@ -5689,10 +5688,11 @@ void Plater::on_config_change(const DynamicPrintConfig &config) else if(opt_key == "extruder_colour") { update_scheduled = true; p->sidebar->obj_list()->update_extruder_colors(); - } else if(opt_key == "max_print_height") { - update_scheduled = true; } + else if(opt_key == "max_print_height") + update_scheduled = true; else if (opt_key == "printer_model") { + p->reset_gcode_toolpaths(); // update to force bed selection(for texturing) bed_shape_changed = true; update_scheduled = true;