From 7f8f11908164c952470e8cddaadbeedbc98e5f89 Mon Sep 17 00:00:00 2001 From: supermerill Date: Thu, 16 May 2024 13:07:34 +0200 Subject: [PATCH] Fix mmu filament stat supermerill/SuperSlicer#4262 --- src/libslic3r/GCode.cpp | 4 +-- src/libslic3r/Print.hpp | 4 +-- src/slic3r/GUI/Plater.cpp | 72 ++++++++++++++++++++++----------------- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 1b4810d5e96..995522a91d9 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -764,9 +764,9 @@ namespace DoExport { if (extruder == extruders.end()) continue; - double s = PI * sqr(0.5* extruder->filament_diameter()); + double section = PI * sqr(0.5 * extruder->filament_diameter()); double weight = volume.second * extruder->filament_density() * 0.001; - total_used_filament += volume.second/s; + total_used_filament += volume.second / section; total_weight += weight; total_cost += weight * extruder->filament_cost() * 0.001; } diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 96a3804ff5e..014da64ea59 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -485,7 +485,7 @@ struct PrintStatistics std::string estimated_normal_print_time; std::string estimated_silent_print_time; double total_used_filament; - std::vector> color_extruderid_to_used_filament; + std::vector> color_extruderid_to_used_filament; // id -> mm (length) double total_extruded_volume; double total_cost; int total_toolchanges; @@ -497,7 +497,7 @@ struct PrintStatistics unsigned int initial_extruder_id; std::string initial_filament_type; std::string printing_filament_types; - std::map filament_stats; + std::map filament_stats; // extruder id -> volume in mm3 // Config with the filled in print statistics. DynamicConfig config() const; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ee30a76694a..d244e1e72db 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1340,28 +1340,36 @@ void Sidebar::update_sliced_info_sizer() //if multiple filament/extruderss, then print them all if (ps.filament_stats.size() > 1 || ps.color_extruderid_to_used_filament.size() > 0) { new_label += ":"; + const std::vector& filament_presets = wxGetApp().preset_bundle->filament_presets; + const PresetCollection& filaments = wxGetApp().preset_bundle->filaments; //for each extruder - for (auto filament : ps.filament_stats) { + for (auto [filament_id, filament_volume] : ps.filament_stats) { int items_printed = 0; double total_length = 0; - // print each color change for this extruder - for (auto entry : ps.color_extruderid_to_used_filament) { - if (filament.first == entry.first) { - items_printed++; - new_label += "\n - " + format_wxstr(_L("Color %1% at extruder %2%"), items_printed , (filament.first + 1)); - total_length += entry.second; - info_text += wxString::Format("\n%.2f (%.2f)", entry.second / 1000, total_length / 1000); + const Preset* filament_preset = filaments.find_preset(filament_presets[filament_id], false); + if (filament_preset) { + double crosssection = 0.5 * filament_preset->config.opt_float("filament_diameter", filament_id); + crosssection *= crosssection * PI; + double mm3_to_m = 0.001 / crosssection; + // print each color change for this extruder + for (auto entry : ps.color_extruderid_to_used_filament) { + if (filament_id == entry.first) { + items_printed++; + new_label += "\n - " + format_wxstr(_L("Color %1% at extruder %2%"), items_printed , (filament_id + 1)); + total_length += entry.second; + info_text += wxString::Format("\n%.2f (%.2f)", entry.second / 1000, total_length / 1000); + } + } + //print total for this extruder + if (items_printed == 0) { + new_label += "\n - " + format_wxstr(_L("Filament at extruder %1%"), filament_id + 1); + //new_label += from_u8((boost::format("\n - %1% %2%") % _utf8(L("Color")) % ps.color_extruderid_to_used_filament.size()).str()); + info_text += wxString::Format("\n%.2f", filament_volume * mm3_to_m); + } + else { + new_label += "\n - " + format_wxstr(_L("Color %1% at extruder %2%"), (items_printed+1), (filament_id + 1)); + info_text += wxString::Format("\n%.2f (%.2f)", (filament_volume - total_length) * mm3_to_m, filament_volume * mm3_to_m); } - } - //print total for this extruder - if (items_printed == 0) { - new_label += "\n - " + format_wxstr(_L("Filament at extruder %1%"), filament.first + 1); - //new_label += from_u8((boost::format("\n - %1% %2%") % _utf8(L("Color")) % ps.color_extruderid_to_used_filament.size()).str()); - info_text += wxString::Format("\n%.2f", filament.second / 1000); - } - else { - new_label += "\n - " + format_wxstr(_L("Color %1% at extruder %2%"), (items_printed+1), (filament.first + 1)); - info_text += wxString::Format("\n%.2f (%.2f)", (filament.second - total_length) / 1000, filament.second / 1000); } } } @@ -1386,15 +1394,15 @@ void Sidebar::update_sliced_info_sizer() bool has_spool = false; new_label += ":"; //for each extruder - for (auto filament : ps.filament_stats) { - const Preset* filament_preset = filaments.find_preset(filament_presets[filament.first], false); + for (auto [filament_id, filament_volume] : ps.filament_stats) { + const Preset* filament_preset = filaments.find_preset(filament_presets[filament_id], false); if (filament_preset) { double spool_weight = filament_preset->config.opt_float("filament_spool_weight", 0); - double filament_density = filament_preset->config.opt_float("filament_density", filament.first); - double crosssection = filament_preset->config.opt_float("filament_diameter", filament.first); - crosssection *= crosssection; - crosssection *= 0.25 * PI; + double filament_density = filament_preset->config.opt_float("filament_density", filament_id); + double crosssection = 0.5 * filament_preset->config.opt_float("filament_diameter", filament_id); + crosssection *= crosssection * PI; double m_to_g = filament_density / (crosssection * 1000); + double mm3_to_g = filament_density *0.001; int items_printed = 0; double total_length = 0; //for (int i = 0; i < ps.color_extruderid_to_used_filament.size(); i++) { @@ -1406,9 +1414,9 @@ void Sidebar::update_sliced_info_sizer() if (spool_weight != 0.0) has_spool = true; for (auto entry : ps.color_extruderid_to_used_filament) { - if (filament.first == entry.first) { + if (filament_id == entry.first) { items_printed++; - new_label += "\n - " + format_wxstr(_L("Color %1% at extruder %2%"), items_printed, (filament.first + 1)); + new_label += "\n - " + format_wxstr(_L("Color %1% at extruder %2%"), items_printed, (filament_id + 1)); total_length += entry.second; info_text += wxString::Format("\n%.2f", entry.second * m_to_g); if (spool_weight != 0.0) @@ -1417,16 +1425,16 @@ void Sidebar::update_sliced_info_sizer() } //print total for this extruder if (items_printed == 0) { - new_label += "\n - " + format_wxstr(_L("Filament at extruder %1%"), filament.first + 1); + new_label += "\n - " + format_wxstr(_L("Filament at extruder %1%"), filament_id + 1); //new_label += from_u8((boost::format("\n - %1% %2%") % _utf8(L("Color")) % ps.color_extruderid_to_used_filament.size()).str()); - info_text += wxString::Format("\n%.2f", filament.second * m_to_g); + info_text += wxString::Format("\n%.2f", filament_volume * mm3_to_g); if (spool_weight != 0.0) - info_text += wxString::Format(" (%.2f)", filament.second * m_to_g + spool_weight); + info_text += wxString::Format(" (%.2f)", filament_volume * mm3_to_g + spool_weight); } else { - new_label += "\n - " + format_wxstr(_L("Color %1% at extruder %2%"), (items_printed + 1), (filament.first + 1)); - info_text += wxString::Format("\n%.2f", (filament.second - total_length) * m_to_g); + new_label += "\n - " + format_wxstr(_L("Color %1% at extruder %2%"), (items_printed + 1), (filament_id + 1)); + info_text += wxString::Format("\n%.2f", (filament_volume - total_length) * mm3_to_g); if (spool_weight != 0.0) - info_text += wxString::Format(" (%.2f)", (filament.second - total_length) * m_to_g + spool_weight); + info_text += wxString::Format(" (%.2f)", (filament_volume - total_length) * mm3_to_g + spool_weight); } } }