Skip to content

Commit

Permalink
Don't rely on gcode to detect a toolchange for cooling buffers.
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jul 23, 2022
1 parent 431a060 commit d62f185
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5401,11 +5401,14 @@ std::string GCode::toolchange(uint16_t extruder_id, double print_z) {

// We inform the writer about what is happening, but we may not use the resulting gcode.
std::string toolchange_command = m_writer.toolchange(extruder_id);
if (toolchange_gcode.empty() && m_writer.multiple_extruders)// !custom_gcode_changes_tool(toolchange_gcode_parsed, m_writer.toolchange_prefix(), extruder_id) && !no_toolchange)
if (toolchange_gcode.empty() && m_writer.multiple_extruders) { // !custom_gcode_changes_tool(toolchange_gcode_parsed, m_writer.toolchange_prefix(), extruder_id) && !no_toolchange)
gcode += toolchange_command;
else {
} else {
// user provided his own toolchange gcode, no need to do anything
}
if (m_enable_cooling_markers) {
gcode += ";_TOOLCHANGE " + std::to_string(extruder_id) + "\n";
}
return gcode;
}

Expand Down
24 changes: 15 additions & 9 deletions src/libslic3r/GCode/CoolingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ struct CoolingLine
float time_max;
// If marked with the "slowdown" flag, the line has been slowed down.
bool slowdown;
// for TYPE_SET_TOOL
uint16_t new_tool;
};

// Calculate the required per extruder time stretches.
Expand Down Expand Up @@ -485,15 +487,17 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
} else if (boost::starts_with(sline, ";_EXTRUDE_END")) {
line.type = CoolingLine::TYPE_EXTRUDE_END;
active_speed_modifier = size_t(-1);
} else if (boost::starts_with(sline, m_toolchange_prefix)) {
uint16_t new_extruder = (uint16_t)atoi(sline.c_str() + m_toolchange_prefix.size());
} else if (boost::starts_with(sline, m_toolchange_prefix) || boost::starts_with(sline, ";_TOOLCHANGE")) {
int prefix = boost::starts_with(sline, ";_TOOLCHANGE") ? 13 : m_toolchange_prefix.size();
uint16_t new_extruder = (uint16_t)atoi(sline.c_str() + prefix);
// Only change extruder in case the number is meaningful. User could provide an out-of-range index through custom gcodes - those shall be ignored.
if (new_extruder < map_extruder_to_per_extruder_adjustment.size()) {
// Switch the tool.
line.type = CoolingLine::TYPE_SET_TOOL;
line.new_tool = new_extruder;
if (new_extruder != current_extruder) {
// Switch the tool.
line.type = CoolingLine::TYPE_SET_TOOL;
current_extruder = new_extruder;
adjustment = &per_extruder_adjustments[map_extruder_to_per_extruder_adjustment[current_extruder]];
adjustment = &per_extruder_adjustments[map_extruder_to_per_extruder_adjustment[current_extruder]];
}
}
else {
Expand Down Expand Up @@ -893,12 +897,14 @@ std::string CoolingBuffer::apply_layer_cooldown(
if (line_start > pos)
new_gcode.append(pos, line_start - pos);
if (line->type & CoolingLine::TYPE_SET_TOOL) {
unsigned int new_extruder = (unsigned int)atoi(line_start + m_toolchange_prefix.size());
if (new_extruder != m_current_extruder) {
m_current_extruder = new_extruder;
if (line->new_tool != m_current_extruder) {
m_current_extruder = line->new_tool;
change_extruder_set_fan();
}
new_gcode.append(line_start, line_end - line_start);
//write line if it's not a cooling marker comment
if (!boost::starts_with(line_start, ";_")) {
new_gcode.append(line_start, line_end - line_start);
}
} else if (line->type & CoolingLine::TYPE_STORE_FOR_WT) {
stored_fan_speed = m_fan_speed;
} else if (line->type & CoolingLine::TYPE_RESTORE_AFTER_WT) {
Expand Down

0 comments on commit d62f185

Please sign in to comment.