mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-31 07:42:03 +08:00
Added debug imgui dialog to allow to change binary gcode parameters at runtime
This commit is contained in:
parent
a11009c3e0
commit
ee87536ff6
@ -12,7 +12,7 @@
|
||||
namespace BinaryGCode {
|
||||
|
||||
static size_t g_checksum_max_cache_size = 65536;
|
||||
static const size_t MAX_GCODE_CACHE_SIZE = 65536;
|
||||
static constexpr size_t MAX_GCODE_CACHE_SIZE = 65536;
|
||||
|
||||
std::string translate_result(BinaryGCode::EResult result)
|
||||
{
|
||||
@ -110,17 +110,17 @@ static bool decode_metadata(const std::vector<uint8_t>& src, std::vector<std::pa
|
||||
{
|
||||
case EMetadataEncodingType::INI:
|
||||
{
|
||||
auto start_it = src.begin();
|
||||
auto begin_it = src.begin();
|
||||
auto end_it = src.begin();
|
||||
while (end_it != src.end()) {
|
||||
while (end_it != src.end() && *end_it != '\n') {
|
||||
++end_it;
|
||||
}
|
||||
const std::string item(start_it, end_it);
|
||||
const std::string item(begin_it, end_it);
|
||||
const size_t pos = item.find_first_of('=');
|
||||
if (pos != std::string::npos) {
|
||||
dst.emplace_back(std::make_pair(item.substr(0, pos), item.substr(pos + 1)));
|
||||
start_it = ++end_it;
|
||||
begin_it = ++end_it;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -787,15 +787,14 @@ EResult ChecksumBlock::read_data(FILE& file, const BlockHeader& block_header)
|
||||
}
|
||||
#endif // ENABLE_CHECKSUM_BLOCK
|
||||
|
||||
EResult Binarizer::initialize(FILE& file, EGCodeEncodingType gcode_encoding_type, EChecksumType checksum_type)
|
||||
EResult Binarizer::initialize(FILE& file, const BinarizerConfig& config)
|
||||
{
|
||||
if (!m_enabled)
|
||||
return EResult::Success;
|
||||
|
||||
m_file = &file;
|
||||
|
||||
m_gcode_encoding_type = gcode_encoding_type;
|
||||
m_checksum_type = checksum_type;
|
||||
m_config = config;
|
||||
#if ENABLE_CHECKSUM_BLOCK
|
||||
// initialize checksum
|
||||
m_checksum = ChecksumBlock();
|
||||
@ -803,35 +802,35 @@ EResult Binarizer::initialize(FILE& file, EGCodeEncodingType gcode_encoding_type
|
||||
|
||||
// save header
|
||||
FileHeader file_header;
|
||||
file_header.checksum_type = (uint16_t)m_checksum_type;
|
||||
file_header.checksum_type = (uint16_t)m_config.checksum;
|
||||
EResult res = file_header.write(*m_file);
|
||||
if (res != EResult::Success)
|
||||
return res;
|
||||
|
||||
// save file metadata block
|
||||
res = m_binary_data.file_metadata.write(*m_file, m_compression_type, m_checksum_type);
|
||||
res = m_binary_data.file_metadata.write(*m_file, m_config.compression, m_config.checksum);
|
||||
if (res != EResult::Success)
|
||||
return res;
|
||||
|
||||
// save printer metadata block
|
||||
res = m_binary_data.printer_metadata.write(*m_file, m_compression_type, m_checksum_type);
|
||||
res = m_binary_data.printer_metadata.write(*m_file, m_config.compression, m_config.checksum);
|
||||
if (res != EResult::Success)
|
||||
return res;
|
||||
|
||||
// save thumbnail blocks
|
||||
for (const ThumbnailBlock& block : m_binary_data.thumbnails) {
|
||||
res = block.write(*m_file, m_checksum_type);
|
||||
res = block.write(*m_file, m_config.checksum);
|
||||
if (res != EResult::Success)
|
||||
return res;
|
||||
}
|
||||
|
||||
// save print metadata block
|
||||
res = m_binary_data.print_metadata.write(*m_file, m_compression_type, m_checksum_type);
|
||||
res = m_binary_data.print_metadata.write(*m_file, m_config.compression, m_config.checksum);
|
||||
if (res != EResult::Success)
|
||||
return res;
|
||||
|
||||
// save slicer metadata block
|
||||
res = m_binary_data.slicer_metadata.write(*m_file, m_compression_type, m_checksum_type);
|
||||
res = m_binary_data.slicer_metadata.write(*m_file, m_config.compression, m_config.checksum);
|
||||
if (res != EResult::Success)
|
||||
return res;
|
||||
|
||||
@ -866,7 +865,7 @@ EResult Binarizer::append_gcode(const std::string& gcode)
|
||||
const size_t line_size = 1 + end_line_pos - begin_pos;
|
||||
if (line_size + m_gcode_cache.length() > MAX_GCODE_CACHE_SIZE) {
|
||||
if (!m_gcode_cache.empty()) {
|
||||
const EResult res = write_gcode_block(*m_file, m_gcode_cache, m_gcode_encoding_type, m_compression_type, m_checksum_type);
|
||||
const EResult res = write_gcode_block(*m_file, m_gcode_cache, m_config.gcode_encoding, m_config.compression, m_config.checksum);
|
||||
if (res != EResult::Success)
|
||||
// propagate error
|
||||
return res;
|
||||
@ -892,7 +891,7 @@ EResult Binarizer::finalize()
|
||||
|
||||
// save gcode cache, if not empty
|
||||
if (!m_gcode_cache.empty()) {
|
||||
const EResult res = write_gcode_block(*m_file, m_gcode_cache, m_gcode_encoding_type, m_compression_type, m_checksum_type);
|
||||
const EResult res = write_gcode_block(*m_file, m_gcode_cache, m_config.gcode_encoding, m_config.compression, m_config.checksum);
|
||||
if (res != EResult::Success)
|
||||
// propagate error
|
||||
return res;
|
||||
|
@ -252,27 +252,31 @@ struct BinaryData
|
||||
}
|
||||
};
|
||||
|
||||
struct BinarizerConfig
|
||||
{
|
||||
ECompressionType compression{ ECompressionType::None };
|
||||
EGCodeEncodingType gcode_encoding{ EGCodeEncodingType::None };
|
||||
EMetadataEncodingType metadata_encoding{ EMetadataEncodingType::INI };
|
||||
EChecksumType checksum{ EChecksumType::None };
|
||||
};
|
||||
|
||||
class Binarizer
|
||||
{
|
||||
public:
|
||||
bool is_enabled() const { return m_enabled; }
|
||||
void set_enabled(bool enable) { m_enabled = enable; }
|
||||
void set_compression_type(ECompressionType type) { m_compression_type = type; }
|
||||
|
||||
BinaryData& get_binary_data() { return m_binary_data; }
|
||||
const BinaryData& get_binary_data() const { return m_binary_data; }
|
||||
|
||||
EResult initialize(FILE& file, EGCodeEncodingType gcode_encoding_type, EChecksumType checksum_type);
|
||||
EResult initialize(FILE& file, const BinarizerConfig& config);
|
||||
EResult append_gcode(const std::string& gcode);
|
||||
EResult finalize();
|
||||
|
||||
private:
|
||||
bool m_enabled{ false };
|
||||
|
||||
EChecksumType m_checksum_type{ EChecksumType::None };
|
||||
ECompressionType m_compression_type{ ECompressionType::None };
|
||||
EGCodeEncodingType m_gcode_encoding_type{ EGCodeEncodingType::None };
|
||||
|
||||
BinarizerConfig m_config;
|
||||
FILE* m_file{ nullptr };
|
||||
BinaryData m_binary_data;
|
||||
std::string m_gcode_cache;
|
||||
|
@ -69,6 +69,10 @@ const std::vector<std::string> GCodeProcessor::Reserved_Tags = {
|
||||
const float GCodeProcessor::Wipe_Width = 0.05f;
|
||||
const float GCodeProcessor::Wipe_Height = 0.05f;
|
||||
|
||||
#if ENABLE_BINARIZED_GCODE
|
||||
BinaryGCode::BinarizerConfig GCodeProcessor::s_binarizer_config{};
|
||||
#endif // ENABLE_BINARIZED
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||
const std::string GCodeProcessor::Mm3_Per_Mm_Tag = "MM3_PER_MM:";
|
||||
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||
@ -3716,7 +3720,7 @@ void GCodeProcessor::post_process()
|
||||
}
|
||||
}
|
||||
|
||||
const BinaryGCode::EResult res = m_binarizer.initialize(*out.f, BinaryGCode::EGCodeEncodingType::None, BinaryGCode::EChecksumType::CRC32);
|
||||
const BinaryGCode::EResult res = m_binarizer.initialize(*out.f, s_binarizer_config);
|
||||
if (res != BinaryGCode::EResult::Success)
|
||||
throw Slic3r::RuntimeError(std::string("Unable to initialize the gcode binarizer.\n"));
|
||||
}
|
||||
|
@ -527,10 +527,15 @@ namespace Slic3r {
|
||||
};
|
||||
#endif // ENABLE_GCODE_VIEWER_DATA_CHECKING
|
||||
|
||||
#if ENABLE_BINARIZED_GCODE_DEBUG_WINDOW
|
||||
static BinaryGCode::BinarizerConfig& get_binarizer_config() { return s_binarizer_config; }
|
||||
#endif // ENABLE_BINARIZED_GCODE_DEBUG_WINDOW
|
||||
|
||||
private:
|
||||
GCodeReader m_parser;
|
||||
#if ENABLE_BINARIZED_GCODE
|
||||
BinaryGCode::Binarizer m_binarizer;
|
||||
static BinaryGCode::BinarizerConfig s_binarizer_config;
|
||||
#endif // ENABLE_BINARIZED_GCODE
|
||||
|
||||
EUnits m_units;
|
||||
|
@ -69,6 +69,7 @@
|
||||
|
||||
// Enable export of binarized gcode
|
||||
#define ENABLE_BINARIZED_GCODE (1 && ENABLE_2_6_1_ALPHA1)
|
||||
#define ENABLE_BINARIZED_GCODE_DEBUG_WINDOW (1 && ENABLE_BINARIZED_GCODE)
|
||||
|
||||
|
||||
#endif // _prusaslicer_technologies_h_
|
||||
|
@ -2048,6 +2048,11 @@ void GLCanvas3D::render()
|
||||
#endif // ENABLE_SLA_VIEW_DEBUG_WINDOW
|
||||
}
|
||||
|
||||
#if ENABLE_BINARIZED_GCODE_DEBUG_WINDOW
|
||||
if (wxGetApp().plater()->is_view3D_shown() && current_printer_technology() != ptSLA && fff_print()->config().gcode_binary)
|
||||
show_binary_gcode_debug_window();
|
||||
#endif // ENABLE_BINARIZED_GCODE_DEBUG_WINDOW
|
||||
|
||||
std::string tooltip;
|
||||
|
||||
// Negative coordinate means out of the window, likely because the window was deactivated.
|
||||
@ -7866,6 +7871,62 @@ void GLCanvas3D::GizmoHighlighter::blink()
|
||||
invalidate();
|
||||
}
|
||||
|
||||
#if ENABLE_BINARIZED_GCODE_DEBUG_WINDOW
|
||||
void GLCanvas3D::show_binary_gcode_debug_window()
|
||||
{
|
||||
BinaryGCode::BinarizerConfig& binarizer_config = GCodeProcessor::get_binarizer_config();
|
||||
|
||||
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
||||
imgui.begin(std::string("Binary GCode"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
|
||||
|
||||
if (ImGui::BeginTable("BinaryGCodeConfig", 2)) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Compression");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const std::vector<std::string> gcode_compressions = { "None" };
|
||||
int compression = (int)binarizer_config.compression;
|
||||
if (imgui.combo(std::string("##1"), gcode_compressions, compression, ImGuiComboFlags_HeightLargest, 0.0f, 100.0f))
|
||||
binarizer_config.compression = (BinaryGCode::ECompressionType)compression;
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "GGcode encoding");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const std::vector<std::string> gcode_encodings = { "None", "MeatPack" };
|
||||
int gcode_encoding = (int)binarizer_config.gcode_encoding;
|
||||
if (imgui.combo(std::string("##2"), gcode_encodings, gcode_encoding, ImGuiComboFlags_HeightLargest, 0.0f, 100.0f))
|
||||
binarizer_config.gcode_encoding = (BinaryGCode::EGCodeEncodingType)gcode_encoding;
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Metadata encoding");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const std::vector<std::string> metadata_encodings = { "INI" };
|
||||
int metadata_encoding = (int)binarizer_config.metadata_encoding;
|
||||
if (imgui.combo(std::string("##3"), metadata_encodings, metadata_encoding, ImGuiComboFlags_HeightLargest, 0.0f, 100.0f))
|
||||
binarizer_config.metadata_encoding = (BinaryGCode::EMetadataEncodingType)metadata_encoding;
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Checksum type");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const std::vector<std::string> checksums = { "None", "CRC32" };
|
||||
int checksum = (int)binarizer_config.checksum;
|
||||
if (imgui.combo(std::string("##4"), checksums, checksum, ImGuiComboFlags_HeightLargest, 0.0f, 100.0f))
|
||||
binarizer_config.checksum = (BinaryGCode::EChecksumType)checksum;
|
||||
|
||||
ImGui::EndTable();
|
||||
|
||||
ImGui::Separator();
|
||||
imgui.text("!!! WARNING !!!");
|
||||
imgui.text("Changing values does NOT invalidate the current slice");
|
||||
}
|
||||
|
||||
imgui.end();
|
||||
}
|
||||
#endif // ENABLE_BINARIZED_GCODE_DEBUG_WINDOW
|
||||
|
||||
const ModelVolume *get_model_volume(const GLVolume &v, const Model &model)
|
||||
{
|
||||
const ModelVolume * ret = nullptr;
|
||||
|
@ -1113,6 +1113,10 @@ private:
|
||||
bool _deactivate_arrange_menu();
|
||||
|
||||
float get_overlay_window_width() { return LayersEditing::get_overlay_window_width(); }
|
||||
|
||||
#if ENABLE_BINARIZED_GCODE_DEBUG_WINDOW
|
||||
void show_binary_gcode_debug_window();
|
||||
#endif // ENABLE_BINARIZED_GCODE_DEBUG_WINDOW
|
||||
};
|
||||
|
||||
const ModelVolume *get_model_volume(const GLVolume &v, const Model &model);
|
||||
|
@ -782,7 +782,8 @@ bool ImGuiWrapper::combo(const wxString& label, const std::vector<std::string>&
|
||||
bool ImGuiWrapper::combo(const std::string& label, const std::vector<std::string>& options, int& selection, ImGuiComboFlags flags/* = 0*/, float label_width/* = 0.0f*/, float item_width/* = 0.0f*/)
|
||||
{
|
||||
// this is to force the label to the left of the widget:
|
||||
if (!label.empty()) {
|
||||
const bool hidden_label = boost::starts_with(label, "##");
|
||||
if (!label.empty() && !hidden_label) {
|
||||
text(label);
|
||||
ImGui::SameLine(label_width);
|
||||
}
|
||||
@ -792,7 +793,7 @@ bool ImGuiWrapper::combo(const std::string& label, const std::vector<std::string
|
||||
bool res = false;
|
||||
|
||||
const char *selection_str = selection < int(options.size()) && selection >= 0 ? options[selection].c_str() : "";
|
||||
if (ImGui::BeginCombo(("##" + label).c_str(), selection_str, flags)) {
|
||||
if (ImGui::BeginCombo(hidden_label ? label.c_str() : ("##" + label).c_str(), selection_str, flags)) {
|
||||
for (int i = 0; i < (int)options.size(); i++) {
|
||||
if (ImGui::Selectable(options[i].c_str(), i == selection)) {
|
||||
selection_out = i;
|
||||
|
Loading…
x
Reference in New Issue
Block a user