diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 103703e594..4eb21dd45f 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -1,5 +1,6 @@ # Copyright (c) 2019 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +import math import numpy from typing import Optional, cast @@ -186,6 +187,11 @@ class LayerPolygon: def types(self): return self._types + @property + def lineLengths(self): + return [math.sqrt(sum((b - a) ** 2 for a, b in zip(self._data[i], self._data[i + 1]))) + for i in range(len(self._data) - 1)] + @property def data(self): return self._data diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 473948bc46..88fc44df98 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -400,6 +400,9 @@ class SimulationView(CuraView): def getMaxFeedrate(self) -> float: return self._max_feedrate + def getSimulationTime(self) -> list: + return [length / feedrate for length, feedrate in zip(self._visible_lengths, self._current_feedrates)] + def getMinThickness(self) -> float: if abs(self._min_thickness - sys.float_info.max) < 10: # Some lenience due to floating point rounding. return 0.0 # If it's still max-float, there are no measurements. Use 0 then. @@ -524,8 +527,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 = numpy.take(polyline.lineLengths, visible_indices) visible_feedrates = numpy.take(polyline.lineFeedrates, visible_indices) visible_feedrates_with_extrusion = numpy.take(polyline.lineFeedrates, visible_indicies_with_extrusion) + self._current_feedrates = visible_feedrates 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 a82d1e3db9..b2ef7b8356 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -136,9 +136,10 @@ Item Timer { id: simulationTimer - interval: 100 + interval: parseFloat(UM.SimulationView.getSimulationTime[pathNumber]).toFixed(2) //10 //dont change running: false repeat: true + property int pathNumber : 0 onTriggered: { var currentPath = UM.SimulationView.currentPath @@ -153,10 +154,12 @@ 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 @@ -184,6 +187,7 @@ 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 } }