FIX: add to incorrect layer when adding pause
1. Caused by floating-point precision. github:#1937,#4250 Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: If7a5dc71a898c1208289b6b89eafef9d4126f17c
This commit is contained in:
parent
8a279ef302
commit
e3c8496a62
|
@ -977,41 +977,40 @@ void ToolOrdering::assign_custom_gcodes(const Print &print)
|
||||||
// If printing on a single extruder machine, make the tool changes trigger color change (M600) events.
|
// If printing on a single extruder machine, make the tool changes trigger color change (M600) events.
|
||||||
bool tool_changes_as_color_changes = mode == CustomGCode::SingleExtruder && model_mode == CustomGCode::MultiAsSingle;
|
bool tool_changes_as_color_changes = mode == CustomGCode::SingleExtruder && model_mode == CustomGCode::MultiAsSingle;
|
||||||
|
|
||||||
// From the last layer to the first one:
|
// take the half of the minimum layer height gap as episilon
|
||||||
for (auto it_lt = m_layer_tools.rbegin(); it_lt != m_layer_tools.rend(); ++ it_lt) {
|
double layer_height_episilon = std::numeric_limits<double>::max();
|
||||||
LayerTools < = *it_lt;
|
for (auto it_prev = m_layer_tools.begin(), it_next = std::next(m_layer_tools.begin()); it_next != m_layer_tools.end(); it_prev = it_next, ++it_next)
|
||||||
// Add the extruders of the current layer to the set of extruders printing at and above this print_z.
|
layer_height_episilon = std::min(layer_height_episilon, it_next->print_z - it_prev->print_z);
|
||||||
for (unsigned int i : lt.extruders)
|
layer_height_episilon *= 0.5;
|
||||||
extruder_printing_above[i] = true;
|
|
||||||
// Skip all custom G-codes above this layer and skip all extruder switches.
|
auto it_lt = m_layer_tools.rbegin();
|
||||||
for (; custom_gcode_it != custom_gcode_per_print_z.gcodes.rend() && (custom_gcode_it->print_z > lt.print_z + EPSILON || custom_gcode_it->type == CustomGCode::ToolChange); ++ custom_gcode_it);
|
for (auto custom_gcode_it = custom_gcode_per_print_z.gcodes.rbegin(); custom_gcode_it != custom_gcode_per_print_z.gcodes.rend(); ++custom_gcode_it) {
|
||||||
if (custom_gcode_it == custom_gcode_per_print_z.gcodes.rend())
|
if (custom_gcode_it->type == CustomGCode::ToolChange)
|
||||||
// Custom G-codes were processed.
|
continue;
|
||||||
break;
|
for (; it_lt != m_layer_tools.rend(); ++it_lt) {
|
||||||
// Some custom G-code is configured for this layer or a layer below.
|
for (unsigned int i : it_lt->extruders)
|
||||||
const CustomGCode::Item &custom_gcode = *custom_gcode_it;
|
extruder_printing_above[i] = true;
|
||||||
// print_z of the layer below the current layer.
|
if (std::abs(it_lt->print_z - custom_gcode_it->print_z) < layer_height_episilon) {
|
||||||
coordf_t print_z_below = 0.;
|
const CustomGCode::Item &custom_gcode = *custom_gcode_it;
|
||||||
if (auto it_lt_below = it_lt; ++ it_lt_below != m_layer_tools.rend())
|
// The custom G-code applies to the current layer.
|
||||||
print_z_below = it_lt_below->print_z;
|
bool color_change = custom_gcode.type == CustomGCode::ColorChange;
|
||||||
if (custom_gcode.print_z > print_z_below + 0.5 * EPSILON) {
|
bool tool_change = custom_gcode.type == CustomGCode::ToolChange;
|
||||||
// The custom G-code applies to the current layer.
|
bool pause_or_custom_gcode = ! color_change && ! tool_change;
|
||||||
bool color_change = custom_gcode.type == CustomGCode::ColorChange;
|
bool apply_color_change = ! ignore_tool_and_color_changes &&
|
||||||
bool tool_change = custom_gcode.type == CustomGCode::ToolChange;
|
// If it is color change, it will actually be useful as the exturder above will print.
|
||||||
bool pause_or_custom_gcode = ! color_change && ! tool_change;
|
// BBS
|
||||||
bool apply_color_change = ! ignore_tool_and_color_changes &&
|
(color_change ?
|
||||||
// If it is color change, it will actually be useful as the exturder above will print.
|
mode == CustomGCode::SingleExtruder ||
|
||||||
// BBS
|
(custom_gcode.extruder <= int(num_filaments) && extruder_printing_above[unsigned(custom_gcode.extruder - 1)]) :
|
||||||
(color_change ?
|
tool_change && tool_changes_as_color_changes);
|
||||||
mode == CustomGCode::SingleExtruder ||
|
if (pause_or_custom_gcode || apply_color_change)
|
||||||
(custom_gcode.extruder <= int(num_filaments) && extruder_printing_above[unsigned(custom_gcode.extruder - 1)]) :
|
it_lt->custom_gcode = &custom_gcode;
|
||||||
tool_change && tool_changes_as_color_changes);
|
|
||||||
if (pause_or_custom_gcode || apply_color_change)
|
++it_lt;
|
||||||
lt.custom_gcode = &custom_gcode;
|
break;
|
||||||
// Consume that custom G-code event.
|
}
|
||||||
++ custom_gcode_it;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const LayerTools& ToolOrdering::tools_for_layer(coordf_t print_z) const
|
const LayerTools& ToolOrdering::tools_for_layer(coordf_t print_z) const
|
||||||
|
|
Loading…
Reference in New Issue