mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 04:42:00 +08:00
SPE-1899: Fixed out-of-synch of preview's moves slider, tool position and gcode window when export to binary gcode is enabled
This commit is contained in:
parent
758ef7b03c
commit
c19ae886ec
@ -4328,62 +4328,22 @@ void GCodeProcessor::post_process()
|
|||||||
out.close();
|
out.close();
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
|
const std::string result_filename = m_result.filename;
|
||||||
if (m_binarizer.is_enabled()) {
|
if (m_binarizer.is_enabled()) {
|
||||||
// updates m_result.lines_ends from binarized gcode file
|
// The list of lines in the binary gcode is different from the original one.
|
||||||
m_result.lines_ends.clear();
|
// This requires to re-process the binarized file to be able to synchronize with it all the data needed by the preview,
|
||||||
|
// as gcode window, tool position and moves slider which relies on indexing the gcode lines.
|
||||||
FilePtr file(boost::nowide::fopen(out_path.c_str(), "rb"));
|
reset();
|
||||||
if (file.f != nullptr) {
|
// the following call modifies m_result.filename
|
||||||
fseek(file.f, 0, SEEK_END);
|
process_binary_file(out_path);
|
||||||
const long file_size = ftell(file.f);
|
// restore the proper filename
|
||||||
rewind(file.f);
|
m_result.filename = result_filename;
|
||||||
|
|
||||||
// read file header
|
|
||||||
using namespace bgcode::core;
|
|
||||||
using namespace bgcode::binarize;
|
|
||||||
FileHeader file_header;
|
|
||||||
EResult res = read_header(*file.f, file_header, nullptr);
|
|
||||||
if (res == EResult::Success) {
|
|
||||||
// search first GCode block
|
|
||||||
BlockHeader block_header;
|
|
||||||
res = read_next_block_header(*file.f, file_header, block_header, EBlockType::GCode, nullptr, 0);
|
|
||||||
while (res == EResult::Success) {
|
|
||||||
GCodeBlock block;
|
|
||||||
res = block.read_data(*file.f, file_header, block_header);
|
|
||||||
if (res != EResult::Success)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// extract lines ends from block
|
|
||||||
std::vector<size_t>& lines_ends = m_result.lines_ends.emplace_back(std::vector<size_t>());
|
|
||||||
for (size_t i = 0; i < block.raw_data.size(); ++i) {
|
|
||||||
if (block.raw_data[i] == '\n')
|
|
||||||
lines_ends.emplace_back(i + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ftell(file.f) == file_size)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// read next block header
|
|
||||||
res = read_next_block_header(*file.f, file_header, block_header, nullptr, 0);
|
|
||||||
if (res != EResult::Success)
|
|
||||||
break;
|
|
||||||
if (block_header.type != (uint16_t)EBlockType::GCode) {
|
|
||||||
res = EResult::InvalidBlockType;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res != EResult::Success && !m_result.lines_ends.empty() && !m_result.lines_ends.front().empty())
|
|
||||||
// some error occourred, clear lines ends
|
|
||||||
m_result.lines_ends = { std::vector<size_t>() };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
export_lines.synchronize_moves(m_result);
|
||||||
|
|
||||||
export_lines.synchronize_moves(m_result);
|
if (rename_file(out_path, result_filename))
|
||||||
|
throw Slic3r::RuntimeError(std::string("Failed to rename the output G-code file from ") + out_path + " to " + result_filename + '\n' +
|
||||||
if (rename_file(out_path, m_result.filename))
|
|
||||||
throw Slic3r::RuntimeError(std::string("Failed to rename the output G-code file from ") + out_path + " to " + m_result.filename + '\n' +
|
|
||||||
"Is " + out_path + " locked?" + '\n');
|
"Is " + out_path + " locked?" + '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user