mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Use findContainersMetadata whenever possible
This ensures that we only load those containers that we actually need the data of. Contributes to issue CURA-4243.
This commit is contained in:
parent
f7e048aee5
commit
6c4c7fff4d
14 changed files with 126 additions and 138 deletions
|
@ -463,9 +463,9 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
|||
result.append(i18n_catalog.i18nc("@item:material", "No material loaded"))
|
||||
continue
|
||||
|
||||
containers = self._container_registry.findInstanceContainers(type = "material", GUID = material_id)
|
||||
containers = self._container_registry.findInstanceContainersMetadata(type = "material", GUID = material_id)
|
||||
if containers:
|
||||
result.append(containers[0].getName())
|
||||
result.append(containers[0]["name"])
|
||||
else:
|
||||
result.append(i18n_catalog.i18nc("@item:material", "Unknown material"))
|
||||
return result
|
||||
|
@ -485,9 +485,9 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
|||
result.append("#00000000") #No material.
|
||||
continue
|
||||
|
||||
containers = self._container_registry.findInstanceContainers(type = "material", GUID = material_id)
|
||||
containers = self._container_registry.findInstanceContainersMetadata(type = "material", GUID = material_id)
|
||||
if containers:
|
||||
result.append(containers[0].getMetaDataEntry("color_code"))
|
||||
result.append(containers[0]["color_code"])
|
||||
else:
|
||||
result.append("#00000000") #Unknown material.
|
||||
return result
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2016 Ultimaker B.V.
|
||||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
# This collects a lot of quality and quality changes related code which was split between ContainerManager
|
||||
|
@ -245,7 +245,7 @@ class QualityManager:
|
|||
|
||||
machine_definition = self.getParentMachineDefinition(machine_definition)
|
||||
criteria["definition"] = machine_definition.getId()
|
||||
found_containers_with_machine_definition = ContainerRegistry.getInstance().findInstanceContainers(**criteria)
|
||||
found_containers_with_machine_definition = ContainerRegistry.getInstance().findInstanceContainersMetadata(**criteria)
|
||||
whole_machine_definition = self.getWholeMachineDefinition(machine_definition)
|
||||
if whole_machine_definition.getMetaDataEntry("has_machine_quality"):
|
||||
definition_id = machine_definition.getMetaDataEntry("quality_definition", whole_machine_definition.getId())
|
||||
|
|
|
@ -55,14 +55,14 @@ class ContainerManager(QObject):
|
|||
# \return The ID of the new container, or an empty string if duplication failed.
|
||||
@pyqtSlot(str, result = str)
|
||||
def duplicateContainer(self, container_id):
|
||||
containers = self._container_registry.findContainers(None, id = container_id)
|
||||
#TODO: It should be able to duplicate a container of which only the metadata is known.
|
||||
containers = self._container_registry.findContainers(id = container_id)
|
||||
if not containers:
|
||||
Logger.log("w", "Could duplicate container %s because it was not found.", container_id)
|
||||
return ""
|
||||
|
||||
container = containers[0]
|
||||
|
||||
new_container = None
|
||||
new_name = self._container_registry.uniqueName(container.getName())
|
||||
# Only InstanceContainer has a duplicate method at the moment.
|
||||
# So fall back to serialize/deserialize when no duplicate method exists.
|
||||
|
@ -87,14 +87,14 @@ class ContainerManager(QObject):
|
|||
# \return True if successful, False if not.
|
||||
@pyqtSlot(str, str, str, result = bool)
|
||||
def renameContainer(self, container_id, new_id, new_name):
|
||||
containers = self._container_registry.findContainers(None, id = container_id)
|
||||
containers = self._container_registry.findContainers(id = container_id)
|
||||
if not containers:
|
||||
Logger.log("w", "Could rename container %s because it was not found.", container_id)
|
||||
return False
|
||||
|
||||
container = containers[0]
|
||||
# First, remove the container from the registry. This will clean up any files related to the container.
|
||||
self._container_registry.removeContainer(container)
|
||||
self._container_registry.removeContainer(container_id)
|
||||
|
||||
# Ensure we have a unique name for the container
|
||||
new_name = self._container_registry.uniqueName(new_name)
|
||||
|
@ -115,7 +115,7 @@ class ContainerManager(QObject):
|
|||
# \return True if the container was successfully removed, False if not.
|
||||
@pyqtSlot(str, result = bool)
|
||||
def removeContainer(self, container_id):
|
||||
containers = self._container_registry.findContainers(None, id = container_id)
|
||||
containers = self._container_registry.findContainers(id = container_id)
|
||||
if not containers:
|
||||
Logger.log("w", "Could remove container %s because it was not found.", container_id)
|
||||
return False
|
||||
|
@ -135,14 +135,14 @@ class ContainerManager(QObject):
|
|||
# \return True if successfully merged, False if not.
|
||||
@pyqtSlot(str, result = bool)
|
||||
def mergeContainers(self, merge_into_id, merge_id):
|
||||
containers = self._container_registry.findContainers(None, id = merge_into_id)
|
||||
containers = self._container_registry.findContainers(id = merge_into_id)
|
||||
if not containers:
|
||||
Logger.log("w", "Could merge into container %s because it was not found.", merge_into_id)
|
||||
return False
|
||||
|
||||
merge_into = containers[0]
|
||||
|
||||
containers = self._container_registry.findContainers(None, id = merge_id)
|
||||
containers = self._container_registry.findContainers(id = merge_id)
|
||||
if not containers:
|
||||
Logger.log("w", "Could not merge container %s because it was not found", merge_id)
|
||||
return False
|
||||
|
@ -164,7 +164,7 @@ class ContainerManager(QObject):
|
|||
# \return True if successful, False if not.
|
||||
@pyqtSlot(str, result = bool)
|
||||
def clearContainer(self, container_id):
|
||||
containers = self._container_registry.findContainers(None, id = container_id)
|
||||
containers = self._container_registry.findContainers(id = container_id)
|
||||
if not containers:
|
||||
Logger.log("w", "Could clear container %s because it was not found.", container_id)
|
||||
return False
|
||||
|
@ -179,16 +179,12 @@ class ContainerManager(QObject):
|
|||
|
||||
@pyqtSlot(str, str, result=str)
|
||||
def getContainerMetaDataEntry(self, container_id, entry_name):
|
||||
containers = self._container_registry.findContainers(None, id=container_id)
|
||||
if not containers:
|
||||
metadatas = self._container_registry.findContainersMetadata(id = container_id)
|
||||
if not metadatas:
|
||||
Logger.log("w", "Could not get metadata of container %s because it was not found.", container_id)
|
||||
return ""
|
||||
|
||||
result = containers[0].getMetaDataEntry(entry_name)
|
||||
if result is not None:
|
||||
return str(result)
|
||||
else:
|
||||
return ""
|
||||
return str(metadatas[0].get(entry_name, ""))
|
||||
|
||||
## Set a metadata entry of the specified container.
|
||||
#
|
||||
|
@ -204,7 +200,7 @@ class ContainerManager(QObject):
|
|||
# \return True if successful, False if not.
|
||||
@pyqtSlot(str, str, str, result = bool)
|
||||
def setContainerMetaDataEntry(self, container_id, entry_name, entry_value):
|
||||
containers = self._container_registry.findContainers(None, id = container_id)
|
||||
containers = self._container_registry.findContainers(id = container_id) #We need the complete container, since we need to know whether the container is read-only or not.
|
||||
if not containers:
|
||||
Logger.log("w", "Could not set metadata of container %s because it was not found.", container_id)
|
||||
return False
|
||||
|
@ -254,7 +250,7 @@ class ContainerManager(QObject):
|
|||
# \return True if successful, False if not.
|
||||
@pyqtSlot(str, str, str, str, result = bool)
|
||||
def setContainerProperty(self, container_id, setting_key, property_name, property_value):
|
||||
containers = self._container_registry.findContainers(None, id = container_id)
|
||||
containers = self._container_registry.findContainers(id = container_id)
|
||||
if not containers:
|
||||
Logger.log("w", "Could not set properties of container %s because it was not found.", container_id)
|
||||
return False
|
||||
|
@ -300,7 +296,7 @@ class ContainerManager(QObject):
|
|||
## Set the name of the specified container.
|
||||
@pyqtSlot(str, str, result = bool)
|
||||
def setContainerName(self, container_id, new_name):
|
||||
containers = self._container_registry.findContainers(None, id = container_id)
|
||||
containers = self._container_registry.findContainers(id = container_id) #We need to get the full container, not just metadata, since we need to know whether it's read-only.
|
||||
if not containers:
|
||||
Logger.log("w", "Could not set name of container %s because it was not found.", container_id)
|
||||
return False
|
||||
|
@ -317,18 +313,15 @@ class ContainerManager(QObject):
|
|||
|
||||
## Find instance containers matching certain criteria.
|
||||
#
|
||||
# This effectively forwards to ContainerRegistry::findInstanceContainers.
|
||||
# This effectively forwards to
|
||||
# ContainerRegistry::findInstanceContainersMetadata.
|
||||
#
|
||||
# \param criteria A dict of key - value pairs to search for.
|
||||
#
|
||||
# \return A list of container IDs that match the given criteria.
|
||||
@pyqtSlot("QVariantMap", result = "QVariantList")
|
||||
def findInstanceContainers(self, criteria):
|
||||
result = []
|
||||
for entry in self._container_registry.findInstanceContainers(**criteria):
|
||||
result.append(entry.getId())
|
||||
|
||||
return result
|
||||
return [entry["id"] for entry in self._container_registry.findInstanceContainersMetadata(**criteria)]
|
||||
|
||||
@pyqtSlot(str, result = bool)
|
||||
def isContainerUsed(self, container_id):
|
||||
|
@ -336,15 +329,17 @@ class ContainerManager(QObject):
|
|||
# check if this is a material container. If so, check if any material with the same base is being used by any
|
||||
# stacks.
|
||||
container_ids_to_check = [container_id]
|
||||
container_results = self._container_registry.findInstanceContainers(id = container_id, type = "material")
|
||||
container_results = self._container_registry.findInstanceContainersMetadata(id = container_id, type = "material")
|
||||
if container_results:
|
||||
this_container = container_results[0]
|
||||
material_base_file = this_container.getMetaDataEntry("base_file", this_container.getId())
|
||||
material_base_file = this_container["id"]
|
||||
if "base_file" in this_container:
|
||||
material_base_file = this_container["base_file"]
|
||||
# check all material container IDs with the same base
|
||||
material_containers = self._container_registry.findInstanceContainers(base_file = material_base_file,
|
||||
material_containers = self._container_registry.findInstanceContainersMetadata(base_file = material_base_file,
|
||||
type = "material")
|
||||
if material_containers:
|
||||
container_ids_to_check = [container.getId() for container in material_containers]
|
||||
container_ids_to_check = [container["id"] for container in material_containers]
|
||||
|
||||
all_stacks = self._container_registry.findContainerStacks()
|
||||
for stack in all_stacks:
|
||||
|
@ -412,7 +407,7 @@ class ContainerManager(QObject):
|
|||
else:
|
||||
mime_type = self._container_name_filters[file_type]["mime"]
|
||||
|
||||
containers = self._container_registry.findContainers(None, id = container_id)
|
||||
containers = self._container_registry.findContainers(id = container_id)
|
||||
if not containers:
|
||||
return { "status": "error", "message": "Container not found"}
|
||||
container = containers[0]
|
||||
|
@ -616,9 +611,9 @@ class ContainerManager(QObject):
|
|||
|
||||
elif activate_quality:
|
||||
definition_id = "fdmprinter" if not self._machine_manager.filterQualityByMachine else self._machine_manager.activeDefinitionId
|
||||
containers = self._container_registry.findInstanceContainers(type = "quality", definition = definition_id, quality_type = activate_quality_type)
|
||||
containers = self._container_registry.findInstanceContainersMetadata(type = "quality", definition = definition_id, quality_type = activate_quality_type)
|
||||
if containers:
|
||||
self._machine_manager.setActiveQuality(containers[0].getId())
|
||||
self._machine_manager.setActiveQuality(containers[0]["id"])
|
||||
self._machine_manager.activeQualityChanged.emit()
|
||||
|
||||
return containers_found
|
||||
|
@ -653,11 +648,13 @@ class ContainerManager(QObject):
|
|||
|
||||
container_registry = self._container_registry
|
||||
|
||||
containers_to_rename = self._container_registry.findInstanceContainers(type = "quality_changes", name = quality_name)
|
||||
containers_to_rename = self._container_registry.findInstanceContainersMetadata(type = "quality_changes", name = quality_name)
|
||||
|
||||
for container in containers_to_rename:
|
||||
stack_id = container.getMetaDataEntry("extruder", global_stack.getId())
|
||||
container_registry.renameContainer(container.getId(), new_name, self._createUniqueId(stack_id, new_name))
|
||||
stack_id = global_stack.getId()
|
||||
if "extruder" in container:
|
||||
stack_id = container["extruder"]
|
||||
container_registry.renameContainer(container["id"], new_name, self._createUniqueId(stack_id, new_name))
|
||||
|
||||
if not containers_to_rename:
|
||||
Logger.log("e", "Unable to rename %s, because we could not find the profile", quality_name)
|
||||
|
@ -789,12 +786,12 @@ class ContainerManager(QObject):
|
|||
return ""
|
||||
|
||||
approximate_diameter = str(round(global_stack.getProperty("material_diameter", "value")))
|
||||
containers = self._container_registry.findInstanceContainers(id = "generic_pla*", approximate_diameter = approximate_diameter)
|
||||
containers = self._container_registry.findInstanceContainersMetadata(id = "generic_pla*", approximate_diameter = approximate_diameter)
|
||||
if not containers:
|
||||
Logger.log("d", "Unable to create a new material by cloning Generic PLA, because it cannot be found for the material diameter for this machine.")
|
||||
return ""
|
||||
|
||||
base_file = containers[0].getMetaDataEntry("base_file")
|
||||
base_file = containers[0].get("base_file")
|
||||
containers = self._container_registry.findInstanceContainers(id = base_file)
|
||||
if not containers:
|
||||
Logger.log("d", "Unable to create a new material by cloning Generic PLA, because the base file for Generic PLA for this machine can not be found.")
|
||||
|
@ -835,12 +832,12 @@ class ContainerManager(QObject):
|
|||
has_variants = parseBool(global_stack.getMetaDataEntry("has_variants", default = False))
|
||||
if has_machine_materials or has_variant_materials:
|
||||
if has_variants:
|
||||
materials = self._container_registry.findInstanceContainers(type = "material", base_file = base_file, definition = global_stack.getBottom().getId(), variant = self._machine_manager.activeVariantId)
|
||||
materials = self._container_registry.findInstanceContainersMetadata(type = "material", base_file = base_file, definition = global_stack.getBottom().getId(), variant = self._machine_manager.activeVariantId)
|
||||
else:
|
||||
materials = self._container_registry.findInstanceContainers(type = "material", base_file = base_file, definition = global_stack.getBottom().getId())
|
||||
materials = self._container_registry.findInstanceContainersMetadata(type = "material", base_file = base_file, definition = global_stack.getBottom().getId())
|
||||
|
||||
if materials:
|
||||
return materials[0].getId()
|
||||
return materials[0]["id"]
|
||||
|
||||
Logger.log("w", "Unable to find a suitable container based on %s for the current machine .", base_file)
|
||||
return "" # do not activate a new material if a container can not be found
|
||||
|
@ -853,25 +850,25 @@ class ContainerManager(QObject):
|
|||
# \return \type{list} a list of names of materials with the same GUID
|
||||
@pyqtSlot(str, result = "QStringList")
|
||||
def getLinkedMaterials(self, material_id: str):
|
||||
containers = self._container_registry.findInstanceContainers(id=material_id)
|
||||
containers = self._container_registry.findInstanceContainersMetadata(id = material_id)
|
||||
if not containers:
|
||||
Logger.log("d", "Unable to find materials linked to material with id %s, because it doesn't exist.", material_id)
|
||||
return []
|
||||
|
||||
material_container = containers[0]
|
||||
material_base_file = material_container.getMetaDataEntry("base_file", "")
|
||||
material_guid = material_container.getMetaDataEntry("GUID", "")
|
||||
material_base_file = material_container.get("base_file", "")
|
||||
material_guid = material_container.get("GUID", "")
|
||||
if not material_guid:
|
||||
Logger.log("d", "Unable to find materials linked to material with id %s, because it doesn't have a GUID.", material_id)
|
||||
return []
|
||||
|
||||
containers = self._container_registry.findInstanceContainers(type = "material", GUID = material_guid)
|
||||
containers = self._container_registry.findInstanceContainersMetadata(type = "material", GUID = material_guid)
|
||||
linked_material_names = []
|
||||
for container in containers:
|
||||
if container.getId() in [material_id, material_base_file] or container.getMetaDataEntry("base_file") != container.getId():
|
||||
if container["id"] in [material_id, material_base_file] or container.get("base_file") != container["id"]:
|
||||
continue
|
||||
|
||||
linked_material_names.append(container.getName())
|
||||
linked_material_names.append(container["name"])
|
||||
return linked_material_names
|
||||
|
||||
## Unlink a material from all other materials by creating a new GUID
|
||||
|
@ -1004,7 +1001,7 @@ class ContainerManager(QObject):
|
|||
|
||||
# If the machine specifies qualities should be filtered, ensure we match the current criteria.
|
||||
if not machine_definition.getMetaDataEntry("has_machine_quality"):
|
||||
quality_changes.setDefinition(self._container_registry.findContainers(id = "fdmprinter")[0])
|
||||
quality_changes.setDefinition(self._container_registry.findDefinitionContainers(id = "fdmprinter")[0])
|
||||
else:
|
||||
quality_changes.setDefinition(QualityManager.getInstance().getParentMachineDefinition(machine_definition))
|
||||
|
||||
|
|
|
@ -86,8 +86,8 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
def _containerExists(self, container_type, container_name):
|
||||
container_class = ContainerStack if container_type == "machine" else InstanceContainer
|
||||
|
||||
return self.findContainers(container_class, id = container_name, type = container_type, ignore_case = True) or \
|
||||
self.findContainers(container_class, name = container_name, type = container_type)
|
||||
return self.findContainersMetadata(id = container_name, type = container_type, ignore_case = True) or \
|
||||
self.findContainersMetadata(container_type = container_class, name = container_name, type = container_type)
|
||||
|
||||
## Exports an profile to a file
|
||||
#
|
||||
|
@ -126,9 +126,9 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
# Global stack
|
||||
extruder_positions.append(-1)
|
||||
else:
|
||||
extruder_containers = ContainerRegistry.getInstance().findDefinitionContainers(id=extruder_id)
|
||||
extruder_containers = ContainerRegistry.getInstance().findDefinitionContainersMetadata(id = extruder_id)
|
||||
if extruder_containers:
|
||||
extruder_positions.append(int(extruder_containers[0].getMetaDataEntry("position", 0)))
|
||||
extruder_positions.append(int(extruder_containers[0].get("position", 0)))
|
||||
else:
|
||||
extruder_positions.append(0)
|
||||
# Ensure the profiles are always exported in order (global, extruder 0, extruder 1, ...)
|
||||
|
@ -397,7 +397,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
# set after upgrading, because the proper global stack was not yet loaded. This method
|
||||
# makes sure those extruders also get the right stack set.
|
||||
def _fixupExtruders(self):
|
||||
extruder_stacks = self.findContainers(ExtruderStack.ExtruderStack)
|
||||
extruder_stacks = self.findContainers(container_type = ExtruderStack.ExtruderStack)
|
||||
for extruder_stack in extruder_stacks:
|
||||
if extruder_stack.getNextStack():
|
||||
# Has the right next stack, so ignore it.
|
||||
|
|
|
@ -14,7 +14,7 @@ from UM.Settings.ContainerStack import ContainerStack, InvalidContainerStackErro
|
|||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.Interfaces import ContainerInterface
|
||||
from UM.Settings.Interfaces import ContainerInterface, DefinitionContainerInterface
|
||||
|
||||
from . import Exceptions
|
||||
|
||||
|
@ -235,7 +235,7 @@ class CuraContainerStack(ContainerStack):
|
|||
## Set the definition container.
|
||||
#
|
||||
# \param new_quality_changes The new definition container. It is expected to have a "type" metadata entry with the value "quality_changes".
|
||||
def setDefinition(self, new_definition: DefinitionContainer) -> None:
|
||||
def setDefinition(self, new_definition: DefinitionContainerInterface) -> None:
|
||||
self.replaceContainer(_ContainerIndexes.Definition, new_definition)
|
||||
|
||||
## Set the definition container by an ID.
|
||||
|
@ -544,10 +544,10 @@ class CuraContainerStack(ContainerStack):
|
|||
material_search_criteria["variant"] = self.variant.id
|
||||
else:
|
||||
material_search_criteria["definition"] = "fdmprinter"
|
||||
material_containers = registry.findInstanceContainers(**material_search_criteria)
|
||||
material_containers = registry.findInstanceContainersMetadata(**material_search_criteria)
|
||||
# Try all materials to see if there is a quality profile available.
|
||||
for material_container in material_containers:
|
||||
search_criteria["material"] = material_container.getId()
|
||||
search_criteria["material"] = material_container["id"]
|
||||
|
||||
containers = registry.findInstanceContainers(**search_criteria)
|
||||
if containers:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
from UM.Logger import Logger
|
||||
|
||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||
from UM.Settings.Interfaces import DefinitionContainerInterface
|
||||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
|
||||
|
@ -34,7 +34,7 @@ class CuraStackBuilder:
|
|||
# Make sure the new name does not collide with any definition or (quality) profile
|
||||
# createUniqueName() only looks at other stacks, but not at definitions or quality profiles
|
||||
# Note that we don't go for uniqueName() immediately because that function matches with ignore_case set to true
|
||||
if registry.findContainers(id = generated_name):
|
||||
if registry.findContainersMetadata(id = generated_name):
|
||||
generated_name = registry.uniqueName(generated_name)
|
||||
|
||||
new_global_stack = cls.createGlobalStack(
|
||||
|
@ -74,7 +74,7 @@ class CuraStackBuilder:
|
|||
#
|
||||
# \return A new Global stack instance with the specified parameters.
|
||||
@classmethod
|
||||
def createExtruderStack(cls, new_stack_id: str, definition: DefinitionContainer, machine_definition: DefinitionContainer, **kwargs) -> ExtruderStack:
|
||||
def createExtruderStack(cls, new_stack_id: str, definition: DefinitionContainerInterface, machine_definition: DefinitionContainerInterface, **kwargs) -> ExtruderStack:
|
||||
stack = ExtruderStack(new_stack_id)
|
||||
stack.setName(definition.getName())
|
||||
stack.setDefinition(definition)
|
||||
|
@ -127,7 +127,7 @@ class CuraStackBuilder:
|
|||
#
|
||||
# \return A new Global stack instance with the specified parameters.
|
||||
@classmethod
|
||||
def createGlobalStack(cls, new_stack_id: str, definition: DefinitionContainer, **kwargs) -> GlobalStack:
|
||||
def createGlobalStack(cls, new_stack_id: str, definition: DefinitionContainerInterface, **kwargs) -> GlobalStack:
|
||||
stack = GlobalStack(new_stack_id)
|
||||
stack.setDefinition(definition)
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ class ExtruderManager(QObject):
|
|||
position = extruder_definition.getMetaDataEntry("position", None)
|
||||
if not position:
|
||||
Logger.log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.getId())
|
||||
if not container_registry.findContainerStacks(machine = machine_id, position = position): # Doesn't exist yet.
|
||||
if not container_registry.findContainerStacksMetadata(machine = machine_id, position = position): # Doesn't exist yet.
|
||||
self.createExtruderTrain(extruder_definition, machine_definition, position, machine_id)
|
||||
changed = True
|
||||
|
||||
|
@ -357,13 +357,13 @@ class ExtruderManager(QObject):
|
|||
if preferred_quality:
|
||||
search_criteria["id"] = preferred_quality
|
||||
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||
if not containers and preferred_quality:
|
||||
quality_containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||
if not quality_containers and preferred_quality:
|
||||
Logger.log("w", "The preferred quality \"%s\" of machine %s doesn't exist or is not a quality profile.", preferred_quality, machine_id)
|
||||
search_criteria.pop("id", None)
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||
if containers:
|
||||
quality = containers[0]
|
||||
quality_containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||
if quality_containers:
|
||||
quality = quality_containers[0]
|
||||
|
||||
container_stack.addContainer(quality)
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ class MachineManager(QObject):
|
|||
# There might already be some output devices by the time the signal is connected
|
||||
self._onOutputDevicesChanged()
|
||||
|
||||
if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacks(id = active_machine_id):
|
||||
if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacksMetadata(id = active_machine_id):
|
||||
# An active machine was saved, so restore it.
|
||||
self.setActiveMachine(active_machine_id)
|
||||
if self._global_container_stack and self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
|
||||
|
@ -151,7 +151,7 @@ class MachineManager(QObject):
|
|||
if not self._global_container_stack:
|
||||
return
|
||||
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainers(type="variant", definition=self._global_container_stack.getBottom().getId(), name=hotend_id)
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(type="variant", definition=self._global_container_stack.getBottom().getId(), name=hotend_id)
|
||||
if containers: # New material ID is known
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
machine_id = self.activeMachineId
|
||||
|
@ -163,7 +163,7 @@ class MachineManager(QObject):
|
|||
break
|
||||
if matching_extruder and matching_extruder.variant.getName() != hotend_id:
|
||||
# Save the material that needs to be changed. Multiple changes will be handled by the callback.
|
||||
self._auto_hotends_changed[str(index)] = containers[0].getId()
|
||||
self._auto_hotends_changed[str(index)] = containers[0]["id"]
|
||||
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||
else:
|
||||
Logger.log("w", "No variant found for printer definition %s with id %s" % (self._global_container_stack.getBottom().getId(), hotend_id))
|
||||
|
@ -176,7 +176,7 @@ class MachineManager(QObject):
|
|||
if self._global_container_stack.getMetaDataEntry("has_machine_materials", False):
|
||||
definition_id = self.activeQualityDefinitionId
|
||||
extruder_manager = ExtruderManager.getInstance()
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainers(type = "material", definition = definition_id, GUID = material_id)
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(type = "material", definition = definition_id, GUID = material_id)
|
||||
if containers: # New material ID is known
|
||||
extruders = list(extruder_manager.getMachineExtruders(self.activeMachineId))
|
||||
matching_extruder = None
|
||||
|
@ -190,12 +190,12 @@ class MachineManager(QObject):
|
|||
if self._global_container_stack.getBottom().getMetaDataEntry("has_variants") and matching_extruder.variant:
|
||||
variant_id = self.getQualityVariantId(self._global_container_stack.getBottom(), matching_extruder.variant)
|
||||
for container in containers:
|
||||
if container.getMetaDataEntry("variant") == variant_id:
|
||||
self._auto_materials_changed[str(index)] = container.getId()
|
||||
if container.get("variant") == variant_id:
|
||||
self._auto_materials_changed[str(index)] = container["id"]
|
||||
break
|
||||
else:
|
||||
# Just use the first result we found.
|
||||
self._auto_materials_changed[str(index)] = containers[0].getId()
|
||||
self._auto_materials_changed[str(index)] = containers[0]["id"]
|
||||
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||
else:
|
||||
Logger.log("w", "No material definition found for printer definition %s and GUID %s" % (definition_id, material_id))
|
||||
|
@ -818,7 +818,7 @@ class MachineManager(QObject):
|
|||
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
|
||||
self.blurSettings.emit()
|
||||
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainers(id = quality_id)
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(id = quality_id)
|
||||
if not containers or not self._global_container_stack:
|
||||
return
|
||||
|
||||
|
@ -826,9 +826,9 @@ class MachineManager(QObject):
|
|||
|
||||
# Quality profile come in two flavours: type=quality and type=quality_changes
|
||||
# If we found a quality_changes profile then look up its parent quality profile.
|
||||
container_type = containers[0].getMetaDataEntry("type")
|
||||
quality_name = containers[0].getName()
|
||||
quality_type = containers[0].getMetaDataEntry("quality_type")
|
||||
container_type = containers[0].get("type")
|
||||
quality_name = containers[0]["name"]
|
||||
quality_type = containers[0].get("quality_type")
|
||||
|
||||
# Get quality container and optionally the quality_changes container.
|
||||
if container_type == "quality":
|
||||
|
@ -1091,15 +1091,15 @@ class MachineManager(QObject):
|
|||
|
||||
# activate a new machine before removing a machine because this is safer
|
||||
if activate_new_machine:
|
||||
machine_stacks = ContainerRegistry.getInstance().findContainerStacks(type = "machine")
|
||||
other_machine_stacks = [s for s in machine_stacks if s.getId() != machine_id]
|
||||
machine_stacks = ContainerRegistry.getInstance().findContainerStacksMetadata(type = "machine")
|
||||
other_machine_stacks = [s for s in machine_stacks if s["id"] != machine_id]
|
||||
if other_machine_stacks:
|
||||
self.setActiveMachine(other_machine_stacks[0].getId())
|
||||
self.setActiveMachine(other_machine_stacks[0]["id"])
|
||||
|
||||
ExtruderManager.getInstance().removeMachineExtruders(machine_id)
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainers(type = "user", machine = machine_id)
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(type = "user", machine = machine_id)
|
||||
for container in containers:
|
||||
ContainerRegistry.getInstance().removeContainer(container.getId())
|
||||
ContainerRegistry.getInstance().removeContainer(container["id"])
|
||||
ContainerRegistry.getInstance().removeContainer(machine_id)
|
||||
|
||||
@pyqtProperty(bool, notify = globalContainerChanged)
|
||||
|
|
|
@ -125,8 +125,12 @@ class ProfilesModel(InstanceContainersModel):
|
|||
# active machine and material, and later yield the right ones.
|
||||
tmp_all_quality_items = OrderedDict()
|
||||
for item in super()._recomputeItems():
|
||||
profile = container_registry.findContainers(id=item["id"])
|
||||
quality_type = profile[0].getMetaDataEntry("quality_type") if profile else ""
|
||||
|
||||
profiles = container_registry.findContainersMetadata(id = item["id"])
|
||||
if not profiles or "quality_type" not in profiles[0]:
|
||||
quality_type = ""
|
||||
else:
|
||||
quality_type = profiles[0]["quality_type"]
|
||||
|
||||
if quality_type not in tmp_all_quality_items:
|
||||
tmp_all_quality_items[quality_type] = {"suitable_container": None, "all_containers": []}
|
||||
|
|
|
@ -130,7 +130,6 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
|||
# A few lists of containers in this project files.
|
||||
# When loading the global stack file, it may be associated with those containers, which may or may not be
|
||||
# in Cura already, so we need to provide them as alternative search lists.
|
||||
definition_container_list = []
|
||||
instance_container_list = []
|
||||
material_container_list = []
|
||||
|
||||
|
@ -146,20 +145,20 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
|||
definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
|
||||
for each_definition_container_file in definition_container_files:
|
||||
container_id = self._stripFileToId(each_definition_container_file)
|
||||
definitions = self._container_registry.findDefinitionContainers(id=container_id)
|
||||
definitions = self._container_registry.findDefinitionContainersMetadata(id = container_id)
|
||||
|
||||
if not definitions:
|
||||
definition_container = DefinitionContainer(container_id)
|
||||
definition_container.deserialize(archive.open(each_definition_container_file).read().decode("utf-8"))
|
||||
definition_container = definition_container.getMetaData()
|
||||
|
||||
else:
|
||||
definition_container = definitions[0]
|
||||
definition_container_list.append(definition_container)
|
||||
|
||||
definition_container_type = definition_container.getMetaDataEntry("type")
|
||||
definition_container_type = definition_container.get("type")
|
||||
if definition_container_type == "machine":
|
||||
machine_type = definition_container.getName()
|
||||
variant_type_name = definition_container.getMetaDataEntry("variants_name", variant_type_name)
|
||||
machine_type = definition_container["name"]
|
||||
variant_type_name = definition_container.get("variants_name", variant_type_name)
|
||||
|
||||
machine_definition_container_count += 1
|
||||
elif definition_container_type == "extruder":
|
||||
|
@ -456,7 +455,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
|||
extruder_stack_id_map = {} # new and old ExtruderStack IDs map
|
||||
if self._resolve_strategies["machine"] == "new":
|
||||
# We need a new id if the id already exists
|
||||
if self._container_registry.findContainerStacks(id = global_stack_id_original):
|
||||
if self._container_registry.findContainerStacksMetadata(id = global_stack_id_original):
|
||||
global_stack_id_new = self.getNewId(global_stack_id_original)
|
||||
global_stack_need_rename = True
|
||||
|
||||
|
@ -465,7 +464,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
|||
for each_extruder_stack_file in extruder_stack_files:
|
||||
old_container_id = self._stripFileToId(each_extruder_stack_file)
|
||||
new_container_id = old_container_id
|
||||
if self._container_registry.findContainerStacks(id = old_container_id):
|
||||
if self._container_registry.findContainerStacksMetadata(id = old_container_id):
|
||||
# get a new name for this extruder
|
||||
new_container_id = self.getNewId(old_container_id)
|
||||
|
||||
|
@ -479,7 +478,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
|||
definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
|
||||
for definition_container_file in definition_container_files:
|
||||
container_id = self._stripFileToId(definition_container_file)
|
||||
definitions = self._container_registry.findDefinitionContainers(id = container_id)
|
||||
definitions = self._container_registry.findDefinitionContainersMetadata(id = container_id)
|
||||
if not definitions:
|
||||
definition_container = DefinitionContainer(container_id)
|
||||
definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
|
||||
|
@ -626,7 +625,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
|||
pass
|
||||
quality_and_definition_changes_instance_containers.append(instance_container)
|
||||
else:
|
||||
existing_container = self._container_registry.findInstanceContainers(id = container_id)
|
||||
existing_container = self._container_registry.findInstanceContainersMetadata(id = container_id)
|
||||
if not existing_container:
|
||||
containers_to_add.append(instance_container)
|
||||
if global_stack_need_rename:
|
||||
|
|
|
@ -724,10 +724,10 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
|||
remote_material_guid,
|
||||
material.getMetaDataEntry("GUID"))
|
||||
|
||||
remote_materials = UM.Settings.ContainerRegistry.ContainerRegistry.getInstance().findInstanceContainers(type = "material", GUID = remote_material_guid, read_only = True)
|
||||
remote_materials = UM.Settings.ContainerRegistry.ContainerRegistry.getInstance().findInstanceContainersMetadata(type = "material", GUID = remote_material_guid, read_only = True)
|
||||
remote_material_name = "Unknown"
|
||||
if remote_materials:
|
||||
remote_material_name = remote_materials[0].getName()
|
||||
remote_material_name = remote_materials[0]["name"]
|
||||
warnings.append(i18n_catalog.i18nc("@label", "Different material (Cura: {0}, Printer: {1}) selected for extruder {2}").format(material.getName(), remote_material_name, index + 1))
|
||||
|
||||
try:
|
||||
|
|
|
@ -94,18 +94,6 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
if not base_container.isReadOnly():
|
||||
base_container.setDirty(dirty)
|
||||
|
||||
## Overridden from InstanceContainer
|
||||
# def setProperty(self, key, property_name, property_value, container = None):
|
||||
# if self.isReadOnly():
|
||||
# return
|
||||
#
|
||||
# super().setProperty(key, property_name, property_value)
|
||||
#
|
||||
# basefile = self.getMetaDataEntry("base_file", self._id) #if basefile is self.id, this is a basefile.
|
||||
# for container in UM.Settings.ContainerRegistry.ContainerRegistry.getInstance().findInstanceContainers(base_file = basefile):
|
||||
# if not container.isReadOnly():
|
||||
# container.setDirty(True)
|
||||
|
||||
## Overridden from InstanceContainer
|
||||
# base file: common settings + supported machines
|
||||
# machine / variant combination: only changes for itself.
|
||||
|
@ -222,8 +210,8 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
|
||||
# Map machine human-readable names to IDs
|
||||
product_id_map = {}
|
||||
for container in registry.findDefinitionContainers(type = "machine"):
|
||||
product_id_map[container.getName()] = container.getId()
|
||||
for container in registry.findDefinitionContainersMetadata(type = "machine"):
|
||||
product_id_map[container["name"]] = container["id"]
|
||||
|
||||
for definition_id, container in machine_container_map.items():
|
||||
definition = container.getDefinition()
|
||||
|
@ -249,11 +237,11 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
|
||||
# Find all hotend sub-profiles corresponding to this material and machine and add them to this profile.
|
||||
for hotend_id, hotend in machine_nozzle_map[definition_id].items():
|
||||
variant_containers = registry.findInstanceContainers(id = hotend.getMetaDataEntry("variant"))
|
||||
variant_containers = registry.findInstanceContainersMetadata(id = hotend.getMetaDataEntry("variant"))
|
||||
if not variant_containers:
|
||||
continue
|
||||
|
||||
builder.start("hotend", {"id": variant_containers[0].getName()})
|
||||
builder.start("hotend", {"id": variant_containers[0]["id"]})
|
||||
|
||||
# Compatible is a special case, as it's added as a meta data entry (instead of an instance).
|
||||
compatible = hotend.getMetaDataEntry("compatible")
|
||||
|
@ -519,8 +507,8 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
|
||||
# Map machine human-readable names to IDs
|
||||
product_id_map = {}
|
||||
for container in ContainerRegistry.getInstance().findDefinitionContainers(type = "machine"):
|
||||
product_id_map[container.getName()] = container.getId()
|
||||
for container in ContainerRegistry.getInstance().findDefinitionContainersMetadata(type = "machine"):
|
||||
product_id_map[container["name"]] = container["id"]
|
||||
|
||||
machines = data.iterfind("./um:settings/um:machine", self.__namespaces)
|
||||
for machine in machines:
|
||||
|
@ -592,10 +580,10 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
if hotend_id is None:
|
||||
continue
|
||||
|
||||
variant_containers = ContainerRegistry.getInstance().findInstanceContainers(id = hotend_id)
|
||||
variant_containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(id = hotend_id)
|
||||
if not variant_containers:
|
||||
# It is not really properly defined what "ID" is so also search for variants by name.
|
||||
variant_containers = ContainerRegistry.getInstance().findInstanceContainers(definition = definition.id, name = hotend_id)
|
||||
variant_containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(definition = definition.id, name = hotend_id)
|
||||
|
||||
if not variant_containers:
|
||||
#Logger.log("d", "No variants found with ID or name %s for machine %s", hotend_id, definition.id)
|
||||
|
@ -630,7 +618,7 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
new_hotend_material._name = self.getName()
|
||||
new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
|
||||
new_hotend_material.setDefinition(definition)
|
||||
new_hotend_material.addMetaDataEntry("variant", variant_containers[0].id)
|
||||
new_hotend_material.addMetaDataEntry("variant", variant_containers[0]["id"])
|
||||
# Don't use setMetadata, as that overrides it for all materials with same base file
|
||||
new_hotend_material.getMetaData()["compatible"] = hotend_compatibility
|
||||
new_hotend_material.getMetaData()["machine_manufacturer"] = machine_manufacturer
|
||||
|
|
|
@ -140,8 +140,8 @@ def test_loadTypes(filename, output_class, container_registry):
|
|||
|
||||
#Check whether the resulting type was correct.
|
||||
stack_id = filename.split(".")[0]
|
||||
for container in container_registry._containers: #Stupid ContainerRegistry class doesn't expose any way of getting at this except by prodding the privates.
|
||||
if container.getId() == stack_id: #This is the one we're testing.
|
||||
for container_id, container in container_registry._containers.items(): #Stupid ContainerRegistry class doesn't expose any way of getting at this except by prodding the privates.
|
||||
if container_id == stack_id: #This is the one we're testing.
|
||||
assert type(container) == output_class
|
||||
break
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue