From 3ef01ecbd873dcfa36a0d697fe2fc6d0c5fe21f8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Sat, 6 Mar 2021 14:05:17 +0100 Subject: [PATCH 1/3] Limit minimum path number to path count, not layer count This was probably copy-pasted wrongly years ago. The Cura interface currently doesn't allow changing the minimum path anyway, so this doesn't have any effect on the actual behaviour of Cura. Still, can't hurt to fix this, for posterity. --- plugins/SimulationView/SimulationView.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 9494e42a5e..38e831d1ec 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Ultimaker B.V. +# Copyright (c) 2021 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. import sys @@ -258,7 +258,6 @@ class SimulationView(CuraView): self._minimum_layer_num = self._current_layer_num self._startUpdateTopLayers() - self.currentLayerNumChanged.emit() def setMinimumLayer(self, value: int) -> None: @@ -272,7 +271,6 @@ class SimulationView(CuraView): self._current_layer_num = self._minimum_layer_num self._startUpdateTopLayers() - self.currentLayerNumChanged.emit() def setPath(self, value: int) -> None: @@ -293,13 +291,12 @@ class SimulationView(CuraView): self._minimum_path_num = value if self._minimum_path_num < 0: self._minimum_path_num = 0 - if self._minimum_path_num > self._max_layers: - self._minimum_path_num = self._max_layers + if self._minimum_path_num > self._max_paths: + self._minimum_path_num = self._max_paths if self._minimum_path_num > self._current_path_num: self._current_path_num = self._minimum_path_num self._startUpdateTopLayers() - self.currentPathNumChanged.emit() def setSimulationViewType(self, layer_view_type: int) -> None: From e9d3ba9b7402458852606d9e050ada4268b567f5 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Sat, 6 Mar 2021 14:15:48 +0100 Subject: [PATCH 2/3] Simplify limits on [minimum] layer/path number Just a few calls to min() or max() do the trick, rather than if statements. I consider this more semantic, because we just intend to clamp values here, and min() and max() are commonly used to do that. It should also be slightly faster because it's less Python and more internal in CPython, but considering that this happens at best like 60 times per second the performance impact of this will be practically nil. --- plugins/SimulationView/SimulationView.py | 36 ++++++------------------ 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 38e831d1ec..48269aae8c 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -249,52 +249,32 @@ class SimulationView(CuraView): def setLayer(self, value: int) -> None: if self._current_layer_num != value: - self._current_layer_num = value - if self._current_layer_num < 0: - self._current_layer_num = 0 - if self._current_layer_num > self._max_layers: - self._current_layer_num = self._max_layers - if self._current_layer_num < self._minimum_layer_num: - self._minimum_layer_num = self._current_layer_num + self._current_layer_num = min(max(value, 0), self._max_layers) + self._minimum_layer_num = min(self._current_layer_num, self._minimum_layer_num) self._startUpdateTopLayers() self.currentLayerNumChanged.emit() def setMinimumLayer(self, value: int) -> None: if self._minimum_layer_num != value: - self._minimum_layer_num = value - if self._minimum_layer_num < 0: - self._minimum_layer_num = 0 - if self._minimum_layer_num > self._max_layers: - self._minimum_layer_num = self._max_layers - if self._minimum_layer_num > self._current_layer_num: - self._current_layer_num = self._minimum_layer_num + self._minimum_layer_num = min(max(value, 0), self._max_layers) + self._current_layer_num = max(self._current_layer_num, self._minimum_layer_num) self._startUpdateTopLayers() self.currentLayerNumChanged.emit() def setPath(self, value: int) -> None: if self._current_path_num != value: - self._current_path_num = value - if self._current_path_num < 0: - self._current_path_num = 0 - if self._current_path_num > self._max_paths: - self._current_path_num = self._max_paths - if self._current_path_num < self._minimum_path_num: - self._minimum_path_num = self._current_path_num + self._current_path_num = min(max(value, 0), self._max_paths) + self._minimum_path_num = min(self._minimum_path_num, self._current_path_num) self._startUpdateTopLayers() self.currentPathNumChanged.emit() def setMinimumPath(self, value: int) -> None: if self._minimum_path_num != value: - self._minimum_path_num = value - if self._minimum_path_num < 0: - self._minimum_path_num = 0 - if self._minimum_path_num > self._max_paths: - self._minimum_path_num = self._max_paths - if self._minimum_path_num > self._current_path_num: - self._current_path_num = self._minimum_path_num + self._minimum_path_num = min(max(value, 0), self._max_paths) + self._current_path_num = max(self._current_path_num, self._minimum_path_num) self._startUpdateTopLayers() self.currentPathNumChanged.emit() From 2cdb025adb1f4e90e3727d543499f2641570f483 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Sat, 6 Mar 2021 14:21:38 +0100 Subject: [PATCH 3/3] Document layer view navigation functions --- plugins/SimulationView/SimulationView.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 48269aae8c..e307df3f1e 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -248,6 +248,12 @@ class SimulationView(CuraView): renderer.queueNode(node, transparent = True, shader = self._ghost_shader) def setLayer(self, value: int) -> None: + """ + Set the upper end of the range of visible layers. + + If setting it below the lower end of the range, the lower end is lowered so that 1 layer stays visible. + :param value: The new layer number to show, 0-indexed. + """ if self._current_layer_num != value: self._current_layer_num = min(max(value, 0), self._max_layers) self._minimum_layer_num = min(self._current_layer_num, self._minimum_layer_num) @@ -256,6 +262,12 @@ class SimulationView(CuraView): self.currentLayerNumChanged.emit() def setMinimumLayer(self, value: int) -> None: + """ + Set the lower end of the range of visible layers. + + If setting it above the upper end of the range, the upper end is increased so that 1 layer stays visible. + :param value: The new lower end of the range of visible layers, 0-indexed. + """ if self._minimum_layer_num != value: self._minimum_layer_num = min(max(value, 0), self._max_layers) self._current_layer_num = max(self._current_layer_num, self._minimum_layer_num) @@ -264,6 +276,12 @@ class SimulationView(CuraView): self.currentLayerNumChanged.emit() def setPath(self, value: int) -> None: + """ + Set the upper end of the range of visible paths on the current layer. + + If setting it below the lower end of the range, the lower end is lowered so that 1 path stays visible. + :param value: The new path index to show, 0-indexed. + """ if self._current_path_num != value: self._current_path_num = min(max(value, 0), self._max_paths) self._minimum_path_num = min(self._minimum_path_num, self._current_path_num) @@ -272,6 +290,12 @@ class SimulationView(CuraView): self.currentPathNumChanged.emit() def setMinimumPath(self, value: int) -> None: + """ + Set the lower end of the range of visible paths on the current layer. + + If setting it above the upper end of the range, the upper end is increased so that 1 path stays visible. + :param value: The new lower end of the range of visible paths, 0-indexed. + """ if self._minimum_path_num != value: self._minimum_path_num = min(max(value, 0), self._max_paths) self._current_path_num = max(self._current_path_num, self._minimum_path_num)