From 6db1342255493c264694074fc3dc7f423038e840 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 3 Oct 2018 10:44:20 +0200 Subject: [PATCH] Fix the layer view when there is a print job with only one layer. Contributes to CURA-5789. --- plugins/SimulationView/LayerSlider.qml | 10 ++++++++++ plugins/SimulationView/SimulationView.py | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/SimulationView/LayerSlider.qml b/plugins/SimulationView/LayerSlider.qml index 841472a836..1552506969 100644 --- a/plugins/SimulationView/LayerSlider.qml +++ b/plugins/SimulationView/LayerSlider.qml @@ -234,6 +234,11 @@ Item UM.SimulationView.setCurrentLayer(value) var diff = (value - sliderRoot.maximumValue) / (sliderRoot.minimumValue - sliderRoot.maximumValue) + // In case there is only one layer, the diff value results in a NaN, so this is for catching this specific case + if (isNaN(diff)) + { + diff = 0 + } var newUpperYPosition = Math.round(diff * (sliderRoot.height - (2 * sliderRoot.handleSize + sliderRoot.minimumRangeHandleSize))) y = newUpperYPosition @@ -339,6 +344,11 @@ Item UM.SimulationView.setMinimumLayer(value) var diff = (value - sliderRoot.maximumValue) / (sliderRoot.minimumValue - sliderRoot.maximumValue) + // In case there is only one layer, the diff value results in a NaN, so this is for catching this specific case + if (isNaN(diff)) + { + diff = 0 + } var newLowerYPosition = Math.round((sliderRoot.handleSize + sliderRoot.minimumRangeHandleSize) + diff * (sliderRoot.height - (2 * sliderRoot.handleSize + sliderRoot.minimumRangeHandleSize))) y = newLowerYPosition diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 44643dbf1c..5b369c26d2 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -334,7 +334,7 @@ class SimulationView(View): self._old_max_layers = self._max_layers ## Recalculate num max layers - new_max_layers = 0 + new_max_layers = -1 for node in DepthFirstIterator(scene.getRoot()): layer_data = node.callDecoration("getLayerData") if not layer_data: @@ -369,7 +369,7 @@ class SimulationView(View): if new_max_layers < layer_count: new_max_layers = layer_count - if new_max_layers > 0 and new_max_layers != self._old_max_layers: + if new_max_layers >= 0 and new_max_layers != self._old_max_layers: self._max_layers = new_max_layers # The qt slider has a bit of weird behavior that if the maxvalue needs to be changed first