Fix of fill_pattern handling in the GUI with 100% infill off-by-one #4999

This commit is contained in:
Vojtech Bubnik 2020-12-07 17:52:37 +01:00
parent 042bfe6be4
commit b27e18c970

View File

@ -2,6 +2,7 @@
#include "ConfigManipulation.hpp" #include "ConfigManipulation.hpp"
#include "I18N.hpp" #include "I18N.hpp"
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "format.hpp"
#include "libslic3r/Model.hpp" #include "libslic3r/Model.hpp"
#include "libslic3r/PresetBundle.hpp" #include "libslic3r/PresetBundle.hpp"
@ -184,30 +185,21 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
} }
if (config->option<ConfigOptionPercent>("fill_density")->value == 100) { if (config->option<ConfigOptionPercent>("fill_density")->value == 100) {
auto fill_pattern = config->option<ConfigOptionEnum<InfillPattern>>("fill_pattern")->value; std::string fill_pattern = config->option<ConfigOptionEnum<InfillPattern>>("fill_pattern")->serialize();
std::string str_fill_pattern = ""; const auto &top_fill_pattern_values = config->def()->get("top_fill_pattern")->enum_values;
t_config_enum_values map_names = config->option<ConfigOptionEnum<InfillPattern>>("fill_pattern")->get_enum_values(); bool correct_100p_fill = std::find(top_fill_pattern_values.begin(), top_fill_pattern_values.end(), fill_pattern) != top_fill_pattern_values.end();
for (auto it : map_names) { if (!correct_100p_fill) {
if (fill_pattern == it.second) {
str_fill_pattern = it.first;
break;
}
}
if (!str_fill_pattern.empty()) {
const std::vector<std::string>& external_fill_pattern = config->def()->get("top_fill_pattern")->enum_values;
bool correct_100p_fill = false;
for (const std::string& fill : external_fill_pattern)
{
if (str_fill_pattern == fill)
correct_100p_fill = true;
}
// get fill_pattern name from enum_labels for using this one at dialog_msg // get fill_pattern name from enum_labels for using this one at dialog_msg
str_fill_pattern = _utf8(config->def()->get("fill_pattern")->enum_labels[fill_pattern]); const ConfigOptionDef *fill_pattern_def = config->def()->get("fill_pattern");
if (!correct_100p_fill) { assert(fill_pattern_def != nullptr);
wxString msg_text = GUI::from_u8((boost::format(_utf8(L("The %1% infill pattern is not supposed to work at 100%% density."))) % str_fill_pattern).str()); auto it_pattern = std::find(fill_pattern_def->enum_values.begin(), fill_pattern_def->enum_values.end(), fill_pattern);
assert(it_pattern != fill_pattern_def->enum_values.end());
if (it_pattern != fill_pattern_def->enum_values.end()) {
wxString msg_text = GUI::format_wxstr(_L("The %1% infill pattern is not supposed to work at 100%% density."),
fill_pattern_def->enum_labels[it_pattern - fill_pattern_def->enum_values.begin()]);
if (is_global_config) if (is_global_config)
msg_text += "\n\n" + _(L("Shall I switch to rectilinear fill pattern?")); msg_text += "\n\n" + _L("Shall I switch to rectilinear fill pattern?");
wxMessageDialog dialog(nullptr, msg_text, _(L("Infill")), wxMessageDialog dialog(nullptr, msg_text, _L("Infill"),
wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK) ); wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK) );
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
auto answer = dialog.ShowModal(); auto answer = dialog.ShowModal();