ENH: remove the appended T cmd after change filament

Jira: none

Signed-off-by: qing.zhang <qing.zhang@bambulab.com>
Change-Id: Id5da64626b7343a71dcb38c06f5b5caf43ec40e2
This commit is contained in:
qing.zhang 2024-06-13 16:03:24 +08:00 committed by lane.wei
parent c0932e16ff
commit 7da565f058
5 changed files with 70 additions and 6 deletions

View File

@ -1123,7 +1123,7 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
BOOST_LOG_TRIVIAL(info) << boost::format("Will export G-code to %1% soon")%path;
GCodeProcessor::s_IsBBLPrinter = print->is_BBL_Printer();
m_writer.set_is_bbl_printer(print->is_BBL_Printer());
print->set_started(psGCodeExport);
// check if any custom gcode contains keywords used by the gcode processor to
@ -5466,9 +5466,10 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z, bool b
m_writer.reset_e();
}
// We inform the writer about what is happening, but we may not use the resulting gcode.
//BBS: don't add T[next extruder] if there is no T cmd on filament change
//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 (! custom_gcode_changes_tool(toolchange_gcode_parsed, m_writer.toolchange_prefix(), extruder_id))
if (!custom_gcode_changes_tool(toolchange_gcode_parsed, m_writer.toolchange_prefix(), extruder_id))
gcode += toolchange_command;
else {
// user provided his own toolchange gcode, no need to do anything

View File

@ -2037,8 +2037,27 @@ void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line, bool
break;
}
break;
default:
break;
case 5:
switch (cmd[1]) {
case '1':
switch (cmd[2]) {
case '0':
switch (cmd[3]) {
case '2':
switch (cmd[4]) {
case '0': {
process_M1020(line); // Select Tool
break;
}
default: break;
}
default: break;
}
default: break;
}
default: break;
}
default: break;
}
break;
case 't':
@ -4221,6 +4240,42 @@ void GCodeProcessor::process_T(const GCodeReader::GCodeLine& line)
process_T(line.cmd());
}
void GCodeProcessor::process_M1020(const GCodeReader::GCodeLine &line)
{
if (line.raw().length() > 5) {
std::string filament_id = line.raw().substr(7);
if (filament_id.empty())
return;
int eid = 0;
eid = std::stoi(filament_id);
if (eid < 0 || eid > 254) {
// M1020-1 is a valid gcode line for RepRap Firmwares (used to deselects all tools)
if ((m_flavor != gcfRepRapFirmware && m_flavor != gcfRepRapSprinter) || eid != -1)
BOOST_LOG_TRIVIAL(error) << "Invalid M1020 command (" << line.raw() << ").";
} else {
unsigned char id = static_cast<unsigned char>(eid);
if (m_extruder_id != id) {
if (id >= m_result.extruders_count)
BOOST_LOG_TRIVIAL(error) << "Invalid M1020 command (" << line.raw() << ").";
else {
m_last_extruder_id = m_extruder_id;
process_filaments(CustomGCode::ToolChange);
m_extruder_id = id;
m_cp_color.current = m_extruder_colors[id];
// BBS: increase filament change times
m_result.lock();
m_result.print_statistics.total_filamentchanges++;
m_result.unlock();
}
// store tool change move
store_move_vertex(EMoveType::Tool_change);
}
}
}
}
void GCodeProcessor::process_T(const std::string_view command)
{
if (command.length() > 1) {

View File

@ -956,6 +956,7 @@ namespace Slic3r {
// Processes T line (Select Tool)
void process_T(const GCodeReader::GCodeLine& line);
void process_T(const std::string_view command);
void process_M1020(const GCodeReader::GCodeLine &line);
//BBS: different path_type is only used for arc move
void store_move_vertex(EMoveType type, EMovePathType path_type = EMovePathType::Noop_move);

View File

@ -305,7 +305,11 @@ std::string GCodeWriter::toolchange(unsigned int extruder_id)
// if we are running a single-extruder setup, just set the extruder and return nothing
std::ostringstream gcode;
if (this->multiple_extruders) {
gcode << this->toolchange_prefix() << extruder_id;
// BBS
if (this->m_is_bbl_printer)
gcode << "M1020 S" << extruder_id;
else
gcode << this->toolchange_prefix() << extruder_id;
//BBS
if (GCodeWriter::full_gcode_comment)
gcode << " ; change extruder";

View File

@ -106,6 +106,7 @@ public:
//BBS:
void set_current_position_clear(bool clear) { m_is_current_pos_clear = clear; };
bool is_current_position_clear() const { return m_is_current_pos_clear; };
void set_is_bbl_printer(bool is_bbl_printer) { m_is_bbl_printer = is_bbl_printer; };
//BBS:
static const bool full_gcode_comment;
//Radian threshold of slope for lazy lift and spiral lift;
@ -140,6 +141,8 @@ private:
double m_x_offset{ 0 };
double m_y_offset{ 0 };
double m_current_speed{ 0 };
bool m_is_bbl_printer = false;
std::string m_gcode_label_objects_start;
std::string m_gcode_label_objects_end;