#461 ensure that the activation of the first extruder when using multi-extruder is done at the right time. (second try)

TODO: rework all these gcode initialisation with sript function, it's an utter mess right now.
This commit is contained in:
supermerill 2020-09-10 21:47:26 +02:00 committed by supermerill
parent 27189e1afd
commit 66dd74551c
2 changed files with 44 additions and 35 deletions

View File

@ -1205,34 +1205,6 @@ static void init_multiextruders(FILE *file, Print &print, GCodeWriter & writer,
int(print.config().temperature.get_at(tool_id)));
}
}
//activate first extruder is multi-extruder and not in start-gcode
if (writer.multiple_extruders) {
if (std::set<uint8_t>{gcfRepRap}.count(print.config().gcode_flavor.value) > 0) {
//if not in gcode
bool find = false;
if (!custom_gcode.empty()) {
const char *ptr = custom_gcode.data();
while (*ptr != 0) {
// Skip whitespaces.
for (; *ptr == ' ' || *ptr == '\t'; ++ptr);
if (*ptr == 'T') {
find = true;
break;
} else if (*ptr == 'A') {
//TODO: ACTIVATE_EXTRUDER for klipper (if used)
}
// Skip the rest of the line.
for (; *ptr != 0 && *ptr != '\r' && *ptr != '\n'; ++ptr);
// Skip the end of line indicators.
for (; *ptr == '\r' || *ptr == '\n'; ++ptr);
}
}
if (!find) {
fprintf(file, writer.toolchange(tool_ordering.first_extruder()).c_str());
}
}
writer.toolchange(tool_ordering.first_extruder());
}
}
@ -1518,10 +1490,47 @@ void GCode::_do_export(Print &print, FILE *file)
// Calculate wiping points if needed
DoExport::init_ooze_prevention(print, m_ooze_prevention);
print.throw_if_canceled();
if (! (has_wipe_tower && print.config().single_extruder_multi_material_priming)) {
// Set initial extruder only after custom start G-code.
// Ugly hack: Do not set the initial extruder if the extruder is primed using the MMU priming towers at the edge of the print bed.
//activate first extruder is multi-extruder and not in start-gcode
if (m_writer.multiple_extruders) {
//if not in gcode
bool find = false;
if (!start_gcode.empty()) {
const char *ptr = start_gcode.data();
while (*ptr != 0) {
// Skip whitespaces.
for (; *ptr == ' ' || *ptr == '\t'; ++ptr);
if (*ptr == 'T') {
// TX for most of the firmwares
find = true;
break;
} else if (*ptr == 'A' && print.config().gcode_flavor.value == gcfKlipper) {
// ACTIVATE_EXTRUDER for klipper (if used)
if (std::string::npos != start_gcode.find("ACTIVATE_EXTRUDER", size_t(ptr - start_gcode.data()))) {
find = true;
break;
}
}
// Skip the rest of the line.
for (; *ptr != 0 && *ptr != '\r' && *ptr != '\n'; ++ptr);
// Skip the end of line indicators.
for (; *ptr == '\r' || *ptr == '\n'; ++ptr);
}
}
if (!find) {
// Set initial extruder only after custom start G-code.
// Ugly hack: Do not set the initial extruder if the extruder is primed using the MMU priming towers at the edge of the print bed.
if (!(has_wipe_tower && print.config().single_extruder_multi_material_priming)) {
_write(file, this->set_extruder(initial_extruder_id, 0.));
} else {
m_writer.toolchange(initial_extruder_id);
}
} else {
// set writer to the tool as should be set in the start_gcode.
_write(file, this->set_extruder(initial_extruder_id, 0., true));
}
} else {
// if we are running a single-extruder setup, just set the extruder and "return nothing"
_write(file, this->set_extruder(initial_extruder_id, 0.));
}
@ -4325,7 +4334,7 @@ std::string GCode::retract(bool toolchange)
return gcode;
}
std::string GCode::set_extruder(unsigned int extruder_id, double print_z)
std::string GCode::set_extruder(unsigned int extruder_id, double print_z, bool no_toolchange /*=false*/)
{
if (!m_writer.need_toolchange(extruder_id))
return "";
@ -4396,7 +4405,7 @@ std::string GCode::set_extruder(unsigned int 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 (! 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) && !no_toolchange)
gcode += toolchange_command;
else {
// user provided his own toolchange gcode, no need to do anything

View File

@ -334,7 +334,7 @@ private:
bool needs_retraction(const Polyline &travel, ExtrusionRole role = erNone);
std::string retract(bool toolchange = false);
std::string unretract() { return m_writer.unlift() + m_writer.unretract(); }
std::string set_extruder(unsigned int extruder_id, double print_z);
std::string set_extruder(unsigned int extruder_id, double print_z, bool no_toolchange = false);
/* Origin of print coordinates expressed in unscaled G-code coordinates.
This affects the input arguments supplied to the extrude*() and travel_to()