mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 03:25:53 +08:00
Few small refactorings
This commit is contained in:
parent
aec962c295
commit
bfbe4dacae
@ -1077,16 +1077,14 @@ ConfigSubstitutions ConfigBase::load_from_binary_gcode_file(const std::string& f
|
|||||||
std::vector<uint8_t> cs_buffer(65536);
|
std::vector<uint8_t> cs_buffer(65536);
|
||||||
EResult res = is_valid_binary_gcode(*file.f, true, cs_buffer.data(), cs_buffer.size());
|
EResult res = is_valid_binary_gcode(*file.f, true, cs_buffer.data(), cs_buffer.size());
|
||||||
if (res != EResult::Success)
|
if (res != EResult::Success)
|
||||||
throw Slic3r::RuntimeError(format("The selected file is not a valid binary gcode.\nError: %1%",
|
throw Slic3r::RuntimeError(format("The selected file is not a valid binary gcode.\nError: %1%", std::string(translate_result(res))));
|
||||||
std::string(translate_result(res))));
|
|
||||||
|
|
||||||
rewind(file.f);
|
|
||||||
|
|
||||||
FileHeader file_header;
|
FileHeader file_header;
|
||||||
res = read_header(*file.f, file_header, nullptr);
|
res = read_header(*file.f, file_header, nullptr);
|
||||||
if (res != EResult::Success)
|
if (res != EResult::Success)
|
||||||
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(translate_result(res))));
|
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(translate_result(res))));
|
||||||
|
|
||||||
|
// searches for config block
|
||||||
BlockHeader block_header;
|
BlockHeader block_header;
|
||||||
res = read_next_block_header(*file.f, file_header, block_header, EBlockType::SlicerMetadata, cs_buffer.data(), cs_buffer.size());
|
res = read_next_block_header(*file.f, file_header, block_header, EBlockType::SlicerMetadata, cs_buffer.data(), cs_buffer.size());
|
||||||
if (res != EResult::Success)
|
if (res != EResult::Success)
|
||||||
@ -1098,6 +1096,7 @@ ConfigSubstitutions ConfigBase::load_from_binary_gcode_file(const std::string& f
|
|||||||
if (res != EResult::Success)
|
if (res != EResult::Success)
|
||||||
throw Slic3r::RuntimeError(format("Error while reading file '%1%': %2%", filename, std::string(translate_result(res))));
|
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) {
|
for (const auto& [key, value] : slicer_metadata_block.raw_data) {
|
||||||
this->set_deserialize(key, value, substitutions_ctxt);
|
this->set_deserialize(key, value, substitutions_ctxt);
|
||||||
}
|
}
|
||||||
|
@ -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
|
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
|
#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()) {
|
if (! print.config().gcode_substitutions.values.empty()) {
|
||||||
m_find_replace = make_unique<GCodeFindReplace>(print.config());
|
m_find_replace = make_unique<GCodeFindReplace>(print.config());
|
||||||
|
@ -71,7 +71,7 @@ const float GCodeProcessor::Wipe_Height = 0.05f;
|
|||||||
|
|
||||||
#if ENABLE_BINARIZED_GCODE
|
#if ENABLE_BINARIZED_GCODE
|
||||||
bgcode::binarize::BinarizerConfig GCodeProcessor::s_binarizer_config{};
|
bgcode::binarize::BinarizerConfig GCodeProcessor::s_binarizer_config{};
|
||||||
#endif // ENABLE_BINARIZED
|
#endif // ENABLE_BINARIZED_GCODE
|
||||||
|
|
||||||
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||||
const std::string GCodeProcessor::Mm3_Per_Mm_Tag = "MM3_PER_MM:";
|
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
|
#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) {
|
for (size_t i = 0; i < out_string.size(); ++i) {
|
||||||
if (out_string[i] == '\n')
|
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");
|
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>());
|
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) {
|
m_parser.parse_buffer(block.raw_data, [this](GCodeReader& reader, const GCodeReader::GCodeLine& line) {
|
||||||
this->process_gcode_line(line, true);
|
this->process_gcode_line(line, true);
|
||||||
@ -3730,9 +3730,8 @@ void GCodeProcessor::post_process()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace bgcode::core;
|
const bgcode::core::EResult res = m_binarizer.initialize(*out.f, s_binarizer_config);
|
||||||
const EResult res = m_binarizer.initialize(*out.f, s_binarizer_config);
|
if (res != bgcode::core::EResult::Success)
|
||||||
if (res != EResult::Success)
|
|
||||||
throw Slic3r::RuntimeError(std::string("Unable to initialize the gcode binarizer.\n"));
|
throw Slic3r::RuntimeError(std::string("Unable to initialize the gcode binarizer.\n"));
|
||||||
}
|
}
|
||||||
#endif // ENABLE_BINARIZED_GCODE
|
#endif // ENABLE_BINARIZED_GCODE
|
||||||
@ -3985,13 +3984,12 @@ void GCodeProcessor::post_process()
|
|||||||
|
|
||||||
#if ENABLE_BINARIZED_GCODE
|
#if ENABLE_BINARIZED_GCODE
|
||||||
if (m_binarizer.is_enabled()) {
|
if (m_binarizer.is_enabled()) {
|
||||||
bgcode::core::EResult res = m_binarizer.append_gcode(out_string);
|
if (m_binarizer.append_gcode(out_string) != bgcode::core::EResult::Success)
|
||||||
if (res != bgcode::core::EResult::Success)
|
|
||||||
throw Slic3r::RuntimeError(std::string("Error while sending gcode to the binarizer.\n"));
|
throw Slic3r::RuntimeError(std::string("Error while sending gcode to the binarizer.\n"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
write_to_file(out, out_string, result, out_path);
|
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
|
#else
|
||||||
write_to_file(out, out_string, result, out_path);
|
write_to_file(out, out_string, result, out_path);
|
||||||
@ -4018,7 +4016,7 @@ void GCodeProcessor::post_process()
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
write_to_file(out, out_string, result, out_path);
|
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
|
#else
|
||||||
write_to_file(out, out_string, result, out_path);
|
write_to_file(out, out_string, result, out_path);
|
||||||
|
@ -69,9 +69,9 @@
|
|||||||
|
|
||||||
// Enable export of binarized gcode
|
// Enable export of binarized gcode
|
||||||
#define ENABLE_BINARIZED_GCODE (1 && ENABLE_2_6_2_ALPHA1)
|
#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
|
#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
|
#endif // _WIN32
|
||||||
#define ENABLE_BINARIZED_GCODE_DEBUG_WINDOW (1 && ENABLE_BINARIZED_GCODE)
|
#define ENABLE_BINARIZED_GCODE_DEBUG_WINDOW (1 && ENABLE_BINARIZED_GCODE)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user