Remove _current_quality_changes_group shadow administration

Get the quality changes group back from whichever one is actually active on the stack. This prevents the two from getting out of sync, which makes the code easier to maintain.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-08-27 13:03:03 +02:00
parent 62395d5503
commit 3f5563514c
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
2 changed files with 33 additions and 13 deletions

View file

@ -61,7 +61,6 @@ class MachineManager(QObject):
self._global_container_stack = None # type: Optional[GlobalStack]
self._current_root_material_id = {} # type: Dict[str, str]
self._current_quality_changes_group = None # type: Optional[QualityChangesGroup]
self._default_extruder_position = "0" # to be updated when extruders are switched on and off
@ -1082,7 +1081,6 @@ class MachineManager(QObject):
def _setEmptyQuality(self) -> None:
if self._global_container_stack is None:
return
self._current_quality_changes_group = None
self._global_container_stack.quality = empty_quality_container
self._global_container_stack.qualityChanges = empty_quality_changes_container
for extruder in self._global_container_stack.extruders.values():
@ -1105,9 +1103,6 @@ class MachineManager(QObject):
if node.container is None:
return
if empty_quality_changes:
self._current_quality_changes_group = None
# Set quality and quality_changes for the GlobalStack
self._global_container_stack.quality = quality_group.node_for_global.container
if empty_quality_changes:
@ -1169,7 +1164,6 @@ class MachineManager(QObject):
extruder.quality = quality_container
extruder.qualityChanges = quality_changes_container
self._current_quality_changes_group = quality_changes_group
self.activeQualityGroupChanged.emit()
self.activeQualityChangesGroupChanged.emit()
@ -1214,10 +1208,11 @@ class MachineManager(QObject):
## Update current quality type and machine after setting material
def _updateQualityWithMaterial(self, *args: Any) -> None:
if self._global_container_stack is None:
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
if global_stack is None:
return
Logger.log("d", "Updating quality/quality_changes due to material change")
current_quality_type = self._global_container_stack.quality.getMetaDataEntry("quality_type")
current_quality_type = global_stack.quality.getMetaDataEntry("quality_type")
candidate_quality_groups = ContainerTree.getInstance().getCurrentQualityGroups()
available_quality_types = {qt for qt, g in candidate_quality_groups.items() if g.is_available}
@ -1229,7 +1224,7 @@ class MachineManager(QObject):
return
if not available_quality_types:
if self._current_quality_changes_group is None:
if global_stack.qualityChanges == empty_quality_changes_container:
Logger.log("i", "No available quality types found, setting all qualities to empty (Not Supported).")
self._setEmptyQuality()
return
@ -1510,7 +1505,7 @@ class MachineManager(QObject):
@pyqtProperty(QObject, fset = setQualityGroup, notify = activeQualityGroupChanged)
def activeQualityGroup(self) -> Optional["QualityGroup"]:
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
if global_stack.quality == empty_quality_container:
if not global_stack or global_stack.quality == empty_quality_container:
return None
return ContainerTree.getInstance().getCurrentQualityGroups().get(self.activeQualityType)
@ -1535,11 +1530,19 @@ class MachineManager(QObject):
@pyqtProperty(QObject, fset = setQualityChangesGroup, notify = activeQualityChangesGroupChanged)
def activeQualityChangesGroup(self) -> Optional["QualityChangesGroup"]:
return self._current_quality_changes_group
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
if not global_stack or global_stack.qualityChanges == empty_quality_changes_container:
return None
candidate_groups = ContainerTree.getInstance().getCurrentQualityChangesGroups()
for group in candidate_groups: # Match on the container ID of the global stack to find the quality changes group belonging to the active configuration.
if group.node_for_global and group.node_for_global.container_id == global_stack.qualityChanges.getId():
return group
return None
@pyqtProperty(bool, notify = activeQualityChangesGroupChanged)
def hasCustomQuality(self) -> bool:
return self._current_quality_changes_group is not None
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
return global_stack is None or global_stack.qualityChanges != empty_quality_changes_container
@pyqtProperty(str, notify = activeQualityGroupChanged)
def activeQualityOrQualityChangesName(self) -> str: