ENH: optimize group logic for unprintable filaments

1.Also fix a tip mistake

jira: NONE

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: Ia52f95988d467a7018579a774376578b83e7ca05
This commit is contained in:
xun.zhang 2025-03-18 21:37:14 +08:00 committed by lane.wei
parent fb74c33625
commit 804fe8d124
3 changed files with 29 additions and 35 deletions

View File

@ -1067,14 +1067,6 @@ std::vector<int> ToolOrdering::get_recommended_filament_maps(const std::vector<s
fg.get_custom_seq = get_custom_seq; fg.get_custom_seq = get_custom_seq;
ret = fg.calc_filament_group(); ret = fg.calc_filament_group();
} }
// todo: need calculated based on already grouped filaments
// PPS-CF/PPA-CF can only be placed on the left extruder
for (unsigned int filament_id : used_filaments) {
if (print_config.filament_type.get_at(filament_id) == "PPS-CF" || print_config.filament_type.get_at(filament_id) == "PPA-CF") {
ret[filament_id] = 0;
}
}
} }
return ret; return ret;

View File

@ -2488,8 +2488,24 @@ FilamentMapMode Print::get_filament_map_mode() const
std::vector<std::set<int>> Print::get_physical_unprintable_filaments(const std::vector<unsigned int>& used_filaments) const std::vector<std::set<int>> Print::get_physical_unprintable_filaments(const std::vector<unsigned int>& used_filaments) const
{ {
// master saved in config is 1 based,so we should transfer to 0 based here int extruder_num = m_config.nozzle_diameter.size();
int master_extruder_id = m_config.master_extruder_id.value - 1; std::vector<std::set<int>>physical_unprintables(extruder_num);
if (extruder_num < 2)
return physical_unprintables;
auto get_unprintable_extruder_id = [&](unsigned int filament_idx)->int {
if (m_config.unprintable_filament_types.empty())
return -1;
for (int eid = 0; eid < m_config.unprintable_filament_types.values.size(); ++eid) {
std::vector<std::string> extruder_unprintables = split_string(m_config.unprintable_filament_types.values[eid], ',');
auto iter = std::find(extruder_unprintables.begin(), extruder_unprintables.end(), m_config.filament_type.values[filament_idx]);
if (iter != extruder_unprintables.end())
return eid;
}
return -1;
};
std::set<int> tpu_filaments; std::set<int> tpu_filaments;
for (auto f : used_filaments) { for (auto f : used_filaments) {
if (m_config.filament_type.get_at(f) == "TPU") if (m_config.filament_type.get_at(f) == "TPU")
@ -2499,27 +2515,13 @@ std::vector<std::set<int>> Print::get_physical_unprintable_filaments(const std::
throw Slic3r::RuntimeError(_u8L("Only supports up to one TPU filament.")); throw Slic3r::RuntimeError(_u8L("Only supports up to one TPU filament."));
} }
int extruder_num = m_config.nozzle_diameter.size(); for (auto f : used_filaments) {
// consider tpu, only place tpu in extruder with ams int extruder_id = get_unprintable_extruder_id(f);
std::vector<std::set<int>>physical_unprintables(extruder_num); if (extruder_id == -1)
if (extruder_num < 2) continue;
return physical_unprintables; physical_unprintables[extruder_id].insert(f);
}
int extruder_without_tpu = 1 - master_extruder_id;
for (auto& f : tpu_filaments)
physical_unprintables[extruder_without_tpu].insert(f);
// consider nozzle hrc, nozzle hrc should larger than filament hrc
for (size_t eid = 0; eid < physical_unprintables.size(); ++eid) {
auto nozzle_type = m_config.nozzle_type.get_at(eid);
int nozzle_hrc = get_hrc_by_nozzle_type(NozzleType(nozzle_type));
for (auto& f : used_filaments) {
int filament_hrc = m_config.required_nozzle_HRC.get_at(f);
if(filament_hrc>nozzle_hrc){
physical_unprintables[eid].insert(f);
}
}
}
return physical_unprintables; return physical_unprintables;
} }

View File

@ -10603,10 +10603,10 @@ void GLCanvas3D::_set_warning_notification(EWarning warning, bool state)
} }
std::string extruder_name = extruder_name_list[extruder_id-1]; std::string extruder_name = extruder_name_list[extruder_id-1];
if (error_iter->second.size() == 1) { if (error_iter->second.size() == 1) {
text += (boost::format(_u8L("Filament %d is placed in the %s, but the generated G-code path exceeds the printable range of the %s.")) %filaments %extruder_name %extruder_name).str(); text += (boost::format(_u8L("Filament %s is placed in the %s, but the generated G-code path exceeds the printable range of the %s.")) %filaments %extruder_name %extruder_name).str();
} }
else { else {
text += (boost::format(_u8L("Filaments %d is placed in the %s, but the generated G-code path exceeds the printable range of the %s.")) %filaments %extruder_name %extruder_name).str(); text += (boost::format(_u8L("Filaments %s is placed in the %s, but the generated G-code path exceeds the printable range of the %s.")) %filaments %extruder_name %extruder_name).str();
} }
} }
error = ErrorType::SLICING_LIMIT_ERROR; error = ErrorType::SLICING_LIMIT_ERROR;
@ -10639,7 +10639,7 @@ void GLCanvas3D::_set_warning_notification(EWarning warning, bool state)
std::string filaments; std::string filaments;
int index = 0; int index = 0;
for (auto filament_id : filament_ids) { for (auto filament_id : filament_ids) {
if (index == 0) { if (index > 0) {
filaments += ", "; filaments += ", ";
} }
filaments += std::to_string(filament_id); filaments += std::to_string(filament_id);
@ -10656,9 +10656,9 @@ void GLCanvas3D::_set_warning_notification(EWarning warning, bool state)
} }
std::string extruder_name = extruder_name_list[extruder_id-1]; std::string extruder_name = extruder_name_list[extruder_id-1];
if (error_iter->second.size() == 1) { if (error_iter->second.size() == 1) {
text += (boost::format(_u8L("Filament %d is placed in the %s, but the generated G-code path exceeds the printable height of the %s.")) % filaments % extruder_name % extruder_name).str(); text += (boost::format(_u8L("Filament %s is placed in the %s, but the generated G-code path exceeds the printable height of the %s.")) % filaments % extruder_name % extruder_name).str();
} else { } else {
text += (boost::format(_u8L("Filaments %d is placed in the %s, but the generated G-code path exceeds the printable height of the %s.")) % filaments % extruder_name % extruder_name).str(); text += (boost::format(_u8L("Filaments %s is placed in the %s, but the generated G-code path exceeds the printable height of the %s.")) % filaments % extruder_name % extruder_name).str();
} }
} }
if (!text.empty()) { if (!text.empty()) {