Merge upstream main (Bambu H2C/A2L multi-nozzle support) into IMEX branch

Conflicts were all co-located additions rather than design collisions:
- GCode.cpp: adopt upstream's toolchange(filament_id, nozzle_id) signature and
  per-variant set_config_index() while keeping the IMEX bare-T<n> suppression;
  rebase the second-layer temperature loop's non-IMEX branch onto upstream's
  get_filament_config_index() resolution.
- Preset.cpp / PresetBundle.cpp / PrintConfig.cpp: keep both sides' option-list
  and enum-map entries.
- GLCanvas3D.cpp: upstream's printable_heights argument plus the IMEX ghost pass.
- PartPlate.cpp: keep <set> (still used).
- test_gcodewriter.cpp / test_3mf.cpp: keep both sides' test cases.
This commit is contained in:
Clifford Garwood
2026-07-13 16:22:22 -04:00
691 changed files with 84512 additions and 2016 deletions
+198 -3
View File
@@ -7,6 +7,7 @@
#include <sstream>
#include <set>
#include <regex>
#include "libslic3r/MultiNozzleUtils.hpp"
#include <future>
#include <glad/gl.h>
#include <boost/algorithm/string.hpp>
@@ -71,6 +72,8 @@ static const int PARTPLATE_PLATENAME_OFFSET_Y = 10;
const float WIPE_TOWER_DEFAULT_X_POS = 165.;
const float WIPE_TOWER_DEFAULT_Y_POS = 250.; // Max y
const float N9_WIPE_TOWER_DEFAULT_Y_POS = 160.;
const float I3_WIPE_TOWER_DEFAULT_X_POS = 0.;
const float I3_WIPE_TOWER_DEFAULT_Y_POS = 250.; // Max y
@@ -320,6 +323,18 @@ std::vector<int> PartPlate::get_real_filament_maps(const DynamicConfig& g_config
return g_maps;
}
std::vector<int> PartPlate::get_real_filament_volume_maps(const DynamicConfig& g_config, bool* use_global_param) const
{
auto maps = get_filament_volume_maps();
if (!maps.empty()) {
if (use_global_param) { *use_global_param = false; }
return maps;
}
auto g_maps = g_config.option<ConfigOptionInts>("filament_volume_map")->values;
if (use_global_param) { *use_global_param = true; }
return g_maps;
}
FilamentMapMode PartPlate::get_real_filament_map_mode(const DynamicConfig& g_config, bool* use_global_param) const
{
auto mode = get_filament_map_mode();
@@ -3020,6 +3035,17 @@ int PartPlate::get_physical_extruder_by_filament_id(const DynamicConfig& g_confi
return the_map->values[zero_base_logical_idx];
}
int PartPlate::get_logical_extruder_by_filament_id(const DynamicConfig& g_config, int idx) const
{
const std::vector<int>& filament_map = get_real_filament_maps(g_config);
if (idx <= 0 || idx > (int)filament_map.size())
{
return -1;
}
return filament_map[idx - 1] - 1;
}
std::vector<int> PartPlate::get_used_filaments()
{
std::vector<int> used_filaments;
@@ -4694,8 +4720,16 @@ int PartPlate::load_gcode_from_file(const std::string& filename)
int ret = 0;
// process gcode
auto& preset_bundle = wxGetApp().preset_bundle;
std::vector<int> filament_maps = this->get_filament_maps();
DynamicPrintConfig full_config = wxGetApp().preset_bundle->full_config(false, filament_maps);
// Inject the plate's volume map (or the per-extruder defaults) exactly like the apply-time
// composition, so the config applied over the loaded slice result matches the next
// background-process apply and does not invalidate the embedded g-code.
std::vector<int> f_volume_maps = this->get_filament_volume_maps();
if (f_volume_maps.empty()) {
f_volume_maps = preset_bundle->get_default_nozzle_volume_types_for_filaments(filament_maps);
}
DynamicPrintConfig full_config = preset_bundle->full_config(false, filament_maps, f_volume_maps);
full_config.apply(m_config, true);
m_print->apply(*m_model, full_config, false);
//BBS: need to apply two times, for after the first apply, the m_print got its object,
@@ -5002,6 +5036,40 @@ void PartPlate::clear_filament_map()
m_config.erase("filament_map");
}
std::vector<int> PartPlate::get_filament_volume_maps() const
{
std::string key = "filament_volume_map";
if (m_config.has(key))
return m_config.option<ConfigOptionInts>(key)->values;
return {};
}
void PartPlate::set_filament_volume_maps(const std::vector<int>& f_maps)
{
m_config.option<ConfigOptionInts>("filament_volume_map", true)->values = f_maps;
}
void PartPlate::clear_filament_volume_map()
{
if (m_config.has("filament_volume_map"))
m_config.erase("filament_volume_map");
}
std::vector<int> PartPlate::get_filament_nozzle_maps() const
{
std::string key = "filament_nozzle_map";
if (m_config.has(key))
return m_config.option<ConfigOptionInts>(key)->values;
return {};
}
void PartPlate::set_filament_nozzle_maps(const std::vector<int>& f_maps)
{
m_config.option<ConfigOptionInts>("filament_nozzle_map", true)->values = f_maps;
}
void PartPlate::clear_filament_map_mode()
{
if (m_config.has("filament_map_mode"))
@@ -5028,6 +5096,16 @@ void PartPlate::set_filament_count(int filament_count)
std::vector<int>& filament_maps = m_config.option<ConfigOptionInts>("filament_map")->values;
filament_maps.resize(filament_count, 1);
}
if (m_config.has("filament_nozzle_map")) {
std::vector<int>& filament_nozzle_map = m_config.option<ConfigOptionInts>("filament_nozzle_map")->values;
filament_nozzle_map.resize(filament_count, 0);
}
if (m_config.has("filament_volume_map")) {
std::vector<int>& filament_volume_map = m_config.option<ConfigOptionInts>("filament_volume_map")->values;
filament_volume_map.resize(filament_count, static_cast<int>(NozzleVolumeType::nvtStandard));
}
}
void PartPlate::on_filament_added()
@@ -5036,6 +5114,27 @@ void PartPlate::on_filament_added()
std::vector<int>& filament_maps = m_config.option<ConfigOptionInts>("filament_map")->values;
filament_maps.push_back(1);
}
if (m_config.has("filament_nozzle_map")) {
std::vector<int>& filament_nozzle_map = m_config.option<ConfigOptionInts>("filament_nozzle_map")->values;
filament_nozzle_map.push_back(0);
}
if (m_config.has("filament_volume_map")) {
std::vector<int>& filament_volume_map = m_config.option<ConfigOptionInts>("filament_volume_map")->values;
// A new filament defaults onto the first extruder, so seed its volume value from
// that extruder's flow type.
int volume_type = static_cast<int>(NozzleVolumeType::nvtStandard);
auto nozzle_volumes = wxGetApp().preset_bundle->project_config.option<ConfigOptionEnumsGeneric>("nozzle_volume_type");
if (nozzle_volumes && !nozzle_volumes->values.empty())
volume_type = nozzle_volumes->values[0];
// Orca: never store the Hybrid marker as a per-filament value; on a Hybrid extruder
// each filament still prints with a concrete flow, defaulting to Standard.
if (volume_type == static_cast<int>(NozzleVolumeType::nvtHybrid))
volume_type = static_cast<int>(NozzleVolumeType::nvtStandard);
filament_volume_map.push_back(volume_type);
}
}
void PartPlate::on_filament_deleted(int filament_count, int filament_id)
@@ -5048,6 +5147,19 @@ void PartPlate::on_filament_deleted(int filament_count, int filament_id)
if (filament_id >= 0 && filament_id < (int) filament_maps.size())
filament_maps.erase(filament_maps.begin() + filament_id);
}
if (m_config.has("filament_nozzle_map")) {
std::vector<int>& filament_nozzle_map = m_config.option<ConfigOptionInts>("filament_nozzle_map")->values;
if (filament_id >= 0 && filament_id < (int) filament_nozzle_map.size())
filament_nozzle_map.erase(filament_nozzle_map.begin() + filament_id);
}
if (m_config.has("filament_volume_map")) {
std::vector<int>& filament_volume_map = m_config.option<ConfigOptionInts>("filament_volume_map")->values;
if (filament_id >= 0 && filament_id < (int) filament_volume_map.size())
filament_volume_map.erase(filament_volume_map.begin() + filament_id);
}
update_first_layer_print_sequence_when_delete_filament(filament_id);
}
@@ -5438,6 +5550,12 @@ void PartPlateList::set_default_wipe_tower_pos_for_plate(int plate_idx, bool ini
y = I3_WIPE_TOWER_DEFAULT_Y_POS;
}
std::string printer_type = wxGetApp().preset_bundle->printers.get_edited_preset().get_printer_type(wxGetApp().preset_bundle);
// Note: printer_type == "N9" and printer_structure_opt->value == PrinterStructure::psI3 can both be true
if (printer_type == "N9") {
y = N9_WIPE_TOWER_DEFAULT_Y_POS;
}
PartPlate *part_plate = get_plate(plate_idx);
Vec3d plate_origin = part_plate->get_origin();
BoundingBoxf3 plate_bbox = part_plate->get_bounding_box();
@@ -5454,7 +5572,14 @@ void PartPlateList::set_default_wipe_tower_pos_for_plate(int plate_idx, bool ini
coordf_t plate_bbox_y_max_local_coord = plate_bbox_2d.max(1) - plate_origin(1);
std::vector<int> filament_maps = part_plate->get_real_filament_maps(proj_cfg);
DynamicPrintConfig full_config = wxGetApp().preset_bundle->full_config(false, filament_maps);
// Keep this composition consistent with the apply-time injection (plate volume map, else
// per-extruder defaults); the config below currently only feeds scalar reads, but a
// divergent volume map would silently mis-resolve any future per-filament read here.
std::vector<int> f_volume_maps = part_plate->get_filament_volume_maps();
if (f_volume_maps.empty()) {
f_volume_maps = wxGetApp().preset_bundle->get_default_nozzle_volume_types_for_filaments(filament_maps);
}
DynamicPrintConfig full_config = wxGetApp().preset_bundle->full_config(false, filament_maps, f_volume_maps);
const DynamicPrintConfig &print_cfg = wxGetApp().preset_bundle->prints.get_edited_preset().config;
float w = dynamic_cast<const ConfigOptionFloat *>(print_cfg.option("prime_tower_width"))->value;
float v = dynamic_cast<const ConfigOptionFloat *>(full_config.option("prime_volume"))->value;
@@ -7502,6 +7627,58 @@ int PartPlateList::load_from_3mf_structure(PlateDataPtrs& plate_data_list, int f
m_plate_list[index]->slice_filaments_info = plate_data_list[i]->slice_filaments_info;
gcode_result->warnings = plate_data_list[i]->warnings;
gcode_result->filament_maps = plate_data_list[i]->filament_maps;
// Reconstruct the device-side nozzle grouping from the loaded 3mf so
// the monitor/preview can map filaments to physical nozzles.
// load_nozzle_infos_with_compatibility handles older single-nozzle 3mf (no <nozzle> tags) by
// falling back to the per-filament group_id, then to the extruder volume types / nozzle diameters.
{
// nozzle_volume_types is space-separated ints; nozzle_diameters is comma/space-separated floats.
auto parse_int_tokens = [](const std::string& str) -> std::vector<int> {
std::vector<int> out;
std::istringstream iss(str);
std::string tok;
while (iss >> tok) { try { out.push_back(std::stoi(tok)); } catch (...) {} }
return out;
};
auto parse_double_tokens = [](const std::string& str) -> std::vector<double> {
std::vector<double> out;
std::string s = str;
std::replace(s.begin(), s.end(), ',', ' ');
std::istringstream iss(s);
std::string tok;
while (iss >> tok) { try { out.push_back(std::stod(tok)); } catch (...) {} }
return out;
};
std::vector<int> nozzle_volume_type_values = parse_int_tokens(plate_data_list[i]->nozzle_volume_types);
std::vector<double> nozzle_diameter_values = parse_double_tokens(plate_data_list[i]->nozzle_diameters);
std::vector<NozzleVolumeType> extruder_volume_types(nozzle_volume_type_values.size(), NozzleVolumeType::nvtStandard);
for (size_t idx = 0; idx < nozzle_volume_type_values.size(); ++idx)
if (nozzle_volume_type_values[idx] >= 0 && nozzle_volume_type_values[idx] <= nvtMaxNozzleVolumeType)
extruder_volume_types[idx] = static_cast<NozzleVolumeType>(nozzle_volume_type_values[idx]);
auto nozzle_infos = MultiNozzleUtils::load_nozzle_infos_with_compatibility(
plate_data_list[i]->nozzles_info,
plate_data_list[i]->slice_filaments_info,
plate_data_list[i]->filament_maps,
extruder_volume_types,
nozzle_diameter_values);
std::vector<int> fil_seq(plate_data_list[i]->filament_change_sequence.begin(), plate_data_list[i]->filament_change_sequence.end());
std::vector<int> noz_seq(plate_data_list[i]->nozzle_change_sequence.begin(), plate_data_list[i]->nozzle_change_sequence.end());
bool enable_filament_dynamic_map = false;
if (plate_data_list[i]->config.has("enable_filament_dynamic_map"))
enable_filament_dynamic_map = plate_data_list[i]->config.option<ConfigOptionBool>("enable_filament_dynamic_map")->value;
auto group_result = MultiNozzleUtils::StaticNozzleGroupResult::create(
plate_data_list[i]->slice_filaments_info, nozzle_infos, fil_seq, noz_seq, enable_filament_dynamic_map);
if (group_result)
gcode_result->nozzle_group_result = std::make_shared<MultiNozzleUtils::StaticNozzleGroupResult>(group_result.value());
else
gcode_result->nozzle_group_result = nullptr;
}
if (m_plater && !plate_data_list[i]->thumbnail_file.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": plate %1%, load thumbnail from %2%.")%(i+1) %plate_data_list[i]->thumbnail_file;
if (boost::filesystem::exists(plate_data_list[i]->thumbnail_file)) {
@@ -7661,9 +7838,10 @@ void PartPlateList::init_bed_type_info()
auto bed_texture_maps = wxGetApp().plater()->get_bed_texture_maps();
std::string bottom_texture_end_name = bed_texture_maps.find("bottom_texture_end_name") != bed_texture_maps.end() ? bed_texture_maps["bottom_texture_end_name"] : "";
std::string bottom_texture_rect_str = bed_texture_maps.find("bottom_texture_rect") != bed_texture_maps.end() ? bed_texture_maps["bottom_texture_rect"] : "";
std::string bottom_texture_rect_longer_str = bed_texture_maps.find("bottom_texture_rect_longer") != bed_texture_maps.end() ? bed_texture_maps["bottom_texture_rect_longer"] : "";
std::string middle_texture_rect_str = bed_texture_maps.find("middle_texture_rect") != bed_texture_maps.end() ? bed_texture_maps["middle_texture_rect"] : "";
std::string use_double_extruder_default_texture = bed_texture_maps.find("use_double_extruder_default_texture") != bed_texture_maps.end() ? bed_texture_maps["use_double_extruder_default_texture"] : "";
std::array<float, 4> bottom_texture_rect = {0, 0, 0, 0}, middle_texture_rect = {0, 0, 0, 0};
std::array<float, 4> bottom_texture_rect = {0, 0, 0, 0}, bottom_texture_rect_longer = {0, 0, 0, 0}, middle_texture_rect = {0, 0, 0, 0};
if (bottom_texture_rect_str.size() > 0) {
std::vector<std::string> items;
boost::algorithm::erase_all(bottom_texture_rect_str, " ");
@@ -7674,6 +7852,16 @@ void PartPlateList::init_bed_type_info()
}
}
}
if (bottom_texture_rect_longer_str.size() > 0) {
std::vector<std::string> items;
boost::algorithm::erase_all(bottom_texture_rect_longer_str, " ");
boost::split(items, bottom_texture_rect_longer_str, boost::is_any_of(","));
if (items.size() == 4) {
for (int i = 0; i < items.size(); i++) {
bottom_texture_rect_longer[i] = std::atof(items[i].c_str());
}
}
}
if (middle_texture_rect_str.size() > 0) {
std::vector<std::string> items;
boost::algorithm::erase_all(middle_texture_rect_str, " ");
@@ -7694,6 +7882,7 @@ void PartPlateList::init_bed_type_info()
}
pte_part2 = BedTextureInfo::TexturePart(45, -14.5, 70, 8, "bbl_bed_pte_left_bottom.svg");
auto &bottom_rect = bottom_texture_rect;
auto &bottom_rect_longer = bottom_texture_rect_longer;
if (bottom_texture_end_name.size() > 0 && bottom_rect[2] > 0.f) {
std::string pte_part2_name = "bbl_bed_pte_bottom_" + bottom_texture_end_name + ".svg";
pte_part2 = BedTextureInfo::TexturePart(bottom_rect[0], bottom_rect[1], bottom_rect[2], bottom_rect[3], pte_part2_name);
@@ -7717,6 +7906,9 @@ void PartPlateList::init_bed_type_info()
if (bottom_texture_end_name.size() > 0 && bottom_rect[2] > 0.f) {
std::string st_part2_name = "bbl_bed_st_bottom_" + bottom_texture_end_name + ".svg";
st_part2 = BedTextureInfo::TexturePart(bottom_rect[0], bottom_rect[1], bottom_rect[2], bottom_rect[3], st_part2_name);
} else if (bottom_rect_longer[2] > 0.f) {
// SuperTack bottom strip uses the wider "longer" rect.
st_part2.update_pos(bottom_rect_longer[0], bottom_rect_longer[1], bottom_rect_longer[2], bottom_rect_longer[3]);
}
ep_part1 = BedTextureInfo::TexturePart(57, 300, 236.12f, 10.f, "bbl_bed_ep_middle.svg");
@@ -7727,6 +7919,9 @@ void PartPlateList::init_bed_type_info()
if (bottom_texture_end_name.size() > 0 && bottom_rect[2] > 0.f) {
std::string ep_part2_name = "bbl_bed_ep_bottom_" + bottom_texture_end_name + ".svg";
ep_part2 = BedTextureInfo::TexturePart(bottom_rect[0], bottom_rect[1], bottom_rect[2], bottom_rect[3], ep_part2_name);
} else if (bottom_rect_longer[2] > 0.f) {
// Engineering-plate bottom strip uses the wider "longer" rect.
ep_part2.update_pos(bottom_rect_longer[0], bottom_rect_longer[1], bottom_rect_longer[2], bottom_rect_longer[3]);
}
pc_part1 = BedTextureInfo::TexturePart(57, 300, 236.12f, 10.f, "bbl_bed_pc_middle.svg");