From 74702b2c6ce4349786fa5b55a6da35ba9873b4a3 Mon Sep 17 00:00:00 2001 From: XunZhangBambu Date: Tue, 19 Mar 2024 16:33:37 +0800 Subject: [PATCH] ENH: seperate support weight from model jira:NEW Signed-off-by: XunZhangBambu Change-Id: I86bb34941269bf1aa29436a94ebbdff675497e85 --- src/libslic3r/GCode.cpp | 15 +++++++++++++++ src/libslic3r/GCode/GCodeProcessor.cpp | 15 +++++++++++++-- src/libslic3r/GCode/GCodeProcessor.hpp | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 5fda1f34d..ae9397e41 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1021,6 +1021,21 @@ namespace DoExport { total_cost += weight * extruder->filament_cost() * 0.001; } + for (auto volume : result.print_statistics.support_volumes_per_extruder) { + total_extruded_volume += volume.second; + + size_t extruder_id = volume.first; + auto extruder = std::find_if(extruders.begin(), extruders.end(), [extruder_id](const Extruder& extr) {return extr.id() == extruder_id; }); + if (extruder == extruders.end()) + continue; + + double s = PI * sqr(0.5* extruder->filament_diameter()); + double weight = volume.second * extruder->filament_density() * 0.001; + total_used_filament += volume.second/s; + total_weight += weight; + total_cost += weight * extruder->filament_cost() * 0.001; + } + print_statistics.total_extruded_volume = total_extruded_volume; print_statistics.total_used_filament = total_used_filament; print_statistics.total_weight = total_weight; diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 39bf12cc0..931ca5b14 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -718,6 +718,9 @@ void GCodeProcessor::UsedFilaments::reset() wipe_tower_cache = 0.0f; wipe_tower_volume_per_extruder.clear(); + + support_volume_cache = 0.0f; + support_volume_per_extruder.clear(); } void GCodeProcessor::UsedFilaments::increase_model_caches(double extruded_volume) @@ -799,6 +802,7 @@ void GCodeProcessor::UsedFilaments::process_caches(GCodeProcessor* processor) process_model_cache(processor); process_role_cache(processor); process_wipe_tower_cache(processor); + process_support_cache(processor); } #if ENABLE_GCODE_VIEWER_STATISTICS @@ -2801,7 +2805,10 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) float delta_xyz = std::sqrt(sqr(delta_pos[X]) + sqr(delta_pos[Y]) + sqr(delta_pos[Z])); float volume_extruded_filament = area_filament_cross_section * delta_pos[E]; float area_toolpath_cross_section = volume_extruded_filament / delta_xyz; - if (m_wipe_tower) { + + if(m_extrusion_role == ExtrusionRole::erSupportMaterial || m_extrusion_role == ExtrusionRole::erSupportMaterialInterface || m_extrusion_role ==ExtrusionRole::erSupportTransition) + m_used_filaments.increase_support_caches(volume_extruded_filament); + else if (m_extrusion_role==ExtrusionRole::erWipeTower) { m_used_filaments.increase_wipe_tower_caches(volume_extruded_filament); } else { @@ -3270,7 +3277,10 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line) if (type == EMoveType::Extrude) { float volume_extruded_filament = area_filament_cross_section * delta_pos[E]; float area_toolpath_cross_section = volume_extruded_filament / delta_xyz; - if (m_wipe_tower) { + + if(m_extrusion_role == ExtrusionRole::erSupportMaterial || m_extrusion_role == ExtrusionRole::erSupportMaterialInterface || m_extrusion_role ==ExtrusionRole::erSupportTransition) + m_used_filaments.increase_support_caches(volume_extruded_filament); + else if (m_extrusion_role == ExtrusionRole::erWipeTower) { //BBS: save wipe tower volume to the cache m_used_filaments.increase_wipe_tower_caches(volume_extruded_filament); } @@ -4367,6 +4377,7 @@ void GCodeProcessor::update_estimated_times_stats() m_result.print_statistics.volumes_per_color_change = m_used_filaments.volumes_per_color_change; m_result.print_statistics.volumes_per_extruder = m_used_filaments.volumes_per_extruder; m_result.print_statistics.wipe_tower_volumes_per_extruder = m_used_filaments.wipe_tower_volume_per_extruder; + m_result.print_statistics.support_volumes_per_extruder = m_used_filaments.support_volume_per_extruder; m_result.print_statistics.flush_per_filament = m_used_filaments.flush_per_filament; m_result.print_statistics.used_filaments_per_role = m_used_filaments.filaments_per_role; } diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index ade7bc359..9a339244f 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -75,6 +75,7 @@ namespace Slic3r { std::vector volumes_per_color_change; std::map volumes_per_extruder; std::map wipe_tower_volumes_per_extruder; + std::map support_volumes_per_extruder; //BBS: the flush amount of every filament std::map flush_per_filament; std::map> used_filaments_per_role; @@ -499,6 +500,9 @@ namespace Slic3r { double wipe_tower_cache; std::mapwipe_tower_volume_per_extruder; + double support_volume_cache; + std::mapsupport_volume_per_extruder; + //BBS: the flush amount of every filament std::map flush_per_filament; @@ -507,12 +511,28 @@ namespace Slic3r { void reset(); + void increase_support_caches(double extruded_volume){ + support_volume_cache += extruded_volume; + role_cache += extruded_volume; + } + void increase_model_caches(double extruded_volume); void increase_wipe_tower_caches(double extruded_volume); void process_color_change_cache(); void process_model_cache(GCodeProcessor* processor); void process_wipe_tower_cache(GCodeProcessor* processor); + void process_support_cache(GCodeProcessor* processor){ + size_t active_extruder_id = processor->m_extruder_id; + if (support_volume_cache != 0.0f) { + if (support_volume_per_extruder.find(active_extruder_id) != support_volume_per_extruder.end()) + support_volume_per_extruder[active_extruder_id] += support_volume_cache; + else + support_volume_per_extruder[active_extruder_id] = support_volume_cache; + support_volume_cache = 0.0f; + } + } + void update_flush_per_filament(size_t extrude_id, float flush_length); void process_role_cache(GCodeProcessor* processor); void process_caches(GCodeProcessor* processor);