Few small refactorings

This commit is contained in:
enricoturri1966 2023-08-21 14:26:03 +02:00
parent aec962c295
commit bfbe4dacae
4 changed files with 16 additions and 22 deletions

View File

@ -1077,16 +1077,14 @@ ConfigSubstitutions ConfigBase::load_from_binary_gcode_file(const std::string& f
std::vector<uint8_t> cs_buffer(65536);
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(translate_result(res))));
rewind(file.f);
throw Slic3r::RuntimeError(format("The selected file is not a valid binary gcode.\nError: %1%", std::string(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))));
// searches for config block
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)
@ -1098,6 +1096,7 @@ ConfigSubstitutions ConfigBase::load_from_binary_gcode_file(const std::string& f
if (res != EResult::Success)
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(translate_result(res))));
// extracts data from block
for (const auto& [key, value] : slicer_metadata_block.raw_data) {
this->set_deserialize(key, value, substitutions_ctxt);
}

View File

@ -1214,13 +1214,10 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
binary_data.printer_metadata.raw_data.emplace_back("extruder_colour", extruder_colours_str); // duplicated into config data
}
}
// modifies m_silent_time_estimator_enabled
DoExport::init_gcode_processor(print.config(), m_processor, m_silent_time_estimator_enabled);
#else
// modifies m_silent_time_estimator_enabled
DoExport::init_gcode_processor(print.config(), m_processor, m_silent_time_estimator_enabled);
#endif // ENABLE_BINARIZED_GCODE
// modifies m_silent_time_estimator_enabled
DoExport::init_gcode_processor(print.config(), m_processor, m_silent_time_estimator_enabled);
if (! print.config().gcode_substitutions.values.empty()) {
m_find_replace = make_unique<GCodeFindReplace>(print.config());

View File

@ -71,7 +71,7 @@ const float GCodeProcessor::Wipe_Height = 0.05f;
#if ENABLE_BINARIZED_GCODE
bgcode::binarize::BinarizerConfig GCodeProcessor::s_binarizer_config{};
#endif // ENABLE_BINARIZED
#endif // ENABLE_BINARIZED_GCODE
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
const std::string GCodeProcessor::Mm3_Per_Mm_Tag = "MM3_PER_MM:";
@ -1129,7 +1129,7 @@ void GCodeProcessor::process_ascii_file(const std::string& filename, std::functi
}
#if ENABLE_BINARIZED_GCODE
static void update_out_file_pos(const std::string& out_string, std::vector<size_t>& lines_ends, size_t* out_file_pos)
static void update_lines_ends_and_out_file_pos(const std::string& out_string, std::vector<size_t>& lines_ends, size_t* out_file_pos)
{
for (size_t i = 0; i < out_string.size(); ++i) {
if (out_string[i] == '\n')
@ -1306,7 +1306,7 @@ void GCodeProcessor::process_binary_file(const std::string& filename, std::funct
throw Slic3r::RuntimeError("Error while reading file '" + filename + "': " + std::string(translate_result(res)) + "\n");
std::vector<size_t>& lines_ends = m_result.lines_ends.emplace_back(std::vector<size_t>());
update_out_file_pos(block.raw_data, lines_ends, nullptr);
update_lines_ends_and_out_file_pos(block.raw_data, lines_ends, nullptr);
m_parser.parse_buffer(block.raw_data, [this](GCodeReader& reader, const GCodeReader::GCodeLine& line) {
this->process_gcode_line(line, true);
@ -3730,9 +3730,8 @@ void GCodeProcessor::post_process()
}
}
using namespace bgcode::core;
const EResult res = m_binarizer.initialize(*out.f, s_binarizer_config);
if (res != EResult::Success)
const bgcode::core::EResult res = m_binarizer.initialize(*out.f, s_binarizer_config);
if (res != bgcode::core::EResult::Success)
throw Slic3r::RuntimeError(std::string("Unable to initialize the gcode binarizer.\n"));
}
#endif // ENABLE_BINARIZED_GCODE
@ -3985,13 +3984,12 @@ 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 {
write_to_file(out, out_string, result, out_path);
update_out_file_pos(out_string, result.lines_ends.front(), &m_out_file_pos);
update_lines_ends_and_out_file_pos(out_string, result.lines_ends.front(), &m_out_file_pos);
}
#else
write_to_file(out, out_string, result, out_path);
@ -4018,7 +4016,7 @@ void GCodeProcessor::post_process()
}
else {
write_to_file(out, out_string, result, out_path);
update_out_file_pos(out_string, result.lines_ends.front(), &m_out_file_pos);
update_lines_ends_and_out_file_pos(out_string, result.lines_ends.front(), &m_out_file_pos);
}
#else
write_to_file(out, out_string, result, out_path);

View File

@ -69,9 +69,9 @@
// Enable export of binarized gcode
#define ENABLE_BINARIZED_GCODE (1 && ENABLE_2_6_2_ALPHA1)
#define ENABLE_BINARIZED_GCODE_DEBUG (1 && ENABLE_BINARIZED_GCODE)
#define ENABLE_BINARIZED_GCODE_DEBUG (0 && ENABLE_BINARIZED_GCODE)
#ifdef _WIN32
#define ENABLE_BINARIZED_GCODE_WIN_DEBUG (0 && ENABLE_BINARIZED_GCODE_DEBUG)
#define ENABLE_BINARIZED_GCODE_WIN_DEBUG (1 && ENABLE_BINARIZED_GCODE_DEBUG)
#endif // _WIN32
#define ENABLE_BINARIZED_GCODE_DEBUG_WINDOW (1 && ENABLE_BINARIZED_GCODE)