mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 09:15:58 +08:00
SPE-1784: New compressed (binary) gcode format integration
Populated printer metadata block Small optimization for print metadata
This commit is contained in:
parent
cd3513a98a
commit
a11009c3e0
@ -1036,14 +1036,7 @@ namespace DoExport {
|
|||||||
++ dst.second;
|
++ dst.second;
|
||||||
};
|
};
|
||||||
#if ENABLE_BINARIZED_GCODE
|
#if ENABLE_BINARIZED_GCODE
|
||||||
if (export_binary_data) {
|
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 {
|
|
||||||
#endif // ENABLE_BINARIZED_GCODE
|
#endif // ENABLE_BINARIZED_GCODE
|
||||||
append(out_filament_used_mm, "%.2lf", used_filament);
|
append(out_filament_used_mm, "%.2lf", used_filament);
|
||||||
append(out_filament_used_cm3, "%.2lf", extruded_volume * 0.001);
|
append(out_filament_used_cm3, "%.2lf", extruded_volume * 0.001);
|
||||||
@ -1053,23 +1046,13 @@ namespace DoExport {
|
|||||||
if (filament_weight > 0.) {
|
if (filament_weight > 0.) {
|
||||||
print_statistics.total_weight = print_statistics.total_weight + filament_weight;
|
print_statistics.total_weight = print_statistics.total_weight + filament_weight;
|
||||||
#if ENABLE_BINARIZED_GCODE
|
#if ENABLE_BINARIZED_GCODE
|
||||||
if (export_binary_data) {
|
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
|
|
||||||
#endif // ENABLE_BINARIZED_GCODE
|
#endif // ENABLE_BINARIZED_GCODE
|
||||||
append(out_filament_used_g, "%.2lf", filament_weight);
|
append(out_filament_used_g, "%.2lf", filament_weight);
|
||||||
if (filament_cost > 0.) {
|
if (filament_cost > 0.) {
|
||||||
print_statistics.total_cost = print_statistics.total_cost + filament_cost;
|
print_statistics.total_cost = print_statistics.total_cost + filament_cost;
|
||||||
#if ENABLE_BINARIZED_GCODE
|
#if ENABLE_BINARIZED_GCODE
|
||||||
if (export_binary_data) {
|
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
|
|
||||||
#endif // ENABLE_BINARIZED_GCODE
|
#endif // ENABLE_BINARIZED_GCODE
|
||||||
append(out_filament_cost, "%.2lf", filament_cost);
|
append(out_filament_cost, "%.2lf", filament_cost);
|
||||||
}
|
}
|
||||||
@ -1165,11 +1148,27 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
|
|||||||
// file data
|
// file data
|
||||||
binary_data.file_metadata.encoding_type = (uint16_t)BinaryGCode::EMetadataEncodingType::INI;
|
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));
|
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
|
// config data
|
||||||
binary_data.slicer_metadata.encoding_type = (uint16_t)BinaryGCode::EMetadataEncodingType::INI;
|
binary_data.slicer_metadata.encoding_type = (uint16_t)BinaryGCode::EMetadataEncodingType::INI;
|
||||||
encode_full_config(print, binary_data.slicer_metadata.raw_data);
|
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
|
// modifies m_silent_time_estimator_enabled
|
||||||
@ -1615,11 +1614,6 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
|
|||||||
|
|
||||||
if (export_to_binary_gcode) {
|
if (export_to_binary_gcode) {
|
||||||
BinaryGCode::BinaryData& binary_data = m_processor.get_binary_data();
|
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)
|
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) });
|
binary_data.print_metadata.raw_data.push_back({ "total toolchanges", std::to_string(print.m_print_statistics.total_toolchanges) });
|
||||||
}
|
}
|
||||||
|
@ -1354,7 +1354,7 @@ void GCodeProcessor::finalize(bool perform_post_process)
|
|||||||
|
|
||||||
m_used_filaments.process_caches(this);
|
m_used_filaments.process_caches(this);
|
||||||
|
|
||||||
update_estimated_times_stats();
|
update_estimated_statistics();
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
@ -3681,25 +3681,27 @@ void GCodeProcessor::post_process()
|
|||||||
|
|
||||||
if (m_binarizer.is_enabled()) {
|
if (m_binarizer.is_enabled()) {
|
||||||
// update print metadata
|
// update print metadata
|
||||||
auto update_value = [](std::string& value, const std::vector<double>& values) {
|
auto stringify = [](const std::vector<double>& values) {
|
||||||
|
std::string ret;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
value.clear();
|
|
||||||
for (size_t i = 0; i < values.size(); ++i) {
|
for (size_t i = 0; i < values.size(); ++i) {
|
||||||
sprintf(buf, i == values.size() - 1 ? " %.2lf" : " %.2lf,", values[i]);
|
sprintf(buf, i < values.size() - 1 ? "%.2lf, " : "%.2lf", values[i]);
|
||||||
value += buf;
|
ret += buf;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
// update binary data
|
// update binary data
|
||||||
BinaryGCode::BinaryData& binary_data = m_binarizer.get_binary_data();
|
BinaryGCode::BinaryData& binary_data = m_binarizer.get_binary_data();
|
||||||
for (auto& [key, value] : binary_data.print_metadata.raw_data) {
|
binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedMm, stringify(filament_mm) });
|
||||||
if (key == PrintStatistics::FilamentUsedMm) update_value(value, filament_mm);
|
binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedCm3, stringify(filament_cm3) });
|
||||||
else if (key == PrintStatistics::FilamentUsedG) update_value(value, filament_g);
|
binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentUsedG, stringify(filament_g) });
|
||||||
else if (key == PrintStatistics::TotalFilamentUsedG) update_value(value, { filament_total_g });
|
binary_data.print_metadata.raw_data.push_back({ PrintStatistics::FilamentCost, stringify(filament_cost) });
|
||||||
else if (key == PrintStatistics::FilamentUsedCm3) update_value(value, filament_cm3);
|
binary_data.print_metadata.raw_data.push_back({ PrintStatistics::TotalFilamentUsedG, stringify({ filament_total_g }) });
|
||||||
else if (key == PrintStatistics::FilamentCost) update_value(value, filament_cost);
|
binary_data.print_metadata.raw_data.push_back({ PrintStatistics::TotalFilamentCost, stringify({ filament_total_cost }) });
|
||||||
else if (key == PrintStatistics::TotalFilamentCost) update_value(value, { 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<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
|
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
|
||||||
const TimeMachine& machine = m_time_processor.machines[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");
|
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 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.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) {
|
auto update_mode = [this](PrintEstimatedStatistics::ETimeMode mode) {
|
||||||
PrintEstimatedStatistics::Mode& data = m_result.print_statistics.modes[static_cast<size_t>(mode)];
|
PrintEstimatedStatistics::Mode& data = m_result.print_statistics.modes[static_cast<size_t>(mode)];
|
||||||
|
@ -66,10 +66,10 @@ namespace Slic3r {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<double> volumes_per_color_change;
|
std::vector<double> volumes_per_color_change;
|
||||||
std::map<size_t, double> volumes_per_extruder;
|
std::map<size_t, double> volumes_per_extruder;
|
||||||
std::map<GCodeExtrusionRole, std::pair<double, double>> used_filaments_per_role;
|
std::map<GCodeExtrusionRole, std::pair<double, double>> used_filaments_per_role;
|
||||||
std::map<size_t, double> cost_per_extruder;
|
std::map<size_t, double> cost_per_extruder;
|
||||||
|
|
||||||
std::array<Mode, static_cast<size_t>(ETimeMode::Count)> modes;
|
std::array<Mode, static_cast<size_t>(ETimeMode::Count)> modes;
|
||||||
|
|
||||||
@ -831,7 +831,7 @@ namespace Slic3r {
|
|||||||
// Simulates firmware st_synchronize() call
|
// Simulates firmware st_synchronize() call
|
||||||
void simulate_st_synchronize(float additional_time = 0.0f);
|
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);
|
double extract_absolute_position_on_axis(Axis axis, const GCodeReader::GCodeLine& line, double area_filament_cross_section);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user