From bf2c8b5a08e0fbf442edfa70ae4f11f04d3c32f2 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Fri, 8 Dec 2023 11:41:16 +0100 Subject: [PATCH] Simulation time fed to the timer controlling speed simulation time is made 10x faster than the actual time, for better visualisation CURA-7647 --- plugins/SimulationView/SimulationView.py | 10 ++++++---- .../SimulationViewMainComponent.qml | 6 +----- plugins/SimulationView/SimulationViewProxy.py | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 18d1f981c7..6874b27625 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -79,7 +79,7 @@ class SimulationView(CuraView): self.currentLayerNumChanged.connect(self._onCurrentLayerNumChanged) self._current_feedrates = {} - self._visible_lengths ={} + self._lengths_of_polyline ={} self._busy = False self._simulation_running = False @@ -403,7 +403,9 @@ class SimulationView(CuraView): return self._max_feedrate def getSimulationTime(self) -> list: - return self._visible_lengths[self._current_layer_num] / self._current_feedrates[self._current_layer_num] + if len(self._lengths_of_polyline) > 0 and len(self._lengths_of_polyline) == len(self._current_feedrates): + return self._lengths_of_polyline[self._current_layer_num] / self._current_feedrates[self._current_layer_num] + return numpy.zeros(0) def getMinThickness(self) -> float: if abs(self._min_thickness - sys.float_info.max) < 10: # Some lenience due to floating point rounding. @@ -529,10 +531,10 @@ class SimulationView(CuraView): visible_indicies_with_extrusion = numpy.where(numpy.isin(polyline.types, visible_line_types_with_extrusion))[0] if visible_indices.size == 0: # No items to take maximum or minimum of. continue - self._visible_lengths[layer_index] = numpy.take(polyline.lineLengths, visible_indices) + self._lengths_of_polyline[layer_index] = polyline.lineLengths visible_feedrates = numpy.take(polyline.lineFeedrates, visible_indices) visible_feedrates_with_extrusion = numpy.take(polyline.lineFeedrates, visible_indicies_with_extrusion) - self._current_feedrates[layer_index] = visible_feedrates + self._current_feedrates[layer_index] = polyline.lineFeedrates visible_linewidths = numpy.take(polyline.lineWidths, visible_indices) visible_linewidths_with_extrusion = numpy.take(polyline.lineWidths, visible_indicies_with_extrusion) visible_thicknesses = numpy.take(polyline.lineThicknesses, visible_indices) diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index 66acff656a..216095c15c 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -136,10 +136,9 @@ Item Timer { id: simulationTimer - interval: parseFloat(UM.SimulationView.getSimulationTime[pathNumber]).toFixed(2) + interval: UM.SimulationView.simulationTime running: false repeat: true - property int pathNumber : 0 onTriggered: { var currentPath = UM.SimulationView.currentPath @@ -154,12 +153,10 @@ Item if (currentPath >= numPaths) { UM.SimulationView.setCurrentPath(0) - pathNumber =0 } else { UM.SimulationView.setCurrentPath(currentPath + 1) - pathNumber = 0 } } // If the simulation is already playing and we reach the end of a layer, then it automatically @@ -187,7 +184,6 @@ Item // 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 - pathNumber += 1 } } diff --git a/plugins/SimulationView/SimulationViewProxy.py b/plugins/SimulationView/SimulationViewProxy.py index 669f7fdbcc..e80005fc36 100644 --- a/plugins/SimulationView/SimulationViewProxy.py +++ b/plugins/SimulationView/SimulationViewProxy.py @@ -2,9 +2,11 @@ # Cura is released under the terms of the LGPLv3 or higher. from typing import TYPE_CHECKING +import numpy from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty from UM.FlameProfiler import pyqtSlot from UM.Application import Application +from UM.Logger import Logger if TYPE_CHECKING: from .SimulationView import SimulationView @@ -54,6 +56,19 @@ class SimulationViewProxy(QObject): def currentPath(self): return self._simulation_view.getCurrentPath() + @pyqtProperty(int, notify=currentPathChanged) + def simulationTime(self): + # This if is activated when there is a layer change + if numpy.all(self._simulation_view.getSimulationTime()==0) or len(self._simulation_view.getSimulationTime()) <= self._simulation_view.getCurrentPath(): + return 100 + # Extracts the currents paths simulation time (in seconds) from the dict of simulation time of the current layer. + # We multiply the time with 100 to make it to ms from s.(Should be 1000 in real time). This scaling makes the simulation time 10x faster than the real time. + simulationTimeOfpath =self._simulation_view.getSimulationTime()[0][self._simulation_view.getCurrentPath()] * 100 + # Since the timer cannot process time less than 1 ms, we put a lower limit here + if simulationTimeOfpath < 1: + return 1 + return int(simulationTimeOfpath) + @pyqtProperty(int, notify=currentPathChanged) def minimumPath(self): return self._simulation_view.getMinimumPath()