From e4eec90046cafe92461d0e5ab944f12e63588aaa Mon Sep 17 00:00:00 2001 From: bubnikv Date: Tue, 6 Nov 2018 19:09:54 +0100 Subject: [PATCH] Fixed loading of old 3mf files. --- src/libslic3r/Config.hpp | 1 + src/slic3r/GUI/Plater.cpp | 28 +++++++++++++++++++--------- src/slic3r/GUI/Preset.cpp | 12 +++++++----- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index fb42a85ae8..64548bf8d9 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1237,6 +1237,7 @@ public: 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. 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. // This DynamicConfig will take ownership of opt. diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 911c930efa..f5561a5ecb 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1151,16 +1151,26 @@ std::vector Plater::priv::load_files(const std::vector &input_ try { if (type_3mf || type_zip_amf) { DynamicPrintConfig config; - config.apply(FullPrintConfig::defaults()); - model = Slic3r::Model::read_from_archive(path.string(), &config, false); - 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(); } + { + DynamicPrintConfig config_loaded; + model = Slic3r::Model::read_from_archive(path.string(), &config_loaded, false); + // Based on the printer technology field found in the loaded config, select the base for the config, + PrinterTechnology printer_technology = Preset::printer_technology(config_loaded); + if (! config_loaded.empty()) { + config.apply(printer_technology == ptFFF ? + static_cast(FullPrintConfig::defaults()) : + static_cast(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()); - // 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 { model = Slic3r::Model::read_from_file(path.string(), nullptr, false); for (auto obj : model.objects) diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index bd43d01ca8..892b391c2b 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -170,10 +170,12 @@ void Preset::set_num_extruders(DynamicPrintConfig &config, unsigned int num_extr { const auto &defaults = FullPrintConfig::defaults(); for (const std::string &key : Preset::nozzle_options()) { + if (key == "default_filament_profile") + continue; auto *opt = config.option(key, false); assert(opt != nullptr); assert(opt->is_vector()); - if (opt != nullptr && opt->is_vector() && key != "default_filament_profile") + if (opt != nullptr && opt->is_vector()) static_cast(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. for (const std::string &key : { "filament_settings_id" }) { auto *opt = config.option(key, false); - assert(opt != nullptr); - assert(opt->type() == coStrings); + assert(opt == nullptr || opt->type() == coStrings); if (opt != nullptr && opt->type() == coStrings) static_cast(opt)->values.resize(n, std::string()); } @@ -534,7 +535,8 @@ Preset& PresetCollection::load_external_preset( cfg.apply_only(config, cfg.keys(), true); // Is there a preset already loaded with the name stored inside the config? std::deque::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. if (select) this->select_preset(it - m_presets.begin()); @@ -542,7 +544,7 @@ Preset& PresetCollection::load_external_preset( } // Update the "inherits" field. 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? if (it->vendor == nullptr) inherits = it->inherits();