mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 15:44:04 -06:00
Always return a MaterialNode from getDefaultMaterial
Its function is, after all, to find the default. It should always have a default. Sometimes that will be the empty material, but so be it. Contributes to issue CURA-6600.
This commit is contained in:
parent
431c8f4900
commit
37bd7c6b0e
1 changed files with 10 additions and 8 deletions
|
@ -226,12 +226,17 @@ class MaterialManager(QObject):
|
||||||
## Get default material for given global stack, extruder position and extruder nozzle name
|
## Get default material for given global stack, extruder position and extruder nozzle name
|
||||||
# you can provide the extruder_definition and then the position is ignored (useful when building up global stack in CuraStackBuilder)
|
# you can provide the extruder_definition and then the position is ignored (useful when building up global stack in CuraStackBuilder)
|
||||||
def getDefaultMaterial(self, global_stack: "GlobalStack", position: str, nozzle_name: Optional[str],
|
def getDefaultMaterial(self, global_stack: "GlobalStack", position: str, nozzle_name: Optional[str],
|
||||||
extruder_definition: Optional["DefinitionContainer"] = None) -> Optional["MaterialNode"]:
|
extruder_definition: Optional["DefinitionContainer"] = None) -> "MaterialNode":
|
||||||
if not parseBool(global_stack.getMetaDataEntry("has_materials", False)):
|
|
||||||
return None
|
|
||||||
|
|
||||||
definition_id = global_stack.definition.getId()
|
definition_id = global_stack.definition.getId()
|
||||||
machine_node = ContainerTree.getInstance().machines[definition_id]
|
machine_node = ContainerTree.getInstance().machines[definition_id]
|
||||||
|
if nozzle_name in machine_node.variants:
|
||||||
|
nozzle_node = machine_node.variants[nozzle_name]
|
||||||
|
else:
|
||||||
|
Logger.log("w", "Could not find variant {nozzle_name} for machine with definition {definition_id} in the container tree".format(nozzle_name = nozzle_name, definition_id = definition_id))
|
||||||
|
nozzle_node = next(iter(machine_node.variants))
|
||||||
|
|
||||||
|
if not parseBool(global_stack.getMetaDataEntry("has_materials", False)):
|
||||||
|
return next(iter(nozzle_node.materials))
|
||||||
|
|
||||||
if extruder_definition is not None:
|
if extruder_definition is not None:
|
||||||
material_diameter = extruder_definition.getProperty("material_diameter", "value")
|
material_diameter = extruder_definition.getProperty("material_diameter", "value")
|
||||||
|
@ -239,10 +244,7 @@ class MaterialManager(QObject):
|
||||||
material_diameter = global_stack.extruders[position].getCompatibleMaterialDiameter()
|
material_diameter = global_stack.extruders[position].getCompatibleMaterialDiameter()
|
||||||
approximate_material_diameter = round(material_diameter)
|
approximate_material_diameter = round(material_diameter)
|
||||||
|
|
||||||
if nozzle_name not in machine_node.variants:
|
return nozzle_node.preferredMaterial(approximate_material_diameter)
|
||||||
Logger.log("w", "Could not find variant {nozzle_name} for machine with definition {definition_id} in the container tree".format(nozzle_name = nozzle_name, definition_id = definition_id))
|
|
||||||
return None
|
|
||||||
return machine_node.variants[nozzle_name].preferredMaterial(approximate_material_diameter)
|
|
||||||
|
|
||||||
def removeMaterialByRootId(self, root_material_id: str):
|
def removeMaterialByRootId(self, root_material_id: str):
|
||||||
container_registry = CuraContainerRegistry.getInstance()
|
container_registry = CuraContainerRegistry.getInstance()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue