Fix GUI update upon material data change

CURA-5084
This commit is contained in:
Lipu Fei 2018-03-13 17:37:55 +01:00
parent d2eb01d137
commit b83fd17038

View File

@ -128,6 +128,9 @@ class MachineManager(QObject):
# When the materials lookup table gets updated, it can mean that a material has its name changed, which should
# be reflected on the GUI. This signal emission makes sure that it happens.
self._material_manager.materialsUpdated.connect(self.rootMaterialChanged)
# When the materials get updated, it can be that an activated material's diameter gets changed. In that case,
# a material update should be triggered to make sure that the machine still has compatible materials activated.
self._material_manager.materialsUpdated.connect(self._updateUponMaterialMetadataChange)
self.rootMaterialChanged.connect(self._onRootMaterialChanged)
activeQualityGroupChanged = pyqtSignal()
@ -1033,11 +1036,9 @@ class MachineManager(QObject):
if container_node:
self._global_container_stack.extruders[position].material = container_node.getContainer()
root_material_id = container_node.metadata["base_file"]
root_material_name = container_node.getContainer().getName()
else:
self._global_container_stack.extruders[position].material = self._empty_material_container
root_material_id = None
root_material_name = None
# The _current_root_material_id is used in the MaterialMenu to see which material is selected
if root_material_id != self._current_root_material_id[position]:
self._current_root_material_id[position] = root_material_id
@ -1054,7 +1055,7 @@ class MachineManager(QObject):
return True
## Update current quality type and machine after setting material
def _updateQualityWithMaterial(self):
def _updateQualityWithMaterial(self, *args):
Logger.log("i", "Updating quality/quality_changes due to material change")
current_quality_type = None
if self._current_quality_group:
@ -1099,9 +1100,15 @@ class MachineManager(QObject):
extruder = self._global_container_stack.extruders[position]
current_material_base_name = extruder.material.getMetaDataEntry("base_file")
current_variant_name = None
if extruder.variant.getId() != self._empty_variant_container.getId():
current_variant_name = extruder.variant.getMetaDataEntry("name")
material_diameter = self._global_container_stack.getProperty("material_diameter", "value")
from UM.Settings.Interfaces import PropertyEvaluationContext
from cura.Settings.CuraContainerStack import _ContainerIndexes
context = PropertyEvaluationContext(extruder)
context.context["evaluate_from_container_index"] = _ContainerIndexes.DefinitionChanges
material_diameter = self._global_container_stack.getProperty("material_diameter", "value", context)
candidate_materials = self._material_manager.getAvailableMaterials(
self._global_container_stack.definition.getId(),
current_variant_name,
@ -1116,6 +1123,11 @@ class MachineManager(QObject):
self._setMaterial(position, new_material)
continue
# The current material is not available, find the preferred one
material_node = self._material_manager.getDefaultMaterial(self._global_container_stack, current_variant_name)
if material_node is not None:
self._setMaterial(position, material_node)
## Given a printer definition name, select the right machine instance. In case it doesn't exist, create a new
# instance with the same network key.
@pyqtSlot(str)
@ -1240,3 +1252,8 @@ class MachineManager(QObject):
elif self._current_quality_group:
name = self._current_quality_group.name
return name
def _updateUponMaterialMetadataChange(self):
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
self._updateMaterialWithVariant(None)
self._updateQualityWithMaterial()