Remove double call of _onGlobalContainerChanged and activeExtruderChanged on switching

When switching printers, it would first emit the global container changed signal which connects to _onGlobalContainerChanged, then update stuff in the extruder manager, then manually call _onGlobalContainerChanged again to update some other stuff with the new data from the extruder manager. This was prohibitively expensive, so this prevents that.
Another double or triple emit of the activeExtruderChanged was removed in the extruder manager when creating the extruders for a printer: It would first set the extruder number to 0, possibly emitting the signal, then emit the signal just to be sure since the extruder itself changed (rather than just the number), and then change the extruder number to the preferred extruder, possibly again emitting a signal. Now it just sets the extruder number to the preferred extruder and always emits the signal once (either through setting the extruder number or manually afterwards).

Contributes to issue CURA-6793.
This commit is contained in:
Ghostkeeper 2019-10-08 16:32:20 +02:00
parent dd8ee2e3d8
commit 0238f65e6a
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
2 changed files with 14 additions and 14 deletions

View file

@ -1,4 +1,4 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant # For communicating data and events to Qt. from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant # For communicating data and events to Qt.
@ -320,12 +320,8 @@ class ExtruderManager(QObject):
self.resetSelectedObjectExtruders() self.resetSelectedObjectExtruders()
## Adds the extruders of the currently active machine. ## Adds the extruders to the selected machine.
def _addCurrentMachineExtruders(self) -> None: def addMachineExtruders(self, global_stack: GlobalStack) -> None:
global_stack = self._application.getGlobalContainerStack()
if not global_stack:
return
extruders_changed = False extruders_changed = False
container_registry = ContainerRegistry.getInstance() container_registry = ContainerRegistry.getInstance()
global_stack_id = global_stack.getId() global_stack_id = global_stack.getId()
@ -351,8 +347,6 @@ class ExtruderManager(QObject):
self.fixSingleExtrusionMachineExtruderDefinition(global_stack) self.fixSingleExtrusionMachineExtruderDefinition(global_stack)
if extruders_changed: if extruders_changed:
self.extrudersChanged.emit(global_stack_id) self.extrudersChanged.emit(global_stack_id)
self.setActiveExtruderIndex(0)
self.activeExtruderChanged.emit()
# After 3.4, all single-extrusion machines have their own extruder definition files instead of reusing # After 3.4, all single-extrusion machines have their own extruder definition files instead of reusing
# "fdmextruder". We need to check a machine here so its extruder definition is correct according to this. # "fdmextruder". We need to check a machine here so its extruder definition is correct according to this.

View file

@ -219,7 +219,10 @@ class MachineManager(QObject):
return 0 return 0
return len(general_definition_containers[0].getAllKeys()) return len(general_definition_containers[0].getAllKeys())
## Triggered when the global container stack is changed in CuraApplication.
def _onGlobalContainerChanged(self) -> None: def _onGlobalContainerChanged(self) -> None:
import traceback
traceback.print_stack()
if self._global_container_stack: if self._global_container_stack:
try: try:
self._global_container_stack.containersChanged.disconnect(self._onContainersChanged) self._global_container_stack.containersChanged.disconnect(self._onContainersChanged)
@ -298,7 +301,6 @@ class MachineManager(QObject):
self.blurSettings.emit() # Ensure no-one has focus. self.blurSettings.emit() # Ensure no-one has focus.
container_registry = CuraContainerRegistry.getInstance() container_registry = CuraContainerRegistry.getInstance()
containers = container_registry.findContainerStacks(id = stack_id) containers = container_registry.findContainerStacks(id = stack_id)
if not containers: if not containers:
return return
@ -308,21 +310,25 @@ class MachineManager(QObject):
# Make sure that the default machine actions for this machine have been added # Make sure that the default machine actions for this machine have been added
self._application.getMachineActionManager().addDefaultMachineActions(global_stack) self._application.getMachineActionManager().addDefaultMachineActions(global_stack)
ExtruderManager.getInstance().fixSingleExtrusionMachineExtruderDefinition(global_stack) extruder_manager = ExtruderManager.getInstance()
extruder_manager.fixSingleExtrusionMachineExtruderDefinition(global_stack)
if not global_stack.isValid(): if not global_stack.isValid():
# Mark global stack as invalid # Mark global stack as invalid
ConfigurationErrorMessage.getInstance().addFaultyContainers(global_stack.getId()) ConfigurationErrorMessage.getInstance().addFaultyContainers(global_stack.getId())
return # We're done here return # We're done here
self._global_container_stack = global_stack self._global_container_stack = global_stack
extruder_manager.addMachineExtruders(global_stack)
self._application.setGlobalContainerStack(global_stack) self._application.setGlobalContainerStack(global_stack)
ExtruderManager.getInstance()._globalContainerStackChanged()
self._onGlobalContainerChanged()
# Switch to the first enabled extruder # Switch to the first enabled extruder
self.updateDefaultExtruder() self.updateDefaultExtruder()
default_extruder_position = int(self.defaultExtruderPosition) default_extruder_position = int(self.defaultExtruderPosition)
ExtruderManager.getInstance().setActiveExtruderIndex(default_extruder_position) old_active_extruder_index = extruder_manager.activeExtruderIndex
extruder_manager.setActiveExtruderIndex(default_extruder_position)
if old_active_extruder_index == default_extruder_position:
# This signal might not have been emitted yet (if it didn't change) but we still want the models to update that depend on it because we changed the contents of the containers too.
extruder_manager.activeExtruderChanged.emit()
self.__emitChangedSignals() self.__emitChangedSignals()