mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Simulation time fed to the timer controlling speed
simulation time is made 10x faster than the actual time, for better visualisation CURA-7647
This commit is contained in:
parent
88d7d65622
commit
bf2c8b5a08
3 changed files with 22 additions and 9 deletions
|
@ -79,7 +79,7 @@ class SimulationView(CuraView):
|
||||||
self.currentLayerNumChanged.connect(self._onCurrentLayerNumChanged)
|
self.currentLayerNumChanged.connect(self._onCurrentLayerNumChanged)
|
||||||
|
|
||||||
self._current_feedrates = {}
|
self._current_feedrates = {}
|
||||||
self._visible_lengths ={}
|
self._lengths_of_polyline ={}
|
||||||
self._busy = False
|
self._busy = False
|
||||||
self._simulation_running = False
|
self._simulation_running = False
|
||||||
|
|
||||||
|
@ -403,7 +403,9 @@ class SimulationView(CuraView):
|
||||||
return self._max_feedrate
|
return self._max_feedrate
|
||||||
|
|
||||||
def getSimulationTime(self) -> list:
|
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:
|
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.
|
||||||
|
@ -529,10 +531,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[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 = 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[layer_index] = visible_feedrates
|
self._current_feedrates[layer_index] = polyline.lineFeedrates
|
||||||
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)
|
||||||
|
|
|
@ -136,10 +136,9 @@ Item
|
||||||
Timer
|
Timer
|
||||||
{
|
{
|
||||||
id: simulationTimer
|
id: simulationTimer
|
||||||
interval: parseFloat(UM.SimulationView.getSimulationTime[pathNumber]).toFixed(2)
|
interval: UM.SimulationView.simulationTime
|
||||||
running: false
|
running: false
|
||||||
repeat: true
|
repeat: true
|
||||||
property int pathNumber : 0
|
|
||||||
onTriggered:
|
onTriggered:
|
||||||
{
|
{
|
||||||
var currentPath = UM.SimulationView.currentPath
|
var currentPath = UM.SimulationView.currentPath
|
||||||
|
@ -154,12 +153,10 @@ 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
|
||||||
|
@ -187,7 +184,6 @@ 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import numpy
|
||||||
from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty
|
from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty
|
||||||
from UM.FlameProfiler import pyqtSlot
|
from UM.FlameProfiler import pyqtSlot
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
|
from UM.Logger import Logger
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .SimulationView import SimulationView
|
from .SimulationView import SimulationView
|
||||||
|
@ -54,6 +56,19 @@ class SimulationViewProxy(QObject):
|
||||||
def currentPath(self):
|
def currentPath(self):
|
||||||
return self._simulation_view.getCurrentPath()
|
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)
|
@pyqtProperty(int, notify=currentPathChanged)
|
||||||
def minimumPath(self):
|
def minimumPath(self):
|
||||||
return self._simulation_view.getMinimumPath()
|
return self._simulation_view.getMinimumPath()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue