Fix of a crash intruduced with e8247c5646

This commit is contained in:
bubnikv 2018-05-23 13:19:25 +02:00
parent 076b293fec
commit a9499ae45c
4 changed files with 29 additions and 15 deletions

View File

@ -546,7 +546,7 @@ filament_cost = 0
filament_density = 0 filament_density = 0
filament_diameter = 1.75 filament_diameter = 1.75
filament_notes = "" filament_notes = ""
filament_settings_id = filament_settings_id = ""
filament_soluble = 0 filament_soluble = 0
min_print_speed = 15 min_print_speed = 15
slowdown_below_layer_time = 20 slowdown_below_layer_time = 20

View File

@ -95,7 +95,7 @@ const std::string& var_dir()
std::string var(const std::string &file_name) std::string var(const std::string &file_name)
{ {
auto file = boost::filesystem::canonical(boost::filesystem::path(g_var_dir) / file_name).make_preferred(); auto file = (boost::filesystem::path(g_var_dir) / file_name).make_preferred();
return file.string(); return file.string();
} }

View File

@ -188,6 +188,14 @@ void Preset::normalize(DynamicPrintConfig &config)
if (opt != nullptr && opt->is_vector()) if (opt != nullptr && opt->is_vector())
static_cast<ConfigOptionVectorBase*>(opt)->resize(n, defaults.option(key)); static_cast<ConfigOptionVectorBase*>(opt)->resize(n, defaults.option(key));
} }
// The following keys are mandatory for the UI, but they are not part of FullPrintConfig, therefore they are handled separately.
for (const std::string &key : { "filament_settings_id" }) {
auto *opt = config.option(key, false);
assert(opt != nullptr);
assert(opt->type() == coStrings);
if (opt != nullptr && opt->type() == coStrings)
static_cast<ConfigOptionStrings*>(opt)->values.resize(n, std::string());
}
} }
} }

View File

@ -54,17 +54,15 @@ PresetBundle::PresetBundle() :
// Create the ID config keys, as they are not part of the Static print config classes. // Create the ID config keys, as they are not part of the Static print config classes.
this->prints.default_preset().config.opt_string("print_settings_id", true); this->prints.default_preset().config.opt_string("print_settings_id", true);
this->filaments.default_preset().config.opt_string("filament_settings_id", true); this->filaments.default_preset().config.option<ConfigOptionStrings>("filament_settings_id", true)->values.assign(1, std::string());
this->printers.default_preset().config.opt_string("printer_settings_id", true); this->printers.default_preset().config.opt_string("printer_settings_id", true);
// Create the "compatible printers" keys, as they are not part of the Static print config classes. // "compatible printers" are not mandatory yet.
this->filaments.default_preset().config.optptr("compatible_printers", true); //FIXME Rename "compatible_printers" and "compatible_printers_condition", as they are defined in both print and filament profiles,
this->filaments.default_preset().config.optptr("compatible_printers_condition", true); // therefore they are clashing when generating a a config file, G-code or AMF/3MF.
this->prints.default_preset().config.optptr("compatible_printers", true); // this->filaments.default_preset().config.optptr("compatible_printers", true);
this->prints.default_preset().config.optptr("compatible_printers_condition", true); // this->filaments.default_preset().config.optptr("compatible_printers_condition", true);
// Create the "inherits" keys. // this->prints.default_preset().config.optptr("compatible_printers", true);
this->prints.default_preset().config.optptr("inherits", true); // this->prints.default_preset().config.optptr("compatible_printers_condition", true);
this->filaments.default_preset().config.optptr("inherits", true);
this->printers.default_preset().config.optptr("inherits", true);
// Create the "printer_vendor", "printer_model" and "printer_variant" keys. // Create the "printer_vendor", "printer_model" and "printer_variant" keys.
this->printers.default_preset().config.optptr("printer_vendor", true); this->printers.default_preset().config.optptr("printer_vendor", true);
this->printers.default_preset().config.optptr("printer_model", true); this->printers.default_preset().config.optptr("printer_model", true);
@ -364,7 +362,9 @@ DynamicPrintConfig PresetBundle::full_config() const
DynamicPrintConfig out; DynamicPrintConfig out;
out.apply(FullPrintConfig()); out.apply(FullPrintConfig());
out.apply(this->prints.get_edited_preset().config); out.apply(this->prints.get_edited_preset().config);
out.apply(this->printers.get_edited_preset().config); // Add the default filament preset to have the "filament_preset_id" defined.
out.apply(this->filaments.default_preset().config);
out.apply(this->printers.get_edited_preset().config);
out.apply(this->project_config); out.apply(this->project_config);
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(out.option("nozzle_diameter")); auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(out.option("nozzle_diameter"));
@ -385,7 +385,7 @@ DynamicPrintConfig PresetBundle::full_config() const
std::vector<const ConfigOption*> filament_opts(num_extruders, nullptr); std::vector<const ConfigOption*> filament_opts(num_extruders, nullptr);
// loop through options and apply them to the resulting config. // loop through options and apply them to the resulting config.
for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) { for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) {
if (key == "compatible_printers") if (key == "compatible_printers" || key == "compatible_printers_condition")
continue; continue;
// Get a destination option. // Get a destination option.
ConfigOption *opt_dst = out.option(key, false); ConfigOption *opt_dst = out.option(key, false);
@ -403,7 +403,9 @@ DynamicPrintConfig PresetBundle::full_config() const
} }
} }
//FIXME These two value types clash between the print and filament profiles. They should be renamed.
out.erase("compatible_printers"); out.erase("compatible_printers");
out.erase("compatible_printers_condition");
static const char *keys[] = { "perimeter", "infill", "solid_infill", "support_material", "support_material_interface" }; static const char *keys[] = { "perimeter", "infill", "solid_infill", "support_material", "support_material_interface" };
for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); ++ i) { for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); ++ i) {
@ -838,13 +840,17 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
// Load the print, filament or printer preset. // Load the print, filament or printer preset.
const DynamicPrintConfig &default_config = presets->default_preset().config; const DynamicPrintConfig &default_config = presets->default_preset().config;
DynamicPrintConfig config(default_config); DynamicPrintConfig config(default_config);
std::vector<std::string> config_keys = config.keys();
// The following two keys are valid, but they are not mandatory.
config_keys.emplace_back("compatible_printers");
config_keys.emplace_back("compatible_printers_condition");
for (auto &kvp : section.second) for (auto &kvp : section.second)
config.set_deserialize(kvp.first, kvp.second.data()); config.set_deserialize(kvp.first, kvp.second.data());
Preset::normalize(config); Preset::normalize(config);
// Report configuration fields, which are misplaced into a wrong group. // Report configuration fields, which are misplaced into a wrong group.
std::string incorrect_keys; std::string incorrect_keys;
size_t n_incorrect_keys = 0; size_t n_incorrect_keys = 0;
for (const std::string &key : config.keys()) for (const std::string &key : config_keys)
if (! default_config.has(key)) { if (! default_config.has(key)) {
if (incorrect_keys.empty()) if (incorrect_keys.empty())
incorrect_keys = key; incorrect_keys = key;