From 99974c7f595751950329136482d527271d08b18c Mon Sep 17 00:00:00 2001 From: "salt.wei" Date: Mon, 17 Oct 2022 20:34:33 +0800 Subject: [PATCH] ENH: add warning info when bed temperature is too high Add bed temperature checker in gcode processer. And save slice warning into GcodeProcessorResult. Signed-off-by: salt.wei Change-Id: Iee96e4ab165a3171a5a1e165450bfc360401647f --- src/libslic3r/Format/bbs_3mf.cpp | 4 +- src/libslic3r/Format/bbs_3mf.hpp | 2 +- src/libslic3r/GCode/GCodeProcessor.cpp | 86 ++++++++++++++++++++++++++ src/libslic3r/GCode/GCodeProcessor.hpp | 18 +++++- src/slic3r/GUI/Plater.cpp | 2 +- src/slic3r/GUI/Plater.hpp | 2 +- src/slic3r/GUI/SelectMachine.cpp | 13 ++-- 7 files changed, 115 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index 352da9411..3a647eaba 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -464,7 +464,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) } /* only for test - GCodeProcessorResult::SliceWarnings sw; + GCodeProcessorResult::SliceWarning sw; sw.msg = BED_TEMP_TOO_HIGH_THAN_FILAMENT; sw.level = 1; result->warnings.push_back(sw); @@ -3226,7 +3226,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) if (m_curr_plater) { std::string msg = bbs_get_attribute_value_string(attributes, num_attributes, WARNING_MSG_TAG); std::string lvl_str = bbs_get_attribute_value_string(attributes, num_attributes, "level"); - GCodeProcessorResult::SliceWarnings sw; + GCodeProcessorResult::SliceWarning sw; sw.msg = msg; try { sw.level = atoi(lvl_str.c_str()); diff --git a/src/libslic3r/Format/bbs_3mf.hpp b/src/libslic3r/Format/bbs_3mf.hpp index f8bb92651..07d55f897 100644 --- a/src/libslic3r/Format/bbs_3mf.hpp +++ b/src/libslic3r/Format/bbs_3mf.hpp @@ -70,7 +70,7 @@ struct PlateData bool is_sliced_valid = false; bool toolpath_outside {false}; - std::vector warnings; + std::vector warnings; std::string get_gcode_prediction_str() { return gcode_prediction; diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index edfb73788..312389a4d 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -36,6 +36,7 @@ static const float DEFAULT_TRAVEL_ACCELERATION = 1250.0f; static const size_t MIN_EXTRUDERS_COUNT = 5; static const float DEFAULT_FILAMENT_DIAMETER = 1.75f; static const float DEFAULT_FILAMENT_DENSITY = 1.245f; +static const int DEFAULT_FILAMENT_VITRIFICATION_TEMPERATURE = 0; static const Slic3r::Vec3f DEFAULT_EXTRUDER_OFFSET = Slic3r::Vec3f::Zero(); namespace Slic3r { @@ -779,6 +780,7 @@ void GCodeProcessorResult::reset() { filament_diameters = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DIAMETER); filament_densities = std::vector(MIN_EXTRUDERS_COUNT, DEFAULT_FILAMENT_DENSITY); custom_gcode_per_print_z = std::vector(); + warnings.clear(); //BBS: add mutex for protection of gcode result unlock(); @@ -880,6 +882,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_extruder_colors.resize(extruders_count); m_result.filament_diameters.resize(extruders_count); m_result.filament_densities.resize(extruders_count); + m_result.filament_vitrification_temperature.resize(extruders_count); m_extruder_temps.resize(extruders_count); for (size_t i = 0; i < extruders_count; ++ i) { @@ -887,6 +890,7 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_extruder_colors[i] = static_cast(i); m_result.filament_diameters[i] = static_cast(config.filament_diameter.get_at(i)); m_result.filament_densities[i] = static_cast(config.filament_density.get_at(i)); + m_result.filament_vitrification_temperature[i] = static_cast(config.temperature_vitrification.get_at(i)); } if (m_flavor == gcfMarlinLegacy || m_flavor == gcfMarlinFirmware) { @@ -988,6 +992,20 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) m_result.filament_densities.emplace_back(DEFAULT_FILAMENT_DENSITY); } } + //BBS + const ConfigOptionInts* filament_vitrification_temperature = config.option("temperature_vitrification"); + if (filament_vitrification_temperature != nullptr) { + m_result.filament_vitrification_temperature.clear(); + m_result.filament_vitrification_temperature.resize(filament_vitrification_temperature->values.size()); + for (size_t i = 0; i < filament_vitrification_temperature->values.size(); ++i) { + m_result.filament_vitrification_temperature[i] = static_cast(filament_vitrification_temperature->values[i]); + } + } + if (m_result.filament_vitrification_temperature.size() < m_result.extruders_count) { + for (size_t i = m_result.filament_vitrification_temperature.size(); i < m_result.extruders_count; ++i) { + m_result.filament_vitrification_temperature.emplace_back(DEFAULT_FILAMENT_VITRIFICATION_TEMPERATURE); + } + } const ConfigOptionPoints* extruder_offset = config.option("extruder_offset"); const ConfigOptionBool* single_extruder_multi_material = config.option("single_extruder_multi_material"); @@ -1201,6 +1219,7 @@ void GCodeProcessor::reset() for (size_t i = 0; i < MIN_EXTRUDERS_COUNT; ++i) { m_extruder_temps[i] = 0.0f; } + m_highest_bed_temp = 0; m_extruded_last_z = 0.0f; m_zero_layer_height = 0.0f; @@ -1366,6 +1385,8 @@ void GCodeProcessor::finalize(bool post_process) #if ENABLE_GCODE_VIEWER_STATISTICS m_result.time = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_start_time).count(); #endif // ENABLE_GCODE_VIEWER_STATISTICS + //BBS: update slice warning + update_slice_warnings(); } float GCodeProcessor::get_time(PrintEstimatedStatistics::ETimeMode mode) const @@ -1655,6 +1676,16 @@ void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line, bool default: break; } break; + case '4': + switch (cmd[3]) { + case '0': { process_M140(line); break; } // Set bed temperature + default: break; + } + case '9': + switch (cmd[3]) { + case '0': { process_M190(line); break; } // Wait bed temperature + default: break; + } default: break; } @@ -3430,6 +3461,21 @@ void GCodeProcessor::process_M135(const GCodeReader::GCodeLine& line) process_T(cmd.substr(pos)); } +void GCodeProcessor::process_M140(const GCodeReader::GCodeLine& line) +{ + float new_temp; + if (line.has_value('S', new_temp)) + m_highest_bed_temp = m_highest_bed_temp < (int)new_temp ? (int)new_temp : m_highest_bed_temp; +} + +void GCodeProcessor::process_M190(const GCodeReader::GCodeLine& line) +{ + float new_temp; + if (line.has_value('S', new_temp)) + m_highest_bed_temp = m_highest_bed_temp < (int)new_temp ? (int)new_temp : m_highest_bed_temp; +} + + void GCodeProcessor::process_M201(const GCodeReader::GCodeLine& line) { // see http://reprap.org/wiki/G-code#M201:_Set_max_printing_acceleration @@ -3851,6 +3897,15 @@ float GCodeProcessor::get_filament_unload_time(size_t extruder_id) return m_time_processor.extruder_unloaded ? 0.0f : m_time_processor.filament_unload_times; } +//BBS +int GCodeProcessor::get_filament_vitrification_temperature(size_t extrude_id) +{ + if (extrude_id < m_result.filament_vitrification_temperature.size()) + return m_result.filament_vitrification_temperature[extrude_id]; + else + return 0; +} + void GCodeProcessor::process_custom_gcode_time(CustomGCode::Type code) { for (size_t i = 0; i < static_cast(PrintEstimatedStatistics::ETimeMode::Count); ++i) { @@ -3912,5 +3967,36 @@ void GCodeProcessor::update_estimated_times_stats() m_result.print_statistics.used_filaments_per_role = m_used_filaments.filaments_per_role; } +//BBS: ugly code... +void GCodeProcessor::update_slice_warnings() +{ + m_result.warnings.clear(); + + auto get_used_extruders = [this]() { + std::vector used_extruders; + used_extruders.reserve(m_used_filaments.volumes_per_extruder.size()); + for (auto item : m_used_filaments.volumes_per_extruder) { + used_extruders.push_back(item.first); + } + return used_extruders; + }; + + auto used_extruders = get_used_extruders(); + assert(!used_extruders.empty()); + if (m_highest_bed_temp != 0) { + for (size_t i = 0; i < used_extruders.size(); i++) { + int temperature = get_filament_vitrification_temperature(used_extruders[i]); + if (temperature != 0 && m_highest_bed_temp > temperature) { + GCodeProcessorResult::SliceWarning warning; + warning.level = 1; + warning.msg = BED_TEMP_TOO_HIGH_THAN_FILAMENT; + m_result.warnings.emplace_back(std::move(warning)); + } + } + } + + m_result.warnings.shrink_to_fit(); +} + } /* namespace Slic3r */ diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 108eef79b..05dab19b9 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -131,14 +131,12 @@ namespace Slic3r { } }; - struct SliceWarnings { + struct SliceWarning { int level; // 0: normal tips, 1: warning; 2: error std::string msg; // enum string std::vector params; // extra msg info }; - std::vector warnings; - std::string filename; unsigned int id; std::vector moves; @@ -155,8 +153,11 @@ namespace Slic3r { std::vector extruder_colors; std::vector filament_diameters; std::vector filament_densities; + std::vector filament_vitrification_temperature; PrintEstimatedStatistics print_statistics; std::vector custom_gcode_per_print_z; + //BBS + std::vector warnings; #if ENABLE_GCODE_VIEWER_STATISTICS int64_t time{ 0 }; @@ -182,6 +183,7 @@ namespace Slic3r { filament_densities = other.filament_densities; print_statistics = other.print_statistics; custom_gcode_per_print_z = other.custom_gcode_per_print_z; + warnings = other.warnings; #if ENABLE_GCODE_VIEWER_STATISTICS time = other.time; #endif @@ -604,6 +606,7 @@ namespace Slic3r { unsigned char m_last_extruder_id; ExtruderColors m_extruder_colors; ExtruderTemps m_extruder_temps; + int m_highest_bed_temp; float m_extruded_last_z; float m_first_layer_height; // mm float m_zero_layer_height; // mm @@ -770,6 +773,12 @@ namespace Slic3r { // Set tool (MakerWare) void process_M135(const GCodeReader::GCodeLine& line); + //BBS: Set bed temperature + void process_M140(const GCodeReader::GCodeLine& line); + + //BBS: wait bed temperature + void process_M190(const GCodeReader::GCodeLine& line); + // Set max printing acceleration void process_M201(const GCodeReader::GCodeLine& line); @@ -822,6 +831,7 @@ namespace Slic3r { void set_travel_acceleration(PrintEstimatedStatistics::ETimeMode mode, float value); float get_filament_load_time(size_t extruder_id); float get_filament_unload_time(size_t extruder_id); + int get_filament_vitrification_temperature(size_t extrude_id); void process_custom_gcode_time(CustomGCode::Type code); void process_filaments(CustomGCode::Type code); @@ -830,6 +840,8 @@ namespace Slic3r { void simulate_st_synchronize(float additional_time = 0.0f); void update_estimated_times_stats(); + //BBS: + void update_slice_warnings(); }; } /* namespace Slic3r */ diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ea271f1bd..2e512424a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2540,7 +2540,7 @@ wxColour Plater::get_next_color_for_filament() return colors[curr_color_filamenet++ % 7]; } -wxString Plater::get_slice_warning_string(GCodeProcessorResult::SliceWarnings& warning) +wxString Plater::get_slice_warning_string(GCodeProcessorResult::SliceWarning& warning) { if (warning.msg == BED_TEMP_TOO_HIGH_THAN_FILAMENT) { return _L("The bed temperature exceeds filament's vitrification temperature. Please open the front door of printer before printing to avoid nozzle clog."); diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index ae6d91dec..36442e2bf 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -235,7 +235,7 @@ public: static void setPrintSpeedTable(Slic3r::GlobalSpeedMap& printSpeedMap); static void setExtruderParams(std::map& extParas); static wxColour get_next_color_for_filament(); - static wxString get_slice_warning_string(GCodeProcessorResult::SliceWarnings& warning); + static wxString get_slice_warning_string(GCodeProcessorResult::SliceWarning& warning); // BBS: restore std::vector load_files(const std::vector& input_files, LoadStrategy strategy = LoadStrategy::LoadModel | LoadStrategy::LoadConfig, bool ask_multi = false); diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index b9707d1ea..95bcca0f5 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -1767,7 +1767,8 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) //Check Printer Model Id bool is_same_printer_type = is_same_printer_model(); - confirm_text += _L("The printer type used to generate G-code is not the same type as the currently selected physical printer. It is recommend to re-slice by selecting the same printer type.\n"); + if (!is_same_printer_type) + confirm_text += _L("The printer type used to generate G-code is not the same type as the currently selected physical printer. It is recommend to re-slice by selecting the same printer type.\n"); //Check slice warnings bool has_slice_warnings = false; @@ -1776,9 +1777,13 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) if (dev) { MachineObject* obj_ = dev->get_selected_machine(); for (auto warning : plate->get_slice_result()->warnings) { - if ((obj_->printer_type == "BL-P001" || obj_->printer_type == "BL-P002") && warning.msg == BED_TEMP_TOO_HIGH_THAN_FILAMENT) { - confirm_text += Plater::get_slice_warning_string(warning) + "\n"; - } else { + if (warning.msg == BED_TEMP_TOO_HIGH_THAN_FILAMENT) { + if ((obj_->printer_type == "BL-P001" || obj_->printer_type == "BL-P002")) { + confirm_text += Plater::get_slice_warning_string(warning) + "\n"; + has_slice_warnings = true; + } + } + else { has_slice_warnings = true; } }