ENH: fix wrong extruder offset when loading from gcode

All extruder offset should be extruder_offset[0] when
it is single extruder multi material.

Add handling when load config from gcode.

This is fix for github issue #213

Signed-off-by: salt.wei <salt.wei@bambulab.com>
Change-Id: Ia881b2bfbbdffa98e3c3db7b35201dc86b520b29
This commit is contained in:
salt.wei 2022-09-08 11:49:03 +08:00 committed by Lane.Wei
parent e7c977f86b
commit 9e2f227aef

View file

@ -990,11 +990,22 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config)
}
const ConfigOptionPoints* extruder_offset = config.option<ConfigOptionPoints>("extruder_offset");
const ConfigOptionBool* single_extruder_multi_material = config.option<ConfigOptionBool>("single_extruder_multi_material");
if (extruder_offset != nullptr) {
m_extruder_offsets.resize(extruder_offset->values.size());
for (size_t i = 0; i < extruder_offset->values.size(); ++i) {
Vec2f offset = extruder_offset->values[i].cast<float>();
m_extruder_offsets[i] = { offset(0), offset(1), 0.0f };
//BBS: for single extruder multi material, only use the offset of first extruder
if (single_extruder_multi_material != nullptr && single_extruder_multi_material->getBool()) {
Vec2f offset = extruder_offset->values[0].cast<float>();
m_extruder_offsets.resize(m_result.extruders_count);
for (size_t i = 0; i < m_result.extruders_count; ++i) {
m_extruder_offsets[i] = { offset(0), offset(1), 0.0f };
}
}
else {
m_extruder_offsets.resize(extruder_offset->values.size());
for (size_t i = 0; i < extruder_offset->values.size(); ++i) {
Vec2f offset = extruder_offset->values[i].cast<float>();
m_extruder_offsets[i] = { offset(0), offset(1), 0.0f };
}
}
}