Improvement in the subtitution information dialog.

This commit is contained in:
bubnikv 2021-07-01 16:48:38 +02:00
parent 9c7743c1c7
commit 0a2a86dea4
5 changed files with 36 additions and 31 deletions

View File

@ -54,13 +54,13 @@ namespace ConfigHelpers {
return boost::iequals(value, "enabled") || boost::iequals(value, "on"); return boost::iequals(value, "enabled") || boost::iequals(value, "on");
} }
enum DeserializationSubstitution { enum class DeserializationSubstitution {
Disabled, Disabled,
DefaultsToFalse, DefaultsToFalse,
DefaultsToTrue DefaultsToTrue
}; };
enum DeserializationResult { enum class DeserializationResult {
Loaded, Loaded,
Substituted, Substituted,
Failed, Failed,
@ -1371,7 +1371,7 @@ public:
} else if (item_str == "0") { } else if (item_str == "0") {
new_value = false; new_value = false;
} else if (substitution != ConfigHelpers::DeserializationSubstitution::Disabled && ConfigHelpers::looks_like_enum_value(item_str)) { } else if (substitution != ConfigHelpers::DeserializationSubstitution::Disabled && ConfigHelpers::looks_like_enum_value(item_str)) {
new_value = ConfigHelpers::enum_looks_like_true_value(item_str) || substituted == ConfigHelpers::DeserializationSubstitution::DefaultsToTrue; new_value = ConfigHelpers::enum_looks_like_true_value(item_str) || substitution == ConfigHelpers::DeserializationSubstitution::DefaultsToTrue;
substituted = true; substituted = true;
} else } else
return ConfigHelpers::DeserializationResult::Failed; return ConfigHelpers::DeserializationResult::Failed;

View File

@ -5,6 +5,7 @@
#include <string> #include <string>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/any.hpp> #include <boost/any.hpp>
#if __APPLE__ #if __APPLE__
@ -259,6 +260,11 @@ void warning_catcher(wxWindow* parent, const wxString& message)
} }
static wxString bold(const wxString& str) static wxString bold(const wxString& str)
{
return wxString::Format("<b>%s</b>", str);
};
static wxString bold_string(const wxString& str)
{ {
return wxString::Format("<b>\"%s\"</b>", str); return wxString::Format("<b>\"%s\"</b>", str);
}; };
@ -290,14 +296,17 @@ static void add_config_substitutions(const ConfigSubstitutions& conf_substitutio
auto it = std::find(values.begin(), values.end(), key_val.first); auto it = std::find(values.begin(), values.end(), key_val.first);
if (it == values.end()) if (it == values.end())
break; break;
new_val = from_u8(_utf8(labels[it - values.begin()])); auto idx = it - values.begin();
new_val = wxString("\"") + values[idx] + "\"" + " (" + from_u8(_utf8(labels[idx])) + ")";
break; break;
} }
if (new_val.IsEmpty()) if (new_val.IsEmpty()) {
new_val = _L("Undef"); assert(false);
new_val = _L("Undefined");
}
} }
else else
new_val = from_u8(_utf8(labels[val])); new_val = wxString("\"") + values[val] + "\"" + " (" + from_u8(_utf8(labels[val])) + ")";
break; break;
} }
case coBool: case coBool:
@ -317,13 +326,21 @@ static void add_config_substitutions(const ConfigSubstitutions& conf_substitutio
assert(false); assert(false);
} }
changes += "<tr><td>" + bold(_(def->label)) + "</td><td>: " + changes += format_wxstr("<tr><td><b>\"%1%\" (%2%)</b></td><td>: ", def->opt_key, _(def->label)) +
format_wxstr(_L("new unknown value %1% was changed to default value %2%"), bold(conf_substitution.old_value), bold(new_val)) + format_wxstr(_L("%1% was substituted with %2%"), bold_string(conf_substitution.old_value), bold(new_val)) +
"</td></tr>"; "</td></tr>";
} }
changes += "</table>"; changes += "</table>";
} }
static wxString substitution_message(const wxString& changes)
{
return
_L("Most likely the configuration was produced by a newer version of PrusaSlicer or by some PrusaSlicer fork.") + " " +
_L("The following values were substituted:") + "\n" + changes + "\n\n" +
_L("Please review the substitutions and adjust them if needed.");
}
void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_substitutions) void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_substitutions)
{ {
wxString changes; wxString changes;
@ -341,37 +358,25 @@ void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_su
}; };
for (const PresetConfigSubstitutions& substitution : presets_config_substitutions) { for (const PresetConfigSubstitutions& substitution : presets_config_substitutions) {
changes += "\n\n" + format_wxstr("%1% : %2%", preset_type_name(substitution.preset_type), bold(substitution.preset_name)); changes += "\n\n" + format_wxstr("%1% : %2%", preset_type_name(substitution.preset_type), bold_string(substitution.preset_name));
if (!substitution.preset_file.empty()) if (!substitution.preset_file.empty())
changes += format_wxstr(" (%1%)", substitution.preset_file); changes += format_wxstr(" (%1%)", substitution.preset_file);
add_config_substitutions(substitution.substitutions, changes); add_config_substitutions(substitution.substitutions, changes);
} }
if (!changes.IsEmpty())
changes += "\n\n";
wxString message = format_wxstr( _L("Loading profiles found following incompatibilities:%1%" InfoDialog msg(nullptr, _L("Configuration bundle was loaded, however some configuration values were not recognized."), substitution_message(changes));
" To recover these files, incompatible values were changed to default values.\n"
" But data in files won't be changed until you save them in PrusaSlicer."), changes);
InfoDialog msg(nullptr, message);
msg.ShowModal(); msg.ShowModal();
} }
void show_substitutions_info(const ConfigSubstitutions& config_substitutions, const std::string& filename) void show_substitutions_info(const ConfigSubstitutions& config_substitutions, const std::string& filename)
{ {
wxString changes = "\n"; wxString changes = "\n";
add_config_substitutions(config_substitutions, changes); add_config_substitutions(config_substitutions, changes);
if (!changes.IsEmpty()) InfoDialog msg(nullptr,
changes += "\n\n"; format_wxstr(_L("Configuration file \"%1%\" was loaded, however some configuration values were not recognized."), from_u8(filename)),
substitution_message(changes));
wxString message = format(_L("Loading %1% file found incompatibilities.\n"
"To recover this file, incompatible values were changed to default values:%2%"
"But data in files won't be changed until you save them in PrusaSlicer."), bold(from_u8(filename)), changes);
InfoDialog msg(nullptr, message);
msg.ShowModal(); msg.ShowModal();
} }

View File

@ -110,8 +110,8 @@ ErrorDialog::ErrorDialog(wxWindow *parent, const wxString &msg, bool monospaced_
// InfoDialog // InfoDialog
InfoDialog::InfoDialog(wxWindow* parent, const wxString& msg) InfoDialog::InfoDialog(wxWindow* parent, const wxString &title, const wxString& msg)
: MsgDialog(parent, wxString::Format(_L("%s information"), SLIC3R_APP_NAME), _L("Note that")) : MsgDialog(parent, wxString::Format(_L("%s information"), SLIC3R_APP_NAME), title)
, msg(msg) , msg(msg)
{ {
this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));

View File

@ -70,7 +70,7 @@ private:
class InfoDialog : public MsgDialog class InfoDialog : public MsgDialog
{ {
public: public:
InfoDialog(wxWindow *parent, const wxString &msg); InfoDialog(wxWindow *parent, const wxString &title, const wxString &msg);
InfoDialog(InfoDialog&&) = delete; InfoDialog(InfoDialog&&) = delete;
InfoDialog(const InfoDialog&) = delete; InfoDialog(const InfoDialog&) = delete;
InfoDialog&operator=(InfoDialog&&) = delete; InfoDialog&operator=(InfoDialog&&) = delete;