mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-17 03:37:48 -06:00
Don't make parent a common property
Instead we use properly-typed and appropriately-named variables in each of the sub classes. Contributes to issue CURA-6600.
This commit is contained in:
parent
d3dc36c187
commit
8ec1c31b58
4 changed files with 27 additions and 27 deletions
|
@ -18,10 +18,8 @@ class ContainerNode:
|
||||||
## Creates a new node for the container tree.
|
## Creates a new node for the container tree.
|
||||||
# \param container_id The ID of the container that this node should
|
# \param container_id The ID of the container that this node should
|
||||||
# represent.
|
# represent.
|
||||||
# \param parent The parent container node, if any.
|
def __init__(self, container_id: str) -> None:
|
||||||
def __init__(self, container_id: str, parent: Optional["ContainerNode"]) -> None:
|
|
||||||
self.container_id = container_id
|
self.container_id = container_id
|
||||||
self.parent = parent
|
|
||||||
self._container = None # type: Optional[InstanceContainer]
|
self._container = None # type: Optional[InstanceContainer]
|
||||||
self.children_map = {} # type: Dict[str, ContainerNode] # Mapping from container ID to container node.
|
self.children_map = {} # type: Dict[str, ContainerNode] # Mapping from container ID to container node.
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ if TYPE_CHECKING:
|
||||||
# The subnodes of these nodes are variants.
|
# The subnodes of these nodes are variants.
|
||||||
class MachineNode(ContainerNode):
|
class MachineNode(ContainerNode):
|
||||||
def __init__(self, container_id: str) -> None:
|
def __init__(self, container_id: str) -> None:
|
||||||
super().__init__(container_id, None)
|
super().__init__(container_id)
|
||||||
self.variants = {} # type: Dict[str, VariantNode] # mapping variant names to their nodes.
|
self.variants = {} # type: Dict[str, VariantNode] # mapping variant names to their nodes.
|
||||||
container_registry = ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
my_metadata = container_registry.findContainersMetadata(id = container_id)[0]
|
my_metadata = container_registry.findContainersMetadata(id = container_id)[0]
|
||||||
|
@ -35,7 +35,7 @@ class MachineNode(ContainerNode):
|
||||||
for variant in variants:
|
for variant in variants:
|
||||||
variant_name = variant["name"]
|
variant_name = variant["name"]
|
||||||
if variant_name not in self.variants:
|
if variant_name not in self.variants:
|
||||||
self.variants[variant_name] = VariantNode(variant["id"], parent = self)
|
self.variants[variant_name] = VariantNode(variant["id"], machine = self)
|
||||||
|
|
||||||
## When a variant gets added to the set of profiles, we need to update our
|
## When a variant gets added to the set of profiles, we need to update our
|
||||||
# tree here.
|
# tree here.
|
||||||
|
@ -50,4 +50,4 @@ class MachineNode(ContainerNode):
|
||||||
if container.getMetaDataEntry("definition") != self.container_id:
|
if container.getMetaDataEntry("definition") != self.container_id:
|
||||||
return # Not a nozzle that fits in my machine.
|
return # Not a nozzle that fits in my machine.
|
||||||
|
|
||||||
self.variants[name] = VariantNode(container.getId(), parent = self)
|
self.variants[name] = VariantNode(container.getId(), machine = self)
|
|
@ -16,8 +16,9 @@ if TYPE_CHECKING:
|
||||||
#
|
#
|
||||||
# Its subcontainers are quality profiles.
|
# Its subcontainers are quality profiles.
|
||||||
class MaterialNode(ContainerNode):
|
class MaterialNode(ContainerNode):
|
||||||
def __init__(self, container_id, parent: VariantNode) -> None:
|
def __init__(self, container_id, variant: VariantNode) -> None:
|
||||||
super().__init__(container_id, parent)
|
super().__init__(container_id)
|
||||||
|
self.variant = variant
|
||||||
self.qualities = {} # type: Dict[str, QualityNode] # Mapping container IDs to quality profiles.
|
self.qualities = {} # type: Dict[str, QualityNode] # Mapping container IDs to quality profiles.
|
||||||
container_registry = ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
my_metadata = container_registry.findContainersMetadata(id = container_id)[0]
|
my_metadata = container_registry.findContainersMetadata(id = container_id)[0]
|
||||||
|
@ -28,25 +29,25 @@ class MaterialNode(ContainerNode):
|
||||||
def _loadAll(self) -> None:
|
def _loadAll(self) -> None:
|
||||||
container_registry = ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
# Find all quality profiles that fit on this material.
|
# Find all quality profiles that fit on this material.
|
||||||
if not self.parent.parent.has_machine_quality: # Need to find the global qualities.
|
if not self.variant.machine.has_machine_quality: # Need to find the global qualities.
|
||||||
qualities = container_registry.findInstanceContainersMetadata(type = "quality", definition = "fdmprinter")
|
qualities = container_registry.findInstanceContainersMetadata(type = "quality", definition = "fdmprinter")
|
||||||
else:
|
else:
|
||||||
qualities = container_registry.findInstanceContainersMetadata(type = "quality", definition = self.parent.parent.quality_definition, variant = self.parent.variant_name, material = self.base_file)
|
qualities = container_registry.findInstanceContainersMetadata(type = "quality", definition = self.variant.machine.quality_definition, variant = self.variant.variant_name, material = self.base_file)
|
||||||
|
|
||||||
for quality in qualities:
|
for quality in qualities:
|
||||||
quality_id = quality["id"]
|
quality_id = quality["id"]
|
||||||
if quality_id not in self.qualities:
|
if quality_id not in self.qualities:
|
||||||
self.qualities[quality_id] = QualityNode(quality_id, parent = self)
|
self.qualities[quality_id] = QualityNode(quality_id, material = self)
|
||||||
|
|
||||||
def _qualityAdded(self, container: ContainerInterface) -> None:
|
def _qualityAdded(self, container: ContainerInterface) -> None:
|
||||||
if container.getMetaDataEntry("type") != "quality":
|
if container.getMetaDataEntry("type") != "quality":
|
||||||
return # Not interested.
|
return # Not interested.
|
||||||
if not self.parent.parent.has_machine_quality:
|
if not self.variant.machine.has_machine_quality:
|
||||||
if container.getMetaDataEntry("definition") != "fdmprinter":
|
if container.getMetaDataEntry("definition") != "fdmprinter":
|
||||||
return # Only want global qualities.
|
return # Only want global qualities.
|
||||||
else:
|
else:
|
||||||
if container.getMetaDataEntry("definition") != self.parent.parent.quality_definition or container.getMetaDataEntry("variant") != self.parent.variant_name or container.getMetaDataEntry("material") != self.base_file:
|
if container.getMetaDataEntry("definition") != self.variant.machine.quality_definition or container.getMetaDataEntry("variant") != self.variant.variant_name or container.getMetaDataEntry("material") != self.base_file:
|
||||||
return # Doesn't match our configuration.
|
return # Doesn't match our configuration.
|
||||||
|
|
||||||
quality_id = container.getId()
|
quality_id = container.getId()
|
||||||
self.qualities[quality_id] = QualityNode(quality_id, parent = self)
|
self.qualities[quality_id] = QualityNode(quality_id, material = self)
|
|
@ -22,8 +22,9 @@ if TYPE_CHECKING:
|
||||||
# material diameter setting, we cannot filter them here. Filtering must be
|
# material diameter setting, we cannot filter them here. Filtering must be
|
||||||
# done in the model.
|
# done in the model.
|
||||||
class VariantNode(ContainerNode):
|
class VariantNode(ContainerNode):
|
||||||
def __init__(self, container_id: str, parent: MachineNode) -> None:
|
def __init__(self, container_id: str, machine: MachineNode) -> None:
|
||||||
super().__init__(container_id, parent)
|
super().__init__(container_id)
|
||||||
|
self.machine = machine
|
||||||
self.materials = {} # type: Dict[str, MaterialNode] # Mapping material base files to their nodes.
|
self.materials = {} # type: Dict[str, MaterialNode] # Mapping material base files to their nodes.
|
||||||
container_registry = ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
self.variant_name = container_registry.findContainersMetadata(id = container_id)[0]["name"] # Store our own name so that we can filter more easily.
|
self.variant_name = container_registry.findContainersMetadata(id = container_id)[0]["name"] # Store our own name so that we can filter more easily.
|
||||||
|
@ -34,24 +35,24 @@ class VariantNode(ContainerNode):
|
||||||
def _loadAll(self):
|
def _loadAll(self):
|
||||||
container_registry = ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
# Find all the materials for this variant's name.
|
# Find all the materials for this variant's name.
|
||||||
if not self.parent.has_machine_materials: # Printer has no specific materials. Look for all fdmprinter materials.
|
if not self.machine.has_machine_materials: # Printer has no specific materials. Look for all fdmprinter materials.
|
||||||
materials = container_registry.findInstanceContainersMetadata(type = "material", definition = "fdmprinter") # These are ONLY the base materials.
|
materials = container_registry.findInstanceContainersMetadata(type = "material", definition = "fdmprinter") # These are ONLY the base materials.
|
||||||
else: # Printer has its own material profiles. Look for material profiles with this printer's definition.
|
else: # Printer has its own material profiles. Look for material profiles with this printer's definition.
|
||||||
all_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = "fdmprinter")
|
all_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = "fdmprinter")
|
||||||
printer_specific_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = self.parent.container_id)
|
printer_specific_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = self.machine.container_id)
|
||||||
variant_specific_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = self.parent.container_id, variant = self.variant_name)
|
variant_specific_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = self.machine.container_id, variant = self.variant_name)
|
||||||
materials_per_base_file = {material["base_file"]: material for material in all_materials}
|
materials_per_base_file = {material["base_file"]: material for material in all_materials}
|
||||||
materials_per_base_file.update({material["base_file"]: material for material in printer_specific_materials}) # Printer-specific profiles override global ones.
|
materials_per_base_file.update({material["base_file"]: material for material in printer_specific_materials}) # Printer-specific profiles override global ones.
|
||||||
materials_per_base_file.update({material["base_file"]: material for material in variant_specific_materials}) # Variant-specific profiles override all of those.
|
materials_per_base_file.update({material["base_file"]: material for material in variant_specific_materials}) # Variant-specific profiles override all of those.
|
||||||
materials = materials_per_base_file.values()
|
materials = materials_per_base_file.values()
|
||||||
|
|
||||||
for excluded_material in self.parent.exclude_materials:
|
for excluded_material in self.machine.exclude_materials:
|
||||||
del materials[excluded_material]
|
del materials[excluded_material]
|
||||||
|
|
||||||
for material in materials:
|
for material in materials:
|
||||||
base_file = material["base_file"]
|
base_file = material["base_file"]
|
||||||
if base_file not in self.materials:
|
if base_file not in self.materials:
|
||||||
self.materials[base_file] = MaterialNode(material["id"], parent = self)
|
self.materials[base_file] = MaterialNode(material["id"], variant = self)
|
||||||
|
|
||||||
## When a material gets added to the set of profiles, we need to update our
|
## When a material gets added to the set of profiles, we need to update our
|
||||||
# tree here.
|
# tree here.
|
||||||
|
@ -59,14 +60,14 @@ class VariantNode(ContainerNode):
|
||||||
if container.getMetaDataEntry("type") != "material":
|
if container.getMetaDataEntry("type") != "material":
|
||||||
return # Not interested.
|
return # Not interested.
|
||||||
material_definition = container.getMetaDataEntry("definition")
|
material_definition = container.getMetaDataEntry("definition")
|
||||||
if not self.parent.has_machine_materials:
|
if not self.machine.has_machine_materials:
|
||||||
if material_definition != "fdmprinter":
|
if material_definition != "fdmprinter":
|
||||||
return
|
return
|
||||||
base_file = container.getMetaDataEntry("base_file")
|
base_file = container.getMetaDataEntry("base_file")
|
||||||
if base_file in self.parent.exclude_materials:
|
if base_file in self.machine.exclude_materials:
|
||||||
return # Material is forbidden for this printer.
|
return # Material is forbidden for this printer.
|
||||||
if base_file not in self.materials: # Completely new base file. Always better than not having a file as long as it matches our set-up.
|
if base_file not in self.materials: # Completely new base file. Always better than not having a file as long as it matches our set-up.
|
||||||
if material_definition != "fdmprinter" and material_definition != self.parent.container_id:
|
if material_definition != "fdmprinter" and material_definition != self.machine.container_id:
|
||||||
return
|
return
|
||||||
material_variant = container.getMetaDataEntry("variant", "empty")
|
material_variant = container.getMetaDataEntry("variant", "empty")
|
||||||
if material_variant != "empty" and material_variant != self.variant_name:
|
if material_variant != "empty" and material_variant != self.variant_name:
|
||||||
|
@ -75,11 +76,11 @@ class VariantNode(ContainerNode):
|
||||||
new_definition = container.getMetaDataEntry("definition")
|
new_definition = container.getMetaDataEntry("definition")
|
||||||
if new_definition == "fdmprinter":
|
if new_definition == "fdmprinter":
|
||||||
return # Just as unspecific or worse.
|
return # Just as unspecific or worse.
|
||||||
if new_definition != self.parent.container_id:
|
if new_definition != self.machine.container_id:
|
||||||
return # Doesn't match this set-up.
|
return # Doesn't match this set-up.
|
||||||
original_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = self.materials[base_file].container_id)[0]
|
original_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = self.materials[base_file].container_id)[0]
|
||||||
original_variant = original_metadata.get("variant", "empty")
|
original_variant = original_metadata.get("variant", "empty")
|
||||||
if original_variant != "empty" or container.getMetaDataEntry("variant", "empty") == "empty":
|
if original_variant != "empty" or container.getMetaDataEntry("variant", "empty") == "empty":
|
||||||
return # Original was already specific or just as unspecific as the new one.
|
return # Original was already specific or just as unspecific as the new one.
|
||||||
|
|
||||||
self.materials[base_file] = MaterialNode(container.getId(), parent = self)
|
self.materials[base_file] = MaterialNode(container.getId(), variant = self)
|
Loading…
Add table
Add a link
Reference in a new issue