Don't use material manager any more to sync with printers

Or to change material from a base file ID.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-09-17 16:35:39 +02:00
parent 5f2e2d5320
commit 37d54071f0
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276

View file

@ -26,7 +26,6 @@ import cura.CuraApplication # Imported like this to prevent circular references
from cura.Machines.ContainerNode import ContainerNode
from cura.Machines.ContainerTree import ContainerTree
from cura.Machines.MaterialManager import MaterialManager
from cura.PrinterOutput.PrinterOutputDevice import PrinterOutputDevice, ConnectionType
from cura.PrinterOutput.Models.PrinterConfigurationModel import PrinterConfigurationModel
@ -1343,6 +1342,7 @@ class MachineManager(QObject):
if self._global_container_stack is None:
return
self.blurSettings.emit()
container_registry = CuraContainerRegistry.getInstance()
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
self.switchPrinterType(configuration.printerType)
@ -1379,20 +1379,18 @@ class MachineManager(QObject):
else:
machine_node = ContainerTree.getInstance().machines.get(self._global_container_stack.definition.getId())
variant_node = machine_node.variants.get(extruder_configuration.hotendID)
if variant_node:
self._setVariantNode(position, variant_node)
else:
self._global_container_stack.extruders[position].variant = empty_variant_container
self._setVariantNode(position, variant_node)
material_container_node = MaterialManager.getInstance().getMaterialNodeByType(self._global_container_stack,
position,
extruder_configuration.hotendID,
configuration.buildplateConfiguration,
extruder_configuration.material.guid)
if material_container_node:
self._setMaterial(position, material_container_node)
else:
self._global_container_stack.extruders[position].material = empty_material_container
# Find the material profile that the printer has stored.
# This might find one of the duplicates if the user duplicated the material to sync with. But that's okay; both have this GUID so both are correct.
approximate_diameter = int(self._global_container_stack.extruderList[int(position)].getApproximateMaterialDiameter())
materials_with_guid = container_registry.findInstanceContainersMetadata(guid = extruder_configuration.material.guid, approximate_diameter = approximate_diameter)
material_container_node = variant_node.preferredMaterial(approximate_diameter)
if materials_with_guid: # We also have the material profile that the printer wants to share.
base_file = materials_with_guid[0]["base_file"]
material_container_node = variant_node.materials.get(base_file, default = material_container_node) # If Cura thinks that the selected material is not available for this printer, revert to the preferred material.
self._setMaterial(position, material_container_node)
self._global_container_stack.extruders[position].setEnabled(True)
self.updateMaterialWithVariant(position)
@ -1440,8 +1438,7 @@ class MachineManager(QObject):
extruder_stack = self._global_container_stack.extruders[position]
nozzle_name = extruder_stack.variant.getName()
material_diameter = extruder_stack.getApproximateMaterialDiameter()
material_node = MaterialManager.getInstance().getMaterialNode(machine_definition_id, nozzle_name, buildplate_name,
material_diameter, root_material_id)
material_node = ContainerTree.getInstance().machines[machine_definition_id].variants[nozzle_name].materials[root_material_id]
self.setMaterial(position, material_node)
## Global_stack: if you want to provide your own global_stack instead of the current active one