Fix a crash on printer presets switching between MM and SM printers:
1. DoubleSlider::Control : Update extruder colors before another updates for layers slider 2. GCodeViewer : Control count of extruders during the legend updating
This commit is contained in:
parent
f11e81517d
commit
204714d566
@ -4086,6 +4086,8 @@ void GCodeViewer::render_legend() const
|
||||
std::vector<std::pair<Color, std::pair<double, double>>> cp_values = color_print_ranges(i, custom_gcode_per_print_z);
|
||||
const int items_cnt = static_cast<int>(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 {
|
||||
@ -4146,6 +4148,11 @@ 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)
|
||||
@ -4153,7 +4160,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, last_color[it->extruder - 1], Color(), time_rec.second });
|
||||
items.push_back({ PartialTime::EType::Print, it->extruder, get_last_color(it->extruder), Color(), time_rec.second });
|
||||
items.push_back({ PartialTime::EType::Pause, it->extruder, Color(), Color(), time_rec.second });
|
||||
custom_gcode_per_print_z.erase(it);
|
||||
}
|
||||
@ -4162,14 +4169,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, 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 });
|
||||
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 });
|
||||
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, last_color[last_extruder_id - 1], Color(), time_rec.second });
|
||||
items.push_back({ PartialTime::EType::Print, last_extruder_id, get_last_color(last_extruder_id), Color(), time_rec.second });
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -605,6 +605,9 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
|
||||
CustomGCode::Info& ticks_info_from_model = plater->model().custom_gcode_per_print_z;
|
||||
check_layers_slider_values(ticks_info_from_model.gcodes, layers_z);
|
||||
|
||||
//first of all update extruder colors to avoid crash, when we are switching printer preset from MM to SM
|
||||
m_layers_slider->SetExtruderColors(plater->get_extruder_colors_from_plater_config());
|
||||
|
||||
m_layers_slider->SetSliderValues(layers_z);
|
||||
assert(m_layers_slider->GetMinValue() == 0);
|
||||
m_layers_slider->SetMaxValue(layers_z.empty() ? 0 : layers_z.size() - 1);
|
||||
@ -629,7 +632,6 @@ void Preview::update_layers_slider(const std::vector<double>& layers_z, bool kee
|
||||
bool sla_print_technology = plater->printer_technology() == ptSLA;
|
||||
bool sequential_print = wxGetApp().preset_bundle->prints.get_edited_preset().config.opt_bool("complete_objects");
|
||||
m_layers_slider->SetDrawMode(sla_print_technology, sequential_print);
|
||||
m_layers_slider->SetExtruderColors(plater->get_extruder_colors_from_plater_config());
|
||||
if (sla_print_technology)
|
||||
m_layers_slider->SetLayersTimes(plater->sla_print().print_statistics().layers_times);
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user