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
|
@ -227,7 +227,7 @@ class PrintInformation(QObject):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
active_material_id = Application.getInstance().getMachineManager().activeMaterialId
|
active_material_id = Application.getInstance().getMachineManager().activeMaterialId
|
||||||
active_material_containers = ContainerRegistry.getInstance().findInstanceContainers(id=active_material_id)
|
active_material_containers = ContainerRegistry.getInstance().findInstanceContainers(id = active_material_id)
|
||||||
|
|
||||||
if active_material_containers:
|
if active_material_containers:
|
||||||
self._active_material_container = active_material_containers[0]
|
self._active_material_container = active_material_containers[0]
|
||||||
|
|
|
@ -463,9 +463,9 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
||||||
result.append(i18n_catalog.i18nc("@item:material", "No material loaded"))
|
result.append(i18n_catalog.i18nc("@item:material", "No material loaded"))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
containers = self._container_registry.findInstanceContainers(type = "material", GUID = material_id)
|
containers = self._container_registry.findInstanceContainersMetadata(type = "material", GUID = material_id)
|
||||||
if containers:
|
if containers:
|
||||||
result.append(containers[0].getName())
|
result.append(containers[0]["name"])
|
||||||
else:
|
else:
|
||||||
result.append(i18n_catalog.i18nc("@item:material", "Unknown material"))
|
result.append(i18n_catalog.i18nc("@item:material", "Unknown material"))
|
||||||
return result
|
return result
|
||||||
|
@ -485,9 +485,9 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
||||||
result.append("#00000000") #No material.
|
result.append("#00000000") #No material.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
containers = self._container_registry.findInstanceContainers(type = "material", GUID = material_id)
|
containers = self._container_registry.findInstanceContainersMetadata(type = "material", GUID = material_id)
|
||||||
if containers:
|
if containers:
|
||||||
result.append(containers[0].getMetaDataEntry("color_code"))
|
result.append(containers[0]["color_code"])
|
||||||
else:
|
else:
|
||||||
result.append("#00000000") #Unknown material.
|
result.append("#00000000") #Unknown material.
|
||||||
return result
|
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.
|
# 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
|
# This collects a lot of quality and quality changes related code which was split between ContainerManager
|
||||||
|
@ -229,7 +229,7 @@ class QualityManager:
|
||||||
machine_definition = Application.getInstance().getGlobalContainerStack().getBottom()
|
machine_definition = Application.getInstance().getGlobalContainerStack().getBottom()
|
||||||
quality_definition_id = machine_definition.getMetaDataEntry("quality_definition")
|
quality_definition_id = machine_definition.getMetaDataEntry("quality_definition")
|
||||||
if quality_definition_id is not None:
|
if quality_definition_id is not None:
|
||||||
machine_definition = ContainerRegistry.getInstance().findDefinitionContainers(id=quality_definition_id)[0]
|
machine_definition = ContainerRegistry.getInstance().findDefinitionContainers(id = quality_definition_id)[0]
|
||||||
|
|
||||||
# for convenience
|
# for convenience
|
||||||
if material_containers is None:
|
if material_containers is None:
|
||||||
|
@ -245,7 +245,7 @@ class QualityManager:
|
||||||
|
|
||||||
machine_definition = self.getParentMachineDefinition(machine_definition)
|
machine_definition = self.getParentMachineDefinition(machine_definition)
|
||||||
criteria["definition"] = machine_definition.getId()
|
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)
|
whole_machine_definition = self.getWholeMachineDefinition(machine_definition)
|
||||||
if whole_machine_definition.getMetaDataEntry("has_machine_quality"):
|
if whole_machine_definition.getMetaDataEntry("has_machine_quality"):
|
||||||
definition_id = machine_definition.getMetaDataEntry("quality_definition", whole_machine_definition.getId())
|
definition_id = machine_definition.getMetaDataEntry("quality_definition", whole_machine_definition.getId())
|
||||||
|
@ -290,13 +290,13 @@ class QualityManager:
|
||||||
# We have a normal (whole) machine defintion
|
# We have a normal (whole) machine defintion
|
||||||
quality_definition = machine_definition.getMetaDataEntry("quality_definition")
|
quality_definition = machine_definition.getMetaDataEntry("quality_definition")
|
||||||
if quality_definition is not None:
|
if quality_definition is not None:
|
||||||
parent_machine_definition = container_registry.findDefinitionContainers(id=quality_definition)[0]
|
parent_machine_definition = container_registry.findDefinitionContainers(id = quality_definition)[0]
|
||||||
return self.getParentMachineDefinition(parent_machine_definition)
|
return self.getParentMachineDefinition(parent_machine_definition)
|
||||||
else:
|
else:
|
||||||
return machine_definition
|
return machine_definition
|
||||||
else:
|
else:
|
||||||
# This looks like an extruder. Find the rest of the machine.
|
# This looks like an extruder. Find the rest of the machine.
|
||||||
whole_machine = container_registry.findDefinitionContainers(id=machine_entry)[0]
|
whole_machine = container_registry.findDefinitionContainers(id = machine_entry)[0]
|
||||||
parent_machine = self.getParentMachineDefinition(whole_machine)
|
parent_machine = self.getParentMachineDefinition(whole_machine)
|
||||||
if whole_machine is parent_machine:
|
if whole_machine is parent_machine:
|
||||||
# This extruder already belongs to a 'parent' machine def.
|
# This extruder already belongs to a 'parent' machine def.
|
||||||
|
@ -305,7 +305,7 @@ class QualityManager:
|
||||||
# Look up the corresponding extruder definition in the parent machine definition.
|
# Look up the corresponding extruder definition in the parent machine definition.
|
||||||
extruder_position = machine_definition.getMetaDataEntry("position")
|
extruder_position = machine_definition.getMetaDataEntry("position")
|
||||||
parent_extruder_id = parent_machine.getMetaDataEntry("machine_extruder_trains")[extruder_position]
|
parent_extruder_id = parent_machine.getMetaDataEntry("machine_extruder_trains")[extruder_position]
|
||||||
return container_registry.findDefinitionContainers(id=parent_extruder_id)[0]
|
return container_registry.findDefinitionContainers(id = parent_extruder_id)[0]
|
||||||
|
|
||||||
## Get the whole/global machine definition from an extruder definition.
|
## Get the whole/global machine definition from an extruder definition.
|
||||||
#
|
#
|
||||||
|
@ -319,5 +319,5 @@ class QualityManager:
|
||||||
return machine_definition
|
return machine_definition
|
||||||
else:
|
else:
|
||||||
container_registry = ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
whole_machine = container_registry.findDefinitionContainers(id=machine_entry)[0]
|
whole_machine = container_registry.findDefinitionContainers(id = machine_entry)[0]
|
||||||
return whole_machine
|
return whole_machine
|
||||||
|
|
|
@ -55,14 +55,14 @@ class ContainerManager(QObject):
|
||||||
# \return The ID of the new container, or an empty string if duplication failed.
|
# \return The ID of the new container, or an empty string if duplication failed.
|
||||||
@pyqtSlot(str, result = str)
|
@pyqtSlot(str, result = str)
|
||||||
def duplicateContainer(self, container_id):
|
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:
|
if not containers:
|
||||||
Logger.log("w", "Could duplicate container %s because it was not found.", container_id)
|
Logger.log("w", "Could duplicate container %s because it was not found.", container_id)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
container = containers[0]
|
container = containers[0]
|
||||||
|
|
||||||
new_container = None
|
|
||||||
new_name = self._container_registry.uniqueName(container.getName())
|
new_name = self._container_registry.uniqueName(container.getName())
|
||||||
# Only InstanceContainer has a duplicate method at the moment.
|
# Only InstanceContainer has a duplicate method at the moment.
|
||||||
# So fall back to serialize/deserialize when no duplicate method exists.
|
# 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.
|
# \return True if successful, False if not.
|
||||||
@pyqtSlot(str, str, str, result = bool)
|
@pyqtSlot(str, str, str, result = bool)
|
||||||
def renameContainer(self, container_id, new_id, new_name):
|
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:
|
if not containers:
|
||||||
Logger.log("w", "Could rename container %s because it was not found.", container_id)
|
Logger.log("w", "Could rename container %s because it was not found.", container_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
container = containers[0]
|
container = containers[0]
|
||||||
# First, remove the container from the registry. This will clean up any files related to the container.
|
# 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
|
# Ensure we have a unique name for the container
|
||||||
new_name = self._container_registry.uniqueName(new_name)
|
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.
|
# \return True if the container was successfully removed, False if not.
|
||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
def removeContainer(self, container_id):
|
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:
|
if not containers:
|
||||||
Logger.log("w", "Could remove container %s because it was not found.", container_id)
|
Logger.log("w", "Could remove container %s because it was not found.", container_id)
|
||||||
return False
|
return False
|
||||||
|
@ -135,14 +135,14 @@ class ContainerManager(QObject):
|
||||||
# \return True if successfully merged, False if not.
|
# \return True if successfully merged, False if not.
|
||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
def mergeContainers(self, merge_into_id, merge_id):
|
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:
|
if not containers:
|
||||||
Logger.log("w", "Could merge into container %s because it was not found.", merge_into_id)
|
Logger.log("w", "Could merge into container %s because it was not found.", merge_into_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
merge_into = containers[0]
|
merge_into = containers[0]
|
||||||
|
|
||||||
containers = self._container_registry.findContainers(None, id = merge_id)
|
containers = self._container_registry.findContainers(id = merge_id)
|
||||||
if not containers:
|
if not containers:
|
||||||
Logger.log("w", "Could not merge container %s because it was not found", merge_id)
|
Logger.log("w", "Could not merge container %s because it was not found", merge_id)
|
||||||
return False
|
return False
|
||||||
|
@ -164,7 +164,7 @@ class ContainerManager(QObject):
|
||||||
# \return True if successful, False if not.
|
# \return True if successful, False if not.
|
||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
def clearContainer(self, container_id):
|
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:
|
if not containers:
|
||||||
Logger.log("w", "Could clear container %s because it was not found.", container_id)
|
Logger.log("w", "Could clear container %s because it was not found.", container_id)
|
||||||
return False
|
return False
|
||||||
|
@ -179,16 +179,12 @@ class ContainerManager(QObject):
|
||||||
|
|
||||||
@pyqtSlot(str, str, result=str)
|
@pyqtSlot(str, str, result=str)
|
||||||
def getContainerMetaDataEntry(self, container_id, entry_name):
|
def getContainerMetaDataEntry(self, container_id, entry_name):
|
||||||
containers = self._container_registry.findContainers(None, id=container_id)
|
metadatas = self._container_registry.findContainersMetadata(id = container_id)
|
||||||
if not containers:
|
if not metadatas:
|
||||||
Logger.log("w", "Could not get metadata of container %s because it was not found.", container_id)
|
Logger.log("w", "Could not get metadata of container %s because it was not found.", container_id)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
result = containers[0].getMetaDataEntry(entry_name)
|
return str(metadatas[0].get(entry_name, ""))
|
||||||
if result is not None:
|
|
||||||
return str(result)
|
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
## Set a metadata entry of the specified container.
|
## Set a metadata entry of the specified container.
|
||||||
#
|
#
|
||||||
|
@ -204,7 +200,7 @@ class ContainerManager(QObject):
|
||||||
# \return True if successful, False if not.
|
# \return True if successful, False if not.
|
||||||
@pyqtSlot(str, str, str, result = bool)
|
@pyqtSlot(str, str, str, result = bool)
|
||||||
def setContainerMetaDataEntry(self, container_id, entry_name, entry_value):
|
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:
|
if not containers:
|
||||||
Logger.log("w", "Could not set metadata of container %s because it was not found.", container_id)
|
Logger.log("w", "Could not set metadata of container %s because it was not found.", container_id)
|
||||||
return False
|
return False
|
||||||
|
@ -254,7 +250,7 @@ class ContainerManager(QObject):
|
||||||
# \return True if successful, False if not.
|
# \return True if successful, False if not.
|
||||||
@pyqtSlot(str, str, str, str, result = bool)
|
@pyqtSlot(str, str, str, str, result = bool)
|
||||||
def setContainerProperty(self, container_id, setting_key, property_name, property_value):
|
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:
|
if not containers:
|
||||||
Logger.log("w", "Could not set properties of container %s because it was not found.", container_id)
|
Logger.log("w", "Could not set properties of container %s because it was not found.", container_id)
|
||||||
return False
|
return False
|
||||||
|
@ -300,7 +296,7 @@ class ContainerManager(QObject):
|
||||||
## Set the name of the specified container.
|
## Set the name of the specified container.
|
||||||
@pyqtSlot(str, str, result = bool)
|
@pyqtSlot(str, str, result = bool)
|
||||||
def setContainerName(self, container_id, new_name):
|
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:
|
if not containers:
|
||||||
Logger.log("w", "Could not set name of container %s because it was not found.", container_id)
|
Logger.log("w", "Could not set name of container %s because it was not found.", container_id)
|
||||||
return False
|
return False
|
||||||
|
@ -317,18 +313,15 @@ class ContainerManager(QObject):
|
||||||
|
|
||||||
## Find instance containers matching certain criteria.
|
## 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.
|
# \param criteria A dict of key - value pairs to search for.
|
||||||
#
|
#
|
||||||
# \return A list of container IDs that match the given criteria.
|
# \return A list of container IDs that match the given criteria.
|
||||||
@pyqtSlot("QVariantMap", result = "QVariantList")
|
@pyqtSlot("QVariantMap", result = "QVariantList")
|
||||||
def findInstanceContainers(self, criteria):
|
def findInstanceContainers(self, criteria):
|
||||||
result = []
|
return [entry["id"] for entry in self._container_registry.findInstanceContainersMetadata(**criteria)]
|
||||||
for entry in self._container_registry.findInstanceContainers(**criteria):
|
|
||||||
result.append(entry.getId())
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
@pyqtSlot(str, result = bool)
|
@pyqtSlot(str, result = bool)
|
||||||
def isContainerUsed(self, container_id):
|
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
|
# check if this is a material container. If so, check if any material with the same base is being used by any
|
||||||
# stacks.
|
# stacks.
|
||||||
container_ids_to_check = [container_id]
|
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:
|
if container_results:
|
||||||
this_container = container_results[0]
|
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
|
# 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")
|
type = "material")
|
||||||
if material_containers:
|
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()
|
all_stacks = self._container_registry.findContainerStacks()
|
||||||
for stack in all_stacks:
|
for stack in all_stacks:
|
||||||
|
@ -412,7 +407,7 @@ class ContainerManager(QObject):
|
||||||
else:
|
else:
|
||||||
mime_type = self._container_name_filters[file_type]["mime"]
|
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:
|
if not containers:
|
||||||
return { "status": "error", "message": "Container not found"}
|
return { "status": "error", "message": "Container not found"}
|
||||||
container = containers[0]
|
container = containers[0]
|
||||||
|
@ -616,9 +611,9 @@ class ContainerManager(QObject):
|
||||||
|
|
||||||
elif activate_quality:
|
elif activate_quality:
|
||||||
definition_id = "fdmprinter" if not self._machine_manager.filterQualityByMachine else self._machine_manager.activeDefinitionId
|
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:
|
if containers:
|
||||||
self._machine_manager.setActiveQuality(containers[0].getId())
|
self._machine_manager.setActiveQuality(containers[0]["id"])
|
||||||
self._machine_manager.activeQualityChanged.emit()
|
self._machine_manager.activeQualityChanged.emit()
|
||||||
|
|
||||||
return containers_found
|
return containers_found
|
||||||
|
@ -653,11 +648,13 @@ class ContainerManager(QObject):
|
||||||
|
|
||||||
container_registry = self._container_registry
|
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:
|
for container in containers_to_rename:
|
||||||
stack_id = container.getMetaDataEntry("extruder", global_stack.getId())
|
stack_id = global_stack.getId()
|
||||||
container_registry.renameContainer(container.getId(), new_name, self._createUniqueId(stack_id, new_name))
|
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:
|
if not containers_to_rename:
|
||||||
Logger.log("e", "Unable to rename %s, because we could not find the profile", quality_name)
|
Logger.log("e", "Unable to rename %s, because we could not find the profile", quality_name)
|
||||||
|
@ -754,7 +751,7 @@ class ContainerManager(QObject):
|
||||||
# \return \type{str} the id of the newly created container.
|
# \return \type{str} the id of the newly created container.
|
||||||
@pyqtSlot(str, result = str)
|
@pyqtSlot(str, result = str)
|
||||||
def duplicateMaterial(self, material_id: str) -> str:
|
def duplicateMaterial(self, material_id: str) -> str:
|
||||||
containers = self._container_registry.findInstanceContainers(id=material_id)
|
containers = self._container_registry.findInstanceContainers(id = material_id)
|
||||||
if not containers:
|
if not containers:
|
||||||
Logger.log("d", "Unable to duplicate the material with id %s, because it doesn't exist.", material_id)
|
Logger.log("d", "Unable to duplicate the material with id %s, because it doesn't exist.", material_id)
|
||||||
return ""
|
return ""
|
||||||
|
@ -789,12 +786,12 @@ class ContainerManager(QObject):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
approximate_diameter = str(round(global_stack.getProperty("material_diameter", "value")))
|
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:
|
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.")
|
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 ""
|
return ""
|
||||||
|
|
||||||
base_file = containers[0].getMetaDataEntry("base_file")
|
base_file = containers[0].get("base_file")
|
||||||
containers = self._container_registry.findInstanceContainers(id = base_file)
|
containers = self._container_registry.findInstanceContainers(id = base_file)
|
||||||
if not containers:
|
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.")
|
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))
|
has_variants = parseBool(global_stack.getMetaDataEntry("has_variants", default = False))
|
||||||
if has_machine_materials or has_variant_materials:
|
if has_machine_materials or has_variant_materials:
|
||||||
if has_variants:
|
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:
|
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:
|
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)
|
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
|
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
|
# \return \type{list} a list of names of materials with the same GUID
|
||||||
@pyqtSlot(str, result = "QStringList")
|
@pyqtSlot(str, result = "QStringList")
|
||||||
def getLinkedMaterials(self, material_id: str):
|
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:
|
if not containers:
|
||||||
Logger.log("d", "Unable to find materials linked to material with id %s, because it doesn't exist.", material_id)
|
Logger.log("d", "Unable to find materials linked to material with id %s, because it doesn't exist.", material_id)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
material_container = containers[0]
|
material_container = containers[0]
|
||||||
material_base_file = material_container.getMetaDataEntry("base_file", "")
|
material_base_file = material_container.get("base_file", "")
|
||||||
material_guid = material_container.getMetaDataEntry("GUID", "")
|
material_guid = material_container.get("GUID", "")
|
||||||
if not material_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)
|
Logger.log("d", "Unable to find materials linked to material with id %s, because it doesn't have a GUID.", material_id)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
containers = self._container_registry.findInstanceContainers(type = "material", GUID = material_guid)
|
containers = self._container_registry.findInstanceContainersMetadata(type = "material", GUID = material_guid)
|
||||||
linked_material_names = []
|
linked_material_names = []
|
||||||
for container in containers:
|
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
|
continue
|
||||||
|
|
||||||
linked_material_names.append(container.getName())
|
linked_material_names.append(container["name"])
|
||||||
return linked_material_names
|
return linked_material_names
|
||||||
|
|
||||||
## Unlink a material from all other materials by creating a new GUID
|
## 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 the machine specifies qualities should be filtered, ensure we match the current criteria.
|
||||||
if not machine_definition.getMetaDataEntry("has_machine_quality"):
|
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:
|
else:
|
||||||
quality_changes.setDefinition(QualityManager.getInstance().getParentMachineDefinition(machine_definition))
|
quality_changes.setDefinition(QualityManager.getInstance().getParentMachineDefinition(machine_definition))
|
||||||
|
|
||||||
|
|
|
@ -86,8 +86,8 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
def _containerExists(self, container_type, container_name):
|
def _containerExists(self, container_type, container_name):
|
||||||
container_class = ContainerStack if container_type == "machine" else InstanceContainer
|
container_class = ContainerStack if container_type == "machine" else InstanceContainer
|
||||||
|
|
||||||
return self.findContainers(container_class, id = container_name, type = container_type, ignore_case = True) or \
|
return self.findContainersMetadata(id = container_name, type = container_type, ignore_case = True) or \
|
||||||
self.findContainers(container_class, name = container_name, type = container_type)
|
self.findContainersMetadata(container_type = container_class, name = container_name, type = container_type)
|
||||||
|
|
||||||
## Exports an profile to a file
|
## Exports an profile to a file
|
||||||
#
|
#
|
||||||
|
@ -116,7 +116,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
found_containers = []
|
found_containers = []
|
||||||
extruder_positions = []
|
extruder_positions = []
|
||||||
for instance_id in instance_ids:
|
for instance_id in instance_ids:
|
||||||
containers = ContainerRegistry.getInstance().findInstanceContainers(id=instance_id)
|
containers = ContainerRegistry.getInstance().findInstanceContainers(id = instance_id)
|
||||||
if containers:
|
if containers:
|
||||||
found_containers.append(containers[0])
|
found_containers.append(containers[0])
|
||||||
|
|
||||||
|
@ -126,9 +126,9 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
# Global stack
|
# Global stack
|
||||||
extruder_positions.append(-1)
|
extruder_positions.append(-1)
|
||||||
else:
|
else:
|
||||||
extruder_containers = ContainerRegistry.getInstance().findDefinitionContainers(id=extruder_id)
|
extruder_containers = ContainerRegistry.getInstance().findDefinitionContainersMetadata(id = extruder_id)
|
||||||
if extruder_containers:
|
if extruder_containers:
|
||||||
extruder_positions.append(int(extruder_containers[0].getMetaDataEntry("position", 0)))
|
extruder_positions.append(int(extruder_containers[0].get("position", 0)))
|
||||||
else:
|
else:
|
||||||
extruder_positions.append(0)
|
extruder_positions.append(0)
|
||||||
# Ensure the profiles are always exported in order (global, extruder 0, extruder 1, ...)
|
# Ensure the profiles are always exported in order (global, extruder 0, extruder 1, ...)
|
||||||
|
@ -294,7 +294,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
quality_type_criteria["definition"] = profile.getDefinition().getId()
|
quality_type_criteria["definition"] = profile.getDefinition().getId()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
profile.setDefinition(ContainerRegistry.getInstance().findDefinitionContainers(id="fdmprinter")[0])
|
profile.setDefinition(ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0])
|
||||||
quality_type_criteria["definition"] = "fdmprinter"
|
quality_type_criteria["definition"] = "fdmprinter"
|
||||||
|
|
||||||
machine_definition = Application.getInstance().getGlobalContainerStack().getBottom()
|
machine_definition = Application.getInstance().getGlobalContainerStack().getBottom()
|
||||||
|
@ -335,7 +335,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if global_container_stack:
|
if global_container_stack:
|
||||||
definition_id = Application.getInstance().getMachineManager().getQualityDefinitionId(global_container_stack.getBottom())
|
definition_id = Application.getInstance().getMachineManager().getQualityDefinitionId(global_container_stack.getBottom())
|
||||||
definition = self.findDefinitionContainers(id=definition_id)[0]
|
definition = self.findDefinitionContainers(id = definition_id)[0]
|
||||||
|
|
||||||
if definition:
|
if definition:
|
||||||
return definition
|
return definition
|
||||||
|
@ -397,13 +397,13 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
# set after upgrading, because the proper global stack was not yet loaded. This method
|
# set after upgrading, because the proper global stack was not yet loaded. This method
|
||||||
# makes sure those extruders also get the right stack set.
|
# makes sure those extruders also get the right stack set.
|
||||||
def _fixupExtruders(self):
|
def _fixupExtruders(self):
|
||||||
extruder_stacks = self.findContainers(ExtruderStack.ExtruderStack)
|
extruder_stacks = self.findContainers(container_type = ExtruderStack.ExtruderStack)
|
||||||
for extruder_stack in extruder_stacks:
|
for extruder_stack in extruder_stacks:
|
||||||
if extruder_stack.getNextStack():
|
if extruder_stack.getNextStack():
|
||||||
# Has the right next stack, so ignore it.
|
# Has the right next stack, so ignore it.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
machines = ContainerRegistry.getInstance().findContainerStacks(id=extruder_stack.getMetaDataEntry("machine", ""))
|
machines = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack.getMetaDataEntry("machine", ""))
|
||||||
if machines:
|
if machines:
|
||||||
extruder_stack.setNextStack(machines[0])
|
extruder_stack.setNextStack(machines[0])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -14,7 +14,7 @@ from UM.Settings.ContainerStack import ContainerStack, InvalidContainerStackErro
|
||||||
from UM.Settings.InstanceContainer import InstanceContainer
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
from UM.Settings.Interfaces import ContainerInterface
|
from UM.Settings.Interfaces import ContainerInterface, DefinitionContainerInterface
|
||||||
|
|
||||||
from . import Exceptions
|
from . import Exceptions
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ class CuraContainerStack(ContainerStack):
|
||||||
## Set the definition container.
|
## 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".
|
# \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)
|
self.replaceContainer(_ContainerIndexes.Definition, new_definition)
|
||||||
|
|
||||||
## Set the definition container by an ID.
|
## Set the definition container by an ID.
|
||||||
|
@ -544,10 +544,10 @@ class CuraContainerStack(ContainerStack):
|
||||||
material_search_criteria["variant"] = self.variant.id
|
material_search_criteria["variant"] = self.variant.id
|
||||||
else:
|
else:
|
||||||
material_search_criteria["definition"] = "fdmprinter"
|
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.
|
# Try all materials to see if there is a quality profile available.
|
||||||
for material_container in material_containers:
|
for material_container in material_containers:
|
||||||
search_criteria["material"] = material_container.getId()
|
search_criteria["material"] = material_container["id"]
|
||||||
|
|
||||||
containers = registry.findInstanceContainers(**search_criteria)
|
containers = registry.findInstanceContainers(**search_criteria)
|
||||||
if containers:
|
if containers:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
from UM.Logger import Logger
|
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.InstanceContainer import InstanceContainer
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
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
|
# 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
|
# 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
|
# 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)
|
generated_name = registry.uniqueName(generated_name)
|
||||||
|
|
||||||
new_global_stack = cls.createGlobalStack(
|
new_global_stack = cls.createGlobalStack(
|
||||||
|
@ -74,7 +74,7 @@ class CuraStackBuilder:
|
||||||
#
|
#
|
||||||
# \return A new Global stack instance with the specified parameters.
|
# \return A new Global stack instance with the specified parameters.
|
||||||
@classmethod
|
@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 = ExtruderStack(new_stack_id)
|
||||||
stack.setName(definition.getName())
|
stack.setName(definition.getName())
|
||||||
stack.setDefinition(definition)
|
stack.setDefinition(definition)
|
||||||
|
@ -127,7 +127,7 @@ class CuraStackBuilder:
|
||||||
#
|
#
|
||||||
# \return A new Global stack instance with the specified parameters.
|
# \return A new Global stack instance with the specified parameters.
|
||||||
@classmethod
|
@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 = GlobalStack(new_stack_id)
|
||||||
stack.setDefinition(definition)
|
stack.setDefinition(definition)
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ class ExtruderManager(QObject):
|
||||||
position = extruder_definition.getMetaDataEntry("position", None)
|
position = extruder_definition.getMetaDataEntry("position", None)
|
||||||
if not position:
|
if not position:
|
||||||
Logger.log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.getId())
|
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)
|
self.createExtruderTrain(extruder_definition, machine_definition, position, machine_id)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
@ -357,13 +357,13 @@ class ExtruderManager(QObject):
|
||||||
if preferred_quality:
|
if preferred_quality:
|
||||||
search_criteria["id"] = preferred_quality
|
search_criteria["id"] = preferred_quality
|
||||||
|
|
||||||
containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
quality_containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||||
if not containers and preferred_quality:
|
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)
|
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)
|
search_criteria.pop("id", None)
|
||||||
containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
quality_containers = ContainerRegistry.getInstance().findInstanceContainers(**search_criteria)
|
||||||
if containers:
|
if quality_containers:
|
||||||
quality = containers[0]
|
quality = quality_containers[0]
|
||||||
|
|
||||||
container_stack.addContainer(quality)
|
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
|
# There might already be some output devices by the time the signal is connected
|
||||||
self._onOutputDevicesChanged()
|
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.
|
# An active machine was saved, so restore it.
|
||||||
self.setActiveMachine(active_machine_id)
|
self.setActiveMachine(active_machine_id)
|
||||||
if self._global_container_stack and self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
|
if self._global_container_stack and self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
|
||||||
|
@ -145,13 +145,13 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
@pyqtProperty(int, constant=True)
|
@pyqtProperty(int, constant=True)
|
||||||
def totalNumberOfSettings(self) -> int:
|
def totalNumberOfSettings(self) -> int:
|
||||||
return len(ContainerRegistry.getInstance().findDefinitionContainers(id="fdmprinter")[0].getAllKeys())
|
return len(ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0].getAllKeys())
|
||||||
|
|
||||||
def _onHotendIdChanged(self, index: Union[str, int], hotend_id: str) -> None:
|
def _onHotendIdChanged(self, index: Union[str, int], hotend_id: str) -> None:
|
||||||
if not self._global_container_stack:
|
if not self._global_container_stack:
|
||||||
return
|
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
|
if containers: # New material ID is known
|
||||||
extruder_manager = ExtruderManager.getInstance()
|
extruder_manager = ExtruderManager.getInstance()
|
||||||
machine_id = self.activeMachineId
|
machine_id = self.activeMachineId
|
||||||
|
@ -163,7 +163,7 @@ class MachineManager(QObject):
|
||||||
break
|
break
|
||||||
if matching_extruder and matching_extruder.variant.getName() != hotend_id:
|
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.
|
# 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)
|
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||||
else:
|
else:
|
||||||
Logger.log("w", "No variant found for printer definition %s with id %s" % (self._global_container_stack.getBottom().getId(), hotend_id))
|
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):
|
if self._global_container_stack.getMetaDataEntry("has_machine_materials", False):
|
||||||
definition_id = self.activeQualityDefinitionId
|
definition_id = self.activeQualityDefinitionId
|
||||||
extruder_manager = ExtruderManager.getInstance()
|
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
|
if containers: # New material ID is known
|
||||||
extruders = list(extruder_manager.getMachineExtruders(self.activeMachineId))
|
extruders = list(extruder_manager.getMachineExtruders(self.activeMachineId))
|
||||||
matching_extruder = None
|
matching_extruder = None
|
||||||
|
@ -190,12 +190,12 @@ class MachineManager(QObject):
|
||||||
if self._global_container_stack.getBottom().getMetaDataEntry("has_variants") and matching_extruder.variant:
|
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)
|
variant_id = self.getQualityVariantId(self._global_container_stack.getBottom(), matching_extruder.variant)
|
||||||
for container in containers:
|
for container in containers:
|
||||||
if container.getMetaDataEntry("variant") == variant_id:
|
if container.get("variant") == variant_id:
|
||||||
self._auto_materials_changed[str(index)] = container.getId()
|
self._auto_materials_changed[str(index)] = container["id"]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# Just use the first result we found.
|
# 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)
|
self._printer_output_devices[0].materialHotendChangedMessage(self._materialHotendChangedCallback)
|
||||||
else:
|
else:
|
||||||
Logger.log("w", "No material definition found for printer definition %s and GUID %s" % (definition_id, material_id))
|
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):
|
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
|
||||||
self.blurSettings.emit()
|
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:
|
if not containers or not self._global_container_stack:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -826,9 +826,9 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
# Quality profile come in two flavours: type=quality and type=quality_changes
|
# 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.
|
# If we found a quality_changes profile then look up its parent quality profile.
|
||||||
container_type = containers[0].getMetaDataEntry("type")
|
container_type = containers[0].get("type")
|
||||||
quality_name = containers[0].getName()
|
quality_name = containers[0]["name"]
|
||||||
quality_type = containers[0].getMetaDataEntry("quality_type")
|
quality_type = containers[0].get("quality_type")
|
||||||
|
|
||||||
# Get quality container and optionally the quality_changes container.
|
# Get quality container and optionally the quality_changes container.
|
||||||
if container_type == "quality":
|
if container_type == "quality":
|
||||||
|
@ -1091,15 +1091,15 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
# activate a new machine before removing a machine because this is safer
|
# activate a new machine before removing a machine because this is safer
|
||||||
if activate_new_machine:
|
if activate_new_machine:
|
||||||
machine_stacks = ContainerRegistry.getInstance().findContainerStacks(type = "machine")
|
machine_stacks = ContainerRegistry.getInstance().findContainerStacksMetadata(type = "machine")
|
||||||
other_machine_stacks = [s for s in machine_stacks if s.getId() != machine_id]
|
other_machine_stacks = [s for s in machine_stacks if s["id"] != machine_id]
|
||||||
if other_machine_stacks:
|
if other_machine_stacks:
|
||||||
self.setActiveMachine(other_machine_stacks[0].getId())
|
self.setActiveMachine(other_machine_stacks[0]["id"])
|
||||||
|
|
||||||
ExtruderManager.getInstance().removeMachineExtruders(machine_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:
|
for container in containers:
|
||||||
ContainerRegistry.getInstance().removeContainer(container.getId())
|
ContainerRegistry.getInstance().removeContainer(container["id"])
|
||||||
ContainerRegistry.getInstance().removeContainer(machine_id)
|
ContainerRegistry.getInstance().removeContainer(machine_id)
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = globalContainerChanged)
|
@pyqtProperty(bool, notify = globalContainerChanged)
|
||||||
|
@ -1138,7 +1138,7 @@ class MachineManager(QObject):
|
||||||
# \returns DefinitionID (string) if found, None otherwise
|
# \returns DefinitionID (string) if found, None otherwise
|
||||||
@pyqtSlot(str, result = str)
|
@pyqtSlot(str, result = str)
|
||||||
def getDefinitionByMachineId(self, machine_id: str) -> str:
|
def getDefinitionByMachineId(self, machine_id: str) -> str:
|
||||||
containers = ContainerRegistry.getInstance().findContainerStacks(id=machine_id)
|
containers = ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
|
||||||
if containers:
|
if containers:
|
||||||
return containers[0].getBottom().getId()
|
return containers[0].getBottom().getId()
|
||||||
|
|
||||||
|
|
|
@ -125,8 +125,12 @@ class ProfilesModel(InstanceContainersModel):
|
||||||
# active machine and material, and later yield the right ones.
|
# active machine and material, and later yield the right ones.
|
||||||
tmp_all_quality_items = OrderedDict()
|
tmp_all_quality_items = OrderedDict()
|
||||||
for item in super()._recomputeItems():
|
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:
|
if quality_type not in tmp_all_quality_items:
|
||||||
tmp_all_quality_items[quality_type] = {"suitable_container": None, "all_containers": []}
|
tmp_all_quality_items[quality_type] = {"suitable_container": None, "all_containers": []}
|
||||||
|
@ -155,7 +159,7 @@ class ProfilesModel(InstanceContainersModel):
|
||||||
|
|
||||||
# Now all the containers are set
|
# Now all the containers are set
|
||||||
for item in containers:
|
for item in containers:
|
||||||
profile = container_registry.findContainers(id=item["id"])
|
profile = container_registry.findContainers(id = item["id"])
|
||||||
if not profile:
|
if not profile:
|
||||||
self._setItemLayerHeight(item, "", unit)
|
self._setItemLayerHeight(item, "", unit)
|
||||||
item["available"] = False
|
item["available"] = False
|
||||||
|
|
|
@ -130,7 +130,6 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
# A few lists of containers in this project files.
|
# 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
|
# 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.
|
# in Cura already, so we need to provide them as alternative search lists.
|
||||||
definition_container_list = []
|
|
||||||
instance_container_list = []
|
instance_container_list = []
|
||||||
material_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)]
|
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:
|
for each_definition_container_file in definition_container_files:
|
||||||
container_id = self._stripFileToId(each_definition_container_file)
|
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:
|
if not definitions:
|
||||||
definition_container = DefinitionContainer(container_id)
|
definition_container = DefinitionContainer(container_id)
|
||||||
definition_container.deserialize(archive.open(each_definition_container_file).read().decode("utf-8"))
|
definition_container.deserialize(archive.open(each_definition_container_file).read().decode("utf-8"))
|
||||||
|
definition_container = definition_container.getMetaData()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
definition_container = definitions[0]
|
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":
|
if definition_container_type == "machine":
|
||||||
machine_type = definition_container.getName()
|
machine_type = definition_container["name"]
|
||||||
variant_type_name = definition_container.getMetaDataEntry("variants_name", variant_type_name)
|
variant_type_name = definition_container.get("variants_name", variant_type_name)
|
||||||
|
|
||||||
machine_definition_container_count += 1
|
machine_definition_container_count += 1
|
||||||
elif definition_container_type == "extruder":
|
elif definition_container_type == "extruder":
|
||||||
|
@ -456,7 +455,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
extruder_stack_id_map = {} # new and old ExtruderStack IDs map
|
extruder_stack_id_map = {} # new and old ExtruderStack IDs map
|
||||||
if self._resolve_strategies["machine"] == "new":
|
if self._resolve_strategies["machine"] == "new":
|
||||||
# We need a new id if the id already exists
|
# 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_id_new = self.getNewId(global_stack_id_original)
|
||||||
global_stack_need_rename = True
|
global_stack_need_rename = True
|
||||||
|
|
||||||
|
@ -465,7 +464,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
for each_extruder_stack_file in extruder_stack_files:
|
for each_extruder_stack_file in extruder_stack_files:
|
||||||
old_container_id = self._stripFileToId(each_extruder_stack_file)
|
old_container_id = self._stripFileToId(each_extruder_stack_file)
|
||||||
new_container_id = old_container_id
|
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
|
# get a new name for this extruder
|
||||||
new_container_id = self.getNewId(old_container_id)
|
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)]
|
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:
|
for definition_container_file in definition_container_files:
|
||||||
container_id = self._stripFileToId(definition_container_file)
|
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:
|
if not definitions:
|
||||||
definition_container = DefinitionContainer(container_id)
|
definition_container = DefinitionContainer(container_id)
|
||||||
definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
|
definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
|
||||||
|
@ -626,7 +625,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
|
||||||
pass
|
pass
|
||||||
quality_and_definition_changes_instance_containers.append(instance_container)
|
quality_and_definition_changes_instance_containers.append(instance_container)
|
||||||
else:
|
else:
|
||||||
existing_container = self._container_registry.findInstanceContainers(id = container_id)
|
existing_container = self._container_registry.findInstanceContainersMetadata(id = container_id)
|
||||||
if not existing_container:
|
if not existing_container:
|
||||||
containers_to_add.append(instance_container)
|
containers_to_add.append(instance_container)
|
||||||
if global_stack_need_rename:
|
if global_stack_need_rename:
|
||||||
|
|
|
@ -724,10 +724,10 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
remote_material_guid,
|
remote_material_guid,
|
||||||
material.getMetaDataEntry("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"
|
remote_material_name = "Unknown"
|
||||||
if remote_materials:
|
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))
|
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:
|
try:
|
||||||
|
|
|
@ -94,18 +94,6 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
if not base_container.isReadOnly():
|
if not base_container.isReadOnly():
|
||||||
base_container.setDirty(dirty)
|
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
|
## Overridden from InstanceContainer
|
||||||
# base file: common settings + supported machines
|
# base file: common settings + supported machines
|
||||||
# machine / variant combination: only changes for itself.
|
# machine / variant combination: only changes for itself.
|
||||||
|
@ -222,8 +210,8 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
|
|
||||||
# Map machine human-readable names to IDs
|
# Map machine human-readable names to IDs
|
||||||
product_id_map = {}
|
product_id_map = {}
|
||||||
for container in registry.findDefinitionContainers(type = "machine"):
|
for container in registry.findDefinitionContainersMetadata(type = "machine"):
|
||||||
product_id_map[container.getName()] = container.getId()
|
product_id_map[container["name"]] = container["id"]
|
||||||
|
|
||||||
for definition_id, container in machine_container_map.items():
|
for definition_id, container in machine_container_map.items():
|
||||||
definition = container.getDefinition()
|
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.
|
# 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():
|
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:
|
if not variant_containers:
|
||||||
continue
|
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 is a special case, as it's added as a meta data entry (instead of an instance).
|
||||||
compatible = hotend.getMetaDataEntry("compatible")
|
compatible = hotend.getMetaDataEntry("compatible")
|
||||||
|
@ -519,8 +507,8 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
|
|
||||||
# Map machine human-readable names to IDs
|
# Map machine human-readable names to IDs
|
||||||
product_id_map = {}
|
product_id_map = {}
|
||||||
for container in ContainerRegistry.getInstance().findDefinitionContainers(type = "machine"):
|
for container in ContainerRegistry.getInstance().findDefinitionContainersMetadata(type = "machine"):
|
||||||
product_id_map[container.getName()] = container.getId()
|
product_id_map[container["name"]] = container["id"]
|
||||||
|
|
||||||
machines = data.iterfind("./um:settings/um:machine", self.__namespaces)
|
machines = data.iterfind("./um:settings/um:machine", self.__namespaces)
|
||||||
for machine in machines:
|
for machine in machines:
|
||||||
|
@ -592,10 +580,10 @@ class XmlMaterialProfile(InstanceContainer):
|
||||||
if hotend_id is None:
|
if hotend_id is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
variant_containers = ContainerRegistry.getInstance().findInstanceContainers(id = hotend_id)
|
variant_containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(id = hotend_id)
|
||||||
if not variant_containers:
|
if not variant_containers:
|
||||||
# It is not really properly defined what "ID" is so also search for variants by name.
|
# 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:
|
if not variant_containers:
|
||||||
#Logger.log("d", "No variants found with ID or name %s for machine %s", hotend_id, definition.id)
|
#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._name = self.getName()
|
||||||
new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
|
new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
|
||||||
new_hotend_material.setDefinition(definition)
|
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
|
# 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()["compatible"] = hotend_compatibility
|
||||||
new_hotend_material.getMetaData()["machine_manufacturer"] = machine_manufacturer
|
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.
|
#Check whether the resulting type was correct.
|
||||||
stack_id = filename.split(".")[0]
|
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.
|
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.getId() == stack_id: #This is the one we're testing.
|
if container_id == stack_id: #This is the one we're testing.
|
||||||
assert type(container) == output_class
|
assert type(container) == output_class
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue