diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index feeb1423cb..6d619ef167 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -236,7 +236,7 @@ void GCodeGenerator::PlaceholderParserIntegration::init(const GCodeWriter &write this->parser.set("zhop", this->opt_zhop); } -void GCodeGenerator::PlaceholderParserIntegration::update_from_gcodewriter(const GCodeWriter &writer) +void GCodeGenerator::PlaceholderParserIntegration::update_from_gcodewriter(const GCodeWriter &writer, const WipeTowerData& wipe_tower_data) { memcpy(this->position.data(), writer.get_position().data(), sizeof(double) * 3); this->opt_position->values = this->position; @@ -253,7 +253,19 @@ void GCodeGenerator::PlaceholderParserIntegration::update_from_gcodewriter(const for (const Extruder &e : extruders) { this->e_retracted[e.id()] = e.retracted(); this->e_restart_extra[e.id()] = e.restart_extra(); - double v = e.extruded_volume(); + + // Wipe tower filament consumption has to be added separately, because that gcode is not generated by GCodeWriter. + double wt_vol = 0.; + const std::vector>>& wtuf = wipe_tower_data.used_filament_until_layer; + if (!wtuf.empty()) { + auto it = std::lower_bound(wtuf.begin(), wtuf.end(), writer.get_position().z(), + [](const auto& a, const float& val) { return a.first < val; }); + if (it == wtuf.end()) + it = wtuf.end() - 1; + wt_vol = it->second[e.id()] * e.filament_crossection(); + } + + double v = e.extruded_volume() + wt_vol; double w = v * e.filament_density() * 0.001; this->opt_extruded_volume->values[e.id()] = v; this->opt_extruded_weight->values[e.id()] = w; @@ -1657,7 +1669,7 @@ std::string GCodeGenerator::placeholder_parser_process( PlaceholderParserIntegration &ppi = m_placeholder_parser_integration; try { - ppi.update_from_gcodewriter(m_writer); + ppi.update_from_gcodewriter(m_writer, m_print->wipe_tower_data()); std::string output = ppi.parser.process(templ, current_extruder_id, config_override, &ppi.output_config, &ppi.context); ppi.validate_output_vector_variables(); diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 4447bdff0f..4d18835332 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -53,6 +53,7 @@ namespace Slic3r { // Forward declarations. class GCodeGenerator; +struct WipeTowerData; namespace { struct Item; } struct PrintInstance; @@ -356,7 +357,7 @@ private: struct PlaceholderParserIntegration { void reset(); void init(const GCodeWriter &config); - void update_from_gcodewriter(const GCodeWriter &writer); + void update_from_gcodewriter(const GCodeWriter &writer, const WipeTowerData& wipe_tower_data); void validate_output_vector_variables(); PlaceholderParser parser;