mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-18 02:52:10 +00:00
ENH: add prompt for incompatible filaments and nozzles
jira: STUDIO-12873 Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: Ieb79a35e0609e7687fdcf31742df3a08fedc925b (cherry picked from commit 1ef32833035629c1b3644d77fdc9c234992090f3)
This commit is contained in:
@@ -1787,6 +1787,85 @@ bool PartPlate::check_mixture_of_pla_and_petg(const DynamicPrintConfig &config)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PartPlate::check_compatible_of_nozzle_and_filament(const DynamicPrintConfig &config, const std::vector<std::string> &filament_presets, std::string &error_msg)
|
||||
{
|
||||
float nozzle_diameter = config.option<ConfigOptionFloatsNullable>("nozzle_diameter")->values[0];
|
||||
auto volume_type_opt = config.option<ConfigOptionEnumsGeneric>("nozzle_volume_type");
|
||||
|
||||
auto get_filament_alias = [](std::string preset_name) -> std::string {
|
||||
size_t at_pos = preset_name.find('@');
|
||||
std::string alias = preset_name.substr(0, at_pos);
|
||||
size_t first = alias.find_first_not_of(' ');
|
||||
if (first == std::string::npos) return "";
|
||||
size_t last = alias.find_last_not_of(' ');
|
||||
return alias.substr(first, last - first + 1);
|
||||
};
|
||||
|
||||
bool with_same_volume_type = std::all_of(volume_type_opt->values.begin(), volume_type_opt->values.end(),
|
||||
[first_value = volume_type_opt->values[0]](int value) { return value == first_value; });
|
||||
|
||||
std::set<std::string> selected_filament_alias;
|
||||
for (auto &filament_preset : filament_presets) { selected_filament_alias.insert(get_filament_alias(filament_preset)); }
|
||||
|
||||
auto get_incompatible_selected = [&](const NozzleVolumeType volume_type) -> std::set<std::string> {
|
||||
std::vector<std::string> incompatible_filaments = Print::get_incompatible_filaments_by_nozzle(nozzle_diameter, volume_type);
|
||||
std::set<std::string> ret;
|
||||
for (auto &filament : selected_filament_alias) {
|
||||
if (std::find(incompatible_filaments.begin(), incompatible_filaments.end(), filament) != incompatible_filaments.end()) ret.insert(filament);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
auto get_nozzle_msg = [](const float nozzle_diameter, const NozzleVolumeType volume_type) -> std::string {
|
||||
std::ostringstream oss;
|
||||
oss << std::fixed << std::setprecision(1) << nozzle_diameter;
|
||||
std::string nozzle_msg = oss.str();
|
||||
((nozzle_msg += "mm ") += _u8L(get_nozzle_volume_type_string(volume_type))) += _u8L(" nozzle");
|
||||
return nozzle_msg;
|
||||
};
|
||||
|
||||
auto get_incompatible_filament_msg = [](const std::set<std::string> &incompatible_selected_filaments) -> std::string {
|
||||
std::string filament_str;
|
||||
size_t idx = 0;
|
||||
for (const auto &filament : incompatible_selected_filaments) {
|
||||
if (idx > 0) filament_str += ',';
|
||||
filament_str += filament;
|
||||
++idx;
|
||||
}
|
||||
return filament_str;
|
||||
};
|
||||
|
||||
error_msg.clear();
|
||||
|
||||
std::set<int> nozzle_volumes(volume_type_opt->values.begin(), volume_type_opt->values.end());
|
||||
std::map<NozzleVolumeType, std::set<std::string>> incompatible_selected_map;
|
||||
|
||||
for (auto volume_type_value : nozzle_volumes) {
|
||||
NozzleVolumeType volume_type = static_cast<NozzleVolumeType>(volume_type_value);
|
||||
auto incompatible_selected = get_incompatible_selected(volume_type);
|
||||
if (!incompatible_selected.empty()) incompatible_selected_map[volume_type] = incompatible_selected;
|
||||
}
|
||||
|
||||
if (incompatible_selected_map.empty()) return true;
|
||||
|
||||
if (incompatible_selected_map.size() == 1) {
|
||||
auto elem = incompatible_selected_map.begin();
|
||||
NozzleVolumeType volume_type = elem->first;
|
||||
auto incompatible_selected = elem->second;
|
||||
error_msg = GUI::format(_L("It is not recommended to print the following filament(s) with %1%: %2%\n"), get_nozzle_msg(nozzle_diameter, volume_type),
|
||||
get_incompatible_filament_msg(incompatible_selected));
|
||||
} else {
|
||||
std::string warning_msg = _u8L("It is not recommended to use the following nozzle and filament combinations:\n");
|
||||
for (auto &elem : incompatible_selected_map) {
|
||||
NozzleVolumeType volume_type = elem.first;
|
||||
auto incompatible_selected = elem.second;
|
||||
warning_msg += GUI::format(_L("%1% with %2%\n"),get_nozzle_msg(nozzle_diameter, volume_type), get_incompatible_filament_msg(incompatible_selected));
|
||||
}
|
||||
error_msg = warning_msg;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*Vec3d PartPlate::calculate_wipe_tower_size(const DynamicPrintConfig &config, const double w, const double wipe_volume, int plate_extruder_size, bool use_global_objects) const
|
||||
{
|
||||
Vec3d wipe_tower_size;
|
||||
|
||||
Reference in New Issue
Block a user