diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index a12237d7c3..33621f5b0b 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -94,6 +94,7 @@ #include #include #include +#include #include #include #include @@ -3713,6 +3714,20 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato this->placeholder_parser().set("first_filaments", new ConfigOptionInts(first_filaments)); this->placeholder_parser().set("initial_tool", initial_extruder_id); this->placeholder_parser().set("initial_extruder", initial_extruder_id); + // Orca: filament types really extruded on this plate, deduplicated, in filament id order. + // Joined with '_': safe in URLs and on print hosts, and unlike '-' it does not clash with + // types that already contain a hyphen (PLA-CF, TPU-95A). + std::string printing_filament_types; + { + std::vector types; + for (const Extruder &extruder : m_writer.extruders()) { + std::string type = m_config.filament_type.get_at(extruder.id()); + if (std::find(types.begin(), types.end(), type) == types.end()) + types.emplace_back(std::move(type)); + } + printing_filament_types = boost::algorithm::join(types, "_"); + } + this->placeholder_parser().set("printing_filament_types", printing_filament_types); //BBS match_physical_extruder_for_each_filament(first_non_support_filaments, m_config); @@ -4914,6 +4929,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato print.tool_ordering())); print.m_print_statistics.initial_tool = initial_extruder_id; print.m_print_statistics.initial_no_support_tool = initial_non_support_extruder_id; + // Set again here: update_print_stats_and_format_filament_stats() above cleared the statistics. + print.m_print_statistics.printing_filament_types = printing_filament_types; if (!is_bbl_printers) { file.write_format("; total filament used [g] = %.2lf\n", print.m_print_statistics.total_weight); diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index a2e289a985..f0ffcb880f 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -5873,6 +5873,7 @@ DynamicConfig PrintStatistics::config() const config.set_key_value("initial_tool", new ConfigOptionInt(static_cast(this->initial_tool))); config.set_key_value("initial_extruder", new ConfigOptionInt(static_cast(this->initial_tool))); config.set_key_value("initial_no_support_extruder", new ConfigOptionInt(static_cast(this->initial_no_support_tool))); + config.set_key_value("printing_filament_types", new ConfigOptionString(this->printing_filament_types)); return config; } @@ -5882,7 +5883,8 @@ DynamicConfig PrintStatistics::placeholders() for (const std::string key : { "print_time", "normal_print_time", "silent_print_time", "used_filament", "extruded_volume", "extruded_volume_total", "total_cost", "total_weight", "extruded_weight_total", - "initial_tool", "initial_extruder", "initial_no_support_extruder", "total_toolchanges", "total_wipe_tower_cost", "total_wipe_tower_filament"}) + "initial_tool", "initial_extruder", "initial_no_support_extruder", "total_toolchanges", "total_wipe_tower_cost", "total_wipe_tower_filament", + "printing_filament_types"}) config.set_key_value(key, new ConfigOptionString(std::string("{") + key + "}")); return config; } diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index b0fd8fd7cd..d9d7f801fe 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -965,6 +965,8 @@ struct PrintStatistics double total_wipe_tower_filament; unsigned int initial_tool; unsigned int initial_no_support_tool; + // Orca: underscore-separated list of the filament types really extruded on the plate. + std::string printing_filament_types; std::map filament_stats; // Config with the filled in print statistics. @@ -984,6 +986,7 @@ struct PrintStatistics total_wipe_tower_filament = 0.; initial_tool = 0; initial_no_support_tool = 0; + printing_filament_types.clear(); filament_stats.clear(); } static const std::string FilamentUsedG; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 2d35a0889d..b8b758278e 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -13433,9 +13433,9 @@ PrintStatisticsConfigDef::PrintStatisticsConfigDef() def->label = L("Print time (normal mode)"); def->tooltip = L("Estimated print time when printed in normal mode (i.e. not in silent mode). Same as normal_print_time."); - //def = this->add("printing_filament_types", coString); - //def->label = L("Used filament types"); - //def->tooltip = L("Comma-separated list of all filament types used during the print."); + def = this->add("printing_filament_types", coString); + def->label = L("Used filament types"); + def->tooltip = L("Underscore-separated list of all filament types used during the print."); def = this->add("silent_print_time", coString); def->label = L("Print time (silent mode)"); diff --git a/tests/fff_print/test_print.cpp b/tests/fff_print/test_print.cpp index d8bfd7c533..d960334d0f 100644 --- a/tests/fff_print/test_print.cpp +++ b/tests/fff_print/test_print.cpp @@ -561,6 +561,40 @@ TEST_CASE("Print: {first_object_name} is not replaced by the saved-project file CHECK(resolved_output_name(model, "{first_object_name}", "SavedProject") == "WidgetPart.gcode"); } +TEST_CASE("{printing_filament_types} lists the filament types really printed", "[Print]") +{ + // Two filaments of different types. The start G-code uses the placeholder too: it has to + // resolve there as well as in the file name. + DynamicPrintConfig config = multifilament_config(2, { + { "filament_type", "ABS;PLA" }, + { "enable_prime_tower", 0 }, + { "filename_format", "{printing_filament_types}-{filament_type[initial_tool]}" }, + { "machine_start_gcode", "; printing types: {printing_filament_types}" }, + }); + + SECTION("only the filament the object is printed with, not filament 1") { + const std::vector> overrides{ { { "extruder", 2 } } }; + Print print; + Model model; + init_print({ cube(20) }, print, model, config, &overrides); + const std::string gcode = Slic3r::Test::gcode(print); + + CHECK(gcode.find("; printing types: PLA\n") != std::string::npos); + CHECK(print.output_filename() == "PLA-PLA.gcode"); + } + + SECTION("every type printed, joined with an underscore") { + const std::vector> overrides{ { { "extruder", 1 } }, { { "extruder", 2 } } }; + Print print; + Model model; + init_print({ cube(20), cube(20) }, print, model, config, &overrides); + const std::string gcode = Slic3r::Test::gcode(print); + + CHECK(gcode.find("; printing types: ABS_PLA\n") != std::string::npos); + CHECK(print.output_filename() == "ABS_PLA-ABS.gcode"); + } +} + TEST_CASE("Print::validate stacks independent warnings", "[Print][validate]") { // Two unrelated checks (region precise-wall + machine acceleration) must each