From 0991c3c01d2f685dd69eb0fadf51e42a2ffe0b12 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Mon, 11 Nov 2024 16:13:10 +0100 Subject: [PATCH] Loop back to the beginning when ending simulation playback CURA-12192 --- plugins/SimulationView/SimulationView.py | 13 +++++-------- .../SimulationView/SimulationViewMainComponent.qml | 4 +--- plugins/SimulationView/SimulationViewProxy.py | 6 +++--- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index b4333219145..10861acfd02 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -222,12 +222,11 @@ def setTime(self, time: float) -> None: self.setPath(i + fractional_value) - def advanceTime(self, time_increase: float) -> bool: + def advanceTime(self, time_increase: float) -> None: """ Advance the time by the given amount. :param time_increase: The amount of time to advance (in seconds). - :return: True if the time was advanced, False if the end of the simulation was reached. """ total_duration = 0.0 if len(self.cumulativeLineDuration()) > 0: @@ -237,15 +236,13 @@ def advanceTime(self, time_increase: float) -> bool: # If we have reached the end of the simulation, go to the next layer. if self.getCurrentLayer() == self.getMaxLayers(): # If we are already at the last layer, go to the first layer. - self.setTime(total_duration) - return False - - # advance to the next layer, and reset the time - self.setLayer(self.getCurrentLayer() + 1) + self.setLayer(0) + else: + # advance to the next layer, and reset the time + self.setLayer(self.getCurrentLayer() + 1) self.setTime(0.0) else: self.setTime(self._current_time + time_increase) - return True def cumulativeLineDuration(self) -> List[float]: # Make sure _cumulative_line_duration is initialized properly diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index d9e7a95bc1c..602d403a8ad 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -144,9 +144,7 @@ Item { // divide by 1000 to account for ms to s conversion const advance_time = simulationTimer.interval / 1000.0; - if (!UM.SimulationView.advanceTime(advance_time)) { - playButton.pauseSimulation(); - } + UM.SimulationView.advanceTime(advance_time); // The status must be set here instead of in the resumeSimulation function otherwise it won't work // correctly, because part of the logic is in this trigger function. isSimulationPlaying = true; diff --git a/plugins/SimulationView/SimulationViewProxy.py b/plugins/SimulationView/SimulationViewProxy.py index bf449a99d11..30fed1422c2 100644 --- a/plugins/SimulationView/SimulationViewProxy.py +++ b/plugins/SimulationView/SimulationViewProxy.py @@ -54,9 +54,9 @@ def numPaths(self): def currentPath(self): return self._simulation_view.getCurrentPath() - @pyqtSlot(float, result=bool) - def advanceTime(self, duration: float) -> bool: - return self._simulation_view.advanceTime(duration) + @pyqtSlot(float) + def advanceTime(self, duration: float) -> None: + self._simulation_view.advanceTime(duration) @pyqtProperty(int, notify=currentPathChanged) def minimumPath(self):