Calculating time of travel for each line segment

CURA-7647
This commit is contained in:
saumya.jain 2023-11-07 18:08:08 +05:30
parent f873a94ef8
commit 6301926885
3 changed files with 16 additions and 1 deletions

View file

@ -1,5 +1,6 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import math
import numpy import numpy
from typing import Optional, cast from typing import Optional, cast
@ -186,6 +187,11 @@ class LayerPolygon:
def types(self): def types(self):
return self._types 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 @property
def data(self): def data(self):
return self._data return self._data

View file

@ -400,6 +400,9 @@ class SimulationView(CuraView):
def getMaxFeedrate(self) -> float: def getMaxFeedrate(self) -> float:
return self._max_feedrate 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: def getMinThickness(self) -> float:
if abs(self._min_thickness - sys.float_info.max) < 10: # Some lenience due to floating point rounding. 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. 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] 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. if visible_indices.size == 0: # No items to take maximum or minimum of.
continue continue
self._visible_lengths = numpy.take(polyline.lineLengths, visible_indices)
visible_feedrates = numpy.take(polyline.lineFeedrates, visible_indices) visible_feedrates = numpy.take(polyline.lineFeedrates, visible_indices)
visible_feedrates_with_extrusion = numpy.take(polyline.lineFeedrates, visible_indicies_with_extrusion) 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 = numpy.take(polyline.lineWidths, visible_indices)
visible_linewidths_with_extrusion = numpy.take(polyline.lineWidths, visible_indicies_with_extrusion) visible_linewidths_with_extrusion = numpy.take(polyline.lineWidths, visible_indicies_with_extrusion)
visible_thicknesses = numpy.take(polyline.lineThicknesses, visible_indices) visible_thicknesses = numpy.take(polyline.lineThicknesses, visible_indices)

View file

@ -136,9 +136,10 @@ Item
Timer Timer
{ {
id: simulationTimer id: simulationTimer
interval: 100 interval: parseFloat(UM.SimulationView.getSimulationTime[pathNumber]).toFixed(2) //10 //dont change
running: false running: false
repeat: true repeat: true
property int pathNumber : 0
onTriggered: onTriggered:
{ {
var currentPath = UM.SimulationView.currentPath var currentPath = UM.SimulationView.currentPath
@ -153,10 +154,12 @@ Item
if (currentPath >= numPaths) if (currentPath >= numPaths)
{ {
UM.SimulationView.setCurrentPath(0) UM.SimulationView.setCurrentPath(0)
pathNumber =0
} }
else else
{ {
UM.SimulationView.setCurrentPath(currentPath + 1) UM.SimulationView.setCurrentPath(currentPath + 1)
pathNumber = 0
} }
} }
// If the simulation is already playing and we reach the end of a layer, then it automatically // 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 // 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. // correctly, because part of the logic is in this trigger function.
isSimulationPlaying = true isSimulationPlaying = true
pathNumber += 1
} }
} }