diff options
author | supermerill <merill@free.fr> | 2022-08-09 23:19:51 +0300 |
---|---|---|
committer | supermerill <merill@free.fr> | 2022-08-11 00:56:58 +0300 |
commit | df7ea0a7123932f6ed6a31e24f7481ff93a90a85 (patch) | |
tree | dc6a0c47e37c0bdde4e4bfa26da81a70177ac875 | |
parent | ed22e605c20332a7b4c6ca7ce2487b08025cc29a (diff) |
Klipper & wipe tower: correct extruder name
Also, can now use {tool_name} and other filaments & extruder settings in filament start/end
supermerill/SuperSlicer#2934
-rw-r--r-- | src/libslic3r/GCode.cpp | 3 | ||||
-rw-r--r-- | src/libslic3r/GCode/WipeTower.cpp | 29 |
2 files changed, 24 insertions, 8 deletions
diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 1468ce55e..f1b9bc04b 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2140,6 +2140,9 @@ void GCode::process_layers( std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, uint16_t current_extruder_id, const DynamicConfig *config_override) { + if (current_extruder_id == uint16_t(-1)) { + current_extruder_id = this->m_writer.tool()->id(); + } DynamicConfig default_config; if (config_override != nullptr) default_config = *config_override; diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 2b08d8447..ab9bcac9d 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -20,7 +20,7 @@ namespace Slic3r class WipeTowerWriter { public: - WipeTowerWriter(float layer_height, float line_width, GCodeFlavor flavor, const std::vector<WipeTower::FilamentParameters>& filament_parameters) : + WipeTowerWriter(float layer_height, float line_width, GCodeFlavor flavor, std::vector<std::string> tool_name, const std::vector<WipeTower::FilamentParameters>& filament_parameters) : m_current_pos(std::numeric_limits<float>::max(), std::numeric_limits<float>::max()), m_current_z(0.f), m_current_feedrate(0.f), @@ -32,6 +32,7 @@ public: m_default_analyzer_line_width(line_width), #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING m_gcode_flavor(flavor), + m_tool_name(tool_name), m_filpar(filament_parameters) { // adds tag for analyzer: @@ -86,12 +87,23 @@ public: } WipeTowerWriter& disable_linear_advance() { - if (m_gcode_flavor == gcfRepRap || m_gcode_flavor == gcfSprinter) + if (m_gcode_flavor == gcfRepRap || m_gcode_flavor == gcfSprinter) { m_gcode += (std::string("M572 D") + std::to_string(this->m_current_tool) + " S0\n"); - else if(m_gcode_flavor == gcfKlipper) - m_gcode += std::string("SET_PRESSURE_ADVANCE ADVANCE=0 EXTRUDER=extruder") + std::to_string(this->m_current_tool) + "\n"; - else + } else if (m_gcode_flavor == gcfKlipper) { + if (this->m_current_tool > 0 && this->m_current_tool < m_tool_name.size() && !m_tool_name[this->m_current_tool].empty() + // NOTE: this will probably break if there's more than 10 tools, as it's relying on the + // ASCII character table. + && m_tool_name[this->m_current_tool][0] != static_cast<char>(('0' + this->m_current_tool))) { + m_gcode += "SET_PRESSURE_ADVANCE ADVANCE=0 EXTRUDER=" + m_tool_name[this->m_current_tool] + "\n"; + } else { + m_gcode += "SET_PRESSURE_ADVANCE ADVANCE=0 EXTRUDER=extruder"; + if (this->m_current_tool > 0) + m_gcode += std::to_string(this->m_current_tool); + m_gcode += "\n"; + } + } else { m_gcode += std::string("M900 K0\n"); + } return *this; } @@ -549,6 +561,7 @@ private: #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING float m_used_filament_length = 0.f; GCodeFlavor m_gcode_flavor; + std::vector<std::string> m_tool_name; const std::vector<WipeTower::FilamentParameters>& m_filpar; std::string set_format_X(float x) @@ -770,7 +783,7 @@ std::vector<WipeTower::ToolChangeResult> WipeTower::prime( for (size_t idx_tool = 0; idx_tool < tools.size(); ++ idx_tool) { size_t old_tool = m_current_tool; - WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_filpar); + WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_config->tool_name.values, m_filpar); writer.set_extrusion_flow(m_extrusion_flow) .set_z(m_z_pos) .set_initial_tool(m_current_tool); @@ -866,7 +879,7 @@ WipeTower::ToolChangeResult WipeTower::tool_change(size_t tool) (tool != (unsigned int)(-1) ? wipe_area+m_depth_traversed-0.5f*m_perimeter_width : m_wipe_tower_depth-m_perimeter_width)); - WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_filpar); + WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_config->tool_name.values, m_filpar); writer.set_extrusion_flow(m_extrusion_flow) .set_z(m_z_pos) .set_initial_tool(m_current_tool) @@ -1301,7 +1314,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() size_t old_tool = m_current_tool; - WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_filpar); + WipeTowerWriter writer(m_layer_height, m_perimeter_width, m_gcode_flavor, m_config->tool_name.values, m_filpar); writer.set_extrusion_flow(m_extrusion_flow) .set_z(m_z_pos) .set_initial_tool(m_current_tool) |