Some code semplification

This commit is contained in:
enricoturri1966 2023-08-14 09:55:00 +02:00
parent 8e391d00da
commit 98be146fa9
5 changed files with 107 additions and 97 deletions

View File

@ -741,8 +741,9 @@ ConfigSubstitutions ConfigBase::load(const std::string& filename, ForwardCompati
if (file == nullptr)
throw Slic3r::RuntimeError("Error opening the file: " + filename + "\n");
using namespace bgcode::core;
std::vector<uint8_t> cs_buffer(65536);
file_type = (bgcode::core::is_valid_binary_gcode(*file, true, cs_buffer.data(), cs_buffer.size()) == bgcode::core::EResult::Success) ? EFileType::BinaryGCode : EFileType::AsciiGCode;
file_type = (is_valid_binary_gcode(*file, true, cs_buffer.data(), cs_buffer.size()) == EResult::Success) ? EFileType::BinaryGCode : EFileType::AsciiGCode;
fclose(file);
}
else
@ -1071,29 +1072,31 @@ ConfigSubstitutions ConfigBase::load_from_binary_gcode_file(const std::string& f
if (file.f == nullptr)
throw Slic3r::RuntimeError(format("Error opening the file: %1%", filename));
using namespace bgcode::core;
using namespace bgcode::binarize;
std::vector<uint8_t> cs_buffer(65536);
bgcode::core::EResult res = bgcode::core::is_valid_binary_gcode(*file.f, true, cs_buffer.data(), cs_buffer.size());
if (res != bgcode::core::EResult::Success)
EResult res = is_valid_binary_gcode(*file.f, true, cs_buffer.data(), cs_buffer.size());
if (res != EResult::Success)
throw Slic3r::RuntimeError(format("The selected file is not a valid binary gcode.\nError: %1%",
std::string(bgcode::core::translate_result(res))));
std::string(translate_result(res))));
rewind(file.f);
bgcode::core::FileHeader file_header;
res = bgcode::core::read_header(*file.f, file_header, nullptr);
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(bgcode::core::translate_result(res))));
FileHeader file_header;
res = read_header(*file.f, file_header, nullptr);
if (res != EResult::Success)
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(translate_result(res))));
bgcode::core::BlockHeader block_header;
res = read_next_block_header(*file.f, file_header, block_header, bgcode::core::EBlockType::SlicerMetadata, cs_buffer.data(), cs_buffer.size());
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(bgcode::core::translate_result(res))));
if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::SlicerMetadata)
BlockHeader block_header;
res = read_next_block_header(*file.f, file_header, block_header, EBlockType::SlicerMetadata, cs_buffer.data(), cs_buffer.size());
if (res != EResult::Success)
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(translate_result(res))));
if ((EBlockType)block_header.type != EBlockType::SlicerMetadata)
throw Slic3r::RuntimeError(format("Unable to find slicer metadata block in file: '%1%'", filename));
bgcode::binarize::SlicerMetadataBlock slicer_metadata_block;
SlicerMetadataBlock slicer_metadata_block;
res = slicer_metadata_block.read_data(*file.f, file_header, block_header);
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(bgcode::core::translate_result(res))));
if (res != EResult::Success)
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(translate_result(res))));
for (const auto& [key, value] : slicer_metadata_block.raw_data) {
this->set_deserialize(key, value, substitutions_ctxt);

View File

@ -1041,8 +1041,9 @@ void GCodeProcessor::process_file(const std::string& filename, std::function<voi
if (file == nullptr)
throw Slic3r::RuntimeError("Error opening the file: " + filename + "\n");
using namespace bgcode::core;
std::vector<uint8_t> cs_buffer(65536);
const bool is_binary = bgcode::core::is_valid_binary_gcode(*file, true, cs_buffer.data(), cs_buffer.size()) == bgcode::core::EResult::Success;
const bool is_binary = is_valid_binary_gcode(*file, true, cs_buffer.data(), cs_buffer.size()) == EResult::Success;
fclose(file);
if (is_binary)
@ -1136,24 +1137,26 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct
rewind(file.f);
// read file header
bgcode::core::FileHeader file_header;
bgcode::core::EResult res = bgcode::core::read_header(*file.f, file_header, nullptr);
if (res != bgcode::core::EResult::Success)
using namespace bgcode::core;
using namespace bgcode::binarize;
FileHeader file_header;
EResult res = read_header(*file.f, file_header, nullptr);
if (res != EResult::Success)
throw Slic3r::RuntimeError("File: " + filename + "does not contain a valid binary gcode\n Error: " +
std::string(bgcode::core::translate_result(res)) + "\n");
std::string(translate_result(res)) + "\n");
// read file metadata block
bgcode::core::BlockHeader block_header;
BlockHeader block_header;
std::vector<uint8_t> cs_buffer(65536);
res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::FileMetadata)
res = read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
if ((EBlockType)block_header.type != EBlockType::FileMetadata)
throw Slic3r::RuntimeError("Unable to find file metadata block in file: " + filename + "\n");
bgcode::binarize::FileMetadataBlock file_metadata_block;
FileMetadataBlock file_metadata_block;
res = file_metadata_block.read_data(*file.f, file_header, block_header);
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
auto producer_it = std::find_if(file_metadata_block.raw_data.begin(), file_metadata_block.raw_data.end(),
[](const std::pair<std::string, std::string>& item) { return item.first == "Producer"; });
if (producer_it != file_metadata_block.raw_data.end() && boost::starts_with(producer_it->second, std::string(SLIC3R_APP_NAME)))
@ -1162,15 +1165,15 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct
m_producer = EProducer::Unknown;
// read printer metadata block
res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::PrinterMetadata)
res = read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
if ((EBlockType)block_header.type != EBlockType::PrinterMetadata)
throw Slic3r::RuntimeError("Unable to find printer metadata block in file: " + filename + "\n");
bgcode::binarize::PrinterMetadataBlock printer_metadata_block;
PrinterMetadataBlock printer_metadata_block;
res = printer_metadata_block.read_data(*file.f, file_header, block_header);
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
#if ENABLE_BINARIZED_GCODE_WIN_DEBUG
OutputDebugStringA("Printer metadata:\n");
for (const auto& [key, value] : printer_metadata_block.raw_data) {
@ -1182,24 +1185,24 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct
#endif // ENABLE_BINARIZED_GCODE_WIN_DEBUG
// read thumbnail blocks
res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
res = read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
while ((bgcode::core::EBlockType)block_header.type == bgcode::core::EBlockType::Thumbnail) {
bgcode::binarize::ThumbnailBlock thumbnail_block;
while ((EBlockType)block_header.type == EBlockType::Thumbnail) {
ThumbnailBlock thumbnail_block;
res = thumbnail_block.read_data(*file.f, file_header, block_header);
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
#if ENABLE_BINARIZED_GCODE_DEBUG
if (thumbnail_block.data.size() > 0) {
auto format_filename = [](const std::string& stem, const bgcode::binarize::ThumbnailBlock& block) {
auto format_filename = [](const std::string& stem, const ThumbnailBlock& block) {
std::string ret = stem + "_" + std::to_string(block.params.width) + "x" + std::to_string(block.params.height);
switch ((bgcode::core::EThumbnailFormat)block.params.format)
switch ((EThumbnailFormat)block.params.format)
{
case bgcode::core::EThumbnailFormat::PNG: { ret += ".png"; break; }
case bgcode::core::EThumbnailFormat::JPG: { ret += ".jpg"; break; }
case bgcode::core::EThumbnailFormat::QOI: { ret += ".qoi"; break; }
case EThumbnailFormat::PNG: { ret += ".png"; break; }
case EThumbnailFormat::JPG: { ret += ".jpg"; break; }
case EThumbnailFormat::QOI: { ret += ".qoi"; break; }
}
return ret;
};
@ -1215,18 +1218,18 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct
}
#endif // ENABLE_BINARIZED_GCODE_DEBUG
res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
res = read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
}
// read print metadata block
if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::PrintMetadata)
if ((EBlockType)block_header.type != EBlockType::PrintMetadata)
throw Slic3r::RuntimeError("Unable to find print metadata block in file: " + filename + "\n");
bgcode::binarize::PrintMetadataBlock print_metadata_block;
PrintMetadataBlock print_metadata_block;
res = print_metadata_block.read_data(*file.f, file_header, block_header);
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
#if ENABLE_BINARIZED_GCODE_WIN_DEBUG
OutputDebugStringA("Print metadata:\n");
for (const auto& [key, value] : print_metadata_block.raw_data) {
@ -1238,15 +1241,15 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct
#endif // ENABLE_BINARIZED_GCODE_WIN_DEBUG
// read slicer metadata block
res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::SlicerMetadata)
res = read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
if ((EBlockType)block_header.type != EBlockType::SlicerMetadata)
throw Slic3r::RuntimeError("Unable to find slicer metadata block in file: " + filename + "\n");
bgcode::binarize::SlicerMetadataBlock slicer_metadata_block;
SlicerMetadataBlock slicer_metadata_block;
res = slicer_metadata_block.read_data(*file.f, file_header, block_header);
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
#if ENABLE_BINARIZED_GCODE_WIN_DEBUG
OutputDebugStringA("Slicer metadata:\n");
for (const auto& [key, value] : slicer_metadata_block.raw_data) {
@ -1273,16 +1276,16 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct
initialize_result_moves();
// read gcodes block
res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if ((bgcode::core::EBlockType)block_header.type != bgcode::core::EBlockType::GCode)
res = read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
if ((EBlockType)block_header.type != EBlockType::GCode)
throw Slic3r::RuntimeError("Unable to find gcode block in file: " + filename + "\n");
while ((bgcode::core::EBlockType)block_header.type == bgcode::core::EBlockType::GCode) {
bgcode::binarize::GCodeBlock block;
while ((EBlockType)block_header.type == EBlockType::GCode) {
GCodeBlock block;
res = block.read_data(*file.f, file_header, block_header);
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
// TODO: Update m_result.lines_ends
@ -1293,9 +1296,9 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct
if (ftell(file.f) == file_size)
break;
res = bgcode::core::read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(bgcode::core::translate_result(res)) + "\n");
res = read_next_block_header(*file.f, file_header, block_header, cs_buffer.data(), cs_buffer.size());
if (res != EResult::Success)
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
}
// Don't post-process the G-code to update time stamps.
@ -3709,8 +3712,9 @@ void GCodeProcessor::post_process()
}
}
const bgcode::core::EResult res = m_binarizer.initialize(*out.f, s_binarizer_config);
if (res != bgcode::core::EResult::Success)
using namespace bgcode::core;
const EResult res = m_binarizer.initialize(*out.f, s_binarizer_config);
if (res != EResult::Success)
throw Slic3r::RuntimeError(std::string("Unable to initialize the gcode binarizer.\n"));
}
#endif // ENABLE_BINARIZED_GCODE
@ -4000,8 +4004,7 @@ void GCodeProcessor::post_process()
#if ENABLE_BINARIZED_GCODE
if (m_binarizer.is_enabled()) {
bgcode::core::EResult res = m_binarizer.append_gcode(out_string);
if (res != bgcode::core::EResult::Success)
if (m_binarizer.append_gcode(out_string) != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError(std::string("Error while sending gcode to the binarizer.\n"));
}
else
@ -4380,8 +4383,7 @@ void GCodeProcessor::post_process()
#if ENABLE_BINARIZED_GCODE
if (m_binarizer.is_enabled()) {
const bgcode::core::EResult res = m_binarizer.finalize();
if (res != bgcode::core::EResult::Success)
if (m_binarizer.finalize() != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError(std::string("Error while finalizing the gcode binarizer.\n"));
}
#endif // ENABLE_BINARIZED_GCODE

View File

@ -64,6 +64,8 @@ template<typename ThrowIfCanceledCallback>
inline void generate_binary_thumbnails(ThumbnailsGeneratorCallback& thumbnail_cb, std::vector<bgcode::binarize::ThumbnailBlock>& out_thumbnails,
const std::vector<Vec2d>& sizes, GCodeThumbnailsFormat format, ThrowIfCanceledCallback throw_if_canceled)
{
using namespace bgcode::core;
using namespace bgcode::binarize;
out_thumbnails.clear();
if (thumbnail_cb != nullptr) {
ThumbnailsList thumbnails = thumbnail_cb(ThumbnailsParams{ sizes, true, true, true, true });
@ -71,13 +73,13 @@ inline void generate_binary_thumbnails(ThumbnailsGeneratorCallback& thumbnail_cb
if (data.is_valid()) {
auto compressed = compress_thumbnail(data, format);
if (compressed->data != nullptr && compressed->size > 0) {
bgcode::binarize::ThumbnailBlock& block = out_thumbnails.emplace_back(bgcode::binarize::ThumbnailBlock());
ThumbnailBlock& block = out_thumbnails.emplace_back(ThumbnailBlock());
block.params.width = (uint16_t)data.width;
block.params.height = (uint16_t)data.height;
switch (format) {
case GCodeThumbnailsFormat::PNG: { block.params.format = (uint16_t)bgcode::core::EThumbnailFormat::PNG; break; }
case GCodeThumbnailsFormat::JPG: { block.params.format = (uint16_t)bgcode::core::EThumbnailFormat::JPG; break; }
case GCodeThumbnailsFormat::QOI: { block.params.format = (uint16_t)bgcode::core::EThumbnailFormat::QOI; break; }
case GCodeThumbnailsFormat::PNG: { block.params.format = (uint16_t)EThumbnailFormat::PNG; break; }
case GCodeThumbnailsFormat::JPG: { block.params.format = (uint16_t)EThumbnailFormat::JPG; break; }
case GCodeThumbnailsFormat::QOI: { block.params.format = (uint16_t)EThumbnailFormat::QOI; break; }
}
block.data.resize(compressed->size);
memcpy(block.data.data(), compressed->data, compressed->size);

View File

@ -7879,6 +7879,7 @@ void GLCanvas3D::show_binary_gcode_debug_window()
ImGuiWrapper& imgui = *wxGetApp().imgui();
imgui.begin(std::string("Binary GCode"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
using namespace bgcode::core;
if (ImGui::BeginTable("BinaryGCodeConfig", 2)) {
ImGui::TableNextRow();
@ -7888,7 +7889,7 @@ void GLCanvas3D::show_binary_gcode_debug_window()
std::vector<std::string> options = { "None", "Deflate", "heatshrink 11,4", "heatshrink 12,4" };
int option_id = (int)binarizer_config.compression.file_metadata;
if (imgui.combo(std::string("##file_metadata_compression"), options, option_id, ImGuiComboFlags_HeightLargest, 0.0f, 175.0f))
binarizer_config.compression.file_metadata = (bgcode::core::ECompressionType)option_id;
binarizer_config.compression.file_metadata = (ECompressionType)option_id;
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
@ -7896,7 +7897,7 @@ void GLCanvas3D::show_binary_gcode_debug_window()
ImGui::TableSetColumnIndex(1);
option_id = (int)binarizer_config.compression.printer_metadata;
if (imgui.combo(std::string("##printer_metadata_compression"), options, option_id, ImGuiComboFlags_HeightLargest, 0.0f, 175.0f))
binarizer_config.compression.printer_metadata = (bgcode::core::ECompressionType)option_id;
binarizer_config.compression.printer_metadata = (ECompressionType)option_id;
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
@ -7904,7 +7905,7 @@ void GLCanvas3D::show_binary_gcode_debug_window()
ImGui::TableSetColumnIndex(1);
option_id = (int)binarizer_config.compression.print_metadata;
if (imgui.combo(std::string("##print_metadata_compression"), options, option_id, ImGuiComboFlags_HeightLargest, 0.0f, 175.0f))
binarizer_config.compression.print_metadata = (bgcode::core::ECompressionType)option_id;
binarizer_config.compression.print_metadata = (ECompressionType)option_id;
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
@ -7912,7 +7913,7 @@ void GLCanvas3D::show_binary_gcode_debug_window()
ImGui::TableSetColumnIndex(1);
option_id = (int)binarizer_config.compression.slicer_metadata;
if (imgui.combo(std::string("##slicer_metadata_compression"), options, option_id, ImGuiComboFlags_HeightLargest, 0.0f, 175.0f))
binarizer_config.compression.slicer_metadata = (bgcode::core::ECompressionType)option_id;
binarizer_config.compression.slicer_metadata = (ECompressionType)option_id;
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
@ -7920,7 +7921,7 @@ void GLCanvas3D::show_binary_gcode_debug_window()
ImGui::TableSetColumnIndex(1);
option_id = (int)binarizer_config.compression.gcode;
if (imgui.combo(std::string("##gcode_compression"), options, option_id, ImGuiComboFlags_HeightLargest, 0.0f, 175.0f))
binarizer_config.compression.gcode = (bgcode::core::ECompressionType)option_id;
binarizer_config.compression.gcode = (ECompressionType)option_id;
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
@ -7929,7 +7930,7 @@ void GLCanvas3D::show_binary_gcode_debug_window()
options = { "None", "MeatPack", "MeatPack Comments" };
option_id = (int)binarizer_config.gcode_encoding;
if (imgui.combo(std::string("##gcode_encoding"), options, option_id, ImGuiComboFlags_HeightLargest, 0.0f, 175.0f))
binarizer_config.gcode_encoding = (bgcode::core::EGCodeEncodingType)option_id;
binarizer_config.gcode_encoding = (EGCodeEncodingType)option_id;
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
@ -7938,7 +7939,7 @@ void GLCanvas3D::show_binary_gcode_debug_window()
options = { "INI" };
option_id = (int)binarizer_config.metadata_encoding;
if (imgui.combo(std::string("##metadata_encoding"), options, option_id, ImGuiComboFlags_HeightLargest, 0.0f, 175.0f))
binarizer_config.metadata_encoding = (bgcode::core::EMetadataEncodingType)option_id;
binarizer_config.metadata_encoding = (EMetadataEncodingType)option_id;
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
@ -7947,7 +7948,7 @@ void GLCanvas3D::show_binary_gcode_debug_window()
options = { "None", "CRC32" };
option_id = (int)binarizer_config.checksum;
if (imgui.combo(std::string("##4"), options, option_id, ImGuiComboFlags_HeightLargest, 0.0f, 175.0f))
binarizer_config.checksum = (bgcode::core::EChecksumType)option_id;
binarizer_config.checksum = (EChecksumType)option_id;
ImGui::EndTable();

View File

@ -5466,9 +5466,10 @@ void Plater::convert_gcode_to_ascii()
// Perform conversion
{
wxBusyCursor busy;
bgcode::core::EResult res = bgcode::convert::from_binary_to_ascii(*in_file.f, *out_file.f, true);
if (res != bgcode::core::EResult::Success) {
MessageDialog msg_dlg(this, _L(std::string(bgcode::core::translate_result(res))), _L("Error converting gcode file"), wxICON_INFORMATION | wxOK);
using namespace bgcode::core;
EResult res = bgcode::convert::from_binary_to_ascii(*in_file.f, *out_file.f, true);
if (res != EResult::Success) {
MessageDialog msg_dlg(this, _L(std::string(translate_result(res))), _L("Error converting gcode file"), wxICON_INFORMATION | wxOK);
msg_dlg.ShowModal();
out_file.close();
boost::nowide::remove(output_file.c_str());
@ -5511,10 +5512,11 @@ void Plater::convert_gcode_to_binary()
// Perform conversion
{
wxBusyCursor busy;
using namespace bgcode::core;
const bgcode::binarize::BinarizerConfig& binarizer_config = GCodeProcessor::get_binarizer_config();
bgcode::core::EResult res = bgcode::convert::from_ascii_to_binary(*in_file.f, *out_file.f, binarizer_config);
if (res != bgcode::core::EResult::Success) {
MessageDialog msg_dlg(this, _L(std::string(bgcode::core::translate_result(res))), _L("Error converting gcode file"), wxICON_INFORMATION | wxOK);
EResult res = bgcode::convert::from_ascii_to_binary(*in_file.f, *out_file.f, binarizer_config);
if (res != EResult::Success) {
MessageDialog msg_dlg(this, _L(std::string(translate_result(res))), _L("Error converting gcode file"), wxICON_INFORMATION | wxOK);
msg_dlg.ShowModal();
out_file.close();
boost::nowide::remove(output_file.c_str());