diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 14e2fdb3fb..d116b10597 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -466,6 +466,14 @@ class SimulationView(CuraView): """ Calculates the limits of the colour schemes, depending on the layer view data that is visible to the user. """ + # Before we start, save the old values so that we can tell if any of the spectrums need to change. + old_min_feedrate = self._min_feedrate + old_max_feedrate = self._max_feedrate + old_min_linewidth = self._min_line_width + old_max_linewidth = self._max_line_width + old_min_thickness = self._min_thickness + old_max_thickness = self._max_thickness + # The colour scheme is only influenced by the visible lines, so filter the lines by if they should be visible. visible_line_types = [] if self.getShowSkin(): # Actually "shell". @@ -509,6 +517,11 @@ class SimulationView(CuraView): # Sometimes, when importing a GCode the line thicknesses are zero and so the minimum (avoiding the zero) can't be calculated. Logger.log("i", "Min thickness can't be calculated because all the values are zero") + if old_min_feedrate != self._min_feedrate or old_max_feedrate != self._max_feedrate \ + or old_min_linewidth != self._min_line_width or old_max_linewidth != self._max_line_width \ + or old_min_thickness != self._min_thickness or old_max_thickness != self._max_thickness: + self.colorSchemeLimitsChanged.emit() + def calculateMaxPathsOnLayer(self, layer_num: int) -> None: # Update the currentPath scene = self.getController().getScene() @@ -536,6 +549,7 @@ class SimulationView(CuraView): busyChanged = Signal() activityChanged = Signal() visibleStructuresChanged = Signal() + colorSchemeLimitsChanged = Signal() def getProxy(self, engine, script_engine): """Hackish way to ensure the proxy is already created diff --git a/plugins/SimulationView/SimulationViewMenuComponent.qml b/plugins/SimulationView/SimulationViewMenuComponent.qml index 708fc932c8..a1ffc22908 100644 --- a/plugins/SimulationView/SimulationViewMenuComponent.qml +++ b/plugins/SimulationView/SimulationViewMenuComponent.qml @@ -389,17 +389,17 @@ Cura.ExpandableComponent // Feedrate selected if (UM.Preferences.getValue("layerview/layer_view_type") == 2) { - return parseFloat(UM.SimulationView.getMinFeedrate()).toFixed(2) + return parseFloat(UM.SimulationView.minFeedrate).toFixed(2) } // Layer thickness selected if (UM.Preferences.getValue("layerview/layer_view_type") == 3) { - return parseFloat(UM.SimulationView.getMinThickness()).toFixed(2) + return parseFloat(UM.SimulationView.minThickness).toFixed(2) } //Line width selected if(UM.Preferences.getValue("layerview/layer_view_type") == 4) { - return parseFloat(UM.SimulationView.getMinLineWidth()).toFixed(2); + return parseFloat(UM.SimulationView.minLineWidth).toFixed(2); } } return catalog.i18nc("@label","min") @@ -448,17 +448,17 @@ Cura.ExpandableComponent // Feedrate selected if (UM.Preferences.getValue("layerview/layer_view_type") == 2) { - return parseFloat(UM.SimulationView.getMaxFeedrate()).toFixed(2) + return parseFloat(UM.SimulationView.maxFeedrate).toFixed(2) } // Layer thickness selected if (UM.Preferences.getValue("layerview/layer_view_type") == 3) { - return parseFloat(UM.SimulationView.getMaxThickness()).toFixed(2) + return parseFloat(UM.SimulationView.maxThickness).toFixed(2) } //Line width selected if(UM.Preferences.getValue("layerview/layer_view_type") == 4) { - return parseFloat(UM.SimulationView.getMaxLineWidth()).toFixed(2); + return parseFloat(UM.SimulationView.maxLineWidth).toFixed(2); } } return catalog.i18nc("@label","max") diff --git a/plugins/SimulationView/SimulationViewProxy.py b/plugins/SimulationView/SimulationViewProxy.py index 12947f6464..bdf787ab3a 100644 --- a/plugins/SimulationView/SimulationViewProxy.py +++ b/plugins/SimulationView/SimulationViewProxy.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Ultimaker B.V. +# Copyright (c) 2021 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. from typing import TYPE_CHECKING @@ -28,6 +28,7 @@ class SimulationViewProxy(QObject): globalStackChanged = pyqtSignal() preferencesChanged = pyqtSignal() busyChanged = pyqtSignal() + colorSchemeLimitsChanged = pyqtSignal() @pyqtProperty(bool, notify=activityChanged) def layerActivity(self): @@ -101,28 +102,28 @@ class SimulationViewProxy(QObject): def getSimulationRunning(self): return self._simulation_view.isSimulationRunning() - @pyqtSlot(result=float) - def getMinFeedrate(self): + @pyqtProperty(float, notify = colorSchemeLimitsChanged) + def minFeedrate(self): return self._simulation_view.getMinFeedrate() - @pyqtSlot(result=float) - def getMaxFeedrate(self): + @pyqtProperty(float, notify = colorSchemeLimitsChanged) + def maxFeedrate(self): return self._simulation_view.getMaxFeedrate() - @pyqtSlot(result=float) - def getMinThickness(self): + @pyqtProperty(float, notify = colorSchemeLimitsChanged) + def minThickness(self): return self._simulation_view.getMinThickness() - @pyqtSlot(result=float) - def getMaxThickness(self): + @pyqtProperty(float, notify = colorSchemeLimitsChanged) + def maxThickness(self): return self._simulation_view.getMaxThickness() - @pyqtSlot(result=float) - def getMaxLineWidth(self): + @pyqtProperty(float, notify = colorSchemeLimitsChanged) + def maxLineWidth(self): return self._simulation_view.getMaxLineWidth() - @pyqtSlot(result=float) - def getMinLineWidth(self): + @pyqtProperty(float, notify = colorSchemeLimitsChanged) + def minLineWidth(self): return self._simulation_view.getMinLineWidth() # Opacity 0..1 @@ -153,6 +154,9 @@ class SimulationViewProxy(QObject): self.currentLayerChanged.emit() self._layerActivityChanged() + def _onColorSchemeLimitsChanged(self): + self.colorSchemeLimitsChanged.emit() + def _onPathChanged(self): self.currentPathChanged.emit() self._layerActivityChanged() @@ -182,6 +186,7 @@ class SimulationViewProxy(QObject): active_view = self._controller.getActiveView() if active_view == self._simulation_view: self._simulation_view.currentLayerNumChanged.connect(self._onLayerChanged) + self._simulation_view.colorSchemeLimitsChanged.connect(self._onColorSchemeLimitsChanged) self._simulation_view.currentPathNumChanged.connect(self._onPathChanged) self._simulation_view.maxLayersChanged.connect(self._onMaxLayersChanged) self._simulation_view.maxPathsChanged.connect(self._onMaxPathsChanged) @@ -194,6 +199,7 @@ class SimulationViewProxy(QObject): # Disconnect all of em again. self.is_simulationView_selected = False self._simulation_view.currentLayerNumChanged.disconnect(self._onLayerChanged) + self._simulation_view.colorSchemeLimitsChanged.connect(self._onColorSchemeLimitsChanged) self._simulation_view.currentPathNumChanged.disconnect(self._onPathChanged) self._simulation_view.maxLayersChanged.disconnect(self._onMaxLayersChanged) self._simulation_view.maxPathsChanged.disconnect(self._onMaxPathsChanged)