From 9ed5d8a1a985e0fa6b65b716ea4de97d55a05ada Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Fri, 1 Nov 2024 15:01:40 +0800 Subject: [PATCH] ENH: use physical extruder map to get ext id jira: NONE Signed-off-by: xun.zhang Change-Id: Ibfaacfc31863404153a80289bd5cb47d72418060 (cherry picked from commit 8616784886afe119b39783559760794caea179d8) --- src/libslic3r/GCode/GCodeProcessor.cpp | 43 ++++++++++++++++---------- src/libslic3r/GCode/GCodeProcessor.hpp | 5 +-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index ce4cec180c..c10e48c0c4 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -1060,9 +1060,9 @@ void GCodeProcessor::run_post_process() } if (cmd.size() >= 2) { if (tool_number != -1) { - if (tool_number < 0 || (int)m_extruder_temps_config.size() <= tool_number) { + if (tool_number < 0 || (int)m_filament_nozzle_temp.size() <= tool_number) { // found an invalid value, clamp it to a valid one - tool_number = std::clamp(0, m_extruder_temps_config.size() - 1, tool_number); + tool_number = std::clamp(0, m_filament_nozzle_temp.size() - 1, tool_number); // emit warning std::string warning = "GCode Post-Processor encountered an invalid toolchange, maybe from a custom gcode:"; warning += "\n> "; @@ -1077,8 +1077,8 @@ void GCodeProcessor::run_post_process() backtrace, cmd, // line inserter [tool_number, this](unsigned int id, const std::vector& time_diffs) { - const int temperature = int(m_layer_id != 1 ? m_extruder_temps_config[tool_number] : - m_extruder_temps_first_layer_config[tool_number]); + const int temperature = int(m_layer_id != 1 ? m_filament_nozzle_temp[tool_number] : + m_filament_nozzle_temp_first_layer[tool_number]); // Orca: M104.1 for XL printers, I can't find the documentation for this so I copied the C++ comments from // Prusa-Firmware-Buddy here /** @@ -1101,9 +1101,10 @@ void GCodeProcessor::run_post_process() out += " S" + std::to_string(temperature) + "\n"; return out; } else { - std::string comment = "preheat T" + std::to_string(tool_number) + + const int real_tool = m_physical_extruder_map[tool_number]; + std::string comment = "preheat T" + std::to_string(real_tool) + " time: " + std::to_string((int) std::round(time_diffs[0])) + "s"; - return GCodeWriter::set_temperature(temperature, this->m_flavor, false, tool_number, comment); + return GCodeWriter::set_temperature(temperature, this->m_flavor, false, real_tool, comment); } }, // line replacer @@ -1115,7 +1116,7 @@ void GCodeProcessor::run_post_process() float val; if (gline.has_value('T', val) && gline.raw().find("cooldown") != std::string::npos) { - if (static_cast(val) == tool_number) + if (static_cast(val) == m_physical_extruder_map[tool_number]) return std::string("; removed M104\n"); } } @@ -1606,6 +1607,8 @@ void GCodeProcessor::apply_config(const PrintConfig& config) for (size_t idx = 0; idx < config.nozzle_volume.size(); ++idx) m_nozzle_volume[idx] = config.nozzle_volume.values[idx]; + m_physical_extruder_map = config.physical_extruder_map.values; + m_extruder_offsets.resize(filament_count); m_extruder_colors.resize(filament_count); m_result.filament_diameters.resize(filament_count); @@ -1614,8 +1617,8 @@ void GCodeProcessor::apply_config(const PrintConfig& config) m_result.filament_vitrification_temperature.resize(filament_count); m_result.filament_costs.resize(filament_count); m_extruder_temps.resize(filament_count); - m_extruder_temps_config.resize(filament_count); - m_extruder_temps_first_layer_config.resize(filament_count); + m_filament_nozzle_temp.resize(filament_count); + m_filament_nozzle_temp_first_layer.resize(filament_count); m_result.nozzle_hrc = static_cast(config.nozzle_hrc.getInt()); std::vector(config.nozzle_type.size()).swap(m_result.nozzle_type); for (size_t idx = 0; idx < m_result.nozzle_type.size(); ++idx) { @@ -1629,11 +1632,11 @@ void GCodeProcessor::apply_config(const PrintConfig& config) for (size_t i = 0; i < filament_count; ++ i) { m_extruder_offsets[i] = to_3d(config.extruder_offset.get_at(filament_map[i] - 1).cast().eval(), 0.f); m_extruder_colors[i] = static_cast(i); - m_extruder_temps_first_layer_config[i] = static_cast(config.nozzle_temperature_initial_layer.get_at(i)); - m_extruder_temps_config[i] = static_cast(config.nozzle_temperature.get_at(i)); - if (m_extruder_temps_config[i] == 0) { + m_filament_nozzle_temp_first_layer[i] = static_cast(config.nozzle_temperature_initial_layer.get_at(i)); + m_filament_nozzle_temp[i] = static_cast(config.nozzle_temperature.get_at(i)); + if (m_filament_nozzle_temp[i] == 0) { // This means the value should be ignored and first layer temp should be used. - m_extruder_temps_config[i] = m_extruder_temps_first_layer_config[i]; + m_filament_nozzle_temp[i] = m_filament_nozzle_temp_first_layer[i]; } m_result.filament_diameters[i] = static_cast(config.filament_diameter.get_at(i)); m_result.required_nozzle_HRC[i] = static_cast(config.required_nozzle_HRC.get_at(i)); @@ -1726,6 +1729,11 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) const ConfigOptionInt *nozzle_HRC = config.option("nozzle_hrc"); if (nozzle_HRC != nullptr) m_result.nozzle_hrc = nozzle_HRC->value; + const ConfigOptionInts* physical_extruder_map = config.option("physical_extruder_map"); + if (physical_extruder_map != nullptr) { + m_physical_extruder_map = physical_extruder_map->values; + } + const ConfigOptionEnumsGenericNullable* nozzle_type = config.option("nozzle_type"); if (nozzle_type != nullptr) { m_result.nozzle_type.resize(nozzle_type->size()); @@ -2082,6 +2090,9 @@ void GCodeProcessor::reset() for (size_t i = 0; i < MIN_EXTRUDERS_COUNT; ++i) { m_extruder_temps[i] = 0.0f; } + + m_physical_extruder_map.clear(); + m_highest_bed_temp = 0; m_extruded_last_z = 0.0f; @@ -2263,14 +2274,14 @@ void GCodeProcessor::finalize(bool post_process) m_height_compare.output(); m_width_compare.output(); #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING + if (post_process){ + run_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(); - - if (post_process) - run_post_process(); } float GCodeProcessor::get_time(PrintEstimatedStatistics::ETimeMode mode) const diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 19cd201b56..ad7dc9d783 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -721,6 +721,9 @@ class Print; bool m_wipe_tower; int m_object_label_id{-1}; std::vector m_remaining_volume; + ExtruderTemps m_filament_nozzle_temp; + ExtruderTemps m_filament_nozzle_temp_first_layer; + std::vector m_physical_extruder_map; bool m_manual_filament_change; //BBS: x, y offset for gcode generated @@ -749,8 +752,6 @@ class Print; unsigned char m_extruder_id; ExtruderColors m_extruder_colors; ExtruderTemps m_extruder_temps; - ExtruderTemps m_extruder_temps_config; - ExtruderTemps m_extruder_temps_first_layer_config; bool m_is_XL_printer = false; int m_highest_bed_temp; float m_extruded_last_z;