From 05e232b498514f20a11fbbfc0f8ca2fe932d44d9 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Dec 2017 17:16:32 +0100 Subject: [PATCH] Move LegacyProfileReader-specific logic into the plug-in itself This had the documentation that it should edit the profiles returned by LegacyProfileReader. Instead, just return correct profiles from the reader... Contributes to issue CURA-4715. --- cura/Settings/CuraContainerRegistry.py | 19 ------------------- .../LegacyProfileReader.py | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/cura/Settings/CuraContainerRegistry.py b/cura/Settings/CuraContainerRegistry.py index f510a9fca9..26d3484a9f 100644 --- a/cura/Settings/CuraContainerRegistry.py +++ b/cura/Settings/CuraContainerRegistry.py @@ -218,25 +218,6 @@ class CuraContainerRegistry(ContainerRegistry): if type(profile_or_list) is not list: profile_or_list = [profile_or_list] - if len(profile_or_list) == 1: - # If there is only 1 stack file it means we're loading a legacy (pre-3.1) .curaprofile. - # In that case we find the per-extruder settings and put those in a new quality_changes container - # so that it is compatible with the new stack setup. - profile = profile_or_list[0] - extruder_stack_quality_changes_container = ContainerManager.getInstance().duplicateContainerInstance(profile) - extruder_stack_quality_changes_container.addMetaDataEntry("extruder", "fdmextruder") - - for quality_changes_setting_key in extruder_stack_quality_changes_container.getAllKeys(): - settable_per_extruder = extruder_stack_quality_changes_container.getProperty(quality_changes_setting_key, "settable_per_extruder") - if settable_per_extruder: - profile.removeInstance(quality_changes_setting_key, postpone_emit = True) - else: - extruder_stack_quality_changes_container.removeInstance(quality_changes_setting_key, postpone_emit = True) - - # We add the new container to the profile list so things like extruder positions are taken care of - # in the next code segment. - profile_or_list.append(extruder_stack_quality_changes_container) - # Import all profiles for profile_index, profile in enumerate(profile_or_list): if profile_index == 0: diff --git a/plugins/LegacyProfileReader/LegacyProfileReader.py b/plugins/LegacyProfileReader/LegacyProfileReader.py index 62ac12dc18..5f80379e49 100644 --- a/plugins/LegacyProfileReader/LegacyProfileReader.py +++ b/plugins/LegacyProfileReader/LegacyProfileReader.py @@ -13,6 +13,7 @@ from UM.PluginRegistry import PluginRegistry # For getting the path to this plu from UM.Settings.ContainerRegistry import ContainerRegistry #To create unique profile IDs. from UM.Settings.InstanceContainer import InstanceContainer # The new profile to make. from cura.ProfileReader import ProfileReader # The plug-in type to implement. +from cura.Settings.ExtruderManager import ExtruderManager #To get the current extruder definition. ## A plugin that reads profile data from legacy Cura versions. @@ -142,14 +143,13 @@ class LegacyProfileReader(ProfileReader): if len(profile.getAllKeys()) == 0: Logger.log("i", "A legacy profile was imported but everything evaluates to the defaults, creating an empty profile.") - # We need to downgrade the container to version 1 (in Cura 2.1) so the upgrade system can correctly upgrade - # it to the latest version. profile.addMetaDataEntry("type", "profile") # don't know what quality_type it is based on, so use "normal" by default profile.addMetaDataEntry("quality_type", "normal") profile.setName("Imported Legacy Profile") profile.setDirty(True) + #Serialise and deserialise in order to perform the version upgrade. parser = configparser.ConfigParser(interpolation=None) data = profile.serialize() parser.read_string(data) @@ -162,8 +162,20 @@ class LegacyProfileReader(ProfileReader): data = stream.getvalue() profile.deserialize(data) + #We need to return one extruder stack and one global stack. global_container_id = container_registry.uniqueName("Global Imported Legacy Profile") global_profile = profile.duplicate(new_id = global_container_id, new_name = "Imported Legacy Profile") #Needs to have the same name as the extruder profile. global_profile.setDirty(True) + #Only the extruder stack has an extruder metadata entry. + profile.addMetaDataEntry("extruder", ExtruderManager.getInstance().getActiveExtruderStack().definition) + + #Split all settings into per-extruder and global settings. + for setting_key in profile.getAllKeys(): + settable_per_extruder = global_container_stack.getProperty(setting_key, "settable_per_extruder") + if settable_per_extruder: + global_profile.removeInstance(setting_key) + else: + profile.removeInstance(setting_key) + return [global_profile, profile]