Skip to content

Commit 9c07218

Browse files
committed
Reworked pressure equalizer and GCode processing pipeline to make pressure equalizer always returns one whole layer at once.
Now pressure equalizer is returning one layer back (the previous layer). GCode produced by pressure equalizer now has the same number of decimal places as non-processed GCode. Pressure equalizer was disabled for external perimeters and gap-fill.
1 parent a497769 commit 9c07218

File tree

4 files changed

+253
-252
lines changed

4 files changed

+253
-252
lines changed

src/libslic3r/GCode.cpp

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,11 +1529,18 @@ void GCode::process_layers(
15291529
{
15301530
// The pipeline is variable: The vase mode filter is optional.
15311531
size_t layer_to_print_idx = 0;
1532-
const auto generator = tbb::make_filter<void, GCode::LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1533-
[this, &print, &tool_ordering, &print_object_instances_ordering, &layers_to_print, &layer_to_print_idx](tbb::flow_control& fc) -> GCode::LayerResult {
1534-
if (layer_to_print_idx == layers_to_print.size()) {
1535-
fc.stop();
1536-
return {};
1532+
const auto generator = tbb::make_filter<void, LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1533+
[this, &print, &tool_ordering, &print_object_instances_ordering, &layers_to_print, &layer_to_print_idx](tbb::flow_control& fc) -> LayerResult {
1534+
if (layer_to_print_idx >= layers_to_print.size()) {
1535+
if ((!m_pressure_equalizer && layer_to_print_idx == layers_to_print.size()) || (m_pressure_equalizer && layer_to_print_idx == (layers_to_print.size() + 1))) {
1536+
fc.stop();
1537+
return {};
1538+
} else {
1539+
// Pressure equalizer need insert empty input. Because it returns one layer back.
1540+
// Insert NOP (no operation) layer;
1541+
++layer_to_print_idx;
1542+
return LayerResult::make_nop_layer_result();
1543+
}
15371544
} else {
15381545
const std::pair<coordf_t, std::vector<LayerToPrint>>& layer = layers_to_print[layer_to_print_idx++];
15391546
const LayerTools& layer_tools = tool_ordering.tools_for_layer(layer.first);
@@ -1543,17 +1550,23 @@ void GCode::process_layers(
15431550
return this->process_layer(print, layer.second, layer_tools, &layer == &layers_to_print.back(), &print_object_instances_ordering, size_t(-1));
15441551
}
15451552
});
1546-
const auto spiral_vase = tbb::make_filter<GCode::LayerResult, GCode::LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1547-
[&spiral_vase = *this->m_spiral_vase](GCode::LayerResult in) -> GCode::LayerResult {
1553+
const auto spiral_vase = tbb::make_filter<LayerResult, LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1554+
[&spiral_vase = *this->m_spiral_vase](LayerResult in) -> LayerResult {
1555+
if (in.nop_layer_result)
1556+
return in;
1557+
15481558
spiral_vase.enable(in.spiral_vase_enable);
1549-
return { spiral_vase.process_layer(std::move(in.gcode)), in.layer_id, in.spiral_vase_enable, in.cooling_buffer_flush, in.pressure_equalizer_buffer_flush };
1559+
return { spiral_vase.process_layer(std::move(in.gcode)), in.layer_id, in.spiral_vase_enable, in.cooling_buffer_flush};
15501560
});
1551-
const auto pressure_equalizer = tbb::make_filter<GCode::LayerResult, GCode::LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1552-
[&pressure_equalizer = *this->m_pressure_equalizer](GCode::LayerResult in) -> GCode::LayerResult {
1553-
return { std::string(pressure_equalizer.process_layer(std::move(in.gcode.c_str()), in.pressure_equalizer_buffer_flush)), in.layer_id, in.spiral_vase_enable, in.cooling_buffer_flush, in.pressure_equalizer_buffer_flush };
1561+
const auto pressure_equalizer = tbb::make_filter<LayerResult, LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1562+
[&pressure_equalizer = *this->m_pressure_equalizer](LayerResult in) -> LayerResult {
1563+
return pressure_equalizer.process_layer(std::move(in));
15541564
});
1555-
const auto cooling = tbb::make_filter<GCode::LayerResult, std::string>(slic3r_tbb_filtermode::serial_in_order,
1556-
[&cooling_buffer = *this->m_cooling_buffer](GCode::LayerResult in) -> std::string {
1565+
const auto cooling = tbb::make_filter<LayerResult, std::string>(slic3r_tbb_filtermode::serial_in_order,
1566+
[&cooling_buffer = *this->m_cooling_buffer](LayerResult in) -> std::string {
1567+
if (in.nop_layer_result)
1568+
return in.gcode;
1569+
15571570
return cooling_buffer.process_layer(std::move(in.gcode), in.layer_id, in.cooling_buffer_flush);
15581571
});
15591572
const auto find_replace = tbb::make_filter<std::string, std::string>(slic3r_tbb_filtermode::serial_in_order,
@@ -1601,28 +1614,39 @@ void GCode::process_layers(
16011614
{
16021615
// The pipeline is variable: The vase mode filter is optional.
16031616
size_t layer_to_print_idx = 0;
1604-
const auto generator = tbb::make_filter<void, GCode::LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1605-
[this, &print, &tool_ordering, &layers_to_print, &layer_to_print_idx, single_object_idx](tbb::flow_control& fc) -> GCode::LayerResult {
1606-
if (layer_to_print_idx == layers_to_print.size()) {
1607-
fc.stop();
1608-
return {};
1617+
const auto generator = tbb::make_filter<void, LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1618+
[this, &print, &tool_ordering, &layers_to_print, &layer_to_print_idx, single_object_idx](tbb::flow_control& fc) -> LayerResult {
1619+
if (layer_to_print_idx >= layers_to_print.size()) {
1620+
if ((!m_pressure_equalizer && layer_to_print_idx == layers_to_print.size()) || (m_pressure_equalizer && layer_to_print_idx == (layers_to_print.size() + 1))) {
1621+
fc.stop();
1622+
return {};
1623+
} else {
1624+
// Pressure equalizer need insert empty input. Because it returns one layer back.
1625+
// Insert NOP (no operation) layer;
1626+
++layer_to_print_idx;
1627+
return LayerResult::make_nop_layer_result();
1628+
}
16091629
} else {
16101630
LayerToPrint &layer = layers_to_print[layer_to_print_idx ++];
16111631
print.throw_if_canceled();
16121632
return this->process_layer(print, { std::move(layer) }, tool_ordering.tools_for_layer(layer.print_z()), &layer == &layers_to_print.back(), nullptr, single_object_idx);
16131633
}
16141634
});
1615-
const auto spiral_vase = tbb::make_filter<GCode::LayerResult, GCode::LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1616-
[&spiral_vase = *this->m_spiral_vase](GCode::LayerResult in)->GCode::LayerResult {
1635+
const auto spiral_vase = tbb::make_filter<LayerResult, LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1636+
[&spiral_vase = *this->m_spiral_vase](LayerResult in)->LayerResult {
1637+
if (in.nop_layer_result)
1638+
return in;
16171639
spiral_vase.enable(in.spiral_vase_enable);
1618-
return { spiral_vase.process_layer(std::move(in.gcode)), in.layer_id, in.spiral_vase_enable, in.cooling_buffer_flush, in.pressure_equalizer_buffer_flush };
1640+
return { spiral_vase.process_layer(std::move(in.gcode)), in.layer_id, in.spiral_vase_enable, in.cooling_buffer_flush };
16191641
});
1620-
const auto pressure_equalizer = tbb::make_filter<GCode::LayerResult, GCode::LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1621-
[&pressure_equalizer = *this->m_pressure_equalizer](GCode::LayerResult in) -> GCode::LayerResult {
1622-
return { std::string(pressure_equalizer.process_layer(std::move(in.gcode.c_str()), in.pressure_equalizer_buffer_flush)), in.layer_id, in.spiral_vase_enable, in.cooling_buffer_flush, in.pressure_equalizer_buffer_flush };
1642+
const auto pressure_equalizer = tbb::make_filter<LayerResult, LayerResult>(slic3r_tbb_filtermode::serial_in_order,
1643+
[&pressure_equalizer = *this->m_pressure_equalizer](LayerResult in) -> LayerResult {
1644+
return pressure_equalizer.process_layer(std::move(in));
16231645
});
1624-
const auto cooling = tbb::make_filter<GCode::LayerResult, std::string>(slic3r_tbb_filtermode::serial_in_order,
1625-
[&cooling_buffer = *this->m_cooling_buffer](GCode::LayerResult in)->std::string {
1646+
const auto cooling = tbb::make_filter<LayerResult, std::string>(slic3r_tbb_filtermode::serial_in_order,
1647+
[&cooling_buffer = *this->m_cooling_buffer](LayerResult in)->std::string {
1648+
if (in.nop_layer_result)
1649+
return in.gcode;
16261650
return cooling_buffer.process_layer(std::move(in.gcode), in.layer_id, in.cooling_buffer_flush);
16271651
});
16281652
const auto find_replace = tbb::make_filter<std::string, std::string>(slic3r_tbb_filtermode::serial_in_order,
@@ -2079,7 +2103,7 @@ namespace Skirt {
20792103
// In non-sequential mode, process_layer is called per each print_z height with all object and support layers accumulated.
20802104
// For multi-material prints, this routine minimizes extruder switches by gathering extruder specific extrusion paths
20812105
// and performing the extruder specific extrusions together.
2082-
GCode::LayerResult GCode::process_layer(
2106+
LayerResult GCode::process_layer(
20832107
const Print &print,
20842108
// Set of object & print layers of the same PrintObject and with the same print_z.
20852109
const std::vector<LayerToPrint> &layers,
@@ -2110,7 +2134,7 @@ GCode::LayerResult GCode::process_layer(
21102134
}
21112135
}
21122136
const Layer &layer = (object_layer != nullptr) ? *object_layer : *support_layer;
2113-
GCode::LayerResult result { {}, layer.id(), false, last_layer, last_layer};
2137+
LayerResult result { {}, layer.id(), false, last_layer, false};
21142138
if (layer_tools.extruders.empty())
21152139
// Nothing to extrude.
21162140
return result;

src/libslic3r/GCode.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ class ColorPrintColors
114114
static const std::vector<std::string>& get() { return Colors; }
115115
};
116116

117+
struct LayerResult {
118+
std::string gcode;
119+
size_t layer_id;
120+
// Is spiral vase post processing enabled for this layer?
121+
bool spiral_vase_enable { false };
122+
// Should the cooling buffer content be flushed at the end of this layer?
123+
bool cooling_buffer_flush { false };
124+
// Is indicating if this LayerResult should be processed, or it is just inserted artificial LayerResult.
125+
// It is used for the pressure equalizer because it needs to buffer one layer back.
126+
bool nop_layer_result { false };
127+
128+
static LayerResult make_nop_layer_result() { return {"", std::numeric_limits<coord_t>::max(), false, false, true}; }
129+
};
130+
117131
class GCode {
118132
public:
119133
GCode() :
@@ -226,16 +240,6 @@ class GCode {
226240
static std::vector<LayerToPrint> collect_layers_to_print(const PrintObject &object);
227241
static std::vector<std::pair<coordf_t, std::vector<LayerToPrint>>> collect_layers_to_print(const Print &print);
228242

229-
struct LayerResult {
230-
std::string gcode;
231-
size_t layer_id;
232-
// Is spiral vase post processing enabled for this layer?
233-
bool spiral_vase_enable { false };
234-
// Should the cooling buffer content be flushed at the end of this layer?
235-
bool cooling_buffer_flush { false };
236-
// Should the PressureEqualizer buffer content be flushed at the end of this layer?
237-
bool pressure_equalizer_buffer_flush { false };
238-
};
239243
LayerResult process_layer(
240244
const Print &print,
241245
// Set of object & print layers of the same PrintObject and with the same print_z.
@@ -446,6 +450,7 @@ class GCode {
446450

447451
friend class Wipe;
448452
friend class WipeTowerIntegration;
453+
friend class PressureEqualizer;
449454
};
450455

451456
std::vector<const PrintInstance*> sort_object_instances_by_model_order(const Print& print);

0 commit comments

Comments
 (0)