mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-07 14:04:03 -06:00
Merge branch 'master' into python_type_hinting
This commit is contained in:
commit
98a6568313
416 changed files with 160213 additions and 173190 deletions
|
@ -2,9 +2,13 @@
|
|||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
import UM.VersionUpgrade #To indicate that a file is of incorrect format.
|
||||
import UM.VersionUpgradeManager #To schedule more files to be upgraded.
|
||||
import UM.Resources #To get the config storage path.
|
||||
|
||||
import configparser #To read config files.
|
||||
import io #To write config files to strings as if they were files.
|
||||
import os.path #To get the path to write new user profiles to.
|
||||
import urllib #To serialise the user container file name properly.
|
||||
|
||||
## Creates a new machine instance instance by parsing a serialised machine
|
||||
# instance in version 1 of the file format.
|
||||
|
@ -79,39 +83,40 @@ class MachineInstance:
|
|||
variant_materials = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariantForMaterials(self._variant_name, type_name)
|
||||
|
||||
#Convert to quality profile if we have one of the built-in profiles, otherwise convert to a quality-changes profile.
|
||||
if has_machine_qualities:
|
||||
material_name_in_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateMaterialForProfiles(self._active_material_name)
|
||||
variant_name_in_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariantForProfiles(self._variant_name)
|
||||
if self._active_profile_name in VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.builtInProfiles(): #This is a built-in profile name. Convert to quality.
|
||||
quality_name = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name)
|
||||
else:
|
||||
quality_name = "normal" #We have a quality-changes profile. Base it on normal, since we have no information to indicate which one it should be based on.
|
||||
if self._active_material_name == "PLA" and self._type_name == "ultimaker2plus": #UM2+ uses a different naming scheme for PLA profiles.
|
||||
active_quality = material_name_in_quality + "_" + variant_name_in_quality + "_" + quality_name
|
||||
else:
|
||||
printer_name_in_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinterForProfile(self._type_name)
|
||||
active_quality = printer_name_in_quality + "_" + material_name_in_quality + "_" + variant_name_in_quality + "_" + quality_name
|
||||
|
||||
if self._active_profile_name in VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.builtInProfiles():
|
||||
active_quality_changes = "empty_quality_changes"
|
||||
else: #No built-in profile. Translate this profile to quality-changes.
|
||||
active_quality_changes = material_name_in_quality + "_" + variant_name_in_quality + "_" + quality_name
|
||||
if self._active_profile_name in VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.builtInProfiles():
|
||||
active_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name)
|
||||
active_quality_changes = "empty_quality_changes"
|
||||
else:
|
||||
if self._active_profile_name in VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.builtInProfiles():
|
||||
active_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name)
|
||||
active_quality_changes = "empty_quality_changes"
|
||||
else:
|
||||
active_quality = "normal"
|
||||
active_quality_changes = self._active_profile_name
|
||||
active_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.getQualityFallback(type_name, variant, active_material)
|
||||
active_quality_changes = self._active_profile_name
|
||||
|
||||
if has_machine_qualities: #This machine now has machine-quality profiles.
|
||||
active_material += "_" + variant_materials #That means that the profile was split into multiple.
|
||||
current_settings = "empty" #The profile didn't know the definition ID when it was upgraded, so it will have been invalid. Sorry, your current settings are lost now.
|
||||
else:
|
||||
current_settings = self._name + "_current_settings"
|
||||
active_material += "_" + variant_materials
|
||||
|
||||
#Create a new user profile and schedule it to be upgraded.
|
||||
user_profile = configparser.ConfigParser(interpolation = None)
|
||||
user_profile["general"] = {
|
||||
"version": "2",
|
||||
"name": "Current settings",
|
||||
"definition": type_name
|
||||
}
|
||||
user_profile["metadata"] = {
|
||||
"type": "user",
|
||||
"machine": self._name
|
||||
}
|
||||
user_profile["values"] = {}
|
||||
|
||||
version_upgrade_manager = UM.VersionUpgradeManager.VersionUpgradeManager.getInstance()
|
||||
user_storage = os.path.join(UM.Resources.getDataStoragePath(), next(iter(version_upgrade_manager.getStoragePaths("user"))))
|
||||
user_profile_file = os.path.join(user_storage, urllib.parse.quote_plus(self._name) + "_current_settings.inst.cfg")
|
||||
if not os.path.exists(user_storage):
|
||||
os.makedirs(user_storage)
|
||||
with open(user_profile_file, "w", encoding = "utf-8") as file_handle:
|
||||
user_profile.write(file_handle)
|
||||
version_upgrade_manager.upgradeExtraFile(user_storage, urllib.parse.quote_plus(self._name), "user")
|
||||
|
||||
containers = [
|
||||
current_settings,
|
||||
self._name + "_current_settings", #The current profile doesn't know the definition ID when it was upgraded, only the instance ID, so it will be invalid. Sorry, your current settings are lost now.
|
||||
active_quality_changes,
|
||||
active_quality,
|
||||
active_material,
|
||||
|
|
|
@ -5,6 +5,7 @@ import configparser #To read config files.
|
|||
import io #To write config files to strings as if they were files.
|
||||
|
||||
import UM.VersionUpgrade
|
||||
from UM.Logger import Logger
|
||||
|
||||
## Creates a new profile instance by parsing a serialised profile in version 1
|
||||
# of the file format.
|
||||
|
@ -49,7 +50,7 @@ class Profile:
|
|||
self._machine_type_id = parser.get("general", "machine_type", fallback = None)
|
||||
self._machine_variant_name = parser.get("general", "machine_variant", fallback = None)
|
||||
self._machine_instance_name = parser.get("general", "machine_instance", fallback = None)
|
||||
if "material" in parser["general"]:
|
||||
if "material" in parser["general"]: #Note: Material name is unused in this upgrade.
|
||||
self._material_name = parser.get("general", "material")
|
||||
elif self._type == "material":
|
||||
self._material_name = parser.get("general", "name", fallback = None)
|
||||
|
@ -80,7 +81,7 @@ class Profile:
|
|||
import VersionUpgrade21to22 # Import here to prevent circular dependencies.
|
||||
|
||||
if self._name == "Current settings":
|
||||
self._filename += "_current_settings" #This resolves a duplicate ID arising from how Cura 2.1 stores its current settings.
|
||||
return None, None #Can't upgrade these, because the new current profile needs to specify the definition ID and the old file only had the machine instance, not the definition.
|
||||
|
||||
config = configparser.ConfigParser(interpolation = None)
|
||||
|
||||
|
@ -94,10 +95,8 @@ class Profile:
|
|||
config.set("general", "definition", "fdmprinter") #In this case, the machine definition is unknown, and it might now have machine-specific profiles, in which case this will fail.
|
||||
|
||||
config.add_section("metadata")
|
||||
if self._type:
|
||||
config.set("metadata", "type", self._type)
|
||||
else:
|
||||
config.set("metadata", "type", "quality")
|
||||
config.set("metadata", "quality_type", "normal") #This feature doesn't exist in 2.1 yet, so we don't know the actual quality type. For now, always base it on normal.
|
||||
config.set("metadata", "type", "quality_changes")
|
||||
if self._weight:
|
||||
config.set("metadata", "weight", str(self._weight))
|
||||
if self._machine_variant_name:
|
||||
|
@ -107,13 +106,13 @@ class Profile:
|
|||
config.set("metadata", "variant", self._machine_variant_name)
|
||||
|
||||
if self._settings:
|
||||
VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings)
|
||||
self._settings = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings)
|
||||
config.add_section("values")
|
||||
for key, value in self._settings.items():
|
||||
config.set("values", key, str(value))
|
||||
|
||||
if self._changed_settings_defaults:
|
||||
VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._changed_settings_defaults)
|
||||
self._changed_settings_defaults = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._changed_settings_defaults)
|
||||
config.add_section("defaults")
|
||||
for key, value in self._changed_settings_defaults.items():
|
||||
config.set("defaults", key, str(value))
|
||||
|
@ -126,34 +125,6 @@ class Profile:
|
|||
for item in disabled_settings_defaults[1:]:
|
||||
disabled_defaults_string += "," + str(item)
|
||||
|
||||
#Material metadata may cause the file to split, so do it last to minimise processing time (do more with the copy).
|
||||
filenames = []
|
||||
configs = []
|
||||
if self._material_name and self._type != "material":
|
||||
config.set("metadata", "material", self._material_name)
|
||||
filenames.append(self._filename)
|
||||
configs.append(config)
|
||||
elif self._type != "material" and self._machine_type_id in VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.machinesWithMachineQuality():
|
||||
#Split this profile into multiple profiles, one for each material.
|
||||
_new_materials = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.machinesWithMachineQuality()[self._machine_type_id]["materials"]
|
||||
_new_variants = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.machinesWithMachineQuality()[self._machine_type_id]["variants"]
|
||||
translated_machine = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinter(self._machine_type_id)
|
||||
for material_id in _new_materials:
|
||||
for variant_id in _new_variants:
|
||||
variant_id_new = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariant(variant_id, translated_machine)
|
||||
filenames.append("{profile}_{material}_{variant}".format(profile = self._filename, material = material_id, variant = variant_id_new))
|
||||
config_copy = configparser.ConfigParser(interpolation = None)
|
||||
config_copy.read_dict(config) #Copy the config to a new ConfigParser instance.
|
||||
variant_id_new_materials = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariantForMaterials(variant_id, translated_machine)
|
||||
config_copy.set("metadata", "material", "{material}_{variant}".format(material = material_id, variant = variant_id_new_materials))
|
||||
configs.append(config_copy)
|
||||
else:
|
||||
configs.append(config)
|
||||
filenames.append(self._filename)
|
||||
|
||||
outputs = []
|
||||
for config in configs:
|
||||
output = io.StringIO()
|
||||
config.write(output)
|
||||
outputs.append(output.getvalue())
|
||||
return filenames, outputs
|
||||
output = io.StringIO()
|
||||
config.write(output)
|
||||
return [self._filename], [output.getvalue()]
|
|
@ -65,11 +65,63 @@ _printer_translations_profiles = {
|
|||
}
|
||||
|
||||
## How to translate profile names from the old version to the new.
|
||||
#
|
||||
# This must have an entry for every built-in profile, since it also services
|
||||
# as a set for which profiles were built-in.
|
||||
_profile_translations = {
|
||||
"Low Quality": "low",
|
||||
"Normal Quality": "normal",
|
||||
"High Quality": "high",
|
||||
"Ulti Quality": "high" #This one doesn't have an equivalent. Map it to high.
|
||||
"Ulti Quality": "high", #This one doesn't have an equivalent. Map it to high.
|
||||
"abs_0.25_normal": "um2p_abs_0.25_normal",
|
||||
"abs_0.4_fast": "um2p_abs_0.4_fast",
|
||||
"abs_0.4_high": "um2p_abs_0.4_high",
|
||||
"abs_0.4_normal": "um2p_abs_0.4_normal",
|
||||
"abs_0.6_normal": "um2p_abs_0.6_normal",
|
||||
"abs_0.8_normal": "um2p_abs_0.8_normal",
|
||||
"cpe_0.25_normal": "um2p_cpe_0.25_normal",
|
||||
"cpe_0.4_fast": "um2p_cpe_0.4_fast",
|
||||
"cpe_0.4_high": "um2p_cpe_0.4_high",
|
||||
"cpe_0.4_normal": "um2p_cpe_0.4_normal",
|
||||
"cpe_0.6_normal": "um2p_cpe_0.6_normal",
|
||||
"cpe_0.8_normal": "um2p_cpe_0.8_normal",
|
||||
"cpep_0.4_draft": "um2p_cpep_0.4_draft",
|
||||
"cpep_0.4_normal": "um2p_cpep_0.4_normal",
|
||||
"cpep_0.6_draft": "um2p_cpep_0.6_draft",
|
||||
"cpep_0.6_normal": "um2p_cpep_0.6_normal",
|
||||
"cpep_0.8_draft": "um2p_cpep_0.8_draft",
|
||||
"cpep_0.8_normal": "um2p_cpep_0.8_normal",
|
||||
"nylon_0.25_high": "um2p_nylon_0.25_high",
|
||||
"nylon_0.25_normal": "um2p_nylon_0.25_normal",
|
||||
"nylon_0.4_fast": "um2p_nylon_0.4_fast",
|
||||
"nylon_0.4_normal": "um2p_nylon_0.4_normal",
|
||||
"nylon_0.6_fast": "um2p_nylon_0.6_fast",
|
||||
"nylon_0.6_normal": "um2p_nylon_0.6_normal",
|
||||
"nylon_0.8_draft": "um2p_nylon_0.8_draft",
|
||||
"nylon_0.8_normal": "um2p_nylon_0.8_normal",
|
||||
"pc_0.25_high": "um2p_pc_0.25_high",
|
||||
"pc_0.25_normal": "um2p_pc_0.25_normal",
|
||||
"pc_0.4_fast": "um2p_pc_0.4_fast",
|
||||
"pc_0.4_normal": "um2p_pc_0.4_normal",
|
||||
"pc_0.6_fast": "um2p_pc_0.6_fast",
|
||||
"pc_0.6_normal": "um2p_pc_0.6_normal",
|
||||
"pc_0.8_draft": "um2p_pc_0.8_draft",
|
||||
"pc_0.8_normal": "um2p_pc_0.8_normal",
|
||||
"pla_0.25_normal": "pla_0.25_normal", #Note that the PLA profiles don't get the um2p_ prefix, though they are for UM2+.
|
||||
"pla_0.4_fast": "pla_0.4_fast",
|
||||
"pla_0.4_high": "pla_0.4_high",
|
||||
"pla_0.4_normal": "pla_0.4_normal",
|
||||
"pla_0.6_normal": "pla_0.6_normal",
|
||||
"pla_0.8_normal": "pla_0.8_normal",
|
||||
"tpu_0.25_high": "um2p_tpu_0.25_high",
|
||||
"tpu_0.4_normal": "um2p_tpu_0.4_normal",
|
||||
"tpu_0.6_fast": "um2p_tpu_0.6_fast"
|
||||
}
|
||||
|
||||
## Settings that are no longer in the new version.
|
||||
_removed_settings = {
|
||||
"fill_perimeter_gaps",
|
||||
"support_area_smoothing"
|
||||
}
|
||||
|
||||
## How to translate setting names from the old version to the new.
|
||||
|
@ -78,6 +130,7 @@ _setting_name_translations = {
|
|||
"remove_overlapping_walls_enabled": "travel_compensate_overlapping_walls_enabled",
|
||||
"remove_overlapping_walls_x_enabled": "travel_compensate_overlapping_walls_x_enabled",
|
||||
"retraction_hop": "retraction_hop_enabled",
|
||||
"skin_overlap": "infill_overlap",
|
||||
"skirt_line_width": "skirt_brim_line_width",
|
||||
"skirt_minimal_length": "skirt_brim_minimal_length",
|
||||
"skirt_speed": "skirt_brim_speed",
|
||||
|
@ -91,6 +144,54 @@ _setting_name_translations = {
|
|||
"support_roof_pattern": "support_interface_pattern"
|
||||
}
|
||||
|
||||
## Custom profiles become quality_changes. This dictates which quality to base
|
||||
# the quality_changes profile on.
|
||||
#
|
||||
# Which quality profile to base the quality_changes on depends on the machine,
|
||||
# material and nozzle.
|
||||
#
|
||||
# If a current configuration is missing, fall back to "normal".
|
||||
_quality_fallbacks = {
|
||||
"ultimaker2_plus": {
|
||||
"ultimaker2_plus_0.25": {
|
||||
"generic_abs": "um2p_abs_0.25_normal",
|
||||
"generic_cpe": "um2p_cpe_0.25_normal",
|
||||
#No CPE+.
|
||||
"generic_nylon": "um2p_nylon_0.25_normal",
|
||||
"generic_pc": "um2p_pc_0.25_normal",
|
||||
"generic_pla": "pla_0.25_normal",
|
||||
"generic_tpu": "um2p_tpu_0.25_high"
|
||||
},
|
||||
"ultimaker2_plus_0.4": {
|
||||
"generic_abs": "um2p_abs_0.4_normal",
|
||||
"generic_cpe": "um2p_cpe_0.4_normal",
|
||||
"generic_cpep": "um2p_cpep_0.4_normal",
|
||||
"generic_nylon": "um2p_nylon_0.4_normal",
|
||||
"generic_pc": "um2p_pc_0.4_normal",
|
||||
"generic_pla": "pla_0.4_normal",
|
||||
"generic_tpu": "um2p_tpu_0.4_normal"
|
||||
},
|
||||
"ultimaker2_plus_0.6": {
|
||||
"generic_abs": "um2p_abs_0.6_normal",
|
||||
"generic_cpe": "um2p_cpe_0.6_normal",
|
||||
"generic_cpep": "um2p_cpep_0.6_normal",
|
||||
"generic_nylon": "um2p_nylon_0.6_normal",
|
||||
"generic_pc": "um2p_pc_0.6_normal",
|
||||
"generic_pla": "pla_0.6_normal",
|
||||
"generic_tpu": "um2p_tpu_0.6_fast",
|
||||
},
|
||||
"ultimaker2_plus_0.8": {
|
||||
"generic_abs": "um2p_abs_0.8_normal",
|
||||
"generic_cpe": "um2p_cpe_0.8_normal",
|
||||
"generic_cpep": "um2p_cpep_0.8_normal",
|
||||
"generic_nylon": "um2p_nylon_0.8_normal",
|
||||
"generic_pc": "um2p_pc_0.8_normal",
|
||||
"generic_pla": "pla_0.8_normal",
|
||||
#No TPU.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
## How to translate variants of specific machines from the old version to the
|
||||
# new.
|
||||
_variant_translations = {
|
||||
|
@ -150,6 +251,25 @@ class VersionUpgrade21to22(VersionUpgrade):
|
|||
parser.read_string(serialised)
|
||||
return int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
|
||||
|
||||
## Gets the fallback quality to use for a specific machine-variant-material
|
||||
# combination.
|
||||
#
|
||||
# For custom profiles we fall back onto this quality profile, since we
|
||||
# don't know which quality profile it was based on.
|
||||
#
|
||||
# \param machine The machine ID of the user's configuration in 2.2.
|
||||
# \param variant The variant ID of the user's configuration in 2.2.
|
||||
# \param material The material ID of the user's configuration in 2.2.
|
||||
@staticmethod
|
||||
def getQualityFallback(machine, variant, material):
|
||||
if machine not in _quality_fallbacks:
|
||||
return "normal"
|
||||
if variant not in _quality_fallbacks[machine]:
|
||||
return "normal"
|
||||
if material not in _quality_fallbacks[machine][variant]:
|
||||
return "normal"
|
||||
return _quality_fallbacks[machine][variant][material]
|
||||
|
||||
## Gets the set of built-in profile names in Cura 2.1.
|
||||
#
|
||||
# This is required to test if profiles should be converted to a quality
|
||||
|
@ -271,15 +391,21 @@ class VersionUpgrade21to22(VersionUpgrade):
|
|||
# \return The same dictionary.
|
||||
@staticmethod
|
||||
def translateSettings(settings):
|
||||
new_settings = {}
|
||||
for key, value in settings.items():
|
||||
if key == "fill_perimeter_gaps": #Setting is removed.
|
||||
del settings[key]
|
||||
elif key == "retraction_combing": #Combing was made into an enum instead of a boolean.
|
||||
settings[key] = "off" if (value == "False") else "all"
|
||||
elif key in _setting_name_translations:
|
||||
del settings[key]
|
||||
settings[_setting_name_translations[key]] = value
|
||||
return settings
|
||||
if key in _removed_settings:
|
||||
continue
|
||||
if key == "retraction_combing": #Combing was made into an enum instead of a boolean.
|
||||
new_settings[key] = "off" if (value == "False") else "all"
|
||||
continue
|
||||
if key == "cool_fan_full_layer": #Layer counting was made one-indexed.
|
||||
new_settings[key] = str(int(value) + 1)
|
||||
continue
|
||||
if key in _setting_name_translations:
|
||||
new_settings[_setting_name_translations[key]] = value
|
||||
continue
|
||||
new_settings[key] = value
|
||||
return new_settings
|
||||
|
||||
## Translates a setting name for the change from Cura 2.1 to 2.2.
|
||||
#
|
||||
|
|
|
@ -35,6 +35,10 @@ def getMetaData():
|
|||
"preferences": {
|
||||
"get_version": upgrade.getCfgVersion,
|
||||
"location": {"."}
|
||||
},
|
||||
"user": {
|
||||
"get_version": upgrade.getCfgVersion,
|
||||
"location": {"./user"}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue