diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index f6b772e946..c9136af7a4 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1036,14 +1036,7 @@ namespace DoExport { ++ dst.second; }; #if ENABLE_BINARIZED_GCODE - if (export_binary_data) { - char buf[128]; - sprintf(buf, "%.2lf", used_filament); - binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedMm, std::string(buf) }); - sprintf(buf, "%.2lf", extruded_volume * 0.001); - binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedCm3, std::string(buf) }); - } - else { + if (!export_binary_data) { #endif // ENABLE_BINARIZED_GCODE append(out_filament_used_mm, "%.2lf", used_filament); append(out_filament_used_cm3, "%.2lf", extruded_volume * 0.001); @@ -1053,23 +1046,13 @@ namespace DoExport { if (filament_weight > 0.) { print_statistics.total_weight = print_statistics.total_weight + filament_weight; #if ENABLE_BINARIZED_GCODE - if (export_binary_data) { - char buf[128]; - sprintf(buf, "%.2lf", filament_weight); - binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedG, std::string(buf) }); - } - else + if (!export_binary_data) #endif // ENABLE_BINARIZED_GCODE append(out_filament_used_g, "%.2lf", filament_weight); if (filament_cost > 0.) { print_statistics.total_cost = print_statistics.total_cost + filament_cost; #if ENABLE_BINARIZED_GCODE - if (export_binary_data) { - char buf[128]; - sprintf(buf, "%.2lf", filament_cost); - binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentCost, std::string(buf) }); - } - else + if (!export_binary_data) #endif // ENABLE_BINARIZED_GCODE append(out_filament_cost, "%.2lf", filament_cost); } @@ -1165,11 +1148,27 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato // file data binary_data.file_metadata.encoding_type = (uint16_t)BinaryGCode::EMetadataEncodingType::INI; binary_data.file_metadata.raw_data.emplace_back("Producer", std::string(SLIC3R_APP_NAME) + " " + std::string(SLIC3R_VERSION)); - // add here other key/value pairs // config data binary_data.slicer_metadata.encoding_type = (uint16_t)BinaryGCode::EMetadataEncodingType::INI; encode_full_config(print, binary_data.slicer_metadata.raw_data); + + // printer data + binary_data.printer_metadata.raw_data.emplace_back("printer model" , print.config().printer_model.value); // duplicated into config data + std::string filament_types_str; + for (size_t i = 0; i < print.config().filament_type.values.size(); ++i) { + filament_types_str += print.config().filament_type.values[i]; + if (i < print.config().filament_type.values.size() - 1) + filament_types_str += ", "; + } + binary_data.printer_metadata.raw_data.emplace_back("filament type", filament_types_str); // duplicated into config data + std::string nozzle_diameters_str; + char buf[1024]; + for (size_t i = 0; i < print.config().nozzle_diameter.values.size(); ++i) { + sprintf(buf, i < print.config().nozzle_diameter.values.size() - 1 ? "%.2lf, " : "%.2lf", print.config().nozzle_diameter.values[i]); + nozzle_diameters_str += buf; + } + binary_data.printer_metadata.raw_data.emplace_back("nozzle diameter", nozzle_diameters_str); // duplicated into config data } // modifies m_silent_time_estimator_enabled @@ -1615,11 +1614,6 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato if (export_to_binary_gcode) { BinaryGCode::BinaryData& binary_data = m_processor.get_binary_data(); - char buf[128]; - sprintf(buf, "%.2lf", print.m_print_statistics.total_weight); - binary_data.print_metadata.raw_data.push_back({ PrintStatistics::TotalFilamentUsedG, std::string(buf) }); - sprintf(buf, "%.2lf", print.m_print_statistics.total_cost); - binary_data.print_metadata.raw_data.push_back({ PrintStatistics::TotalFilamentCost, std::string(buf) }); if (print.m_print_statistics.total_toolchanges > 0) binary_data.print_metadata.raw_data.push_back({ "total toolchanges", std::to_string(print.m_print_statistics.total_toolchanges) }); } diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 1cdcba4115..b66850fd07 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -1354,7 +1354,7 @@ void GCodeProcessor::finalize(bool perform_post_process) m_used_filaments.process_caches(this); - update_estimated_times_stats(); + update_estimated_statistics(); #if ENABLE_GCODE_VIEWER_DATA_CHECKING std::cout << "\n"; @@ -3681,25 +3681,27 @@ void GCodeProcessor::post_process() if (m_binarizer.is_enabled()) { // update print metadata - auto update_value = [](std::string& value, const std::vector& values) { + auto stringify = [](const std::vector& values) { + std::string ret; char buf[1024]; - value.clear(); for (size_t i = 0; i < values.size(); ++i) { - sprintf(buf, i == values.size() - 1 ? " %.2lf" : " %.2lf,", values[i]); - value += buf; + sprintf(buf, i < values.size() - 1 ? "%.2lf, " : "%.2lf", values[i]); + ret += buf; } + return ret; }; // update binary data BinaryGCode::BinaryData& binary_data = m_binarizer.get_binary_data(); - for (auto& [key, value] : binary_data.print_metadata.raw_data) { - if (key == PrintStatistics::FilamentUsedMm) update_value(value, filament_mm); - else if (key == PrintStatistics::FilamentUsedG) update_value(value, filament_g); - else if (key == PrintStatistics::TotalFilamentUsedG) update_value(value, { filament_total_g }); - else if (key == PrintStatistics::FilamentUsedCm3) update_value(value, filament_cm3); - else if (key == PrintStatistics::FilamentCost) update_value(value, filament_cost); - else if (key == PrintStatistics::TotalFilamentCost) update_value(value, { filament_total_cost }); - } + binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedMm, stringify(filament_mm) }); + binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedCm3, stringify(filament_cm3) }); + binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedG, stringify(filament_g) }); + binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentCost, stringify(filament_cost) }); + binary_data.print_metadata.raw_data.push_back({ PrintStatistics::TotalFilamentUsedG, stringify({ filament_total_g }) }); + binary_data.print_metadata.raw_data.push_back({ PrintStatistics::TotalFilamentCost, stringify({ filament_total_cost }) }); + + binary_data.printer_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedMm, stringify(filament_mm) }); // duplicated into print metadata + binary_data.printer_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedG, stringify(filament_g) }); // duplicated into print metadata for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { const TimeMachine& machine = m_time_processor.machines[i]; @@ -3709,6 +3711,8 @@ void GCodeProcessor::post_process() sprintf(buf, "(%s mode)", (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent"); binary_data.print_metadata.raw_data.push_back({ "estimated printing time " + std::string(buf), get_time_dhms(machine.time) }); binary_data.print_metadata.raw_data.push_back({ "estimated first layer printing time " + std::string(buf), get_time_dhms(machine.layers_time.empty() ? 0.f : machine.layers_time.front()) }); + + binary_data.printer_metadata.raw_data.push_back({ "estimated printing time " + std::string(buf), get_time_dhms(machine.time) }); } } @@ -4596,7 +4600,7 @@ void GCodeProcessor::simulate_st_synchronize(float additional_time) } } -void GCodeProcessor::update_estimated_times_stats() +void GCodeProcessor::update_estimated_statistics() { auto update_mode = [this](PrintEstimatedStatistics::ETimeMode mode) { PrintEstimatedStatistics::Mode& data = m_result.print_statistics.modes[static_cast(mode)]; diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index fe2db07f99..9ca4455945 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -66,10 +66,10 @@ namespace Slic3r { } }; - std::vector volumes_per_color_change; - std::map volumes_per_extruder; + std::vector volumes_per_color_change; + std::map volumes_per_extruder; std::map> used_filaments_per_role; - std::map cost_per_extruder; + std::map cost_per_extruder; std::array(ETimeMode::Count)> modes; @@ -831,7 +831,7 @@ namespace Slic3r { // Simulates firmware st_synchronize() call void simulate_st_synchronize(float additional_time = 0.0f); - void update_estimated_times_stats(); + void update_estimated_statistics(); double extract_absolute_position_on_axis(Axis axis, const GCodeReader::GCodeLine& line, double area_filament_cross_section); };