mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07:28 -06:00
Don't get whole container to just get metadata
A performance improvement, especially in the material models. Contributes to issue CURA-6793.
This commit is contained in:
parent
9f84304829
commit
7348c70af6
7 changed files with 14 additions and 15 deletions
|
@ -132,7 +132,7 @@ class MaterialManager(QObject):
|
|||
# Fetch the available materials (ContainerNode) for the current active machine and extruder setup.
|
||||
materials = self.getAvailableMaterials(machine.definition.getId(), nozzle_name)
|
||||
compatible_material_diameter = extruder_stack.getApproximateMaterialDiameter()
|
||||
result = {key: material for key, material in materials.items() if material.container and float(material.container.getMetaDataEntry("approximate_diameter")) == compatible_material_diameter}
|
||||
result = {key: material for key, material in materials.items() if material.container and float(material.getMetaDataEntry("approximate_diameter")) == compatible_material_diameter}
|
||||
return result
|
||||
|
||||
#
|
||||
|
|
|
@ -126,8 +126,8 @@ class BaseMaterialsModel(ListModel):
|
|||
if material_base_file in self._available_materials:
|
||||
self._update()
|
||||
|
||||
## This is an abstract method that needs to be implemented by the specific
|
||||
# models themselves.
|
||||
## This is an abstract method that needs to be implemented by the specific
|
||||
# models themselves.
|
||||
def _update(self):
|
||||
self._favorite_ids = set(cura.CuraApplication.CuraApplication.getInstance().getPreferences().getValue("cura/favorite_materials").split(";"))
|
||||
|
||||
|
@ -141,7 +141,7 @@ class BaseMaterialsModel(ListModel):
|
|||
nozzle_name = extruder_stack.variant.getName()
|
||||
materials = ContainerTree.getInstance().machines[global_stack.definition.getId()].variants[nozzle_name].materials
|
||||
approximate_material_diameter = extruder_stack.getApproximateMaterialDiameter()
|
||||
self._available_materials = {key: material for key, material in materials.items() if float(material.container.getMetaDataEntry("approximate_diameter", -1)) == approximate_material_diameter}
|
||||
self._available_materials = {key: material for key, material in materials.items() if float(material.getMetaDataEntry("approximate_diameter", -1)) == approximate_material_diameter}
|
||||
|
||||
## This method is used by all material models in the beginning of the
|
||||
# _update() method in order to prevent errors. It's the same in all models
|
||||
|
|
|
@ -27,7 +27,7 @@ class FavoriteMaterialsModel(BaseMaterialsModel):
|
|||
|
||||
for root_material_id, container_node in self._available_materials.items():
|
||||
# Do not include the materials from a to-be-removed package
|
||||
if bool(container_node.container.getMetaDataEntry("removed", False)):
|
||||
if bool(container_node.getMetaDataEntry("removed", False)):
|
||||
continue
|
||||
|
||||
# Only add results for favorite materials
|
||||
|
|
|
@ -18,11 +18,11 @@ class GenericMaterialsModel(BaseMaterialsModel):
|
|||
|
||||
for root_material_id, container_node in self._available_materials.items():
|
||||
# Do not include the materials from a to-be-removed package
|
||||
if bool(container_node.container.getMetaDataEntry("removed", False)):
|
||||
if bool(container_node.getMetaDataEntry("removed", False)):
|
||||
continue
|
||||
|
||||
# Only add results for generic materials
|
||||
if container_node.container.getMetaDataEntry("brand", "unknown").lower() != "generic":
|
||||
if container_node.getMetaDataEntry("brand", "unknown").lower() != "generic":
|
||||
continue
|
||||
|
||||
item = self._createMaterialItem(root_material_id, container_node)
|
||||
|
|
|
@ -37,18 +37,18 @@ class MaterialBrandsModel(BaseMaterialsModel):
|
|||
# Part 1: Generate the entire tree of brands -> material types -> spcific materials
|
||||
for root_material_id, container_node in self._available_materials.items():
|
||||
# Do not include the materials from a to-be-removed package
|
||||
if bool(container_node.container.getMetaDataEntry("removed", False)):
|
||||
if bool(container_node.getMetaDataEntry("removed", False)):
|
||||
continue
|
||||
|
||||
# Add brands we haven't seen yet to the dict, skipping generics
|
||||
brand = container_node.container.getMetaDataEntry("brand", "")
|
||||
brand = container_node.getMetaDataEntry("brand", "")
|
||||
if brand.lower() == "generic":
|
||||
continue
|
||||
if brand not in brand_group_dict:
|
||||
brand_group_dict[brand] = {}
|
||||
|
||||
# Add material types we haven't seen yet to the dict
|
||||
material_type = container_node.container.getMetaDataEntry("material", "")
|
||||
material_type = container_node.getMetaDataEntry("material", "")
|
||||
if material_type not in brand_group_dict[brand]:
|
||||
brand_group_dict[brand][material_type] = []
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ class QualityGroup:
|
|||
if not node.container:
|
||||
Logger.log("w", "Node {0} doesn't have a container.".format(node.container_id))
|
||||
return
|
||||
is_experimental = parseBool(node.container.getMetaDataEntry("is_experimental", False))
|
||||
is_experimental = parseBool(node.getMetaDataEntry("is_experimental", False))
|
||||
self.is_experimental |= is_experimental
|
||||
|
||||
def setExtruderNode(self, position: int, node: "ContainerNode") -> None:
|
||||
|
@ -78,5 +78,5 @@ class QualityGroup:
|
|||
if not node.container:
|
||||
Logger.log("w", "Node {0} doesn't have a container.".format(node.container_id))
|
||||
return
|
||||
is_experimental = parseBool(node.container.getMetaDataEntry("is_experimental", False))
|
||||
is_experimental = parseBool(node.getMetaDataEntry("is_experimental", False))
|
||||
self.is_experimental |= is_experimental
|
||||
|
|
|
@ -85,7 +85,7 @@ class ContainerManager(QObject):
|
|||
if container_node.container is None:
|
||||
Logger.log("w", "Container node {0} doesn't have a container.".format(container_node.container_id))
|
||||
return False
|
||||
root_material_id = container_node.container.getMetaDataEntry("base_file", "")
|
||||
root_material_id = container_node.getMetaDataEntry("base_file", "")
|
||||
container_registry = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry()
|
||||
if container_registry.isReadOnly(root_material_id):
|
||||
Logger.log("w", "Cannot set metadata of read-only container %s.", root_material_id)
|
||||
|
@ -350,8 +350,7 @@ class ContainerManager(QObject):
|
|||
@pyqtSlot("QVariant")
|
||||
def unlinkMaterial(self, material_node: "MaterialNode") -> None:
|
||||
# Get the material group
|
||||
if material_node.container is None:
|
||||
Logger.log("w", "Material node {0} doesn't have a container.".format(material_node.container_id))
|
||||
if material_node.container is None: # Failed to lazy-load this container.
|
||||
return
|
||||
root_material_query = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry().findInstanceContainers(id = material_node.getMetaDataEntry("base_file", ""))
|
||||
if not root_material_query:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue