Fixed loading of old 3mf files.

This commit is contained in:
bubnikv 2018-11-06 19:09:54 +01:00
parent 879a7bb9e4
commit e4eec90046
3 changed files with 27 additions and 14 deletions

View File

@ -1237,6 +1237,7 @@ public:
ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) override; ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) override;
// Overrides ConfigBase::keys(). Collect names of all configuration values maintained by this configuration store. // Overrides ConfigBase::keys(). Collect names of all configuration values maintained by this configuration store.
t_config_option_keys keys() const override; t_config_option_keys keys() const override;
bool empty() const { return options.empty(); }
// Set a value for an opt_key. Returns true if the value did not exist yet. // Set a value for an opt_key. Returns true if the value did not exist yet.
// This DynamicConfig will take ownership of opt. // This DynamicConfig will take ownership of opt.

View File

@ -1151,16 +1151,26 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
try { try {
if (type_3mf || type_zip_amf) { if (type_3mf || type_zip_amf) {
DynamicPrintConfig config; DynamicPrintConfig config;
config.apply(FullPrintConfig::defaults()); {
model = Slic3r::Model::read_from_archive(path.string(), &config, false); DynamicPrintConfig config_loaded;
Preset::normalize(config); model = Slic3r::Model::read_from_archive(path.string(), &config_loaded, false);
wxGetApp().preset_bundle->load_config_model(filename.string(), std::move(config)); // Based on the printer technology field found in the loaded config, select the base for the config,
for (const auto &kv : main_frame->options_tabs()) { kv.second->load_current_preset(); } PrinterTechnology printer_technology = Preset::printer_technology(config_loaded);
if (! config_loaded.empty()) {
config.apply(printer_technology == ptFFF ?
static_cast<const ConfigBase&>(FullPrintConfig::defaults()) :
static_cast<const ConfigBase&>(SLAFullPrintConfig::defaults()));
// and place the loaded config over the base.
config += std::move(config_loaded);
}
}
if (! config.empty()) {
Preset::normalize(config);
wxGetApp().preset_bundle->load_config_model(filename.string(), std::move(config));
for (const auto &kv : main_frame->options_tabs())
kv.second->load_current_preset();
}
wxGetApp().app_config->update_config_dir(path.parent_path().string()); wxGetApp().app_config->update_config_dir(path.parent_path().string());
// forces the update of the config here, or it will invalidate the imported layer heights profile if done using the timer
// and if the config contains a "layer_height" different from the current defined one
// TODO:
// $self->async_apply_config;
} else { } else {
model = Slic3r::Model::read_from_file(path.string(), nullptr, false); model = Slic3r::Model::read_from_file(path.string(), nullptr, false);
for (auto obj : model.objects) for (auto obj : model.objects)

View File

@ -170,10 +170,12 @@ void Preset::set_num_extruders(DynamicPrintConfig &config, unsigned int num_extr
{ {
const auto &defaults = FullPrintConfig::defaults(); const auto &defaults = FullPrintConfig::defaults();
for (const std::string &key : Preset::nozzle_options()) { for (const std::string &key : Preset::nozzle_options()) {
if (key == "default_filament_profile")
continue;
auto *opt = config.option(key, false); auto *opt = config.option(key, false);
assert(opt != nullptr); assert(opt != nullptr);
assert(opt->is_vector()); assert(opt->is_vector());
if (opt != nullptr && opt->is_vector() && key != "default_filament_profile") if (opt != nullptr && opt->is_vector())
static_cast<ConfigOptionVectorBase*>(opt)->resize(num_extruders, defaults.option(key)); static_cast<ConfigOptionVectorBase*>(opt)->resize(num_extruders, defaults.option(key));
} }
} }
@ -202,8 +204,7 @@ void Preset::normalize(DynamicPrintConfig &config)
// The following keys are mandatory for the UI, but they are not part of FullPrintConfig, therefore they are handled separately. // 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" }) { for (const std::string &key : { "filament_settings_id" }) {
auto *opt = config.option(key, false); auto *opt = config.option(key, false);
assert(opt != nullptr); assert(opt == nullptr || opt->type() == coStrings);
assert(opt->type() == coStrings);
if (opt != nullptr && opt->type() == coStrings) if (opt != nullptr && opt->type() == coStrings)
static_cast<ConfigOptionStrings*>(opt)->values.resize(n, std::string()); static_cast<ConfigOptionStrings*>(opt)->values.resize(n, std::string());
} }
@ -534,7 +535,8 @@ Preset& PresetCollection::load_external_preset(
cfg.apply_only(config, cfg.keys(), true); cfg.apply_only(config, cfg.keys(), true);
// Is there a preset already loaded with the name stored inside the config? // Is there a preset already loaded with the name stored inside the config?
std::deque<Preset>::iterator it = this->find_preset_internal(original_name); std::deque<Preset>::iterator it = this->find_preset_internal(original_name);
if (it != m_presets.end() && it->name == original_name && profile_print_params_same(it->config, cfg)) { bool found = it != m_presets.end() && it->name == original_name;
if (found && profile_print_params_same(it->config, cfg)) {
// The preset exists and it matches the values stored inside config. // The preset exists and it matches the values stored inside config.
if (select) if (select)
this->select_preset(it - m_presets.begin()); this->select_preset(it - m_presets.begin());
@ -542,7 +544,7 @@ Preset& PresetCollection::load_external_preset(
} }
// Update the "inherits" field. // Update the "inherits" field.
std::string &inherits = Preset::inherits(cfg); std::string &inherits = Preset::inherits(cfg);
if (it != m_presets.end() && inherits.empty()) { if (found && inherits.empty()) {
// There is a profile with the same name already loaded. Should we update the "inherits" field? // There is a profile with the same name already loaded. Should we update the "inherits" field?
if (it->vendor == nullptr) if (it->vendor == nullptr)
inherits = it->inherits(); inherits = it->inherits();