allow bad key/value from imported .3mf/gcode

these will be silently ignored and so the default value will be used.
This commit is contained in:
supermerill 2020-11-28 20:50:24 +01:00
parent afcdb1b6bb
commit 19d2115f20
2 changed files with 8 additions and 10 deletions

View File

@ -530,10 +530,11 @@ bool ConfigBase::set_deserialize_nothrow(const t_config_option_key &opt_key_src,
return this->set_deserialize_raw(opt_key, value, append); return this->set_deserialize_raw(opt_key, value, append);
} }
void ConfigBase::set_deserialize(const t_config_option_key &opt_key_src, const std::string &value_src, bool append) void ConfigBase::set_deserialize(const t_config_option_key& opt_key_src, const std::string& value_src, bool append)
{ {
if (! this->set_deserialize_nothrow(opt_key_src, value_src, append)) if (!this->set_deserialize_nothrow(opt_key_src, value_src, append)) {
throw BadOptionTypeException(format("ConfigBase::set_deserialize() failed for parameter \"%1%\", value \"%2%\"", opt_key_src, value_src)); throw BadOptionTypeException(format("ConfigBase::set_deserialize() failed for parameter \"%1%\", value \"%2%\"", opt_key_src, value_src));
}
} }
void ConfigBase::set_deserialize(std::initializer_list<SetDeserializeItem> items) void ConfigBase::set_deserialize(std::initializer_list<SetDeserializeItem> items)
@ -580,10 +581,7 @@ bool ConfigBase::set_deserialize_raw(const t_config_option_key &opt_key_src, con
if (opt == nullptr) if (opt == nullptr)
throw new UnknownOptionException(opt_key); throw new UnknownOptionException(opt_key);
bool ok= opt->deserialize(value, append); bool ok= opt->deserialize(value, append);
if (!ok) { return ok;
return opt->deserialize(value, append);
}
return true;
} }
// Return an absolute value of a possibly relative config variable. // Return an absolute value of a possibly relative config variable.
@ -783,8 +781,9 @@ size_t ConfigBase::load_from_gcode_string(const char* str)
if (key == nullptr) if (key == nullptr)
break; break;
try { try {
this->set_deserialize(std::string(key, key_end), std::string(value, end)); //change it from set_deserialize to set_deserialize_nothrow to allow bad/old config to swtch to default value.
++num_key_value_pairs; if(this->set_deserialize_nothrow(std::string(key, key_end), std::string(value, end)))
++num_key_value_pairs;
} }
catch (UnknownOptionException & /* e */) { catch (UnknownOptionException & /* e */) {
// ignore // ignore

View File

@ -714,7 +714,6 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L("Fill pattern for bottom infill. This only affects the bottom visible layer, and not its adjacent solid shells."); def->tooltip = L("Fill pattern for bottom infill. This only affects the bottom visible layer, and not its adjacent solid shells.");
def->cli = "bottom-fill-pattern|external-fill-pattern=s"; def->cli = "bottom-fill-pattern|external-fill-pattern=s";
def->enum_keys_map = &ConfigOptionEnum<InfillPattern>::get_enum_values(); def->enum_keys_map = &ConfigOptionEnum<InfillPattern>::get_enum_values();
def->enum_values.push_back("rectilinear"); def->enum_values.push_back("rectilinear");
def->enum_values.push_back("rectilineargapfill"); def->enum_values.push_back("rectilineargapfill");
def->enum_values.push_back("monotonic"); def->enum_values.push_back("monotonic");