Skip to content

Commit

Permalink
Updated conversion of print and printer metadata to match PrusaSlicer…
Browse files Browse the repository at this point in the history
… export
  • Loading branch information
enricoturri1966 committed Jul 30, 2024
1 parent dcb8f7b commit 70013a1
Showing 1 changed file with 80 additions and 70 deletions.
150 changes: 80 additions & 70 deletions src/LibBGCode/convert/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,36 +184,38 @@ BGCODE_CONVERT_EXPORT EResult from_ascii_to_binary(FILE& src_file, FILE& dst_fil
using namespace std::literals;
static constexpr const std::string_view GeneratedByPrusaSlicer = "generated by PrusaSlicer"sv;

static constexpr const std::string_view PrinterModel = "printer_model"sv;
static constexpr const std::string_view FilamentType = "filament_type"sv;
static constexpr const std::string_view NozzleDiameter = "nozzle_diameter"sv;
static constexpr const std::string_view BedTemperature = "bed_temperature"sv;
static constexpr const std::string_view BrimWidth = "brim_width"sv;
static constexpr const std::string_view FillDensity = "fill_density"sv;
static constexpr const std::string_view LayerHeight = "layer_height"sv;
static constexpr const std::string_view Temperature = "temperature"sv;
static constexpr const std::string_view Ironing = "ironing"sv;
static constexpr const std::string_view SupportMaterial = "support_material"sv;
static constexpr const std::string_view MaxLayerZ = "max_layer_z"sv;
static constexpr const std::string_view ExtruderColour = "extruder_colour"sv;
static constexpr const std::string_view FilamentUsedMm = "filament used [mm]"sv;
static constexpr const std::string_view FilamentUsedG = "filament used [g]"sv;
static constexpr const std::string_view EstimatedPrintingTimeNormal = "estimated printing time (normal mode)"sv;
static constexpr const std::string_view FilamentUsedCm3 = "filament used [cm3]"sv;
static constexpr const std::string_view FilamentCost = "filament cost"sv;
static constexpr const std::string_view TotalFilamentUsedG = "total filament used [g]"sv;
static constexpr const std::string_view TotalFilamentCost = "total filament cost"sv;
static constexpr const std::string_view TotalFilamentUsedWipeTower = "total filament used for wipe tower [g]"sv;
static constexpr const std::string_view EstimatedPrintingTimeSilent = "estimated printing time (silent mode)"sv;
static constexpr const std::string_view PrinterModel = "printer_model"sv;
static constexpr const std::string_view FilamentType = "filament_type"sv;
static constexpr const std::string_view NozzleDiameter = "nozzle_diameter"sv;
static constexpr const std::string_view BedTemperature = "bed_temperature"sv;
static constexpr const std::string_view BrimWidth = "brim_width"sv;
static constexpr const std::string_view FillDensity = "fill_density"sv;
static constexpr const std::string_view LayerHeight = "layer_height"sv;
static constexpr const std::string_view Temperature = "temperature"sv;
static constexpr const std::string_view Ironing = "ironing"sv;
static constexpr const std::string_view SupportMaterial = "support_material"sv;
static constexpr const std::string_view MaxLayerZ = "max_layer_z"sv;
static constexpr const std::string_view ExtruderColour = "extruder_colour"sv;
static constexpr const std::string_view FilamentUsedMm = "filament used [mm]"sv;
static constexpr const std::string_view FilamentUsedG = "filament used [g]"sv;
static constexpr const std::string_view EstimatedPrintingTimeNormal = "estimated printing time (normal mode)"sv;
static constexpr const std::string_view FilamentUsedCm3 = "filament used [cm3]"sv;
static constexpr const std::string_view FilamentCost = "filament cost"sv;
static constexpr const std::string_view TotalFilamentUsedG = "total filament used [g]"sv;
static constexpr const std::string_view TotalFilamentCost = "total filament cost"sv;
static constexpr const std::string_view TotalFilamentUsedWipeTower = "total filament used for wipe tower [g]"sv;
static constexpr const std::string_view EstimatedPrintingTimeSilent = "estimated printing time (silent mode)"sv;
static constexpr const std::string_view Estimated1stLayerPrintingTimeNormal = "estimated first layer printing time (normal mode)"sv;
static constexpr const std::string_view Estimated1stLayerPrintingTimeSilent = "estimated first layer printing time (silent mode)"sv;
static constexpr const std::string_view ObjectsInfo = "objects_info"sv;
static constexpr const std::string_view TotalToolChanges = "total toolchanges"sv;

static constexpr const std::string_view ThumbnailPNGBegin = "thumbnail begin"sv;
static constexpr const std::string_view ThumbnailPNGEnd = "thumbnail end"sv;
static constexpr const std::string_view ThumbnailPNGEnd = "thumbnail end"sv;
static constexpr const std::string_view ThumbnailJPGBegin = "thumbnail_JPG begin"sv;
static constexpr const std::string_view ThumbnailJPGEnd = "thumbnail_JPG end"sv;
static constexpr const std::string_view ThumbnailJPGEnd = "thumbnail_JPG end"sv;
static constexpr const std::string_view ThumbnailQOIBegin = "thumbnail_QOI begin"sv;
static constexpr const std::string_view ThumbnailQOIEnd = "thumbnail_QOI end"sv;
static constexpr const std::string_view ThumbnailQOIEnd = "thumbnail_QOI end"sv;

static constexpr const std::string_view PrusaSlicerConfig = "prusaslicer_config"sv;

Expand Down Expand Up @@ -267,6 +269,8 @@ BGCODE_CONVERT_EXPORT EResult from_ascii_to_binary(FILE& src_file, FILE& dst_fil
std::string estimated_printing_time_silent;
std::string estimated_1st_layer_printing_time_normal;
std::string estimated_1st_layer_printing_time_silent;
std::string objects_info;
std::string total_tool_changes;

std::optional<EThumbnailFormat> reading_thumbnail;
size_t curr_thumbnail_data_size = 0;
Expand Down Expand Up @@ -322,29 +326,31 @@ BGCODE_CONVERT_EXPORT EResult from_ascii_to_binary(FILE& src_file, FILE& dst_fil
return false;
};

if (collect_metadata(PrinterModel, printer_model, true)) return;
if (collect_metadata(FilamentType, filament_type, true)) return;
if (collect_metadata(NozzleDiameter, nozzle_diameter, true)) return;
if (collect_metadata(BedTemperature, bed_temperature, true)) return;
if (collect_metadata(BrimWidth, brim_width, true)) return;
if (collect_metadata(FillDensity, fill_density, true)) return;
if (collect_metadata(LayerHeight, layer_height, true)) return;
if (collect_metadata(Temperature, temperature, true)) return;
if (collect_metadata(Ironing, ironing, true)) return;
if (collect_metadata(SupportMaterial, support_material, true)) return;
if (collect_metadata(MaxLayerZ, max_layer_z)) return;
if (collect_metadata(ExtruderColour, extruder_colour, true)) return;
if (collect_metadata(FilamentUsedMm, filament_used_mm)) return;
if (collect_metadata(FilamentUsedG, filament_used_g)) return;
if (collect_metadata(EstimatedPrintingTimeNormal, estimated_printing_time_normal)) return;
if (collect_metadata(FilamentUsedCm3, filament_used_cm3)) return;
if (collect_metadata(FilamentCost, filament_cost)) return;
if (collect_metadata(TotalFilamentUsedG, total_filament_used_g)) return;
if (collect_metadata(TotalFilamentCost, total_filament_cost)) return;
if (collect_metadata(TotalFilamentUsedWipeTower, total_filament_used_wipe_tower)) return;
if (collect_metadata(EstimatedPrintingTimeSilent, estimated_printing_time_silent)) return;
if (collect_metadata(PrinterModel, printer_model, true)) return;
if (collect_metadata(FilamentType, filament_type, true)) return;
if (collect_metadata(NozzleDiameter, nozzle_diameter, true)) return;
if (collect_metadata(BedTemperature, bed_temperature, true)) return;
if (collect_metadata(BrimWidth, brim_width, true)) return;
if (collect_metadata(FillDensity, fill_density, true)) return;
if (collect_metadata(LayerHeight, layer_height, true)) return;
if (collect_metadata(Temperature, temperature, true)) return;
if (collect_metadata(Ironing, ironing, true)) return;
if (collect_metadata(SupportMaterial, support_material, true)) return;
if (collect_metadata(MaxLayerZ, max_layer_z)) return;
if (collect_metadata(ExtruderColour, extruder_colour, true)) return;
if (collect_metadata(FilamentUsedMm, filament_used_mm)) return;
if (collect_metadata(FilamentUsedG, filament_used_g)) return;
if (collect_metadata(EstimatedPrintingTimeNormal, estimated_printing_time_normal)) return;
if (collect_metadata(FilamentUsedCm3, filament_used_cm3)) return;
if (collect_metadata(FilamentCost, filament_cost)) return;
if (collect_metadata(TotalFilamentUsedG, total_filament_used_g)) return;
if (collect_metadata(TotalFilamentCost, total_filament_cost)) return;
if (collect_metadata(TotalFilamentUsedWipeTower, total_filament_used_wipe_tower)) return;
if (collect_metadata(EstimatedPrintingTimeSilent, estimated_printing_time_silent)) return;
if (collect_metadata(Estimated1stLayerPrintingTimeNormal, estimated_1st_layer_printing_time_normal)) return;
if (collect_metadata(Estimated1stLayerPrintingTimeSilent, estimated_1st_layer_printing_time_silent)) return;
if (collect_metadata(ObjectsInfo, objects_info)) return;
if (collect_metadata(TotalToolChanges, total_tool_changes)) return;

// update slicer metadata
if (!reading_config) {
Expand Down Expand Up @@ -500,34 +506,38 @@ BGCODE_CONVERT_EXPORT EResult from_ascii_to_binary(FILE& src_file, FILE& dst_fil
};

// update printer metadata
append_metadata(binary_data.printer_metadata.raw_data, std::string(PrinterModel), printer_model);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentType), filament_type);
append_metadata(binary_data.printer_metadata.raw_data, std::string(NozzleDiameter), nozzle_diameter);
append_metadata(binary_data.printer_metadata.raw_data, std::string(BedTemperature), bed_temperature);
append_metadata(binary_data.printer_metadata.raw_data, std::string(BrimWidth), brim_width);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FillDensity), fill_density);
append_metadata(binary_data.printer_metadata.raw_data, std::string(LayerHeight), layer_height);
append_metadata(binary_data.printer_metadata.raw_data, std::string(Temperature), temperature);
append_metadata(binary_data.printer_metadata.raw_data, std::string(Ironing), ironing);
append_metadata(binary_data.printer_metadata.raw_data, std::string(SupportMaterial), support_material);
append_metadata(binary_data.printer_metadata.raw_data, std::string(MaxLayerZ), max_layer_z);
append_metadata(binary_data.printer_metadata.raw_data, std::string(ExtruderColour), extruder_colour);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentUsedMm), filament_used_mm);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentUsedCm3), filament_used_cm3);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentUsedG), filament_used_g);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentCost), filament_cost);
append_metadata(binary_data.printer_metadata.raw_data, std::string(PrinterModel), printer_model);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentType), filament_type);
append_metadata(binary_data.printer_metadata.raw_data, std::string(NozzleDiameter), nozzle_diameter);
append_metadata(binary_data.printer_metadata.raw_data, std::string(BedTemperature), bed_temperature);
append_metadata(binary_data.printer_metadata.raw_data, std::string(BrimWidth), brim_width);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FillDensity), fill_density);
append_metadata(binary_data.printer_metadata.raw_data, std::string(LayerHeight), layer_height);
append_metadata(binary_data.printer_metadata.raw_data, std::string(Temperature), temperature);
append_metadata(binary_data.printer_metadata.raw_data, std::string(Ironing), ironing);
append_metadata(binary_data.printer_metadata.raw_data, std::string(SupportMaterial), support_material);
append_metadata(binary_data.printer_metadata.raw_data, std::string(MaxLayerZ), max_layer_z);
append_metadata(binary_data.printer_metadata.raw_data, std::string(ExtruderColour), extruder_colour);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentUsedMm), filament_used_mm);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentUsedCm3), filament_used_cm3);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentUsedG), filament_used_g);
append_metadata(binary_data.printer_metadata.raw_data, std::string(FilamentCost), filament_cost);
append_metadata(binary_data.printer_metadata.raw_data, std::string(EstimatedPrintingTimeNormal), estimated_printing_time_normal);
append_metadata(binary_data.printer_metadata.raw_data, std::string(EstimatedPrintingTimeSilent), estimated_printing_time_silent);
append_metadata(binary_data.printer_metadata.raw_data, std::string(TotalFilamentUsedWipeTower), total_filament_used_wipe_tower);
append_metadata(binary_data.printer_metadata.raw_data, std::string(ObjectsInfo), objects_info);

// update print metadata
append_metadata(binary_data.print_metadata.raw_data, std::string(FilamentUsedMm), filament_used_mm);
append_metadata(binary_data.print_metadata.raw_data, std::string(FilamentUsedCm3), filament_used_cm3);
append_metadata(binary_data.print_metadata.raw_data, std::string(FilamentUsedG), filament_used_g);
append_metadata(binary_data.print_metadata.raw_data, std::string(FilamentCost), filament_cost);
append_metadata(binary_data.print_metadata.raw_data, std::string(TotalFilamentUsedG), total_filament_used_g);
append_metadata(binary_data.print_metadata.raw_data, std::string(TotalFilamentCost), total_filament_cost);
append_metadata(binary_data.print_metadata.raw_data, std::string(TotalFilamentUsedWipeTower), total_filament_used_wipe_tower);
append_metadata(binary_data.print_metadata.raw_data, std::string(EstimatedPrintingTimeNormal), estimated_printing_time_normal);
append_metadata(binary_data.print_metadata.raw_data, std::string(EstimatedPrintingTimeSilent), estimated_printing_time_silent);
append_metadata(binary_data.print_metadata.raw_data, std::string(TotalToolChanges), total_tool_changes);
append_metadata(binary_data.print_metadata.raw_data, std::string(FilamentUsedMm), filament_used_mm);
append_metadata(binary_data.print_metadata.raw_data, std::string(FilamentUsedCm3), filament_used_cm3);
append_metadata(binary_data.print_metadata.raw_data, std::string(FilamentUsedG), filament_used_g);
append_metadata(binary_data.print_metadata.raw_data, std::string(FilamentCost), filament_cost);
append_metadata(binary_data.print_metadata.raw_data, std::string(TotalFilamentUsedG), total_filament_used_g);
append_metadata(binary_data.print_metadata.raw_data, std::string(TotalFilamentCost), total_filament_cost);
append_metadata(binary_data.print_metadata.raw_data, std::string(TotalFilamentUsedWipeTower), total_filament_used_wipe_tower);
append_metadata(binary_data.print_metadata.raw_data, std::string(EstimatedPrintingTimeNormal), estimated_printing_time_normal);
append_metadata(binary_data.print_metadata.raw_data, std::string(EstimatedPrintingTimeSilent), estimated_printing_time_silent);
append_metadata(binary_data.print_metadata.raw_data, std::string(Estimated1stLayerPrintingTimeNormal), estimated_1st_layer_printing_time_normal);
append_metadata(binary_data.print_metadata.raw_data, std::string(Estimated1stLayerPrintingTimeSilent), estimated_1st_layer_printing_time_silent);

Expand Down

0 comments on commit 70013a1

Please sign in to comment.