mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 05:55:53 +08:00
Move getQualityGroups to MachineNode
It's specific to that machine and the container tree structure, so this is the best place for it we could find. Contributes to issue CURA-6600.
This commit is contained in:
parent
ca163ea5f0
commit
bee5491879
@ -1,13 +1,14 @@
|
|||||||
# Copyright (c) 2019 Ultimaker B.V.
|
# Copyright (c) 2019 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.
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import List, TYPE_CHECKING
|
||||||
|
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Util import parseBool
|
from UM.Util import parseBool
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry # To find all the variants for this machine.
|
from UM.Settings.ContainerRegistry import ContainerRegistry # To find all the variants for this machine.
|
||||||
from UM.Settings.Interfaces import ContainerInterface
|
from UM.Settings.Interfaces import ContainerInterface
|
||||||
from cura.Machines.ContainerNode import ContainerNode
|
from cura.Machines.ContainerNode import ContainerNode
|
||||||
|
from cura.Machines.QualityGroup import QualityGroup # To construct groups of quality profiles that belong together.
|
||||||
from cura.Machines.QualityNode import QualityNode
|
from cura.Machines.QualityNode import QualityNode
|
||||||
from cura.Machines.VariantNode import VariantNode
|
from cura.Machines.VariantNode import VariantNode
|
||||||
|
|
||||||
@ -40,6 +41,53 @@ class MachineNode(ContainerNode):
|
|||||||
container_registry.containerAdded.connect(self._variantAdded)
|
container_registry.containerAdded.connect(self._variantAdded)
|
||||||
self._loadAll()
|
self._loadAll()
|
||||||
|
|
||||||
|
## Get the available quality groups for this machine.
|
||||||
|
#
|
||||||
|
# This returns all quality groups, regardless of whether they are
|
||||||
|
# available to the combination of extruders or not. On the resulting
|
||||||
|
# quality groups, the is_available property is set to indicate whether the
|
||||||
|
# quality group can be selected according to the combination of extruders
|
||||||
|
# in the parameters.
|
||||||
|
# \param variant_names The names of the variants loaded in each extruder.
|
||||||
|
# \param material_bases The base file names of the materials loaded in
|
||||||
|
# each extruder.
|
||||||
|
# \param extruder_enabled Whether or not the extruders are enabled. This
|
||||||
|
# allows the function to set the is_available properly.
|
||||||
|
# \return For each available quality type, a QualityGroup instance.
|
||||||
|
def getQualityGroups(self, variant_names: List[str], material_bases: List[str], extruder_enabled: List[bool]) -> Dict[str, QualityGroup]:
|
||||||
|
if len(variant_names) != len(material_bases) or len(variant_names) != len(extruder_enabled):
|
||||||
|
Logger.log("e", "The number of extruders in the list of variants (" + str(len(variant_names)) + ") is not equal to the number of extruders in the list of materials (" + str(len(material_bases)) + ") or the list of enabled extruders (" + str(len(extruder_enabled)) + ").")
|
||||||
|
return {}
|
||||||
|
# For each extruder, find which quality profiles are available. Later we'll intersect the quality types.
|
||||||
|
qualities_per_type_per_extruder = [] # type: List[Dict[str, QualityNode]]
|
||||||
|
for extruder_nr, variant_name in enumerate(variant_names):
|
||||||
|
if not extruder_enabled[extruder_nr]:
|
||||||
|
continue # No qualities are available in this extruder. It'll get skipped when calculating the available quality types.
|
||||||
|
material_base = material_bases[extruder_nr]
|
||||||
|
if variant_name not in self.variants or material_base not in self.variants[variant_name].materials:
|
||||||
|
# The printer has no variant/material-specific quality profiles. Use the global quality profiles.
|
||||||
|
qualities_per_type_per_extruder[extruder_nr] = self.global_qualities
|
||||||
|
else:
|
||||||
|
# Use the actually specialised quality profiles.
|
||||||
|
qualities_per_type_per_extruder[extruder_nr] = self.variants[variant_name].materials[material_base].qualities
|
||||||
|
|
||||||
|
# Create the quality group for each available type.
|
||||||
|
quality_groups = {}
|
||||||
|
for quality_type, global_quality_node in self.global_qualities.items():
|
||||||
|
quality_groups[quality_type] = QualityGroup(name = global_quality_node.getMetaDataEntry("name", "Unnamed profile"), quality_type = quality_type)
|
||||||
|
quality_groups[quality_type].node_for_global = global_quality_node
|
||||||
|
for extruder, qualities_per_type in qualities_per_type_per_extruder:
|
||||||
|
quality_groups[quality_type].nodes_for_extruders[extruder] = qualities_per_type[quality_type]
|
||||||
|
|
||||||
|
available_quality_types = set(quality_groups.keys())
|
||||||
|
for extruder_nr, qualities_per_type in enumerate(qualities_per_type_per_extruder):
|
||||||
|
if not extruder_enabled[extruder_nr]:
|
||||||
|
continue
|
||||||
|
available_quality_types.intersection_update(qualities_per_type.keys())
|
||||||
|
for quality_type in available_quality_types:
|
||||||
|
quality_groups[quality_type].is_available = True
|
||||||
|
return quality_groups
|
||||||
|
|
||||||
## (Re)loads all variants under this printer.
|
## (Re)loads all variants under this printer.
|
||||||
def _loadAll(self):
|
def _loadAll(self):
|
||||||
# Find all the variants for this definition ID.
|
# Find all the variants for this definition ID.
|
||||||
|
@ -105,39 +105,17 @@ class QualityManager(QObject):
|
|||||||
# \return A dictionary with quality types as keys and the quality groups
|
# \return A dictionary with quality types as keys and the quality groups
|
||||||
# for those types as values.
|
# for those types as values.
|
||||||
def getQualityGroups(self, global_stack: "GlobalStack") -> Dict[str, QualityGroup]:
|
def getQualityGroups(self, global_stack: "GlobalStack") -> Dict[str, QualityGroup]:
|
||||||
|
# Gather up the variant names and material base files for each extruder.
|
||||||
|
variant_names = []
|
||||||
|
material_bases = []
|
||||||
|
extruder_enabled = []
|
||||||
|
for extruder in global_stack.extruders.values():
|
||||||
|
variant_names.append(extruder.variant.getName())
|
||||||
|
material_bases.append(extruder.material.getMetaDataEntry("base_file"))
|
||||||
|
extruder_enabled.append(extruder.isEnabled)
|
||||||
|
|
||||||
definition_id = global_stack.definition.getId()
|
definition_id = global_stack.definition.getId()
|
||||||
machine_node = ContainerTree.getInstance().machines[definition_id]
|
return ContainerTree.getInstance().machines[definition_id].getQualityGroups(variant_names, material_bases, extruder_enabled)
|
||||||
|
|
||||||
# For each extruder, find which quality profiles are available. Later we'll intersect the quality types.
|
|
||||||
qualities_per_type_per_extruder = {} # type: Dict[str, Dict[str, QualityNode]]
|
|
||||||
for extruder_nr, extruder in global_stack.extruders.items():
|
|
||||||
if not extruder.isEnabled:
|
|
||||||
continue # No qualities available in this extruder. It'll get skipped when intersecting the quality types.
|
|
||||||
nozzle_name = extruder.variant.getName()
|
|
||||||
material_base = extruder.material.getMetaDataEntry("base_file")
|
|
||||||
if nozzle_name not in machine_node.variants or material_base not in machine_node.variants[nozzle_name].materials:
|
|
||||||
# The printer has no variant/material-specific quality profiles. Use the global quality profiles.
|
|
||||||
qualities_per_type_per_extruder[extruder_nr] = machine_node.global_qualities
|
|
||||||
else:
|
|
||||||
# Use the actually specialised quality profiles.
|
|
||||||
qualities_per_type_per_extruder[extruder_nr] = machine_node.variants[nozzle_name].materials[material_base].qualities
|
|
||||||
|
|
||||||
# Create the quality group for each available type.
|
|
||||||
quality_groups = {}
|
|
||||||
for quality_type, global_quality_node in machine_node.global_qualities.items():
|
|
||||||
quality_groups[quality_type] = QualityGroup(name = global_quality_node.getMetaDataEntry("name", "Unnamed profile"), quality_type = quality_type)
|
|
||||||
quality_groups[quality_type].node_for_global = global_quality_node
|
|
||||||
for extruder, qualities_per_type in qualities_per_type_per_extruder:
|
|
||||||
quality_groups[quality_type].nodes_for_extruders[extruder] = qualities_per_type[quality_type]
|
|
||||||
|
|
||||||
available_quality_types = set(quality_groups.keys())
|
|
||||||
for extruder_nr, qualities_per_type in qualities_per_type_per_extruder.items():
|
|
||||||
if not global_stack.extruders[extruder_nr].isEnabled:
|
|
||||||
continue
|
|
||||||
available_quality_types.intersection_update(qualities_per_type.keys())
|
|
||||||
for quality_type in available_quality_types:
|
|
||||||
quality_groups[quality_type].is_available = True
|
|
||||||
return quality_groups
|
|
||||||
|
|
||||||
def getQualityGroupsForMachineDefinition(self, machine: "GlobalStack") -> Dict[str, QualityGroup]:
|
def getQualityGroupsForMachineDefinition(self, machine: "GlobalStack") -> Dict[str, QualityGroup]:
|
||||||
machine_definition_id = getMachineDefinitionIDForQualitySearch(machine.definition)
|
machine_definition_id = getMachineDefinitionIDForQualitySearch(machine.definition)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user