GCodeAnalyzer now recognizes tool-changing commands with MakerWare and Sailfish flavor

These firmwares use M135 Tn and M108 Tn commands for changing active tool, which the analyzer did not recognize. The toolpaths were then rendered in wrong color, extruder offset etc. This surfaced in issue https://github.com/prusa3d/PrusaSlicer/issues/2566
This commit is contained in:
Lukas Matena 2019-07-12 12:38:00 +02:00
parent cc70c8dff9
commit 2ee572bd31
3 changed files with 48 additions and 2 deletions

View file

@ -586,6 +586,9 @@ void GCode::_do_export(Print &print, FILE *file)
}
m_analyzer.set_extruder_offsets(extruder_offsets);
// tell analyzer about the gcode flavor
m_analyzer.set_gcode_flavor(print.config().gcode_flavor);
// resets analyzer's tracking data
m_last_mm3_per_mm = GCodeAnalyzer::Default_mm3_per_mm;
m_last_width = GCodeAnalyzer::Default_Width;

View file

@ -106,6 +106,11 @@ void GCodeAnalyzer::set_extruder_offsets(const GCodeAnalyzer::ExtruderOffsetsMap
m_extruder_offsets = extruder_offsets;
}
void GCodeAnalyzer::set_gcode_flavor(const GCodeFlavor& flavor)
{
m_gcode_flavor = flavor;
}
void GCodeAnalyzer::reset()
{
_set_units(Millimeters);
@ -249,6 +254,14 @@ void GCodeAnalyzer::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLi
_processM83(line);
break;
}
case 108:
case 135:
{
// these are used by MakerWare and Sailfish firmwares
// for tool changing - we can process it in one place
_processM108orM135(line);
break;
}
}
break;
@ -426,9 +439,27 @@ void GCodeAnalyzer::_processM600(const GCodeReader::GCodeLine& line)
_set_cp_color_id(m_state.cur_cp_color_id);
}
void GCodeAnalyzer::_processT(const GCodeReader::GCodeLine& line)
void GCodeAnalyzer::_processM108orM135(const GCodeReader::GCodeLine& line)
{
// These M-codes are used by MakerWare and Sailfish to change active tool.
// They have to be processed otherwise toolchanges will be unrecognised
// by the analyzer - see https://github.com/prusa3d/PrusaSlicer/issues/2566
size_t code = ::atoi(&(line.cmd()[1]));
if ((code == 108 && m_gcode_flavor == gcfSailfish)
|| (code == 135 && m_gcode_flavor == gcfMakerWare)) {
std::string cmd = line.raw();
size_t T_pos = cmd.find("T");
if (T_pos != std::string::npos) {
cmd = cmd.substr(T_pos);
_processT(cmd);
}
}
}
void GCodeAnalyzer::_processT(const std::string& cmd)
{
std::string cmd = line.cmd();
if (cmd.length() > 1)
{
unsigned int id = (unsigned int)::strtol(cmd.substr(1).c_str(), nullptr, 10);
@ -442,6 +473,11 @@ void GCodeAnalyzer::_processT(const GCodeReader::GCodeLine& line)
}
}
void GCodeAnalyzer::_processT(const GCodeReader::GCodeLine& line)
{
_processT(line.cmd());
}
bool GCodeAnalyzer::_process_tags(const GCodeReader::GCodeLine& line)
{
std::string comment = line.comment();

View file

@ -106,6 +106,7 @@ private:
GCodeReader m_parser;
TypeToMovesMap m_moves_map;
ExtruderOffsetsMap m_extruder_offsets;
GCodeFlavor m_gcode_flavor;
// The output of process_layer()
std::string m_process_output;
@ -115,6 +116,8 @@ public:
void set_extruder_offsets(const ExtruderOffsetsMap& extruder_offsets);
void set_gcode_flavor(const GCodeFlavor& flavor);
// Reinitialize the analyzer
void reset();
@ -164,10 +167,14 @@ private:
// Set extruder to relative mode
void _processM83(const GCodeReader::GCodeLine& line);
// Set tool (MakerWare and Sailfish flavor)
void _processM108orM135(const GCodeReader::GCodeLine& line);
// Set color change
void _processM600(const GCodeReader::GCodeLine& line);
// Processes T line (Select Tool)
void _processT(const std::string& command);
void _processT(const GCodeReader::GCodeLine& line);
// Processes the tags