mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-30 15:54:32 +08:00
Fix GUI update upon material data change
CURA-5084
This commit is contained in:
parent
d2eb01d137
commit
b83fd17038
@ -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
|
# 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.
|
# be reflected on the GUI. This signal emission makes sure that it happens.
|
||||||
self._material_manager.materialsUpdated.connect(self.rootMaterialChanged)
|
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)
|
self.rootMaterialChanged.connect(self._onRootMaterialChanged)
|
||||||
|
|
||||||
activeQualityGroupChanged = pyqtSignal()
|
activeQualityGroupChanged = pyqtSignal()
|
||||||
@ -1033,11 +1036,9 @@ class MachineManager(QObject):
|
|||||||
if container_node:
|
if container_node:
|
||||||
self._global_container_stack.extruders[position].material = container_node.getContainer()
|
self._global_container_stack.extruders[position].material = container_node.getContainer()
|
||||||
root_material_id = container_node.metadata["base_file"]
|
root_material_id = container_node.metadata["base_file"]
|
||||||
root_material_name = container_node.getContainer().getName()
|
|
||||||
else:
|
else:
|
||||||
self._global_container_stack.extruders[position].material = self._empty_material_container
|
self._global_container_stack.extruders[position].material = self._empty_material_container
|
||||||
root_material_id = None
|
root_material_id = None
|
||||||
root_material_name = None
|
|
||||||
# The _current_root_material_id is used in the MaterialMenu to see which material is selected
|
# 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]:
|
if root_material_id != self._current_root_material_id[position]:
|
||||||
self._current_root_material_id[position] = root_material_id
|
self._current_root_material_id[position] = root_material_id
|
||||||
@ -1054,7 +1055,7 @@ class MachineManager(QObject):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
## Update current quality type and machine after setting material
|
## 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")
|
Logger.log("i", "Updating quality/quality_changes due to material change")
|
||||||
current_quality_type = None
|
current_quality_type = None
|
||||||
if self._current_quality_group:
|
if self._current_quality_group:
|
||||||
@ -1099,9 +1100,15 @@ class MachineManager(QObject):
|
|||||||
extruder = self._global_container_stack.extruders[position]
|
extruder = self._global_container_stack.extruders[position]
|
||||||
|
|
||||||
current_material_base_name = extruder.material.getMetaDataEntry("base_file")
|
current_material_base_name = extruder.material.getMetaDataEntry("base_file")
|
||||||
current_variant_name = extruder.variant.getMetaDataEntry("name")
|
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(
|
candidate_materials = self._material_manager.getAvailableMaterials(
|
||||||
self._global_container_stack.definition.getId(),
|
self._global_container_stack.definition.getId(),
|
||||||
current_variant_name,
|
current_variant_name,
|
||||||
@ -1116,6 +1123,11 @@ class MachineManager(QObject):
|
|||||||
self._setMaterial(position, new_material)
|
self._setMaterial(position, new_material)
|
||||||
continue
|
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
|
## 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.
|
# instance with the same network key.
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
@ -1240,3 +1252,8 @@ class MachineManager(QObject):
|
|||||||
elif self._current_quality_group:
|
elif self._current_quality_group:
|
||||||
name = self._current_quality_group.name
|
name = self._current_quality_group.name
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
def _updateUponMaterialMetadataChange(self):
|
||||||
|
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
|
||||||
|
self._updateMaterialWithVariant(None)
|
||||||
|
self._updateQualityWithMaterial()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user